Coverage Report

Created: 2025-10-13 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython3/Modules/clinic/posixmodule.c.h
Line
Count
Source
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
#include "pycore_abstract.h"      // _PyNumber_Index()
10
#include "pycore_long.h"          // _PyLong_UnsignedInt_Converter()
11
#include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
12
13
PyDoc_STRVAR(os_stat__doc__,
14
"stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
15
"--\n"
16
"\n"
17
"Perform a stat system call on the given path.\n"
18
"\n"
19
"  path\n"
20
"    Path to be examined; can be string, bytes, a path-like object or\n"
21
"    open-file-descriptor int.\n"
22
"  dir_fd\n"
23
"    If not None, it should be a file descriptor open to a directory,\n"
24
"    and path should be a relative string; path will then be relative to\n"
25
"    that directory.\n"
26
"  follow_symlinks\n"
27
"    If False, and the last element of the path is a symbolic link,\n"
28
"    stat will examine the symbolic link itself instead of the file\n"
29
"    the link points to.\n"
30
"\n"
31
"dir_fd and follow_symlinks may not be implemented\n"
32
"  on your platform.  If they are unavailable, using them will raise a\n"
33
"  NotImplementedError.\n"
34
"\n"
35
"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
36
"  an open file descriptor.");
37
38
#define OS_STAT_METHODDEF    \
39
    {"stat", _PyCFunction_CAST(os_stat), METH_FASTCALL|METH_KEYWORDS, os_stat__doc__},
40
41
static PyObject *
42
os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
43
44
static PyObject *
45
os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
46
2.10k
{
47
2.10k
    PyObject *return_value = NULL;
48
2.10k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
49
50
2.10k
    #define NUM_KEYWORDS 3
51
2.10k
    static struct {
52
2.10k
        PyGC_Head _this_is_not_used;
53
2.10k
        PyObject_VAR_HEAD
54
2.10k
        Py_hash_t ob_hash;
55
2.10k
        PyObject *ob_item[NUM_KEYWORDS];
56
2.10k
    } _kwtuple = {
57
2.10k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
58
2.10k
        .ob_hash = -1,
59
2.10k
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
60
2.10k
    };
61
2.10k
    #undef NUM_KEYWORDS
62
2.10k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
63
64
    #else  // !Py_BUILD_CORE
65
    #  define KWTUPLE NULL
66
    #endif  // !Py_BUILD_CORE
67
68
2.10k
    static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
69
2.10k
    static _PyArg_Parser _parser = {
70
2.10k
        .keywords = _keywords,
71
2.10k
        .fname = "stat",
72
2.10k
        .kwtuple = KWTUPLE,
73
2.10k
    };
74
2.10k
    #undef KWTUPLE
75
2.10k
    PyObject *argsbuf[3];
76
2.10k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
77
2.10k
    path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1);
78
2.10k
    int dir_fd = DEFAULT_DIR_FD;
79
2.10k
    int follow_symlinks = 1;
80
81
2.10k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
82
2.10k
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
83
2.10k
    if (!args) {
84
0
        goto exit;
85
0
    }
86
2.10k
    if (!path_converter(args[0], &path)) {
87
0
        goto exit;
88
0
    }
89
2.10k
    if (!noptargs) {
90
2.10k
        goto skip_optional_kwonly;
91
2.10k
    }
92
0
    if (args[1]) {
93
0
        if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
94
0
            goto exit;
95
0
        }
96
0
        if (!--noptargs) {
97
0
            goto skip_optional_kwonly;
98
0
        }
99
0
    }
100
0
    follow_symlinks = PyObject_IsTrue(args[2]);
101
0
    if (follow_symlinks < 0) {
102
0
        goto exit;
103
0
    }
104
2.10k
skip_optional_kwonly:
105
2.10k
    return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
106
107
2.10k
exit:
108
    /* Cleanup for path */
109
2.10k
    path_cleanup(&path);
110
111
2.10k
    return return_value;
112
2.10k
}
113
114
PyDoc_STRVAR(os_lstat__doc__,
115
"lstat($module, /, path, *, dir_fd=None)\n"
116
"--\n"
117
"\n"
118
"Perform a stat system call on the given path, without following symbolic links.\n"
119
"\n"
120
"Like stat(), but do not follow symbolic links.\n"
121
"Equivalent to stat(path, follow_symlinks=False).");
122
123
#define OS_LSTAT_METHODDEF    \
124
    {"lstat", _PyCFunction_CAST(os_lstat), METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
125
126
static PyObject *
127
os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
128
129
static PyObject *
130
os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
131
0
{
132
0
    PyObject *return_value = NULL;
133
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
134
135
0
    #define NUM_KEYWORDS 2
136
0
    static struct {
137
0
        PyGC_Head _this_is_not_used;
138
0
        PyObject_VAR_HEAD
139
0
        Py_hash_t ob_hash;
140
0
        PyObject *ob_item[NUM_KEYWORDS];
141
0
    } _kwtuple = {
142
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
143
0
        .ob_hash = -1,
144
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
145
0
    };
146
0
    #undef NUM_KEYWORDS
147
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
148
149
    #else  // !Py_BUILD_CORE
150
    #  define KWTUPLE NULL
151
    #endif  // !Py_BUILD_CORE
152
153
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
154
0
    static _PyArg_Parser _parser = {
155
0
        .keywords = _keywords,
156
0
        .fname = "lstat",
157
0
        .kwtuple = KWTUPLE,
158
0
    };
159
0
    #undef KWTUPLE
160
0
    PyObject *argsbuf[2];
161
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
162
0
    path_t path = PATH_T_INITIALIZE_P("lstat", "path", 0, 0, 0, 0);
163
0
    int dir_fd = DEFAULT_DIR_FD;
164
165
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
166
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
167
0
    if (!args) {
168
0
        goto exit;
169
0
    }
170
0
    if (!path_converter(args[0], &path)) {
171
0
        goto exit;
172
0
    }
173
0
    if (!noptargs) {
174
0
        goto skip_optional_kwonly;
175
0
    }
176
0
    if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
177
0
        goto exit;
178
0
    }
179
0
skip_optional_kwonly:
180
0
    return_value = os_lstat_impl(module, &path, dir_fd);
181
182
0
exit:
183
    /* Cleanup for path */
184
0
    path_cleanup(&path);
185
186
0
    return return_value;
187
0
}
188
189
PyDoc_STRVAR(os_access__doc__,
190
"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
191
"       follow_symlinks=True)\n"
192
"--\n"
193
"\n"
194
"Use the real uid/gid to test for access to a path.\n"
195
"\n"
196
"  path\n"
197
"    Path to be tested; can be string, bytes, or a path-like object.\n"
198
"  mode\n"
199
"    Operating-system mode bitfield.  Can be F_OK to test existence,\n"
200
"    or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
201
"  dir_fd\n"
202
"    If not None, it should be a file descriptor open to a directory,\n"
203
"    and path should be relative; path will then be relative to that\n"
204
"    directory.\n"
205
"  effective_ids\n"
206
"    If True, access will use the effective uid/gid instead of\n"
207
"    the real uid/gid.\n"
208
"  follow_symlinks\n"
209
"    If False, and the last element of the path is a symbolic link,\n"
210
"    access will examine the symbolic link itself instead of the file\n"
211
"    the link points to.\n"
212
"\n"
213
"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
214
"  on your platform.  If they are unavailable, using them will raise a\n"
215
"  NotImplementedError.\n"
216
"\n"
217
"Note that most operations will use the effective uid/gid, therefore this\n"
218
"  routine can be used in a suid/sgid environment to test if the invoking\n"
219
"  user has the specified access to the path.");
220
221
#define OS_ACCESS_METHODDEF    \
222
    {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
223
224
static int
225
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
226
               int effective_ids, int follow_symlinks);
227
228
static PyObject *
229
os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
230
0
{
231
0
    PyObject *return_value = NULL;
232
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
233
234
0
    #define NUM_KEYWORDS 5
235
0
    static struct {
236
0
        PyGC_Head _this_is_not_used;
237
0
        PyObject_VAR_HEAD
238
0
        Py_hash_t ob_hash;
239
0
        PyObject *ob_item[NUM_KEYWORDS];
240
0
    } _kwtuple = {
241
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
242
0
        .ob_hash = -1,
243
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), },
244
0
    };
245
0
    #undef NUM_KEYWORDS
246
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
247
248
    #else  // !Py_BUILD_CORE
249
    #  define KWTUPLE NULL
250
    #endif  // !Py_BUILD_CORE
251
252
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
253
0
    static _PyArg_Parser _parser = {
254
0
        .keywords = _keywords,
255
0
        .fname = "access",
256
0
        .kwtuple = KWTUPLE,
257
0
    };
258
0
    #undef KWTUPLE
259
0
    PyObject *argsbuf[5];
260
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
261
0
    path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0);
262
0
    int mode;
263
0
    int dir_fd = DEFAULT_DIR_FD;
264
0
    int effective_ids = 0;
265
0
    int follow_symlinks = 1;
266
0
    int _return_value;
267
268
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
269
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
270
0
    if (!args) {
271
0
        goto exit;
272
0
    }
273
0
    if (!path_converter(args[0], &path)) {
274
0
        goto exit;
275
0
    }
276
0
    mode = PyLong_AsInt(args[1]);
277
0
    if (mode == -1 && PyErr_Occurred()) {
278
0
        goto exit;
279
0
    }
280
0
    if (!noptargs) {
281
0
        goto skip_optional_kwonly;
282
0
    }
283
0
    if (args[2]) {
284
0
        if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
285
0
            goto exit;
286
0
        }
287
0
        if (!--noptargs) {
288
0
            goto skip_optional_kwonly;
289
0
        }
290
0
    }
291
0
    if (args[3]) {
292
0
        effective_ids = PyObject_IsTrue(args[3]);
293
0
        if (effective_ids < 0) {
294
0
            goto exit;
295
0
        }
296
0
        if (!--noptargs) {
297
0
            goto skip_optional_kwonly;
298
0
        }
299
0
    }
300
0
    follow_symlinks = PyObject_IsTrue(args[4]);
301
0
    if (follow_symlinks < 0) {
302
0
        goto exit;
303
0
    }
304
0
skip_optional_kwonly:
305
0
    _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
306
0
    if ((_return_value == -1) && PyErr_Occurred()) {
307
0
        goto exit;
308
0
    }
309
0
    return_value = PyBool_FromLong((long)_return_value);
310
311
0
exit:
312
    /* Cleanup for path */
313
0
    path_cleanup(&path);
314
315
0
    return return_value;
316
0
}
317
318
#if defined(HAVE_TTYNAME_R)
319
320
PyDoc_STRVAR(os_ttyname__doc__,
321
"ttyname($module, fd, /)\n"
322
"--\n"
323
"\n"
324
"Return the name of the terminal device connected to \'fd\'.\n"
325
"\n"
326
"  fd\n"
327
"    Integer file descriptor handle.");
328
329
#define OS_TTYNAME_METHODDEF    \
330
    {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
331
332
static PyObject *
333
os_ttyname_impl(PyObject *module, int fd);
334
335
static PyObject *
336
os_ttyname(PyObject *module, PyObject *arg)
337
0
{
338
0
    PyObject *return_value = NULL;
339
0
    int fd;
340
341
0
    fd = PyLong_AsInt(arg);
342
0
    if (fd == -1 && PyErr_Occurred()) {
343
0
        goto exit;
344
0
    }
345
0
    return_value = os_ttyname_impl(module, fd);
346
347
0
exit:
348
0
    return return_value;
349
0
}
350
351
#endif /* defined(HAVE_TTYNAME_R) */
352
353
#if defined(HAVE_CTERMID)
354
355
PyDoc_STRVAR(os_ctermid__doc__,
356
"ctermid($module, /)\n"
357
"--\n"
358
"\n"
359
"Return the name of the controlling terminal for this process.");
360
361
#define OS_CTERMID_METHODDEF    \
362
    {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
363
364
static PyObject *
365
os_ctermid_impl(PyObject *module);
366
367
static PyObject *
368
os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
369
0
{
370
0
    return os_ctermid_impl(module);
371
0
}
372
373
#endif /* defined(HAVE_CTERMID) */
374
375
PyDoc_STRVAR(os_chdir__doc__,
376
"chdir($module, /, path)\n"
377
"--\n"
378
"\n"
379
"Change the current working directory to the specified path.\n"
380
"\n"
381
"path may always be specified as a string.\n"
382
"On some platforms, path may also be specified as an open file descriptor.\n"
383
"If this functionality is unavailable, using it raises an exception.");
384
385
#define OS_CHDIR_METHODDEF    \
386
    {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
387
388
static PyObject *
389
os_chdir_impl(PyObject *module, path_t *path);
390
391
static PyObject *
392
os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
393
0
{
394
0
    PyObject *return_value = NULL;
395
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
396
397
0
    #define NUM_KEYWORDS 1
398
0
    static struct {
399
0
        PyGC_Head _this_is_not_used;
400
0
        PyObject_VAR_HEAD
401
0
        Py_hash_t ob_hash;
402
0
        PyObject *ob_item[NUM_KEYWORDS];
403
0
    } _kwtuple = {
404
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
405
0
        .ob_hash = -1,
406
0
        .ob_item = { &_Py_ID(path), },
407
0
    };
408
0
    #undef NUM_KEYWORDS
409
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
410
411
    #else  // !Py_BUILD_CORE
412
    #  define KWTUPLE NULL
413
    #endif  // !Py_BUILD_CORE
414
415
0
    static const char * const _keywords[] = {"path", NULL};
416
0
    static _PyArg_Parser _parser = {
417
0
        .keywords = _keywords,
418
0
        .fname = "chdir",
419
0
        .kwtuple = KWTUPLE,
420
0
    };
421
0
    #undef KWTUPLE
422
0
    PyObject *argsbuf[1];
423
0
    path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR);
424
425
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
426
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
427
0
    if (!args) {
428
0
        goto exit;
429
0
    }
430
0
    if (!path_converter(args[0], &path)) {
431
0
        goto exit;
432
0
    }
433
0
    return_value = os_chdir_impl(module, &path);
434
435
0
exit:
436
    /* Cleanup for path */
437
0
    path_cleanup(&path);
438
439
0
    return return_value;
440
0
}
441
442
#if defined(HAVE_FCHDIR)
443
444
PyDoc_STRVAR(os_fchdir__doc__,
445
"fchdir($module, /, fd)\n"
446
"--\n"
447
"\n"
448
"Change to the directory of the given file descriptor.\n"
449
"\n"
450
"fd must be opened on a directory, not a file.\n"
451
"Equivalent to os.chdir(fd).");
452
453
#define OS_FCHDIR_METHODDEF    \
454
    {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
455
456
static PyObject *
457
os_fchdir_impl(PyObject *module, int fd);
458
459
static PyObject *
460
os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
461
0
{
462
0
    PyObject *return_value = NULL;
463
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
464
465
0
    #define NUM_KEYWORDS 1
466
0
    static struct {
467
0
        PyGC_Head _this_is_not_used;
468
0
        PyObject_VAR_HEAD
469
0
        Py_hash_t ob_hash;
470
0
        PyObject *ob_item[NUM_KEYWORDS];
471
0
    } _kwtuple = {
472
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
473
0
        .ob_hash = -1,
474
0
        .ob_item = { &_Py_ID(fd), },
475
0
    };
476
0
    #undef NUM_KEYWORDS
477
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
478
479
    #else  // !Py_BUILD_CORE
480
    #  define KWTUPLE NULL
481
    #endif  // !Py_BUILD_CORE
482
483
0
    static const char * const _keywords[] = {"fd", NULL};
484
0
    static _PyArg_Parser _parser = {
485
0
        .keywords = _keywords,
486
0
        .fname = "fchdir",
487
0
        .kwtuple = KWTUPLE,
488
0
    };
489
0
    #undef KWTUPLE
490
0
    PyObject *argsbuf[1];
491
0
    int fd;
492
493
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
494
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
495
0
    if (!args) {
496
0
        goto exit;
497
0
    }
498
0
    fd = PyObject_AsFileDescriptor(args[0]);
499
0
    if (fd < 0) {
500
0
        goto exit;
501
0
    }
502
0
    return_value = os_fchdir_impl(module, fd);
503
504
0
exit:
505
0
    return return_value;
506
0
}
507
508
#endif /* defined(HAVE_FCHDIR) */
509
510
PyDoc_STRVAR(os_chmod__doc__,
511
"chmod($module, /, path, mode, *, dir_fd=None,\n"
512
"      follow_symlinks=(os.name != \'nt\'))\n"
513
"--\n"
514
"\n"
515
"Change the access permissions of a file.\n"
516
"\n"
517
"  path\n"
518
"    Path to be modified.  May always be specified as a str, bytes, or a path-like object.\n"
519
"    On some platforms, path may also be specified as an open file descriptor.\n"
520
"    If this functionality is unavailable, using it raises an exception.\n"
521
"  mode\n"
522
"    Operating-system mode bitfield.\n"
523
"    Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
524
"    numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
525
"    Python.\n"
526
"  dir_fd\n"
527
"    If not None, it should be a file descriptor open to a directory,\n"
528
"    and path should be relative; path will then be relative to that\n"
529
"    directory.\n"
530
"  follow_symlinks\n"
531
"    If False, and the last element of the path is a symbolic link,\n"
532
"    chmod will modify the symbolic link itself instead of the file\n"
533
"    the link points to.\n"
534
"\n"
535
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
536
"  an open file descriptor.\n"
537
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
538
"  If they are unavailable, using them will raise a NotImplementedError.");
539
540
#define OS_CHMOD_METHODDEF    \
541
    {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
542
543
static PyObject *
544
os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
545
              int follow_symlinks);
546
547
static PyObject *
548
os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
549
0
{
550
0
    PyObject *return_value = NULL;
551
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
552
553
0
    #define NUM_KEYWORDS 4
554
0
    static struct {
555
0
        PyGC_Head _this_is_not_used;
556
0
        PyObject_VAR_HEAD
557
0
        Py_hash_t ob_hash;
558
0
        PyObject *ob_item[NUM_KEYWORDS];
559
0
    } _kwtuple = {
560
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
561
0
        .ob_hash = -1,
562
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
563
0
    };
564
0
    #undef NUM_KEYWORDS
565
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
566
567
    #else  // !Py_BUILD_CORE
568
    #  define KWTUPLE NULL
569
    #endif  // !Py_BUILD_CORE
570
571
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
572
0
    static _PyArg_Parser _parser = {
573
0
        .keywords = _keywords,
574
0
        .fname = "chmod",
575
0
        .kwtuple = KWTUPLE,
576
0
    };
577
0
    #undef KWTUPLE
578
0
    PyObject *argsbuf[4];
579
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
580
0
    path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD);
581
0
    int mode;
582
0
    int dir_fd = DEFAULT_DIR_FD;
583
0
    int follow_symlinks = CHMOD_DEFAULT_FOLLOW_SYMLINKS;
584
585
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
586
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
587
0
    if (!args) {
588
0
        goto exit;
589
0
    }
590
0
    if (!path_converter(args[0], &path)) {
591
0
        goto exit;
592
0
    }
593
0
    mode = PyLong_AsInt(args[1]);
594
0
    if (mode == -1 && PyErr_Occurred()) {
595
0
        goto exit;
596
0
    }
597
0
    if (!noptargs) {
598
0
        goto skip_optional_kwonly;
599
0
    }
600
0
    if (args[2]) {
601
0
        if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
602
0
            goto exit;
603
0
        }
604
0
        if (!--noptargs) {
605
0
            goto skip_optional_kwonly;
606
0
        }
607
0
    }
608
0
    follow_symlinks = PyObject_IsTrue(args[3]);
609
0
    if (follow_symlinks < 0) {
610
0
        goto exit;
611
0
    }
612
0
skip_optional_kwonly:
613
0
    return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
614
615
0
exit:
616
    /* Cleanup for path */
617
0
    path_cleanup(&path);
618
619
0
    return return_value;
620
0
}
621
622
#if (defined(HAVE_FCHMOD) || defined(MS_WINDOWS))
623
624
PyDoc_STRVAR(os_fchmod__doc__,
625
"fchmod($module, /, fd, mode)\n"
626
"--\n"
627
"\n"
628
"Change the access permissions of the file given by file descriptor fd.\n"
629
"\n"
630
"  fd\n"
631
"    The file descriptor of the file to be modified.\n"
632
"  mode\n"
633
"    Operating-system mode bitfield.\n"
634
"    Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
635
"    numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
636
"    Python.\n"
637
"\n"
638
"Equivalent to os.chmod(fd, mode).");
639
640
#define OS_FCHMOD_METHODDEF    \
641
    {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
642
643
static PyObject *
644
os_fchmod_impl(PyObject *module, int fd, int mode);
645
646
static PyObject *
647
os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
648
0
{
649
0
    PyObject *return_value = NULL;
650
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
651
652
0
    #define NUM_KEYWORDS 2
653
0
    static struct {
654
0
        PyGC_Head _this_is_not_used;
655
0
        PyObject_VAR_HEAD
656
0
        Py_hash_t ob_hash;
657
0
        PyObject *ob_item[NUM_KEYWORDS];
658
0
    } _kwtuple = {
659
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
660
0
        .ob_hash = -1,
661
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(mode), },
662
0
    };
663
0
    #undef NUM_KEYWORDS
664
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
665
666
    #else  // !Py_BUILD_CORE
667
    #  define KWTUPLE NULL
668
    #endif  // !Py_BUILD_CORE
669
670
0
    static const char * const _keywords[] = {"fd", "mode", NULL};
671
0
    static _PyArg_Parser _parser = {
672
0
        .keywords = _keywords,
673
0
        .fname = "fchmod",
674
0
        .kwtuple = KWTUPLE,
675
0
    };
676
0
    #undef KWTUPLE
677
0
    PyObject *argsbuf[2];
678
0
    int fd;
679
0
    int mode;
680
681
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
682
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
683
0
    if (!args) {
684
0
        goto exit;
685
0
    }
686
0
    fd = PyLong_AsInt(args[0]);
687
0
    if (fd == -1 && PyErr_Occurred()) {
688
0
        goto exit;
689
0
    }
690
0
    mode = PyLong_AsInt(args[1]);
691
0
    if (mode == -1 && PyErr_Occurred()) {
692
0
        goto exit;
693
0
    }
694
0
    return_value = os_fchmod_impl(module, fd, mode);
695
696
0
exit:
697
0
    return return_value;
698
0
}
699
700
#endif /* (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) */
701
702
#if (defined(HAVE_LCHMOD) || defined(MS_WINDOWS))
703
704
PyDoc_STRVAR(os_lchmod__doc__,
705
"lchmod($module, /, path, mode)\n"
706
"--\n"
707
"\n"
708
"Change the access permissions of a file, without following symbolic links.\n"
709
"\n"
710
"If path is a symlink, this affects the link itself rather than the target.\n"
711
"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
712
713
#define OS_LCHMOD_METHODDEF    \
714
    {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
715
716
static PyObject *
717
os_lchmod_impl(PyObject *module, path_t *path, int mode);
718
719
static PyObject *
720
os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
721
{
722
    PyObject *return_value = NULL;
723
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
724
725
    #define NUM_KEYWORDS 2
726
    static struct {
727
        PyGC_Head _this_is_not_used;
728
        PyObject_VAR_HEAD
729
        Py_hash_t ob_hash;
730
        PyObject *ob_item[NUM_KEYWORDS];
731
    } _kwtuple = {
732
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
733
        .ob_hash = -1,
734
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), },
735
    };
736
    #undef NUM_KEYWORDS
737
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
738
739
    #else  // !Py_BUILD_CORE
740
    #  define KWTUPLE NULL
741
    #endif  // !Py_BUILD_CORE
742
743
    static const char * const _keywords[] = {"path", "mode", NULL};
744
    static _PyArg_Parser _parser = {
745
        .keywords = _keywords,
746
        .fname = "lchmod",
747
        .kwtuple = KWTUPLE,
748
    };
749
    #undef KWTUPLE
750
    PyObject *argsbuf[2];
751
    path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0);
752
    int mode;
753
754
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
755
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
756
    if (!args) {
757
        goto exit;
758
    }
759
    if (!path_converter(args[0], &path)) {
760
        goto exit;
761
    }
762
    mode = PyLong_AsInt(args[1]);
763
    if (mode == -1 && PyErr_Occurred()) {
764
        goto exit;
765
    }
766
    return_value = os_lchmod_impl(module, &path, mode);
767
768
exit:
769
    /* Cleanup for path */
770
    path_cleanup(&path);
771
772
    return return_value;
773
}
774
775
#endif /* (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) */
776
777
#if defined(HAVE_CHFLAGS)
778
779
PyDoc_STRVAR(os_chflags__doc__,
780
"chflags($module, /, path, flags, follow_symlinks=True)\n"
781
"--\n"
782
"\n"
783
"Set file flags.\n"
784
"\n"
785
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
786
"  link, chflags will change flags on the symbolic link itself instead of the\n"
787
"  file the link points to.\n"
788
"follow_symlinks may not be implemented on your platform.  If it is\n"
789
"unavailable, using it will raise a NotImplementedError.");
790
791
#define OS_CHFLAGS_METHODDEF    \
792
    {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
793
794
static PyObject *
795
os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
796
                int follow_symlinks);
797
798
static PyObject *
799
os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
800
{
801
    PyObject *return_value = NULL;
802
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
803
804
    #define NUM_KEYWORDS 3
805
    static struct {
806
        PyGC_Head _this_is_not_used;
807
        PyObject_VAR_HEAD
808
        Py_hash_t ob_hash;
809
        PyObject *ob_item[NUM_KEYWORDS];
810
    } _kwtuple = {
811
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
812
        .ob_hash = -1,
813
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
814
    };
815
    #undef NUM_KEYWORDS
816
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
817
818
    #else  // !Py_BUILD_CORE
819
    #  define KWTUPLE NULL
820
    #endif  // !Py_BUILD_CORE
821
822
    static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
823
    static _PyArg_Parser _parser = {
824
        .keywords = _keywords,
825
        .fname = "chflags",
826
        .kwtuple = KWTUPLE,
827
    };
828
    #undef KWTUPLE
829
    PyObject *argsbuf[3];
830
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
831
    path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0);
832
    unsigned long flags;
833
    int follow_symlinks = 1;
834
835
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
836
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
837
    if (!args) {
838
        goto exit;
839
    }
840
    if (!path_converter(args[0], &path)) {
841
        goto exit;
842
    }
843
    if (!PyIndex_Check(args[1])) {
844
        _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]);
845
        goto exit;
846
    }
847
    {
848
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long),
849
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
850
                Py_ASNATIVEBYTES_ALLOW_INDEX |
851
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
852
        if (_bytes < 0) {
853
            goto exit;
854
        }
855
        if ((size_t)_bytes > sizeof(unsigned long)) {
856
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
857
                "integer value out of range", 1) < 0)
858
            {
859
                goto exit;
860
            }
861
        }
862
    }
863
    if (!noptargs) {
864
        goto skip_optional_pos;
865
    }
866
    follow_symlinks = PyObject_IsTrue(args[2]);
867
    if (follow_symlinks < 0) {
868
        goto exit;
869
    }
870
skip_optional_pos:
871
    return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
872
873
exit:
874
    /* Cleanup for path */
875
    path_cleanup(&path);
876
877
    return return_value;
878
}
879
880
#endif /* defined(HAVE_CHFLAGS) */
881
882
#if defined(HAVE_LCHFLAGS)
883
884
PyDoc_STRVAR(os_lchflags__doc__,
885
"lchflags($module, /, path, flags)\n"
886
"--\n"
887
"\n"
888
"Set file flags.\n"
889
"\n"
890
"This function will not follow symbolic links.\n"
891
"Equivalent to chflags(path, flags, follow_symlinks=False).");
892
893
#define OS_LCHFLAGS_METHODDEF    \
894
    {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
895
896
static PyObject *
897
os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
898
899
static PyObject *
900
os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
901
{
902
    PyObject *return_value = NULL;
903
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
904
905
    #define NUM_KEYWORDS 2
906
    static struct {
907
        PyGC_Head _this_is_not_used;
908
        PyObject_VAR_HEAD
909
        Py_hash_t ob_hash;
910
        PyObject *ob_item[NUM_KEYWORDS];
911
    } _kwtuple = {
912
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
913
        .ob_hash = -1,
914
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), },
915
    };
916
    #undef NUM_KEYWORDS
917
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
918
919
    #else  // !Py_BUILD_CORE
920
    #  define KWTUPLE NULL
921
    #endif  // !Py_BUILD_CORE
922
923
    static const char * const _keywords[] = {"path", "flags", NULL};
924
    static _PyArg_Parser _parser = {
925
        .keywords = _keywords,
926
        .fname = "lchflags",
927
        .kwtuple = KWTUPLE,
928
    };
929
    #undef KWTUPLE
930
    PyObject *argsbuf[2];
931
    path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0);
932
    unsigned long flags;
933
934
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
935
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
936
    if (!args) {
937
        goto exit;
938
    }
939
    if (!path_converter(args[0], &path)) {
940
        goto exit;
941
    }
942
    if (!PyIndex_Check(args[1])) {
943
        _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]);
944
        goto exit;
945
    }
946
    {
947
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long),
948
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
949
                Py_ASNATIVEBYTES_ALLOW_INDEX |
950
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
951
        if (_bytes < 0) {
952
            goto exit;
953
        }
954
        if ((size_t)_bytes > sizeof(unsigned long)) {
955
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
956
                "integer value out of range", 1) < 0)
957
            {
958
                goto exit;
959
            }
960
        }
961
    }
962
    return_value = os_lchflags_impl(module, &path, flags);
963
964
exit:
965
    /* Cleanup for path */
966
    path_cleanup(&path);
967
968
    return return_value;
969
}
970
971
#endif /* defined(HAVE_LCHFLAGS) */
972
973
#if defined(HAVE_CHROOT)
974
975
PyDoc_STRVAR(os_chroot__doc__,
976
"chroot($module, /, path)\n"
977
"--\n"
978
"\n"
979
"Change root directory to path.");
980
981
#define OS_CHROOT_METHODDEF    \
982
    {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
983
984
static PyObject *
985
os_chroot_impl(PyObject *module, path_t *path);
986
987
static PyObject *
988
os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
989
0
{
990
0
    PyObject *return_value = NULL;
991
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
992
993
0
    #define NUM_KEYWORDS 1
994
0
    static struct {
995
0
        PyGC_Head _this_is_not_used;
996
0
        PyObject_VAR_HEAD
997
0
        Py_hash_t ob_hash;
998
0
        PyObject *ob_item[NUM_KEYWORDS];
999
0
    } _kwtuple = {
1000
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1001
0
        .ob_hash = -1,
1002
0
        .ob_item = { &_Py_ID(path), },
1003
0
    };
1004
0
    #undef NUM_KEYWORDS
1005
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1006
1007
    #else  // !Py_BUILD_CORE
1008
    #  define KWTUPLE NULL
1009
    #endif  // !Py_BUILD_CORE
1010
1011
0
    static const char * const _keywords[] = {"path", NULL};
1012
0
    static _PyArg_Parser _parser = {
1013
0
        .keywords = _keywords,
1014
0
        .fname = "chroot",
1015
0
        .kwtuple = KWTUPLE,
1016
0
    };
1017
0
    #undef KWTUPLE
1018
0
    PyObject *argsbuf[1];
1019
0
    path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0);
1020
1021
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1022
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1023
0
    if (!args) {
1024
0
        goto exit;
1025
0
    }
1026
0
    if (!path_converter(args[0], &path)) {
1027
0
        goto exit;
1028
0
    }
1029
0
    return_value = os_chroot_impl(module, &path);
1030
1031
0
exit:
1032
    /* Cleanup for path */
1033
0
    path_cleanup(&path);
1034
1035
0
    return return_value;
1036
0
}
1037
1038
#endif /* defined(HAVE_CHROOT) */
1039
1040
#if defined(HAVE_FSYNC)
1041
1042
PyDoc_STRVAR(os_fsync__doc__,
1043
"fsync($module, /, fd)\n"
1044
"--\n"
1045
"\n"
1046
"Force write of fd to disk.");
1047
1048
#define OS_FSYNC_METHODDEF    \
1049
    {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
1050
1051
static PyObject *
1052
os_fsync_impl(PyObject *module, int fd);
1053
1054
static PyObject *
1055
os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1056
0
{
1057
0
    PyObject *return_value = NULL;
1058
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1059
1060
0
    #define NUM_KEYWORDS 1
1061
0
    static struct {
1062
0
        PyGC_Head _this_is_not_used;
1063
0
        PyObject_VAR_HEAD
1064
0
        Py_hash_t ob_hash;
1065
0
        PyObject *ob_item[NUM_KEYWORDS];
1066
0
    } _kwtuple = {
1067
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1068
0
        .ob_hash = -1,
1069
0
        .ob_item = { &_Py_ID(fd), },
1070
0
    };
1071
0
    #undef NUM_KEYWORDS
1072
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1073
1074
    #else  // !Py_BUILD_CORE
1075
    #  define KWTUPLE NULL
1076
    #endif  // !Py_BUILD_CORE
1077
1078
0
    static const char * const _keywords[] = {"fd", NULL};
1079
0
    static _PyArg_Parser _parser = {
1080
0
        .keywords = _keywords,
1081
0
        .fname = "fsync",
1082
0
        .kwtuple = KWTUPLE,
1083
0
    };
1084
0
    #undef KWTUPLE
1085
0
    PyObject *argsbuf[1];
1086
0
    int fd;
1087
1088
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1089
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1090
0
    if (!args) {
1091
0
        goto exit;
1092
0
    }
1093
0
    fd = PyObject_AsFileDescriptor(args[0]);
1094
0
    if (fd < 0) {
1095
0
        goto exit;
1096
0
    }
1097
0
    return_value = os_fsync_impl(module, fd);
1098
1099
0
exit:
1100
0
    return return_value;
1101
0
}
1102
1103
#endif /* defined(HAVE_FSYNC) */
1104
1105
#if defined(HAVE_SYNC)
1106
1107
PyDoc_STRVAR(os_sync__doc__,
1108
"sync($module, /)\n"
1109
"--\n"
1110
"\n"
1111
"Force write of everything to disk.");
1112
1113
#define OS_SYNC_METHODDEF    \
1114
    {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
1115
1116
static PyObject *
1117
os_sync_impl(PyObject *module);
1118
1119
static PyObject *
1120
os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
1121
0
{
1122
0
    return os_sync_impl(module);
1123
0
}
1124
1125
#endif /* defined(HAVE_SYNC) */
1126
1127
#if defined(HAVE_FDATASYNC)
1128
1129
PyDoc_STRVAR(os_fdatasync__doc__,
1130
"fdatasync($module, /, fd)\n"
1131
"--\n"
1132
"\n"
1133
"Force write of fd to disk without forcing update of metadata.");
1134
1135
#define OS_FDATASYNC_METHODDEF    \
1136
    {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
1137
1138
static PyObject *
1139
os_fdatasync_impl(PyObject *module, int fd);
1140
1141
static PyObject *
1142
os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1143
0
{
1144
0
    PyObject *return_value = NULL;
1145
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1146
1147
0
    #define NUM_KEYWORDS 1
1148
0
    static struct {
1149
0
        PyGC_Head _this_is_not_used;
1150
0
        PyObject_VAR_HEAD
1151
0
        Py_hash_t ob_hash;
1152
0
        PyObject *ob_item[NUM_KEYWORDS];
1153
0
    } _kwtuple = {
1154
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1155
0
        .ob_hash = -1,
1156
0
        .ob_item = { &_Py_ID(fd), },
1157
0
    };
1158
0
    #undef NUM_KEYWORDS
1159
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1160
1161
    #else  // !Py_BUILD_CORE
1162
    #  define KWTUPLE NULL
1163
    #endif  // !Py_BUILD_CORE
1164
1165
0
    static const char * const _keywords[] = {"fd", NULL};
1166
0
    static _PyArg_Parser _parser = {
1167
0
        .keywords = _keywords,
1168
0
        .fname = "fdatasync",
1169
0
        .kwtuple = KWTUPLE,
1170
0
    };
1171
0
    #undef KWTUPLE
1172
0
    PyObject *argsbuf[1];
1173
0
    int fd;
1174
1175
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1176
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1177
0
    if (!args) {
1178
0
        goto exit;
1179
0
    }
1180
0
    fd = PyObject_AsFileDescriptor(args[0]);
1181
0
    if (fd < 0) {
1182
0
        goto exit;
1183
0
    }
1184
0
    return_value = os_fdatasync_impl(module, fd);
1185
1186
0
exit:
1187
0
    return return_value;
1188
0
}
1189
1190
#endif /* defined(HAVE_FDATASYNC) */
1191
1192
#if defined(HAVE_CHOWN)
1193
1194
PyDoc_STRVAR(os_chown__doc__,
1195
"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
1196
"--\n"
1197
"\n"
1198
"Change the owner and group id of path to the numeric uid and gid.\\\n"
1199
"\n"
1200
"  path\n"
1201
"    Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
1202
"  dir_fd\n"
1203
"    If not None, it should be a file descriptor open to a directory,\n"
1204
"    and path should be relative; path will then be relative to that\n"
1205
"    directory.\n"
1206
"  follow_symlinks\n"
1207
"    If False, and the last element of the path is a symbolic link,\n"
1208
"    stat will examine the symbolic link itself instead of the file\n"
1209
"    the link points to.\n"
1210
"\n"
1211
"path may always be specified as a string.\n"
1212
"On some platforms, path may also be specified as an open file descriptor.\n"
1213
"  If this functionality is unavailable, using it raises an exception.\n"
1214
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1215
"  and path should be relative; path will then be relative to that directory.\n"
1216
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1217
"  link, chown will modify the symbolic link itself instead of the file the\n"
1218
"  link points to.\n"
1219
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
1220
"  an open file descriptor.\n"
1221
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
1222
"  If they are unavailable, using them will raise a NotImplementedError.");
1223
1224
#define OS_CHOWN_METHODDEF    \
1225
    {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
1226
1227
static PyObject *
1228
os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
1229
              int dir_fd, int follow_symlinks);
1230
1231
static PyObject *
1232
os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1233
0
{
1234
0
    PyObject *return_value = NULL;
1235
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1236
1237
0
    #define NUM_KEYWORDS 5
1238
0
    static struct {
1239
0
        PyGC_Head _this_is_not_used;
1240
0
        PyObject_VAR_HEAD
1241
0
        Py_hash_t ob_hash;
1242
0
        PyObject *ob_item[NUM_KEYWORDS];
1243
0
    } _kwtuple = {
1244
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1245
0
        .ob_hash = -1,
1246
0
        .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
1247
0
    };
1248
0
    #undef NUM_KEYWORDS
1249
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1250
1251
    #else  // !Py_BUILD_CORE
1252
    #  define KWTUPLE NULL
1253
    #endif  // !Py_BUILD_CORE
1254
1255
0
    static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
1256
0
    static _PyArg_Parser _parser = {
1257
0
        .keywords = _keywords,
1258
0
        .fname = "chown",
1259
0
        .kwtuple = KWTUPLE,
1260
0
    };
1261
0
    #undef KWTUPLE
1262
0
    PyObject *argsbuf[5];
1263
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
1264
0
    path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN);
1265
0
    uid_t uid;
1266
0
    gid_t gid;
1267
0
    int dir_fd = DEFAULT_DIR_FD;
1268
0
    int follow_symlinks = 1;
1269
1270
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1271
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1272
0
    if (!args) {
1273
0
        goto exit;
1274
0
    }
1275
0
    if (!path_converter(args[0], &path)) {
1276
0
        goto exit;
1277
0
    }
1278
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1279
0
        goto exit;
1280
0
    }
1281
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1282
0
        goto exit;
1283
0
    }
1284
0
    if (!noptargs) {
1285
0
        goto skip_optional_kwonly;
1286
0
    }
1287
0
    if (args[3]) {
1288
0
        if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
1289
0
            goto exit;
1290
0
        }
1291
0
        if (!--noptargs) {
1292
0
            goto skip_optional_kwonly;
1293
0
        }
1294
0
    }
1295
0
    follow_symlinks = PyObject_IsTrue(args[4]);
1296
0
    if (follow_symlinks < 0) {
1297
0
        goto exit;
1298
0
    }
1299
0
skip_optional_kwonly:
1300
0
    return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
1301
1302
0
exit:
1303
    /* Cleanup for path */
1304
0
    path_cleanup(&path);
1305
1306
0
    return return_value;
1307
0
}
1308
1309
#endif /* defined(HAVE_CHOWN) */
1310
1311
#if defined(HAVE_FCHOWN)
1312
1313
PyDoc_STRVAR(os_fchown__doc__,
1314
"fchown($module, /, fd, uid, gid)\n"
1315
"--\n"
1316
"\n"
1317
"Change the owner and group id of the file specified by file descriptor.\n"
1318
"\n"
1319
"Equivalent to os.chown(fd, uid, gid).");
1320
1321
#define OS_FCHOWN_METHODDEF    \
1322
    {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
1323
1324
static PyObject *
1325
os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
1326
1327
static PyObject *
1328
os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1329
0
{
1330
0
    PyObject *return_value = NULL;
1331
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1332
1333
0
    #define NUM_KEYWORDS 3
1334
0
    static struct {
1335
0
        PyGC_Head _this_is_not_used;
1336
0
        PyObject_VAR_HEAD
1337
0
        Py_hash_t ob_hash;
1338
0
        PyObject *ob_item[NUM_KEYWORDS];
1339
0
    } _kwtuple = {
1340
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1341
0
        .ob_hash = -1,
1342
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), },
1343
0
    };
1344
0
    #undef NUM_KEYWORDS
1345
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1346
1347
    #else  // !Py_BUILD_CORE
1348
    #  define KWTUPLE NULL
1349
    #endif  // !Py_BUILD_CORE
1350
1351
0
    static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
1352
0
    static _PyArg_Parser _parser = {
1353
0
        .keywords = _keywords,
1354
0
        .fname = "fchown",
1355
0
        .kwtuple = KWTUPLE,
1356
0
    };
1357
0
    #undef KWTUPLE
1358
0
    PyObject *argsbuf[3];
1359
0
    int fd;
1360
0
    uid_t uid;
1361
0
    gid_t gid;
1362
1363
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1364
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1365
0
    if (!args) {
1366
0
        goto exit;
1367
0
    }
1368
0
    fd = PyLong_AsInt(args[0]);
1369
0
    if (fd == -1 && PyErr_Occurred()) {
1370
0
        goto exit;
1371
0
    }
1372
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1373
0
        goto exit;
1374
0
    }
1375
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1376
0
        goto exit;
1377
0
    }
1378
0
    return_value = os_fchown_impl(module, fd, uid, gid);
1379
1380
0
exit:
1381
0
    return return_value;
1382
0
}
1383
1384
#endif /* defined(HAVE_FCHOWN) */
1385
1386
#if defined(HAVE_LCHOWN)
1387
1388
PyDoc_STRVAR(os_lchown__doc__,
1389
"lchown($module, /, path, uid, gid)\n"
1390
"--\n"
1391
"\n"
1392
"Change the owner and group id of path to the numeric uid and gid.\n"
1393
"\n"
1394
"This function will not follow symbolic links.\n"
1395
"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
1396
1397
#define OS_LCHOWN_METHODDEF    \
1398
    {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
1399
1400
static PyObject *
1401
os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
1402
1403
static PyObject *
1404
os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1405
0
{
1406
0
    PyObject *return_value = NULL;
1407
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1408
1409
0
    #define NUM_KEYWORDS 3
1410
0
    static struct {
1411
0
        PyGC_Head _this_is_not_used;
1412
0
        PyObject_VAR_HEAD
1413
0
        Py_hash_t ob_hash;
1414
0
        PyObject *ob_item[NUM_KEYWORDS];
1415
0
    } _kwtuple = {
1416
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1417
0
        .ob_hash = -1,
1418
0
        .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), },
1419
0
    };
1420
0
    #undef NUM_KEYWORDS
1421
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1422
1423
    #else  // !Py_BUILD_CORE
1424
    #  define KWTUPLE NULL
1425
    #endif  // !Py_BUILD_CORE
1426
1427
0
    static const char * const _keywords[] = {"path", "uid", "gid", NULL};
1428
0
    static _PyArg_Parser _parser = {
1429
0
        .keywords = _keywords,
1430
0
        .fname = "lchown",
1431
0
        .kwtuple = KWTUPLE,
1432
0
    };
1433
0
    #undef KWTUPLE
1434
0
    PyObject *argsbuf[3];
1435
0
    path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0);
1436
0
    uid_t uid;
1437
0
    gid_t gid;
1438
1439
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1440
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1441
0
    if (!args) {
1442
0
        goto exit;
1443
0
    }
1444
0
    if (!path_converter(args[0], &path)) {
1445
0
        goto exit;
1446
0
    }
1447
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1448
0
        goto exit;
1449
0
    }
1450
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1451
0
        goto exit;
1452
0
    }
1453
0
    return_value = os_lchown_impl(module, &path, uid, gid);
1454
1455
0
exit:
1456
    /* Cleanup for path */
1457
0
    path_cleanup(&path);
1458
1459
0
    return return_value;
1460
0
}
1461
1462
#endif /* defined(HAVE_LCHOWN) */
1463
1464
PyDoc_STRVAR(os_getcwd__doc__,
1465
"getcwd($module, /)\n"
1466
"--\n"
1467
"\n"
1468
"Return a unicode string representing the current working directory.");
1469
1470
#define OS_GETCWD_METHODDEF    \
1471
    {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
1472
1473
static PyObject *
1474
os_getcwd_impl(PyObject *module);
1475
1476
static PyObject *
1477
os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
1478
0
{
1479
0
    return os_getcwd_impl(module);
1480
0
}
1481
1482
PyDoc_STRVAR(os_getcwdb__doc__,
1483
"getcwdb($module, /)\n"
1484
"--\n"
1485
"\n"
1486
"Return a bytes string representing the current working directory.");
1487
1488
#define OS_GETCWDB_METHODDEF    \
1489
    {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
1490
1491
static PyObject *
1492
os_getcwdb_impl(PyObject *module);
1493
1494
static PyObject *
1495
os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
1496
0
{
1497
0
    return os_getcwdb_impl(module);
1498
0
}
1499
1500
#if defined(HAVE_LINK)
1501
1502
PyDoc_STRVAR(os_link__doc__,
1503
"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
1504
"     follow_symlinks=(os.name != \'nt\'))\n"
1505
"--\n"
1506
"\n"
1507
"Create a hard link to a file.\n"
1508
"\n"
1509
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1510
"  descriptor open to a directory, and the respective path string (src or dst)\n"
1511
"  should be relative; the path will then be relative to that directory.\n"
1512
"If follow_symlinks is False, and the last element of src is a symbolic\n"
1513
"  link, link will create a link to the symbolic link itself instead of the\n"
1514
"  file the link points to.\n"
1515
"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
1516
"  platform.  If they are unavailable, using them will raise a\n"
1517
"  NotImplementedError.");
1518
1519
#define OS_LINK_METHODDEF    \
1520
    {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
1521
1522
static PyObject *
1523
os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1524
             int dst_dir_fd, int follow_symlinks);
1525
1526
static PyObject *
1527
os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1528
0
{
1529
0
    PyObject *return_value = NULL;
1530
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1531
1532
0
    #define NUM_KEYWORDS 5
1533
0
    static struct {
1534
0
        PyGC_Head _this_is_not_used;
1535
0
        PyObject_VAR_HEAD
1536
0
        Py_hash_t ob_hash;
1537
0
        PyObject *ob_item[NUM_KEYWORDS];
1538
0
    } _kwtuple = {
1539
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1540
0
        .ob_hash = -1,
1541
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), },
1542
0
    };
1543
0
    #undef NUM_KEYWORDS
1544
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1545
1546
    #else  // !Py_BUILD_CORE
1547
    #  define KWTUPLE NULL
1548
    #endif  // !Py_BUILD_CORE
1549
1550
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
1551
0
    static _PyArg_Parser _parser = {
1552
0
        .keywords = _keywords,
1553
0
        .fname = "link",
1554
0
        .kwtuple = KWTUPLE,
1555
0
    };
1556
0
    #undef KWTUPLE
1557
0
    PyObject *argsbuf[5];
1558
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1559
0
    path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0);
1560
0
    path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0);
1561
0
    int src_dir_fd = DEFAULT_DIR_FD;
1562
0
    int dst_dir_fd = DEFAULT_DIR_FD;
1563
0
    int follow_symlinks = -1;
1564
1565
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1566
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1567
0
    if (!args) {
1568
0
        goto exit;
1569
0
    }
1570
0
    if (!path_converter(args[0], &src)) {
1571
0
        goto exit;
1572
0
    }
1573
0
    if (!path_converter(args[1], &dst)) {
1574
0
        goto exit;
1575
0
    }
1576
0
    if (!noptargs) {
1577
0
        goto skip_optional_kwonly;
1578
0
    }
1579
0
    if (args[2]) {
1580
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
1581
0
            goto exit;
1582
0
        }
1583
0
        if (!--noptargs) {
1584
0
            goto skip_optional_kwonly;
1585
0
        }
1586
0
    }
1587
0
    if (args[3]) {
1588
0
        if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1589
0
            goto exit;
1590
0
        }
1591
0
        if (!--noptargs) {
1592
0
            goto skip_optional_kwonly;
1593
0
        }
1594
0
    }
1595
0
    follow_symlinks = PyObject_IsTrue(args[4]);
1596
0
    if (follow_symlinks < 0) {
1597
0
        goto exit;
1598
0
    }
1599
0
skip_optional_kwonly:
1600
0
    return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
1601
1602
0
exit:
1603
    /* Cleanup for src */
1604
0
    path_cleanup(&src);
1605
    /* Cleanup for dst */
1606
0
    path_cleanup(&dst);
1607
1608
0
    return return_value;
1609
0
}
1610
1611
#endif /* defined(HAVE_LINK) */
1612
1613
PyDoc_STRVAR(os_listdir__doc__,
1614
"listdir($module, /, path=None)\n"
1615
"--\n"
1616
"\n"
1617
"Return a list containing the names of the files in the directory.\n"
1618
"\n"
1619
"path can be specified as either str, bytes, or a path-like object.  If path is bytes,\n"
1620
"  the filenames returned will also be bytes; in all other circumstances\n"
1621
"  the filenames returned will be str.\n"
1622
"If path is None, uses the path=\'.\'.\n"
1623
"On some platforms, path may also be specified as an open file descriptor;\\\n"
1624
"  the file descriptor must refer to a directory.\n"
1625
"  If this functionality is unavailable, using it raises NotImplementedError.\n"
1626
"\n"
1627
"The list is in arbitrary order.  It does not include the special\n"
1628
"entries \'.\' and \'..\' even if they are present in the directory.");
1629
1630
#define OS_LISTDIR_METHODDEF    \
1631
    {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
1632
1633
static PyObject *
1634
os_listdir_impl(PyObject *module, path_t *path);
1635
1636
static PyObject *
1637
os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1638
120
{
1639
120
    PyObject *return_value = NULL;
1640
120
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1641
1642
120
    #define NUM_KEYWORDS 1
1643
120
    static struct {
1644
120
        PyGC_Head _this_is_not_used;
1645
120
        PyObject_VAR_HEAD
1646
120
        Py_hash_t ob_hash;
1647
120
        PyObject *ob_item[NUM_KEYWORDS];
1648
120
    } _kwtuple = {
1649
120
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1650
120
        .ob_hash = -1,
1651
120
        .ob_item = { &_Py_ID(path), },
1652
120
    };
1653
120
    #undef NUM_KEYWORDS
1654
120
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1655
1656
    #else  // !Py_BUILD_CORE
1657
    #  define KWTUPLE NULL
1658
    #endif  // !Py_BUILD_CORE
1659
1660
120
    static const char * const _keywords[] = {"path", NULL};
1661
120
    static _PyArg_Parser _parser = {
1662
120
        .keywords = _keywords,
1663
120
        .fname = "listdir",
1664
120
        .kwtuple = KWTUPLE,
1665
120
    };
1666
120
    #undef KWTUPLE
1667
120
    PyObject *argsbuf[1];
1668
120
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1669
120
    path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
1670
1671
120
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1672
120
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1673
120
    if (!args) {
1674
0
        goto exit;
1675
0
    }
1676
120
    if (!noptargs) {
1677
0
        goto skip_optional_pos;
1678
0
    }
1679
120
    if (!path_converter(args[0], &path)) {
1680
0
        goto exit;
1681
0
    }
1682
120
skip_optional_pos:
1683
120
    return_value = os_listdir_impl(module, &path);
1684
1685
120
exit:
1686
    /* Cleanup for path */
1687
120
    path_cleanup(&path);
1688
1689
120
    return return_value;
1690
120
}
1691
1692
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
1693
1694
PyDoc_STRVAR(os_listdrives__doc__,
1695
"listdrives($module, /)\n"
1696
"--\n"
1697
"\n"
1698
"Return a list containing the names of drives in the system.\n"
1699
"\n"
1700
"A drive name typically looks like \'C:\\\\\'.");
1701
1702
#define OS_LISTDRIVES_METHODDEF    \
1703
    {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__},
1704
1705
static PyObject *
1706
os_listdrives_impl(PyObject *module);
1707
1708
static PyObject *
1709
os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored))
1710
{
1711
    return os_listdrives_impl(module);
1712
}
1713
1714
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
1715
1716
#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
1717
1718
PyDoc_STRVAR(os_listvolumes__doc__,
1719
"listvolumes($module, /)\n"
1720
"--\n"
1721
"\n"
1722
"Return a list containing the volumes in the system.\n"
1723
"\n"
1724
"Volumes are typically represented as a GUID path.");
1725
1726
#define OS_LISTVOLUMES_METHODDEF    \
1727
    {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__},
1728
1729
static PyObject *
1730
os_listvolumes_impl(PyObject *module);
1731
1732
static PyObject *
1733
os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored))
1734
{
1735
    return os_listvolumes_impl(module);
1736
}
1737
1738
#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
1739
1740
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
1741
1742
PyDoc_STRVAR(os_listmounts__doc__,
1743
"listmounts($module, /, volume)\n"
1744
"--\n"
1745
"\n"
1746
"Return a list containing mount points for a particular volume.\n"
1747
"\n"
1748
"\'volume\' should be a GUID path as returned from os.listvolumes.");
1749
1750
#define OS_LISTMOUNTS_METHODDEF    \
1751
    {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__},
1752
1753
static PyObject *
1754
os_listmounts_impl(PyObject *module, path_t *volume);
1755
1756
static PyObject *
1757
os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1758
{
1759
    PyObject *return_value = NULL;
1760
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1761
1762
    #define NUM_KEYWORDS 1
1763
    static struct {
1764
        PyGC_Head _this_is_not_used;
1765
        PyObject_VAR_HEAD
1766
        Py_hash_t ob_hash;
1767
        PyObject *ob_item[NUM_KEYWORDS];
1768
    } _kwtuple = {
1769
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1770
        .ob_hash = -1,
1771
        .ob_item = { &_Py_ID(volume), },
1772
    };
1773
    #undef NUM_KEYWORDS
1774
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1775
1776
    #else  // !Py_BUILD_CORE
1777
    #  define KWTUPLE NULL
1778
    #endif  // !Py_BUILD_CORE
1779
1780
    static const char * const _keywords[] = {"volume", NULL};
1781
    static _PyArg_Parser _parser = {
1782
        .keywords = _keywords,
1783
        .fname = "listmounts",
1784
        .kwtuple = KWTUPLE,
1785
    };
1786
    #undef KWTUPLE
1787
    PyObject *argsbuf[1];
1788
    path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0);
1789
1790
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1791
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1792
    if (!args) {
1793
        goto exit;
1794
    }
1795
    if (!path_converter(args[0], &volume)) {
1796
        goto exit;
1797
    }
1798
    return_value = os_listmounts_impl(module, &volume);
1799
1800
exit:
1801
    /* Cleanup for volume */
1802
    path_cleanup(&volume);
1803
1804
    return return_value;
1805
}
1806
1807
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
1808
1809
#if defined(MS_WINDOWS)
1810
1811
PyDoc_STRVAR(os__path_isdevdrive__doc__,
1812
"_path_isdevdrive($module, /, path)\n"
1813
"--\n"
1814
"\n"
1815
"Determines whether the specified path is on a Windows Dev Drive.");
1816
1817
#define OS__PATH_ISDEVDRIVE_METHODDEF    \
1818
    {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__},
1819
1820
static PyObject *
1821
os__path_isdevdrive_impl(PyObject *module, path_t *path);
1822
1823
static PyObject *
1824
os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1825
{
1826
    PyObject *return_value = NULL;
1827
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1828
1829
    #define NUM_KEYWORDS 1
1830
    static struct {
1831
        PyGC_Head _this_is_not_used;
1832
        PyObject_VAR_HEAD
1833
        Py_hash_t ob_hash;
1834
        PyObject *ob_item[NUM_KEYWORDS];
1835
    } _kwtuple = {
1836
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1837
        .ob_hash = -1,
1838
        .ob_item = { &_Py_ID(path), },
1839
    };
1840
    #undef NUM_KEYWORDS
1841
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1842
1843
    #else  // !Py_BUILD_CORE
1844
    #  define KWTUPLE NULL
1845
    #endif  // !Py_BUILD_CORE
1846
1847
    static const char * const _keywords[] = {"path", NULL};
1848
    static _PyArg_Parser _parser = {
1849
        .keywords = _keywords,
1850
        .fname = "_path_isdevdrive",
1851
        .kwtuple = KWTUPLE,
1852
    };
1853
    #undef KWTUPLE
1854
    PyObject *argsbuf[1];
1855
    path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0);
1856
1857
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1858
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1859
    if (!args) {
1860
        goto exit;
1861
    }
1862
    if (!path_converter(args[0], &path)) {
1863
        goto exit;
1864
    }
1865
    return_value = os__path_isdevdrive_impl(module, &path);
1866
1867
exit:
1868
    /* Cleanup for path */
1869
    path_cleanup(&path);
1870
1871
    return return_value;
1872
}
1873
1874
#endif /* defined(MS_WINDOWS) */
1875
1876
#if defined(MS_WINDOWS)
1877
1878
PyDoc_STRVAR(os__getfullpathname__doc__,
1879
"_getfullpathname($module, path, /)\n"
1880
"--\n"
1881
"\n");
1882
1883
#define OS__GETFULLPATHNAME_METHODDEF    \
1884
    {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
1885
1886
static PyObject *
1887
os__getfullpathname_impl(PyObject *module, path_t *path);
1888
1889
static PyObject *
1890
os__getfullpathname(PyObject *module, PyObject *arg)
1891
{
1892
    PyObject *return_value = NULL;
1893
    path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0);
1894
1895
    if (!path_converter(arg, &path)) {
1896
        goto exit;
1897
    }
1898
    return_value = os__getfullpathname_impl(module, &path);
1899
1900
exit:
1901
    /* Cleanup for path */
1902
    path_cleanup(&path);
1903
1904
    return return_value;
1905
}
1906
1907
#endif /* defined(MS_WINDOWS) */
1908
1909
#if defined(MS_WINDOWS)
1910
1911
PyDoc_STRVAR(os__getfinalpathname__doc__,
1912
"_getfinalpathname($module, path, /)\n"
1913
"--\n"
1914
"\n"
1915
"A helper function for samepath on windows.");
1916
1917
#define OS__GETFINALPATHNAME_METHODDEF    \
1918
    {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
1919
1920
static PyObject *
1921
os__getfinalpathname_impl(PyObject *module, path_t *path);
1922
1923
static PyObject *
1924
os__getfinalpathname(PyObject *module, PyObject *arg)
1925
{
1926
    PyObject *return_value = NULL;
1927
    path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0);
1928
1929
    if (!path_converter(arg, &path)) {
1930
        goto exit;
1931
    }
1932
    return_value = os__getfinalpathname_impl(module, &path);
1933
1934
exit:
1935
    /* Cleanup for path */
1936
    path_cleanup(&path);
1937
1938
    return return_value;
1939
}
1940
1941
#endif /* defined(MS_WINDOWS) */
1942
1943
#if defined(MS_WINDOWS)
1944
1945
PyDoc_STRVAR(os__findfirstfile__doc__,
1946
"_findfirstfile($module, path, /)\n"
1947
"--\n"
1948
"\n"
1949
"A function to get the real file name without accessing the file in Windows.");
1950
1951
#define OS__FINDFIRSTFILE_METHODDEF    \
1952
    {"_findfirstfile", (PyCFunction)os__findfirstfile, METH_O, os__findfirstfile__doc__},
1953
1954
static PyObject *
1955
os__findfirstfile_impl(PyObject *module, path_t *path);
1956
1957
static PyObject *
1958
os__findfirstfile(PyObject *module, PyObject *arg)
1959
{
1960
    PyObject *return_value = NULL;
1961
    path_t path = PATH_T_INITIALIZE_P("_findfirstfile", "path", 0, 0, 0, 0);
1962
1963
    if (!path_converter(arg, &path)) {
1964
        goto exit;
1965
    }
1966
    return_value = os__findfirstfile_impl(module, &path);
1967
1968
exit:
1969
    /* Cleanup for path */
1970
    path_cleanup(&path);
1971
1972
    return return_value;
1973
}
1974
1975
#endif /* defined(MS_WINDOWS) */
1976
1977
#if defined(MS_WINDOWS)
1978
1979
PyDoc_STRVAR(os__getvolumepathname__doc__,
1980
"_getvolumepathname($module, /, path)\n"
1981
"--\n"
1982
"\n"
1983
"A helper function for ismount on Win32.");
1984
1985
#define OS__GETVOLUMEPATHNAME_METHODDEF    \
1986
    {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
1987
1988
static PyObject *
1989
os__getvolumepathname_impl(PyObject *module, path_t *path);
1990
1991
static PyObject *
1992
os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1993
{
1994
    PyObject *return_value = NULL;
1995
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1996
1997
    #define NUM_KEYWORDS 1
1998
    static struct {
1999
        PyGC_Head _this_is_not_used;
2000
        PyObject_VAR_HEAD
2001
        Py_hash_t ob_hash;
2002
        PyObject *ob_item[NUM_KEYWORDS];
2003
    } _kwtuple = {
2004
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2005
        .ob_hash = -1,
2006
        .ob_item = { &_Py_ID(path), },
2007
    };
2008
    #undef NUM_KEYWORDS
2009
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2010
2011
    #else  // !Py_BUILD_CORE
2012
    #  define KWTUPLE NULL
2013
    #endif  // !Py_BUILD_CORE
2014
2015
    static const char * const _keywords[] = {"path", NULL};
2016
    static _PyArg_Parser _parser = {
2017
        .keywords = _keywords,
2018
        .fname = "_getvolumepathname",
2019
        .kwtuple = KWTUPLE,
2020
    };
2021
    #undef KWTUPLE
2022
    PyObject *argsbuf[1];
2023
    path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0);
2024
2025
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2026
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2027
    if (!args) {
2028
        goto exit;
2029
    }
2030
    if (!path_converter(args[0], &path)) {
2031
        goto exit;
2032
    }
2033
    return_value = os__getvolumepathname_impl(module, &path);
2034
2035
exit:
2036
    /* Cleanup for path */
2037
    path_cleanup(&path);
2038
2039
    return return_value;
2040
}
2041
2042
#endif /* defined(MS_WINDOWS) */
2043
2044
#if defined(MS_WINDOWS)
2045
2046
PyDoc_STRVAR(os__path_splitroot__doc__,
2047
"_path_splitroot($module, path, /)\n"
2048
"--\n"
2049
"\n"
2050
"Removes everything after the root on Win32.");
2051
2052
#define OS__PATH_SPLITROOT_METHODDEF    \
2053
    {"_path_splitroot", (PyCFunction)os__path_splitroot, METH_O, os__path_splitroot__doc__},
2054
2055
static PyObject *
2056
os__path_splitroot_impl(PyObject *module, path_t *path);
2057
2058
static PyObject *
2059
os__path_splitroot(PyObject *module, PyObject *arg)
2060
{
2061
    PyObject *return_value = NULL;
2062
    path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0);
2063
2064
    if (!path_converter(arg, &path)) {
2065
        goto exit;
2066
    }
2067
    return_value = os__path_splitroot_impl(module, &path);
2068
2069
exit:
2070
    /* Cleanup for path */
2071
    path_cleanup(&path);
2072
2073
    return return_value;
2074
}
2075
2076
#endif /* defined(MS_WINDOWS) */
2077
2078
#if defined(MS_WINDOWS)
2079
2080
PyDoc_STRVAR(os__path_exists__doc__,
2081
"_path_exists($module, /, path)\n"
2082
"--\n"
2083
"\n"
2084
"Test whether a path exists.  Returns False for broken symbolic links.");
2085
2086
#define OS__PATH_EXISTS_METHODDEF    \
2087
    {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__},
2088
2089
static int
2090
os__path_exists_impl(PyObject *module, path_t *path);
2091
2092
static PyObject *
2093
os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2094
{
2095
    PyObject *return_value = NULL;
2096
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2097
2098
    #define NUM_KEYWORDS 1
2099
    static struct {
2100
        PyGC_Head _this_is_not_used;
2101
        PyObject_VAR_HEAD
2102
        Py_hash_t ob_hash;
2103
        PyObject *ob_item[NUM_KEYWORDS];
2104
    } _kwtuple = {
2105
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2106
        .ob_hash = -1,
2107
        .ob_item = { &_Py_ID(path), },
2108
    };
2109
    #undef NUM_KEYWORDS
2110
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2111
2112
    #else  // !Py_BUILD_CORE
2113
    #  define KWTUPLE NULL
2114
    #endif  // !Py_BUILD_CORE
2115
2116
    static const char * const _keywords[] = {"path", NULL};
2117
    static _PyArg_Parser _parser = {
2118
        .keywords = _keywords,
2119
        .fname = "_path_exists",
2120
        .kwtuple = KWTUPLE,
2121
    };
2122
    #undef KWTUPLE
2123
    PyObject *argsbuf[1];
2124
    path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1);
2125
    int _return_value;
2126
2127
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2128
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2129
    if (!args) {
2130
        goto exit;
2131
    }
2132
    if (!path_converter(args[0], &path)) {
2133
        goto exit;
2134
    }
2135
    _return_value = os__path_exists_impl(module, &path);
2136
    if ((_return_value == -1) && PyErr_Occurred()) {
2137
        goto exit;
2138
    }
2139
    return_value = PyBool_FromLong((long)_return_value);
2140
2141
exit:
2142
    /* Cleanup for path */
2143
    path_cleanup(&path);
2144
2145
    return return_value;
2146
}
2147
2148
#endif /* defined(MS_WINDOWS) */
2149
2150
#if defined(MS_WINDOWS)
2151
2152
PyDoc_STRVAR(os__path_lexists__doc__,
2153
"_path_lexists($module, /, path)\n"
2154
"--\n"
2155
"\n"
2156
"Test whether a path exists.  Returns True for broken symbolic links.");
2157
2158
#define OS__PATH_LEXISTS_METHODDEF    \
2159
    {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__},
2160
2161
static int
2162
os__path_lexists_impl(PyObject *module, path_t *path);
2163
2164
static PyObject *
2165
os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2166
{
2167
    PyObject *return_value = NULL;
2168
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2169
2170
    #define NUM_KEYWORDS 1
2171
    static struct {
2172
        PyGC_Head _this_is_not_used;
2173
        PyObject_VAR_HEAD
2174
        Py_hash_t ob_hash;
2175
        PyObject *ob_item[NUM_KEYWORDS];
2176
    } _kwtuple = {
2177
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2178
        .ob_hash = -1,
2179
        .ob_item = { &_Py_ID(path), },
2180
    };
2181
    #undef NUM_KEYWORDS
2182
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2183
2184
    #else  // !Py_BUILD_CORE
2185
    #  define KWTUPLE NULL
2186
    #endif  // !Py_BUILD_CORE
2187
2188
    static const char * const _keywords[] = {"path", NULL};
2189
    static _PyArg_Parser _parser = {
2190
        .keywords = _keywords,
2191
        .fname = "_path_lexists",
2192
        .kwtuple = KWTUPLE,
2193
    };
2194
    #undef KWTUPLE
2195
    PyObject *argsbuf[1];
2196
    path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1);
2197
    int _return_value;
2198
2199
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2200
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2201
    if (!args) {
2202
        goto exit;
2203
    }
2204
    if (!path_converter(args[0], &path)) {
2205
        goto exit;
2206
    }
2207
    _return_value = os__path_lexists_impl(module, &path);
2208
    if ((_return_value == -1) && PyErr_Occurred()) {
2209
        goto exit;
2210
    }
2211
    return_value = PyBool_FromLong((long)_return_value);
2212
2213
exit:
2214
    /* Cleanup for path */
2215
    path_cleanup(&path);
2216
2217
    return return_value;
2218
}
2219
2220
#endif /* defined(MS_WINDOWS) */
2221
2222
#if defined(MS_WINDOWS)
2223
2224
PyDoc_STRVAR(os__path_isdir__doc__,
2225
"_path_isdir($module, path, /)\n"
2226
"--\n"
2227
"\n"
2228
"Return true if the pathname refers to an existing directory.");
2229
2230
#define OS__PATH_ISDIR_METHODDEF    \
2231
    {"_path_isdir", (PyCFunction)os__path_isdir, METH_O, os__path_isdir__doc__},
2232
2233
static int
2234
os__path_isdir_impl(PyObject *module, path_t *path);
2235
2236
static PyObject *
2237
os__path_isdir(PyObject *module, PyObject *arg)
2238
{
2239
    PyObject *return_value = NULL;
2240
    path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1);
2241
    int _return_value;
2242
2243
    if (!path_converter(arg, &path)) {
2244
        goto exit;
2245
    }
2246
    _return_value = os__path_isdir_impl(module, &path);
2247
    if ((_return_value == -1) && PyErr_Occurred()) {
2248
        goto exit;
2249
    }
2250
    return_value = PyBool_FromLong((long)_return_value);
2251
2252
exit:
2253
    /* Cleanup for path */
2254
    path_cleanup(&path);
2255
2256
    return return_value;
2257
}
2258
2259
#endif /* defined(MS_WINDOWS) */
2260
2261
#if defined(MS_WINDOWS)
2262
2263
PyDoc_STRVAR(os__path_isfile__doc__,
2264
"_path_isfile($module, /, path)\n"
2265
"--\n"
2266
"\n"
2267
"Test whether a path is a regular file");
2268
2269
#define OS__PATH_ISFILE_METHODDEF    \
2270
    {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
2271
2272
static int
2273
os__path_isfile_impl(PyObject *module, path_t *path);
2274
2275
static PyObject *
2276
os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2277
{
2278
    PyObject *return_value = NULL;
2279
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2280
2281
    #define NUM_KEYWORDS 1
2282
    static struct {
2283
        PyGC_Head _this_is_not_used;
2284
        PyObject_VAR_HEAD
2285
        Py_hash_t ob_hash;
2286
        PyObject *ob_item[NUM_KEYWORDS];
2287
    } _kwtuple = {
2288
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2289
        .ob_hash = -1,
2290
        .ob_item = { &_Py_ID(path), },
2291
    };
2292
    #undef NUM_KEYWORDS
2293
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2294
2295
    #else  // !Py_BUILD_CORE
2296
    #  define KWTUPLE NULL
2297
    #endif  // !Py_BUILD_CORE
2298
2299
    static const char * const _keywords[] = {"path", NULL};
2300
    static _PyArg_Parser _parser = {
2301
        .keywords = _keywords,
2302
        .fname = "_path_isfile",
2303
        .kwtuple = KWTUPLE,
2304
    };
2305
    #undef KWTUPLE
2306
    PyObject *argsbuf[1];
2307
    path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1);
2308
    int _return_value;
2309
2310
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2311
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2312
    if (!args) {
2313
        goto exit;
2314
    }
2315
    if (!path_converter(args[0], &path)) {
2316
        goto exit;
2317
    }
2318
    _return_value = os__path_isfile_impl(module, &path);
2319
    if ((_return_value == -1) && PyErr_Occurred()) {
2320
        goto exit;
2321
    }
2322
    return_value = PyBool_FromLong((long)_return_value);
2323
2324
exit:
2325
    /* Cleanup for path */
2326
    path_cleanup(&path);
2327
2328
    return return_value;
2329
}
2330
2331
#endif /* defined(MS_WINDOWS) */
2332
2333
#if defined(MS_WINDOWS)
2334
2335
PyDoc_STRVAR(os__path_islink__doc__,
2336
"_path_islink($module, /, path)\n"
2337
"--\n"
2338
"\n"
2339
"Test whether a path is a symbolic link");
2340
2341
#define OS__PATH_ISLINK_METHODDEF    \
2342
    {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
2343
2344
static int
2345
os__path_islink_impl(PyObject *module, path_t *path);
2346
2347
static PyObject *
2348
os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2349
{
2350
    PyObject *return_value = NULL;
2351
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2352
2353
    #define NUM_KEYWORDS 1
2354
    static struct {
2355
        PyGC_Head _this_is_not_used;
2356
        PyObject_VAR_HEAD
2357
        Py_hash_t ob_hash;
2358
        PyObject *ob_item[NUM_KEYWORDS];
2359
    } _kwtuple = {
2360
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2361
        .ob_hash = -1,
2362
        .ob_item = { &_Py_ID(path), },
2363
    };
2364
    #undef NUM_KEYWORDS
2365
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2366
2367
    #else  // !Py_BUILD_CORE
2368
    #  define KWTUPLE NULL
2369
    #endif  // !Py_BUILD_CORE
2370
2371
    static const char * const _keywords[] = {"path", NULL};
2372
    static _PyArg_Parser _parser = {
2373
        .keywords = _keywords,
2374
        .fname = "_path_islink",
2375
        .kwtuple = KWTUPLE,
2376
    };
2377
    #undef KWTUPLE
2378
    PyObject *argsbuf[1];
2379
    path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1);
2380
    int _return_value;
2381
2382
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2383
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2384
    if (!args) {
2385
        goto exit;
2386
    }
2387
    if (!path_converter(args[0], &path)) {
2388
        goto exit;
2389
    }
2390
    _return_value = os__path_islink_impl(module, &path);
2391
    if ((_return_value == -1) && PyErr_Occurred()) {
2392
        goto exit;
2393
    }
2394
    return_value = PyBool_FromLong((long)_return_value);
2395
2396
exit:
2397
    /* Cleanup for path */
2398
    path_cleanup(&path);
2399
2400
    return return_value;
2401
}
2402
2403
#endif /* defined(MS_WINDOWS) */
2404
2405
#if defined(MS_WINDOWS)
2406
2407
PyDoc_STRVAR(os__path_isjunction__doc__,
2408
"_path_isjunction($module, /, path)\n"
2409
"--\n"
2410
"\n"
2411
"Test whether a path is a junction");
2412
2413
#define OS__PATH_ISJUNCTION_METHODDEF    \
2414
    {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__},
2415
2416
static int
2417
os__path_isjunction_impl(PyObject *module, path_t *path);
2418
2419
static PyObject *
2420
os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2421
{
2422
    PyObject *return_value = NULL;
2423
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2424
2425
    #define NUM_KEYWORDS 1
2426
    static struct {
2427
        PyGC_Head _this_is_not_used;
2428
        PyObject_VAR_HEAD
2429
        Py_hash_t ob_hash;
2430
        PyObject *ob_item[NUM_KEYWORDS];
2431
    } _kwtuple = {
2432
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2433
        .ob_hash = -1,
2434
        .ob_item = { &_Py_ID(path), },
2435
    };
2436
    #undef NUM_KEYWORDS
2437
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2438
2439
    #else  // !Py_BUILD_CORE
2440
    #  define KWTUPLE NULL
2441
    #endif  // !Py_BUILD_CORE
2442
2443
    static const char * const _keywords[] = {"path", NULL};
2444
    static _PyArg_Parser _parser = {
2445
        .keywords = _keywords,
2446
        .fname = "_path_isjunction",
2447
        .kwtuple = KWTUPLE,
2448
    };
2449
    #undef KWTUPLE
2450
    PyObject *argsbuf[1];
2451
    path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1);
2452
    int _return_value;
2453
2454
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2455
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2456
    if (!args) {
2457
        goto exit;
2458
    }
2459
    if (!path_converter(args[0], &path)) {
2460
        goto exit;
2461
    }
2462
    _return_value = os__path_isjunction_impl(module, &path);
2463
    if ((_return_value == -1) && PyErr_Occurred()) {
2464
        goto exit;
2465
    }
2466
    return_value = PyBool_FromLong((long)_return_value);
2467
2468
exit:
2469
    /* Cleanup for path */
2470
    path_cleanup(&path);
2471
2472
    return return_value;
2473
}
2474
2475
#endif /* defined(MS_WINDOWS) */
2476
2477
PyDoc_STRVAR(os__path_splitroot_ex__doc__,
2478
"_path_splitroot_ex($module, path, /)\n"
2479
"--\n"
2480
"\n"
2481
"Split a pathname into drive, root and tail.\n"
2482
"\n"
2483
"The tail contains anything after the root.");
2484
2485
#define OS__PATH_SPLITROOT_EX_METHODDEF    \
2486
    {"_path_splitroot_ex", (PyCFunction)os__path_splitroot_ex, METH_O, os__path_splitroot_ex__doc__},
2487
2488
static PyObject *
2489
os__path_splitroot_ex_impl(PyObject *module, path_t *path);
2490
2491
static PyObject *
2492
os__path_splitroot_ex(PyObject *module, PyObject *arg)
2493
0
{
2494
0
    PyObject *return_value = NULL;
2495
0
    path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0);
2496
2497
0
    if (!path_converter(arg, &path)) {
2498
0
        goto exit;
2499
0
    }
2500
0
    return_value = os__path_splitroot_ex_impl(module, &path);
2501
2502
0
exit:
2503
    /* Cleanup for path */
2504
0
    path_cleanup(&path);
2505
2506
0
    return return_value;
2507
0
}
2508
2509
PyDoc_STRVAR(os__path_normpath__doc__,
2510
"_path_normpath($module, /, path)\n"
2511
"--\n"
2512
"\n"
2513
"Normalize path, eliminating double slashes, etc.");
2514
2515
#define OS__PATH_NORMPATH_METHODDEF    \
2516
    {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
2517
2518
static PyObject *
2519
os__path_normpath_impl(PyObject *module, path_t *path);
2520
2521
static PyObject *
2522
os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2523
110
{
2524
110
    PyObject *return_value = NULL;
2525
110
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2526
2527
110
    #define NUM_KEYWORDS 1
2528
110
    static struct {
2529
110
        PyGC_Head _this_is_not_used;
2530
110
        PyObject_VAR_HEAD
2531
110
        Py_hash_t ob_hash;
2532
110
        PyObject *ob_item[NUM_KEYWORDS];
2533
110
    } _kwtuple = {
2534
110
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2535
110
        .ob_hash = -1,
2536
110
        .ob_item = { &_Py_ID(path), },
2537
110
    };
2538
110
    #undef NUM_KEYWORDS
2539
110
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2540
2541
    #else  // !Py_BUILD_CORE
2542
    #  define KWTUPLE NULL
2543
    #endif  // !Py_BUILD_CORE
2544
2545
110
    static const char * const _keywords[] = {"path", NULL};
2546
110
    static _PyArg_Parser _parser = {
2547
110
        .keywords = _keywords,
2548
110
        .fname = "_path_normpath",
2549
110
        .kwtuple = KWTUPLE,
2550
110
    };
2551
110
    #undef KWTUPLE
2552
110
    PyObject *argsbuf[1];
2553
110
    path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0);
2554
2555
110
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2556
110
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2557
110
    if (!args) {
2558
0
        goto exit;
2559
0
    }
2560
110
    if (!path_converter(args[0], &path)) {
2561
0
        goto exit;
2562
0
    }
2563
110
    return_value = os__path_normpath_impl(module, &path);
2564
2565
110
exit:
2566
    /* Cleanup for path */
2567
110
    path_cleanup(&path);
2568
2569
110
    return return_value;
2570
110
}
2571
2572
PyDoc_STRVAR(os_mkdir__doc__,
2573
"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
2574
"--\n"
2575
"\n"
2576
"Create a directory.\n"
2577
"\n"
2578
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2579
"  and path should be relative; path will then be relative to that directory.\n"
2580
"dir_fd may not be implemented on your platform.\n"
2581
"  If it is unavailable, using it will raise a NotImplementedError.\n"
2582
"\n"
2583
"The mode argument is ignored on Windows. Where it is used, the current umask\n"
2584
"value is first masked out.");
2585
2586
#define OS_MKDIR_METHODDEF    \
2587
    {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
2588
2589
static PyObject *
2590
os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
2591
2592
static PyObject *
2593
os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2594
0
{
2595
0
    PyObject *return_value = NULL;
2596
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2597
2598
0
    #define NUM_KEYWORDS 3
2599
0
    static struct {
2600
0
        PyGC_Head _this_is_not_used;
2601
0
        PyObject_VAR_HEAD
2602
0
        Py_hash_t ob_hash;
2603
0
        PyObject *ob_item[NUM_KEYWORDS];
2604
0
    } _kwtuple = {
2605
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2606
0
        .ob_hash = -1,
2607
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
2608
0
    };
2609
0
    #undef NUM_KEYWORDS
2610
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2611
2612
    #else  // !Py_BUILD_CORE
2613
    #  define KWTUPLE NULL
2614
    #endif  // !Py_BUILD_CORE
2615
2616
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
2617
0
    static _PyArg_Parser _parser = {
2618
0
        .keywords = _keywords,
2619
0
        .fname = "mkdir",
2620
0
        .kwtuple = KWTUPLE,
2621
0
    };
2622
0
    #undef KWTUPLE
2623
0
    PyObject *argsbuf[3];
2624
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
2625
0
    path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0);
2626
0
    int mode = 511;
2627
0
    int dir_fd = DEFAULT_DIR_FD;
2628
2629
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2630
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2631
0
    if (!args) {
2632
0
        goto exit;
2633
0
    }
2634
0
    if (!path_converter(args[0], &path)) {
2635
0
        goto exit;
2636
0
    }
2637
0
    if (!noptargs) {
2638
0
        goto skip_optional_pos;
2639
0
    }
2640
0
    if (args[1]) {
2641
0
        mode = PyLong_AsInt(args[1]);
2642
0
        if (mode == -1 && PyErr_Occurred()) {
2643
0
            goto exit;
2644
0
        }
2645
0
        if (!--noptargs) {
2646
0
            goto skip_optional_pos;
2647
0
        }
2648
0
    }
2649
0
skip_optional_pos:
2650
0
    if (!noptargs) {
2651
0
        goto skip_optional_kwonly;
2652
0
    }
2653
0
    if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
2654
0
        goto exit;
2655
0
    }
2656
0
skip_optional_kwonly:
2657
0
    return_value = os_mkdir_impl(module, &path, mode, dir_fd);
2658
2659
0
exit:
2660
    /* Cleanup for path */
2661
0
    path_cleanup(&path);
2662
2663
0
    return return_value;
2664
0
}
2665
2666
#if defined(HAVE_NICE)
2667
2668
PyDoc_STRVAR(os_nice__doc__,
2669
"nice($module, increment, /)\n"
2670
"--\n"
2671
"\n"
2672
"Add increment to the priority of process and return the new priority.");
2673
2674
#define OS_NICE_METHODDEF    \
2675
    {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
2676
2677
static PyObject *
2678
os_nice_impl(PyObject *module, int increment);
2679
2680
static PyObject *
2681
os_nice(PyObject *module, PyObject *arg)
2682
0
{
2683
0
    PyObject *return_value = NULL;
2684
0
    int increment;
2685
2686
0
    increment = PyLong_AsInt(arg);
2687
0
    if (increment == -1 && PyErr_Occurred()) {
2688
0
        goto exit;
2689
0
    }
2690
0
    return_value = os_nice_impl(module, increment);
2691
2692
0
exit:
2693
0
    return return_value;
2694
0
}
2695
2696
#endif /* defined(HAVE_NICE) */
2697
2698
#if defined(HAVE_GETPRIORITY)
2699
2700
PyDoc_STRVAR(os_getpriority__doc__,
2701
"getpriority($module, /, which, who)\n"
2702
"--\n"
2703
"\n"
2704
"Return program scheduling priority.");
2705
2706
#define OS_GETPRIORITY_METHODDEF    \
2707
    {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
2708
2709
static PyObject *
2710
os_getpriority_impl(PyObject *module, int which, int who);
2711
2712
static PyObject *
2713
os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2714
0
{
2715
0
    PyObject *return_value = NULL;
2716
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2717
2718
0
    #define NUM_KEYWORDS 2
2719
0
    static struct {
2720
0
        PyGC_Head _this_is_not_used;
2721
0
        PyObject_VAR_HEAD
2722
0
        Py_hash_t ob_hash;
2723
0
        PyObject *ob_item[NUM_KEYWORDS];
2724
0
    } _kwtuple = {
2725
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2726
0
        .ob_hash = -1,
2727
0
        .ob_item = { &_Py_ID(which), &_Py_ID(who), },
2728
0
    };
2729
0
    #undef NUM_KEYWORDS
2730
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2731
2732
    #else  // !Py_BUILD_CORE
2733
    #  define KWTUPLE NULL
2734
    #endif  // !Py_BUILD_CORE
2735
2736
0
    static const char * const _keywords[] = {"which", "who", NULL};
2737
0
    static _PyArg_Parser _parser = {
2738
0
        .keywords = _keywords,
2739
0
        .fname = "getpriority",
2740
0
        .kwtuple = KWTUPLE,
2741
0
    };
2742
0
    #undef KWTUPLE
2743
0
    PyObject *argsbuf[2];
2744
0
    int which;
2745
0
    int who;
2746
2747
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2748
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2749
0
    if (!args) {
2750
0
        goto exit;
2751
0
    }
2752
0
    which = PyLong_AsInt(args[0]);
2753
0
    if (which == -1 && PyErr_Occurred()) {
2754
0
        goto exit;
2755
0
    }
2756
0
    who = PyLong_AsInt(args[1]);
2757
0
    if (who == -1 && PyErr_Occurred()) {
2758
0
        goto exit;
2759
0
    }
2760
0
    return_value = os_getpriority_impl(module, which, who);
2761
2762
0
exit:
2763
0
    return return_value;
2764
0
}
2765
2766
#endif /* defined(HAVE_GETPRIORITY) */
2767
2768
#if defined(HAVE_SETPRIORITY)
2769
2770
PyDoc_STRVAR(os_setpriority__doc__,
2771
"setpriority($module, /, which, who, priority)\n"
2772
"--\n"
2773
"\n"
2774
"Set program scheduling priority.");
2775
2776
#define OS_SETPRIORITY_METHODDEF    \
2777
    {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
2778
2779
static PyObject *
2780
os_setpriority_impl(PyObject *module, int which, int who, int priority);
2781
2782
static PyObject *
2783
os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2784
0
{
2785
0
    PyObject *return_value = NULL;
2786
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2787
2788
0
    #define NUM_KEYWORDS 3
2789
0
    static struct {
2790
0
        PyGC_Head _this_is_not_used;
2791
0
        PyObject_VAR_HEAD
2792
0
        Py_hash_t ob_hash;
2793
0
        PyObject *ob_item[NUM_KEYWORDS];
2794
0
    } _kwtuple = {
2795
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2796
0
        .ob_hash = -1,
2797
0
        .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), },
2798
0
    };
2799
0
    #undef NUM_KEYWORDS
2800
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2801
2802
    #else  // !Py_BUILD_CORE
2803
    #  define KWTUPLE NULL
2804
    #endif  // !Py_BUILD_CORE
2805
2806
0
    static const char * const _keywords[] = {"which", "who", "priority", NULL};
2807
0
    static _PyArg_Parser _parser = {
2808
0
        .keywords = _keywords,
2809
0
        .fname = "setpriority",
2810
0
        .kwtuple = KWTUPLE,
2811
0
    };
2812
0
    #undef KWTUPLE
2813
0
    PyObject *argsbuf[3];
2814
0
    int which;
2815
0
    int who;
2816
0
    int priority;
2817
2818
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2819
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2820
0
    if (!args) {
2821
0
        goto exit;
2822
0
    }
2823
0
    which = PyLong_AsInt(args[0]);
2824
0
    if (which == -1 && PyErr_Occurred()) {
2825
0
        goto exit;
2826
0
    }
2827
0
    who = PyLong_AsInt(args[1]);
2828
0
    if (who == -1 && PyErr_Occurred()) {
2829
0
        goto exit;
2830
0
    }
2831
0
    priority = PyLong_AsInt(args[2]);
2832
0
    if (priority == -1 && PyErr_Occurred()) {
2833
0
        goto exit;
2834
0
    }
2835
0
    return_value = os_setpriority_impl(module, which, who, priority);
2836
2837
0
exit:
2838
0
    return return_value;
2839
0
}
2840
2841
#endif /* defined(HAVE_SETPRIORITY) */
2842
2843
PyDoc_STRVAR(os_rename__doc__,
2844
"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
2845
"--\n"
2846
"\n"
2847
"Rename a file or directory.\n"
2848
"\n"
2849
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
2850
"  descriptor open to a directory, and the respective path string (src or dst)\n"
2851
"  should be relative; the path will then be relative to that directory.\n"
2852
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
2853
"  If they are unavailable, using them will raise a NotImplementedError.");
2854
2855
#define OS_RENAME_METHODDEF    \
2856
    {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
2857
2858
static PyObject *
2859
os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
2860
               int dst_dir_fd);
2861
2862
static PyObject *
2863
os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2864
0
{
2865
0
    PyObject *return_value = NULL;
2866
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2867
2868
0
    #define NUM_KEYWORDS 4
2869
0
    static struct {
2870
0
        PyGC_Head _this_is_not_used;
2871
0
        PyObject_VAR_HEAD
2872
0
        Py_hash_t ob_hash;
2873
0
        PyObject *ob_item[NUM_KEYWORDS];
2874
0
    } _kwtuple = {
2875
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2876
0
        .ob_hash = -1,
2877
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
2878
0
    };
2879
0
    #undef NUM_KEYWORDS
2880
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2881
2882
    #else  // !Py_BUILD_CORE
2883
    #  define KWTUPLE NULL
2884
    #endif  // !Py_BUILD_CORE
2885
2886
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
2887
0
    static _PyArg_Parser _parser = {
2888
0
        .keywords = _keywords,
2889
0
        .fname = "rename",
2890
0
        .kwtuple = KWTUPLE,
2891
0
    };
2892
0
    #undef KWTUPLE
2893
0
    PyObject *argsbuf[4];
2894
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
2895
0
    path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0);
2896
0
    path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0);
2897
0
    int src_dir_fd = DEFAULT_DIR_FD;
2898
0
    int dst_dir_fd = DEFAULT_DIR_FD;
2899
2900
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2901
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2902
0
    if (!args) {
2903
0
        goto exit;
2904
0
    }
2905
0
    if (!path_converter(args[0], &src)) {
2906
0
        goto exit;
2907
0
    }
2908
0
    if (!path_converter(args[1], &dst)) {
2909
0
        goto exit;
2910
0
    }
2911
0
    if (!noptargs) {
2912
0
        goto skip_optional_kwonly;
2913
0
    }
2914
0
    if (args[2]) {
2915
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
2916
0
            goto exit;
2917
0
        }
2918
0
        if (!--noptargs) {
2919
0
            goto skip_optional_kwonly;
2920
0
        }
2921
0
    }
2922
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
2923
0
        goto exit;
2924
0
    }
2925
0
skip_optional_kwonly:
2926
0
    return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
2927
2928
0
exit:
2929
    /* Cleanup for src */
2930
0
    path_cleanup(&src);
2931
    /* Cleanup for dst */
2932
0
    path_cleanup(&dst);
2933
2934
0
    return return_value;
2935
0
}
2936
2937
PyDoc_STRVAR(os_replace__doc__,
2938
"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
2939
"--\n"
2940
"\n"
2941
"Rename a file or directory, overwriting the destination.\n"
2942
"\n"
2943
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
2944
"  descriptor open to a directory, and the respective path string (src or dst)\n"
2945
"  should be relative; the path will then be relative to that directory.\n"
2946
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
2947
"  If they are unavailable, using them will raise a NotImplementedError.");
2948
2949
#define OS_REPLACE_METHODDEF    \
2950
    {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
2951
2952
static PyObject *
2953
os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
2954
                int dst_dir_fd);
2955
2956
static PyObject *
2957
os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2958
0
{
2959
0
    PyObject *return_value = NULL;
2960
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2961
2962
0
    #define NUM_KEYWORDS 4
2963
0
    static struct {
2964
0
        PyGC_Head _this_is_not_used;
2965
0
        PyObject_VAR_HEAD
2966
0
        Py_hash_t ob_hash;
2967
0
        PyObject *ob_item[NUM_KEYWORDS];
2968
0
    } _kwtuple = {
2969
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2970
0
        .ob_hash = -1,
2971
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
2972
0
    };
2973
0
    #undef NUM_KEYWORDS
2974
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2975
2976
    #else  // !Py_BUILD_CORE
2977
    #  define KWTUPLE NULL
2978
    #endif  // !Py_BUILD_CORE
2979
2980
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
2981
0
    static _PyArg_Parser _parser = {
2982
0
        .keywords = _keywords,
2983
0
        .fname = "replace",
2984
0
        .kwtuple = KWTUPLE,
2985
0
    };
2986
0
    #undef KWTUPLE
2987
0
    PyObject *argsbuf[4];
2988
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
2989
0
    path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0);
2990
0
    path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0);
2991
0
    int src_dir_fd = DEFAULT_DIR_FD;
2992
0
    int dst_dir_fd = DEFAULT_DIR_FD;
2993
2994
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2995
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2996
0
    if (!args) {
2997
0
        goto exit;
2998
0
    }
2999
0
    if (!path_converter(args[0], &src)) {
3000
0
        goto exit;
3001
0
    }
3002
0
    if (!path_converter(args[1], &dst)) {
3003
0
        goto exit;
3004
0
    }
3005
0
    if (!noptargs) {
3006
0
        goto skip_optional_kwonly;
3007
0
    }
3008
0
    if (args[2]) {
3009
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
3010
0
            goto exit;
3011
0
        }
3012
0
        if (!--noptargs) {
3013
0
            goto skip_optional_kwonly;
3014
0
        }
3015
0
    }
3016
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
3017
0
        goto exit;
3018
0
    }
3019
0
skip_optional_kwonly:
3020
0
    return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
3021
3022
0
exit:
3023
    /* Cleanup for src */
3024
0
    path_cleanup(&src);
3025
    /* Cleanup for dst */
3026
0
    path_cleanup(&dst);
3027
3028
0
    return return_value;
3029
0
}
3030
3031
PyDoc_STRVAR(os_rmdir__doc__,
3032
"rmdir($module, /, path, *, dir_fd=None)\n"
3033
"--\n"
3034
"\n"
3035
"Remove a directory.\n"
3036
"\n"
3037
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3038
"  and path should be relative; path will then be relative to that directory.\n"
3039
"dir_fd may not be implemented on your platform.\n"
3040
"  If it is unavailable, using it will raise a NotImplementedError.");
3041
3042
#define OS_RMDIR_METHODDEF    \
3043
    {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
3044
3045
static PyObject *
3046
os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
3047
3048
static PyObject *
3049
os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3050
0
{
3051
0
    PyObject *return_value = NULL;
3052
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3053
3054
0
    #define NUM_KEYWORDS 2
3055
0
    static struct {
3056
0
        PyGC_Head _this_is_not_used;
3057
0
        PyObject_VAR_HEAD
3058
0
        Py_hash_t ob_hash;
3059
0
        PyObject *ob_item[NUM_KEYWORDS];
3060
0
    } _kwtuple = {
3061
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3062
0
        .ob_hash = -1,
3063
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3064
0
    };
3065
0
    #undef NUM_KEYWORDS
3066
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3067
3068
    #else  // !Py_BUILD_CORE
3069
    #  define KWTUPLE NULL
3070
    #endif  // !Py_BUILD_CORE
3071
3072
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3073
0
    static _PyArg_Parser _parser = {
3074
0
        .keywords = _keywords,
3075
0
        .fname = "rmdir",
3076
0
        .kwtuple = KWTUPLE,
3077
0
    };
3078
0
    #undef KWTUPLE
3079
0
    PyObject *argsbuf[2];
3080
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3081
0
    path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0);
3082
0
    int dir_fd = DEFAULT_DIR_FD;
3083
3084
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3085
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3086
0
    if (!args) {
3087
0
        goto exit;
3088
0
    }
3089
0
    if (!path_converter(args[0], &path)) {
3090
0
        goto exit;
3091
0
    }
3092
0
    if (!noptargs) {
3093
0
        goto skip_optional_kwonly;
3094
0
    }
3095
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3096
0
        goto exit;
3097
0
    }
3098
0
skip_optional_kwonly:
3099
0
    return_value = os_rmdir_impl(module, &path, dir_fd);
3100
3101
0
exit:
3102
    /* Cleanup for path */
3103
0
    path_cleanup(&path);
3104
3105
0
    return return_value;
3106
0
}
3107
3108
#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
3109
3110
PyDoc_STRVAR(os_system__doc__,
3111
"system($module, /, command)\n"
3112
"--\n"
3113
"\n"
3114
"Execute the command in a subshell.");
3115
3116
#define OS_SYSTEM_METHODDEF    \
3117
    {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3118
3119
static long
3120
os_system_impl(PyObject *module, const wchar_t *command);
3121
3122
static PyObject *
3123
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3124
{
3125
    PyObject *return_value = NULL;
3126
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3127
3128
    #define NUM_KEYWORDS 1
3129
    static struct {
3130
        PyGC_Head _this_is_not_used;
3131
        PyObject_VAR_HEAD
3132
        Py_hash_t ob_hash;
3133
        PyObject *ob_item[NUM_KEYWORDS];
3134
    } _kwtuple = {
3135
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3136
        .ob_hash = -1,
3137
        .ob_item = { &_Py_ID(command), },
3138
    };
3139
    #undef NUM_KEYWORDS
3140
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3141
3142
    #else  // !Py_BUILD_CORE
3143
    #  define KWTUPLE NULL
3144
    #endif  // !Py_BUILD_CORE
3145
3146
    static const char * const _keywords[] = {"command", NULL};
3147
    static _PyArg_Parser _parser = {
3148
        .keywords = _keywords,
3149
        .fname = "system",
3150
        .kwtuple = KWTUPLE,
3151
    };
3152
    #undef KWTUPLE
3153
    PyObject *argsbuf[1];
3154
    const wchar_t *command = NULL;
3155
    long _return_value;
3156
3157
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3158
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3159
    if (!args) {
3160
        goto exit;
3161
    }
3162
    if (!PyUnicode_Check(args[0])) {
3163
        _PyArg_BadArgument("system", "argument 'command'", "str", args[0]);
3164
        goto exit;
3165
    }
3166
    command = PyUnicode_AsWideCharString(args[0], NULL);
3167
    if (command == NULL) {
3168
        goto exit;
3169
    }
3170
    _return_value = os_system_impl(module, command);
3171
    if ((_return_value == -1) && PyErr_Occurred()) {
3172
        goto exit;
3173
    }
3174
    return_value = PyLong_FromLong(_return_value);
3175
3176
exit:
3177
    /* Cleanup for command */
3178
    PyMem_Free((void *)command);
3179
3180
    return return_value;
3181
}
3182
3183
#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
3184
3185
#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
3186
3187
PyDoc_STRVAR(os_system__doc__,
3188
"system($module, /, command)\n"
3189
"--\n"
3190
"\n"
3191
"Execute the command in a subshell.");
3192
3193
#define OS_SYSTEM_METHODDEF    \
3194
    {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3195
3196
static long
3197
os_system_impl(PyObject *module, PyObject *command);
3198
3199
static PyObject *
3200
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3201
0
{
3202
0
    PyObject *return_value = NULL;
3203
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3204
3205
0
    #define NUM_KEYWORDS 1
3206
0
    static struct {
3207
0
        PyGC_Head _this_is_not_used;
3208
0
        PyObject_VAR_HEAD
3209
0
        Py_hash_t ob_hash;
3210
0
        PyObject *ob_item[NUM_KEYWORDS];
3211
0
    } _kwtuple = {
3212
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3213
0
        .ob_hash = -1,
3214
0
        .ob_item = { &_Py_ID(command), },
3215
0
    };
3216
0
    #undef NUM_KEYWORDS
3217
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3218
3219
    #else  // !Py_BUILD_CORE
3220
    #  define KWTUPLE NULL
3221
    #endif  // !Py_BUILD_CORE
3222
3223
0
    static const char * const _keywords[] = {"command", NULL};
3224
0
    static _PyArg_Parser _parser = {
3225
0
        .keywords = _keywords,
3226
0
        .fname = "system",
3227
0
        .kwtuple = KWTUPLE,
3228
0
    };
3229
0
    #undef KWTUPLE
3230
0
    PyObject *argsbuf[1];
3231
0
    PyObject *command = NULL;
3232
0
    long _return_value;
3233
3234
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3235
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3236
0
    if (!args) {
3237
0
        goto exit;
3238
0
    }
3239
0
    if (!PyUnicode_FSConverter(args[0], &command)) {
3240
0
        goto exit;
3241
0
    }
3242
0
    _return_value = os_system_impl(module, command);
3243
0
    if ((_return_value == -1) && PyErr_Occurred()) {
3244
0
        goto exit;
3245
0
    }
3246
0
    return_value = PyLong_FromLong(_return_value);
3247
3248
0
exit:
3249
    /* Cleanup for command */
3250
0
    Py_XDECREF(command);
3251
3252
0
    return return_value;
3253
0
}
3254
3255
#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
3256
3257
#if defined(HAVE_UMASK)
3258
3259
PyDoc_STRVAR(os_umask__doc__,
3260
"umask($module, mask, /)\n"
3261
"--\n"
3262
"\n"
3263
"Set the current numeric umask and return the previous umask.");
3264
3265
#define OS_UMASK_METHODDEF    \
3266
    {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
3267
3268
static PyObject *
3269
os_umask_impl(PyObject *module, int mask);
3270
3271
static PyObject *
3272
os_umask(PyObject *module, PyObject *arg)
3273
0
{
3274
0
    PyObject *return_value = NULL;
3275
0
    int mask;
3276
3277
0
    mask = PyLong_AsInt(arg);
3278
0
    if (mask == -1 && PyErr_Occurred()) {
3279
0
        goto exit;
3280
0
    }
3281
0
    return_value = os_umask_impl(module, mask);
3282
3283
0
exit:
3284
0
    return return_value;
3285
0
}
3286
3287
#endif /* defined(HAVE_UMASK) */
3288
3289
PyDoc_STRVAR(os_unlink__doc__,
3290
"unlink($module, /, path, *, dir_fd=None)\n"
3291
"--\n"
3292
"\n"
3293
"Remove a file (same as remove()).\n"
3294
"\n"
3295
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3296
"  and path should be relative; path will then be relative to that directory.\n"
3297
"dir_fd may not be implemented on your platform.\n"
3298
"  If it is unavailable, using it will raise a NotImplementedError.");
3299
3300
#define OS_UNLINK_METHODDEF    \
3301
    {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
3302
3303
static PyObject *
3304
os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
3305
3306
static PyObject *
3307
os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3308
0
{
3309
0
    PyObject *return_value = NULL;
3310
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3311
3312
0
    #define NUM_KEYWORDS 2
3313
0
    static struct {
3314
0
        PyGC_Head _this_is_not_used;
3315
0
        PyObject_VAR_HEAD
3316
0
        Py_hash_t ob_hash;
3317
0
        PyObject *ob_item[NUM_KEYWORDS];
3318
0
    } _kwtuple = {
3319
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3320
0
        .ob_hash = -1,
3321
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3322
0
    };
3323
0
    #undef NUM_KEYWORDS
3324
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3325
3326
    #else  // !Py_BUILD_CORE
3327
    #  define KWTUPLE NULL
3328
    #endif  // !Py_BUILD_CORE
3329
3330
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3331
0
    static _PyArg_Parser _parser = {
3332
0
        .keywords = _keywords,
3333
0
        .fname = "unlink",
3334
0
        .kwtuple = KWTUPLE,
3335
0
    };
3336
0
    #undef KWTUPLE
3337
0
    PyObject *argsbuf[2];
3338
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3339
0
    path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0);
3340
0
    int dir_fd = DEFAULT_DIR_FD;
3341
3342
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3343
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3344
0
    if (!args) {
3345
0
        goto exit;
3346
0
    }
3347
0
    if (!path_converter(args[0], &path)) {
3348
0
        goto exit;
3349
0
    }
3350
0
    if (!noptargs) {
3351
0
        goto skip_optional_kwonly;
3352
0
    }
3353
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3354
0
        goto exit;
3355
0
    }
3356
0
skip_optional_kwonly:
3357
0
    return_value = os_unlink_impl(module, &path, dir_fd);
3358
3359
0
exit:
3360
    /* Cleanup for path */
3361
0
    path_cleanup(&path);
3362
3363
0
    return return_value;
3364
0
}
3365
3366
PyDoc_STRVAR(os_remove__doc__,
3367
"remove($module, /, path, *, dir_fd=None)\n"
3368
"--\n"
3369
"\n"
3370
"Remove a file (same as unlink()).\n"
3371
"\n"
3372
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3373
"  and path should be relative; path will then be relative to that directory.\n"
3374
"dir_fd may not be implemented on your platform.\n"
3375
"  If it is unavailable, using it will raise a NotImplementedError.");
3376
3377
#define OS_REMOVE_METHODDEF    \
3378
    {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
3379
3380
static PyObject *
3381
os_remove_impl(PyObject *module, path_t *path, int dir_fd);
3382
3383
static PyObject *
3384
os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3385
0
{
3386
0
    PyObject *return_value = NULL;
3387
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3388
3389
0
    #define NUM_KEYWORDS 2
3390
0
    static struct {
3391
0
        PyGC_Head _this_is_not_used;
3392
0
        PyObject_VAR_HEAD
3393
0
        Py_hash_t ob_hash;
3394
0
        PyObject *ob_item[NUM_KEYWORDS];
3395
0
    } _kwtuple = {
3396
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3397
0
        .ob_hash = -1,
3398
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3399
0
    };
3400
0
    #undef NUM_KEYWORDS
3401
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3402
3403
    #else  // !Py_BUILD_CORE
3404
    #  define KWTUPLE NULL
3405
    #endif  // !Py_BUILD_CORE
3406
3407
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3408
0
    static _PyArg_Parser _parser = {
3409
0
        .keywords = _keywords,
3410
0
        .fname = "remove",
3411
0
        .kwtuple = KWTUPLE,
3412
0
    };
3413
0
    #undef KWTUPLE
3414
0
    PyObject *argsbuf[2];
3415
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3416
0
    path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0);
3417
0
    int dir_fd = DEFAULT_DIR_FD;
3418
3419
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3420
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3421
0
    if (!args) {
3422
0
        goto exit;
3423
0
    }
3424
0
    if (!path_converter(args[0], &path)) {
3425
0
        goto exit;
3426
0
    }
3427
0
    if (!noptargs) {
3428
0
        goto skip_optional_kwonly;
3429
0
    }
3430
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3431
0
        goto exit;
3432
0
    }
3433
0
skip_optional_kwonly:
3434
0
    return_value = os_remove_impl(module, &path, dir_fd);
3435
3436
0
exit:
3437
    /* Cleanup for path */
3438
0
    path_cleanup(&path);
3439
3440
0
    return return_value;
3441
0
}
3442
3443
#if defined(HAVE_UNAME)
3444
3445
PyDoc_STRVAR(os_uname__doc__,
3446
"uname($module, /)\n"
3447
"--\n"
3448
"\n"
3449
"Return an object identifying the current operating system.\n"
3450
"\n"
3451
"The object behaves like a named tuple with the following fields:\n"
3452
"  (sysname, nodename, release, version, machine)");
3453
3454
#define OS_UNAME_METHODDEF    \
3455
    {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
3456
3457
static PyObject *
3458
os_uname_impl(PyObject *module);
3459
3460
static PyObject *
3461
os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
3462
0
{
3463
0
    return os_uname_impl(module);
3464
0
}
3465
3466
#endif /* defined(HAVE_UNAME) */
3467
3468
PyDoc_STRVAR(os_utime__doc__,
3469
"utime($module, /, path, times=None, *, ns=<unrepresentable>,\n"
3470
"      dir_fd=None, follow_symlinks=True)\n"
3471
"--\n"
3472
"\n"
3473
"Set the access and modified time of path.\n"
3474
"\n"
3475
"path may always be specified as a string.\n"
3476
"On some platforms, path may also be specified as an open file descriptor.\n"
3477
"  If this functionality is unavailable, using it raises an exception.\n"
3478
"\n"
3479
"If times is not None, it must be a tuple (atime, mtime);\n"
3480
"    atime and mtime should be expressed as float seconds since the epoch.\n"
3481
"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
3482
"    atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
3483
"    since the epoch.\n"
3484
"If times is None and ns is unspecified, utime uses the current time.\n"
3485
"Specifying tuples for both times and ns is an error.\n"
3486
"\n"
3487
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3488
"  and path should be relative; path will then be relative to that directory.\n"
3489
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
3490
"  link, utime will modify the symbolic link itself instead of the file the\n"
3491
"  link points to.\n"
3492
"It is an error to use dir_fd or follow_symlinks when specifying path\n"
3493
"  as an open file descriptor.\n"
3494
"dir_fd and follow_symlinks may not be available on your platform.\n"
3495
"  If they are unavailable, using them will raise a NotImplementedError.");
3496
3497
#define OS_UTIME_METHODDEF    \
3498
    {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
3499
3500
static PyObject *
3501
os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
3502
              int dir_fd, int follow_symlinks);
3503
3504
static PyObject *
3505
os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3506
0
{
3507
0
    PyObject *return_value = NULL;
3508
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3509
3510
0
    #define NUM_KEYWORDS 5
3511
0
    static struct {
3512
0
        PyGC_Head _this_is_not_used;
3513
0
        PyObject_VAR_HEAD
3514
0
        Py_hash_t ob_hash;
3515
0
        PyObject *ob_item[NUM_KEYWORDS];
3516
0
    } _kwtuple = {
3517
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3518
0
        .ob_hash = -1,
3519
0
        .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
3520
0
    };
3521
0
    #undef NUM_KEYWORDS
3522
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3523
3524
    #else  // !Py_BUILD_CORE
3525
    #  define KWTUPLE NULL
3526
    #endif  // !Py_BUILD_CORE
3527
3528
0
    static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
3529
0
    static _PyArg_Parser _parser = {
3530
0
        .keywords = _keywords,
3531
0
        .fname = "utime",
3532
0
        .kwtuple = KWTUPLE,
3533
0
    };
3534
0
    #undef KWTUPLE
3535
0
    PyObject *argsbuf[5];
3536
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3537
0
    path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD);
3538
0
    PyObject *times = Py_None;
3539
0
    PyObject *ns = NULL;
3540
0
    int dir_fd = DEFAULT_DIR_FD;
3541
0
    int follow_symlinks = 1;
3542
3543
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3544
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3545
0
    if (!args) {
3546
0
        goto exit;
3547
0
    }
3548
0
    if (!path_converter(args[0], &path)) {
3549
0
        goto exit;
3550
0
    }
3551
0
    if (!noptargs) {
3552
0
        goto skip_optional_pos;
3553
0
    }
3554
0
    if (args[1]) {
3555
0
        times = args[1];
3556
0
        if (!--noptargs) {
3557
0
            goto skip_optional_pos;
3558
0
        }
3559
0
    }
3560
0
skip_optional_pos:
3561
0
    if (!noptargs) {
3562
0
        goto skip_optional_kwonly;
3563
0
    }
3564
0
    if (args[2]) {
3565
0
        ns = args[2];
3566
0
        if (!--noptargs) {
3567
0
            goto skip_optional_kwonly;
3568
0
        }
3569
0
    }
3570
0
    if (args[3]) {
3571
0
        if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
3572
0
            goto exit;
3573
0
        }
3574
0
        if (!--noptargs) {
3575
0
            goto skip_optional_kwonly;
3576
0
        }
3577
0
    }
3578
0
    follow_symlinks = PyObject_IsTrue(args[4]);
3579
0
    if (follow_symlinks < 0) {
3580
0
        goto exit;
3581
0
    }
3582
0
skip_optional_kwonly:
3583
0
    return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
3584
3585
0
exit:
3586
    /* Cleanup for path */
3587
0
    path_cleanup(&path);
3588
3589
0
    return return_value;
3590
0
}
3591
3592
PyDoc_STRVAR(os__exit__doc__,
3593
"_exit($module, /, status)\n"
3594
"--\n"
3595
"\n"
3596
"Exit to the system with specified status, without normal exit processing.");
3597
3598
#define OS__EXIT_METHODDEF    \
3599
    {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
3600
3601
static PyObject *
3602
os__exit_impl(PyObject *module, int status);
3603
3604
static PyObject *
3605
os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3606
0
{
3607
0
    PyObject *return_value = NULL;
3608
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3609
3610
0
    #define NUM_KEYWORDS 1
3611
0
    static struct {
3612
0
        PyGC_Head _this_is_not_used;
3613
0
        PyObject_VAR_HEAD
3614
0
        Py_hash_t ob_hash;
3615
0
        PyObject *ob_item[NUM_KEYWORDS];
3616
0
    } _kwtuple = {
3617
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3618
0
        .ob_hash = -1,
3619
0
        .ob_item = { &_Py_ID(status), },
3620
0
    };
3621
0
    #undef NUM_KEYWORDS
3622
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3623
3624
    #else  // !Py_BUILD_CORE
3625
    #  define KWTUPLE NULL
3626
    #endif  // !Py_BUILD_CORE
3627
3628
0
    static const char * const _keywords[] = {"status", NULL};
3629
0
    static _PyArg_Parser _parser = {
3630
0
        .keywords = _keywords,
3631
0
        .fname = "_exit",
3632
0
        .kwtuple = KWTUPLE,
3633
0
    };
3634
0
    #undef KWTUPLE
3635
0
    PyObject *argsbuf[1];
3636
0
    int status;
3637
3638
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3639
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3640
0
    if (!args) {
3641
0
        goto exit;
3642
0
    }
3643
0
    status = PyLong_AsInt(args[0]);
3644
0
    if (status == -1 && PyErr_Occurred()) {
3645
0
        goto exit;
3646
0
    }
3647
0
    return_value = os__exit_impl(module, status);
3648
3649
0
exit:
3650
0
    return return_value;
3651
0
}
3652
3653
#if defined(HAVE_EXECV)
3654
3655
PyDoc_STRVAR(os_execv__doc__,
3656
"execv($module, path, argv, /)\n"
3657
"--\n"
3658
"\n"
3659
"Execute an executable path with arguments, replacing current process.\n"
3660
"\n"
3661
"  path\n"
3662
"    Path of executable file.\n"
3663
"  argv\n"
3664
"    Tuple or list of strings.");
3665
3666
#define OS_EXECV_METHODDEF    \
3667
    {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__},
3668
3669
static PyObject *
3670
os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
3671
3672
static PyObject *
3673
os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3674
0
{
3675
0
    PyObject *return_value = NULL;
3676
0
    path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0);
3677
0
    PyObject *argv;
3678
3679
0
    if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
3680
0
        goto exit;
3681
0
    }
3682
0
    if (!path_converter(args[0], &path)) {
3683
0
        goto exit;
3684
0
    }
3685
0
    argv = args[1];
3686
0
    return_value = os_execv_impl(module, &path, argv);
3687
3688
0
exit:
3689
    /* Cleanup for path */
3690
0
    path_cleanup(&path);
3691
3692
0
    return return_value;
3693
0
}
3694
3695
#endif /* defined(HAVE_EXECV) */
3696
3697
#if defined(HAVE_EXECV)
3698
3699
PyDoc_STRVAR(os_execve__doc__,
3700
"execve($module, /, path, argv, env)\n"
3701
"--\n"
3702
"\n"
3703
"Execute an executable path with arguments, replacing current process.\n"
3704
"\n"
3705
"  path\n"
3706
"    Path of executable file.\n"
3707
"  argv\n"
3708
"    Tuple or list of strings.\n"
3709
"  env\n"
3710
"    Dictionary of strings mapping to strings.");
3711
3712
#define OS_EXECVE_METHODDEF    \
3713
    {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
3714
3715
static PyObject *
3716
os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
3717
3718
static PyObject *
3719
os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3720
0
{
3721
0
    PyObject *return_value = NULL;
3722
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3723
3724
0
    #define NUM_KEYWORDS 3
3725
0
    static struct {
3726
0
        PyGC_Head _this_is_not_used;
3727
0
        PyObject_VAR_HEAD
3728
0
        Py_hash_t ob_hash;
3729
0
        PyObject *ob_item[NUM_KEYWORDS];
3730
0
    } _kwtuple = {
3731
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3732
0
        .ob_hash = -1,
3733
0
        .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), },
3734
0
    };
3735
0
    #undef NUM_KEYWORDS
3736
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3737
3738
    #else  // !Py_BUILD_CORE
3739
    #  define KWTUPLE NULL
3740
    #endif  // !Py_BUILD_CORE
3741
3742
0
    static const char * const _keywords[] = {"path", "argv", "env", NULL};
3743
0
    static _PyArg_Parser _parser = {
3744
0
        .keywords = _keywords,
3745
0
        .fname = "execve",
3746
0
        .kwtuple = KWTUPLE,
3747
0
    };
3748
0
    #undef KWTUPLE
3749
0
    PyObject *argsbuf[3];
3750
0
    path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE);
3751
0
    PyObject *argv;
3752
0
    PyObject *env;
3753
3754
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3755
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3756
0
    if (!args) {
3757
0
        goto exit;
3758
0
    }
3759
0
    if (!path_converter(args[0], &path)) {
3760
0
        goto exit;
3761
0
    }
3762
0
    argv = args[1];
3763
0
    env = args[2];
3764
0
    return_value = os_execve_impl(module, &path, argv, env);
3765
3766
0
exit:
3767
    /* Cleanup for path */
3768
0
    path_cleanup(&path);
3769
3770
0
    return return_value;
3771
0
}
3772
3773
#endif /* defined(HAVE_EXECV) */
3774
3775
#if defined(HAVE_POSIX_SPAWN)
3776
3777
PyDoc_STRVAR(os_posix_spawn__doc__,
3778
"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
3779
"            setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
3780
"            setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
3781
"--\n"
3782
"\n"
3783
"Execute the program specified by path in a new process.\n"
3784
"\n"
3785
"  path\n"
3786
"    Path of executable file.\n"
3787
"  argv\n"
3788
"    Tuple or list of strings.\n"
3789
"  env\n"
3790
"    Dictionary of strings mapping to strings.\n"
3791
"  file_actions\n"
3792
"    A sequence of file action tuples.\n"
3793
"  setpgroup\n"
3794
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
3795
"  resetids\n"
3796
"    If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
3797
"  setsid\n"
3798
"    If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
3799
"  setsigmask\n"
3800
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
3801
"  setsigdef\n"
3802
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
3803
"  scheduler\n"
3804
"    A tuple with the scheduler policy (optional) and parameters.");
3805
3806
#define OS_POSIX_SPAWN_METHODDEF    \
3807
    {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
3808
3809
static PyObject *
3810
os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
3811
                    PyObject *env, PyObject *file_actions,
3812
                    PyObject *setpgroup, int resetids, int setsid,
3813
                    PyObject *setsigmask, PyObject *setsigdef,
3814
                    PyObject *scheduler);
3815
3816
static PyObject *
3817
os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3818
0
{
3819
0
    PyObject *return_value = NULL;
3820
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3821
3822
0
    #define NUM_KEYWORDS 7
3823
0
    static struct {
3824
0
        PyGC_Head _this_is_not_used;
3825
0
        PyObject_VAR_HEAD
3826
0
        Py_hash_t ob_hash;
3827
0
        PyObject *ob_item[NUM_KEYWORDS];
3828
0
    } _kwtuple = {
3829
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3830
0
        .ob_hash = -1,
3831
0
        .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
3832
0
    };
3833
0
    #undef NUM_KEYWORDS
3834
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3835
3836
    #else  // !Py_BUILD_CORE
3837
    #  define KWTUPLE NULL
3838
    #endif  // !Py_BUILD_CORE
3839
3840
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
3841
0
    static _PyArg_Parser _parser = {
3842
0
        .keywords = _keywords,
3843
0
        .fname = "posix_spawn",
3844
0
        .kwtuple = KWTUPLE,
3845
0
    };
3846
0
    #undef KWTUPLE
3847
0
    PyObject *argsbuf[10];
3848
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
3849
0
    path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0);
3850
0
    PyObject *argv;
3851
0
    PyObject *env;
3852
0
    PyObject *file_actions = NULL;
3853
0
    PyObject *setpgroup = NULL;
3854
0
    int resetids = 0;
3855
0
    int setsid = 0;
3856
0
    PyObject *setsigmask = NULL;
3857
0
    PyObject *setsigdef = NULL;
3858
0
    PyObject *scheduler = NULL;
3859
3860
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3861
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3862
0
    if (!args) {
3863
0
        goto exit;
3864
0
    }
3865
0
    if (!path_converter(args[0], &path)) {
3866
0
        goto exit;
3867
0
    }
3868
0
    argv = args[1];
3869
0
    env = args[2];
3870
0
    if (!noptargs) {
3871
0
        goto skip_optional_kwonly;
3872
0
    }
3873
0
    if (args[3]) {
3874
0
        file_actions = args[3];
3875
0
        if (!--noptargs) {
3876
0
            goto skip_optional_kwonly;
3877
0
        }
3878
0
    }
3879
0
    if (args[4]) {
3880
0
        setpgroup = args[4];
3881
0
        if (!--noptargs) {
3882
0
            goto skip_optional_kwonly;
3883
0
        }
3884
0
    }
3885
0
    if (args[5]) {
3886
0
        resetids = PyObject_IsTrue(args[5]);
3887
0
        if (resetids < 0) {
3888
0
            goto exit;
3889
0
        }
3890
0
        if (!--noptargs) {
3891
0
            goto skip_optional_kwonly;
3892
0
        }
3893
0
    }
3894
0
    if (args[6]) {
3895
0
        setsid = PyObject_IsTrue(args[6]);
3896
0
        if (setsid < 0) {
3897
0
            goto exit;
3898
0
        }
3899
0
        if (!--noptargs) {
3900
0
            goto skip_optional_kwonly;
3901
0
        }
3902
0
    }
3903
0
    if (args[7]) {
3904
0
        setsigmask = args[7];
3905
0
        if (!--noptargs) {
3906
0
            goto skip_optional_kwonly;
3907
0
        }
3908
0
    }
3909
0
    if (args[8]) {
3910
0
        setsigdef = args[8];
3911
0
        if (!--noptargs) {
3912
0
            goto skip_optional_kwonly;
3913
0
        }
3914
0
    }
3915
0
    scheduler = args[9];
3916
0
skip_optional_kwonly:
3917
0
    return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
3918
3919
0
exit:
3920
    /* Cleanup for path */
3921
0
    path_cleanup(&path);
3922
3923
0
    return return_value;
3924
0
}
3925
3926
#endif /* defined(HAVE_POSIX_SPAWN) */
3927
3928
#if defined(HAVE_POSIX_SPAWNP)
3929
3930
PyDoc_STRVAR(os_posix_spawnp__doc__,
3931
"posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
3932
"             setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
3933
"             setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
3934
"--\n"
3935
"\n"
3936
"Execute the program specified by path in a new process.\n"
3937
"\n"
3938
"  path\n"
3939
"    Path of executable file.\n"
3940
"  argv\n"
3941
"    Tuple or list of strings.\n"
3942
"  env\n"
3943
"    Dictionary of strings mapping to strings.\n"
3944
"  file_actions\n"
3945
"    A sequence of file action tuples.\n"
3946
"  setpgroup\n"
3947
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
3948
"  resetids\n"
3949
"    If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
3950
"  setsid\n"
3951
"    If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
3952
"  setsigmask\n"
3953
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
3954
"  setsigdef\n"
3955
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
3956
"  scheduler\n"
3957
"    A tuple with the scheduler policy (optional) and parameters.");
3958
3959
#define OS_POSIX_SPAWNP_METHODDEF    \
3960
    {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
3961
3962
static PyObject *
3963
os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
3964
                     PyObject *env, PyObject *file_actions,
3965
                     PyObject *setpgroup, int resetids, int setsid,
3966
                     PyObject *setsigmask, PyObject *setsigdef,
3967
                     PyObject *scheduler);
3968
3969
static PyObject *
3970
os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3971
0
{
3972
0
    PyObject *return_value = NULL;
3973
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3974
3975
0
    #define NUM_KEYWORDS 7
3976
0
    static struct {
3977
0
        PyGC_Head _this_is_not_used;
3978
0
        PyObject_VAR_HEAD
3979
0
        Py_hash_t ob_hash;
3980
0
        PyObject *ob_item[NUM_KEYWORDS];
3981
0
    } _kwtuple = {
3982
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3983
0
        .ob_hash = -1,
3984
0
        .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
3985
0
    };
3986
0
    #undef NUM_KEYWORDS
3987
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3988
3989
    #else  // !Py_BUILD_CORE
3990
    #  define KWTUPLE NULL
3991
    #endif  // !Py_BUILD_CORE
3992
3993
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
3994
0
    static _PyArg_Parser _parser = {
3995
0
        .keywords = _keywords,
3996
0
        .fname = "posix_spawnp",
3997
0
        .kwtuple = KWTUPLE,
3998
0
    };
3999
0
    #undef KWTUPLE
4000
0
    PyObject *argsbuf[10];
4001
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
4002
0
    path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0);
4003
0
    PyObject *argv;
4004
0
    PyObject *env;
4005
0
    PyObject *file_actions = NULL;
4006
0
    PyObject *setpgroup = NULL;
4007
0
    int resetids = 0;
4008
0
    int setsid = 0;
4009
0
    PyObject *setsigmask = NULL;
4010
0
    PyObject *setsigdef = NULL;
4011
0
    PyObject *scheduler = NULL;
4012
4013
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4014
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4015
0
    if (!args) {
4016
0
        goto exit;
4017
0
    }
4018
0
    if (!path_converter(args[0], &path)) {
4019
0
        goto exit;
4020
0
    }
4021
0
    argv = args[1];
4022
0
    env = args[2];
4023
0
    if (!noptargs) {
4024
0
        goto skip_optional_kwonly;
4025
0
    }
4026
0
    if (args[3]) {
4027
0
        file_actions = args[3];
4028
0
        if (!--noptargs) {
4029
0
            goto skip_optional_kwonly;
4030
0
        }
4031
0
    }
4032
0
    if (args[4]) {
4033
0
        setpgroup = args[4];
4034
0
        if (!--noptargs) {
4035
0
            goto skip_optional_kwonly;
4036
0
        }
4037
0
    }
4038
0
    if (args[5]) {
4039
0
        resetids = PyObject_IsTrue(args[5]);
4040
0
        if (resetids < 0) {
4041
0
            goto exit;
4042
0
        }
4043
0
        if (!--noptargs) {
4044
0
            goto skip_optional_kwonly;
4045
0
        }
4046
0
    }
4047
0
    if (args[6]) {
4048
0
        setsid = PyObject_IsTrue(args[6]);
4049
0
        if (setsid < 0) {
4050
0
            goto exit;
4051
0
        }
4052
0
        if (!--noptargs) {
4053
0
            goto skip_optional_kwonly;
4054
0
        }
4055
0
    }
4056
0
    if (args[7]) {
4057
0
        setsigmask = args[7];
4058
0
        if (!--noptargs) {
4059
0
            goto skip_optional_kwonly;
4060
0
        }
4061
0
    }
4062
0
    if (args[8]) {
4063
0
        setsigdef = args[8];
4064
0
        if (!--noptargs) {
4065
0
            goto skip_optional_kwonly;
4066
0
        }
4067
0
    }
4068
0
    scheduler = args[9];
4069
0
skip_optional_kwonly:
4070
0
    return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
4071
4072
0
exit:
4073
    /* Cleanup for path */
4074
0
    path_cleanup(&path);
4075
4076
0
    return return_value;
4077
0
}
4078
4079
#endif /* defined(HAVE_POSIX_SPAWNP) */
4080
4081
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4082
4083
PyDoc_STRVAR(os_spawnv__doc__,
4084
"spawnv($module, mode, path, argv, /)\n"
4085
"--\n"
4086
"\n"
4087
"Execute the program specified by path in a new process.\n"
4088
"\n"
4089
"  mode\n"
4090
"    Mode of process creation.\n"
4091
"  path\n"
4092
"    Path of executable file.\n"
4093
"  argv\n"
4094
"    Tuple or list of strings.");
4095
4096
#define OS_SPAWNV_METHODDEF    \
4097
    {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__},
4098
4099
static PyObject *
4100
os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
4101
4102
static PyObject *
4103
os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4104
{
4105
    PyObject *return_value = NULL;
4106
    int mode;
4107
    path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0);
4108
    PyObject *argv;
4109
4110
    if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
4111
        goto exit;
4112
    }
4113
    mode = PyLong_AsInt(args[0]);
4114
    if (mode == -1 && PyErr_Occurred()) {
4115
        goto exit;
4116
    }
4117
    if (!path_converter(args[1], &path)) {
4118
        goto exit;
4119
    }
4120
    argv = args[2];
4121
    return_value = os_spawnv_impl(module, mode, &path, argv);
4122
4123
exit:
4124
    /* Cleanup for path */
4125
    path_cleanup(&path);
4126
4127
    return return_value;
4128
}
4129
4130
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4131
4132
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4133
4134
PyDoc_STRVAR(os_spawnve__doc__,
4135
"spawnve($module, mode, path, argv, env, /)\n"
4136
"--\n"
4137
"\n"
4138
"Execute the program specified by path in a new process.\n"
4139
"\n"
4140
"  mode\n"
4141
"    Mode of process creation.\n"
4142
"  path\n"
4143
"    Path of executable file.\n"
4144
"  argv\n"
4145
"    Tuple or list of strings.\n"
4146
"  env\n"
4147
"    Dictionary of strings mapping to strings.");
4148
4149
#define OS_SPAWNVE_METHODDEF    \
4150
    {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__},
4151
4152
static PyObject *
4153
os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
4154
                PyObject *env);
4155
4156
static PyObject *
4157
os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4158
{
4159
    PyObject *return_value = NULL;
4160
    int mode;
4161
    path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0);
4162
    PyObject *argv;
4163
    PyObject *env;
4164
4165
    if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
4166
        goto exit;
4167
    }
4168
    mode = PyLong_AsInt(args[0]);
4169
    if (mode == -1 && PyErr_Occurred()) {
4170
        goto exit;
4171
    }
4172
    if (!path_converter(args[1], &path)) {
4173
        goto exit;
4174
    }
4175
    argv = args[2];
4176
    env = args[3];
4177
    return_value = os_spawnve_impl(module, mode, &path, argv, env);
4178
4179
exit:
4180
    /* Cleanup for path */
4181
    path_cleanup(&path);
4182
4183
    return return_value;
4184
}
4185
4186
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4187
4188
#if defined(HAVE_FORK)
4189
4190
PyDoc_STRVAR(os_register_at_fork__doc__,
4191
"register_at_fork($module, /, *, before=<unrepresentable>,\n"
4192
"                 after_in_child=<unrepresentable>,\n"
4193
"                 after_in_parent=<unrepresentable>)\n"
4194
"--\n"
4195
"\n"
4196
"Register callables to be called when forking a new process.\n"
4197
"\n"
4198
"  before\n"
4199
"    A callable to be called in the parent before the fork() syscall.\n"
4200
"  after_in_child\n"
4201
"    A callable to be called in the child after fork().\n"
4202
"  after_in_parent\n"
4203
"    A callable to be called in the parent after fork().\n"
4204
"\n"
4205
"\'before\' callbacks are called in reverse order.\n"
4206
"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
4207
4208
#define OS_REGISTER_AT_FORK_METHODDEF    \
4209
    {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
4210
4211
static PyObject *
4212
os_register_at_fork_impl(PyObject *module, PyObject *before,
4213
                         PyObject *after_in_child, PyObject *after_in_parent);
4214
4215
static PyObject *
4216
os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4217
0
{
4218
0
    PyObject *return_value = NULL;
4219
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4220
4221
0
    #define NUM_KEYWORDS 3
4222
0
    static struct {
4223
0
        PyGC_Head _this_is_not_used;
4224
0
        PyObject_VAR_HEAD
4225
0
        Py_hash_t ob_hash;
4226
0
        PyObject *ob_item[NUM_KEYWORDS];
4227
0
    } _kwtuple = {
4228
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4229
0
        .ob_hash = -1,
4230
0
        .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), },
4231
0
    };
4232
0
    #undef NUM_KEYWORDS
4233
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4234
4235
    #else  // !Py_BUILD_CORE
4236
    #  define KWTUPLE NULL
4237
    #endif  // !Py_BUILD_CORE
4238
4239
0
    static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
4240
0
    static _PyArg_Parser _parser = {
4241
0
        .keywords = _keywords,
4242
0
        .fname = "register_at_fork",
4243
0
        .kwtuple = KWTUPLE,
4244
0
    };
4245
0
    #undef KWTUPLE
4246
0
    PyObject *argsbuf[3];
4247
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
4248
0
    PyObject *before = NULL;
4249
0
    PyObject *after_in_child = NULL;
4250
0
    PyObject *after_in_parent = NULL;
4251
4252
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4253
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4254
0
    if (!args) {
4255
0
        goto exit;
4256
0
    }
4257
0
    if (!noptargs) {
4258
0
        goto skip_optional_kwonly;
4259
0
    }
4260
0
    if (args[0]) {
4261
0
        before = args[0];
4262
0
        if (!--noptargs) {
4263
0
            goto skip_optional_kwonly;
4264
0
        }
4265
0
    }
4266
0
    if (args[1]) {
4267
0
        after_in_child = args[1];
4268
0
        if (!--noptargs) {
4269
0
            goto skip_optional_kwonly;
4270
0
        }
4271
0
    }
4272
0
    after_in_parent = args[2];
4273
0
skip_optional_kwonly:
4274
0
    return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
4275
4276
0
exit:
4277
0
    return return_value;
4278
0
}
4279
4280
#endif /* defined(HAVE_FORK) */
4281
4282
#if defined(HAVE_FORK1)
4283
4284
PyDoc_STRVAR(os_fork1__doc__,
4285
"fork1($module, /)\n"
4286
"--\n"
4287
"\n"
4288
"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
4289
"\n"
4290
"Return 0 to child process and PID of child to parent process.");
4291
4292
#define OS_FORK1_METHODDEF    \
4293
    {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
4294
4295
static PyObject *
4296
os_fork1_impl(PyObject *module);
4297
4298
static PyObject *
4299
os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
4300
{
4301
    return os_fork1_impl(module);
4302
}
4303
4304
#endif /* defined(HAVE_FORK1) */
4305
4306
#if defined(HAVE_FORK)
4307
4308
PyDoc_STRVAR(os_fork__doc__,
4309
"fork($module, /)\n"
4310
"--\n"
4311
"\n"
4312
"Fork a child process.\n"
4313
"\n"
4314
"Return 0 to child process and PID of child to parent process.");
4315
4316
#define OS_FORK_METHODDEF    \
4317
    {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
4318
4319
static PyObject *
4320
os_fork_impl(PyObject *module);
4321
4322
static PyObject *
4323
os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
4324
0
{
4325
0
    return os_fork_impl(module);
4326
0
}
4327
4328
#endif /* defined(HAVE_FORK) */
4329
4330
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4331
4332
PyDoc_STRVAR(os_sched_get_priority_max__doc__,
4333
"sched_get_priority_max($module, /, policy)\n"
4334
"--\n"
4335
"\n"
4336
"Get the maximum scheduling priority for policy.");
4337
4338
#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF    \
4339
    {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
4340
4341
static PyObject *
4342
os_sched_get_priority_max_impl(PyObject *module, int policy);
4343
4344
static PyObject *
4345
os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4346
0
{
4347
0
    PyObject *return_value = NULL;
4348
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4349
4350
0
    #define NUM_KEYWORDS 1
4351
0
    static struct {
4352
0
        PyGC_Head _this_is_not_used;
4353
0
        PyObject_VAR_HEAD
4354
0
        Py_hash_t ob_hash;
4355
0
        PyObject *ob_item[NUM_KEYWORDS];
4356
0
    } _kwtuple = {
4357
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4358
0
        .ob_hash = -1,
4359
0
        .ob_item = { &_Py_ID(policy), },
4360
0
    };
4361
0
    #undef NUM_KEYWORDS
4362
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4363
4364
    #else  // !Py_BUILD_CORE
4365
    #  define KWTUPLE NULL
4366
    #endif  // !Py_BUILD_CORE
4367
4368
0
    static const char * const _keywords[] = {"policy", NULL};
4369
0
    static _PyArg_Parser _parser = {
4370
0
        .keywords = _keywords,
4371
0
        .fname = "sched_get_priority_max",
4372
0
        .kwtuple = KWTUPLE,
4373
0
    };
4374
0
    #undef KWTUPLE
4375
0
    PyObject *argsbuf[1];
4376
0
    int policy;
4377
4378
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4379
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4380
0
    if (!args) {
4381
0
        goto exit;
4382
0
    }
4383
0
    policy = PyLong_AsInt(args[0]);
4384
0
    if (policy == -1 && PyErr_Occurred()) {
4385
0
        goto exit;
4386
0
    }
4387
0
    return_value = os_sched_get_priority_max_impl(module, policy);
4388
4389
0
exit:
4390
0
    return return_value;
4391
0
}
4392
4393
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4394
4395
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4396
4397
PyDoc_STRVAR(os_sched_get_priority_min__doc__,
4398
"sched_get_priority_min($module, /, policy)\n"
4399
"--\n"
4400
"\n"
4401
"Get the minimum scheduling priority for policy.");
4402
4403
#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF    \
4404
    {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
4405
4406
static PyObject *
4407
os_sched_get_priority_min_impl(PyObject *module, int policy);
4408
4409
static PyObject *
4410
os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4411
0
{
4412
0
    PyObject *return_value = NULL;
4413
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4414
4415
0
    #define NUM_KEYWORDS 1
4416
0
    static struct {
4417
0
        PyGC_Head _this_is_not_used;
4418
0
        PyObject_VAR_HEAD
4419
0
        Py_hash_t ob_hash;
4420
0
        PyObject *ob_item[NUM_KEYWORDS];
4421
0
    } _kwtuple = {
4422
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4423
0
        .ob_hash = -1,
4424
0
        .ob_item = { &_Py_ID(policy), },
4425
0
    };
4426
0
    #undef NUM_KEYWORDS
4427
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4428
4429
    #else  // !Py_BUILD_CORE
4430
    #  define KWTUPLE NULL
4431
    #endif  // !Py_BUILD_CORE
4432
4433
0
    static const char * const _keywords[] = {"policy", NULL};
4434
0
    static _PyArg_Parser _parser = {
4435
0
        .keywords = _keywords,
4436
0
        .fname = "sched_get_priority_min",
4437
0
        .kwtuple = KWTUPLE,
4438
0
    };
4439
0
    #undef KWTUPLE
4440
0
    PyObject *argsbuf[1];
4441
0
    int policy;
4442
4443
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4444
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4445
0
    if (!args) {
4446
0
        goto exit;
4447
0
    }
4448
0
    policy = PyLong_AsInt(args[0]);
4449
0
    if (policy == -1 && PyErr_Occurred()) {
4450
0
        goto exit;
4451
0
    }
4452
0
    return_value = os_sched_get_priority_min_impl(module, policy);
4453
4454
0
exit:
4455
0
    return return_value;
4456
0
}
4457
4458
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4459
4460
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4461
4462
PyDoc_STRVAR(os_sched_getscheduler__doc__,
4463
"sched_getscheduler($module, pid, /)\n"
4464
"--\n"
4465
"\n"
4466
"Get the scheduling policy for the process identified by pid.\n"
4467
"\n"
4468
"Passing 0 for pid returns the scheduling policy for the calling process.");
4469
4470
#define OS_SCHED_GETSCHEDULER_METHODDEF    \
4471
    {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
4472
4473
static PyObject *
4474
os_sched_getscheduler_impl(PyObject *module, pid_t pid);
4475
4476
static PyObject *
4477
os_sched_getscheduler(PyObject *module, PyObject *arg)
4478
0
{
4479
0
    PyObject *return_value = NULL;
4480
0
    pid_t pid;
4481
4482
0
    pid = PyLong_AsPid(arg);
4483
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4484
0
        goto exit;
4485
0
    }
4486
0
    return_value = os_sched_getscheduler_impl(module, pid);
4487
4488
0
exit:
4489
0
    return return_value;
4490
0
}
4491
4492
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4493
4494
#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
4495
4496
PyDoc_STRVAR(os_sched_param__doc__,
4497
"sched_param(sched_priority)\n"
4498
"--\n"
4499
"\n"
4500
"Currently has only one field: sched_priority\n"
4501
"\n"
4502
"  sched_priority\n"
4503
"    A scheduling parameter.");
4504
4505
static PyObject *
4506
os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
4507
4508
static PyObject *
4509
os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
4510
0
{
4511
0
    PyObject *return_value = NULL;
4512
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4513
4514
0
    #define NUM_KEYWORDS 1
4515
0
    static struct {
4516
0
        PyGC_Head _this_is_not_used;
4517
0
        PyObject_VAR_HEAD
4518
0
        Py_hash_t ob_hash;
4519
0
        PyObject *ob_item[NUM_KEYWORDS];
4520
0
    } _kwtuple = {
4521
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4522
0
        .ob_hash = -1,
4523
0
        .ob_item = { &_Py_ID(sched_priority), },
4524
0
    };
4525
0
    #undef NUM_KEYWORDS
4526
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4527
4528
    #else  // !Py_BUILD_CORE
4529
    #  define KWTUPLE NULL
4530
    #endif  // !Py_BUILD_CORE
4531
4532
0
    static const char * const _keywords[] = {"sched_priority", NULL};
4533
0
    static _PyArg_Parser _parser = {
4534
0
        .keywords = _keywords,
4535
0
        .fname = "sched_param",
4536
0
        .kwtuple = KWTUPLE,
4537
0
    };
4538
0
    #undef KWTUPLE
4539
0
    PyObject *argsbuf[1];
4540
0
    PyObject * const *fastargs;
4541
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
4542
0
    PyObject *sched_priority;
4543
4544
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
4545
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4546
0
    if (!fastargs) {
4547
0
        goto exit;
4548
0
    }
4549
0
    sched_priority = fastargs[0];
4550
0
    return_value = os_sched_param_impl(type, sched_priority);
4551
4552
0
exit:
4553
0
    return return_value;
4554
0
}
4555
4556
#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
4557
4558
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4559
4560
PyDoc_STRVAR(os_sched_setscheduler__doc__,
4561
"sched_setscheduler($module, pid, policy, param, /)\n"
4562
"--\n"
4563
"\n"
4564
"Set the scheduling policy for the process identified by pid.\n"
4565
"\n"
4566
"If pid is 0, the calling process is changed.\n"
4567
"param is an instance of sched_param.");
4568
4569
#define OS_SCHED_SETSCHEDULER_METHODDEF    \
4570
    {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__},
4571
4572
static PyObject *
4573
os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
4574
                           PyObject *param_obj);
4575
4576
static PyObject *
4577
os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4578
0
{
4579
0
    PyObject *return_value = NULL;
4580
0
    pid_t pid;
4581
0
    int policy;
4582
0
    PyObject *param_obj;
4583
4584
0
    if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) {
4585
0
        goto exit;
4586
0
    }
4587
0
    pid = PyLong_AsPid(args[0]);
4588
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4589
0
        goto exit;
4590
0
    }
4591
0
    policy = PyLong_AsInt(args[1]);
4592
0
    if (policy == -1 && PyErr_Occurred()) {
4593
0
        goto exit;
4594
0
    }
4595
0
    param_obj = args[2];
4596
0
    return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj);
4597
4598
0
exit:
4599
0
    return return_value;
4600
0
}
4601
4602
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4603
4604
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4605
4606
PyDoc_STRVAR(os_sched_getparam__doc__,
4607
"sched_getparam($module, pid, /)\n"
4608
"--\n"
4609
"\n"
4610
"Returns scheduling parameters for the process identified by pid.\n"
4611
"\n"
4612
"If pid is 0, returns parameters for the calling process.\n"
4613
"Return value is an instance of sched_param.");
4614
4615
#define OS_SCHED_GETPARAM_METHODDEF    \
4616
    {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
4617
4618
static PyObject *
4619
os_sched_getparam_impl(PyObject *module, pid_t pid);
4620
4621
static PyObject *
4622
os_sched_getparam(PyObject *module, PyObject *arg)
4623
0
{
4624
0
    PyObject *return_value = NULL;
4625
0
    pid_t pid;
4626
4627
0
    pid = PyLong_AsPid(arg);
4628
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4629
0
        goto exit;
4630
0
    }
4631
0
    return_value = os_sched_getparam_impl(module, pid);
4632
4633
0
exit:
4634
0
    return return_value;
4635
0
}
4636
4637
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4638
4639
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4640
4641
PyDoc_STRVAR(os_sched_setparam__doc__,
4642
"sched_setparam($module, pid, param, /)\n"
4643
"--\n"
4644
"\n"
4645
"Set scheduling parameters for the process identified by pid.\n"
4646
"\n"
4647
"If pid is 0, sets parameters for the calling process.\n"
4648
"param should be an instance of sched_param.");
4649
4650
#define OS_SCHED_SETPARAM_METHODDEF    \
4651
    {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__},
4652
4653
static PyObject *
4654
os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj);
4655
4656
static PyObject *
4657
os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4658
0
{
4659
0
    PyObject *return_value = NULL;
4660
0
    pid_t pid;
4661
0
    PyObject *param_obj;
4662
4663
0
    if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) {
4664
0
        goto exit;
4665
0
    }
4666
0
    pid = PyLong_AsPid(args[0]);
4667
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4668
0
        goto exit;
4669
0
    }
4670
0
    param_obj = args[1];
4671
0
    return_value = os_sched_setparam_impl(module, pid, param_obj);
4672
4673
0
exit:
4674
0
    return return_value;
4675
0
}
4676
4677
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4678
4679
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
4680
4681
PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
4682
"sched_rr_get_interval($module, pid, /)\n"
4683
"--\n"
4684
"\n"
4685
"Return the round-robin quantum for the process identified by pid, in seconds.\n"
4686
"\n"
4687
"Value returned is a float.");
4688
4689
#define OS_SCHED_RR_GET_INTERVAL_METHODDEF    \
4690
    {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
4691
4692
static double
4693
os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
4694
4695
static PyObject *
4696
os_sched_rr_get_interval(PyObject *module, PyObject *arg)
4697
0
{
4698
0
    PyObject *return_value = NULL;
4699
0
    pid_t pid;
4700
0
    double _return_value;
4701
4702
0
    pid = PyLong_AsPid(arg);
4703
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4704
0
        goto exit;
4705
0
    }
4706
0
    _return_value = os_sched_rr_get_interval_impl(module, pid);
4707
0
    if ((_return_value == -1.0) && PyErr_Occurred()) {
4708
0
        goto exit;
4709
0
    }
4710
0
    return_value = PyFloat_FromDouble(_return_value);
4711
4712
0
exit:
4713
0
    return return_value;
4714
0
}
4715
4716
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
4717
4718
#if defined(HAVE_SCHED_H)
4719
4720
PyDoc_STRVAR(os_sched_yield__doc__,
4721
"sched_yield($module, /)\n"
4722
"--\n"
4723
"\n"
4724
"Voluntarily relinquish the CPU.");
4725
4726
#define OS_SCHED_YIELD_METHODDEF    \
4727
    {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
4728
4729
static PyObject *
4730
os_sched_yield_impl(PyObject *module);
4731
4732
static PyObject *
4733
os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
4734
0
{
4735
0
    return os_sched_yield_impl(module);
4736
0
}
4737
4738
#endif /* defined(HAVE_SCHED_H) */
4739
4740
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4741
4742
PyDoc_STRVAR(os_sched_setaffinity__doc__,
4743
"sched_setaffinity($module, pid, mask, /)\n"
4744
"--\n"
4745
"\n"
4746
"Set the CPU affinity of the process identified by pid to mask.\n"
4747
"\n"
4748
"mask should be an iterable of integers identifying CPUs.");
4749
4750
#define OS_SCHED_SETAFFINITY_METHODDEF    \
4751
    {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__},
4752
4753
static PyObject *
4754
os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
4755
4756
static PyObject *
4757
os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4758
0
{
4759
0
    PyObject *return_value = NULL;
4760
0
    pid_t pid;
4761
0
    PyObject *mask;
4762
4763
0
    if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) {
4764
0
        goto exit;
4765
0
    }
4766
0
    pid = PyLong_AsPid(args[0]);
4767
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4768
0
        goto exit;
4769
0
    }
4770
0
    mask = args[1];
4771
0
    return_value = os_sched_setaffinity_impl(module, pid, mask);
4772
4773
0
exit:
4774
0
    return return_value;
4775
0
}
4776
4777
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4778
4779
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4780
4781
PyDoc_STRVAR(os_sched_getaffinity__doc__,
4782
"sched_getaffinity($module, pid, /)\n"
4783
"--\n"
4784
"\n"
4785
"Return the affinity of the process identified by pid (or the current process if zero).\n"
4786
"\n"
4787
"The affinity is returned as a set of CPU identifiers.");
4788
4789
#define OS_SCHED_GETAFFINITY_METHODDEF    \
4790
    {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
4791
4792
static PyObject *
4793
os_sched_getaffinity_impl(PyObject *module, pid_t pid);
4794
4795
static PyObject *
4796
os_sched_getaffinity(PyObject *module, PyObject *arg)
4797
0
{
4798
0
    PyObject *return_value = NULL;
4799
0
    pid_t pid;
4800
4801
0
    pid = PyLong_AsPid(arg);
4802
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4803
0
        goto exit;
4804
0
    }
4805
0
    return_value = os_sched_getaffinity_impl(module, pid);
4806
4807
0
exit:
4808
0
    return return_value;
4809
0
}
4810
4811
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4812
4813
#if defined(HAVE_POSIX_OPENPT)
4814
4815
PyDoc_STRVAR(os_posix_openpt__doc__,
4816
"posix_openpt($module, oflag, /)\n"
4817
"--\n"
4818
"\n"
4819
"Open and return a file descriptor for a master pseudo-terminal device.\n"
4820
"\n"
4821
"Performs a posix_openpt() C function call. The oflag argument is used to\n"
4822
"set file status flags and file access modes as specified in the manual page\n"
4823
"of posix_openpt() of your system.");
4824
4825
#define OS_POSIX_OPENPT_METHODDEF    \
4826
    {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__},
4827
4828
static int
4829
os_posix_openpt_impl(PyObject *module, int oflag);
4830
4831
static PyObject *
4832
os_posix_openpt(PyObject *module, PyObject *arg)
4833
0
{
4834
0
    PyObject *return_value = NULL;
4835
0
    int oflag;
4836
0
    int _return_value;
4837
4838
0
    oflag = PyLong_AsInt(arg);
4839
0
    if (oflag == -1 && PyErr_Occurred()) {
4840
0
        goto exit;
4841
0
    }
4842
0
    _return_value = os_posix_openpt_impl(module, oflag);
4843
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4844
0
        goto exit;
4845
0
    }
4846
0
    return_value = PyLong_FromLong((long)_return_value);
4847
4848
0
exit:
4849
0
    return return_value;
4850
0
}
4851
4852
#endif /* defined(HAVE_POSIX_OPENPT) */
4853
4854
#if defined(HAVE_GRANTPT)
4855
4856
PyDoc_STRVAR(os_grantpt__doc__,
4857
"grantpt($module, fd, /)\n"
4858
"--\n"
4859
"\n"
4860
"Grant access to the slave pseudo-terminal device.\n"
4861
"\n"
4862
"  fd\n"
4863
"    File descriptor of a master pseudo-terminal device.\n"
4864
"\n"
4865
"Performs a grantpt() C function call.");
4866
4867
#define OS_GRANTPT_METHODDEF    \
4868
    {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__},
4869
4870
static PyObject *
4871
os_grantpt_impl(PyObject *module, int fd);
4872
4873
static PyObject *
4874
os_grantpt(PyObject *module, PyObject *arg)
4875
0
{
4876
0
    PyObject *return_value = NULL;
4877
0
    int fd;
4878
4879
0
    fd = PyObject_AsFileDescriptor(arg);
4880
0
    if (fd < 0) {
4881
0
        goto exit;
4882
0
    }
4883
0
    return_value = os_grantpt_impl(module, fd);
4884
4885
0
exit:
4886
0
    return return_value;
4887
0
}
4888
4889
#endif /* defined(HAVE_GRANTPT) */
4890
4891
#if defined(HAVE_UNLOCKPT)
4892
4893
PyDoc_STRVAR(os_unlockpt__doc__,
4894
"unlockpt($module, fd, /)\n"
4895
"--\n"
4896
"\n"
4897
"Unlock a pseudo-terminal master/slave pair.\n"
4898
"\n"
4899
"  fd\n"
4900
"    File descriptor of a master pseudo-terminal device.\n"
4901
"\n"
4902
"Performs an unlockpt() C function call.");
4903
4904
#define OS_UNLOCKPT_METHODDEF    \
4905
    {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__},
4906
4907
static PyObject *
4908
os_unlockpt_impl(PyObject *module, int fd);
4909
4910
static PyObject *
4911
os_unlockpt(PyObject *module, PyObject *arg)
4912
0
{
4913
0
    PyObject *return_value = NULL;
4914
0
    int fd;
4915
4916
0
    fd = PyObject_AsFileDescriptor(arg);
4917
0
    if (fd < 0) {
4918
0
        goto exit;
4919
0
    }
4920
0
    return_value = os_unlockpt_impl(module, fd);
4921
4922
0
exit:
4923
0
    return return_value;
4924
0
}
4925
4926
#endif /* defined(HAVE_UNLOCKPT) */
4927
4928
#if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R))
4929
4930
PyDoc_STRVAR(os_ptsname__doc__,
4931
"ptsname($module, fd, /)\n"
4932
"--\n"
4933
"\n"
4934
"Return the name of the slave pseudo-terminal device.\n"
4935
"\n"
4936
"  fd\n"
4937
"    File descriptor of a master pseudo-terminal device.\n"
4938
"\n"
4939
"If the ptsname_r() C function is available, it is called;\n"
4940
"otherwise, performs a ptsname() C function call.");
4941
4942
#define OS_PTSNAME_METHODDEF    \
4943
    {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__},
4944
4945
static PyObject *
4946
os_ptsname_impl(PyObject *module, int fd);
4947
4948
static PyObject *
4949
os_ptsname(PyObject *module, PyObject *arg)
4950
0
{
4951
0
    PyObject *return_value = NULL;
4952
0
    int fd;
4953
4954
0
    fd = PyObject_AsFileDescriptor(arg);
4955
0
    if (fd < 0) {
4956
0
        goto exit;
4957
0
    }
4958
0
    return_value = os_ptsname_impl(module, fd);
4959
4960
0
exit:
4961
0
    return return_value;
4962
0
}
4963
4964
#endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */
4965
4966
#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
4967
4968
PyDoc_STRVAR(os_openpty__doc__,
4969
"openpty($module, /)\n"
4970
"--\n"
4971
"\n"
4972
"Open a pseudo-terminal.\n"
4973
"\n"
4974
"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
4975
"for both the master and slave ends.");
4976
4977
#define OS_OPENPTY_METHODDEF    \
4978
    {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
4979
4980
static PyObject *
4981
os_openpty_impl(PyObject *module);
4982
4983
static PyObject *
4984
os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
4985
0
{
4986
0
    return os_openpty_impl(module);
4987
0
}
4988
4989
#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
4990
4991
#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY))
4992
4993
PyDoc_STRVAR(os_login_tty__doc__,
4994
"login_tty($module, fd, /)\n"
4995
"--\n"
4996
"\n"
4997
"Prepare the tty of which fd is a file descriptor for a new login session.\n"
4998
"\n"
4999
"Make the calling process a session leader; make the tty the\n"
5000
"controlling tty, the stdin, the stdout, and the stderr of the\n"
5001
"calling process; close fd.");
5002
5003
#define OS_LOGIN_TTY_METHODDEF    \
5004
    {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__},
5005
5006
static PyObject *
5007
os_login_tty_impl(PyObject *module, int fd);
5008
5009
static PyObject *
5010
os_login_tty(PyObject *module, PyObject *arg)
5011
0
{
5012
0
    PyObject *return_value = NULL;
5013
0
    int fd;
5014
5015
0
    fd = PyObject_AsFileDescriptor(arg);
5016
0
    if (fd < 0) {
5017
0
        goto exit;
5018
0
    }
5019
0
    return_value = os_login_tty_impl(module, fd);
5020
5021
0
exit:
5022
0
    return return_value;
5023
0
}
5024
5025
#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */
5026
5027
#if defined(HAVE_FORKPTY)
5028
5029
PyDoc_STRVAR(os_forkpty__doc__,
5030
"forkpty($module, /)\n"
5031
"--\n"
5032
"\n"
5033
"Fork a new process with a new pseudo-terminal as controlling tty.\n"
5034
"\n"
5035
"Returns a tuple of (pid, master_fd).\n"
5036
"Like fork(), return pid of 0 to the child process,\n"
5037
"and pid of child to the parent process.\n"
5038
"To both, return fd of newly opened pseudo-terminal.\n"
5039
"The master_fd is non-inheritable.");
5040
5041
#define OS_FORKPTY_METHODDEF    \
5042
    {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
5043
5044
static PyObject *
5045
os_forkpty_impl(PyObject *module);
5046
5047
static PyObject *
5048
os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
5049
0
{
5050
0
    return os_forkpty_impl(module);
5051
0
}
5052
5053
#endif /* defined(HAVE_FORKPTY) */
5054
5055
#if defined(HAVE_GETEGID)
5056
5057
PyDoc_STRVAR(os_getegid__doc__,
5058
"getegid($module, /)\n"
5059
"--\n"
5060
"\n"
5061
"Return the current process\'s effective group id.");
5062
5063
#define OS_GETEGID_METHODDEF    \
5064
    {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
5065
5066
static PyObject *
5067
os_getegid_impl(PyObject *module);
5068
5069
static PyObject *
5070
os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
5071
22
{
5072
22
    return os_getegid_impl(module);
5073
22
}
5074
5075
#endif /* defined(HAVE_GETEGID) */
5076
5077
#if defined(HAVE_GETEUID)
5078
5079
PyDoc_STRVAR(os_geteuid__doc__,
5080
"geteuid($module, /)\n"
5081
"--\n"
5082
"\n"
5083
"Return the current process\'s effective user id.");
5084
5085
#define OS_GETEUID_METHODDEF    \
5086
    {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
5087
5088
static PyObject *
5089
os_geteuid_impl(PyObject *module);
5090
5091
static PyObject *
5092
os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5093
22
{
5094
22
    return os_geteuid_impl(module);
5095
22
}
5096
5097
#endif /* defined(HAVE_GETEUID) */
5098
5099
#if defined(HAVE_GETGID)
5100
5101
PyDoc_STRVAR(os_getgid__doc__,
5102
"getgid($module, /)\n"
5103
"--\n"
5104
"\n"
5105
"Return the current process\'s group id.");
5106
5107
#define OS_GETGID_METHODDEF    \
5108
    {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
5109
5110
static PyObject *
5111
os_getgid_impl(PyObject *module);
5112
5113
static PyObject *
5114
os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
5115
22
{
5116
22
    return os_getgid_impl(module);
5117
22
}
5118
5119
#endif /* defined(HAVE_GETGID) */
5120
5121
#if defined(HAVE_GETPID)
5122
5123
PyDoc_STRVAR(os_getpid__doc__,
5124
"getpid($module, /)\n"
5125
"--\n"
5126
"\n"
5127
"Return the current process id.");
5128
5129
#define OS_GETPID_METHODDEF    \
5130
    {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
5131
5132
static PyObject *
5133
os_getpid_impl(PyObject *module);
5134
5135
static PyObject *
5136
os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
5137
0
{
5138
0
    return os_getpid_impl(module);
5139
0
}
5140
5141
#endif /* defined(HAVE_GETPID) */
5142
5143
#if defined(HAVE_GETGROUPLIST) && defined(__APPLE__)
5144
5145
PyDoc_STRVAR(os_getgrouplist__doc__,
5146
"getgrouplist($module, user, group, /)\n"
5147
"--\n"
5148
"\n"
5149
"Returns a list of groups to which a user belongs.\n"
5150
"\n"
5151
"  user\n"
5152
"    username to lookup\n"
5153
"  group\n"
5154
"    base group id of the user");
5155
5156
#define OS_GETGROUPLIST_METHODDEF    \
5157
    {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5158
5159
static PyObject *
5160
os_getgrouplist_impl(PyObject *module, const char *user, int basegid);
5161
5162
static PyObject *
5163
os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5164
{
5165
    PyObject *return_value = NULL;
5166
    const char *user;
5167
    int basegid;
5168
5169
    if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5170
        goto exit;
5171
    }
5172
    if (!PyUnicode_Check(args[0])) {
5173
        _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5174
        goto exit;
5175
    }
5176
    Py_ssize_t user_length;
5177
    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5178
    if (user == NULL) {
5179
        goto exit;
5180
    }
5181
    if (strlen(user) != (size_t)user_length) {
5182
        PyErr_SetString(PyExc_ValueError, "embedded null character");
5183
        goto exit;
5184
    }
5185
    basegid = PyLong_AsInt(args[1]);
5186
    if (basegid == -1 && PyErr_Occurred()) {
5187
        goto exit;
5188
    }
5189
    return_value = os_getgrouplist_impl(module, user, basegid);
5190
5191
exit:
5192
    return return_value;
5193
}
5194
5195
#endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */
5196
5197
#if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__)
5198
5199
PyDoc_STRVAR(os_getgrouplist__doc__,
5200
"getgrouplist($module, user, group, /)\n"
5201
"--\n"
5202
"\n"
5203
"Returns a list of groups to which a user belongs.\n"
5204
"\n"
5205
"  user\n"
5206
"    username to lookup\n"
5207
"  group\n"
5208
"    base group id of the user");
5209
5210
#define OS_GETGROUPLIST_METHODDEF    \
5211
    {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5212
5213
static PyObject *
5214
os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid);
5215
5216
static PyObject *
5217
os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5218
0
{
5219
0
    PyObject *return_value = NULL;
5220
0
    const char *user;
5221
0
    gid_t basegid;
5222
5223
0
    if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5224
0
        goto exit;
5225
0
    }
5226
0
    if (!PyUnicode_Check(args[0])) {
5227
0
        _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5228
0
        goto exit;
5229
0
    }
5230
0
    Py_ssize_t user_length;
5231
0
    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5232
0
    if (user == NULL) {
5233
0
        goto exit;
5234
0
    }
5235
0
    if (strlen(user) != (size_t)user_length) {
5236
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
5237
0
        goto exit;
5238
0
    }
5239
0
    if (!_Py_Gid_Converter(args[1], &basegid)) {
5240
0
        goto exit;
5241
0
    }
5242
0
    return_value = os_getgrouplist_impl(module, user, basegid);
5243
5244
0
exit:
5245
0
    return return_value;
5246
0
}
5247
5248
#endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */
5249
5250
#if defined(HAVE_GETGROUPS)
5251
5252
PyDoc_STRVAR(os_getgroups__doc__,
5253
"getgroups($module, /)\n"
5254
"--\n"
5255
"\n"
5256
"Return list of supplemental group IDs for the process.");
5257
5258
#define OS_GETGROUPS_METHODDEF    \
5259
    {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
5260
5261
static PyObject *
5262
os_getgroups_impl(PyObject *module);
5263
5264
static PyObject *
5265
os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
5266
0
{
5267
0
    return os_getgroups_impl(module);
5268
0
}
5269
5270
#endif /* defined(HAVE_GETGROUPS) */
5271
5272
#if defined(HAVE_INITGROUPS) && defined(__APPLE__)
5273
5274
PyDoc_STRVAR(os_initgroups__doc__,
5275
"initgroups($module, username, gid, /)\n"
5276
"--\n"
5277
"\n"
5278
"Initialize the group access list.\n"
5279
"\n"
5280
"Call the system initgroups() to initialize the group access list with all of\n"
5281
"the groups of which the specified username is a member, plus the specified\n"
5282
"group id.");
5283
5284
#define OS_INITGROUPS_METHODDEF    \
5285
    {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5286
5287
static PyObject *
5288
os_initgroups_impl(PyObject *module, PyObject *oname, int gid);
5289
5290
static PyObject *
5291
os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5292
{
5293
    PyObject *return_value = NULL;
5294
    PyObject *oname = NULL;
5295
    int gid;
5296
5297
    if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5298
        goto exit;
5299
    }
5300
    if (!PyUnicode_FSConverter(args[0], &oname)) {
5301
        goto exit;
5302
    }
5303
    gid = PyLong_AsInt(args[1]);
5304
    if (gid == -1 && PyErr_Occurred()) {
5305
        goto exit;
5306
    }
5307
    return_value = os_initgroups_impl(module, oname, gid);
5308
5309
exit:
5310
    /* Cleanup for oname */
5311
    Py_XDECREF(oname);
5312
5313
    return return_value;
5314
}
5315
5316
#endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */
5317
5318
#if defined(HAVE_INITGROUPS) && !defined(__APPLE__)
5319
5320
PyDoc_STRVAR(os_initgroups__doc__,
5321
"initgroups($module, username, gid, /)\n"
5322
"--\n"
5323
"\n"
5324
"Initialize the group access list.\n"
5325
"\n"
5326
"Call the system initgroups() to initialize the group access list with all of\n"
5327
"the groups of which the specified username is a member, plus the specified\n"
5328
"group id.");
5329
5330
#define OS_INITGROUPS_METHODDEF    \
5331
    {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5332
5333
static PyObject *
5334
os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid);
5335
5336
static PyObject *
5337
os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5338
0
{
5339
0
    PyObject *return_value = NULL;
5340
0
    PyObject *oname = NULL;
5341
0
    gid_t gid;
5342
5343
0
    if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5344
0
        goto exit;
5345
0
    }
5346
0
    if (!PyUnicode_FSConverter(args[0], &oname)) {
5347
0
        goto exit;
5348
0
    }
5349
0
    if (!_Py_Gid_Converter(args[1], &gid)) {
5350
0
        goto exit;
5351
0
    }
5352
0
    return_value = os_initgroups_impl(module, oname, gid);
5353
5354
0
exit:
5355
    /* Cleanup for oname */
5356
0
    Py_XDECREF(oname);
5357
5358
0
    return return_value;
5359
0
}
5360
5361
#endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */
5362
5363
#if defined(HAVE_GETPGID)
5364
5365
PyDoc_STRVAR(os_getpgid__doc__,
5366
"getpgid($module, /, pid)\n"
5367
"--\n"
5368
"\n"
5369
"Call the system call getpgid(), and return the result.");
5370
5371
#define OS_GETPGID_METHODDEF    \
5372
    {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
5373
5374
static PyObject *
5375
os_getpgid_impl(PyObject *module, pid_t pid);
5376
5377
static PyObject *
5378
os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5379
0
{
5380
0
    PyObject *return_value = NULL;
5381
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5382
5383
0
    #define NUM_KEYWORDS 1
5384
0
    static struct {
5385
0
        PyGC_Head _this_is_not_used;
5386
0
        PyObject_VAR_HEAD
5387
0
        Py_hash_t ob_hash;
5388
0
        PyObject *ob_item[NUM_KEYWORDS];
5389
0
    } _kwtuple = {
5390
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5391
0
        .ob_hash = -1,
5392
0
        .ob_item = { &_Py_ID(pid), },
5393
0
    };
5394
0
    #undef NUM_KEYWORDS
5395
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5396
5397
    #else  // !Py_BUILD_CORE
5398
    #  define KWTUPLE NULL
5399
    #endif  // !Py_BUILD_CORE
5400
5401
0
    static const char * const _keywords[] = {"pid", NULL};
5402
0
    static _PyArg_Parser _parser = {
5403
0
        .keywords = _keywords,
5404
0
        .fname = "getpgid",
5405
0
        .kwtuple = KWTUPLE,
5406
0
    };
5407
0
    #undef KWTUPLE
5408
0
    PyObject *argsbuf[1];
5409
0
    pid_t pid;
5410
5411
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
5412
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
5413
0
    if (!args) {
5414
0
        goto exit;
5415
0
    }
5416
0
    pid = PyLong_AsPid(args[0]);
5417
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5418
0
        goto exit;
5419
0
    }
5420
0
    return_value = os_getpgid_impl(module, pid);
5421
5422
0
exit:
5423
0
    return return_value;
5424
0
}
5425
5426
#endif /* defined(HAVE_GETPGID) */
5427
5428
#if defined(HAVE_GETPGRP)
5429
5430
PyDoc_STRVAR(os_getpgrp__doc__,
5431
"getpgrp($module, /)\n"
5432
"--\n"
5433
"\n"
5434
"Return the current process group id.");
5435
5436
#define OS_GETPGRP_METHODDEF    \
5437
    {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
5438
5439
static PyObject *
5440
os_getpgrp_impl(PyObject *module);
5441
5442
static PyObject *
5443
os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5444
0
{
5445
0
    return os_getpgrp_impl(module);
5446
0
}
5447
5448
#endif /* defined(HAVE_GETPGRP) */
5449
5450
#if defined(HAVE_SETPGRP)
5451
5452
PyDoc_STRVAR(os_setpgrp__doc__,
5453
"setpgrp($module, /)\n"
5454
"--\n"
5455
"\n"
5456
"Make the current process the leader of its process group.");
5457
5458
#define OS_SETPGRP_METHODDEF    \
5459
    {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
5460
5461
static PyObject *
5462
os_setpgrp_impl(PyObject *module);
5463
5464
static PyObject *
5465
os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5466
0
{
5467
0
    return os_setpgrp_impl(module);
5468
0
}
5469
5470
#endif /* defined(HAVE_SETPGRP) */
5471
5472
#if defined(HAVE_GETPPID)
5473
5474
PyDoc_STRVAR(os_getppid__doc__,
5475
"getppid($module, /)\n"
5476
"--\n"
5477
"\n"
5478
"Return the parent\'s process id.\n"
5479
"\n"
5480
"If the parent process has already exited, Windows machines will still\n"
5481
"return its id; others systems will return the id of the \'init\' process (1).");
5482
5483
#define OS_GETPPID_METHODDEF    \
5484
    {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
5485
5486
static PyObject *
5487
os_getppid_impl(PyObject *module);
5488
5489
static PyObject *
5490
os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
5491
0
{
5492
0
    return os_getppid_impl(module);
5493
0
}
5494
5495
#endif /* defined(HAVE_GETPPID) */
5496
5497
#if defined(HAVE_GETLOGIN)
5498
5499
PyDoc_STRVAR(os_getlogin__doc__,
5500
"getlogin($module, /)\n"
5501
"--\n"
5502
"\n"
5503
"Return the actual login name.");
5504
5505
#define OS_GETLOGIN_METHODDEF    \
5506
    {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
5507
5508
static PyObject *
5509
os_getlogin_impl(PyObject *module);
5510
5511
static PyObject *
5512
os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
5513
0
{
5514
0
    return os_getlogin_impl(module);
5515
0
}
5516
5517
#endif /* defined(HAVE_GETLOGIN) */
5518
5519
#if defined(HAVE_GETUID)
5520
5521
PyDoc_STRVAR(os_getuid__doc__,
5522
"getuid($module, /)\n"
5523
"--\n"
5524
"\n"
5525
"Return the current process\'s user id.");
5526
5527
#define OS_GETUID_METHODDEF    \
5528
    {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
5529
5530
static PyObject *
5531
os_getuid_impl(PyObject *module);
5532
5533
static PyObject *
5534
os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5535
22
{
5536
22
    return os_getuid_impl(module);
5537
22
}
5538
5539
#endif /* defined(HAVE_GETUID) */
5540
5541
#if defined(HAVE_KILL)
5542
5543
PyDoc_STRVAR(os_kill__doc__,
5544
"kill($module, pid, signal, /)\n"
5545
"--\n"
5546
"\n"
5547
"Kill a process with a signal.");
5548
5549
#define OS_KILL_METHODDEF    \
5550
    {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__},
5551
5552
static PyObject *
5553
os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
5554
5555
static PyObject *
5556
os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5557
0
{
5558
0
    PyObject *return_value = NULL;
5559
0
    pid_t pid;
5560
0
    Py_ssize_t signal;
5561
5562
0
    if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) {
5563
0
        goto exit;
5564
0
    }
5565
0
    pid = PyLong_AsPid(args[0]);
5566
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5567
0
        goto exit;
5568
0
    }
5569
0
    {
5570
0
        Py_ssize_t ival = -1;
5571
0
        PyObject *iobj = _PyNumber_Index(args[1]);
5572
0
        if (iobj != NULL) {
5573
0
            ival = PyLong_AsSsize_t(iobj);
5574
0
            Py_DECREF(iobj);
5575
0
        }
5576
0
        if (ival == -1 && PyErr_Occurred()) {
5577
0
            goto exit;
5578
0
        }
5579
0
        signal = ival;
5580
0
    }
5581
0
    return_value = os_kill_impl(module, pid, signal);
5582
5583
0
exit:
5584
0
    return return_value;
5585
0
}
5586
5587
#endif /* defined(HAVE_KILL) */
5588
5589
#if defined(HAVE_KILLPG)
5590
5591
PyDoc_STRVAR(os_killpg__doc__,
5592
"killpg($module, pgid, signal, /)\n"
5593
"--\n"
5594
"\n"
5595
"Kill a process group with a signal.");
5596
5597
#define OS_KILLPG_METHODDEF    \
5598
    {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__},
5599
5600
static PyObject *
5601
os_killpg_impl(PyObject *module, pid_t pgid, int signal);
5602
5603
static PyObject *
5604
os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5605
0
{
5606
0
    PyObject *return_value = NULL;
5607
0
    pid_t pgid;
5608
0
    int signal;
5609
5610
0
    if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) {
5611
0
        goto exit;
5612
0
    }
5613
0
    pgid = PyLong_AsPid(args[0]);
5614
0
    if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
5615
0
        goto exit;
5616
0
    }
5617
0
    signal = PyLong_AsInt(args[1]);
5618
0
    if (signal == -1 && PyErr_Occurred()) {
5619
0
        goto exit;
5620
0
    }
5621
0
    return_value = os_killpg_impl(module, pgid, signal);
5622
5623
0
exit:
5624
0
    return return_value;
5625
0
}
5626
5627
#endif /* defined(HAVE_KILLPG) */
5628
5629
#if defined(HAVE_PLOCK)
5630
5631
PyDoc_STRVAR(os_plock__doc__,
5632
"plock($module, op, /)\n"
5633
"--\n"
5634
"\n"
5635
"Lock program segments into memory.\");");
5636
5637
#define OS_PLOCK_METHODDEF    \
5638
    {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
5639
5640
static PyObject *
5641
os_plock_impl(PyObject *module, int op);
5642
5643
static PyObject *
5644
os_plock(PyObject *module, PyObject *arg)
5645
{
5646
    PyObject *return_value = NULL;
5647
    int op;
5648
5649
    op = PyLong_AsInt(arg);
5650
    if (op == -1 && PyErr_Occurred()) {
5651
        goto exit;
5652
    }
5653
    return_value = os_plock_impl(module, op);
5654
5655
exit:
5656
    return return_value;
5657
}
5658
5659
#endif /* defined(HAVE_PLOCK) */
5660
5661
#if defined(HAVE_SETUID)
5662
5663
PyDoc_STRVAR(os_setuid__doc__,
5664
"setuid($module, uid, /)\n"
5665
"--\n"
5666
"\n"
5667
"Set the current process\'s user id.");
5668
5669
#define OS_SETUID_METHODDEF    \
5670
    {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
5671
5672
static PyObject *
5673
os_setuid_impl(PyObject *module, uid_t uid);
5674
5675
static PyObject *
5676
os_setuid(PyObject *module, PyObject *arg)
5677
0
{
5678
0
    PyObject *return_value = NULL;
5679
0
    uid_t uid;
5680
5681
0
    if (!_Py_Uid_Converter(arg, &uid)) {
5682
0
        goto exit;
5683
0
    }
5684
0
    return_value = os_setuid_impl(module, uid);
5685
5686
0
exit:
5687
0
    return return_value;
5688
0
}
5689
5690
#endif /* defined(HAVE_SETUID) */
5691
5692
#if defined(HAVE_SETEUID)
5693
5694
PyDoc_STRVAR(os_seteuid__doc__,
5695
"seteuid($module, euid, /)\n"
5696
"--\n"
5697
"\n"
5698
"Set the current process\'s effective user id.");
5699
5700
#define OS_SETEUID_METHODDEF    \
5701
    {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
5702
5703
static PyObject *
5704
os_seteuid_impl(PyObject *module, uid_t euid);
5705
5706
static PyObject *
5707
os_seteuid(PyObject *module, PyObject *arg)
5708
0
{
5709
0
    PyObject *return_value = NULL;
5710
0
    uid_t euid;
5711
5712
0
    if (!_Py_Uid_Converter(arg, &euid)) {
5713
0
        goto exit;
5714
0
    }
5715
0
    return_value = os_seteuid_impl(module, euid);
5716
5717
0
exit:
5718
0
    return return_value;
5719
0
}
5720
5721
#endif /* defined(HAVE_SETEUID) */
5722
5723
#if defined(HAVE_SETEGID)
5724
5725
PyDoc_STRVAR(os_setegid__doc__,
5726
"setegid($module, egid, /)\n"
5727
"--\n"
5728
"\n"
5729
"Set the current process\'s effective group id.");
5730
5731
#define OS_SETEGID_METHODDEF    \
5732
    {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
5733
5734
static PyObject *
5735
os_setegid_impl(PyObject *module, gid_t egid);
5736
5737
static PyObject *
5738
os_setegid(PyObject *module, PyObject *arg)
5739
0
{
5740
0
    PyObject *return_value = NULL;
5741
0
    gid_t egid;
5742
5743
0
    if (!_Py_Gid_Converter(arg, &egid)) {
5744
0
        goto exit;
5745
0
    }
5746
0
    return_value = os_setegid_impl(module, egid);
5747
5748
0
exit:
5749
0
    return return_value;
5750
0
}
5751
5752
#endif /* defined(HAVE_SETEGID) */
5753
5754
#if defined(HAVE_SETREUID)
5755
5756
PyDoc_STRVAR(os_setreuid__doc__,
5757
"setreuid($module, ruid, euid, /)\n"
5758
"--\n"
5759
"\n"
5760
"Set the current process\'s real and effective user ids.");
5761
5762
#define OS_SETREUID_METHODDEF    \
5763
    {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__},
5764
5765
static PyObject *
5766
os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
5767
5768
static PyObject *
5769
os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5770
0
{
5771
0
    PyObject *return_value = NULL;
5772
0
    uid_t ruid;
5773
0
    uid_t euid;
5774
5775
0
    if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
5776
0
        goto exit;
5777
0
    }
5778
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
5779
0
        goto exit;
5780
0
    }
5781
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
5782
0
        goto exit;
5783
0
    }
5784
0
    return_value = os_setreuid_impl(module, ruid, euid);
5785
5786
0
exit:
5787
0
    return return_value;
5788
0
}
5789
5790
#endif /* defined(HAVE_SETREUID) */
5791
5792
#if defined(HAVE_SETREGID)
5793
5794
PyDoc_STRVAR(os_setregid__doc__,
5795
"setregid($module, rgid, egid, /)\n"
5796
"--\n"
5797
"\n"
5798
"Set the current process\'s real and effective group ids.");
5799
5800
#define OS_SETREGID_METHODDEF    \
5801
    {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__},
5802
5803
static PyObject *
5804
os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
5805
5806
static PyObject *
5807
os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5808
0
{
5809
0
    PyObject *return_value = NULL;
5810
0
    gid_t rgid;
5811
0
    gid_t egid;
5812
5813
0
    if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
5814
0
        goto exit;
5815
0
    }
5816
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
5817
0
        goto exit;
5818
0
    }
5819
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
5820
0
        goto exit;
5821
0
    }
5822
0
    return_value = os_setregid_impl(module, rgid, egid);
5823
5824
0
exit:
5825
0
    return return_value;
5826
0
}
5827
5828
#endif /* defined(HAVE_SETREGID) */
5829
5830
#if defined(HAVE_SETGID)
5831
5832
PyDoc_STRVAR(os_setgid__doc__,
5833
"setgid($module, gid, /)\n"
5834
"--\n"
5835
"\n"
5836
"Set the current process\'s group id.");
5837
5838
#define OS_SETGID_METHODDEF    \
5839
    {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
5840
5841
static PyObject *
5842
os_setgid_impl(PyObject *module, gid_t gid);
5843
5844
static PyObject *
5845
os_setgid(PyObject *module, PyObject *arg)
5846
0
{
5847
0
    PyObject *return_value = NULL;
5848
0
    gid_t gid;
5849
5850
0
    if (!_Py_Gid_Converter(arg, &gid)) {
5851
0
        goto exit;
5852
0
    }
5853
0
    return_value = os_setgid_impl(module, gid);
5854
5855
0
exit:
5856
0
    return return_value;
5857
0
}
5858
5859
#endif /* defined(HAVE_SETGID) */
5860
5861
#if defined(HAVE_SETGROUPS)
5862
5863
PyDoc_STRVAR(os_setgroups__doc__,
5864
"setgroups($module, groups, /)\n"
5865
"--\n"
5866
"\n"
5867
"Set the groups of the current process to list.");
5868
5869
#define OS_SETGROUPS_METHODDEF    \
5870
    {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
5871
5872
#endif /* defined(HAVE_SETGROUPS) */
5873
5874
#if defined(HAVE_WAIT3)
5875
5876
PyDoc_STRVAR(os_wait3__doc__,
5877
"wait3($module, /, options)\n"
5878
"--\n"
5879
"\n"
5880
"Wait for completion of a child process.\n"
5881
"\n"
5882
"Returns a tuple of information about the child process:\n"
5883
"  (pid, status, rusage)");
5884
5885
#define OS_WAIT3_METHODDEF    \
5886
    {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
5887
5888
static PyObject *
5889
os_wait3_impl(PyObject *module, int options);
5890
5891
static PyObject *
5892
os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5893
0
{
5894
0
    PyObject *return_value = NULL;
5895
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5896
5897
0
    #define NUM_KEYWORDS 1
5898
0
    static struct {
5899
0
        PyGC_Head _this_is_not_used;
5900
0
        PyObject_VAR_HEAD
5901
0
        Py_hash_t ob_hash;
5902
0
        PyObject *ob_item[NUM_KEYWORDS];
5903
0
    } _kwtuple = {
5904
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5905
0
        .ob_hash = -1,
5906
0
        .ob_item = { &_Py_ID(options), },
5907
0
    };
5908
0
    #undef NUM_KEYWORDS
5909
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5910
5911
    #else  // !Py_BUILD_CORE
5912
    #  define KWTUPLE NULL
5913
    #endif  // !Py_BUILD_CORE
5914
5915
0
    static const char * const _keywords[] = {"options", NULL};
5916
0
    static _PyArg_Parser _parser = {
5917
0
        .keywords = _keywords,
5918
0
        .fname = "wait3",
5919
0
        .kwtuple = KWTUPLE,
5920
0
    };
5921
0
    #undef KWTUPLE
5922
0
    PyObject *argsbuf[1];
5923
0
    int options;
5924
5925
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
5926
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
5927
0
    if (!args) {
5928
0
        goto exit;
5929
0
    }
5930
0
    options = PyLong_AsInt(args[0]);
5931
0
    if (options == -1 && PyErr_Occurred()) {
5932
0
        goto exit;
5933
0
    }
5934
0
    return_value = os_wait3_impl(module, options);
5935
5936
0
exit:
5937
0
    return return_value;
5938
0
}
5939
5940
#endif /* defined(HAVE_WAIT3) */
5941
5942
#if defined(HAVE_WAIT4)
5943
5944
PyDoc_STRVAR(os_wait4__doc__,
5945
"wait4($module, /, pid, options)\n"
5946
"--\n"
5947
"\n"
5948
"Wait for completion of a specific child process.\n"
5949
"\n"
5950
"Returns a tuple of information about the child process:\n"
5951
"  (pid, status, rusage)");
5952
5953
#define OS_WAIT4_METHODDEF    \
5954
    {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
5955
5956
static PyObject *
5957
os_wait4_impl(PyObject *module, pid_t pid, int options);
5958
5959
static PyObject *
5960
os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5961
0
{
5962
0
    PyObject *return_value = NULL;
5963
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5964
5965
0
    #define NUM_KEYWORDS 2
5966
0
    static struct {
5967
0
        PyGC_Head _this_is_not_used;
5968
0
        PyObject_VAR_HEAD
5969
0
        Py_hash_t ob_hash;
5970
0
        PyObject *ob_item[NUM_KEYWORDS];
5971
0
    } _kwtuple = {
5972
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5973
0
        .ob_hash = -1,
5974
0
        .ob_item = { &_Py_ID(pid), &_Py_ID(options), },
5975
0
    };
5976
0
    #undef NUM_KEYWORDS
5977
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5978
5979
    #else  // !Py_BUILD_CORE
5980
    #  define KWTUPLE NULL
5981
    #endif  // !Py_BUILD_CORE
5982
5983
0
    static const char * const _keywords[] = {"pid", "options", NULL};
5984
0
    static _PyArg_Parser _parser = {
5985
0
        .keywords = _keywords,
5986
0
        .fname = "wait4",
5987
0
        .kwtuple = KWTUPLE,
5988
0
    };
5989
0
    #undef KWTUPLE
5990
0
    PyObject *argsbuf[2];
5991
0
    pid_t pid;
5992
0
    int options;
5993
5994
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
5995
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
5996
0
    if (!args) {
5997
0
        goto exit;
5998
0
    }
5999
0
    pid = PyLong_AsPid(args[0]);
6000
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6001
0
        goto exit;
6002
0
    }
6003
0
    options = PyLong_AsInt(args[1]);
6004
0
    if (options == -1 && PyErr_Occurred()) {
6005
0
        goto exit;
6006
0
    }
6007
0
    return_value = os_wait4_impl(module, pid, options);
6008
6009
0
exit:
6010
0
    return return_value;
6011
0
}
6012
6013
#endif /* defined(HAVE_WAIT4) */
6014
6015
#if defined(HAVE_WAITID)
6016
6017
PyDoc_STRVAR(os_waitid__doc__,
6018
"waitid($module, idtype, id, options, /)\n"
6019
"--\n"
6020
"\n"
6021
"Returns the result of waiting for a process or processes.\n"
6022
"\n"
6023
"  idtype\n"
6024
"    Must be one of be P_PID, P_PGID or P_ALL.\n"
6025
"  id\n"
6026
"    The id to wait on.\n"
6027
"  options\n"
6028
"    Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
6029
"    or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
6030
"\n"
6031
"Returns either waitid_result or None if WNOHANG is specified and there are\n"
6032
"no children in a waitable state.");
6033
6034
#define OS_WAITID_METHODDEF    \
6035
    {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__},
6036
6037
static PyObject *
6038
os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
6039
6040
static PyObject *
6041
os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6042
0
{
6043
0
    PyObject *return_value = NULL;
6044
0
    idtype_t idtype;
6045
0
    id_t id;
6046
0
    int options;
6047
6048
0
    if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) {
6049
0
        goto exit;
6050
0
    }
6051
0
    if (!idtype_t_converter(args[0], &idtype)) {
6052
0
        goto exit;
6053
0
    }
6054
0
    id = (id_t)PyLong_AsPid(args[1]);
6055
0
    if (id == (id_t)(-1) && PyErr_Occurred()) {
6056
0
        goto exit;
6057
0
    }
6058
0
    options = PyLong_AsInt(args[2]);
6059
0
    if (options == -1 && PyErr_Occurred()) {
6060
0
        goto exit;
6061
0
    }
6062
0
    return_value = os_waitid_impl(module, idtype, id, options);
6063
6064
0
exit:
6065
0
    return return_value;
6066
0
}
6067
6068
#endif /* defined(HAVE_WAITID) */
6069
6070
#if defined(HAVE_WAITPID)
6071
6072
PyDoc_STRVAR(os_waitpid__doc__,
6073
"waitpid($module, pid, options, /)\n"
6074
"--\n"
6075
"\n"
6076
"Wait for completion of a given child process.\n"
6077
"\n"
6078
"Returns a tuple of information regarding the child process:\n"
6079
"    (pid, status)\n"
6080
"\n"
6081
"The options argument is ignored on Windows.");
6082
6083
#define OS_WAITPID_METHODDEF    \
6084
    {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6085
6086
static PyObject *
6087
os_waitpid_impl(PyObject *module, pid_t pid, int options);
6088
6089
static PyObject *
6090
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6091
0
{
6092
0
    PyObject *return_value = NULL;
6093
0
    pid_t pid;
6094
0
    int options;
6095
6096
0
    if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6097
0
        goto exit;
6098
0
    }
6099
0
    pid = PyLong_AsPid(args[0]);
6100
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6101
0
        goto exit;
6102
0
    }
6103
0
    options = PyLong_AsInt(args[1]);
6104
0
    if (options == -1 && PyErr_Occurred()) {
6105
0
        goto exit;
6106
0
    }
6107
0
    return_value = os_waitpid_impl(module, pid, options);
6108
6109
0
exit:
6110
0
    return return_value;
6111
0
}
6112
6113
#endif /* defined(HAVE_WAITPID) */
6114
6115
#if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT)
6116
6117
PyDoc_STRVAR(os_waitpid__doc__,
6118
"waitpid($module, pid, options, /)\n"
6119
"--\n"
6120
"\n"
6121
"Wait for completion of a given process.\n"
6122
"\n"
6123
"Returns a tuple of information regarding the process:\n"
6124
"    (pid, status << 8)\n"
6125
"\n"
6126
"The options argument is ignored on Windows.");
6127
6128
#define OS_WAITPID_METHODDEF    \
6129
    {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6130
6131
static PyObject *
6132
os_waitpid_impl(PyObject *module, intptr_t pid, int options);
6133
6134
static PyObject *
6135
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6136
{
6137
    PyObject *return_value = NULL;
6138
    intptr_t pid;
6139
    int options;
6140
6141
    if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6142
        goto exit;
6143
    }
6144
    pid = (intptr_t)PyLong_AsVoidPtr(args[0]);
6145
    if (!pid && PyErr_Occurred()) {
6146
        goto exit;
6147
    }
6148
    options = PyLong_AsInt(args[1]);
6149
    if (options == -1 && PyErr_Occurred()) {
6150
        goto exit;
6151
    }
6152
    return_value = os_waitpid_impl(module, pid, options);
6153
6154
exit:
6155
    return return_value;
6156
}
6157
6158
#endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */
6159
6160
#if defined(HAVE_WAIT)
6161
6162
PyDoc_STRVAR(os_wait__doc__,
6163
"wait($module, /)\n"
6164
"--\n"
6165
"\n"
6166
"Wait for completion of a child process.\n"
6167
"\n"
6168
"Returns a tuple of information about the child process:\n"
6169
"    (pid, status)");
6170
6171
#define OS_WAIT_METHODDEF    \
6172
    {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
6173
6174
static PyObject *
6175
os_wait_impl(PyObject *module);
6176
6177
static PyObject *
6178
os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
6179
0
{
6180
0
    return os_wait_impl(module);
6181
0
}
6182
6183
#endif /* defined(HAVE_WAIT) */
6184
6185
#if (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))
6186
6187
PyDoc_STRVAR(os_pidfd_open__doc__,
6188
"pidfd_open($module, /, pid, flags=0)\n"
6189
"--\n"
6190
"\n"
6191
"Return a file descriptor referring to the process *pid*.\n"
6192
"\n"
6193
"The descriptor can be used to perform process management without races and\n"
6194
"signals.");
6195
6196
#define OS_PIDFD_OPEN_METHODDEF    \
6197
    {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__},
6198
6199
static PyObject *
6200
os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags);
6201
6202
static PyObject *
6203
os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6204
0
{
6205
0
    PyObject *return_value = NULL;
6206
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6207
6208
0
    #define NUM_KEYWORDS 2
6209
0
    static struct {
6210
0
        PyGC_Head _this_is_not_used;
6211
0
        PyObject_VAR_HEAD
6212
0
        Py_hash_t ob_hash;
6213
0
        PyObject *ob_item[NUM_KEYWORDS];
6214
0
    } _kwtuple = {
6215
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6216
0
        .ob_hash = -1,
6217
0
        .ob_item = { &_Py_ID(pid), &_Py_ID(flags), },
6218
0
    };
6219
0
    #undef NUM_KEYWORDS
6220
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6221
6222
    #else  // !Py_BUILD_CORE
6223
    #  define KWTUPLE NULL
6224
    #endif  // !Py_BUILD_CORE
6225
6226
0
    static const char * const _keywords[] = {"pid", "flags", NULL};
6227
0
    static _PyArg_Parser _parser = {
6228
0
        .keywords = _keywords,
6229
0
        .fname = "pidfd_open",
6230
0
        .kwtuple = KWTUPLE,
6231
0
    };
6232
0
    #undef KWTUPLE
6233
0
    PyObject *argsbuf[2];
6234
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6235
0
    pid_t pid;
6236
0
    unsigned int flags = 0;
6237
6238
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6239
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6240
0
    if (!args) {
6241
0
        goto exit;
6242
0
    }
6243
0
    pid = PyLong_AsPid(args[0]);
6244
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6245
0
        goto exit;
6246
0
    }
6247
0
    if (!noptargs) {
6248
0
        goto skip_optional_pos;
6249
0
    }
6250
0
    if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) {
6251
0
        goto exit;
6252
0
    }
6253
0
skip_optional_pos:
6254
0
    return_value = os_pidfd_open_impl(module, pid, flags);
6255
6256
0
exit:
6257
0
    return return_value;
6258
0
}
6259
6260
#endif /* (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */
6261
6262
#if defined(HAVE_SETNS)
6263
6264
PyDoc_STRVAR(os_setns__doc__,
6265
"setns($module, /, fd, nstype=0)\n"
6266
"--\n"
6267
"\n"
6268
"Move the calling thread into different namespaces.\n"
6269
"\n"
6270
"  fd\n"
6271
"    A file descriptor to a namespace.\n"
6272
"  nstype\n"
6273
"    Type of namespace.");
6274
6275
#define OS_SETNS_METHODDEF    \
6276
    {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__},
6277
6278
static PyObject *
6279
os_setns_impl(PyObject *module, int fd, int nstype);
6280
6281
static PyObject *
6282
os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6283
0
{
6284
0
    PyObject *return_value = NULL;
6285
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6286
6287
0
    #define NUM_KEYWORDS 2
6288
0
    static struct {
6289
0
        PyGC_Head _this_is_not_used;
6290
0
        PyObject_VAR_HEAD
6291
0
        Py_hash_t ob_hash;
6292
0
        PyObject *ob_item[NUM_KEYWORDS];
6293
0
    } _kwtuple = {
6294
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6295
0
        .ob_hash = -1,
6296
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), },
6297
0
    };
6298
0
    #undef NUM_KEYWORDS
6299
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6300
6301
    #else  // !Py_BUILD_CORE
6302
    #  define KWTUPLE NULL
6303
    #endif  // !Py_BUILD_CORE
6304
6305
0
    static const char * const _keywords[] = {"fd", "nstype", NULL};
6306
0
    static _PyArg_Parser _parser = {
6307
0
        .keywords = _keywords,
6308
0
        .fname = "setns",
6309
0
        .kwtuple = KWTUPLE,
6310
0
    };
6311
0
    #undef KWTUPLE
6312
0
    PyObject *argsbuf[2];
6313
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6314
0
    int fd;
6315
0
    int nstype = 0;
6316
6317
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6318
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6319
0
    if (!args) {
6320
0
        goto exit;
6321
0
    }
6322
0
    fd = PyObject_AsFileDescriptor(args[0]);
6323
0
    if (fd < 0) {
6324
0
        goto exit;
6325
0
    }
6326
0
    if (!noptargs) {
6327
0
        goto skip_optional_pos;
6328
0
    }
6329
0
    nstype = PyLong_AsInt(args[1]);
6330
0
    if (nstype == -1 && PyErr_Occurred()) {
6331
0
        goto exit;
6332
0
    }
6333
0
skip_optional_pos:
6334
0
    return_value = os_setns_impl(module, fd, nstype);
6335
6336
0
exit:
6337
0
    return return_value;
6338
0
}
6339
6340
#endif /* defined(HAVE_SETNS) */
6341
6342
#if defined(HAVE_UNSHARE)
6343
6344
PyDoc_STRVAR(os_unshare__doc__,
6345
"unshare($module, /, flags)\n"
6346
"--\n"
6347
"\n"
6348
"Disassociate parts of a process (or thread) execution context.\n"
6349
"\n"
6350
"  flags\n"
6351
"    Namespaces to be unshared.");
6352
6353
#define OS_UNSHARE_METHODDEF    \
6354
    {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__},
6355
6356
static PyObject *
6357
os_unshare_impl(PyObject *module, int flags);
6358
6359
static PyObject *
6360
os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6361
0
{
6362
0
    PyObject *return_value = NULL;
6363
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6364
6365
0
    #define NUM_KEYWORDS 1
6366
0
    static struct {
6367
0
        PyGC_Head _this_is_not_used;
6368
0
        PyObject_VAR_HEAD
6369
0
        Py_hash_t ob_hash;
6370
0
        PyObject *ob_item[NUM_KEYWORDS];
6371
0
    } _kwtuple = {
6372
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6373
0
        .ob_hash = -1,
6374
0
        .ob_item = { &_Py_ID(flags), },
6375
0
    };
6376
0
    #undef NUM_KEYWORDS
6377
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6378
6379
    #else  // !Py_BUILD_CORE
6380
    #  define KWTUPLE NULL
6381
    #endif  // !Py_BUILD_CORE
6382
6383
0
    static const char * const _keywords[] = {"flags", NULL};
6384
0
    static _PyArg_Parser _parser = {
6385
0
        .keywords = _keywords,
6386
0
        .fname = "unshare",
6387
0
        .kwtuple = KWTUPLE,
6388
0
    };
6389
0
    #undef KWTUPLE
6390
0
    PyObject *argsbuf[1];
6391
0
    int flags;
6392
6393
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6394
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6395
0
    if (!args) {
6396
0
        goto exit;
6397
0
    }
6398
0
    flags = PyLong_AsInt(args[0]);
6399
0
    if (flags == -1 && PyErr_Occurred()) {
6400
0
        goto exit;
6401
0
    }
6402
0
    return_value = os_unshare_impl(module, flags);
6403
6404
0
exit:
6405
0
    return return_value;
6406
0
}
6407
6408
#endif /* defined(HAVE_UNSHARE) */
6409
6410
#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
6411
6412
PyDoc_STRVAR(os_readlink__doc__,
6413
"readlink($module, /, path, *, dir_fd=None)\n"
6414
"--\n"
6415
"\n"
6416
"Return a string representing the path to which the symbolic link points.\n"
6417
"\n"
6418
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
6419
"and path should be relative; path will then be relative to that directory.\n"
6420
"\n"
6421
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
6422
"using it will raise a NotImplementedError.");
6423
6424
#define OS_READLINK_METHODDEF    \
6425
    {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
6426
6427
static PyObject *
6428
os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
6429
6430
static PyObject *
6431
os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6432
0
{
6433
0
    PyObject *return_value = NULL;
6434
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6435
6436
0
    #define NUM_KEYWORDS 2
6437
0
    static struct {
6438
0
        PyGC_Head _this_is_not_used;
6439
0
        PyObject_VAR_HEAD
6440
0
        Py_hash_t ob_hash;
6441
0
        PyObject *ob_item[NUM_KEYWORDS];
6442
0
    } _kwtuple = {
6443
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6444
0
        .ob_hash = -1,
6445
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
6446
0
    };
6447
0
    #undef NUM_KEYWORDS
6448
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6449
6450
    #else  // !Py_BUILD_CORE
6451
    #  define KWTUPLE NULL
6452
    #endif  // !Py_BUILD_CORE
6453
6454
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
6455
0
    static _PyArg_Parser _parser = {
6456
0
        .keywords = _keywords,
6457
0
        .fname = "readlink",
6458
0
        .kwtuple = KWTUPLE,
6459
0
    };
6460
0
    #undef KWTUPLE
6461
0
    PyObject *argsbuf[2];
6462
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6463
0
    path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0);
6464
0
    int dir_fd = DEFAULT_DIR_FD;
6465
6466
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6467
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6468
0
    if (!args) {
6469
0
        goto exit;
6470
0
    }
6471
0
    if (!path_converter(args[0], &path)) {
6472
0
        goto exit;
6473
0
    }
6474
0
    if (!noptargs) {
6475
0
        goto skip_optional_kwonly;
6476
0
    }
6477
0
    if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
6478
0
        goto exit;
6479
0
    }
6480
0
skip_optional_kwonly:
6481
0
    return_value = os_readlink_impl(module, &path, dir_fd);
6482
6483
0
exit:
6484
    /* Cleanup for path */
6485
0
    path_cleanup(&path);
6486
6487
0
    return return_value;
6488
0
}
6489
6490
#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
6491
6492
#if defined(HAVE_SYMLINK)
6493
6494
PyDoc_STRVAR(os_symlink__doc__,
6495
"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
6496
"--\n"
6497
"\n"
6498
"Create a symbolic link pointing to src named dst.\n"
6499
"\n"
6500
"target_is_directory is required on Windows if the target is to be\n"
6501
"  interpreted as a directory.  (On Windows, symlink requires\n"
6502
"  Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
6503
"  target_is_directory is ignored on non-Windows platforms.\n"
6504
"\n"
6505
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
6506
"  and path should be relative; path will then be relative to that directory.\n"
6507
"dir_fd may not be implemented on your platform.\n"
6508
"  If it is unavailable, using it will raise a NotImplementedError.");
6509
6510
#define OS_SYMLINK_METHODDEF    \
6511
    {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
6512
6513
static PyObject *
6514
os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
6515
                int target_is_directory, int dir_fd);
6516
6517
static PyObject *
6518
os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6519
0
{
6520
0
    PyObject *return_value = NULL;
6521
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6522
6523
0
    #define NUM_KEYWORDS 4
6524
0
    static struct {
6525
0
        PyGC_Head _this_is_not_used;
6526
0
        PyObject_VAR_HEAD
6527
0
        Py_hash_t ob_hash;
6528
0
        PyObject *ob_item[NUM_KEYWORDS];
6529
0
    } _kwtuple = {
6530
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6531
0
        .ob_hash = -1,
6532
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), },
6533
0
    };
6534
0
    #undef NUM_KEYWORDS
6535
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6536
6537
    #else  // !Py_BUILD_CORE
6538
    #  define KWTUPLE NULL
6539
    #endif  // !Py_BUILD_CORE
6540
6541
0
    static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
6542
0
    static _PyArg_Parser _parser = {
6543
0
        .keywords = _keywords,
6544
0
        .fname = "symlink",
6545
0
        .kwtuple = KWTUPLE,
6546
0
    };
6547
0
    #undef KWTUPLE
6548
0
    PyObject *argsbuf[4];
6549
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
6550
0
    path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0);
6551
0
    path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0);
6552
0
    int target_is_directory = 0;
6553
0
    int dir_fd = DEFAULT_DIR_FD;
6554
6555
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6556
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6557
0
    if (!args) {
6558
0
        goto exit;
6559
0
    }
6560
0
    if (!path_converter(args[0], &src)) {
6561
0
        goto exit;
6562
0
    }
6563
0
    if (!path_converter(args[1], &dst)) {
6564
0
        goto exit;
6565
0
    }
6566
0
    if (!noptargs) {
6567
0
        goto skip_optional_pos;
6568
0
    }
6569
0
    if (args[2]) {
6570
0
        target_is_directory = PyObject_IsTrue(args[2]);
6571
0
        if (target_is_directory < 0) {
6572
0
            goto exit;
6573
0
        }
6574
0
        if (!--noptargs) {
6575
0
            goto skip_optional_pos;
6576
0
        }
6577
0
    }
6578
0
skip_optional_pos:
6579
0
    if (!noptargs) {
6580
0
        goto skip_optional_kwonly;
6581
0
    }
6582
0
    if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
6583
0
        goto exit;
6584
0
    }
6585
0
skip_optional_kwonly:
6586
0
    return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
6587
6588
0
exit:
6589
    /* Cleanup for src */
6590
0
    path_cleanup(&src);
6591
    /* Cleanup for dst */
6592
0
    path_cleanup(&dst);
6593
6594
0
    return return_value;
6595
0
}
6596
6597
#endif /* defined(HAVE_SYMLINK) */
6598
6599
PyDoc_STRVAR(os_times__doc__,
6600
"times($module, /)\n"
6601
"--\n"
6602
"\n"
6603
"Return a collection containing process timing information.\n"
6604
"\n"
6605
"The object returned behaves like a named tuple with these fields:\n"
6606
"  (utime, stime, cutime, cstime, elapsed_time)\n"
6607
"All fields are floating-point numbers.");
6608
6609
#define OS_TIMES_METHODDEF    \
6610
    {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
6611
6612
static PyObject *
6613
os_times_impl(PyObject *module);
6614
6615
static PyObject *
6616
os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
6617
0
{
6618
0
    return os_times_impl(module);
6619
0
}
6620
6621
#if defined(HAVE_TIMERFD_CREATE)
6622
6623
PyDoc_STRVAR(os_timerfd_create__doc__,
6624
"timerfd_create($module, clockid, /, *, flags=0)\n"
6625
"--\n"
6626
"\n"
6627
"Create and return a timer file descriptor.\n"
6628
"\n"
6629
"  clockid\n"
6630
"    A valid clock ID constant as timer file descriptor.\n"
6631
"\n"
6632
"    time.CLOCK_REALTIME\n"
6633
"    time.CLOCK_MONOTONIC\n"
6634
"    time.CLOCK_BOOTTIME\n"
6635
"  flags\n"
6636
"    0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n"
6637
"\n"
6638
"    os.TFD_NONBLOCK\n"
6639
"        If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n"
6640
"        If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n"
6641
"\n"
6642
"    os.TFD_CLOEXEC\n"
6643
"        If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag");
6644
6645
#define OS_TIMERFD_CREATE_METHODDEF    \
6646
    {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__},
6647
6648
static PyObject *
6649
os_timerfd_create_impl(PyObject *module, int clockid, int flags);
6650
6651
static PyObject *
6652
os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6653
0
{
6654
0
    PyObject *return_value = NULL;
6655
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6656
6657
0
    #define NUM_KEYWORDS 1
6658
0
    static struct {
6659
0
        PyGC_Head _this_is_not_used;
6660
0
        PyObject_VAR_HEAD
6661
0
        Py_hash_t ob_hash;
6662
0
        PyObject *ob_item[NUM_KEYWORDS];
6663
0
    } _kwtuple = {
6664
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6665
0
        .ob_hash = -1,
6666
0
        .ob_item = { &_Py_ID(flags), },
6667
0
    };
6668
0
    #undef NUM_KEYWORDS
6669
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6670
6671
    #else  // !Py_BUILD_CORE
6672
    #  define KWTUPLE NULL
6673
    #endif  // !Py_BUILD_CORE
6674
6675
0
    static const char * const _keywords[] = {"", "flags", NULL};
6676
0
    static _PyArg_Parser _parser = {
6677
0
        .keywords = _keywords,
6678
0
        .fname = "timerfd_create",
6679
0
        .kwtuple = KWTUPLE,
6680
0
    };
6681
0
    #undef KWTUPLE
6682
0
    PyObject *argsbuf[2];
6683
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6684
0
    int clockid;
6685
0
    int flags = 0;
6686
6687
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6688
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6689
0
    if (!args) {
6690
0
        goto exit;
6691
0
    }
6692
0
    clockid = PyLong_AsInt(args[0]);
6693
0
    if (clockid == -1 && PyErr_Occurred()) {
6694
0
        goto exit;
6695
0
    }
6696
0
    if (!noptargs) {
6697
0
        goto skip_optional_kwonly;
6698
0
    }
6699
0
    flags = PyLong_AsInt(args[1]);
6700
0
    if (flags == -1 && PyErr_Occurred()) {
6701
0
        goto exit;
6702
0
    }
6703
0
skip_optional_kwonly:
6704
0
    return_value = os_timerfd_create_impl(module, clockid, flags);
6705
6706
0
exit:
6707
0
    return return_value;
6708
0
}
6709
6710
#endif /* defined(HAVE_TIMERFD_CREATE) */
6711
6712
#if defined(HAVE_TIMERFD_CREATE)
6713
6714
PyDoc_STRVAR(os_timerfd_settime__doc__,
6715
"timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n"
6716
"--\n"
6717
"\n"
6718
"Alter a timer file descriptor\'s internal timer in seconds.\n"
6719
"\n"
6720
"  fd\n"
6721
"    A timer file descriptor.\n"
6722
"  flags\n"
6723
"    0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
6724
"  initial\n"
6725
"    The initial expiration time, in seconds.\n"
6726
"  interval\n"
6727
"    The timer\'s interval, in seconds.");
6728
6729
#define OS_TIMERFD_SETTIME_METHODDEF    \
6730
    {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__},
6731
6732
static PyObject *
6733
os_timerfd_settime_impl(PyObject *module, int fd, int flags,
6734
                        double initial_double, double interval_double);
6735
6736
static PyObject *
6737
os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6738
0
{
6739
0
    PyObject *return_value = NULL;
6740
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6741
6742
0
    #define NUM_KEYWORDS 3
6743
0
    static struct {
6744
0
        PyGC_Head _this_is_not_used;
6745
0
        PyObject_VAR_HEAD
6746
0
        Py_hash_t ob_hash;
6747
0
        PyObject *ob_item[NUM_KEYWORDS];
6748
0
    } _kwtuple = {
6749
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6750
0
        .ob_hash = -1,
6751
0
        .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
6752
0
    };
6753
0
    #undef NUM_KEYWORDS
6754
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6755
6756
    #else  // !Py_BUILD_CORE
6757
    #  define KWTUPLE NULL
6758
    #endif  // !Py_BUILD_CORE
6759
6760
0
    static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
6761
0
    static _PyArg_Parser _parser = {
6762
0
        .keywords = _keywords,
6763
0
        .fname = "timerfd_settime",
6764
0
        .kwtuple = KWTUPLE,
6765
0
    };
6766
0
    #undef KWTUPLE
6767
0
    PyObject *argsbuf[4];
6768
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6769
0
    int fd;
6770
0
    int flags = 0;
6771
0
    double initial_double = 0.0;
6772
0
    double interval_double = 0.0;
6773
6774
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6775
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6776
0
    if (!args) {
6777
0
        goto exit;
6778
0
    }
6779
0
    fd = PyObject_AsFileDescriptor(args[0]);
6780
0
    if (fd < 0) {
6781
0
        goto exit;
6782
0
    }
6783
0
    if (!noptargs) {
6784
0
        goto skip_optional_kwonly;
6785
0
    }
6786
0
    if (args[1]) {
6787
0
        flags = PyLong_AsInt(args[1]);
6788
0
        if (flags == -1 && PyErr_Occurred()) {
6789
0
            goto exit;
6790
0
        }
6791
0
        if (!--noptargs) {
6792
0
            goto skip_optional_kwonly;
6793
0
        }
6794
0
    }
6795
0
    if (args[2]) {
6796
0
        if (PyFloat_CheckExact(args[2])) {
6797
0
            initial_double = PyFloat_AS_DOUBLE(args[2]);
6798
0
        }
6799
0
        else
6800
0
        {
6801
0
            initial_double = PyFloat_AsDouble(args[2]);
6802
0
            if (initial_double == -1.0 && PyErr_Occurred()) {
6803
0
                goto exit;
6804
0
            }
6805
0
        }
6806
0
        if (!--noptargs) {
6807
0
            goto skip_optional_kwonly;
6808
0
        }
6809
0
    }
6810
0
    if (PyFloat_CheckExact(args[3])) {
6811
0
        interval_double = PyFloat_AS_DOUBLE(args[3]);
6812
0
    }
6813
0
    else
6814
0
    {
6815
0
        interval_double = PyFloat_AsDouble(args[3]);
6816
0
        if (interval_double == -1.0 && PyErr_Occurred()) {
6817
0
            goto exit;
6818
0
        }
6819
0
    }
6820
0
skip_optional_kwonly:
6821
0
    return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double);
6822
6823
0
exit:
6824
0
    return return_value;
6825
0
}
6826
6827
#endif /* defined(HAVE_TIMERFD_CREATE) */
6828
6829
#if defined(HAVE_TIMERFD_CREATE)
6830
6831
PyDoc_STRVAR(os_timerfd_settime_ns__doc__,
6832
"timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n"
6833
"--\n"
6834
"\n"
6835
"Alter a timer file descriptor\'s internal timer in nanoseconds.\n"
6836
"\n"
6837
"  fd\n"
6838
"    A timer file descriptor.\n"
6839
"  flags\n"
6840
"    0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
6841
"  initial\n"
6842
"    initial expiration timing in seconds.\n"
6843
"  interval\n"
6844
"    interval for the timer in seconds.");
6845
6846
#define OS_TIMERFD_SETTIME_NS_METHODDEF    \
6847
    {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__},
6848
6849
static PyObject *
6850
os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags,
6851
                           long long initial, long long interval);
6852
6853
static PyObject *
6854
os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6855
0
{
6856
0
    PyObject *return_value = NULL;
6857
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6858
6859
0
    #define NUM_KEYWORDS 3
6860
0
    static struct {
6861
0
        PyGC_Head _this_is_not_used;
6862
0
        PyObject_VAR_HEAD
6863
0
        Py_hash_t ob_hash;
6864
0
        PyObject *ob_item[NUM_KEYWORDS];
6865
0
    } _kwtuple = {
6866
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6867
0
        .ob_hash = -1,
6868
0
        .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
6869
0
    };
6870
0
    #undef NUM_KEYWORDS
6871
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6872
6873
    #else  // !Py_BUILD_CORE
6874
    #  define KWTUPLE NULL
6875
    #endif  // !Py_BUILD_CORE
6876
6877
0
    static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
6878
0
    static _PyArg_Parser _parser = {
6879
0
        .keywords = _keywords,
6880
0
        .fname = "timerfd_settime_ns",
6881
0
        .kwtuple = KWTUPLE,
6882
0
    };
6883
0
    #undef KWTUPLE
6884
0
    PyObject *argsbuf[4];
6885
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6886
0
    int fd;
6887
0
    int flags = 0;
6888
0
    long long initial = 0;
6889
0
    long long interval = 0;
6890
6891
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6892
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6893
0
    if (!args) {
6894
0
        goto exit;
6895
0
    }
6896
0
    fd = PyObject_AsFileDescriptor(args[0]);
6897
0
    if (fd < 0) {
6898
0
        goto exit;
6899
0
    }
6900
0
    if (!noptargs) {
6901
0
        goto skip_optional_kwonly;
6902
0
    }
6903
0
    if (args[1]) {
6904
0
        flags = PyLong_AsInt(args[1]);
6905
0
        if (flags == -1 && PyErr_Occurred()) {
6906
0
            goto exit;
6907
0
        }
6908
0
        if (!--noptargs) {
6909
0
            goto skip_optional_kwonly;
6910
0
        }
6911
0
    }
6912
0
    if (args[2]) {
6913
0
        initial = PyLong_AsLongLong(args[2]);
6914
0
        if (initial == -1 && PyErr_Occurred()) {
6915
0
            goto exit;
6916
0
        }
6917
0
        if (!--noptargs) {
6918
0
            goto skip_optional_kwonly;
6919
0
        }
6920
0
    }
6921
0
    interval = PyLong_AsLongLong(args[3]);
6922
0
    if (interval == -1 && PyErr_Occurred()) {
6923
0
        goto exit;
6924
0
    }
6925
0
skip_optional_kwonly:
6926
0
    return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval);
6927
6928
0
exit:
6929
0
    return return_value;
6930
0
}
6931
6932
#endif /* defined(HAVE_TIMERFD_CREATE) */
6933
6934
#if defined(HAVE_TIMERFD_CREATE)
6935
6936
PyDoc_STRVAR(os_timerfd_gettime__doc__,
6937
"timerfd_gettime($module, fd, /)\n"
6938
"--\n"
6939
"\n"
6940
"Return a tuple of a timer file descriptor\'s (interval, next expiration) in float seconds.\n"
6941
"\n"
6942
"  fd\n"
6943
"    A timer file descriptor.");
6944
6945
#define OS_TIMERFD_GETTIME_METHODDEF    \
6946
    {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__},
6947
6948
static PyObject *
6949
os_timerfd_gettime_impl(PyObject *module, int fd);
6950
6951
static PyObject *
6952
os_timerfd_gettime(PyObject *module, PyObject *arg)
6953
0
{
6954
0
    PyObject *return_value = NULL;
6955
0
    int fd;
6956
6957
0
    fd = PyObject_AsFileDescriptor(arg);
6958
0
    if (fd < 0) {
6959
0
        goto exit;
6960
0
    }
6961
0
    return_value = os_timerfd_gettime_impl(module, fd);
6962
6963
0
exit:
6964
0
    return return_value;
6965
0
}
6966
6967
#endif /* defined(HAVE_TIMERFD_CREATE) */
6968
6969
#if defined(HAVE_TIMERFD_CREATE)
6970
6971
PyDoc_STRVAR(os_timerfd_gettime_ns__doc__,
6972
"timerfd_gettime_ns($module, fd, /)\n"
6973
"--\n"
6974
"\n"
6975
"Return a tuple of a timer file descriptor\'s (interval, next expiration) in nanoseconds.\n"
6976
"\n"
6977
"  fd\n"
6978
"    A timer file descriptor.");
6979
6980
#define OS_TIMERFD_GETTIME_NS_METHODDEF    \
6981
    {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__},
6982
6983
static PyObject *
6984
os_timerfd_gettime_ns_impl(PyObject *module, int fd);
6985
6986
static PyObject *
6987
os_timerfd_gettime_ns(PyObject *module, PyObject *arg)
6988
0
{
6989
0
    PyObject *return_value = NULL;
6990
0
    int fd;
6991
6992
0
    fd = PyObject_AsFileDescriptor(arg);
6993
0
    if (fd < 0) {
6994
0
        goto exit;
6995
0
    }
6996
0
    return_value = os_timerfd_gettime_ns_impl(module, fd);
6997
6998
0
exit:
6999
0
    return return_value;
7000
0
}
7001
7002
#endif /* defined(HAVE_TIMERFD_CREATE) */
7003
7004
#if defined(HAVE_GETSID)
7005
7006
PyDoc_STRVAR(os_getsid__doc__,
7007
"getsid($module, pid, /)\n"
7008
"--\n"
7009
"\n"
7010
"Call the system call getsid(pid) and return the result.");
7011
7012
#define OS_GETSID_METHODDEF    \
7013
    {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
7014
7015
static PyObject *
7016
os_getsid_impl(PyObject *module, pid_t pid);
7017
7018
static PyObject *
7019
os_getsid(PyObject *module, PyObject *arg)
7020
0
{
7021
0
    PyObject *return_value = NULL;
7022
0
    pid_t pid;
7023
7024
0
    pid = PyLong_AsPid(arg);
7025
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7026
0
        goto exit;
7027
0
    }
7028
0
    return_value = os_getsid_impl(module, pid);
7029
7030
0
exit:
7031
0
    return return_value;
7032
0
}
7033
7034
#endif /* defined(HAVE_GETSID) */
7035
7036
#if defined(HAVE_SETSID)
7037
7038
PyDoc_STRVAR(os_setsid__doc__,
7039
"setsid($module, /)\n"
7040
"--\n"
7041
"\n"
7042
"Call the system call setsid().");
7043
7044
#define OS_SETSID_METHODDEF    \
7045
    {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
7046
7047
static PyObject *
7048
os_setsid_impl(PyObject *module);
7049
7050
static PyObject *
7051
os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
7052
0
{
7053
0
    return os_setsid_impl(module);
7054
0
}
7055
7056
#endif /* defined(HAVE_SETSID) */
7057
7058
#if defined(HAVE_SETPGID)
7059
7060
PyDoc_STRVAR(os_setpgid__doc__,
7061
"setpgid($module, pid, pgrp, /)\n"
7062
"--\n"
7063
"\n"
7064
"Call the system call setpgid(pid, pgrp).");
7065
7066
#define OS_SETPGID_METHODDEF    \
7067
    {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__},
7068
7069
static PyObject *
7070
os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
7071
7072
static PyObject *
7073
os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7074
0
{
7075
0
    PyObject *return_value = NULL;
7076
0
    pid_t pid;
7077
0
    pid_t pgrp;
7078
7079
0
    if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) {
7080
0
        goto exit;
7081
0
    }
7082
0
    pid = PyLong_AsPid(args[0]);
7083
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7084
0
        goto exit;
7085
0
    }
7086
0
    pgrp = PyLong_AsPid(args[1]);
7087
0
    if (pgrp == (pid_t)(-1) && PyErr_Occurred()) {
7088
0
        goto exit;
7089
0
    }
7090
0
    return_value = os_setpgid_impl(module, pid, pgrp);
7091
7092
0
exit:
7093
0
    return return_value;
7094
0
}
7095
7096
#endif /* defined(HAVE_SETPGID) */
7097
7098
#if defined(HAVE_TCGETPGRP)
7099
7100
PyDoc_STRVAR(os_tcgetpgrp__doc__,
7101
"tcgetpgrp($module, fd, /)\n"
7102
"--\n"
7103
"\n"
7104
"Return the process group associated with the terminal specified by fd.");
7105
7106
#define OS_TCGETPGRP_METHODDEF    \
7107
    {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
7108
7109
static PyObject *
7110
os_tcgetpgrp_impl(PyObject *module, int fd);
7111
7112
static PyObject *
7113
os_tcgetpgrp(PyObject *module, PyObject *arg)
7114
0
{
7115
0
    PyObject *return_value = NULL;
7116
0
    int fd;
7117
7118
0
    fd = PyLong_AsInt(arg);
7119
0
    if (fd == -1 && PyErr_Occurred()) {
7120
0
        goto exit;
7121
0
    }
7122
0
    return_value = os_tcgetpgrp_impl(module, fd);
7123
7124
0
exit:
7125
0
    return return_value;
7126
0
}
7127
7128
#endif /* defined(HAVE_TCGETPGRP) */
7129
7130
#if defined(HAVE_TCSETPGRP)
7131
7132
PyDoc_STRVAR(os_tcsetpgrp__doc__,
7133
"tcsetpgrp($module, fd, pgid, /)\n"
7134
"--\n"
7135
"\n"
7136
"Set the process group associated with the terminal specified by fd.");
7137
7138
#define OS_TCSETPGRP_METHODDEF    \
7139
    {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__},
7140
7141
static PyObject *
7142
os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
7143
7144
static PyObject *
7145
os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7146
0
{
7147
0
    PyObject *return_value = NULL;
7148
0
    int fd;
7149
0
    pid_t pgid;
7150
7151
0
    if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) {
7152
0
        goto exit;
7153
0
    }
7154
0
    fd = PyLong_AsInt(args[0]);
7155
0
    if (fd == -1 && PyErr_Occurred()) {
7156
0
        goto exit;
7157
0
    }
7158
0
    pgid = PyLong_AsPid(args[1]);
7159
0
    if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
7160
0
        goto exit;
7161
0
    }
7162
0
    return_value = os_tcsetpgrp_impl(module, fd, pgid);
7163
7164
0
exit:
7165
0
    return return_value;
7166
0
}
7167
7168
#endif /* defined(HAVE_TCSETPGRP) */
7169
7170
PyDoc_STRVAR(os_open__doc__,
7171
"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
7172
"--\n"
7173
"\n"
7174
"Open a file for low level IO.  Returns a file descriptor (integer).\n"
7175
"\n"
7176
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
7177
"  and path should be relative; path will then be relative to that directory.\n"
7178
"dir_fd may not be implemented on your platform.\n"
7179
"  If it is unavailable, using it will raise a NotImplementedError.");
7180
7181
#define OS_OPEN_METHODDEF    \
7182
    {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
7183
7184
static int
7185
os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
7186
7187
static PyObject *
7188
os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7189
0
{
7190
0
    PyObject *return_value = NULL;
7191
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7192
7193
0
    #define NUM_KEYWORDS 4
7194
0
    static struct {
7195
0
        PyGC_Head _this_is_not_used;
7196
0
        PyObject_VAR_HEAD
7197
0
        Py_hash_t ob_hash;
7198
0
        PyObject *ob_item[NUM_KEYWORDS];
7199
0
    } _kwtuple = {
7200
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7201
0
        .ob_hash = -1,
7202
0
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), },
7203
0
    };
7204
0
    #undef NUM_KEYWORDS
7205
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7206
7207
    #else  // !Py_BUILD_CORE
7208
    #  define KWTUPLE NULL
7209
    #endif  // !Py_BUILD_CORE
7210
7211
0
    static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
7212
0
    static _PyArg_Parser _parser = {
7213
0
        .keywords = _keywords,
7214
0
        .fname = "open",
7215
0
        .kwtuple = KWTUPLE,
7216
0
    };
7217
0
    #undef KWTUPLE
7218
0
    PyObject *argsbuf[4];
7219
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7220
0
    path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0);
7221
0
    int flags;
7222
0
    int mode = 511;
7223
0
    int dir_fd = DEFAULT_DIR_FD;
7224
0
    int _return_value;
7225
7226
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7227
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7228
0
    if (!args) {
7229
0
        goto exit;
7230
0
    }
7231
0
    if (!path_converter(args[0], &path)) {
7232
0
        goto exit;
7233
0
    }
7234
0
    flags = PyLong_AsInt(args[1]);
7235
0
    if (flags == -1 && PyErr_Occurred()) {
7236
0
        goto exit;
7237
0
    }
7238
0
    if (!noptargs) {
7239
0
        goto skip_optional_pos;
7240
0
    }
7241
0
    if (args[2]) {
7242
0
        mode = PyLong_AsInt(args[2]);
7243
0
        if (mode == -1 && PyErr_Occurred()) {
7244
0
            goto exit;
7245
0
        }
7246
0
        if (!--noptargs) {
7247
0
            goto skip_optional_pos;
7248
0
        }
7249
0
    }
7250
0
skip_optional_pos:
7251
0
    if (!noptargs) {
7252
0
        goto skip_optional_kwonly;
7253
0
    }
7254
0
    if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
7255
0
        goto exit;
7256
0
    }
7257
0
skip_optional_kwonly:
7258
0
    _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
7259
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7260
0
        goto exit;
7261
0
    }
7262
0
    return_value = PyLong_FromLong((long)_return_value);
7263
7264
0
exit:
7265
    /* Cleanup for path */
7266
0
    path_cleanup(&path);
7267
7268
0
    return return_value;
7269
0
}
7270
7271
PyDoc_STRVAR(os_close__doc__,
7272
"close($module, /, fd)\n"
7273
"--\n"
7274
"\n"
7275
"Close a file descriptor.");
7276
7277
#define OS_CLOSE_METHODDEF    \
7278
    {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
7279
7280
static PyObject *
7281
os_close_impl(PyObject *module, int fd);
7282
7283
static PyObject *
7284
os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7285
0
{
7286
0
    PyObject *return_value = NULL;
7287
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7288
7289
0
    #define NUM_KEYWORDS 1
7290
0
    static struct {
7291
0
        PyGC_Head _this_is_not_used;
7292
0
        PyObject_VAR_HEAD
7293
0
        Py_hash_t ob_hash;
7294
0
        PyObject *ob_item[NUM_KEYWORDS];
7295
0
    } _kwtuple = {
7296
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7297
0
        .ob_hash = -1,
7298
0
        .ob_item = { &_Py_ID(fd), },
7299
0
    };
7300
0
    #undef NUM_KEYWORDS
7301
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7302
7303
    #else  // !Py_BUILD_CORE
7304
    #  define KWTUPLE NULL
7305
    #endif  // !Py_BUILD_CORE
7306
7307
0
    static const char * const _keywords[] = {"fd", NULL};
7308
0
    static _PyArg_Parser _parser = {
7309
0
        .keywords = _keywords,
7310
0
        .fname = "close",
7311
0
        .kwtuple = KWTUPLE,
7312
0
    };
7313
0
    #undef KWTUPLE
7314
0
    PyObject *argsbuf[1];
7315
0
    int fd;
7316
7317
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7318
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7319
0
    if (!args) {
7320
0
        goto exit;
7321
0
    }
7322
0
    fd = PyLong_AsInt(args[0]);
7323
0
    if (fd == -1 && PyErr_Occurred()) {
7324
0
        goto exit;
7325
0
    }
7326
0
    return_value = os_close_impl(module, fd);
7327
7328
0
exit:
7329
0
    return return_value;
7330
0
}
7331
7332
PyDoc_STRVAR(os_closerange__doc__,
7333
"closerange($module, fd_low, fd_high, /)\n"
7334
"--\n"
7335
"\n"
7336
"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
7337
7338
#define OS_CLOSERANGE_METHODDEF    \
7339
    {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__},
7340
7341
static PyObject *
7342
os_closerange_impl(PyObject *module, int fd_low, int fd_high);
7343
7344
static PyObject *
7345
os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7346
0
{
7347
0
    PyObject *return_value = NULL;
7348
0
    int fd_low;
7349
0
    int fd_high;
7350
7351
0
    if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
7352
0
        goto exit;
7353
0
    }
7354
0
    fd_low = PyLong_AsInt(args[0]);
7355
0
    if (fd_low == -1 && PyErr_Occurred()) {
7356
0
        goto exit;
7357
0
    }
7358
0
    fd_high = PyLong_AsInt(args[1]);
7359
0
    if (fd_high == -1 && PyErr_Occurred()) {
7360
0
        goto exit;
7361
0
    }
7362
0
    return_value = os_closerange_impl(module, fd_low, fd_high);
7363
7364
0
exit:
7365
0
    return return_value;
7366
0
}
7367
7368
PyDoc_STRVAR(os_dup__doc__,
7369
"dup($module, fd, /)\n"
7370
"--\n"
7371
"\n"
7372
"Return a duplicate of a file descriptor.");
7373
7374
#define OS_DUP_METHODDEF    \
7375
    {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
7376
7377
static int
7378
os_dup_impl(PyObject *module, int fd);
7379
7380
static PyObject *
7381
os_dup(PyObject *module, PyObject *arg)
7382
0
{
7383
0
    PyObject *return_value = NULL;
7384
0
    int fd;
7385
0
    int _return_value;
7386
7387
0
    fd = PyLong_AsInt(arg);
7388
0
    if (fd == -1 && PyErr_Occurred()) {
7389
0
        goto exit;
7390
0
    }
7391
0
    _return_value = os_dup_impl(module, fd);
7392
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7393
0
        goto exit;
7394
0
    }
7395
0
    return_value = PyLong_FromLong((long)_return_value);
7396
7397
0
exit:
7398
0
    return return_value;
7399
0
}
7400
7401
#if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
7402
7403
PyDoc_STRVAR(os_dup2__doc__,
7404
"dup2($module, /, fd, fd2, inheritable=True)\n"
7405
"--\n"
7406
"\n"
7407
"Duplicate file descriptor.");
7408
7409
#define OS_DUP2_METHODDEF    \
7410
    {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
7411
7412
static int
7413
os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
7414
7415
static PyObject *
7416
os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7417
0
{
7418
0
    PyObject *return_value = NULL;
7419
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7420
7421
0
    #define NUM_KEYWORDS 3
7422
0
    static struct {
7423
0
        PyGC_Head _this_is_not_used;
7424
0
        PyObject_VAR_HEAD
7425
0
        Py_hash_t ob_hash;
7426
0
        PyObject *ob_item[NUM_KEYWORDS];
7427
0
    } _kwtuple = {
7428
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7429
0
        .ob_hash = -1,
7430
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), },
7431
0
    };
7432
0
    #undef NUM_KEYWORDS
7433
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7434
7435
    #else  // !Py_BUILD_CORE
7436
    #  define KWTUPLE NULL
7437
    #endif  // !Py_BUILD_CORE
7438
7439
0
    static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
7440
0
    static _PyArg_Parser _parser = {
7441
0
        .keywords = _keywords,
7442
0
        .fname = "dup2",
7443
0
        .kwtuple = KWTUPLE,
7444
0
    };
7445
0
    #undef KWTUPLE
7446
0
    PyObject *argsbuf[3];
7447
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7448
0
    int fd;
7449
0
    int fd2;
7450
0
    int inheritable = 1;
7451
0
    int _return_value;
7452
7453
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7454
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7455
0
    if (!args) {
7456
0
        goto exit;
7457
0
    }
7458
0
    fd = PyLong_AsInt(args[0]);
7459
0
    if (fd == -1 && PyErr_Occurred()) {
7460
0
        goto exit;
7461
0
    }
7462
0
    fd2 = PyLong_AsInt(args[1]);
7463
0
    if (fd2 == -1 && PyErr_Occurred()) {
7464
0
        goto exit;
7465
0
    }
7466
0
    if (!noptargs) {
7467
0
        goto skip_optional_pos;
7468
0
    }
7469
0
    inheritable = PyObject_IsTrue(args[2]);
7470
0
    if (inheritable < 0) {
7471
0
        goto exit;
7472
0
    }
7473
0
skip_optional_pos:
7474
0
    _return_value = os_dup2_impl(module, fd, fd2, inheritable);
7475
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7476
0
        goto exit;
7477
0
    }
7478
0
    return_value = PyLong_FromLong((long)_return_value);
7479
7480
0
exit:
7481
0
    return return_value;
7482
0
}
7483
7484
#endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
7485
7486
#if defined(HAVE_LOCKF)
7487
7488
PyDoc_STRVAR(os_lockf__doc__,
7489
"lockf($module, fd, command, length, /)\n"
7490
"--\n"
7491
"\n"
7492
"Apply, test or remove a POSIX lock on an open file descriptor.\n"
7493
"\n"
7494
"  fd\n"
7495
"    An open file descriptor.\n"
7496
"  command\n"
7497
"    One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
7498
"  length\n"
7499
"    The number of bytes to lock, starting at the current position.");
7500
7501
#define OS_LOCKF_METHODDEF    \
7502
    {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__},
7503
7504
static PyObject *
7505
os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
7506
7507
static PyObject *
7508
os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7509
0
{
7510
0
    PyObject *return_value = NULL;
7511
0
    int fd;
7512
0
    int command;
7513
0
    Py_off_t length;
7514
7515
0
    if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
7516
0
        goto exit;
7517
0
    }
7518
0
    fd = PyLong_AsInt(args[0]);
7519
0
    if (fd == -1 && PyErr_Occurred()) {
7520
0
        goto exit;
7521
0
    }
7522
0
    command = PyLong_AsInt(args[1]);
7523
0
    if (command == -1 && PyErr_Occurred()) {
7524
0
        goto exit;
7525
0
    }
7526
0
    if (!Py_off_t_converter(args[2], &length)) {
7527
0
        goto exit;
7528
0
    }
7529
0
    return_value = os_lockf_impl(module, fd, command, length);
7530
7531
0
exit:
7532
0
    return return_value;
7533
0
}
7534
7535
#endif /* defined(HAVE_LOCKF) */
7536
7537
PyDoc_STRVAR(os_lseek__doc__,
7538
"lseek($module, fd, position, whence, /)\n"
7539
"--\n"
7540
"\n"
7541
"Set the position of a file descriptor.  Return the new position.\n"
7542
"\n"
7543
"  fd\n"
7544
"    An open file descriptor, as returned by os.open().\n"
7545
"  position\n"
7546
"    Position, interpreted relative to \'whence\'.\n"
7547
"  whence\n"
7548
"    The relative position to seek from. Valid values are:\n"
7549
"    - SEEK_SET: seek from the start of the file.\n"
7550
"    - SEEK_CUR: seek from the current file position.\n"
7551
"    - SEEK_END: seek from the end of the file.\n"
7552
"\n"
7553
"The return value is the number of bytes relative to the beginning of the file.");
7554
7555
#define OS_LSEEK_METHODDEF    \
7556
    {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__},
7557
7558
static Py_off_t
7559
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
7560
7561
static PyObject *
7562
os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7563
0
{
7564
0
    PyObject *return_value = NULL;
7565
0
    int fd;
7566
0
    Py_off_t position;
7567
0
    int how;
7568
0
    Py_off_t _return_value;
7569
7570
0
    if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
7571
0
        goto exit;
7572
0
    }
7573
0
    fd = PyLong_AsInt(args[0]);
7574
0
    if (fd == -1 && PyErr_Occurred()) {
7575
0
        goto exit;
7576
0
    }
7577
0
    if (!Py_off_t_converter(args[1], &position)) {
7578
0
        goto exit;
7579
0
    }
7580
0
    how = PyLong_AsInt(args[2]);
7581
0
    if (how == -1 && PyErr_Occurred()) {
7582
0
        goto exit;
7583
0
    }
7584
0
    _return_value = os_lseek_impl(module, fd, position, how);
7585
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7586
0
        goto exit;
7587
0
    }
7588
0
    return_value = PyLong_FromPy_off_t(_return_value);
7589
7590
0
exit:
7591
0
    return return_value;
7592
0
}
7593
7594
PyDoc_STRVAR(os_read__doc__,
7595
"read($module, fd, length, /)\n"
7596
"--\n"
7597
"\n"
7598
"Read from a file descriptor.  Returns a bytes object.");
7599
7600
#define OS_READ_METHODDEF    \
7601
    {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__},
7602
7603
static PyObject *
7604
os_read_impl(PyObject *module, int fd, Py_ssize_t length);
7605
7606
static PyObject *
7607
os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7608
0
{
7609
0
    PyObject *return_value = NULL;
7610
0
    int fd;
7611
0
    Py_ssize_t length;
7612
7613
0
    if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
7614
0
        goto exit;
7615
0
    }
7616
0
    fd = PyLong_AsInt(args[0]);
7617
0
    if (fd == -1 && PyErr_Occurred()) {
7618
0
        goto exit;
7619
0
    }
7620
0
    {
7621
0
        Py_ssize_t ival = -1;
7622
0
        PyObject *iobj = _PyNumber_Index(args[1]);
7623
0
        if (iobj != NULL) {
7624
0
            ival = PyLong_AsSsize_t(iobj);
7625
0
            Py_DECREF(iobj);
7626
0
        }
7627
0
        if (ival == -1 && PyErr_Occurred()) {
7628
0
            goto exit;
7629
0
        }
7630
0
        length = ival;
7631
0
    }
7632
0
    return_value = os_read_impl(module, fd, length);
7633
7634
0
exit:
7635
0
    return return_value;
7636
0
}
7637
7638
PyDoc_STRVAR(os_readinto__doc__,
7639
"readinto($module, fd, buffer, /)\n"
7640
"--\n"
7641
"\n"
7642
"Read into a buffer object from a file descriptor.\n"
7643
"\n"
7644
"The buffer should be mutable and bytes-like. On success, returns the number of\n"
7645
"bytes read. Less bytes may be read than the size of the buffer. The underlying\n"
7646
"system call will be retried when interrupted by a signal, unless the signal\n"
7647
"handler raises an exception. Other errors will not be retried and an error will\n"
7648
"be raised.\n"
7649
"\n"
7650
"Returns 0 if *fd* is at end of file or if the provided *buffer* has length 0\n"
7651
"(which can be used to check for errors without reading data). Never returns\n"
7652
"negative.");
7653
7654
#define OS_READINTO_METHODDEF    \
7655
    {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__},
7656
7657
static Py_ssize_t
7658
os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer);
7659
7660
static PyObject *
7661
os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7662
0
{
7663
0
    PyObject *return_value = NULL;
7664
0
    int fd;
7665
0
    Py_buffer buffer = {NULL, NULL};
7666
0
    Py_ssize_t _return_value;
7667
7668
0
    if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) {
7669
0
        goto exit;
7670
0
    }
7671
0
    fd = PyLong_AsInt(args[0]);
7672
0
    if (fd == -1 && PyErr_Occurred()) {
7673
0
        goto exit;
7674
0
    }
7675
0
    if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) {
7676
0
        _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]);
7677
0
        goto exit;
7678
0
    }
7679
0
    _return_value = os_readinto_impl(module, fd, &buffer);
7680
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7681
0
        goto exit;
7682
0
    }
7683
0
    return_value = PyLong_FromSsize_t(_return_value);
7684
7685
0
exit:
7686
    /* Cleanup for buffer */
7687
0
    if (buffer.obj) {
7688
0
       PyBuffer_Release(&buffer);
7689
0
    }
7690
7691
0
    return return_value;
7692
0
}
7693
7694
#if defined(HAVE_READV)
7695
7696
PyDoc_STRVAR(os_readv__doc__,
7697
"readv($module, fd, buffers, /)\n"
7698
"--\n"
7699
"\n"
7700
"Read from a file descriptor fd into an iterable of buffers.\n"
7701
"\n"
7702
"The buffers should be mutable buffers accepting bytes.\n"
7703
"readv will transfer data into each buffer until it is full\n"
7704
"and then move on to the next buffer in the sequence to hold\n"
7705
"the rest of the data.\n"
7706
"\n"
7707
"readv returns the total number of bytes read,\n"
7708
"which may be less than the total capacity of all the buffers.");
7709
7710
#define OS_READV_METHODDEF    \
7711
    {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__},
7712
7713
static Py_ssize_t
7714
os_readv_impl(PyObject *module, int fd, PyObject *buffers);
7715
7716
static PyObject *
7717
os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7718
0
{
7719
0
    PyObject *return_value = NULL;
7720
0
    int fd;
7721
0
    PyObject *buffers;
7722
0
    Py_ssize_t _return_value;
7723
7724
0
    if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
7725
0
        goto exit;
7726
0
    }
7727
0
    fd = PyLong_AsInt(args[0]);
7728
0
    if (fd == -1 && PyErr_Occurred()) {
7729
0
        goto exit;
7730
0
    }
7731
0
    buffers = args[1];
7732
0
    _return_value = os_readv_impl(module, fd, buffers);
7733
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7734
0
        goto exit;
7735
0
    }
7736
0
    return_value = PyLong_FromSsize_t(_return_value);
7737
7738
0
exit:
7739
0
    return return_value;
7740
0
}
7741
7742
#endif /* defined(HAVE_READV) */
7743
7744
#if defined(HAVE_PREAD)
7745
7746
PyDoc_STRVAR(os_pread__doc__,
7747
"pread($module, fd, length, offset, /)\n"
7748
"--\n"
7749
"\n"
7750
"Read a number of bytes from a file descriptor starting at a particular offset.\n"
7751
"\n"
7752
"Read length bytes from file descriptor fd, starting at offset bytes from\n"
7753
"the beginning of the file.  The file offset remains unchanged.");
7754
7755
#define OS_PREAD_METHODDEF    \
7756
    {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__},
7757
7758
static PyObject *
7759
os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset);
7760
7761
static PyObject *
7762
os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7763
0
{
7764
0
    PyObject *return_value = NULL;
7765
0
    int fd;
7766
0
    Py_ssize_t length;
7767
0
    Py_off_t offset;
7768
7769
0
    if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
7770
0
        goto exit;
7771
0
    }
7772
0
    fd = PyLong_AsInt(args[0]);
7773
0
    if (fd == -1 && PyErr_Occurred()) {
7774
0
        goto exit;
7775
0
    }
7776
0
    {
7777
0
        Py_ssize_t ival = -1;
7778
0
        PyObject *iobj = _PyNumber_Index(args[1]);
7779
0
        if (iobj != NULL) {
7780
0
            ival = PyLong_AsSsize_t(iobj);
7781
0
            Py_DECREF(iobj);
7782
0
        }
7783
0
        if (ival == -1 && PyErr_Occurred()) {
7784
0
            goto exit;
7785
0
        }
7786
0
        length = ival;
7787
0
    }
7788
0
    if (!Py_off_t_converter(args[2], &offset)) {
7789
0
        goto exit;
7790
0
    }
7791
0
    return_value = os_pread_impl(module, fd, length, offset);
7792
7793
0
exit:
7794
0
    return return_value;
7795
0
}
7796
7797
#endif /* defined(HAVE_PREAD) */
7798
7799
#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
7800
7801
PyDoc_STRVAR(os_preadv__doc__,
7802
"preadv($module, fd, buffers, offset, flags=0, /)\n"
7803
"--\n"
7804
"\n"
7805
"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
7806
"\n"
7807
"Combines the functionality of readv() and pread(). As readv(), it will\n"
7808
"transfer data into each buffer until it is full and then move on to the next\n"
7809
"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
7810
"specifies the file offset at which the input operation is to be performed. It\n"
7811
"will return the total number of bytes read (which can be less than the total\n"
7812
"capacity of all the objects).\n"
7813
"\n"
7814
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
7815
"\n"
7816
"- RWF_HIPRI\n"
7817
"- RWF_NOWAIT\n"
7818
"- RWF_DONTCACHE\n"
7819
"\n"
7820
"Using non-zero flags requires Linux 4.6 or newer.");
7821
7822
#define OS_PREADV_METHODDEF    \
7823
    {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__},
7824
7825
static Py_ssize_t
7826
os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
7827
               int flags);
7828
7829
static PyObject *
7830
os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7831
0
{
7832
0
    PyObject *return_value = NULL;
7833
0
    int fd;
7834
0
    PyObject *buffers;
7835
0
    Py_off_t offset;
7836
0
    int flags = 0;
7837
0
    Py_ssize_t _return_value;
7838
7839
0
    if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
7840
0
        goto exit;
7841
0
    }
7842
0
    fd = PyLong_AsInt(args[0]);
7843
0
    if (fd == -1 && PyErr_Occurred()) {
7844
0
        goto exit;
7845
0
    }
7846
0
    buffers = args[1];
7847
0
    if (!Py_off_t_converter(args[2], &offset)) {
7848
0
        goto exit;
7849
0
    }
7850
0
    if (nargs < 4) {
7851
0
        goto skip_optional;
7852
0
    }
7853
0
    flags = PyLong_AsInt(args[3]);
7854
0
    if (flags == -1 && PyErr_Occurred()) {
7855
0
        goto exit;
7856
0
    }
7857
0
skip_optional:
7858
0
    _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
7859
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7860
0
        goto exit;
7861
0
    }
7862
0
    return_value = PyLong_FromSsize_t(_return_value);
7863
7864
0
exit:
7865
0
    return return_value;
7866
0
}
7867
7868
#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
7869
7870
PyDoc_STRVAR(os_write__doc__,
7871
"write($module, fd, data, /)\n"
7872
"--\n"
7873
"\n"
7874
"Write a bytes object to a file descriptor.");
7875
7876
#define OS_WRITE_METHODDEF    \
7877
    {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__},
7878
7879
static Py_ssize_t
7880
os_write_impl(PyObject *module, int fd, Py_buffer *data);
7881
7882
static PyObject *
7883
os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7884
0
{
7885
0
    PyObject *return_value = NULL;
7886
0
    int fd;
7887
0
    Py_buffer data = {NULL, NULL};
7888
0
    Py_ssize_t _return_value;
7889
7890
0
    if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
7891
0
        goto exit;
7892
0
    }
7893
0
    fd = PyLong_AsInt(args[0]);
7894
0
    if (fd == -1 && PyErr_Occurred()) {
7895
0
        goto exit;
7896
0
    }
7897
0
    if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
7898
0
        goto exit;
7899
0
    }
7900
0
    _return_value = os_write_impl(module, fd, &data);
7901
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7902
0
        goto exit;
7903
0
    }
7904
0
    return_value = PyLong_FromSsize_t(_return_value);
7905
7906
0
exit:
7907
    /* Cleanup for data */
7908
0
    if (data.obj) {
7909
0
       PyBuffer_Release(&data);
7910
0
    }
7911
7912
0
    return return_value;
7913
0
}
7914
7915
#if defined(HAVE_SENDFILE) && defined(__APPLE__)
7916
7917
PyDoc_STRVAR(os_sendfile__doc__,
7918
"sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
7919
"         trailers=(), flags=0)\n"
7920
"--\n"
7921
"\n"
7922
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
7923
7924
#define OS_SENDFILE_METHODDEF    \
7925
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
7926
7927
static PyObject *
7928
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
7929
                 Py_off_t sbytes, PyObject *headers, PyObject *trailers,
7930
                 int flags);
7931
7932
static PyObject *
7933
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7934
{
7935
    PyObject *return_value = NULL;
7936
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7937
7938
    #define NUM_KEYWORDS 7
7939
    static struct {
7940
        PyGC_Head _this_is_not_used;
7941
        PyObject_VAR_HEAD
7942
        Py_hash_t ob_hash;
7943
        PyObject *ob_item[NUM_KEYWORDS];
7944
    } _kwtuple = {
7945
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7946
        .ob_hash = -1,
7947
        .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), },
7948
    };
7949
    #undef NUM_KEYWORDS
7950
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7951
7952
    #else  // !Py_BUILD_CORE
7953
    #  define KWTUPLE NULL
7954
    #endif  // !Py_BUILD_CORE
7955
7956
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
7957
    static _PyArg_Parser _parser = {
7958
        .keywords = _keywords,
7959
        .fname = "sendfile",
7960
        .kwtuple = KWTUPLE,
7961
    };
7962
    #undef KWTUPLE
7963
    PyObject *argsbuf[7];
7964
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
7965
    int out_fd;
7966
    int in_fd;
7967
    Py_off_t offset;
7968
    Py_off_t sbytes;
7969
    PyObject *headers = NULL;
7970
    PyObject *trailers = NULL;
7971
    int flags = 0;
7972
7973
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7974
            /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7975
    if (!args) {
7976
        goto exit;
7977
    }
7978
    out_fd = PyLong_AsInt(args[0]);
7979
    if (out_fd == -1 && PyErr_Occurred()) {
7980
        goto exit;
7981
    }
7982
    in_fd = PyLong_AsInt(args[1]);
7983
    if (in_fd == -1 && PyErr_Occurred()) {
7984
        goto exit;
7985
    }
7986
    if (!Py_off_t_converter(args[2], &offset)) {
7987
        goto exit;
7988
    }
7989
    if (!Py_off_t_converter(args[3], &sbytes)) {
7990
        goto exit;
7991
    }
7992
    if (!noptargs) {
7993
        goto skip_optional_pos;
7994
    }
7995
    if (args[4]) {
7996
        headers = args[4];
7997
        if (!--noptargs) {
7998
            goto skip_optional_pos;
7999
        }
8000
    }
8001
    if (args[5]) {
8002
        trailers = args[5];
8003
        if (!--noptargs) {
8004
            goto skip_optional_pos;
8005
        }
8006
    }
8007
    flags = PyLong_AsInt(args[6]);
8008
    if (flags == -1 && PyErr_Occurred()) {
8009
        goto exit;
8010
    }
8011
skip_optional_pos:
8012
    return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags);
8013
8014
exit:
8015
    return return_value;
8016
}
8017
8018
#endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */
8019
8020
#if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__))
8021
8022
PyDoc_STRVAR(os_sendfile__doc__,
8023
"sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
8024
"         trailers=(), flags=0)\n"
8025
"--\n"
8026
"\n"
8027
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8028
8029
#define OS_SENDFILE_METHODDEF    \
8030
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8031
8032
static PyObject *
8033
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
8034
                 Py_ssize_t count, PyObject *headers, PyObject *trailers,
8035
                 int flags);
8036
8037
static PyObject *
8038
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8039
{
8040
    PyObject *return_value = NULL;
8041
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8042
8043
    #define NUM_KEYWORDS 7
8044
    static struct {
8045
        PyGC_Head _this_is_not_used;
8046
        PyObject_VAR_HEAD
8047
        Py_hash_t ob_hash;
8048
        PyObject *ob_item[NUM_KEYWORDS];
8049
    } _kwtuple = {
8050
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8051
        .ob_hash = -1,
8052
        .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), },
8053
    };
8054
    #undef NUM_KEYWORDS
8055
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8056
8057
    #else  // !Py_BUILD_CORE
8058
    #  define KWTUPLE NULL
8059
    #endif  // !Py_BUILD_CORE
8060
8061
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
8062
    static _PyArg_Parser _parser = {
8063
        .keywords = _keywords,
8064
        .fname = "sendfile",
8065
        .kwtuple = KWTUPLE,
8066
    };
8067
    #undef KWTUPLE
8068
    PyObject *argsbuf[7];
8069
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
8070
    int out_fd;
8071
    int in_fd;
8072
    Py_off_t offset;
8073
    Py_ssize_t count;
8074
    PyObject *headers = NULL;
8075
    PyObject *trailers = NULL;
8076
    int flags = 0;
8077
8078
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8079
            /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8080
    if (!args) {
8081
        goto exit;
8082
    }
8083
    out_fd = PyLong_AsInt(args[0]);
8084
    if (out_fd == -1 && PyErr_Occurred()) {
8085
        goto exit;
8086
    }
8087
    in_fd = PyLong_AsInt(args[1]);
8088
    if (in_fd == -1 && PyErr_Occurred()) {
8089
        goto exit;
8090
    }
8091
    if (!Py_off_t_converter(args[2], &offset)) {
8092
        goto exit;
8093
    }
8094
    {
8095
        Py_ssize_t ival = -1;
8096
        PyObject *iobj = _PyNumber_Index(args[3]);
8097
        if (iobj != NULL) {
8098
            ival = PyLong_AsSsize_t(iobj);
8099
            Py_DECREF(iobj);
8100
        }
8101
        if (ival == -1 && PyErr_Occurred()) {
8102
            goto exit;
8103
        }
8104
        count = ival;
8105
        if (count < 0) {
8106
            PyErr_SetString(PyExc_ValueError,
8107
                            "count cannot be negative");
8108
            goto exit;
8109
        }
8110
    }
8111
    if (!noptargs) {
8112
        goto skip_optional_pos;
8113
    }
8114
    if (args[4]) {
8115
        headers = args[4];
8116
        if (!--noptargs) {
8117
            goto skip_optional_pos;
8118
        }
8119
    }
8120
    if (args[5]) {
8121
        trailers = args[5];
8122
        if (!--noptargs) {
8123
            goto skip_optional_pos;
8124
        }
8125
    }
8126
    flags = PyLong_AsInt(args[6]);
8127
    if (flags == -1 && PyErr_Occurred()) {
8128
        goto exit;
8129
    }
8130
skip_optional_pos:
8131
    return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags);
8132
8133
exit:
8134
    return return_value;
8135
}
8136
8137
#endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */
8138
8139
#if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__))
8140
8141
PyDoc_STRVAR(os_sendfile__doc__,
8142
"sendfile($module, /, out_fd, in_fd, offset, count)\n"
8143
"--\n"
8144
"\n"
8145
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8146
8147
#define OS_SENDFILE_METHODDEF    \
8148
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8149
8150
static PyObject *
8151
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
8152
                 Py_ssize_t count);
8153
8154
static PyObject *
8155
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8156
0
{
8157
0
    PyObject *return_value = NULL;
8158
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8159
8160
0
    #define NUM_KEYWORDS 4
8161
0
    static struct {
8162
0
        PyGC_Head _this_is_not_used;
8163
0
        PyObject_VAR_HEAD
8164
0
        Py_hash_t ob_hash;
8165
0
        PyObject *ob_item[NUM_KEYWORDS];
8166
0
    } _kwtuple = {
8167
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8168
0
        .ob_hash = -1,
8169
0
        .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), },
8170
0
    };
8171
0
    #undef NUM_KEYWORDS
8172
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8173
8174
    #else  // !Py_BUILD_CORE
8175
    #  define KWTUPLE NULL
8176
    #endif  // !Py_BUILD_CORE
8177
8178
0
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL};
8179
0
    static _PyArg_Parser _parser = {
8180
0
        .keywords = _keywords,
8181
0
        .fname = "sendfile",
8182
0
        .kwtuple = KWTUPLE,
8183
0
    };
8184
0
    #undef KWTUPLE
8185
0
    PyObject *argsbuf[4];
8186
0
    int out_fd;
8187
0
    int in_fd;
8188
0
    PyObject *offobj;
8189
0
    Py_ssize_t count;
8190
8191
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8192
0
            /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8193
0
    if (!args) {
8194
0
        goto exit;
8195
0
    }
8196
0
    out_fd = PyLong_AsInt(args[0]);
8197
0
    if (out_fd == -1 && PyErr_Occurred()) {
8198
0
        goto exit;
8199
0
    }
8200
0
    in_fd = PyLong_AsInt(args[1]);
8201
0
    if (in_fd == -1 && PyErr_Occurred()) {
8202
0
        goto exit;
8203
0
    }
8204
0
    offobj = args[2];
8205
0
    {
8206
0
        Py_ssize_t ival = -1;
8207
0
        PyObject *iobj = _PyNumber_Index(args[3]);
8208
0
        if (iobj != NULL) {
8209
0
            ival = PyLong_AsSsize_t(iobj);
8210
0
            Py_DECREF(iobj);
8211
0
        }
8212
0
        if (ival == -1 && PyErr_Occurred()) {
8213
0
            goto exit;
8214
0
        }
8215
0
        count = ival;
8216
0
        if (count < 0) {
8217
0
            PyErr_SetString(PyExc_ValueError,
8218
0
                            "count cannot be negative");
8219
0
            goto exit;
8220
0
        }
8221
0
    }
8222
0
    return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count);
8223
8224
0
exit:
8225
0
    return return_value;
8226
0
}
8227
8228
#endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */
8229
8230
#if defined(__APPLE__)
8231
8232
PyDoc_STRVAR(os__fcopyfile__doc__,
8233
"_fcopyfile($module, in_fd, out_fd, flags, /)\n"
8234
"--\n"
8235
"\n"
8236
"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
8237
8238
#define OS__FCOPYFILE_METHODDEF    \
8239
    {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__},
8240
8241
static PyObject *
8242
os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags);
8243
8244
static PyObject *
8245
os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8246
{
8247
    PyObject *return_value = NULL;
8248
    int in_fd;
8249
    int out_fd;
8250
    int flags;
8251
8252
    if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
8253
        goto exit;
8254
    }
8255
    in_fd = PyLong_AsInt(args[0]);
8256
    if (in_fd == -1 && PyErr_Occurred()) {
8257
        goto exit;
8258
    }
8259
    out_fd = PyLong_AsInt(args[1]);
8260
    if (out_fd == -1 && PyErr_Occurred()) {
8261
        goto exit;
8262
    }
8263
    flags = PyLong_AsInt(args[2]);
8264
    if (flags == -1 && PyErr_Occurred()) {
8265
        goto exit;
8266
    }
8267
    return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags);
8268
8269
exit:
8270
    return return_value;
8271
}
8272
8273
#endif /* defined(__APPLE__) */
8274
8275
PyDoc_STRVAR(os_fstat__doc__,
8276
"fstat($module, /, fd)\n"
8277
"--\n"
8278
"\n"
8279
"Perform a stat system call on the given file descriptor.\n"
8280
"\n"
8281
"Like stat(), but for an open file descriptor.\n"
8282
"Equivalent to os.stat(fd).");
8283
8284
#define OS_FSTAT_METHODDEF    \
8285
    {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
8286
8287
static PyObject *
8288
os_fstat_impl(PyObject *module, int fd);
8289
8290
static PyObject *
8291
os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8292
0
{
8293
0
    PyObject *return_value = NULL;
8294
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8295
8296
0
    #define NUM_KEYWORDS 1
8297
0
    static struct {
8298
0
        PyGC_Head _this_is_not_used;
8299
0
        PyObject_VAR_HEAD
8300
0
        Py_hash_t ob_hash;
8301
0
        PyObject *ob_item[NUM_KEYWORDS];
8302
0
    } _kwtuple = {
8303
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8304
0
        .ob_hash = -1,
8305
0
        .ob_item = { &_Py_ID(fd), },
8306
0
    };
8307
0
    #undef NUM_KEYWORDS
8308
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8309
8310
    #else  // !Py_BUILD_CORE
8311
    #  define KWTUPLE NULL
8312
    #endif  // !Py_BUILD_CORE
8313
8314
0
    static const char * const _keywords[] = {"fd", NULL};
8315
0
    static _PyArg_Parser _parser = {
8316
0
        .keywords = _keywords,
8317
0
        .fname = "fstat",
8318
0
        .kwtuple = KWTUPLE,
8319
0
    };
8320
0
    #undef KWTUPLE
8321
0
    PyObject *argsbuf[1];
8322
0
    int fd;
8323
8324
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8325
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8326
0
    if (!args) {
8327
0
        goto exit;
8328
0
    }
8329
0
    fd = PyLong_AsInt(args[0]);
8330
0
    if (fd == -1 && PyErr_Occurred()) {
8331
0
        goto exit;
8332
0
    }
8333
0
    return_value = os_fstat_impl(module, fd);
8334
8335
0
exit:
8336
0
    return return_value;
8337
0
}
8338
8339
PyDoc_STRVAR(os_isatty__doc__,
8340
"isatty($module, fd, /)\n"
8341
"--\n"
8342
"\n"
8343
"Return True if the fd is connected to a terminal.\n"
8344
"\n"
8345
"Return True if the file descriptor is an open file descriptor\n"
8346
"connected to the slave end of a terminal.");
8347
8348
#define OS_ISATTY_METHODDEF    \
8349
    {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
8350
8351
static int
8352
os_isatty_impl(PyObject *module, int fd);
8353
8354
static PyObject *
8355
os_isatty(PyObject *module, PyObject *arg)
8356
0
{
8357
0
    PyObject *return_value = NULL;
8358
0
    int fd;
8359
0
    int _return_value;
8360
8361
0
    fd = PyLong_AsInt(arg);
8362
0
    if (fd == -1 && PyErr_Occurred()) {
8363
0
        goto exit;
8364
0
    }
8365
0
    _return_value = os_isatty_impl(module, fd);
8366
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8367
0
        goto exit;
8368
0
    }
8369
0
    return_value = PyBool_FromLong((long)_return_value);
8370
8371
0
exit:
8372
0
    return return_value;
8373
0
}
8374
8375
#if defined(HAVE_PIPE)
8376
8377
PyDoc_STRVAR(os_pipe__doc__,
8378
"pipe($module, /)\n"
8379
"--\n"
8380
"\n"
8381
"Create a pipe.\n"
8382
"\n"
8383
"Returns a tuple of two file descriptors:\n"
8384
"  (read_fd, write_fd)");
8385
8386
#define OS_PIPE_METHODDEF    \
8387
    {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
8388
8389
static PyObject *
8390
os_pipe_impl(PyObject *module);
8391
8392
static PyObject *
8393
os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
8394
0
{
8395
0
    return os_pipe_impl(module);
8396
0
}
8397
8398
#endif /* defined(HAVE_PIPE) */
8399
8400
#if defined(HAVE_PIPE2)
8401
8402
PyDoc_STRVAR(os_pipe2__doc__,
8403
"pipe2($module, flags, /)\n"
8404
"--\n"
8405
"\n"
8406
"Create a pipe with flags set atomically.\n"
8407
"\n"
8408
"Returns a tuple of two file descriptors:\n"
8409
"  (read_fd, write_fd)\n"
8410
"\n"
8411
"flags can be constructed by ORing together one or more of these values:\n"
8412
"O_NONBLOCK, O_CLOEXEC.");
8413
8414
#define OS_PIPE2_METHODDEF    \
8415
    {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
8416
8417
static PyObject *
8418
os_pipe2_impl(PyObject *module, int flags);
8419
8420
static PyObject *
8421
os_pipe2(PyObject *module, PyObject *arg)
8422
0
{
8423
0
    PyObject *return_value = NULL;
8424
0
    int flags;
8425
8426
0
    flags = PyLong_AsInt(arg);
8427
0
    if (flags == -1 && PyErr_Occurred()) {
8428
0
        goto exit;
8429
0
    }
8430
0
    return_value = os_pipe2_impl(module, flags);
8431
8432
0
exit:
8433
0
    return return_value;
8434
0
}
8435
8436
#endif /* defined(HAVE_PIPE2) */
8437
8438
#if defined(HAVE_WRITEV)
8439
8440
PyDoc_STRVAR(os_writev__doc__,
8441
"writev($module, fd, buffers, /)\n"
8442
"--\n"
8443
"\n"
8444
"Iterate over buffers, and write the contents of each to a file descriptor.\n"
8445
"\n"
8446
"Returns the total number of bytes written.\n"
8447
"buffers must be a sequence of bytes-like objects.");
8448
8449
#define OS_WRITEV_METHODDEF    \
8450
    {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__},
8451
8452
static Py_ssize_t
8453
os_writev_impl(PyObject *module, int fd, PyObject *buffers);
8454
8455
static PyObject *
8456
os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8457
0
{
8458
0
    PyObject *return_value = NULL;
8459
0
    int fd;
8460
0
    PyObject *buffers;
8461
0
    Py_ssize_t _return_value;
8462
8463
0
    if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
8464
0
        goto exit;
8465
0
    }
8466
0
    fd = PyLong_AsInt(args[0]);
8467
0
    if (fd == -1 && PyErr_Occurred()) {
8468
0
        goto exit;
8469
0
    }
8470
0
    buffers = args[1];
8471
0
    _return_value = os_writev_impl(module, fd, buffers);
8472
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8473
0
        goto exit;
8474
0
    }
8475
0
    return_value = PyLong_FromSsize_t(_return_value);
8476
8477
0
exit:
8478
0
    return return_value;
8479
0
}
8480
8481
#endif /* defined(HAVE_WRITEV) */
8482
8483
#if defined(HAVE_PWRITE)
8484
8485
PyDoc_STRVAR(os_pwrite__doc__,
8486
"pwrite($module, fd, buffer, offset, /)\n"
8487
"--\n"
8488
"\n"
8489
"Write bytes to a file descriptor starting at a particular offset.\n"
8490
"\n"
8491
"Write buffer to fd, starting at offset bytes from the beginning of\n"
8492
"the file.  Returns the number of bytes written.  Does not change the\n"
8493
"current file offset.");
8494
8495
#define OS_PWRITE_METHODDEF    \
8496
    {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__},
8497
8498
static Py_ssize_t
8499
os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
8500
8501
static PyObject *
8502
os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8503
0
{
8504
0
    PyObject *return_value = NULL;
8505
0
    int fd;
8506
0
    Py_buffer buffer = {NULL, NULL};
8507
0
    Py_off_t offset;
8508
0
    Py_ssize_t _return_value;
8509
8510
0
    if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
8511
0
        goto exit;
8512
0
    }
8513
0
    fd = PyLong_AsInt(args[0]);
8514
0
    if (fd == -1 && PyErr_Occurred()) {
8515
0
        goto exit;
8516
0
    }
8517
0
    if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
8518
0
        goto exit;
8519
0
    }
8520
0
    if (!Py_off_t_converter(args[2], &offset)) {
8521
0
        goto exit;
8522
0
    }
8523
0
    _return_value = os_pwrite_impl(module, fd, &buffer, offset);
8524
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8525
0
        goto exit;
8526
0
    }
8527
0
    return_value = PyLong_FromSsize_t(_return_value);
8528
8529
0
exit:
8530
    /* Cleanup for buffer */
8531
0
    if (buffer.obj) {
8532
0
       PyBuffer_Release(&buffer);
8533
0
    }
8534
8535
0
    return return_value;
8536
0
}
8537
8538
#endif /* defined(HAVE_PWRITE) */
8539
8540
#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
8541
8542
PyDoc_STRVAR(os_pwritev__doc__,
8543
"pwritev($module, fd, buffers, offset, flags=0, /)\n"
8544
"--\n"
8545
"\n"
8546
"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
8547
"\n"
8548
"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
8549
"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
8550
"buffer is written before proceeding to second, and so on. The operating system may\n"
8551
"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
8552
"This function writes the contents of each object to the file descriptor and returns\n"
8553
"the total number of bytes written.\n"
8554
"\n"
8555
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
8556
"\n"
8557
"- RWF_DSYNC\n"
8558
"- RWF_SYNC\n"
8559
"- RWF_APPEND\n"
8560
"- RWF_DONTCACHE\n"
8561
"\n"
8562
"Using non-zero flags requires Linux 4.7 or newer.");
8563
8564
#define OS_PWRITEV_METHODDEF    \
8565
    {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__},
8566
8567
static Py_ssize_t
8568
os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
8569
                int flags);
8570
8571
static PyObject *
8572
os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8573
0
{
8574
0
    PyObject *return_value = NULL;
8575
0
    int fd;
8576
0
    PyObject *buffers;
8577
0
    Py_off_t offset;
8578
0
    int flags = 0;
8579
0
    Py_ssize_t _return_value;
8580
8581
0
    if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
8582
0
        goto exit;
8583
0
    }
8584
0
    fd = PyLong_AsInt(args[0]);
8585
0
    if (fd == -1 && PyErr_Occurred()) {
8586
0
        goto exit;
8587
0
    }
8588
0
    buffers = args[1];
8589
0
    if (!Py_off_t_converter(args[2], &offset)) {
8590
0
        goto exit;
8591
0
    }
8592
0
    if (nargs < 4) {
8593
0
        goto skip_optional;
8594
0
    }
8595
0
    flags = PyLong_AsInt(args[3]);
8596
0
    if (flags == -1 && PyErr_Occurred()) {
8597
0
        goto exit;
8598
0
    }
8599
0
skip_optional:
8600
0
    _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
8601
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8602
0
        goto exit;
8603
0
    }
8604
0
    return_value = PyLong_FromSsize_t(_return_value);
8605
8606
0
exit:
8607
0
    return return_value;
8608
0
}
8609
8610
#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
8611
8612
#if defined(HAVE_COPY_FILE_RANGE)
8613
8614
PyDoc_STRVAR(os_copy_file_range__doc__,
8615
"copy_file_range($module, /, src, dst, count, offset_src=None,\n"
8616
"                offset_dst=None)\n"
8617
"--\n"
8618
"\n"
8619
"Copy count bytes from one file descriptor to another.\n"
8620
"\n"
8621
"  src\n"
8622
"    Source file descriptor.\n"
8623
"  dst\n"
8624
"    Destination file descriptor.\n"
8625
"  count\n"
8626
"    Number of bytes to copy.\n"
8627
"  offset_src\n"
8628
"    Starting offset in src.\n"
8629
"  offset_dst\n"
8630
"    Starting offset in dst.\n"
8631
"\n"
8632
"If offset_src is None, then src is read from the current position;\n"
8633
"respectively for offset_dst.");
8634
8635
#define OS_COPY_FILE_RANGE_METHODDEF    \
8636
    {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__},
8637
8638
static PyObject *
8639
os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count,
8640
                        PyObject *offset_src, PyObject *offset_dst);
8641
8642
static PyObject *
8643
os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8644
0
{
8645
0
    PyObject *return_value = NULL;
8646
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8647
8648
0
    #define NUM_KEYWORDS 5
8649
0
    static struct {
8650
0
        PyGC_Head _this_is_not_used;
8651
0
        PyObject_VAR_HEAD
8652
0
        Py_hash_t ob_hash;
8653
0
        PyObject *ob_item[NUM_KEYWORDS];
8654
0
    } _kwtuple = {
8655
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8656
0
        .ob_hash = -1,
8657
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), },
8658
0
    };
8659
0
    #undef NUM_KEYWORDS
8660
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8661
8662
    #else  // !Py_BUILD_CORE
8663
    #  define KWTUPLE NULL
8664
    #endif  // !Py_BUILD_CORE
8665
8666
0
    static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL};
8667
0
    static _PyArg_Parser _parser = {
8668
0
        .keywords = _keywords,
8669
0
        .fname = "copy_file_range",
8670
0
        .kwtuple = KWTUPLE,
8671
0
    };
8672
0
    #undef KWTUPLE
8673
0
    PyObject *argsbuf[5];
8674
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
8675
0
    int src;
8676
0
    int dst;
8677
0
    Py_ssize_t count;
8678
0
    PyObject *offset_src = Py_None;
8679
0
    PyObject *offset_dst = Py_None;
8680
8681
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8682
0
            /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8683
0
    if (!args) {
8684
0
        goto exit;
8685
0
    }
8686
0
    src = PyLong_AsInt(args[0]);
8687
0
    if (src == -1 && PyErr_Occurred()) {
8688
0
        goto exit;
8689
0
    }
8690
0
    dst = PyLong_AsInt(args[1]);
8691
0
    if (dst == -1 && PyErr_Occurred()) {
8692
0
        goto exit;
8693
0
    }
8694
0
    {
8695
0
        Py_ssize_t ival = -1;
8696
0
        PyObject *iobj = _PyNumber_Index(args[2]);
8697
0
        if (iobj != NULL) {
8698
0
            ival = PyLong_AsSsize_t(iobj);
8699
0
            Py_DECREF(iobj);
8700
0
        }
8701
0
        if (ival == -1 && PyErr_Occurred()) {
8702
0
            goto exit;
8703
0
        }
8704
0
        count = ival;
8705
0
        if (count < 0) {
8706
0
            PyErr_SetString(PyExc_ValueError,
8707
0
                            "count cannot be negative");
8708
0
            goto exit;
8709
0
        }
8710
0
    }
8711
0
    if (!noptargs) {
8712
0
        goto skip_optional_pos;
8713
0
    }
8714
0
    if (args[3]) {
8715
0
        offset_src = args[3];
8716
0
        if (!--noptargs) {
8717
0
            goto skip_optional_pos;
8718
0
        }
8719
0
    }
8720
0
    offset_dst = args[4];
8721
0
skip_optional_pos:
8722
0
    return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst);
8723
8724
0
exit:
8725
0
    return return_value;
8726
0
}
8727
8728
#endif /* defined(HAVE_COPY_FILE_RANGE) */
8729
8730
#if ((defined(HAVE_SPLICE) && !defined(_AIX)))
8731
8732
PyDoc_STRVAR(os_splice__doc__,
8733
"splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n"
8734
"       flags=0)\n"
8735
"--\n"
8736
"\n"
8737
"Transfer count bytes from one pipe to a descriptor or vice versa.\n"
8738
"\n"
8739
"  src\n"
8740
"    Source file descriptor.\n"
8741
"  dst\n"
8742
"    Destination file descriptor.\n"
8743
"  count\n"
8744
"    Number of bytes to copy.\n"
8745
"  offset_src\n"
8746
"    Starting offset in src.\n"
8747
"  offset_dst\n"
8748
"    Starting offset in dst.\n"
8749
"  flags\n"
8750
"    Flags to modify the semantics of the call.\n"
8751
"\n"
8752
"If offset_src is None, then src is read from the current position;\n"
8753
"respectively for offset_dst. The offset associated to the file\n"
8754
"descriptor that refers to a pipe must be None.");
8755
8756
#define OS_SPLICE_METHODDEF    \
8757
    {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__},
8758
8759
static PyObject *
8760
os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
8761
               PyObject *offset_src, PyObject *offset_dst,
8762
               unsigned int flags);
8763
8764
static PyObject *
8765
os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8766
0
{
8767
0
    PyObject *return_value = NULL;
8768
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8769
8770
0
    #define NUM_KEYWORDS 6
8771
0
    static struct {
8772
0
        PyGC_Head _this_is_not_used;
8773
0
        PyObject_VAR_HEAD
8774
0
        Py_hash_t ob_hash;
8775
0
        PyObject *ob_item[NUM_KEYWORDS];
8776
0
    } _kwtuple = {
8777
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8778
0
        .ob_hash = -1,
8779
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), },
8780
0
    };
8781
0
    #undef NUM_KEYWORDS
8782
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8783
8784
    #else  // !Py_BUILD_CORE
8785
    #  define KWTUPLE NULL
8786
    #endif  // !Py_BUILD_CORE
8787
8788
0
    static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL};
8789
0
    static _PyArg_Parser _parser = {
8790
0
        .keywords = _keywords,
8791
0
        .fname = "splice",
8792
0
        .kwtuple = KWTUPLE,
8793
0
    };
8794
0
    #undef KWTUPLE
8795
0
    PyObject *argsbuf[6];
8796
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
8797
0
    int src;
8798
0
    int dst;
8799
0
    Py_ssize_t count;
8800
0
    PyObject *offset_src = Py_None;
8801
0
    PyObject *offset_dst = Py_None;
8802
0
    unsigned int flags = 0;
8803
8804
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8805
0
            /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8806
0
    if (!args) {
8807
0
        goto exit;
8808
0
    }
8809
0
    src = PyLong_AsInt(args[0]);
8810
0
    if (src == -1 && PyErr_Occurred()) {
8811
0
        goto exit;
8812
0
    }
8813
0
    dst = PyLong_AsInt(args[1]);
8814
0
    if (dst == -1 && PyErr_Occurred()) {
8815
0
        goto exit;
8816
0
    }
8817
0
    {
8818
0
        Py_ssize_t ival = -1;
8819
0
        PyObject *iobj = _PyNumber_Index(args[2]);
8820
0
        if (iobj != NULL) {
8821
0
            ival = PyLong_AsSsize_t(iobj);
8822
0
            Py_DECREF(iobj);
8823
0
        }
8824
0
        if (ival == -1 && PyErr_Occurred()) {
8825
0
            goto exit;
8826
0
        }
8827
0
        count = ival;
8828
0
        if (count < 0) {
8829
0
            PyErr_SetString(PyExc_ValueError,
8830
0
                            "count cannot be negative");
8831
0
            goto exit;
8832
0
        }
8833
0
    }
8834
0
    if (!noptargs) {
8835
0
        goto skip_optional_pos;
8836
0
    }
8837
0
    if (args[3]) {
8838
0
        offset_src = args[3];
8839
0
        if (!--noptargs) {
8840
0
            goto skip_optional_pos;
8841
0
        }
8842
0
    }
8843
0
    if (args[4]) {
8844
0
        offset_dst = args[4];
8845
0
        if (!--noptargs) {
8846
0
            goto skip_optional_pos;
8847
0
        }
8848
0
    }
8849
0
    if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) {
8850
0
        goto exit;
8851
0
    }
8852
0
skip_optional_pos:
8853
0
    return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags);
8854
8855
0
exit:
8856
0
    return return_value;
8857
0
}
8858
8859
#endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */
8860
8861
#if defined(HAVE_MKFIFO)
8862
8863
PyDoc_STRVAR(os_mkfifo__doc__,
8864
"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
8865
"--\n"
8866
"\n"
8867
"Create a \"fifo\" (a POSIX named pipe).\n"
8868
"\n"
8869
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
8870
"  and path should be relative; path will then be relative to that directory.\n"
8871
"dir_fd may not be implemented on your platform.\n"
8872
"  If it is unavailable, using it will raise a NotImplementedError.");
8873
8874
#define OS_MKFIFO_METHODDEF    \
8875
    {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
8876
8877
static PyObject *
8878
os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
8879
8880
static PyObject *
8881
os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8882
0
{
8883
0
    PyObject *return_value = NULL;
8884
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8885
8886
0
    #define NUM_KEYWORDS 3
8887
0
    static struct {
8888
0
        PyGC_Head _this_is_not_used;
8889
0
        PyObject_VAR_HEAD
8890
0
        Py_hash_t ob_hash;
8891
0
        PyObject *ob_item[NUM_KEYWORDS];
8892
0
    } _kwtuple = {
8893
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8894
0
        .ob_hash = -1,
8895
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
8896
0
    };
8897
0
    #undef NUM_KEYWORDS
8898
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8899
8900
    #else  // !Py_BUILD_CORE
8901
    #  define KWTUPLE NULL
8902
    #endif  // !Py_BUILD_CORE
8903
8904
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
8905
0
    static _PyArg_Parser _parser = {
8906
0
        .keywords = _keywords,
8907
0
        .fname = "mkfifo",
8908
0
        .kwtuple = KWTUPLE,
8909
0
    };
8910
0
    #undef KWTUPLE
8911
0
    PyObject *argsbuf[3];
8912
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
8913
0
    path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0);
8914
0
    int mode = 438;
8915
0
    int dir_fd = DEFAULT_DIR_FD;
8916
8917
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8918
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8919
0
    if (!args) {
8920
0
        goto exit;
8921
0
    }
8922
0
    if (!path_converter(args[0], &path)) {
8923
0
        goto exit;
8924
0
    }
8925
0
    if (!noptargs) {
8926
0
        goto skip_optional_pos;
8927
0
    }
8928
0
    if (args[1]) {
8929
0
        mode = PyLong_AsInt(args[1]);
8930
0
        if (mode == -1 && PyErr_Occurred()) {
8931
0
            goto exit;
8932
0
        }
8933
0
        if (!--noptargs) {
8934
0
            goto skip_optional_pos;
8935
0
        }
8936
0
    }
8937
0
skip_optional_pos:
8938
0
    if (!noptargs) {
8939
0
        goto skip_optional_kwonly;
8940
0
    }
8941
0
    if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
8942
0
        goto exit;
8943
0
    }
8944
0
skip_optional_kwonly:
8945
0
    return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
8946
8947
0
exit:
8948
    /* Cleanup for path */
8949
0
    path_cleanup(&path);
8950
8951
0
    return return_value;
8952
0
}
8953
8954
#endif /* defined(HAVE_MKFIFO) */
8955
8956
#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
8957
8958
PyDoc_STRVAR(os_mknod__doc__,
8959
"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
8960
"--\n"
8961
"\n"
8962
"Create a node in the file system.\n"
8963
"\n"
8964
"Create a node in the file system (file, device special file or named pipe)\n"
8965
"at path.  mode specifies both the permissions to use and the\n"
8966
"type of node to be created, being combined (bitwise OR) with one of\n"
8967
"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO.  If S_IFCHR or S_IFBLK is set on mode,\n"
8968
"device defines the newly created device special file (probably using\n"
8969
"os.makedev()).  Otherwise device is ignored.\n"
8970
"\n"
8971
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
8972
"  and path should be relative; path will then be relative to that directory.\n"
8973
"dir_fd may not be implemented on your platform.\n"
8974
"  If it is unavailable, using it will raise a NotImplementedError.");
8975
8976
#define OS_MKNOD_METHODDEF    \
8977
    {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
8978
8979
static PyObject *
8980
os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
8981
              int dir_fd);
8982
8983
static PyObject *
8984
os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8985
0
{
8986
0
    PyObject *return_value = NULL;
8987
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8988
8989
0
    #define NUM_KEYWORDS 4
8990
0
    static struct {
8991
0
        PyGC_Head _this_is_not_used;
8992
0
        PyObject_VAR_HEAD
8993
0
        Py_hash_t ob_hash;
8994
0
        PyObject *ob_item[NUM_KEYWORDS];
8995
0
    } _kwtuple = {
8996
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8997
0
        .ob_hash = -1,
8998
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), },
8999
0
    };
9000
0
    #undef NUM_KEYWORDS
9001
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9002
9003
    #else  // !Py_BUILD_CORE
9004
    #  define KWTUPLE NULL
9005
    #endif  // !Py_BUILD_CORE
9006
9007
0
    static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
9008
0
    static _PyArg_Parser _parser = {
9009
0
        .keywords = _keywords,
9010
0
        .fname = "mknod",
9011
0
        .kwtuple = KWTUPLE,
9012
0
    };
9013
0
    #undef KWTUPLE
9014
0
    PyObject *argsbuf[4];
9015
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
9016
0
    path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0);
9017
0
    int mode = 384;
9018
0
    dev_t device = 0;
9019
0
    int dir_fd = DEFAULT_DIR_FD;
9020
9021
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9022
0
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9023
0
    if (!args) {
9024
0
        goto exit;
9025
0
    }
9026
0
    if (!path_converter(args[0], &path)) {
9027
0
        goto exit;
9028
0
    }
9029
0
    if (!noptargs) {
9030
0
        goto skip_optional_pos;
9031
0
    }
9032
0
    if (args[1]) {
9033
0
        mode = PyLong_AsInt(args[1]);
9034
0
        if (mode == -1 && PyErr_Occurred()) {
9035
0
            goto exit;
9036
0
        }
9037
0
        if (!--noptargs) {
9038
0
            goto skip_optional_pos;
9039
0
        }
9040
0
    }
9041
0
    if (args[2]) {
9042
0
        if (!_Py_Dev_Converter(args[2], &device)) {
9043
0
            goto exit;
9044
0
        }
9045
0
        if (!--noptargs) {
9046
0
            goto skip_optional_pos;
9047
0
        }
9048
0
    }
9049
0
skip_optional_pos:
9050
0
    if (!noptargs) {
9051
0
        goto skip_optional_kwonly;
9052
0
    }
9053
0
    if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
9054
0
        goto exit;
9055
0
    }
9056
0
skip_optional_kwonly:
9057
0
    return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
9058
9059
0
exit:
9060
    /* Cleanup for path */
9061
0
    path_cleanup(&path);
9062
9063
0
    return return_value;
9064
0
}
9065
9066
#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
9067
9068
#if defined(HAVE_DEVICE_MACROS)
9069
9070
PyDoc_STRVAR(os_major__doc__,
9071
"major($module, device, /)\n"
9072
"--\n"
9073
"\n"
9074
"Extracts a device major number from a raw device number.");
9075
9076
#define OS_MAJOR_METHODDEF    \
9077
    {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
9078
9079
static PyObject *
9080
os_major_impl(PyObject *module, dev_t device);
9081
9082
static PyObject *
9083
os_major(PyObject *module, PyObject *arg)
9084
0
{
9085
0
    PyObject *return_value = NULL;
9086
0
    dev_t device;
9087
9088
0
    if (!_Py_Dev_Converter(arg, &device)) {
9089
0
        goto exit;
9090
0
    }
9091
0
    return_value = os_major_impl(module, device);
9092
9093
0
exit:
9094
0
    return return_value;
9095
0
}
9096
9097
#endif /* defined(HAVE_DEVICE_MACROS) */
9098
9099
#if defined(HAVE_DEVICE_MACROS)
9100
9101
PyDoc_STRVAR(os_minor__doc__,
9102
"minor($module, device, /)\n"
9103
"--\n"
9104
"\n"
9105
"Extracts a device minor number from a raw device number.");
9106
9107
#define OS_MINOR_METHODDEF    \
9108
    {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
9109
9110
static PyObject *
9111
os_minor_impl(PyObject *module, dev_t device);
9112
9113
static PyObject *
9114
os_minor(PyObject *module, PyObject *arg)
9115
0
{
9116
0
    PyObject *return_value = NULL;
9117
0
    dev_t device;
9118
9119
0
    if (!_Py_Dev_Converter(arg, &device)) {
9120
0
        goto exit;
9121
0
    }
9122
0
    return_value = os_minor_impl(module, device);
9123
9124
0
exit:
9125
0
    return return_value;
9126
0
}
9127
9128
#endif /* defined(HAVE_DEVICE_MACROS) */
9129
9130
#if defined(HAVE_DEVICE_MACROS)
9131
9132
PyDoc_STRVAR(os_makedev__doc__,
9133
"makedev($module, major, minor, /)\n"
9134
"--\n"
9135
"\n"
9136
"Composes a raw device number from the major and minor device numbers.");
9137
9138
#define OS_MAKEDEV_METHODDEF    \
9139
    {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__},
9140
9141
static dev_t
9142
os_makedev_impl(PyObject *module, dev_t major, dev_t minor);
9143
9144
static PyObject *
9145
os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9146
0
{
9147
0
    PyObject *return_value = NULL;
9148
0
    dev_t major;
9149
0
    dev_t minor;
9150
0
    dev_t _return_value;
9151
9152
0
    if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
9153
0
        goto exit;
9154
0
    }
9155
0
    if (!_Py_Dev_Converter(args[0], &major)) {
9156
0
        goto exit;
9157
0
    }
9158
0
    if (!_Py_Dev_Converter(args[1], &minor)) {
9159
0
        goto exit;
9160
0
    }
9161
0
    _return_value = os_makedev_impl(module, major, minor);
9162
0
    if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
9163
0
        goto exit;
9164
0
    }
9165
0
    return_value = _PyLong_FromDev(_return_value);
9166
9167
0
exit:
9168
0
    return return_value;
9169
0
}
9170
9171
#endif /* defined(HAVE_DEVICE_MACROS) */
9172
9173
#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
9174
9175
PyDoc_STRVAR(os_ftruncate__doc__,
9176
"ftruncate($module, fd, length, /)\n"
9177
"--\n"
9178
"\n"
9179
"Truncate a file, specified by file descriptor, to a specific length.");
9180
9181
#define OS_FTRUNCATE_METHODDEF    \
9182
    {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__},
9183
9184
static PyObject *
9185
os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
9186
9187
static PyObject *
9188
os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9189
0
{
9190
0
    PyObject *return_value = NULL;
9191
0
    int fd;
9192
0
    Py_off_t length;
9193
9194
0
    if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
9195
0
        goto exit;
9196
0
    }
9197
0
    fd = PyLong_AsInt(args[0]);
9198
0
    if (fd == -1 && PyErr_Occurred()) {
9199
0
        goto exit;
9200
0
    }
9201
0
    if (!Py_off_t_converter(args[1], &length)) {
9202
0
        goto exit;
9203
0
    }
9204
0
    return_value = os_ftruncate_impl(module, fd, length);
9205
9206
0
exit:
9207
0
    return return_value;
9208
0
}
9209
9210
#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
9211
9212
#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
9213
9214
PyDoc_STRVAR(os_truncate__doc__,
9215
"truncate($module, /, path, length)\n"
9216
"--\n"
9217
"\n"
9218
"Truncate a file, specified by path, to a specific length.\n"
9219
"\n"
9220
"On some platforms, path may also be specified as an open file descriptor.\n"
9221
"  If this functionality is unavailable, using it raises an exception.");
9222
9223
#define OS_TRUNCATE_METHODDEF    \
9224
    {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
9225
9226
static PyObject *
9227
os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
9228
9229
static PyObject *
9230
os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9231
0
{
9232
0
    PyObject *return_value = NULL;
9233
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9234
9235
0
    #define NUM_KEYWORDS 2
9236
0
    static struct {
9237
0
        PyGC_Head _this_is_not_used;
9238
0
        PyObject_VAR_HEAD
9239
0
        Py_hash_t ob_hash;
9240
0
        PyObject *ob_item[NUM_KEYWORDS];
9241
0
    } _kwtuple = {
9242
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9243
0
        .ob_hash = -1,
9244
0
        .ob_item = { &_Py_ID(path), &_Py_ID(length), },
9245
0
    };
9246
0
    #undef NUM_KEYWORDS
9247
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9248
9249
    #else  // !Py_BUILD_CORE
9250
    #  define KWTUPLE NULL
9251
    #endif  // !Py_BUILD_CORE
9252
9253
0
    static const char * const _keywords[] = {"path", "length", NULL};
9254
0
    static _PyArg_Parser _parser = {
9255
0
        .keywords = _keywords,
9256
0
        .fname = "truncate",
9257
0
        .kwtuple = KWTUPLE,
9258
0
    };
9259
0
    #undef KWTUPLE
9260
0
    PyObject *argsbuf[2];
9261
0
    path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE);
9262
0
    Py_off_t length;
9263
9264
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9265
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9266
0
    if (!args) {
9267
0
        goto exit;
9268
0
    }
9269
0
    if (!path_converter(args[0], &path)) {
9270
0
        goto exit;
9271
0
    }
9272
0
    if (!Py_off_t_converter(args[1], &length)) {
9273
0
        goto exit;
9274
0
    }
9275
0
    return_value = os_truncate_impl(module, &path, length);
9276
9277
0
exit:
9278
    /* Cleanup for path */
9279
0
    path_cleanup(&path);
9280
9281
0
    return return_value;
9282
0
}
9283
9284
#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
9285
9286
#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__))
9287
9288
PyDoc_STRVAR(os_posix_fallocate__doc__,
9289
"posix_fallocate($module, fd, offset, length, /)\n"
9290
"--\n"
9291
"\n"
9292
"Ensure a file has allocated at least a particular number of bytes on disk.\n"
9293
"\n"
9294
"Ensure that the file specified by fd encompasses a range of bytes\n"
9295
"starting at offset bytes from the beginning and continuing for length bytes.");
9296
9297
#define OS_POSIX_FALLOCATE_METHODDEF    \
9298
    {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__},
9299
9300
static PyObject *
9301
os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
9302
                        Py_off_t length);
9303
9304
static PyObject *
9305
os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9306
0
{
9307
0
    PyObject *return_value = NULL;
9308
0
    int fd;
9309
0
    Py_off_t offset;
9310
0
    Py_off_t length;
9311
9312
0
    if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
9313
0
        goto exit;
9314
0
    }
9315
0
    fd = PyLong_AsInt(args[0]);
9316
0
    if (fd == -1 && PyErr_Occurred()) {
9317
0
        goto exit;
9318
0
    }
9319
0
    if (!Py_off_t_converter(args[1], &offset)) {
9320
0
        goto exit;
9321
0
    }
9322
0
    if (!Py_off_t_converter(args[2], &length)) {
9323
0
        goto exit;
9324
0
    }
9325
0
    return_value = os_posix_fallocate_impl(module, fd, offset, length);
9326
9327
0
exit:
9328
0
    return return_value;
9329
0
}
9330
9331
#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */
9332
9333
#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
9334
9335
PyDoc_STRVAR(os_posix_fadvise__doc__,
9336
"posix_fadvise($module, fd, offset, length, advice, /)\n"
9337
"--\n"
9338
"\n"
9339
"Announce an intention to access data in a specific pattern.\n"
9340
"\n"
9341
"Announce an intention to access data in a specific pattern, thus allowing\n"
9342
"the kernel to make optimizations.\n"
9343
"The advice applies to the region of the file specified by fd starting at\n"
9344
"offset and continuing for length bytes.\n"
9345
"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
9346
"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
9347
"POSIX_FADV_DONTNEED.");
9348
9349
#define OS_POSIX_FADVISE_METHODDEF    \
9350
    {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__},
9351
9352
static PyObject *
9353
os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
9354
                      Py_off_t length, int advice);
9355
9356
static PyObject *
9357
os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9358
0
{
9359
0
    PyObject *return_value = NULL;
9360
0
    int fd;
9361
0
    Py_off_t offset;
9362
0
    Py_off_t length;
9363
0
    int advice;
9364
9365
0
    if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
9366
0
        goto exit;
9367
0
    }
9368
0
    fd = PyLong_AsInt(args[0]);
9369
0
    if (fd == -1 && PyErr_Occurred()) {
9370
0
        goto exit;
9371
0
    }
9372
0
    if (!Py_off_t_converter(args[1], &offset)) {
9373
0
        goto exit;
9374
0
    }
9375
0
    if (!Py_off_t_converter(args[2], &length)) {
9376
0
        goto exit;
9377
0
    }
9378
0
    advice = PyLong_AsInt(args[3]);
9379
0
    if (advice == -1 && PyErr_Occurred()) {
9380
0
        goto exit;
9381
0
    }
9382
0
    return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
9383
9384
0
exit:
9385
0
    return return_value;
9386
0
}
9387
9388
#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
9389
9390
#if defined(MS_WINDOWS)
9391
9392
PyDoc_STRVAR(os_putenv__doc__,
9393
"putenv($module, name, value, /)\n"
9394
"--\n"
9395
"\n"
9396
"Change or add an environment variable.");
9397
9398
#define OS_PUTENV_METHODDEF    \
9399
    {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9400
9401
static PyObject *
9402
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9403
9404
static PyObject *
9405
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9406
{
9407
    PyObject *return_value = NULL;
9408
    PyObject *name;
9409
    PyObject *value;
9410
9411
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9412
        goto exit;
9413
    }
9414
    if (!PyUnicode_Check(args[0])) {
9415
        _PyArg_BadArgument("putenv", "argument 1", "str", args[0]);
9416
        goto exit;
9417
    }
9418
    name = args[0];
9419
    if (!PyUnicode_Check(args[1])) {
9420
        _PyArg_BadArgument("putenv", "argument 2", "str", args[1]);
9421
        goto exit;
9422
    }
9423
    value = args[1];
9424
    return_value = os_putenv_impl(module, name, value);
9425
9426
exit:
9427
    return return_value;
9428
}
9429
9430
#endif /* defined(MS_WINDOWS) */
9431
9432
#if !defined(MS_WINDOWS)
9433
9434
PyDoc_STRVAR(os_putenv__doc__,
9435
"putenv($module, name, value, /)\n"
9436
"--\n"
9437
"\n"
9438
"Change or add an environment variable.");
9439
9440
#define OS_PUTENV_METHODDEF    \
9441
    {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9442
9443
static PyObject *
9444
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9445
9446
static PyObject *
9447
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9448
0
{
9449
0
    PyObject *return_value = NULL;
9450
0
    PyObject *name = NULL;
9451
0
    PyObject *value = NULL;
9452
9453
0
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9454
0
        goto exit;
9455
0
    }
9456
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
9457
0
        goto exit;
9458
0
    }
9459
0
    if (!PyUnicode_FSConverter(args[1], &value)) {
9460
0
        goto exit;
9461
0
    }
9462
0
    return_value = os_putenv_impl(module, name, value);
9463
9464
0
exit:
9465
    /* Cleanup for name */
9466
0
    Py_XDECREF(name);
9467
    /* Cleanup for value */
9468
0
    Py_XDECREF(value);
9469
9470
0
    return return_value;
9471
0
}
9472
9473
#endif /* !defined(MS_WINDOWS) */
9474
9475
#if defined(MS_WINDOWS)
9476
9477
PyDoc_STRVAR(os_unsetenv__doc__,
9478
"unsetenv($module, name, /)\n"
9479
"--\n"
9480
"\n"
9481
"Delete an environment variable.");
9482
9483
#define OS_UNSETENV_METHODDEF    \
9484
    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9485
9486
static PyObject *
9487
os_unsetenv_impl(PyObject *module, PyObject *name);
9488
9489
static PyObject *
9490
os_unsetenv(PyObject *module, PyObject *arg)
9491
{
9492
    PyObject *return_value = NULL;
9493
    PyObject *name;
9494
9495
    if (!PyUnicode_Check(arg)) {
9496
        _PyArg_BadArgument("unsetenv", "argument", "str", arg);
9497
        goto exit;
9498
    }
9499
    name = arg;
9500
    return_value = os_unsetenv_impl(module, name);
9501
9502
exit:
9503
    return return_value;
9504
}
9505
9506
#endif /* defined(MS_WINDOWS) */
9507
9508
#if !defined(MS_WINDOWS)
9509
9510
PyDoc_STRVAR(os_unsetenv__doc__,
9511
"unsetenv($module, name, /)\n"
9512
"--\n"
9513
"\n"
9514
"Delete an environment variable.");
9515
9516
#define OS_UNSETENV_METHODDEF    \
9517
    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9518
9519
static PyObject *
9520
os_unsetenv_impl(PyObject *module, PyObject *name);
9521
9522
static PyObject *
9523
os_unsetenv(PyObject *module, PyObject *arg)
9524
0
{
9525
0
    PyObject *return_value = NULL;
9526
0
    PyObject *name = NULL;
9527
9528
0
    if (!PyUnicode_FSConverter(arg, &name)) {
9529
0
        goto exit;
9530
0
    }
9531
0
    return_value = os_unsetenv_impl(module, name);
9532
9533
0
exit:
9534
    /* Cleanup for name */
9535
0
    Py_XDECREF(name);
9536
9537
0
    return return_value;
9538
0
}
9539
9540
#endif /* !defined(MS_WINDOWS) */
9541
9542
#if defined(HAVE_CLEARENV)
9543
9544
PyDoc_STRVAR(os__clearenv__doc__,
9545
"_clearenv($module, /)\n"
9546
"--\n"
9547
"\n");
9548
9549
#define OS__CLEARENV_METHODDEF    \
9550
    {"_clearenv", (PyCFunction)os__clearenv, METH_NOARGS, os__clearenv__doc__},
9551
9552
static PyObject *
9553
os__clearenv_impl(PyObject *module);
9554
9555
static PyObject *
9556
os__clearenv(PyObject *module, PyObject *Py_UNUSED(ignored))
9557
0
{
9558
0
    return os__clearenv_impl(module);
9559
0
}
9560
9561
#endif /* defined(HAVE_CLEARENV) */
9562
9563
PyDoc_STRVAR(os_strerror__doc__,
9564
"strerror($module, code, /)\n"
9565
"--\n"
9566
"\n"
9567
"Translate an error code to a message string.");
9568
9569
#define OS_STRERROR_METHODDEF    \
9570
    {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
9571
9572
static PyObject *
9573
os_strerror_impl(PyObject *module, int code);
9574
9575
static PyObject *
9576
os_strerror(PyObject *module, PyObject *arg)
9577
0
{
9578
0
    PyObject *return_value = NULL;
9579
0
    int code;
9580
9581
0
    code = PyLong_AsInt(arg);
9582
0
    if (code == -1 && PyErr_Occurred()) {
9583
0
        goto exit;
9584
0
    }
9585
0
    return_value = os_strerror_impl(module, code);
9586
9587
0
exit:
9588
0
    return return_value;
9589
0
}
9590
9591
#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
9592
9593
PyDoc_STRVAR(os_WCOREDUMP__doc__,
9594
"WCOREDUMP($module, status, /)\n"
9595
"--\n"
9596
"\n"
9597
"Return True if the process returning status was dumped to a core file.");
9598
9599
#define OS_WCOREDUMP_METHODDEF    \
9600
    {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
9601
9602
static int
9603
os_WCOREDUMP_impl(PyObject *module, int status);
9604
9605
static PyObject *
9606
os_WCOREDUMP(PyObject *module, PyObject *arg)
9607
0
{
9608
0
    PyObject *return_value = NULL;
9609
0
    int status;
9610
0
    int _return_value;
9611
9612
0
    status = PyLong_AsInt(arg);
9613
0
    if (status == -1 && PyErr_Occurred()) {
9614
0
        goto exit;
9615
0
    }
9616
0
    _return_value = os_WCOREDUMP_impl(module, status);
9617
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9618
0
        goto exit;
9619
0
    }
9620
0
    return_value = PyBool_FromLong((long)_return_value);
9621
9622
0
exit:
9623
0
    return return_value;
9624
0
}
9625
9626
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
9627
9628
#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
9629
9630
PyDoc_STRVAR(os_WIFCONTINUED__doc__,
9631
"WIFCONTINUED($module, /, status)\n"
9632
"--\n"
9633
"\n"
9634
"Return True if a particular process was continued from a job control stop.\n"
9635
"\n"
9636
"Return True if the process returning status was continued from a\n"
9637
"job control stop.");
9638
9639
#define OS_WIFCONTINUED_METHODDEF    \
9640
    {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
9641
9642
static int
9643
os_WIFCONTINUED_impl(PyObject *module, int status);
9644
9645
static PyObject *
9646
os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9647
0
{
9648
0
    PyObject *return_value = NULL;
9649
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9650
9651
0
    #define NUM_KEYWORDS 1
9652
0
    static struct {
9653
0
        PyGC_Head _this_is_not_used;
9654
0
        PyObject_VAR_HEAD
9655
0
        Py_hash_t ob_hash;
9656
0
        PyObject *ob_item[NUM_KEYWORDS];
9657
0
    } _kwtuple = {
9658
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9659
0
        .ob_hash = -1,
9660
0
        .ob_item = { &_Py_ID(status), },
9661
0
    };
9662
0
    #undef NUM_KEYWORDS
9663
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9664
9665
    #else  // !Py_BUILD_CORE
9666
    #  define KWTUPLE NULL
9667
    #endif  // !Py_BUILD_CORE
9668
9669
0
    static const char * const _keywords[] = {"status", NULL};
9670
0
    static _PyArg_Parser _parser = {
9671
0
        .keywords = _keywords,
9672
0
        .fname = "WIFCONTINUED",
9673
0
        .kwtuple = KWTUPLE,
9674
0
    };
9675
0
    #undef KWTUPLE
9676
0
    PyObject *argsbuf[1];
9677
0
    int status;
9678
0
    int _return_value;
9679
9680
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9681
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9682
0
    if (!args) {
9683
0
        goto exit;
9684
0
    }
9685
0
    status = PyLong_AsInt(args[0]);
9686
0
    if (status == -1 && PyErr_Occurred()) {
9687
0
        goto exit;
9688
0
    }
9689
0
    _return_value = os_WIFCONTINUED_impl(module, status);
9690
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9691
0
        goto exit;
9692
0
    }
9693
0
    return_value = PyBool_FromLong((long)_return_value);
9694
9695
0
exit:
9696
0
    return return_value;
9697
0
}
9698
9699
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
9700
9701
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
9702
9703
PyDoc_STRVAR(os_WIFSTOPPED__doc__,
9704
"WIFSTOPPED($module, /, status)\n"
9705
"--\n"
9706
"\n"
9707
"Return True if the process returning status was stopped.");
9708
9709
#define OS_WIFSTOPPED_METHODDEF    \
9710
    {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
9711
9712
static int
9713
os_WIFSTOPPED_impl(PyObject *module, int status);
9714
9715
static PyObject *
9716
os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9717
0
{
9718
0
    PyObject *return_value = NULL;
9719
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9720
9721
0
    #define NUM_KEYWORDS 1
9722
0
    static struct {
9723
0
        PyGC_Head _this_is_not_used;
9724
0
        PyObject_VAR_HEAD
9725
0
        Py_hash_t ob_hash;
9726
0
        PyObject *ob_item[NUM_KEYWORDS];
9727
0
    } _kwtuple = {
9728
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9729
0
        .ob_hash = -1,
9730
0
        .ob_item = { &_Py_ID(status), },
9731
0
    };
9732
0
    #undef NUM_KEYWORDS
9733
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9734
9735
    #else  // !Py_BUILD_CORE
9736
    #  define KWTUPLE NULL
9737
    #endif  // !Py_BUILD_CORE
9738
9739
0
    static const char * const _keywords[] = {"status", NULL};
9740
0
    static _PyArg_Parser _parser = {
9741
0
        .keywords = _keywords,
9742
0
        .fname = "WIFSTOPPED",
9743
0
        .kwtuple = KWTUPLE,
9744
0
    };
9745
0
    #undef KWTUPLE
9746
0
    PyObject *argsbuf[1];
9747
0
    int status;
9748
0
    int _return_value;
9749
9750
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9751
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9752
0
    if (!args) {
9753
0
        goto exit;
9754
0
    }
9755
0
    status = PyLong_AsInt(args[0]);
9756
0
    if (status == -1 && PyErr_Occurred()) {
9757
0
        goto exit;
9758
0
    }
9759
0
    _return_value = os_WIFSTOPPED_impl(module, status);
9760
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9761
0
        goto exit;
9762
0
    }
9763
0
    return_value = PyBool_FromLong((long)_return_value);
9764
9765
0
exit:
9766
0
    return return_value;
9767
0
}
9768
9769
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
9770
9771
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
9772
9773
PyDoc_STRVAR(os_WIFSIGNALED__doc__,
9774
"WIFSIGNALED($module, /, status)\n"
9775
"--\n"
9776
"\n"
9777
"Return True if the process returning status was terminated by a signal.");
9778
9779
#define OS_WIFSIGNALED_METHODDEF    \
9780
    {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
9781
9782
static int
9783
os_WIFSIGNALED_impl(PyObject *module, int status);
9784
9785
static PyObject *
9786
os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9787
0
{
9788
0
    PyObject *return_value = NULL;
9789
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9790
9791
0
    #define NUM_KEYWORDS 1
9792
0
    static struct {
9793
0
        PyGC_Head _this_is_not_used;
9794
0
        PyObject_VAR_HEAD
9795
0
        Py_hash_t ob_hash;
9796
0
        PyObject *ob_item[NUM_KEYWORDS];
9797
0
    } _kwtuple = {
9798
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9799
0
        .ob_hash = -1,
9800
0
        .ob_item = { &_Py_ID(status), },
9801
0
    };
9802
0
    #undef NUM_KEYWORDS
9803
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9804
9805
    #else  // !Py_BUILD_CORE
9806
    #  define KWTUPLE NULL
9807
    #endif  // !Py_BUILD_CORE
9808
9809
0
    static const char * const _keywords[] = {"status", NULL};
9810
0
    static _PyArg_Parser _parser = {
9811
0
        .keywords = _keywords,
9812
0
        .fname = "WIFSIGNALED",
9813
0
        .kwtuple = KWTUPLE,
9814
0
    };
9815
0
    #undef KWTUPLE
9816
0
    PyObject *argsbuf[1];
9817
0
    int status;
9818
0
    int _return_value;
9819
9820
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9821
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9822
0
    if (!args) {
9823
0
        goto exit;
9824
0
    }
9825
0
    status = PyLong_AsInt(args[0]);
9826
0
    if (status == -1 && PyErr_Occurred()) {
9827
0
        goto exit;
9828
0
    }
9829
0
    _return_value = os_WIFSIGNALED_impl(module, status);
9830
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9831
0
        goto exit;
9832
0
    }
9833
0
    return_value = PyBool_FromLong((long)_return_value);
9834
9835
0
exit:
9836
0
    return return_value;
9837
0
}
9838
9839
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
9840
9841
#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
9842
9843
PyDoc_STRVAR(os_WIFEXITED__doc__,
9844
"WIFEXITED($module, /, status)\n"
9845
"--\n"
9846
"\n"
9847
"Return True if the process returning status exited via the exit() system call.");
9848
9849
#define OS_WIFEXITED_METHODDEF    \
9850
    {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
9851
9852
static int
9853
os_WIFEXITED_impl(PyObject *module, int status);
9854
9855
static PyObject *
9856
os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9857
0
{
9858
0
    PyObject *return_value = NULL;
9859
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9860
9861
0
    #define NUM_KEYWORDS 1
9862
0
    static struct {
9863
0
        PyGC_Head _this_is_not_used;
9864
0
        PyObject_VAR_HEAD
9865
0
        Py_hash_t ob_hash;
9866
0
        PyObject *ob_item[NUM_KEYWORDS];
9867
0
    } _kwtuple = {
9868
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9869
0
        .ob_hash = -1,
9870
0
        .ob_item = { &_Py_ID(status), },
9871
0
    };
9872
0
    #undef NUM_KEYWORDS
9873
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9874
9875
    #else  // !Py_BUILD_CORE
9876
    #  define KWTUPLE NULL
9877
    #endif  // !Py_BUILD_CORE
9878
9879
0
    static const char * const _keywords[] = {"status", NULL};
9880
0
    static _PyArg_Parser _parser = {
9881
0
        .keywords = _keywords,
9882
0
        .fname = "WIFEXITED",
9883
0
        .kwtuple = KWTUPLE,
9884
0
    };
9885
0
    #undef KWTUPLE
9886
0
    PyObject *argsbuf[1];
9887
0
    int status;
9888
0
    int _return_value;
9889
9890
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9891
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9892
0
    if (!args) {
9893
0
        goto exit;
9894
0
    }
9895
0
    status = PyLong_AsInt(args[0]);
9896
0
    if (status == -1 && PyErr_Occurred()) {
9897
0
        goto exit;
9898
0
    }
9899
0
    _return_value = os_WIFEXITED_impl(module, status);
9900
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9901
0
        goto exit;
9902
0
    }
9903
0
    return_value = PyBool_FromLong((long)_return_value);
9904
9905
0
exit:
9906
0
    return return_value;
9907
0
}
9908
9909
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
9910
9911
#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
9912
9913
PyDoc_STRVAR(os_WEXITSTATUS__doc__,
9914
"WEXITSTATUS($module, /, status)\n"
9915
"--\n"
9916
"\n"
9917
"Return the process return code from status.");
9918
9919
#define OS_WEXITSTATUS_METHODDEF    \
9920
    {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
9921
9922
static int
9923
os_WEXITSTATUS_impl(PyObject *module, int status);
9924
9925
static PyObject *
9926
os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9927
0
{
9928
0
    PyObject *return_value = NULL;
9929
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9930
9931
0
    #define NUM_KEYWORDS 1
9932
0
    static struct {
9933
0
        PyGC_Head _this_is_not_used;
9934
0
        PyObject_VAR_HEAD
9935
0
        Py_hash_t ob_hash;
9936
0
        PyObject *ob_item[NUM_KEYWORDS];
9937
0
    } _kwtuple = {
9938
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9939
0
        .ob_hash = -1,
9940
0
        .ob_item = { &_Py_ID(status), },
9941
0
    };
9942
0
    #undef NUM_KEYWORDS
9943
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9944
9945
    #else  // !Py_BUILD_CORE
9946
    #  define KWTUPLE NULL
9947
    #endif  // !Py_BUILD_CORE
9948
9949
0
    static const char * const _keywords[] = {"status", NULL};
9950
0
    static _PyArg_Parser _parser = {
9951
0
        .keywords = _keywords,
9952
0
        .fname = "WEXITSTATUS",
9953
0
        .kwtuple = KWTUPLE,
9954
0
    };
9955
0
    #undef KWTUPLE
9956
0
    PyObject *argsbuf[1];
9957
0
    int status;
9958
0
    int _return_value;
9959
9960
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9961
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9962
0
    if (!args) {
9963
0
        goto exit;
9964
0
    }
9965
0
    status = PyLong_AsInt(args[0]);
9966
0
    if (status == -1 && PyErr_Occurred()) {
9967
0
        goto exit;
9968
0
    }
9969
0
    _return_value = os_WEXITSTATUS_impl(module, status);
9970
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9971
0
        goto exit;
9972
0
    }
9973
0
    return_value = PyLong_FromLong((long)_return_value);
9974
9975
0
exit:
9976
0
    return return_value;
9977
0
}
9978
9979
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
9980
9981
#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
9982
9983
PyDoc_STRVAR(os_WTERMSIG__doc__,
9984
"WTERMSIG($module, /, status)\n"
9985
"--\n"
9986
"\n"
9987
"Return the signal that terminated the process that provided the status value.");
9988
9989
#define OS_WTERMSIG_METHODDEF    \
9990
    {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
9991
9992
static int
9993
os_WTERMSIG_impl(PyObject *module, int status);
9994
9995
static PyObject *
9996
os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9997
0
{
9998
0
    PyObject *return_value = NULL;
9999
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10000
10001
0
    #define NUM_KEYWORDS 1
10002
0
    static struct {
10003
0
        PyGC_Head _this_is_not_used;
10004
0
        PyObject_VAR_HEAD
10005
0
        Py_hash_t ob_hash;
10006
0
        PyObject *ob_item[NUM_KEYWORDS];
10007
0
    } _kwtuple = {
10008
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10009
0
        .ob_hash = -1,
10010
0
        .ob_item = { &_Py_ID(status), },
10011
0
    };
10012
0
    #undef NUM_KEYWORDS
10013
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10014
10015
    #else  // !Py_BUILD_CORE
10016
    #  define KWTUPLE NULL
10017
    #endif  // !Py_BUILD_CORE
10018
10019
0
    static const char * const _keywords[] = {"status", NULL};
10020
0
    static _PyArg_Parser _parser = {
10021
0
        .keywords = _keywords,
10022
0
        .fname = "WTERMSIG",
10023
0
        .kwtuple = KWTUPLE,
10024
0
    };
10025
0
    #undef KWTUPLE
10026
0
    PyObject *argsbuf[1];
10027
0
    int status;
10028
0
    int _return_value;
10029
10030
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10031
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10032
0
    if (!args) {
10033
0
        goto exit;
10034
0
    }
10035
0
    status = PyLong_AsInt(args[0]);
10036
0
    if (status == -1 && PyErr_Occurred()) {
10037
0
        goto exit;
10038
0
    }
10039
0
    _return_value = os_WTERMSIG_impl(module, status);
10040
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10041
0
        goto exit;
10042
0
    }
10043
0
    return_value = PyLong_FromLong((long)_return_value);
10044
10045
0
exit:
10046
0
    return return_value;
10047
0
}
10048
10049
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
10050
10051
#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
10052
10053
PyDoc_STRVAR(os_WSTOPSIG__doc__,
10054
"WSTOPSIG($module, /, status)\n"
10055
"--\n"
10056
"\n"
10057
"Return the signal that stopped the process that provided the status value.");
10058
10059
#define OS_WSTOPSIG_METHODDEF    \
10060
    {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
10061
10062
static int
10063
os_WSTOPSIG_impl(PyObject *module, int status);
10064
10065
static PyObject *
10066
os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10067
0
{
10068
0
    PyObject *return_value = NULL;
10069
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10070
10071
0
    #define NUM_KEYWORDS 1
10072
0
    static struct {
10073
0
        PyGC_Head _this_is_not_used;
10074
0
        PyObject_VAR_HEAD
10075
0
        Py_hash_t ob_hash;
10076
0
        PyObject *ob_item[NUM_KEYWORDS];
10077
0
    } _kwtuple = {
10078
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10079
0
        .ob_hash = -1,
10080
0
        .ob_item = { &_Py_ID(status), },
10081
0
    };
10082
0
    #undef NUM_KEYWORDS
10083
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10084
10085
    #else  // !Py_BUILD_CORE
10086
    #  define KWTUPLE NULL
10087
    #endif  // !Py_BUILD_CORE
10088
10089
0
    static const char * const _keywords[] = {"status", NULL};
10090
0
    static _PyArg_Parser _parser = {
10091
0
        .keywords = _keywords,
10092
0
        .fname = "WSTOPSIG",
10093
0
        .kwtuple = KWTUPLE,
10094
0
    };
10095
0
    #undef KWTUPLE
10096
0
    PyObject *argsbuf[1];
10097
0
    int status;
10098
0
    int _return_value;
10099
10100
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10101
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10102
0
    if (!args) {
10103
0
        goto exit;
10104
0
    }
10105
0
    status = PyLong_AsInt(args[0]);
10106
0
    if (status == -1 && PyErr_Occurred()) {
10107
0
        goto exit;
10108
0
    }
10109
0
    _return_value = os_WSTOPSIG_impl(module, status);
10110
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10111
0
        goto exit;
10112
0
    }
10113
0
    return_value = PyLong_FromLong((long)_return_value);
10114
10115
0
exit:
10116
0
    return return_value;
10117
0
}
10118
10119
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
10120
10121
#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
10122
10123
PyDoc_STRVAR(os_fstatvfs__doc__,
10124
"fstatvfs($module, fd, /)\n"
10125
"--\n"
10126
"\n"
10127
"Perform an fstatvfs system call on the given fd.\n"
10128
"\n"
10129
"Equivalent to statvfs(fd).");
10130
10131
#define OS_FSTATVFS_METHODDEF    \
10132
    {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
10133
10134
static PyObject *
10135
os_fstatvfs_impl(PyObject *module, int fd);
10136
10137
static PyObject *
10138
os_fstatvfs(PyObject *module, PyObject *arg)
10139
0
{
10140
0
    PyObject *return_value = NULL;
10141
0
    int fd;
10142
10143
0
    fd = PyLong_AsInt(arg);
10144
0
    if (fd == -1 && PyErr_Occurred()) {
10145
0
        goto exit;
10146
0
    }
10147
0
    return_value = os_fstatvfs_impl(module, fd);
10148
10149
0
exit:
10150
0
    return return_value;
10151
0
}
10152
10153
#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10154
10155
#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
10156
10157
PyDoc_STRVAR(os_statvfs__doc__,
10158
"statvfs($module, /, path)\n"
10159
"--\n"
10160
"\n"
10161
"Perform a statvfs system call on the given path.\n"
10162
"\n"
10163
"path may always be specified as a string.\n"
10164
"On some platforms, path may also be specified as an open file descriptor.\n"
10165
"  If this functionality is unavailable, using it raises an exception.");
10166
10167
#define OS_STATVFS_METHODDEF    \
10168
    {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
10169
10170
static PyObject *
10171
os_statvfs_impl(PyObject *module, path_t *path);
10172
10173
static PyObject *
10174
os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10175
0
{
10176
0
    PyObject *return_value = NULL;
10177
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10178
10179
0
    #define NUM_KEYWORDS 1
10180
0
    static struct {
10181
0
        PyGC_Head _this_is_not_used;
10182
0
        PyObject_VAR_HEAD
10183
0
        Py_hash_t ob_hash;
10184
0
        PyObject *ob_item[NUM_KEYWORDS];
10185
0
    } _kwtuple = {
10186
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10187
0
        .ob_hash = -1,
10188
0
        .ob_item = { &_Py_ID(path), },
10189
0
    };
10190
0
    #undef NUM_KEYWORDS
10191
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10192
10193
    #else  // !Py_BUILD_CORE
10194
    #  define KWTUPLE NULL
10195
    #endif  // !Py_BUILD_CORE
10196
10197
0
    static const char * const _keywords[] = {"path", NULL};
10198
0
    static _PyArg_Parser _parser = {
10199
0
        .keywords = _keywords,
10200
0
        .fname = "statvfs",
10201
0
        .kwtuple = KWTUPLE,
10202
0
    };
10203
0
    #undef KWTUPLE
10204
0
    PyObject *argsbuf[1];
10205
0
    path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS);
10206
10207
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10208
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10209
0
    if (!args) {
10210
0
        goto exit;
10211
0
    }
10212
0
    if (!path_converter(args[0], &path)) {
10213
0
        goto exit;
10214
0
    }
10215
0
    return_value = os_statvfs_impl(module, &path);
10216
10217
0
exit:
10218
    /* Cleanup for path */
10219
0
    path_cleanup(&path);
10220
10221
0
    return return_value;
10222
0
}
10223
10224
#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10225
10226
#if defined(MS_WINDOWS)
10227
10228
PyDoc_STRVAR(os__getdiskusage__doc__,
10229
"_getdiskusage($module, /, path)\n"
10230
"--\n"
10231
"\n"
10232
"Return disk usage statistics about the given path as a (total, free) tuple.");
10233
10234
#define OS__GETDISKUSAGE_METHODDEF    \
10235
    {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
10236
10237
static PyObject *
10238
os__getdiskusage_impl(PyObject *module, path_t *path);
10239
10240
static PyObject *
10241
os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10242
{
10243
    PyObject *return_value = NULL;
10244
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10245
10246
    #define NUM_KEYWORDS 1
10247
    static struct {
10248
        PyGC_Head _this_is_not_used;
10249
        PyObject_VAR_HEAD
10250
        Py_hash_t ob_hash;
10251
        PyObject *ob_item[NUM_KEYWORDS];
10252
    } _kwtuple = {
10253
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10254
        .ob_hash = -1,
10255
        .ob_item = { &_Py_ID(path), },
10256
    };
10257
    #undef NUM_KEYWORDS
10258
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10259
10260
    #else  // !Py_BUILD_CORE
10261
    #  define KWTUPLE NULL
10262
    #endif  // !Py_BUILD_CORE
10263
10264
    static const char * const _keywords[] = {"path", NULL};
10265
    static _PyArg_Parser _parser = {
10266
        .keywords = _keywords,
10267
        .fname = "_getdiskusage",
10268
        .kwtuple = KWTUPLE,
10269
    };
10270
    #undef KWTUPLE
10271
    PyObject *argsbuf[1];
10272
    path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0);
10273
10274
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10275
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10276
    if (!args) {
10277
        goto exit;
10278
    }
10279
    if (!path_converter(args[0], &path)) {
10280
        goto exit;
10281
    }
10282
    return_value = os__getdiskusage_impl(module, &path);
10283
10284
exit:
10285
    /* Cleanup for path */
10286
    path_cleanup(&path);
10287
10288
    return return_value;
10289
}
10290
10291
#endif /* defined(MS_WINDOWS) */
10292
10293
#if defined(HAVE_FPATHCONF)
10294
10295
PyDoc_STRVAR(os_fpathconf__doc__,
10296
"fpathconf($module, fd, name, /)\n"
10297
"--\n"
10298
"\n"
10299
"Return the configuration limit name for the file descriptor fd.\n"
10300
"\n"
10301
"If there is no limit, return -1.");
10302
10303
#define OS_FPATHCONF_METHODDEF    \
10304
    {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__},
10305
10306
static long
10307
os_fpathconf_impl(PyObject *module, int fd, int name);
10308
10309
static PyObject *
10310
os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10311
0
{
10312
0
    PyObject *return_value = NULL;
10313
0
    int fd;
10314
0
    int name;
10315
0
    long _return_value;
10316
10317
0
    if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
10318
0
        goto exit;
10319
0
    }
10320
0
    fd = PyObject_AsFileDescriptor(args[0]);
10321
0
    if (fd < 0) {
10322
0
        goto exit;
10323
0
    }
10324
0
    if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10325
0
        goto exit;
10326
0
    }
10327
0
    _return_value = os_fpathconf_impl(module, fd, name);
10328
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10329
0
        goto exit;
10330
0
    }
10331
0
    return_value = PyLong_FromLong(_return_value);
10332
10333
0
exit:
10334
0
    return return_value;
10335
0
}
10336
10337
#endif /* defined(HAVE_FPATHCONF) */
10338
10339
#if defined(HAVE_PATHCONF)
10340
10341
PyDoc_STRVAR(os_pathconf__doc__,
10342
"pathconf($module, /, path, name)\n"
10343
"--\n"
10344
"\n"
10345
"Return the configuration limit name for the file or directory path.\n"
10346
"\n"
10347
"If there is no limit, return -1.\n"
10348
"On some platforms, path may also be specified as an open file descriptor.\n"
10349
"  If this functionality is unavailable, using it raises an exception.");
10350
10351
#define OS_PATHCONF_METHODDEF    \
10352
    {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
10353
10354
static long
10355
os_pathconf_impl(PyObject *module, path_t *path, int name);
10356
10357
static PyObject *
10358
os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10359
0
{
10360
0
    PyObject *return_value = NULL;
10361
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10362
10363
0
    #define NUM_KEYWORDS 2
10364
0
    static struct {
10365
0
        PyGC_Head _this_is_not_used;
10366
0
        PyObject_VAR_HEAD
10367
0
        Py_hash_t ob_hash;
10368
0
        PyObject *ob_item[NUM_KEYWORDS];
10369
0
    } _kwtuple = {
10370
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10371
0
        .ob_hash = -1,
10372
0
        .ob_item = { &_Py_ID(path), &_Py_ID(name), },
10373
0
    };
10374
0
    #undef NUM_KEYWORDS
10375
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10376
10377
    #else  // !Py_BUILD_CORE
10378
    #  define KWTUPLE NULL
10379
    #endif  // !Py_BUILD_CORE
10380
10381
0
    static const char * const _keywords[] = {"path", "name", NULL};
10382
0
    static _PyArg_Parser _parser = {
10383
0
        .keywords = _keywords,
10384
0
        .fname = "pathconf",
10385
0
        .kwtuple = KWTUPLE,
10386
0
    };
10387
0
    #undef KWTUPLE
10388
0
    PyObject *argsbuf[2];
10389
0
    path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF);
10390
0
    int name;
10391
0
    long _return_value;
10392
10393
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10394
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10395
0
    if (!args) {
10396
0
        goto exit;
10397
0
    }
10398
0
    if (!path_converter(args[0], &path)) {
10399
0
        goto exit;
10400
0
    }
10401
0
    if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10402
0
        goto exit;
10403
0
    }
10404
0
    _return_value = os_pathconf_impl(module, &path, name);
10405
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10406
0
        goto exit;
10407
0
    }
10408
0
    return_value = PyLong_FromLong(_return_value);
10409
10410
0
exit:
10411
    /* Cleanup for path */
10412
0
    path_cleanup(&path);
10413
10414
0
    return return_value;
10415
0
}
10416
10417
#endif /* defined(HAVE_PATHCONF) */
10418
10419
#if defined(HAVE_CONFSTR)
10420
10421
PyDoc_STRVAR(os_confstr__doc__,
10422
"confstr($module, name, /)\n"
10423
"--\n"
10424
"\n"
10425
"Return a string-valued system configuration variable.");
10426
10427
#define OS_CONFSTR_METHODDEF    \
10428
    {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
10429
10430
static PyObject *
10431
os_confstr_impl(PyObject *module, int name);
10432
10433
static PyObject *
10434
os_confstr(PyObject *module, PyObject *arg)
10435
0
{
10436
0
    PyObject *return_value = NULL;
10437
0
    int name;
10438
10439
0
    if (!conv_confname(module, arg, &name, "confstr_names")) {
10440
0
        goto exit;
10441
0
    }
10442
0
    return_value = os_confstr_impl(module, name);
10443
10444
0
exit:
10445
0
    return return_value;
10446
0
}
10447
10448
#endif /* defined(HAVE_CONFSTR) */
10449
10450
#if defined(HAVE_SYSCONF)
10451
10452
PyDoc_STRVAR(os_sysconf__doc__,
10453
"sysconf($module, name, /)\n"
10454
"--\n"
10455
"\n"
10456
"Return an integer-valued system configuration variable.");
10457
10458
#define OS_SYSCONF_METHODDEF    \
10459
    {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
10460
10461
static long
10462
os_sysconf_impl(PyObject *module, int name);
10463
10464
static PyObject *
10465
os_sysconf(PyObject *module, PyObject *arg)
10466
0
{
10467
0
    PyObject *return_value = NULL;
10468
0
    int name;
10469
0
    long _return_value;
10470
10471
0
    if (!conv_confname(module, arg, &name, "sysconf_names")) {
10472
0
        goto exit;
10473
0
    }
10474
0
    _return_value = os_sysconf_impl(module, name);
10475
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10476
0
        goto exit;
10477
0
    }
10478
0
    return_value = PyLong_FromLong(_return_value);
10479
10480
0
exit:
10481
0
    return return_value;
10482
0
}
10483
10484
#endif /* defined(HAVE_SYSCONF) */
10485
10486
PyDoc_STRVAR(os_abort__doc__,
10487
"abort($module, /)\n"
10488
"--\n"
10489
"\n"
10490
"Abort the interpreter immediately.\n"
10491
"\n"
10492
"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
10493
"on the hosting operating system.  This function never returns.");
10494
10495
#define OS_ABORT_METHODDEF    \
10496
    {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
10497
10498
static PyObject *
10499
os_abort_impl(PyObject *module);
10500
10501
static PyObject *
10502
os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
10503
0
{
10504
0
    return os_abort_impl(module);
10505
0
}
10506
10507
#if defined(MS_WINDOWS)
10508
10509
PyDoc_STRVAR(os_startfile__doc__,
10510
"startfile($module, /, filepath, operation=<unrepresentable>,\n"
10511
"          arguments=<unrepresentable>, cwd=None, show_cmd=1)\n"
10512
"--\n"
10513
"\n"
10514
"Start a file with its associated application.\n"
10515
"\n"
10516
"When \"operation\" is not specified or \"open\", this acts like\n"
10517
"double-clicking the file in Explorer, or giving the file name as an\n"
10518
"argument to the DOS \"start\" command: the file is opened with whatever\n"
10519
"application (if any) its extension is associated.\n"
10520
"When another \"operation\" is given, it specifies what should be done with\n"
10521
"the file.  A typical operation is \"print\".\n"
10522
"\n"
10523
"\"arguments\" is passed to the application, but should be omitted if the\n"
10524
"file is a document.\n"
10525
"\n"
10526
"\"cwd\" is the working directory for the operation. If \"filepath\" is\n"
10527
"relative, it will be resolved against this directory. This argument\n"
10528
"should usually be an absolute path.\n"
10529
"\n"
10530
"\"show_cmd\" can be used to override the recommended visibility option.\n"
10531
"See the Windows ShellExecute documentation for values.\n"
10532
"\n"
10533
"startfile returns as soon as the associated application is launched.\n"
10534
"There is no option to wait for the application to close, and no way\n"
10535
"to retrieve the application\'s exit status.\n"
10536
"\n"
10537
"The filepath is relative to the current directory.  If you want to use\n"
10538
"an absolute path, make sure the first character is not a slash (\"/\");\n"
10539
"the underlying Win32 ShellExecute function doesn\'t work if it is.");
10540
10541
#define OS_STARTFILE_METHODDEF    \
10542
    {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
10543
10544
static PyObject *
10545
os_startfile_impl(PyObject *module, path_t *filepath,
10546
                  const wchar_t *operation, const wchar_t *arguments,
10547
                  path_t *cwd, int show_cmd);
10548
10549
static PyObject *
10550
os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10551
{
10552
    PyObject *return_value = NULL;
10553
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10554
10555
    #define NUM_KEYWORDS 5
10556
    static struct {
10557
        PyGC_Head _this_is_not_used;
10558
        PyObject_VAR_HEAD
10559
        Py_hash_t ob_hash;
10560
        PyObject *ob_item[NUM_KEYWORDS];
10561
    } _kwtuple = {
10562
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10563
        .ob_hash = -1,
10564
        .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), },
10565
    };
10566
    #undef NUM_KEYWORDS
10567
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10568
10569
    #else  // !Py_BUILD_CORE
10570
    #  define KWTUPLE NULL
10571
    #endif  // !Py_BUILD_CORE
10572
10573
    static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL};
10574
    static _PyArg_Parser _parser = {
10575
        .keywords = _keywords,
10576
        .fname = "startfile",
10577
        .kwtuple = KWTUPLE,
10578
    };
10579
    #undef KWTUPLE
10580
    PyObject *argsbuf[5];
10581
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
10582
    path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0);
10583
    const wchar_t *operation = NULL;
10584
    const wchar_t *arguments = NULL;
10585
    path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0);
10586
    int show_cmd = 1;
10587
10588
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10589
            /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10590
    if (!args) {
10591
        goto exit;
10592
    }
10593
    if (!path_converter(args[0], &filepath)) {
10594
        goto exit;
10595
    }
10596
    if (!noptargs) {
10597
        goto skip_optional_pos;
10598
    }
10599
    if (args[1]) {
10600
        if (!PyUnicode_Check(args[1])) {
10601
            _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]);
10602
            goto exit;
10603
        }
10604
        operation = PyUnicode_AsWideCharString(args[1], NULL);
10605
        if (operation == NULL) {
10606
            goto exit;
10607
        }
10608
        if (!--noptargs) {
10609
            goto skip_optional_pos;
10610
        }
10611
    }
10612
    if (args[2]) {
10613
        if (!PyUnicode_Check(args[2])) {
10614
            _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]);
10615
            goto exit;
10616
        }
10617
        arguments = PyUnicode_AsWideCharString(args[2], NULL);
10618
        if (arguments == NULL) {
10619
            goto exit;
10620
        }
10621
        if (!--noptargs) {
10622
            goto skip_optional_pos;
10623
        }
10624
    }
10625
    if (args[3]) {
10626
        if (!path_converter(args[3], &cwd)) {
10627
            goto exit;
10628
        }
10629
        if (!--noptargs) {
10630
            goto skip_optional_pos;
10631
        }
10632
    }
10633
    show_cmd = PyLong_AsInt(args[4]);
10634
    if (show_cmd == -1 && PyErr_Occurred()) {
10635
        goto exit;
10636
    }
10637
skip_optional_pos:
10638
    return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd);
10639
10640
exit:
10641
    /* Cleanup for filepath */
10642
    path_cleanup(&filepath);
10643
    /* Cleanup for operation */
10644
    PyMem_Free((void *)operation);
10645
    /* Cleanup for arguments */
10646
    PyMem_Free((void *)arguments);
10647
    /* Cleanup for cwd */
10648
    path_cleanup(&cwd);
10649
10650
    return return_value;
10651
}
10652
10653
#endif /* defined(MS_WINDOWS) */
10654
10655
#if defined(HAVE_GETLOADAVG)
10656
10657
PyDoc_STRVAR(os_getloadavg__doc__,
10658
"getloadavg($module, /)\n"
10659
"--\n"
10660
"\n"
10661
"Return average recent system load information.\n"
10662
"\n"
10663
"Return the number of processes in the system run queue averaged over\n"
10664
"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
10665
"Raises OSError if the load average was unobtainable.");
10666
10667
#define OS_GETLOADAVG_METHODDEF    \
10668
    {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
10669
10670
static PyObject *
10671
os_getloadavg_impl(PyObject *module);
10672
10673
static PyObject *
10674
os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
10675
0
{
10676
0
    return os_getloadavg_impl(module);
10677
0
}
10678
10679
#endif /* defined(HAVE_GETLOADAVG) */
10680
10681
PyDoc_STRVAR(os_device_encoding__doc__,
10682
"device_encoding($module, /, fd)\n"
10683
"--\n"
10684
"\n"
10685
"Return a string describing the encoding of a terminal\'s file descriptor.\n"
10686
"\n"
10687
"The file descriptor must be attached to a terminal.\n"
10688
"If the device is not a terminal, return None.");
10689
10690
#define OS_DEVICE_ENCODING_METHODDEF    \
10691
    {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
10692
10693
static PyObject *
10694
os_device_encoding_impl(PyObject *module, int fd);
10695
10696
static PyObject *
10697
os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10698
0
{
10699
0
    PyObject *return_value = NULL;
10700
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10701
10702
0
    #define NUM_KEYWORDS 1
10703
0
    static struct {
10704
0
        PyGC_Head _this_is_not_used;
10705
0
        PyObject_VAR_HEAD
10706
0
        Py_hash_t ob_hash;
10707
0
        PyObject *ob_item[NUM_KEYWORDS];
10708
0
    } _kwtuple = {
10709
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10710
0
        .ob_hash = -1,
10711
0
        .ob_item = { &_Py_ID(fd), },
10712
0
    };
10713
0
    #undef NUM_KEYWORDS
10714
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10715
10716
    #else  // !Py_BUILD_CORE
10717
    #  define KWTUPLE NULL
10718
    #endif  // !Py_BUILD_CORE
10719
10720
0
    static const char * const _keywords[] = {"fd", NULL};
10721
0
    static _PyArg_Parser _parser = {
10722
0
        .keywords = _keywords,
10723
0
        .fname = "device_encoding",
10724
0
        .kwtuple = KWTUPLE,
10725
0
    };
10726
0
    #undef KWTUPLE
10727
0
    PyObject *argsbuf[1];
10728
0
    int fd;
10729
10730
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10731
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10732
0
    if (!args) {
10733
0
        goto exit;
10734
0
    }
10735
0
    fd = PyLong_AsInt(args[0]);
10736
0
    if (fd == -1 && PyErr_Occurred()) {
10737
0
        goto exit;
10738
0
    }
10739
0
    return_value = os_device_encoding_impl(module, fd);
10740
10741
0
exit:
10742
0
    return return_value;
10743
0
}
10744
10745
#if defined(HAVE_SETRESUID)
10746
10747
PyDoc_STRVAR(os_setresuid__doc__,
10748
"setresuid($module, ruid, euid, suid, /)\n"
10749
"--\n"
10750
"\n"
10751
"Set the current process\'s real, effective, and saved user ids.");
10752
10753
#define OS_SETRESUID_METHODDEF    \
10754
    {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__},
10755
10756
static PyObject *
10757
os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
10758
10759
static PyObject *
10760
os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10761
0
{
10762
0
    PyObject *return_value = NULL;
10763
0
    uid_t ruid;
10764
0
    uid_t euid;
10765
0
    uid_t suid;
10766
10767
0
    if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
10768
0
        goto exit;
10769
0
    }
10770
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
10771
0
        goto exit;
10772
0
    }
10773
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
10774
0
        goto exit;
10775
0
    }
10776
0
    if (!_Py_Uid_Converter(args[2], &suid)) {
10777
0
        goto exit;
10778
0
    }
10779
0
    return_value = os_setresuid_impl(module, ruid, euid, suid);
10780
10781
0
exit:
10782
0
    return return_value;
10783
0
}
10784
10785
#endif /* defined(HAVE_SETRESUID) */
10786
10787
#if defined(HAVE_SETRESGID)
10788
10789
PyDoc_STRVAR(os_setresgid__doc__,
10790
"setresgid($module, rgid, egid, sgid, /)\n"
10791
"--\n"
10792
"\n"
10793
"Set the current process\'s real, effective, and saved group ids.");
10794
10795
#define OS_SETRESGID_METHODDEF    \
10796
    {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__},
10797
10798
static PyObject *
10799
os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
10800
10801
static PyObject *
10802
os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10803
0
{
10804
0
    PyObject *return_value = NULL;
10805
0
    gid_t rgid;
10806
0
    gid_t egid;
10807
0
    gid_t sgid;
10808
10809
0
    if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
10810
0
        goto exit;
10811
0
    }
10812
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
10813
0
        goto exit;
10814
0
    }
10815
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
10816
0
        goto exit;
10817
0
    }
10818
0
    if (!_Py_Gid_Converter(args[2], &sgid)) {
10819
0
        goto exit;
10820
0
    }
10821
0
    return_value = os_setresgid_impl(module, rgid, egid, sgid);
10822
10823
0
exit:
10824
0
    return return_value;
10825
0
}
10826
10827
#endif /* defined(HAVE_SETRESGID) */
10828
10829
#if defined(HAVE_GETRESUID)
10830
10831
PyDoc_STRVAR(os_getresuid__doc__,
10832
"getresuid($module, /)\n"
10833
"--\n"
10834
"\n"
10835
"Return a tuple of the current process\'s real, effective, and saved user ids.");
10836
10837
#define OS_GETRESUID_METHODDEF    \
10838
    {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
10839
10840
static PyObject *
10841
os_getresuid_impl(PyObject *module);
10842
10843
static PyObject *
10844
os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
10845
0
{
10846
0
    return os_getresuid_impl(module);
10847
0
}
10848
10849
#endif /* defined(HAVE_GETRESUID) */
10850
10851
#if defined(HAVE_GETRESGID)
10852
10853
PyDoc_STRVAR(os_getresgid__doc__,
10854
"getresgid($module, /)\n"
10855
"--\n"
10856
"\n"
10857
"Return a tuple of the current process\'s real, effective, and saved group ids.");
10858
10859
#define OS_GETRESGID_METHODDEF    \
10860
    {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
10861
10862
static PyObject *
10863
os_getresgid_impl(PyObject *module);
10864
10865
static PyObject *
10866
os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
10867
0
{
10868
0
    return os_getresgid_impl(module);
10869
0
}
10870
10871
#endif /* defined(HAVE_GETRESGID) */
10872
10873
#if defined(USE_XATTRS)
10874
10875
PyDoc_STRVAR(os_getxattr__doc__,
10876
"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
10877
"--\n"
10878
"\n"
10879
"Return the value of extended attribute attribute on path.\n"
10880
"\n"
10881
"path may be either a string, a path-like object, or an open file descriptor.\n"
10882
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
10883
"  link, getxattr will examine the symbolic link itself instead of the file\n"
10884
"  the link points to.");
10885
10886
#define OS_GETXATTR_METHODDEF    \
10887
    {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
10888
10889
static PyObject *
10890
os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
10891
                 int follow_symlinks);
10892
10893
static PyObject *
10894
os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10895
0
{
10896
0
    PyObject *return_value = NULL;
10897
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10898
10899
0
    #define NUM_KEYWORDS 3
10900
0
    static struct {
10901
0
        PyGC_Head _this_is_not_used;
10902
0
        PyObject_VAR_HEAD
10903
0
        Py_hash_t ob_hash;
10904
0
        PyObject *ob_item[NUM_KEYWORDS];
10905
0
    } _kwtuple = {
10906
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10907
0
        .ob_hash = -1,
10908
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
10909
0
    };
10910
0
    #undef NUM_KEYWORDS
10911
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10912
10913
    #else  // !Py_BUILD_CORE
10914
    #  define KWTUPLE NULL
10915
    #endif  // !Py_BUILD_CORE
10916
10917
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
10918
0
    static _PyArg_Parser _parser = {
10919
0
        .keywords = _keywords,
10920
0
        .fname = "getxattr",
10921
0
        .kwtuple = KWTUPLE,
10922
0
    };
10923
0
    #undef KWTUPLE
10924
0
    PyObject *argsbuf[3];
10925
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
10926
0
    path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1);
10927
0
    path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0);
10928
0
    int follow_symlinks = 1;
10929
10930
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10931
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10932
0
    if (!args) {
10933
0
        goto exit;
10934
0
    }
10935
0
    if (!path_converter(args[0], &path)) {
10936
0
        goto exit;
10937
0
    }
10938
0
    if (!path_converter(args[1], &attribute)) {
10939
0
        goto exit;
10940
0
    }
10941
0
    if (!noptargs) {
10942
0
        goto skip_optional_kwonly;
10943
0
    }
10944
0
    follow_symlinks = PyObject_IsTrue(args[2]);
10945
0
    if (follow_symlinks < 0) {
10946
0
        goto exit;
10947
0
    }
10948
0
skip_optional_kwonly:
10949
0
    return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
10950
10951
0
exit:
10952
    /* Cleanup for path */
10953
0
    path_cleanup(&path);
10954
    /* Cleanup for attribute */
10955
0
    path_cleanup(&attribute);
10956
10957
0
    return return_value;
10958
0
}
10959
10960
#endif /* defined(USE_XATTRS) */
10961
10962
#if defined(USE_XATTRS)
10963
10964
PyDoc_STRVAR(os_setxattr__doc__,
10965
"setxattr($module, /, path, attribute, value, flags=0, *,\n"
10966
"         follow_symlinks=True)\n"
10967
"--\n"
10968
"\n"
10969
"Set extended attribute attribute on path to value.\n"
10970
"\n"
10971
"path may be either a string, a path-like object,  or an open file descriptor.\n"
10972
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
10973
"  link, setxattr will modify the symbolic link itself instead of the file\n"
10974
"  the link points to.");
10975
10976
#define OS_SETXATTR_METHODDEF    \
10977
    {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
10978
10979
static PyObject *
10980
os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
10981
                 Py_buffer *value, int flags, int follow_symlinks);
10982
10983
static PyObject *
10984
os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10985
0
{
10986
0
    PyObject *return_value = NULL;
10987
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10988
10989
0
    #define NUM_KEYWORDS 5
10990
0
    static struct {
10991
0
        PyGC_Head _this_is_not_used;
10992
0
        PyObject_VAR_HEAD
10993
0
        Py_hash_t ob_hash;
10994
0
        PyObject *ob_item[NUM_KEYWORDS];
10995
0
    } _kwtuple = {
10996
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10997
0
        .ob_hash = -1,
10998
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
10999
0
    };
11000
0
    #undef NUM_KEYWORDS
11001
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11002
11003
    #else  // !Py_BUILD_CORE
11004
    #  define KWTUPLE NULL
11005
    #endif  // !Py_BUILD_CORE
11006
11007
0
    static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
11008
0
    static _PyArg_Parser _parser = {
11009
0
        .keywords = _keywords,
11010
0
        .fname = "setxattr",
11011
0
        .kwtuple = KWTUPLE,
11012
0
    };
11013
0
    #undef KWTUPLE
11014
0
    PyObject *argsbuf[5];
11015
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
11016
0
    path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1);
11017
0
    path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0);
11018
0
    Py_buffer value = {NULL, NULL};
11019
0
    int flags = 0;
11020
0
    int follow_symlinks = 1;
11021
11022
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11023
0
            /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11024
0
    if (!args) {
11025
0
        goto exit;
11026
0
    }
11027
0
    if (!path_converter(args[0], &path)) {
11028
0
        goto exit;
11029
0
    }
11030
0
    if (!path_converter(args[1], &attribute)) {
11031
0
        goto exit;
11032
0
    }
11033
0
    if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
11034
0
        goto exit;
11035
0
    }
11036
0
    if (!noptargs) {
11037
0
        goto skip_optional_pos;
11038
0
    }
11039
0
    if (args[3]) {
11040
0
        flags = PyLong_AsInt(args[3]);
11041
0
        if (flags == -1 && PyErr_Occurred()) {
11042
0
            goto exit;
11043
0
        }
11044
0
        if (!--noptargs) {
11045
0
            goto skip_optional_pos;
11046
0
        }
11047
0
    }
11048
0
skip_optional_pos:
11049
0
    if (!noptargs) {
11050
0
        goto skip_optional_kwonly;
11051
0
    }
11052
0
    follow_symlinks = PyObject_IsTrue(args[4]);
11053
0
    if (follow_symlinks < 0) {
11054
0
        goto exit;
11055
0
    }
11056
0
skip_optional_kwonly:
11057
0
    return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
11058
11059
0
exit:
11060
    /* Cleanup for path */
11061
0
    path_cleanup(&path);
11062
    /* Cleanup for attribute */
11063
0
    path_cleanup(&attribute);
11064
    /* Cleanup for value */
11065
0
    if (value.obj) {
11066
0
       PyBuffer_Release(&value);
11067
0
    }
11068
11069
0
    return return_value;
11070
0
}
11071
11072
#endif /* defined(USE_XATTRS) */
11073
11074
#if defined(USE_XATTRS)
11075
11076
PyDoc_STRVAR(os_removexattr__doc__,
11077
"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
11078
"--\n"
11079
"\n"
11080
"Remove extended attribute attribute on path.\n"
11081
"\n"
11082
"path may be either a string, a path-like object, or an open file descriptor.\n"
11083
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
11084
"  link, removexattr will modify the symbolic link itself instead of the file\n"
11085
"  the link points to.");
11086
11087
#define OS_REMOVEXATTR_METHODDEF    \
11088
    {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
11089
11090
static PyObject *
11091
os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
11092
                    int follow_symlinks);
11093
11094
static PyObject *
11095
os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11096
0
{
11097
0
    PyObject *return_value = NULL;
11098
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11099
11100
0
    #define NUM_KEYWORDS 3
11101
0
    static struct {
11102
0
        PyGC_Head _this_is_not_used;
11103
0
        PyObject_VAR_HEAD
11104
0
        Py_hash_t ob_hash;
11105
0
        PyObject *ob_item[NUM_KEYWORDS];
11106
0
    } _kwtuple = {
11107
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11108
0
        .ob_hash = -1,
11109
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
11110
0
    };
11111
0
    #undef NUM_KEYWORDS
11112
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11113
11114
    #else  // !Py_BUILD_CORE
11115
    #  define KWTUPLE NULL
11116
    #endif  // !Py_BUILD_CORE
11117
11118
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
11119
0
    static _PyArg_Parser _parser = {
11120
0
        .keywords = _keywords,
11121
0
        .fname = "removexattr",
11122
0
        .kwtuple = KWTUPLE,
11123
0
    };
11124
0
    #undef KWTUPLE
11125
0
    PyObject *argsbuf[3];
11126
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
11127
0
    path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1);
11128
0
    path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0);
11129
0
    int follow_symlinks = 1;
11130
11131
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11132
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11133
0
    if (!args) {
11134
0
        goto exit;
11135
0
    }
11136
0
    if (!path_converter(args[0], &path)) {
11137
0
        goto exit;
11138
0
    }
11139
0
    if (!path_converter(args[1], &attribute)) {
11140
0
        goto exit;
11141
0
    }
11142
0
    if (!noptargs) {
11143
0
        goto skip_optional_kwonly;
11144
0
    }
11145
0
    follow_symlinks = PyObject_IsTrue(args[2]);
11146
0
    if (follow_symlinks < 0) {
11147
0
        goto exit;
11148
0
    }
11149
0
skip_optional_kwonly:
11150
0
    return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
11151
11152
0
exit:
11153
    /* Cleanup for path */
11154
0
    path_cleanup(&path);
11155
    /* Cleanup for attribute */
11156
0
    path_cleanup(&attribute);
11157
11158
0
    return return_value;
11159
0
}
11160
11161
#endif /* defined(USE_XATTRS) */
11162
11163
#if defined(USE_XATTRS)
11164
11165
PyDoc_STRVAR(os_listxattr__doc__,
11166
"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
11167
"--\n"
11168
"\n"
11169
"Return a list of extended attributes on path.\n"
11170
"\n"
11171
"path may be either None, a string, a path-like object, or an open file descriptor.\n"
11172
"if path is None, listxattr will examine the current directory.\n"
11173
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
11174
"  link, listxattr will examine the symbolic link itself instead of the file\n"
11175
"  the link points to.");
11176
11177
#define OS_LISTXATTR_METHODDEF    \
11178
    {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
11179
11180
static PyObject *
11181
os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
11182
11183
static PyObject *
11184
os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11185
0
{
11186
0
    PyObject *return_value = NULL;
11187
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11188
11189
0
    #define NUM_KEYWORDS 2
11190
0
    static struct {
11191
0
        PyGC_Head _this_is_not_used;
11192
0
        PyObject_VAR_HEAD
11193
0
        Py_hash_t ob_hash;
11194
0
        PyObject *ob_item[NUM_KEYWORDS];
11195
0
    } _kwtuple = {
11196
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11197
0
        .ob_hash = -1,
11198
0
        .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), },
11199
0
    };
11200
0
    #undef NUM_KEYWORDS
11201
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11202
11203
    #else  // !Py_BUILD_CORE
11204
    #  define KWTUPLE NULL
11205
    #endif  // !Py_BUILD_CORE
11206
11207
0
    static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
11208
0
    static _PyArg_Parser _parser = {
11209
0
        .keywords = _keywords,
11210
0
        .fname = "listxattr",
11211
0
        .kwtuple = KWTUPLE,
11212
0
    };
11213
0
    #undef KWTUPLE
11214
0
    PyObject *argsbuf[2];
11215
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
11216
0
    path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1);
11217
0
    int follow_symlinks = 1;
11218
11219
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11220
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11221
0
    if (!args) {
11222
0
        goto exit;
11223
0
    }
11224
0
    if (!noptargs) {
11225
0
        goto skip_optional_pos;
11226
0
    }
11227
0
    if (args[0]) {
11228
0
        if (!path_converter(args[0], &path)) {
11229
0
            goto exit;
11230
0
        }
11231
0
        if (!--noptargs) {
11232
0
            goto skip_optional_pos;
11233
0
        }
11234
0
    }
11235
0
skip_optional_pos:
11236
0
    if (!noptargs) {
11237
0
        goto skip_optional_kwonly;
11238
0
    }
11239
0
    follow_symlinks = PyObject_IsTrue(args[1]);
11240
0
    if (follow_symlinks < 0) {
11241
0
        goto exit;
11242
0
    }
11243
0
skip_optional_kwonly:
11244
0
    return_value = os_listxattr_impl(module, &path, follow_symlinks);
11245
11246
0
exit:
11247
    /* Cleanup for path */
11248
0
    path_cleanup(&path);
11249
11250
0
    return return_value;
11251
0
}
11252
11253
#endif /* defined(USE_XATTRS) */
11254
11255
PyDoc_STRVAR(os_urandom__doc__,
11256
"urandom($module, size, /)\n"
11257
"--\n"
11258
"\n"
11259
"Return a bytes object containing random bytes suitable for cryptographic use.");
11260
11261
#define OS_URANDOM_METHODDEF    \
11262
    {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
11263
11264
static PyObject *
11265
os_urandom_impl(PyObject *module, Py_ssize_t size);
11266
11267
static PyObject *
11268
os_urandom(PyObject *module, PyObject *arg)
11269
0
{
11270
0
    PyObject *return_value = NULL;
11271
0
    Py_ssize_t size;
11272
11273
0
    {
11274
0
        Py_ssize_t ival = -1;
11275
0
        PyObject *iobj = _PyNumber_Index(arg);
11276
0
        if (iobj != NULL) {
11277
0
            ival = PyLong_AsSsize_t(iobj);
11278
0
            Py_DECREF(iobj);
11279
0
        }
11280
0
        if (ival == -1 && PyErr_Occurred()) {
11281
0
            goto exit;
11282
0
        }
11283
0
        size = ival;
11284
0
        if (size < 0) {
11285
0
            PyErr_SetString(PyExc_ValueError,
11286
0
                            "size cannot be negative");
11287
0
            goto exit;
11288
0
        }
11289
0
    }
11290
0
    return_value = os_urandom_impl(module, size);
11291
11292
0
exit:
11293
0
    return return_value;
11294
0
}
11295
11296
#if defined(HAVE_MEMFD_CREATE)
11297
11298
PyDoc_STRVAR(os_memfd_create__doc__,
11299
"memfd_create($module, /, name, flags=MFD_CLOEXEC)\n"
11300
"--\n"
11301
"\n");
11302
11303
#define OS_MEMFD_CREATE_METHODDEF    \
11304
    {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__},
11305
11306
static PyObject *
11307
os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags);
11308
11309
static PyObject *
11310
os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11311
0
{
11312
0
    PyObject *return_value = NULL;
11313
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11314
11315
0
    #define NUM_KEYWORDS 2
11316
0
    static struct {
11317
0
        PyGC_Head _this_is_not_used;
11318
0
        PyObject_VAR_HEAD
11319
0
        Py_hash_t ob_hash;
11320
0
        PyObject *ob_item[NUM_KEYWORDS];
11321
0
    } _kwtuple = {
11322
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11323
0
        .ob_hash = -1,
11324
0
        .ob_item = { &_Py_ID(name), &_Py_ID(flags), },
11325
0
    };
11326
0
    #undef NUM_KEYWORDS
11327
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11328
11329
    #else  // !Py_BUILD_CORE
11330
    #  define KWTUPLE NULL
11331
    #endif  // !Py_BUILD_CORE
11332
11333
0
    static const char * const _keywords[] = {"name", "flags", NULL};
11334
0
    static _PyArg_Parser _parser = {
11335
0
        .keywords = _keywords,
11336
0
        .fname = "memfd_create",
11337
0
        .kwtuple = KWTUPLE,
11338
0
    };
11339
0
    #undef KWTUPLE
11340
0
    PyObject *argsbuf[2];
11341
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11342
0
    PyObject *name = NULL;
11343
0
    unsigned int flags = MFD_CLOEXEC;
11344
11345
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11346
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11347
0
    if (!args) {
11348
0
        goto exit;
11349
0
    }
11350
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
11351
0
        goto exit;
11352
0
    }
11353
0
    if (!noptargs) {
11354
0
        goto skip_optional_pos;
11355
0
    }
11356
0
    {
11357
0
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned int),
11358
0
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
11359
0
                Py_ASNATIVEBYTES_ALLOW_INDEX |
11360
0
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
11361
0
        if (_bytes < 0) {
11362
0
            goto exit;
11363
0
        }
11364
0
        if ((size_t)_bytes > sizeof(unsigned int)) {
11365
0
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
11366
0
                "integer value out of range", 1) < 0)
11367
0
            {
11368
0
                goto exit;
11369
0
            }
11370
0
        }
11371
0
    }
11372
0
skip_optional_pos:
11373
0
    return_value = os_memfd_create_impl(module, name, flags);
11374
11375
0
exit:
11376
    /* Cleanup for name */
11377
0
    Py_XDECREF(name);
11378
11379
0
    return return_value;
11380
0
}
11381
11382
#endif /* defined(HAVE_MEMFD_CREATE) */
11383
11384
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11385
11386
PyDoc_STRVAR(os_eventfd__doc__,
11387
"eventfd($module, /, initval, flags=EFD_CLOEXEC)\n"
11388
"--\n"
11389
"\n"
11390
"Creates and returns an event notification file descriptor.");
11391
11392
#define OS_EVENTFD_METHODDEF    \
11393
    {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__},
11394
11395
static PyObject *
11396
os_eventfd_impl(PyObject *module, unsigned int initval, int flags);
11397
11398
static PyObject *
11399
os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11400
0
{
11401
0
    PyObject *return_value = NULL;
11402
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11403
11404
0
    #define NUM_KEYWORDS 2
11405
0
    static struct {
11406
0
        PyGC_Head _this_is_not_used;
11407
0
        PyObject_VAR_HEAD
11408
0
        Py_hash_t ob_hash;
11409
0
        PyObject *ob_item[NUM_KEYWORDS];
11410
0
    } _kwtuple = {
11411
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11412
0
        .ob_hash = -1,
11413
0
        .ob_item = { &_Py_ID(initval), &_Py_ID(flags), },
11414
0
    };
11415
0
    #undef NUM_KEYWORDS
11416
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11417
11418
    #else  // !Py_BUILD_CORE
11419
    #  define KWTUPLE NULL
11420
    #endif  // !Py_BUILD_CORE
11421
11422
0
    static const char * const _keywords[] = {"initval", "flags", NULL};
11423
0
    static _PyArg_Parser _parser = {
11424
0
        .keywords = _keywords,
11425
0
        .fname = "eventfd",
11426
0
        .kwtuple = KWTUPLE,
11427
0
    };
11428
0
    #undef KWTUPLE
11429
0
    PyObject *argsbuf[2];
11430
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11431
0
    unsigned int initval;
11432
0
    int flags = EFD_CLOEXEC;
11433
11434
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11435
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11436
0
    if (!args) {
11437
0
        goto exit;
11438
0
    }
11439
0
    if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) {
11440
0
        goto exit;
11441
0
    }
11442
0
    if (!noptargs) {
11443
0
        goto skip_optional_pos;
11444
0
    }
11445
0
    flags = PyLong_AsInt(args[1]);
11446
0
    if (flags == -1 && PyErr_Occurred()) {
11447
0
        goto exit;
11448
0
    }
11449
0
skip_optional_pos:
11450
0
    return_value = os_eventfd_impl(module, initval, flags);
11451
11452
0
exit:
11453
0
    return return_value;
11454
0
}
11455
11456
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11457
11458
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11459
11460
PyDoc_STRVAR(os_eventfd_read__doc__,
11461
"eventfd_read($module, /, fd)\n"
11462
"--\n"
11463
"\n"
11464
"Read eventfd value");
11465
11466
#define OS_EVENTFD_READ_METHODDEF    \
11467
    {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__},
11468
11469
static PyObject *
11470
os_eventfd_read_impl(PyObject *module, int fd);
11471
11472
static PyObject *
11473
os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11474
0
{
11475
0
    PyObject *return_value = NULL;
11476
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11477
11478
0
    #define NUM_KEYWORDS 1
11479
0
    static struct {
11480
0
        PyGC_Head _this_is_not_used;
11481
0
        PyObject_VAR_HEAD
11482
0
        Py_hash_t ob_hash;
11483
0
        PyObject *ob_item[NUM_KEYWORDS];
11484
0
    } _kwtuple = {
11485
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11486
0
        .ob_hash = -1,
11487
0
        .ob_item = { &_Py_ID(fd), },
11488
0
    };
11489
0
    #undef NUM_KEYWORDS
11490
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11491
11492
    #else  // !Py_BUILD_CORE
11493
    #  define KWTUPLE NULL
11494
    #endif  // !Py_BUILD_CORE
11495
11496
0
    static const char * const _keywords[] = {"fd", NULL};
11497
0
    static _PyArg_Parser _parser = {
11498
0
        .keywords = _keywords,
11499
0
        .fname = "eventfd_read",
11500
0
        .kwtuple = KWTUPLE,
11501
0
    };
11502
0
    #undef KWTUPLE
11503
0
    PyObject *argsbuf[1];
11504
0
    int fd;
11505
11506
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11507
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11508
0
    if (!args) {
11509
0
        goto exit;
11510
0
    }
11511
0
    fd = PyObject_AsFileDescriptor(args[0]);
11512
0
    if (fd < 0) {
11513
0
        goto exit;
11514
0
    }
11515
0
    return_value = os_eventfd_read_impl(module, fd);
11516
11517
0
exit:
11518
0
    return return_value;
11519
0
}
11520
11521
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11522
11523
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11524
11525
PyDoc_STRVAR(os_eventfd_write__doc__,
11526
"eventfd_write($module, /, fd, value)\n"
11527
"--\n"
11528
"\n"
11529
"Write eventfd value.");
11530
11531
#define OS_EVENTFD_WRITE_METHODDEF    \
11532
    {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__},
11533
11534
static PyObject *
11535
os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value);
11536
11537
static PyObject *
11538
os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11539
0
{
11540
0
    PyObject *return_value = NULL;
11541
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11542
11543
0
    #define NUM_KEYWORDS 2
11544
0
    static struct {
11545
0
        PyGC_Head _this_is_not_used;
11546
0
        PyObject_VAR_HEAD
11547
0
        Py_hash_t ob_hash;
11548
0
        PyObject *ob_item[NUM_KEYWORDS];
11549
0
    } _kwtuple = {
11550
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11551
0
        .ob_hash = -1,
11552
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(value), },
11553
0
    };
11554
0
    #undef NUM_KEYWORDS
11555
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11556
11557
    #else  // !Py_BUILD_CORE
11558
    #  define KWTUPLE NULL
11559
    #endif  // !Py_BUILD_CORE
11560
11561
0
    static const char * const _keywords[] = {"fd", "value", NULL};
11562
0
    static _PyArg_Parser _parser = {
11563
0
        .keywords = _keywords,
11564
0
        .fname = "eventfd_write",
11565
0
        .kwtuple = KWTUPLE,
11566
0
    };
11567
0
    #undef KWTUPLE
11568
0
    PyObject *argsbuf[2];
11569
0
    int fd;
11570
0
    unsigned long long value;
11571
11572
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11573
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11574
0
    if (!args) {
11575
0
        goto exit;
11576
0
    }
11577
0
    fd = PyObject_AsFileDescriptor(args[0]);
11578
0
    if (fd < 0) {
11579
0
        goto exit;
11580
0
    }
11581
0
    if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) {
11582
0
        goto exit;
11583
0
    }
11584
0
    return_value = os_eventfd_write_impl(module, fd, value);
11585
11586
0
exit:
11587
0
    return return_value;
11588
0
}
11589
11590
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11591
11592
#if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL))
11593
11594
PyDoc_STRVAR(os_get_terminal_size__doc__,
11595
"get_terminal_size($module, fd=<unrepresentable>, /)\n"
11596
"--\n"
11597
"\n"
11598
"Return the size of the terminal window as (columns, lines).\n"
11599
"\n"
11600
"The optional argument fd (default standard output) specifies\n"
11601
"which file descriptor should be queried.\n"
11602
"\n"
11603
"If the file descriptor is not connected to a terminal, an OSError\n"
11604
"is thrown.\n"
11605
"\n"
11606
"This function will only be defined if an implementation is\n"
11607
"available for this system.\n"
11608
"\n"
11609
"shutil.get_terminal_size is the high-level function which should\n"
11610
"normally be used, os.get_terminal_size is the low-level implementation.");
11611
11612
#define OS_GET_TERMINAL_SIZE_METHODDEF    \
11613
    {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__},
11614
11615
static PyObject *
11616
os_get_terminal_size_impl(PyObject *module, int fd);
11617
11618
static PyObject *
11619
os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11620
0
{
11621
0
    PyObject *return_value = NULL;
11622
0
    int fd = fileno(stdout);
11623
11624
0
    if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) {
11625
0
        goto exit;
11626
0
    }
11627
0
    if (nargs < 1) {
11628
0
        goto skip_optional;
11629
0
    }
11630
0
    fd = PyLong_AsInt(args[0]);
11631
0
    if (fd == -1 && PyErr_Occurred()) {
11632
0
        goto exit;
11633
0
    }
11634
0
skip_optional:
11635
0
    return_value = os_get_terminal_size_impl(module, fd);
11636
11637
0
exit:
11638
0
    return return_value;
11639
0
}
11640
11641
#endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */
11642
11643
PyDoc_STRVAR(os_cpu_count__doc__,
11644
"cpu_count($module, /)\n"
11645
"--\n"
11646
"\n"
11647
"Return the number of logical CPUs in the system.\n"
11648
"\n"
11649
"Return None if indeterminable.");
11650
11651
#define OS_CPU_COUNT_METHODDEF    \
11652
    {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
11653
11654
static PyObject *
11655
os_cpu_count_impl(PyObject *module);
11656
11657
static PyObject *
11658
os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
11659
0
{
11660
0
    return os_cpu_count_impl(module);
11661
0
}
11662
11663
PyDoc_STRVAR(os_get_inheritable__doc__,
11664
"get_inheritable($module, fd, /)\n"
11665
"--\n"
11666
"\n"
11667
"Get the close-on-exe flag of the specified file descriptor.");
11668
11669
#define OS_GET_INHERITABLE_METHODDEF    \
11670
    {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
11671
11672
static int
11673
os_get_inheritable_impl(PyObject *module, int fd);
11674
11675
static PyObject *
11676
os_get_inheritable(PyObject *module, PyObject *arg)
11677
0
{
11678
0
    PyObject *return_value = NULL;
11679
0
    int fd;
11680
0
    int _return_value;
11681
11682
0
    fd = PyLong_AsInt(arg);
11683
0
    if (fd == -1 && PyErr_Occurred()) {
11684
0
        goto exit;
11685
0
    }
11686
0
    _return_value = os_get_inheritable_impl(module, fd);
11687
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11688
0
        goto exit;
11689
0
    }
11690
0
    return_value = PyBool_FromLong((long)_return_value);
11691
11692
0
exit:
11693
0
    return return_value;
11694
0
}
11695
11696
PyDoc_STRVAR(os_set_inheritable__doc__,
11697
"set_inheritable($module, fd, inheritable, /)\n"
11698
"--\n"
11699
"\n"
11700
"Set the inheritable flag of the specified file descriptor.");
11701
11702
#define OS_SET_INHERITABLE_METHODDEF    \
11703
    {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__},
11704
11705
static PyObject *
11706
os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
11707
11708
static PyObject *
11709
os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11710
0
{
11711
0
    PyObject *return_value = NULL;
11712
0
    int fd;
11713
0
    int inheritable;
11714
11715
0
    if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
11716
0
        goto exit;
11717
0
    }
11718
0
    fd = PyLong_AsInt(args[0]);
11719
0
    if (fd == -1 && PyErr_Occurred()) {
11720
0
        goto exit;
11721
0
    }
11722
0
    inheritable = PyLong_AsInt(args[1]);
11723
0
    if (inheritable == -1 && PyErr_Occurred()) {
11724
0
        goto exit;
11725
0
    }
11726
0
    return_value = os_set_inheritable_impl(module, fd, inheritable);
11727
11728
0
exit:
11729
0
    return return_value;
11730
0
}
11731
11732
#if defined(MS_WINDOWS)
11733
11734
PyDoc_STRVAR(os_get_handle_inheritable__doc__,
11735
"get_handle_inheritable($module, handle, /)\n"
11736
"--\n"
11737
"\n"
11738
"Get the close-on-exe flag of the specified file descriptor.");
11739
11740
#define OS_GET_HANDLE_INHERITABLE_METHODDEF    \
11741
    {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
11742
11743
static int
11744
os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
11745
11746
static PyObject *
11747
os_get_handle_inheritable(PyObject *module, PyObject *arg)
11748
{
11749
    PyObject *return_value = NULL;
11750
    intptr_t handle;
11751
    int _return_value;
11752
11753
    handle = (intptr_t)PyLong_AsVoidPtr(arg);
11754
    if (!handle && PyErr_Occurred()) {
11755
        goto exit;
11756
    }
11757
    _return_value = os_get_handle_inheritable_impl(module, handle);
11758
    if ((_return_value == -1) && PyErr_Occurred()) {
11759
        goto exit;
11760
    }
11761
    return_value = PyBool_FromLong((long)_return_value);
11762
11763
exit:
11764
    return return_value;
11765
}
11766
11767
#endif /* defined(MS_WINDOWS) */
11768
11769
#if defined(MS_WINDOWS)
11770
11771
PyDoc_STRVAR(os_set_handle_inheritable__doc__,
11772
"set_handle_inheritable($module, handle, inheritable, /)\n"
11773
"--\n"
11774
"\n"
11775
"Set the inheritable flag of the specified handle.");
11776
11777
#define OS_SET_HANDLE_INHERITABLE_METHODDEF    \
11778
    {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__},
11779
11780
static PyObject *
11781
os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
11782
                               int inheritable);
11783
11784
static PyObject *
11785
os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11786
{
11787
    PyObject *return_value = NULL;
11788
    intptr_t handle;
11789
    int inheritable;
11790
11791
    if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) {
11792
        goto exit;
11793
    }
11794
    handle = (intptr_t)PyLong_AsVoidPtr(args[0]);
11795
    if (!handle && PyErr_Occurred()) {
11796
        goto exit;
11797
    }
11798
    inheritable = PyObject_IsTrue(args[1]);
11799
    if (inheritable < 0) {
11800
        goto exit;
11801
    }
11802
    return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
11803
11804
exit:
11805
    return return_value;
11806
}
11807
11808
#endif /* defined(MS_WINDOWS) */
11809
11810
PyDoc_STRVAR(os_get_blocking__doc__,
11811
"get_blocking($module, fd, /)\n"
11812
"--\n"
11813
"\n"
11814
"Get the blocking mode of the file descriptor.\n"
11815
"\n"
11816
"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
11817
11818
#define OS_GET_BLOCKING_METHODDEF    \
11819
    {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
11820
11821
static int
11822
os_get_blocking_impl(PyObject *module, int fd);
11823
11824
static PyObject *
11825
os_get_blocking(PyObject *module, PyObject *arg)
11826
0
{
11827
0
    PyObject *return_value = NULL;
11828
0
    int fd;
11829
0
    int _return_value;
11830
11831
0
    fd = PyLong_AsInt(arg);
11832
0
    if (fd == -1 && PyErr_Occurred()) {
11833
0
        goto exit;
11834
0
    }
11835
0
    _return_value = os_get_blocking_impl(module, fd);
11836
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11837
0
        goto exit;
11838
0
    }
11839
0
    return_value = PyBool_FromLong((long)_return_value);
11840
11841
0
exit:
11842
0
    return return_value;
11843
0
}
11844
11845
PyDoc_STRVAR(os_set_blocking__doc__,
11846
"set_blocking($module, fd, blocking, /)\n"
11847
"--\n"
11848
"\n"
11849
"Set the blocking mode of the specified file descriptor.\n"
11850
"\n"
11851
"Set the O_NONBLOCK flag if blocking is False,\n"
11852
"clear the O_NONBLOCK flag otherwise.");
11853
11854
#define OS_SET_BLOCKING_METHODDEF    \
11855
    {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__},
11856
11857
static PyObject *
11858
os_set_blocking_impl(PyObject *module, int fd, int blocking);
11859
11860
static PyObject *
11861
os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11862
0
{
11863
0
    PyObject *return_value = NULL;
11864
0
    int fd;
11865
0
    int blocking;
11866
11867
0
    if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
11868
0
        goto exit;
11869
0
    }
11870
0
    fd = PyLong_AsInt(args[0]);
11871
0
    if (fd == -1 && PyErr_Occurred()) {
11872
0
        goto exit;
11873
0
    }
11874
0
    blocking = PyObject_IsTrue(args[1]);
11875
0
    if (blocking < 0) {
11876
0
        goto exit;
11877
0
    }
11878
0
    return_value = os_set_blocking_impl(module, fd, blocking);
11879
11880
0
exit:
11881
0
    return return_value;
11882
0
}
11883
11884
PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
11885
"is_symlink($self, /)\n"
11886
"--\n"
11887
"\n"
11888
"Return True if the entry is a symbolic link; cached per entry.");
11889
11890
#define OS_DIRENTRY_IS_SYMLINK_METHODDEF    \
11891
    {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__},
11892
11893
static int
11894
os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class);
11895
11896
static PyObject *
11897
os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11898
0
{
11899
0
    PyObject *return_value = NULL;
11900
0
    int _return_value;
11901
11902
0
    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
11903
0
        PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
11904
0
        goto exit;
11905
0
    }
11906
0
    _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class);
11907
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11908
0
        goto exit;
11909
0
    }
11910
0
    return_value = PyBool_FromLong((long)_return_value);
11911
11912
0
exit:
11913
0
    return return_value;
11914
0
}
11915
11916
PyDoc_STRVAR(os_DirEntry_is_junction__doc__,
11917
"is_junction($self, /)\n"
11918
"--\n"
11919
"\n"
11920
"Return True if the entry is a junction; cached per entry.");
11921
11922
#define OS_DIRENTRY_IS_JUNCTION_METHODDEF    \
11923
    {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__},
11924
11925
static int
11926
os_DirEntry_is_junction_impl(DirEntry *self);
11927
11928
static PyObject *
11929
os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored))
11930
0
{
11931
0
    PyObject *return_value = NULL;
11932
0
    int _return_value;
11933
11934
0
    _return_value = os_DirEntry_is_junction_impl((DirEntry *)self);
11935
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11936
0
        goto exit;
11937
0
    }
11938
0
    return_value = PyBool_FromLong((long)_return_value);
11939
11940
0
exit:
11941
0
    return return_value;
11942
0
}
11943
11944
PyDoc_STRVAR(os_DirEntry_stat__doc__,
11945
"stat($self, /, *, follow_symlinks=True)\n"
11946
"--\n"
11947
"\n"
11948
"Return stat_result object for the entry; cached per entry.");
11949
11950
#define OS_DIRENTRY_STAT_METHODDEF    \
11951
    {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
11952
11953
static PyObject *
11954
os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class,
11955
                      int follow_symlinks);
11956
11957
static PyObject *
11958
os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11959
0
{
11960
0
    PyObject *return_value = NULL;
11961
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11962
11963
0
    #define NUM_KEYWORDS 1
11964
0
    static struct {
11965
0
        PyGC_Head _this_is_not_used;
11966
0
        PyObject_VAR_HEAD
11967
0
        Py_hash_t ob_hash;
11968
0
        PyObject *ob_item[NUM_KEYWORDS];
11969
0
    } _kwtuple = {
11970
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11971
0
        .ob_hash = -1,
11972
0
        .ob_item = { &_Py_ID(follow_symlinks), },
11973
0
    };
11974
0
    #undef NUM_KEYWORDS
11975
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11976
11977
    #else  // !Py_BUILD_CORE
11978
    #  define KWTUPLE NULL
11979
    #endif  // !Py_BUILD_CORE
11980
11981
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
11982
0
    static _PyArg_Parser _parser = {
11983
0
        .keywords = _keywords,
11984
0
        .fname = "stat",
11985
0
        .kwtuple = KWTUPLE,
11986
0
    };
11987
0
    #undef KWTUPLE
11988
0
    PyObject *argsbuf[1];
11989
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
11990
0
    int follow_symlinks = 1;
11991
11992
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11993
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11994
0
    if (!args) {
11995
0
        goto exit;
11996
0
    }
11997
0
    if (!noptargs) {
11998
0
        goto skip_optional_kwonly;
11999
0
    }
12000
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12001
0
    if (follow_symlinks < 0) {
12002
0
        goto exit;
12003
0
    }
12004
0
skip_optional_kwonly:
12005
0
    return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks);
12006
12007
0
exit:
12008
0
    return return_value;
12009
0
}
12010
12011
PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
12012
"is_dir($self, /, *, follow_symlinks=True)\n"
12013
"--\n"
12014
"\n"
12015
"Return True if the entry is a directory; cached per entry.");
12016
12017
#define OS_DIRENTRY_IS_DIR_METHODDEF    \
12018
    {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
12019
12020
static int
12021
os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class,
12022
                        int follow_symlinks);
12023
12024
static PyObject *
12025
os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12026
0
{
12027
0
    PyObject *return_value = NULL;
12028
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12029
12030
0
    #define NUM_KEYWORDS 1
12031
0
    static struct {
12032
0
        PyGC_Head _this_is_not_used;
12033
0
        PyObject_VAR_HEAD
12034
0
        Py_hash_t ob_hash;
12035
0
        PyObject *ob_item[NUM_KEYWORDS];
12036
0
    } _kwtuple = {
12037
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12038
0
        .ob_hash = -1,
12039
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12040
0
    };
12041
0
    #undef NUM_KEYWORDS
12042
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12043
12044
    #else  // !Py_BUILD_CORE
12045
    #  define KWTUPLE NULL
12046
    #endif  // !Py_BUILD_CORE
12047
12048
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12049
0
    static _PyArg_Parser _parser = {
12050
0
        .keywords = _keywords,
12051
0
        .fname = "is_dir",
12052
0
        .kwtuple = KWTUPLE,
12053
0
    };
12054
0
    #undef KWTUPLE
12055
0
    PyObject *argsbuf[1];
12056
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12057
0
    int follow_symlinks = 1;
12058
0
    int _return_value;
12059
12060
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12061
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12062
0
    if (!args) {
12063
0
        goto exit;
12064
0
    }
12065
0
    if (!noptargs) {
12066
0
        goto skip_optional_kwonly;
12067
0
    }
12068
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12069
0
    if (follow_symlinks < 0) {
12070
0
        goto exit;
12071
0
    }
12072
0
skip_optional_kwonly:
12073
0
    _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks);
12074
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12075
0
        goto exit;
12076
0
    }
12077
0
    return_value = PyBool_FromLong((long)_return_value);
12078
12079
0
exit:
12080
0
    return return_value;
12081
0
}
12082
12083
PyDoc_STRVAR(os_DirEntry_is_file__doc__,
12084
"is_file($self, /, *, follow_symlinks=True)\n"
12085
"--\n"
12086
"\n"
12087
"Return True if the entry is a file; cached per entry.");
12088
12089
#define OS_DIRENTRY_IS_FILE_METHODDEF    \
12090
    {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
12091
12092
static int
12093
os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class,
12094
                         int follow_symlinks);
12095
12096
static PyObject *
12097
os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12098
0
{
12099
0
    PyObject *return_value = NULL;
12100
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12101
12102
0
    #define NUM_KEYWORDS 1
12103
0
    static struct {
12104
0
        PyGC_Head _this_is_not_used;
12105
0
        PyObject_VAR_HEAD
12106
0
        Py_hash_t ob_hash;
12107
0
        PyObject *ob_item[NUM_KEYWORDS];
12108
0
    } _kwtuple = {
12109
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12110
0
        .ob_hash = -1,
12111
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12112
0
    };
12113
0
    #undef NUM_KEYWORDS
12114
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12115
12116
    #else  // !Py_BUILD_CORE
12117
    #  define KWTUPLE NULL
12118
    #endif  // !Py_BUILD_CORE
12119
12120
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12121
0
    static _PyArg_Parser _parser = {
12122
0
        .keywords = _keywords,
12123
0
        .fname = "is_file",
12124
0
        .kwtuple = KWTUPLE,
12125
0
    };
12126
0
    #undef KWTUPLE
12127
0
    PyObject *argsbuf[1];
12128
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12129
0
    int follow_symlinks = 1;
12130
0
    int _return_value;
12131
12132
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12133
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12134
0
    if (!args) {
12135
0
        goto exit;
12136
0
    }
12137
0
    if (!noptargs) {
12138
0
        goto skip_optional_kwonly;
12139
0
    }
12140
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12141
0
    if (follow_symlinks < 0) {
12142
0
        goto exit;
12143
0
    }
12144
0
skip_optional_kwonly:
12145
0
    _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks);
12146
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12147
0
        goto exit;
12148
0
    }
12149
0
    return_value = PyBool_FromLong((long)_return_value);
12150
12151
0
exit:
12152
0
    return return_value;
12153
0
}
12154
12155
PyDoc_STRVAR(os_DirEntry_inode__doc__,
12156
"inode($self, /)\n"
12157
"--\n"
12158
"\n"
12159
"Return inode of the entry; cached per entry.");
12160
12161
#define OS_DIRENTRY_INODE_METHODDEF    \
12162
    {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
12163
12164
static PyObject *
12165
os_DirEntry_inode_impl(DirEntry *self);
12166
12167
static PyObject *
12168
os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored))
12169
0
{
12170
0
    return os_DirEntry_inode_impl((DirEntry *)self);
12171
0
}
12172
12173
PyDoc_STRVAR(os_DirEntry___fspath____doc__,
12174
"__fspath__($self, /)\n"
12175
"--\n"
12176
"\n"
12177
"Returns the path for the entry.");
12178
12179
#define OS_DIRENTRY___FSPATH___METHODDEF    \
12180
    {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
12181
12182
static PyObject *
12183
os_DirEntry___fspath___impl(DirEntry *self);
12184
12185
static PyObject *
12186
os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored))
12187
0
{
12188
0
    return os_DirEntry___fspath___impl((DirEntry *)self);
12189
0
}
12190
12191
PyDoc_STRVAR(os_scandir__doc__,
12192
"scandir($module, /, path=None)\n"
12193
"--\n"
12194
"\n"
12195
"Return an iterator of DirEntry objects for given path.\n"
12196
"\n"
12197
"path can be specified as either str, bytes, or a path-like object.  If path\n"
12198
"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
12199
"all other circumstances they will be str.\n"
12200
"\n"
12201
"If path is None, uses the path=\'.\'.");
12202
12203
#define OS_SCANDIR_METHODDEF    \
12204
    {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
12205
12206
static PyObject *
12207
os_scandir_impl(PyObject *module, path_t *path);
12208
12209
static PyObject *
12210
os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12211
0
{
12212
0
    PyObject *return_value = NULL;
12213
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12214
12215
0
    #define NUM_KEYWORDS 1
12216
0
    static struct {
12217
0
        PyGC_Head _this_is_not_used;
12218
0
        PyObject_VAR_HEAD
12219
0
        Py_hash_t ob_hash;
12220
0
        PyObject *ob_item[NUM_KEYWORDS];
12221
0
    } _kwtuple = {
12222
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12223
0
        .ob_hash = -1,
12224
0
        .ob_item = { &_Py_ID(path), },
12225
0
    };
12226
0
    #undef NUM_KEYWORDS
12227
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12228
12229
    #else  // !Py_BUILD_CORE
12230
    #  define KWTUPLE NULL
12231
    #endif  // !Py_BUILD_CORE
12232
12233
0
    static const char * const _keywords[] = {"path", NULL};
12234
0
    static _PyArg_Parser _parser = {
12235
0
        .keywords = _keywords,
12236
0
        .fname = "scandir",
12237
0
        .kwtuple = KWTUPLE,
12238
0
    };
12239
0
    #undef KWTUPLE
12240
0
    PyObject *argsbuf[1];
12241
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12242
0
    path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
12243
12244
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12245
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12246
0
    if (!args) {
12247
0
        goto exit;
12248
0
    }
12249
0
    if (!noptargs) {
12250
0
        goto skip_optional_pos;
12251
0
    }
12252
0
    if (!path_converter(args[0], &path)) {
12253
0
        goto exit;
12254
0
    }
12255
0
skip_optional_pos:
12256
0
    return_value = os_scandir_impl(module, &path);
12257
12258
0
exit:
12259
    /* Cleanup for path */
12260
0
    path_cleanup(&path);
12261
12262
0
    return return_value;
12263
0
}
12264
12265
PyDoc_STRVAR(os_fspath__doc__,
12266
"fspath($module, /, path)\n"
12267
"--\n"
12268
"\n"
12269
"Return the file system path representation of the object.\n"
12270
"\n"
12271
"If the object is str or bytes, then allow it to pass through as-is. If the\n"
12272
"object defines __fspath__(), then return the result of that method. All other\n"
12273
"types raise a TypeError.");
12274
12275
#define OS_FSPATH_METHODDEF    \
12276
    {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
12277
12278
static PyObject *
12279
os_fspath_impl(PyObject *module, PyObject *path);
12280
12281
static PyObject *
12282
os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12283
1.93k
{
12284
1.93k
    PyObject *return_value = NULL;
12285
1.93k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12286
12287
1.93k
    #define NUM_KEYWORDS 1
12288
1.93k
    static struct {
12289
1.93k
        PyGC_Head _this_is_not_used;
12290
1.93k
        PyObject_VAR_HEAD
12291
1.93k
        Py_hash_t ob_hash;
12292
1.93k
        PyObject *ob_item[NUM_KEYWORDS];
12293
1.93k
    } _kwtuple = {
12294
1.93k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12295
1.93k
        .ob_hash = -1,
12296
1.93k
        .ob_item = { &_Py_ID(path), },
12297
1.93k
    };
12298
1.93k
    #undef NUM_KEYWORDS
12299
1.93k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12300
12301
    #else  // !Py_BUILD_CORE
12302
    #  define KWTUPLE NULL
12303
    #endif  // !Py_BUILD_CORE
12304
12305
1.93k
    static const char * const _keywords[] = {"path", NULL};
12306
1.93k
    static _PyArg_Parser _parser = {
12307
1.93k
        .keywords = _keywords,
12308
1.93k
        .fname = "fspath",
12309
1.93k
        .kwtuple = KWTUPLE,
12310
1.93k
    };
12311
1.93k
    #undef KWTUPLE
12312
1.93k
    PyObject *argsbuf[1];
12313
1.93k
    PyObject *path;
12314
12315
1.93k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12316
1.93k
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12317
1.93k
    if (!args) {
12318
0
        goto exit;
12319
0
    }
12320
1.93k
    path = args[0];
12321
1.93k
    return_value = os_fspath_impl(module, path);
12322
12323
1.93k
exit:
12324
1.93k
    return return_value;
12325
1.93k
}
12326
12327
#if defined(HAVE_GETRANDOM_SYSCALL)
12328
12329
PyDoc_STRVAR(os_getrandom__doc__,
12330
"getrandom($module, /, size, flags=0)\n"
12331
"--\n"
12332
"\n"
12333
"Obtain a series of random bytes.");
12334
12335
#define OS_GETRANDOM_METHODDEF    \
12336
    {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
12337
12338
static PyObject *
12339
os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
12340
12341
static PyObject *
12342
os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12343
0
{
12344
0
    PyObject *return_value = NULL;
12345
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12346
12347
0
    #define NUM_KEYWORDS 2
12348
0
    static struct {
12349
0
        PyGC_Head _this_is_not_used;
12350
0
        PyObject_VAR_HEAD
12351
0
        Py_hash_t ob_hash;
12352
0
        PyObject *ob_item[NUM_KEYWORDS];
12353
0
    } _kwtuple = {
12354
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12355
0
        .ob_hash = -1,
12356
0
        .ob_item = { &_Py_ID(size), &_Py_ID(flags), },
12357
0
    };
12358
0
    #undef NUM_KEYWORDS
12359
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12360
12361
    #else  // !Py_BUILD_CORE
12362
    #  define KWTUPLE NULL
12363
    #endif  // !Py_BUILD_CORE
12364
12365
0
    static const char * const _keywords[] = {"size", "flags", NULL};
12366
0
    static _PyArg_Parser _parser = {
12367
0
        .keywords = _keywords,
12368
0
        .fname = "getrandom",
12369
0
        .kwtuple = KWTUPLE,
12370
0
    };
12371
0
    #undef KWTUPLE
12372
0
    PyObject *argsbuf[2];
12373
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
12374
0
    Py_ssize_t size;
12375
0
    int flags = 0;
12376
12377
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12378
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12379
0
    if (!args) {
12380
0
        goto exit;
12381
0
    }
12382
0
    {
12383
0
        Py_ssize_t ival = -1;
12384
0
        PyObject *iobj = _PyNumber_Index(args[0]);
12385
0
        if (iobj != NULL) {
12386
0
            ival = PyLong_AsSsize_t(iobj);
12387
0
            Py_DECREF(iobj);
12388
0
        }
12389
0
        if (ival == -1 && PyErr_Occurred()) {
12390
0
            goto exit;
12391
0
        }
12392
0
        size = ival;
12393
0
    }
12394
0
    if (!noptargs) {
12395
0
        goto skip_optional_pos;
12396
0
    }
12397
0
    flags = PyLong_AsInt(args[1]);
12398
0
    if (flags == -1 && PyErr_Occurred()) {
12399
0
        goto exit;
12400
0
    }
12401
0
skip_optional_pos:
12402
0
    return_value = os_getrandom_impl(module, size, flags);
12403
12404
0
exit:
12405
0
    return return_value;
12406
0
}
12407
12408
#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
12409
12410
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12411
12412
PyDoc_STRVAR(os__add_dll_directory__doc__,
12413
"_add_dll_directory($module, /, path)\n"
12414
"--\n"
12415
"\n"
12416
"Add a path to the DLL search path.\n"
12417
"\n"
12418
"This search path is used when resolving dependencies for imported\n"
12419
"extension modules (the module itself is resolved through sys.path),\n"
12420
"and also by ctypes.\n"
12421
"\n"
12422
"Returns an opaque value that may be passed to os.remove_dll_directory\n"
12423
"to remove this directory from the search path.");
12424
12425
#define OS__ADD_DLL_DIRECTORY_METHODDEF    \
12426
    {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
12427
12428
static PyObject *
12429
os__add_dll_directory_impl(PyObject *module, path_t *path);
12430
12431
static PyObject *
12432
os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12433
{
12434
    PyObject *return_value = NULL;
12435
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12436
12437
    #define NUM_KEYWORDS 1
12438
    static struct {
12439
        PyGC_Head _this_is_not_used;
12440
        PyObject_VAR_HEAD
12441
        Py_hash_t ob_hash;
12442
        PyObject *ob_item[NUM_KEYWORDS];
12443
    } _kwtuple = {
12444
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12445
        .ob_hash = -1,
12446
        .ob_item = { &_Py_ID(path), },
12447
    };
12448
    #undef NUM_KEYWORDS
12449
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12450
12451
    #else  // !Py_BUILD_CORE
12452
    #  define KWTUPLE NULL
12453
    #endif  // !Py_BUILD_CORE
12454
12455
    static const char * const _keywords[] = {"path", NULL};
12456
    static _PyArg_Parser _parser = {
12457
        .keywords = _keywords,
12458
        .fname = "_add_dll_directory",
12459
        .kwtuple = KWTUPLE,
12460
    };
12461
    #undef KWTUPLE
12462
    PyObject *argsbuf[1];
12463
    path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0);
12464
12465
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12466
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12467
    if (!args) {
12468
        goto exit;
12469
    }
12470
    if (!path_converter(args[0], &path)) {
12471
        goto exit;
12472
    }
12473
    return_value = os__add_dll_directory_impl(module, &path);
12474
12475
exit:
12476
    /* Cleanup for path */
12477
    path_cleanup(&path);
12478
12479
    return return_value;
12480
}
12481
12482
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12483
12484
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12485
12486
PyDoc_STRVAR(os__remove_dll_directory__doc__,
12487
"_remove_dll_directory($module, /, cookie)\n"
12488
"--\n"
12489
"\n"
12490
"Removes a path from the DLL search path.\n"
12491
"\n"
12492
"The parameter is an opaque value that was returned from\n"
12493
"os.add_dll_directory. You can only remove directories that you added\n"
12494
"yourself.");
12495
12496
#define OS__REMOVE_DLL_DIRECTORY_METHODDEF    \
12497
    {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
12498
12499
static PyObject *
12500
os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
12501
12502
static PyObject *
12503
os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12504
{
12505
    PyObject *return_value = NULL;
12506
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12507
12508
    #define NUM_KEYWORDS 1
12509
    static struct {
12510
        PyGC_Head _this_is_not_used;
12511
        PyObject_VAR_HEAD
12512
        Py_hash_t ob_hash;
12513
        PyObject *ob_item[NUM_KEYWORDS];
12514
    } _kwtuple = {
12515
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12516
        .ob_hash = -1,
12517
        .ob_item = { &_Py_ID(cookie), },
12518
    };
12519
    #undef NUM_KEYWORDS
12520
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12521
12522
    #else  // !Py_BUILD_CORE
12523
    #  define KWTUPLE NULL
12524
    #endif  // !Py_BUILD_CORE
12525
12526
    static const char * const _keywords[] = {"cookie", NULL};
12527
    static _PyArg_Parser _parser = {
12528
        .keywords = _keywords,
12529
        .fname = "_remove_dll_directory",
12530
        .kwtuple = KWTUPLE,
12531
    };
12532
    #undef KWTUPLE
12533
    PyObject *argsbuf[1];
12534
    PyObject *cookie;
12535
12536
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12537
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12538
    if (!args) {
12539
        goto exit;
12540
    }
12541
    cookie = args[0];
12542
    return_value = os__remove_dll_directory_impl(module, cookie);
12543
12544
exit:
12545
    return return_value;
12546
}
12547
12548
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12549
12550
#if (defined(WIFEXITED) || defined(MS_WINDOWS))
12551
12552
PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__,
12553
"waitstatus_to_exitcode($module, /, status)\n"
12554
"--\n"
12555
"\n"
12556
"Convert a wait status to an exit code.\n"
12557
"\n"
12558
"On Unix:\n"
12559
"\n"
12560
"* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n"
12561
"* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n"
12562
"* Otherwise, raise a ValueError.\n"
12563
"\n"
12564
"On Windows, return status shifted right by 8 bits.\n"
12565
"\n"
12566
"On Unix, if the process is being traced or if waitpid() was called with\n"
12567
"WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n"
12568
"This function must not be called if WIFSTOPPED(status) is true.");
12569
12570
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF    \
12571
    {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__},
12572
12573
static PyObject *
12574
os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj);
12575
12576
static PyObject *
12577
os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12578
0
{
12579
0
    PyObject *return_value = NULL;
12580
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12581
12582
0
    #define NUM_KEYWORDS 1
12583
0
    static struct {
12584
0
        PyGC_Head _this_is_not_used;
12585
0
        PyObject_VAR_HEAD
12586
0
        Py_hash_t ob_hash;
12587
0
        PyObject *ob_item[NUM_KEYWORDS];
12588
0
    } _kwtuple = {
12589
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12590
0
        .ob_hash = -1,
12591
0
        .ob_item = { &_Py_ID(status), },
12592
0
    };
12593
0
    #undef NUM_KEYWORDS
12594
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12595
12596
    #else  // !Py_BUILD_CORE
12597
    #  define KWTUPLE NULL
12598
    #endif  // !Py_BUILD_CORE
12599
12600
0
    static const char * const _keywords[] = {"status", NULL};
12601
0
    static _PyArg_Parser _parser = {
12602
0
        .keywords = _keywords,
12603
0
        .fname = "waitstatus_to_exitcode",
12604
0
        .kwtuple = KWTUPLE,
12605
0
    };
12606
0
    #undef KWTUPLE
12607
0
    PyObject *argsbuf[1];
12608
0
    PyObject *status_obj;
12609
12610
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12611
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12612
0
    if (!args) {
12613
0
        goto exit;
12614
0
    }
12615
0
    status_obj = args[0];
12616
0
    return_value = os_waitstatus_to_exitcode_impl(module, status_obj);
12617
12618
0
exit:
12619
0
    return return_value;
12620
0
}
12621
12622
#endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */
12623
12624
#if defined(MS_WINDOWS)
12625
12626
PyDoc_STRVAR(os__supports_virtual_terminal__doc__,
12627
"_supports_virtual_terminal($module, /)\n"
12628
"--\n"
12629
"\n"
12630
"Checks if virtual terminal is supported in windows");
12631
12632
#define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF    \
12633
    {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__},
12634
12635
static PyObject *
12636
os__supports_virtual_terminal_impl(PyObject *module);
12637
12638
static PyObject *
12639
os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored))
12640
{
12641
    return os__supports_virtual_terminal_impl(module);
12642
}
12643
12644
#endif /* defined(MS_WINDOWS) */
12645
12646
PyDoc_STRVAR(os__inputhook__doc__,
12647
"_inputhook($module, /)\n"
12648
"--\n"
12649
"\n"
12650
"Calls PyOS_CallInputHook droppong the GIL first");
12651
12652
#define OS__INPUTHOOK_METHODDEF    \
12653
    {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__},
12654
12655
static PyObject *
12656
os__inputhook_impl(PyObject *module);
12657
12658
static PyObject *
12659
os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored))
12660
0
{
12661
0
    return os__inputhook_impl(module);
12662
0
}
12663
12664
PyDoc_STRVAR(os__is_inputhook_installed__doc__,
12665
"_is_inputhook_installed($module, /)\n"
12666
"--\n"
12667
"\n"
12668
"Checks if PyOS_CallInputHook is set");
12669
12670
#define OS__IS_INPUTHOOK_INSTALLED_METHODDEF    \
12671
    {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__},
12672
12673
static PyObject *
12674
os__is_inputhook_installed_impl(PyObject *module);
12675
12676
static PyObject *
12677
os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored))
12678
0
{
12679
0
    return os__is_inputhook_installed_impl(module);
12680
0
}
12681
12682
PyDoc_STRVAR(os__create_environ__doc__,
12683
"_create_environ($module, /)\n"
12684
"--\n"
12685
"\n"
12686
"Create the environment dictionary.");
12687
12688
#define OS__CREATE_ENVIRON_METHODDEF    \
12689
    {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__},
12690
12691
static PyObject *
12692
os__create_environ_impl(PyObject *module);
12693
12694
static PyObject *
12695
os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored))
12696
0
{
12697
0
    return os__create_environ_impl(module);
12698
0
}
12699
12700
#if defined(__EMSCRIPTEN__)
12701
12702
PyDoc_STRVAR(os__emscripten_debugger__doc__,
12703
"_emscripten_debugger($module, /)\n"
12704
"--\n"
12705
"\n"
12706
"Create a breakpoint for the JavaScript debugger. Emscripten only.");
12707
12708
#define OS__EMSCRIPTEN_DEBUGGER_METHODDEF    \
12709
    {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__},
12710
12711
static PyObject *
12712
os__emscripten_debugger_impl(PyObject *module);
12713
12714
static PyObject *
12715
os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored))
12716
{
12717
    return os__emscripten_debugger_impl(module);
12718
}
12719
12720
#endif /* defined(__EMSCRIPTEN__) */
12721
12722
#if defined(__EMSCRIPTEN__)
12723
12724
PyDoc_STRVAR(os__emscripten_log__doc__,
12725
"_emscripten_log($module, /, arg)\n"
12726
"--\n"
12727
"\n"
12728
"Log something to the JS console. Emscripten only.");
12729
12730
#define OS__EMSCRIPTEN_LOG_METHODDEF    \
12731
    {"_emscripten_log", _PyCFunction_CAST(os__emscripten_log), METH_FASTCALL|METH_KEYWORDS, os__emscripten_log__doc__},
12732
12733
static PyObject *
12734
os__emscripten_log_impl(PyObject *module, const char *arg);
12735
12736
static PyObject *
12737
os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12738
{
12739
    PyObject *return_value = NULL;
12740
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12741
12742
    #define NUM_KEYWORDS 1
12743
    static struct {
12744
        PyGC_Head _this_is_not_used;
12745
        PyObject_VAR_HEAD
12746
        Py_hash_t ob_hash;
12747
        PyObject *ob_item[NUM_KEYWORDS];
12748
    } _kwtuple = {
12749
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12750
        .ob_hash = -1,
12751
        .ob_item = { &_Py_ID(arg), },
12752
    };
12753
    #undef NUM_KEYWORDS
12754
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12755
12756
    #else  // !Py_BUILD_CORE
12757
    #  define KWTUPLE NULL
12758
    #endif  // !Py_BUILD_CORE
12759
12760
    static const char * const _keywords[] = {"arg", NULL};
12761
    static _PyArg_Parser _parser = {
12762
        .keywords = _keywords,
12763
        .fname = "_emscripten_log",
12764
        .kwtuple = KWTUPLE,
12765
    };
12766
    #undef KWTUPLE
12767
    PyObject *argsbuf[1];
12768
    const char *arg;
12769
12770
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12771
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12772
    if (!args) {
12773
        goto exit;
12774
    }
12775
    if (!PyUnicode_Check(args[0])) {
12776
        _PyArg_BadArgument("_emscripten_log", "argument 'arg'", "str", args[0]);
12777
        goto exit;
12778
    }
12779
    Py_ssize_t arg_length;
12780
    arg = PyUnicode_AsUTF8AndSize(args[0], &arg_length);
12781
    if (arg == NULL) {
12782
        goto exit;
12783
    }
12784
    if (strlen(arg) != (size_t)arg_length) {
12785
        PyErr_SetString(PyExc_ValueError, "embedded null character");
12786
        goto exit;
12787
    }
12788
    return_value = os__emscripten_log_impl(module, arg);
12789
12790
exit:
12791
    return return_value;
12792
}
12793
12794
#endif /* defined(__EMSCRIPTEN__) */
12795
12796
#ifndef OS_TTYNAME_METHODDEF
12797
    #define OS_TTYNAME_METHODDEF
12798
#endif /* !defined(OS_TTYNAME_METHODDEF) */
12799
12800
#ifndef OS_CTERMID_METHODDEF
12801
    #define OS_CTERMID_METHODDEF
12802
#endif /* !defined(OS_CTERMID_METHODDEF) */
12803
12804
#ifndef OS_FCHDIR_METHODDEF
12805
    #define OS_FCHDIR_METHODDEF
12806
#endif /* !defined(OS_FCHDIR_METHODDEF) */
12807
12808
#ifndef OS_FCHMOD_METHODDEF
12809
    #define OS_FCHMOD_METHODDEF
12810
#endif /* !defined(OS_FCHMOD_METHODDEF) */
12811
12812
#ifndef OS_LCHMOD_METHODDEF
12813
    #define OS_LCHMOD_METHODDEF
12814
#endif /* !defined(OS_LCHMOD_METHODDEF) */
12815
12816
#ifndef OS_CHFLAGS_METHODDEF
12817
    #define OS_CHFLAGS_METHODDEF
12818
#endif /* !defined(OS_CHFLAGS_METHODDEF) */
12819
12820
#ifndef OS_LCHFLAGS_METHODDEF
12821
    #define OS_LCHFLAGS_METHODDEF
12822
#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
12823
12824
#ifndef OS_CHROOT_METHODDEF
12825
    #define OS_CHROOT_METHODDEF
12826
#endif /* !defined(OS_CHROOT_METHODDEF) */
12827
12828
#ifndef OS_FSYNC_METHODDEF
12829
    #define OS_FSYNC_METHODDEF
12830
#endif /* !defined(OS_FSYNC_METHODDEF) */
12831
12832
#ifndef OS_SYNC_METHODDEF
12833
    #define OS_SYNC_METHODDEF
12834
#endif /* !defined(OS_SYNC_METHODDEF) */
12835
12836
#ifndef OS_FDATASYNC_METHODDEF
12837
    #define OS_FDATASYNC_METHODDEF
12838
#endif /* !defined(OS_FDATASYNC_METHODDEF) */
12839
12840
#ifndef OS_CHOWN_METHODDEF
12841
    #define OS_CHOWN_METHODDEF
12842
#endif /* !defined(OS_CHOWN_METHODDEF) */
12843
12844
#ifndef OS_FCHOWN_METHODDEF
12845
    #define OS_FCHOWN_METHODDEF
12846
#endif /* !defined(OS_FCHOWN_METHODDEF) */
12847
12848
#ifndef OS_LCHOWN_METHODDEF
12849
    #define OS_LCHOWN_METHODDEF
12850
#endif /* !defined(OS_LCHOWN_METHODDEF) */
12851
12852
#ifndef OS_LINK_METHODDEF
12853
    #define OS_LINK_METHODDEF
12854
#endif /* !defined(OS_LINK_METHODDEF) */
12855
12856
#ifndef OS_LISTDRIVES_METHODDEF
12857
    #define OS_LISTDRIVES_METHODDEF
12858
#endif /* !defined(OS_LISTDRIVES_METHODDEF) */
12859
12860
#ifndef OS_LISTVOLUMES_METHODDEF
12861
    #define OS_LISTVOLUMES_METHODDEF
12862
#endif /* !defined(OS_LISTVOLUMES_METHODDEF) */
12863
12864
#ifndef OS_LISTMOUNTS_METHODDEF
12865
    #define OS_LISTMOUNTS_METHODDEF
12866
#endif /* !defined(OS_LISTMOUNTS_METHODDEF) */
12867
12868
#ifndef OS__PATH_ISDEVDRIVE_METHODDEF
12869
    #define OS__PATH_ISDEVDRIVE_METHODDEF
12870
#endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */
12871
12872
#ifndef OS__GETFULLPATHNAME_METHODDEF
12873
    #define OS__GETFULLPATHNAME_METHODDEF
12874
#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
12875
12876
#ifndef OS__GETFINALPATHNAME_METHODDEF
12877
    #define OS__GETFINALPATHNAME_METHODDEF
12878
#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
12879
12880
#ifndef OS__FINDFIRSTFILE_METHODDEF
12881
    #define OS__FINDFIRSTFILE_METHODDEF
12882
#endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */
12883
12884
#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
12885
    #define OS__GETVOLUMEPATHNAME_METHODDEF
12886
#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
12887
12888
#ifndef OS__PATH_SPLITROOT_METHODDEF
12889
    #define OS__PATH_SPLITROOT_METHODDEF
12890
#endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */
12891
12892
#ifndef OS__PATH_EXISTS_METHODDEF
12893
    #define OS__PATH_EXISTS_METHODDEF
12894
#endif /* !defined(OS__PATH_EXISTS_METHODDEF) */
12895
12896
#ifndef OS__PATH_LEXISTS_METHODDEF
12897
    #define OS__PATH_LEXISTS_METHODDEF
12898
#endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */
12899
12900
#ifndef OS__PATH_ISDIR_METHODDEF
12901
    #define OS__PATH_ISDIR_METHODDEF
12902
#endif /* !defined(OS__PATH_ISDIR_METHODDEF) */
12903
12904
#ifndef OS__PATH_ISFILE_METHODDEF
12905
    #define OS__PATH_ISFILE_METHODDEF
12906
#endif /* !defined(OS__PATH_ISFILE_METHODDEF) */
12907
12908
#ifndef OS__PATH_ISLINK_METHODDEF
12909
    #define OS__PATH_ISLINK_METHODDEF
12910
#endif /* !defined(OS__PATH_ISLINK_METHODDEF) */
12911
12912
#ifndef OS__PATH_ISJUNCTION_METHODDEF
12913
    #define OS__PATH_ISJUNCTION_METHODDEF
12914
#endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */
12915
12916
#ifndef OS_NICE_METHODDEF
12917
    #define OS_NICE_METHODDEF
12918
#endif /* !defined(OS_NICE_METHODDEF) */
12919
12920
#ifndef OS_GETPRIORITY_METHODDEF
12921
    #define OS_GETPRIORITY_METHODDEF
12922
#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
12923
12924
#ifndef OS_SETPRIORITY_METHODDEF
12925
    #define OS_SETPRIORITY_METHODDEF
12926
#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
12927
12928
#ifndef OS_SYSTEM_METHODDEF
12929
    #define OS_SYSTEM_METHODDEF
12930
#endif /* !defined(OS_SYSTEM_METHODDEF) */
12931
12932
#ifndef OS_UMASK_METHODDEF
12933
    #define OS_UMASK_METHODDEF
12934
#endif /* !defined(OS_UMASK_METHODDEF) */
12935
12936
#ifndef OS_UNAME_METHODDEF
12937
    #define OS_UNAME_METHODDEF
12938
#endif /* !defined(OS_UNAME_METHODDEF) */
12939
12940
#ifndef OS_EXECV_METHODDEF
12941
    #define OS_EXECV_METHODDEF
12942
#endif /* !defined(OS_EXECV_METHODDEF) */
12943
12944
#ifndef OS_EXECVE_METHODDEF
12945
    #define OS_EXECVE_METHODDEF
12946
#endif /* !defined(OS_EXECVE_METHODDEF) */
12947
12948
#ifndef OS_POSIX_SPAWN_METHODDEF
12949
    #define OS_POSIX_SPAWN_METHODDEF
12950
#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
12951
12952
#ifndef OS_POSIX_SPAWNP_METHODDEF
12953
    #define OS_POSIX_SPAWNP_METHODDEF
12954
#endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
12955
12956
#ifndef OS_SPAWNV_METHODDEF
12957
    #define OS_SPAWNV_METHODDEF
12958
#endif /* !defined(OS_SPAWNV_METHODDEF) */
12959
12960
#ifndef OS_SPAWNVE_METHODDEF
12961
    #define OS_SPAWNVE_METHODDEF
12962
#endif /* !defined(OS_SPAWNVE_METHODDEF) */
12963
12964
#ifndef OS_REGISTER_AT_FORK_METHODDEF
12965
    #define OS_REGISTER_AT_FORK_METHODDEF
12966
#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
12967
12968
#ifndef OS_FORK1_METHODDEF
12969
    #define OS_FORK1_METHODDEF
12970
#endif /* !defined(OS_FORK1_METHODDEF) */
12971
12972
#ifndef OS_FORK_METHODDEF
12973
    #define OS_FORK_METHODDEF
12974
#endif /* !defined(OS_FORK_METHODDEF) */
12975
12976
#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
12977
    #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
12978
#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
12979
12980
#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
12981
    #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
12982
#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
12983
12984
#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
12985
    #define OS_SCHED_GETSCHEDULER_METHODDEF
12986
#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
12987
12988
#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
12989
    #define OS_SCHED_SETSCHEDULER_METHODDEF
12990
#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
12991
12992
#ifndef OS_SCHED_GETPARAM_METHODDEF
12993
    #define OS_SCHED_GETPARAM_METHODDEF
12994
#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
12995
12996
#ifndef OS_SCHED_SETPARAM_METHODDEF
12997
    #define OS_SCHED_SETPARAM_METHODDEF
12998
#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
12999
13000
#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
13001
    #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
13002
#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
13003
13004
#ifndef OS_SCHED_YIELD_METHODDEF
13005
    #define OS_SCHED_YIELD_METHODDEF
13006
#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
13007
13008
#ifndef OS_SCHED_SETAFFINITY_METHODDEF
13009
    #define OS_SCHED_SETAFFINITY_METHODDEF
13010
#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
13011
13012
#ifndef OS_SCHED_GETAFFINITY_METHODDEF
13013
    #define OS_SCHED_GETAFFINITY_METHODDEF
13014
#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
13015
13016
#ifndef OS_POSIX_OPENPT_METHODDEF
13017
    #define OS_POSIX_OPENPT_METHODDEF
13018
#endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */
13019
13020
#ifndef OS_GRANTPT_METHODDEF
13021
    #define OS_GRANTPT_METHODDEF
13022
#endif /* !defined(OS_GRANTPT_METHODDEF) */
13023
13024
#ifndef OS_UNLOCKPT_METHODDEF
13025
    #define OS_UNLOCKPT_METHODDEF
13026
#endif /* !defined(OS_UNLOCKPT_METHODDEF) */
13027
13028
#ifndef OS_PTSNAME_METHODDEF
13029
    #define OS_PTSNAME_METHODDEF
13030
#endif /* !defined(OS_PTSNAME_METHODDEF) */
13031
13032
#ifndef OS_OPENPTY_METHODDEF
13033
    #define OS_OPENPTY_METHODDEF
13034
#endif /* !defined(OS_OPENPTY_METHODDEF) */
13035
13036
#ifndef OS_LOGIN_TTY_METHODDEF
13037
    #define OS_LOGIN_TTY_METHODDEF
13038
#endif /* !defined(OS_LOGIN_TTY_METHODDEF) */
13039
13040
#ifndef OS_FORKPTY_METHODDEF
13041
    #define OS_FORKPTY_METHODDEF
13042
#endif /* !defined(OS_FORKPTY_METHODDEF) */
13043
13044
#ifndef OS_GETEGID_METHODDEF
13045
    #define OS_GETEGID_METHODDEF
13046
#endif /* !defined(OS_GETEGID_METHODDEF) */
13047
13048
#ifndef OS_GETEUID_METHODDEF
13049
    #define OS_GETEUID_METHODDEF
13050
#endif /* !defined(OS_GETEUID_METHODDEF) */
13051
13052
#ifndef OS_GETGID_METHODDEF
13053
    #define OS_GETGID_METHODDEF
13054
#endif /* !defined(OS_GETGID_METHODDEF) */
13055
13056
#ifndef OS_GETPID_METHODDEF
13057
    #define OS_GETPID_METHODDEF
13058
#endif /* !defined(OS_GETPID_METHODDEF) */
13059
13060
#ifndef OS_GETGROUPLIST_METHODDEF
13061
    #define OS_GETGROUPLIST_METHODDEF
13062
#endif /* !defined(OS_GETGROUPLIST_METHODDEF) */
13063
13064
#ifndef OS_GETGROUPS_METHODDEF
13065
    #define OS_GETGROUPS_METHODDEF
13066
#endif /* !defined(OS_GETGROUPS_METHODDEF) */
13067
13068
#ifndef OS_INITGROUPS_METHODDEF
13069
    #define OS_INITGROUPS_METHODDEF
13070
#endif /* !defined(OS_INITGROUPS_METHODDEF) */
13071
13072
#ifndef OS_GETPGID_METHODDEF
13073
    #define OS_GETPGID_METHODDEF
13074
#endif /* !defined(OS_GETPGID_METHODDEF) */
13075
13076
#ifndef OS_GETPGRP_METHODDEF
13077
    #define OS_GETPGRP_METHODDEF
13078
#endif /* !defined(OS_GETPGRP_METHODDEF) */
13079
13080
#ifndef OS_SETPGRP_METHODDEF
13081
    #define OS_SETPGRP_METHODDEF
13082
#endif /* !defined(OS_SETPGRP_METHODDEF) */
13083
13084
#ifndef OS_GETPPID_METHODDEF
13085
    #define OS_GETPPID_METHODDEF
13086
#endif /* !defined(OS_GETPPID_METHODDEF) */
13087
13088
#ifndef OS_GETLOGIN_METHODDEF
13089
    #define OS_GETLOGIN_METHODDEF
13090
#endif /* !defined(OS_GETLOGIN_METHODDEF) */
13091
13092
#ifndef OS_GETUID_METHODDEF
13093
    #define OS_GETUID_METHODDEF
13094
#endif /* !defined(OS_GETUID_METHODDEF) */
13095
13096
#ifndef OS_KILL_METHODDEF
13097
    #define OS_KILL_METHODDEF
13098
#endif /* !defined(OS_KILL_METHODDEF) */
13099
13100
#ifndef OS_KILLPG_METHODDEF
13101
    #define OS_KILLPG_METHODDEF
13102
#endif /* !defined(OS_KILLPG_METHODDEF) */
13103
13104
#ifndef OS_PLOCK_METHODDEF
13105
    #define OS_PLOCK_METHODDEF
13106
#endif /* !defined(OS_PLOCK_METHODDEF) */
13107
13108
#ifndef OS_SETUID_METHODDEF
13109
    #define OS_SETUID_METHODDEF
13110
#endif /* !defined(OS_SETUID_METHODDEF) */
13111
13112
#ifndef OS_SETEUID_METHODDEF
13113
    #define OS_SETEUID_METHODDEF
13114
#endif /* !defined(OS_SETEUID_METHODDEF) */
13115
13116
#ifndef OS_SETEGID_METHODDEF
13117
    #define OS_SETEGID_METHODDEF
13118
#endif /* !defined(OS_SETEGID_METHODDEF) */
13119
13120
#ifndef OS_SETREUID_METHODDEF
13121
    #define OS_SETREUID_METHODDEF
13122
#endif /* !defined(OS_SETREUID_METHODDEF) */
13123
13124
#ifndef OS_SETREGID_METHODDEF
13125
    #define OS_SETREGID_METHODDEF
13126
#endif /* !defined(OS_SETREGID_METHODDEF) */
13127
13128
#ifndef OS_SETGID_METHODDEF
13129
    #define OS_SETGID_METHODDEF
13130
#endif /* !defined(OS_SETGID_METHODDEF) */
13131
13132
#ifndef OS_SETGROUPS_METHODDEF
13133
    #define OS_SETGROUPS_METHODDEF
13134
#endif /* !defined(OS_SETGROUPS_METHODDEF) */
13135
13136
#ifndef OS_WAIT3_METHODDEF
13137
    #define OS_WAIT3_METHODDEF
13138
#endif /* !defined(OS_WAIT3_METHODDEF) */
13139
13140
#ifndef OS_WAIT4_METHODDEF
13141
    #define OS_WAIT4_METHODDEF
13142
#endif /* !defined(OS_WAIT4_METHODDEF) */
13143
13144
#ifndef OS_WAITID_METHODDEF
13145
    #define OS_WAITID_METHODDEF
13146
#endif /* !defined(OS_WAITID_METHODDEF) */
13147
13148
#ifndef OS_WAITPID_METHODDEF
13149
    #define OS_WAITPID_METHODDEF
13150
#endif /* !defined(OS_WAITPID_METHODDEF) */
13151
13152
#ifndef OS_WAIT_METHODDEF
13153
    #define OS_WAIT_METHODDEF
13154
#endif /* !defined(OS_WAIT_METHODDEF) */
13155
13156
#ifndef OS_PIDFD_OPEN_METHODDEF
13157
    #define OS_PIDFD_OPEN_METHODDEF
13158
#endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */
13159
13160
#ifndef OS_SETNS_METHODDEF
13161
    #define OS_SETNS_METHODDEF
13162
#endif /* !defined(OS_SETNS_METHODDEF) */
13163
13164
#ifndef OS_UNSHARE_METHODDEF
13165
    #define OS_UNSHARE_METHODDEF
13166
#endif /* !defined(OS_UNSHARE_METHODDEF) */
13167
13168
#ifndef OS_READLINK_METHODDEF
13169
    #define OS_READLINK_METHODDEF
13170
#endif /* !defined(OS_READLINK_METHODDEF) */
13171
13172
#ifndef OS_SYMLINK_METHODDEF
13173
    #define OS_SYMLINK_METHODDEF
13174
#endif /* !defined(OS_SYMLINK_METHODDEF) */
13175
13176
#ifndef OS_TIMERFD_CREATE_METHODDEF
13177
    #define OS_TIMERFD_CREATE_METHODDEF
13178
#endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */
13179
13180
#ifndef OS_TIMERFD_SETTIME_METHODDEF
13181
    #define OS_TIMERFD_SETTIME_METHODDEF
13182
#endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */
13183
13184
#ifndef OS_TIMERFD_SETTIME_NS_METHODDEF
13185
    #define OS_TIMERFD_SETTIME_NS_METHODDEF
13186
#endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */
13187
13188
#ifndef OS_TIMERFD_GETTIME_METHODDEF
13189
    #define OS_TIMERFD_GETTIME_METHODDEF
13190
#endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */
13191
13192
#ifndef OS_TIMERFD_GETTIME_NS_METHODDEF
13193
    #define OS_TIMERFD_GETTIME_NS_METHODDEF
13194
#endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */
13195
13196
#ifndef OS_GETSID_METHODDEF
13197
    #define OS_GETSID_METHODDEF
13198
#endif /* !defined(OS_GETSID_METHODDEF) */
13199
13200
#ifndef OS_SETSID_METHODDEF
13201
    #define OS_SETSID_METHODDEF
13202
#endif /* !defined(OS_SETSID_METHODDEF) */
13203
13204
#ifndef OS_SETPGID_METHODDEF
13205
    #define OS_SETPGID_METHODDEF
13206
#endif /* !defined(OS_SETPGID_METHODDEF) */
13207
13208
#ifndef OS_TCGETPGRP_METHODDEF
13209
    #define OS_TCGETPGRP_METHODDEF
13210
#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
13211
13212
#ifndef OS_TCSETPGRP_METHODDEF
13213
    #define OS_TCSETPGRP_METHODDEF
13214
#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
13215
13216
#ifndef OS_DUP2_METHODDEF
13217
    #define OS_DUP2_METHODDEF
13218
#endif /* !defined(OS_DUP2_METHODDEF) */
13219
13220
#ifndef OS_LOCKF_METHODDEF
13221
    #define OS_LOCKF_METHODDEF
13222
#endif /* !defined(OS_LOCKF_METHODDEF) */
13223
13224
#ifndef OS_READV_METHODDEF
13225
    #define OS_READV_METHODDEF
13226
#endif /* !defined(OS_READV_METHODDEF) */
13227
13228
#ifndef OS_PREAD_METHODDEF
13229
    #define OS_PREAD_METHODDEF
13230
#endif /* !defined(OS_PREAD_METHODDEF) */
13231
13232
#ifndef OS_PREADV_METHODDEF
13233
    #define OS_PREADV_METHODDEF
13234
#endif /* !defined(OS_PREADV_METHODDEF) */
13235
13236
#ifndef OS_SENDFILE_METHODDEF
13237
    #define OS_SENDFILE_METHODDEF
13238
#endif /* !defined(OS_SENDFILE_METHODDEF) */
13239
13240
#ifndef OS__FCOPYFILE_METHODDEF
13241
    #define OS__FCOPYFILE_METHODDEF
13242
#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
13243
13244
#ifndef OS_PIPE_METHODDEF
13245
    #define OS_PIPE_METHODDEF
13246
#endif /* !defined(OS_PIPE_METHODDEF) */
13247
13248
#ifndef OS_PIPE2_METHODDEF
13249
    #define OS_PIPE2_METHODDEF
13250
#endif /* !defined(OS_PIPE2_METHODDEF) */
13251
13252
#ifndef OS_WRITEV_METHODDEF
13253
    #define OS_WRITEV_METHODDEF
13254
#endif /* !defined(OS_WRITEV_METHODDEF) */
13255
13256
#ifndef OS_PWRITE_METHODDEF
13257
    #define OS_PWRITE_METHODDEF
13258
#endif /* !defined(OS_PWRITE_METHODDEF) */
13259
13260
#ifndef OS_PWRITEV_METHODDEF
13261
    #define OS_PWRITEV_METHODDEF
13262
#endif /* !defined(OS_PWRITEV_METHODDEF) */
13263
13264
#ifndef OS_COPY_FILE_RANGE_METHODDEF
13265
    #define OS_COPY_FILE_RANGE_METHODDEF
13266
#endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
13267
13268
#ifndef OS_SPLICE_METHODDEF
13269
    #define OS_SPLICE_METHODDEF
13270
#endif /* !defined(OS_SPLICE_METHODDEF) */
13271
13272
#ifndef OS_MKFIFO_METHODDEF
13273
    #define OS_MKFIFO_METHODDEF
13274
#endif /* !defined(OS_MKFIFO_METHODDEF) */
13275
13276
#ifndef OS_MKNOD_METHODDEF
13277
    #define OS_MKNOD_METHODDEF
13278
#endif /* !defined(OS_MKNOD_METHODDEF) */
13279
13280
#ifndef OS_MAJOR_METHODDEF
13281
    #define OS_MAJOR_METHODDEF
13282
#endif /* !defined(OS_MAJOR_METHODDEF) */
13283
13284
#ifndef OS_MINOR_METHODDEF
13285
    #define OS_MINOR_METHODDEF
13286
#endif /* !defined(OS_MINOR_METHODDEF) */
13287
13288
#ifndef OS_MAKEDEV_METHODDEF
13289
    #define OS_MAKEDEV_METHODDEF
13290
#endif /* !defined(OS_MAKEDEV_METHODDEF) */
13291
13292
#ifndef OS_FTRUNCATE_METHODDEF
13293
    #define OS_FTRUNCATE_METHODDEF
13294
#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
13295
13296
#ifndef OS_TRUNCATE_METHODDEF
13297
    #define OS_TRUNCATE_METHODDEF
13298
#endif /* !defined(OS_TRUNCATE_METHODDEF) */
13299
13300
#ifndef OS_POSIX_FALLOCATE_METHODDEF
13301
    #define OS_POSIX_FALLOCATE_METHODDEF
13302
#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
13303
13304
#ifndef OS_POSIX_FADVISE_METHODDEF
13305
    #define OS_POSIX_FADVISE_METHODDEF
13306
#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
13307
13308
#ifndef OS_PUTENV_METHODDEF
13309
    #define OS_PUTENV_METHODDEF
13310
#endif /* !defined(OS_PUTENV_METHODDEF) */
13311
13312
#ifndef OS_UNSETENV_METHODDEF
13313
    #define OS_UNSETENV_METHODDEF
13314
#endif /* !defined(OS_UNSETENV_METHODDEF) */
13315
13316
#ifndef OS__CLEARENV_METHODDEF
13317
    #define OS__CLEARENV_METHODDEF
13318
#endif /* !defined(OS__CLEARENV_METHODDEF) */
13319
13320
#ifndef OS_WCOREDUMP_METHODDEF
13321
    #define OS_WCOREDUMP_METHODDEF
13322
#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
13323
13324
#ifndef OS_WIFCONTINUED_METHODDEF
13325
    #define OS_WIFCONTINUED_METHODDEF
13326
#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
13327
13328
#ifndef OS_WIFSTOPPED_METHODDEF
13329
    #define OS_WIFSTOPPED_METHODDEF
13330
#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
13331
13332
#ifndef OS_WIFSIGNALED_METHODDEF
13333
    #define OS_WIFSIGNALED_METHODDEF
13334
#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
13335
13336
#ifndef OS_WIFEXITED_METHODDEF
13337
    #define OS_WIFEXITED_METHODDEF
13338
#endif /* !defined(OS_WIFEXITED_METHODDEF) */
13339
13340
#ifndef OS_WEXITSTATUS_METHODDEF
13341
    #define OS_WEXITSTATUS_METHODDEF
13342
#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
13343
13344
#ifndef OS_WTERMSIG_METHODDEF
13345
    #define OS_WTERMSIG_METHODDEF
13346
#endif /* !defined(OS_WTERMSIG_METHODDEF) */
13347
13348
#ifndef OS_WSTOPSIG_METHODDEF
13349
    #define OS_WSTOPSIG_METHODDEF
13350
#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
13351
13352
#ifndef OS_FSTATVFS_METHODDEF
13353
    #define OS_FSTATVFS_METHODDEF
13354
#endif /* !defined(OS_FSTATVFS_METHODDEF) */
13355
13356
#ifndef OS_STATVFS_METHODDEF
13357
    #define OS_STATVFS_METHODDEF
13358
#endif /* !defined(OS_STATVFS_METHODDEF) */
13359
13360
#ifndef OS__GETDISKUSAGE_METHODDEF
13361
    #define OS__GETDISKUSAGE_METHODDEF
13362
#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
13363
13364
#ifndef OS_FPATHCONF_METHODDEF
13365
    #define OS_FPATHCONF_METHODDEF
13366
#endif /* !defined(OS_FPATHCONF_METHODDEF) */
13367
13368
#ifndef OS_PATHCONF_METHODDEF
13369
    #define OS_PATHCONF_METHODDEF
13370
#endif /* !defined(OS_PATHCONF_METHODDEF) */
13371
13372
#ifndef OS_CONFSTR_METHODDEF
13373
    #define OS_CONFSTR_METHODDEF
13374
#endif /* !defined(OS_CONFSTR_METHODDEF) */
13375
13376
#ifndef OS_SYSCONF_METHODDEF
13377
    #define OS_SYSCONF_METHODDEF
13378
#endif /* !defined(OS_SYSCONF_METHODDEF) */
13379
13380
#ifndef OS_STARTFILE_METHODDEF
13381
    #define OS_STARTFILE_METHODDEF
13382
#endif /* !defined(OS_STARTFILE_METHODDEF) */
13383
13384
#ifndef OS_GETLOADAVG_METHODDEF
13385
    #define OS_GETLOADAVG_METHODDEF
13386
#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
13387
13388
#ifndef OS_SETRESUID_METHODDEF
13389
    #define OS_SETRESUID_METHODDEF
13390
#endif /* !defined(OS_SETRESUID_METHODDEF) */
13391
13392
#ifndef OS_SETRESGID_METHODDEF
13393
    #define OS_SETRESGID_METHODDEF
13394
#endif /* !defined(OS_SETRESGID_METHODDEF) */
13395
13396
#ifndef OS_GETRESUID_METHODDEF
13397
    #define OS_GETRESUID_METHODDEF
13398
#endif /* !defined(OS_GETRESUID_METHODDEF) */
13399
13400
#ifndef OS_GETRESGID_METHODDEF
13401
    #define OS_GETRESGID_METHODDEF
13402
#endif /* !defined(OS_GETRESGID_METHODDEF) */
13403
13404
#ifndef OS_GETXATTR_METHODDEF
13405
    #define OS_GETXATTR_METHODDEF
13406
#endif /* !defined(OS_GETXATTR_METHODDEF) */
13407
13408
#ifndef OS_SETXATTR_METHODDEF
13409
    #define OS_SETXATTR_METHODDEF
13410
#endif /* !defined(OS_SETXATTR_METHODDEF) */
13411
13412
#ifndef OS_REMOVEXATTR_METHODDEF
13413
    #define OS_REMOVEXATTR_METHODDEF
13414
#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
13415
13416
#ifndef OS_LISTXATTR_METHODDEF
13417
    #define OS_LISTXATTR_METHODDEF
13418
#endif /* !defined(OS_LISTXATTR_METHODDEF) */
13419
13420
#ifndef OS_MEMFD_CREATE_METHODDEF
13421
    #define OS_MEMFD_CREATE_METHODDEF
13422
#endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */
13423
13424
#ifndef OS_EVENTFD_METHODDEF
13425
    #define OS_EVENTFD_METHODDEF
13426
#endif /* !defined(OS_EVENTFD_METHODDEF) */
13427
13428
#ifndef OS_EVENTFD_READ_METHODDEF
13429
    #define OS_EVENTFD_READ_METHODDEF
13430
#endif /* !defined(OS_EVENTFD_READ_METHODDEF) */
13431
13432
#ifndef OS_EVENTFD_WRITE_METHODDEF
13433
    #define OS_EVENTFD_WRITE_METHODDEF
13434
#endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */
13435
13436
#ifndef OS_GET_TERMINAL_SIZE_METHODDEF
13437
    #define OS_GET_TERMINAL_SIZE_METHODDEF
13438
#endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */
13439
13440
#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
13441
    #define OS_GET_HANDLE_INHERITABLE_METHODDEF
13442
#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
13443
13444
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
13445
    #define OS_SET_HANDLE_INHERITABLE_METHODDEF
13446
#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
13447
13448
#ifndef OS_GETRANDOM_METHODDEF
13449
    #define OS_GETRANDOM_METHODDEF
13450
#endif /* !defined(OS_GETRANDOM_METHODDEF) */
13451
13452
#ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
13453
    #define OS__ADD_DLL_DIRECTORY_METHODDEF
13454
#endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
13455
13456
#ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
13457
    #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
13458
#endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
13459
13460
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13461
    #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13462
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
13463
13464
#ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13465
    #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13466
#endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */
13467
13468
#ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13469
    #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13470
#endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */
13471
13472
#ifndef OS__EMSCRIPTEN_LOG_METHODDEF
13473
    #define OS__EMSCRIPTEN_LOG_METHODDEF
13474
#endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */
13475
/*[clinic end generated code: output=67f0df7cd5a7de20 input=a9049054013a1b77]*/