Coverage Report

Created: 2026-01-10 07:03

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.16k
{
47
2.16k
    PyObject *return_value = NULL;
48
2.16k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
49
50
2.16k
    #define NUM_KEYWORDS 3
51
2.16k
    static struct {
52
2.16k
        PyGC_Head _this_is_not_used;
53
2.16k
        PyObject_VAR_HEAD
54
2.16k
        Py_hash_t ob_hash;
55
2.16k
        PyObject *ob_item[NUM_KEYWORDS];
56
2.16k
    } _kwtuple = {
57
2.16k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
58
2.16k
        .ob_hash = -1,
59
2.16k
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
60
2.16k
    };
61
2.16k
    #undef NUM_KEYWORDS
62
2.16k
    #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.16k
    static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
69
2.16k
    static _PyArg_Parser _parser = {
70
2.16k
        .keywords = _keywords,
71
2.16k
        .fname = "stat",
72
2.16k
        .kwtuple = KWTUPLE,
73
2.16k
    };
74
2.16k
    #undef KWTUPLE
75
2.16k
    PyObject *argsbuf[3];
76
2.16k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
77
2.16k
    path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1);
78
2.16k
    int dir_fd = DEFAULT_DIR_FD;
79
2.16k
    int follow_symlinks = 1;
80
81
2.16k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
82
2.16k
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
83
2.16k
    if (!args) {
84
0
        goto exit;
85
0
    }
86
2.16k
    if (!path_converter(args[0], &path)) {
87
0
        goto exit;
88
0
    }
89
2.16k
    if (!noptargs) {
90
2.16k
        goto skip_optional_kwonly;
91
2.16k
    }
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.16k
skip_optional_kwonly:
105
2.16k
    return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
106
107
2.16k
exit:
108
    /* Cleanup for path */
109
2.16k
    path_cleanup(&path);
110
111
2.16k
    return return_value;
112
2.16k
}
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
#if defined(HAVE_STATX)
190
191
PyDoc_STRVAR(os_statx__doc__,
192
"statx($module, /, path, mask, *, flags=0, dir_fd=None,\n"
193
"      follow_symlinks=True)\n"
194
"--\n"
195
"\n"
196
"Perform a statx system call on the given path.\n"
197
"\n"
198
"  path\n"
199
"    Path to be examined; can be string, bytes, a path-like object or\n"
200
"    open-file-descriptor int.\n"
201
"  mask\n"
202
"    A bitmask of STATX_* constants defining the requested information.\n"
203
"  flags\n"
204
"    A bitmask of AT_NO_AUTOMOUNT and/or AT_STATX_* flags.\n"
205
"  dir_fd\n"
206
"    If not None, it should be a file descriptor open to a directory,\n"
207
"    and path should be a relative string; path will then be relative to\n"
208
"    that directory.\n"
209
"  follow_symlinks\n"
210
"    If False, and the last element of the path is a symbolic link,\n"
211
"    statx will examine the symbolic link itself instead of the file\n"
212
"    the link points to.\n"
213
"\n"
214
"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
215
"  an open file descriptor.");
216
217
#define OS_STATX_METHODDEF    \
218
    {"statx", _PyCFunction_CAST(os_statx), METH_FASTCALL|METH_KEYWORDS, os_statx__doc__},
219
220
static PyObject *
221
os_statx_impl(PyObject *module, path_t *path, unsigned int mask, int flags,
222
              int dir_fd, int follow_symlinks);
223
224
static PyObject *
225
os_statx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
226
0
{
227
0
    PyObject *return_value = NULL;
228
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
229
230
0
    #define NUM_KEYWORDS 5
231
0
    static struct {
232
0
        PyGC_Head _this_is_not_used;
233
0
        PyObject_VAR_HEAD
234
0
        Py_hash_t ob_hash;
235
0
        PyObject *ob_item[NUM_KEYWORDS];
236
0
    } _kwtuple = {
237
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
238
0
        .ob_hash = -1,
239
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mask), &_Py_ID(flags), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
240
0
    };
241
0
    #undef NUM_KEYWORDS
242
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
243
244
    #else  // !Py_BUILD_CORE
245
    #  define KWTUPLE NULL
246
    #endif  // !Py_BUILD_CORE
247
248
0
    static const char * const _keywords[] = {"path", "mask", "flags", "dir_fd", "follow_symlinks", NULL};
249
0
    static _PyArg_Parser _parser = {
250
0
        .keywords = _keywords,
251
0
        .fname = "statx",
252
0
        .kwtuple = KWTUPLE,
253
0
    };
254
0
    #undef KWTUPLE
255
0
    PyObject *argsbuf[5];
256
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
257
0
    path_t path = PATH_T_INITIALIZE_P("statx", "path", 0, 0, 0, 1);
258
0
    unsigned int mask;
259
0
    int flags = 0;
260
0
    int dir_fd = DEFAULT_DIR_FD;
261
0
    int follow_symlinks = 1;
262
263
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
264
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
265
0
    if (!args) {
266
0
        goto exit;
267
0
    }
268
0
    if (!path_converter(args[0], &path)) {
269
0
        goto exit;
270
0
    }
271
0
    {
272
0
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &mask, sizeof(unsigned int),
273
0
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
274
0
                Py_ASNATIVEBYTES_ALLOW_INDEX |
275
0
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
276
0
        if (_bytes < 0) {
277
0
            goto exit;
278
0
        }
279
0
        if ((size_t)_bytes > sizeof(unsigned int)) {
280
0
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
281
0
                "integer value out of range", 1) < 0)
282
0
            {
283
0
                goto exit;
284
0
            }
285
0
        }
286
0
    }
287
0
    if (!noptargs) {
288
0
        goto skip_optional_kwonly;
289
0
    }
290
0
    if (args[2]) {
291
0
        flags = PyLong_AsInt(args[2]);
292
0
        if (flags == -1 && PyErr_Occurred()) {
293
0
            goto exit;
294
0
        }
295
0
        if (!--noptargs) {
296
0
            goto skip_optional_kwonly;
297
0
        }
298
0
    }
299
0
    if (args[3]) {
300
0
        if (!dir_fd_converter(args[3], &dir_fd)) {
301
0
            goto exit;
302
0
        }
303
0
        if (!--noptargs) {
304
0
            goto skip_optional_kwonly;
305
0
        }
306
0
    }
307
0
    follow_symlinks = PyObject_IsTrue(args[4]);
308
0
    if (follow_symlinks < 0) {
309
0
        goto exit;
310
0
    }
311
0
skip_optional_kwonly:
312
0
    return_value = os_statx_impl(module, &path, mask, flags, dir_fd, follow_symlinks);
313
314
0
exit:
315
    /* Cleanup for path */
316
0
    path_cleanup(&path);
317
318
0
    return return_value;
319
0
}
320
321
#endif /* defined(HAVE_STATX) */
322
323
PyDoc_STRVAR(os_access__doc__,
324
"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
325
"       follow_symlinks=True)\n"
326
"--\n"
327
"\n"
328
"Use the real uid/gid to test for access to a path.\n"
329
"\n"
330
"  path\n"
331
"    Path to be tested; can be string, bytes, or a path-like object.\n"
332
"  mode\n"
333
"    Operating-system mode bitfield.  Can be F_OK to test existence,\n"
334
"    or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
335
"  dir_fd\n"
336
"    If not None, it should be a file descriptor open to a directory,\n"
337
"    and path should be relative; path will then be relative to that\n"
338
"    directory.\n"
339
"  effective_ids\n"
340
"    If True, access will use the effective uid/gid instead of\n"
341
"    the real uid/gid.\n"
342
"  follow_symlinks\n"
343
"    If False, and the last element of the path is a symbolic link,\n"
344
"    access will examine the symbolic link itself instead of the file\n"
345
"    the link points to.\n"
346
"\n"
347
"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
348
"  on your platform.  If they are unavailable, using them will raise a\n"
349
"  NotImplementedError.\n"
350
"\n"
351
"Note that most operations will use the effective uid/gid, therefore this\n"
352
"  routine can be used in a suid/sgid environment to test if the invoking\n"
353
"  user has the specified access to the path.");
354
355
#define OS_ACCESS_METHODDEF    \
356
    {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
357
358
static int
359
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
360
               int effective_ids, int follow_symlinks);
361
362
static PyObject *
363
os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
364
0
{
365
0
    PyObject *return_value = NULL;
366
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
367
368
0
    #define NUM_KEYWORDS 5
369
0
    static struct {
370
0
        PyGC_Head _this_is_not_used;
371
0
        PyObject_VAR_HEAD
372
0
        Py_hash_t ob_hash;
373
0
        PyObject *ob_item[NUM_KEYWORDS];
374
0
    } _kwtuple = {
375
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
376
0
        .ob_hash = -1,
377
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), },
378
0
    };
379
0
    #undef NUM_KEYWORDS
380
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
381
382
    #else  // !Py_BUILD_CORE
383
    #  define KWTUPLE NULL
384
    #endif  // !Py_BUILD_CORE
385
386
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
387
0
    static _PyArg_Parser _parser = {
388
0
        .keywords = _keywords,
389
0
        .fname = "access",
390
0
        .kwtuple = KWTUPLE,
391
0
    };
392
0
    #undef KWTUPLE
393
0
    PyObject *argsbuf[5];
394
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
395
0
    path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0);
396
0
    int mode;
397
0
    int dir_fd = DEFAULT_DIR_FD;
398
0
    int effective_ids = 0;
399
0
    int follow_symlinks = 1;
400
0
    int _return_value;
401
402
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
403
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
404
0
    if (!args) {
405
0
        goto exit;
406
0
    }
407
0
    if (!path_converter(args[0], &path)) {
408
0
        goto exit;
409
0
    }
410
0
    mode = PyLong_AsInt(args[1]);
411
0
    if (mode == -1 && PyErr_Occurred()) {
412
0
        goto exit;
413
0
    }
414
0
    if (!noptargs) {
415
0
        goto skip_optional_kwonly;
416
0
    }
417
0
    if (args[2]) {
418
0
        if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
419
0
            goto exit;
420
0
        }
421
0
        if (!--noptargs) {
422
0
            goto skip_optional_kwonly;
423
0
        }
424
0
    }
425
0
    if (args[3]) {
426
0
        effective_ids = PyObject_IsTrue(args[3]);
427
0
        if (effective_ids < 0) {
428
0
            goto exit;
429
0
        }
430
0
        if (!--noptargs) {
431
0
            goto skip_optional_kwonly;
432
0
        }
433
0
    }
434
0
    follow_symlinks = PyObject_IsTrue(args[4]);
435
0
    if (follow_symlinks < 0) {
436
0
        goto exit;
437
0
    }
438
0
skip_optional_kwonly:
439
0
    _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
440
0
    if ((_return_value == -1) && PyErr_Occurred()) {
441
0
        goto exit;
442
0
    }
443
0
    return_value = PyBool_FromLong((long)_return_value);
444
445
0
exit:
446
    /* Cleanup for path */
447
0
    path_cleanup(&path);
448
449
0
    return return_value;
450
0
}
451
452
#if defined(HAVE_TTYNAME_R)
453
454
PyDoc_STRVAR(os_ttyname__doc__,
455
"ttyname($module, fd, /)\n"
456
"--\n"
457
"\n"
458
"Return the name of the terminal device connected to \'fd\'.\n"
459
"\n"
460
"  fd\n"
461
"    Integer file descriptor handle.");
462
463
#define OS_TTYNAME_METHODDEF    \
464
    {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
465
466
static PyObject *
467
os_ttyname_impl(PyObject *module, int fd);
468
469
static PyObject *
470
os_ttyname(PyObject *module, PyObject *arg)
471
0
{
472
0
    PyObject *return_value = NULL;
473
0
    int fd;
474
475
0
    fd = PyLong_AsInt(arg);
476
0
    if (fd == -1 && PyErr_Occurred()) {
477
0
        goto exit;
478
0
    }
479
0
    return_value = os_ttyname_impl(module, fd);
480
481
0
exit:
482
0
    return return_value;
483
0
}
484
485
#endif /* defined(HAVE_TTYNAME_R) */
486
487
#if defined(HAVE_CTERMID)
488
489
PyDoc_STRVAR(os_ctermid__doc__,
490
"ctermid($module, /)\n"
491
"--\n"
492
"\n"
493
"Return the name of the controlling terminal for this process.");
494
495
#define OS_CTERMID_METHODDEF    \
496
    {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
497
498
static PyObject *
499
os_ctermid_impl(PyObject *module);
500
501
static PyObject *
502
os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
503
0
{
504
0
    return os_ctermid_impl(module);
505
0
}
506
507
#endif /* defined(HAVE_CTERMID) */
508
509
PyDoc_STRVAR(os_chdir__doc__,
510
"chdir($module, /, path)\n"
511
"--\n"
512
"\n"
513
"Change the current working directory to the specified path.\n"
514
"\n"
515
"path may always be specified as a string.\n"
516
"On some platforms, path may also be specified as an open file descriptor.\n"
517
"If this functionality is unavailable, using it raises an exception.");
518
519
#define OS_CHDIR_METHODDEF    \
520
    {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
521
522
static PyObject *
523
os_chdir_impl(PyObject *module, path_t *path);
524
525
static PyObject *
526
os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
527
0
{
528
0
    PyObject *return_value = NULL;
529
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
530
531
0
    #define NUM_KEYWORDS 1
532
0
    static struct {
533
0
        PyGC_Head _this_is_not_used;
534
0
        PyObject_VAR_HEAD
535
0
        Py_hash_t ob_hash;
536
0
        PyObject *ob_item[NUM_KEYWORDS];
537
0
    } _kwtuple = {
538
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
539
0
        .ob_hash = -1,
540
0
        .ob_item = { &_Py_ID(path), },
541
0
    };
542
0
    #undef NUM_KEYWORDS
543
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
544
545
    #else  // !Py_BUILD_CORE
546
    #  define KWTUPLE NULL
547
    #endif  // !Py_BUILD_CORE
548
549
0
    static const char * const _keywords[] = {"path", NULL};
550
0
    static _PyArg_Parser _parser = {
551
0
        .keywords = _keywords,
552
0
        .fname = "chdir",
553
0
        .kwtuple = KWTUPLE,
554
0
    };
555
0
    #undef KWTUPLE
556
0
    PyObject *argsbuf[1];
557
0
    path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR);
558
559
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
560
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
561
0
    if (!args) {
562
0
        goto exit;
563
0
    }
564
0
    if (!path_converter(args[0], &path)) {
565
0
        goto exit;
566
0
    }
567
0
    return_value = os_chdir_impl(module, &path);
568
569
0
exit:
570
    /* Cleanup for path */
571
0
    path_cleanup(&path);
572
573
0
    return return_value;
574
0
}
575
576
#if defined(HAVE_FCHDIR)
577
578
PyDoc_STRVAR(os_fchdir__doc__,
579
"fchdir($module, /, fd)\n"
580
"--\n"
581
"\n"
582
"Change to the directory of the given file descriptor.\n"
583
"\n"
584
"fd must be opened on a directory, not a file.\n"
585
"Equivalent to os.chdir(fd).");
586
587
#define OS_FCHDIR_METHODDEF    \
588
    {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
589
590
static PyObject *
591
os_fchdir_impl(PyObject *module, int fd);
592
593
static PyObject *
594
os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
595
0
{
596
0
    PyObject *return_value = NULL;
597
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
598
599
0
    #define NUM_KEYWORDS 1
600
0
    static struct {
601
0
        PyGC_Head _this_is_not_used;
602
0
        PyObject_VAR_HEAD
603
0
        Py_hash_t ob_hash;
604
0
        PyObject *ob_item[NUM_KEYWORDS];
605
0
    } _kwtuple = {
606
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
607
0
        .ob_hash = -1,
608
0
        .ob_item = { &_Py_ID(fd), },
609
0
    };
610
0
    #undef NUM_KEYWORDS
611
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
612
613
    #else  // !Py_BUILD_CORE
614
    #  define KWTUPLE NULL
615
    #endif  // !Py_BUILD_CORE
616
617
0
    static const char * const _keywords[] = {"fd", NULL};
618
0
    static _PyArg_Parser _parser = {
619
0
        .keywords = _keywords,
620
0
        .fname = "fchdir",
621
0
        .kwtuple = KWTUPLE,
622
0
    };
623
0
    #undef KWTUPLE
624
0
    PyObject *argsbuf[1];
625
0
    int fd;
626
627
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
628
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
629
0
    if (!args) {
630
0
        goto exit;
631
0
    }
632
0
    fd = PyObject_AsFileDescriptor(args[0]);
633
0
    if (fd < 0) {
634
0
        goto exit;
635
0
    }
636
0
    return_value = os_fchdir_impl(module, fd);
637
638
0
exit:
639
0
    return return_value;
640
0
}
641
642
#endif /* defined(HAVE_FCHDIR) */
643
644
PyDoc_STRVAR(os_chmod__doc__,
645
"chmod($module, /, path, mode, *, dir_fd=None,\n"
646
"      follow_symlinks=(os.name != \'nt\'))\n"
647
"--\n"
648
"\n"
649
"Change the access permissions of a file.\n"
650
"\n"
651
"  path\n"
652
"    Path to be modified.  May always be specified as a str, bytes, or a path-like object.\n"
653
"    On some platforms, path may also be specified as an open file descriptor.\n"
654
"    If this functionality is unavailable, using it raises an exception.\n"
655
"  mode\n"
656
"    Operating-system mode bitfield.\n"
657
"    Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
658
"    numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
659
"    Python.\n"
660
"  dir_fd\n"
661
"    If not None, it should be a file descriptor open to a directory,\n"
662
"    and path should be relative; path will then be relative to that\n"
663
"    directory.\n"
664
"  follow_symlinks\n"
665
"    If False, and the last element of the path is a symbolic link,\n"
666
"    chmod will modify the symbolic link itself instead of the file\n"
667
"    the link points to.\n"
668
"\n"
669
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
670
"  an open file descriptor.\n"
671
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
672
"  If they are unavailable, using them will raise a NotImplementedError.");
673
674
#define OS_CHMOD_METHODDEF    \
675
    {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
676
677
static PyObject *
678
os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
679
              int follow_symlinks);
680
681
static PyObject *
682
os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
683
0
{
684
0
    PyObject *return_value = NULL;
685
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
686
687
0
    #define NUM_KEYWORDS 4
688
0
    static struct {
689
0
        PyGC_Head _this_is_not_used;
690
0
        PyObject_VAR_HEAD
691
0
        Py_hash_t ob_hash;
692
0
        PyObject *ob_item[NUM_KEYWORDS];
693
0
    } _kwtuple = {
694
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
695
0
        .ob_hash = -1,
696
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
697
0
    };
698
0
    #undef NUM_KEYWORDS
699
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
700
701
    #else  // !Py_BUILD_CORE
702
    #  define KWTUPLE NULL
703
    #endif  // !Py_BUILD_CORE
704
705
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
706
0
    static _PyArg_Parser _parser = {
707
0
        .keywords = _keywords,
708
0
        .fname = "chmod",
709
0
        .kwtuple = KWTUPLE,
710
0
    };
711
0
    #undef KWTUPLE
712
0
    PyObject *argsbuf[4];
713
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
714
0
    path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD);
715
0
    int mode;
716
0
    int dir_fd = DEFAULT_DIR_FD;
717
0
    int follow_symlinks = CHMOD_DEFAULT_FOLLOW_SYMLINKS;
718
719
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
720
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
721
0
    if (!args) {
722
0
        goto exit;
723
0
    }
724
0
    if (!path_converter(args[0], &path)) {
725
0
        goto exit;
726
0
    }
727
0
    mode = PyLong_AsInt(args[1]);
728
0
    if (mode == -1 && PyErr_Occurred()) {
729
0
        goto exit;
730
0
    }
731
0
    if (!noptargs) {
732
0
        goto skip_optional_kwonly;
733
0
    }
734
0
    if (args[2]) {
735
0
        if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
736
0
            goto exit;
737
0
        }
738
0
        if (!--noptargs) {
739
0
            goto skip_optional_kwonly;
740
0
        }
741
0
    }
742
0
    follow_symlinks = PyObject_IsTrue(args[3]);
743
0
    if (follow_symlinks < 0) {
744
0
        goto exit;
745
0
    }
746
0
skip_optional_kwonly:
747
0
    return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
748
749
0
exit:
750
    /* Cleanup for path */
751
0
    path_cleanup(&path);
752
753
0
    return return_value;
754
0
}
755
756
#if (defined(HAVE_FCHMOD) || defined(MS_WINDOWS))
757
758
PyDoc_STRVAR(os_fchmod__doc__,
759
"fchmod($module, /, fd, mode)\n"
760
"--\n"
761
"\n"
762
"Change the access permissions of the file given by file descriptor fd.\n"
763
"\n"
764
"  fd\n"
765
"    The file descriptor of the file to be modified.\n"
766
"  mode\n"
767
"    Operating-system mode bitfield.\n"
768
"    Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
769
"    numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
770
"    Python.\n"
771
"\n"
772
"Equivalent to os.chmod(fd, mode).");
773
774
#define OS_FCHMOD_METHODDEF    \
775
    {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
776
777
static PyObject *
778
os_fchmod_impl(PyObject *module, int fd, int mode);
779
780
static PyObject *
781
os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
782
0
{
783
0
    PyObject *return_value = NULL;
784
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
785
786
0
    #define NUM_KEYWORDS 2
787
0
    static struct {
788
0
        PyGC_Head _this_is_not_used;
789
0
        PyObject_VAR_HEAD
790
0
        Py_hash_t ob_hash;
791
0
        PyObject *ob_item[NUM_KEYWORDS];
792
0
    } _kwtuple = {
793
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
794
0
        .ob_hash = -1,
795
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(mode), },
796
0
    };
797
0
    #undef NUM_KEYWORDS
798
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
799
800
    #else  // !Py_BUILD_CORE
801
    #  define KWTUPLE NULL
802
    #endif  // !Py_BUILD_CORE
803
804
0
    static const char * const _keywords[] = {"fd", "mode", NULL};
805
0
    static _PyArg_Parser _parser = {
806
0
        .keywords = _keywords,
807
0
        .fname = "fchmod",
808
0
        .kwtuple = KWTUPLE,
809
0
    };
810
0
    #undef KWTUPLE
811
0
    PyObject *argsbuf[2];
812
0
    int fd;
813
0
    int mode;
814
815
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
816
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
817
0
    if (!args) {
818
0
        goto exit;
819
0
    }
820
0
    fd = PyLong_AsInt(args[0]);
821
0
    if (fd == -1 && PyErr_Occurred()) {
822
0
        goto exit;
823
0
    }
824
0
    mode = PyLong_AsInt(args[1]);
825
0
    if (mode == -1 && PyErr_Occurred()) {
826
0
        goto exit;
827
0
    }
828
0
    return_value = os_fchmod_impl(module, fd, mode);
829
830
0
exit:
831
0
    return return_value;
832
0
}
833
834
#endif /* (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) */
835
836
#if (defined(HAVE_LCHMOD) || defined(MS_WINDOWS))
837
838
PyDoc_STRVAR(os_lchmod__doc__,
839
"lchmod($module, /, path, mode)\n"
840
"--\n"
841
"\n"
842
"Change the access permissions of a file, without following symbolic links.\n"
843
"\n"
844
"If path is a symlink, this affects the link itself rather than the target.\n"
845
"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
846
847
#define OS_LCHMOD_METHODDEF    \
848
    {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
849
850
static PyObject *
851
os_lchmod_impl(PyObject *module, path_t *path, int mode);
852
853
static PyObject *
854
os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
855
{
856
    PyObject *return_value = NULL;
857
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
858
859
    #define NUM_KEYWORDS 2
860
    static struct {
861
        PyGC_Head _this_is_not_used;
862
        PyObject_VAR_HEAD
863
        Py_hash_t ob_hash;
864
        PyObject *ob_item[NUM_KEYWORDS];
865
    } _kwtuple = {
866
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
867
        .ob_hash = -1,
868
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), },
869
    };
870
    #undef NUM_KEYWORDS
871
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
872
873
    #else  // !Py_BUILD_CORE
874
    #  define KWTUPLE NULL
875
    #endif  // !Py_BUILD_CORE
876
877
    static const char * const _keywords[] = {"path", "mode", NULL};
878
    static _PyArg_Parser _parser = {
879
        .keywords = _keywords,
880
        .fname = "lchmod",
881
        .kwtuple = KWTUPLE,
882
    };
883
    #undef KWTUPLE
884
    PyObject *argsbuf[2];
885
    path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0);
886
    int mode;
887
888
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
889
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
890
    if (!args) {
891
        goto exit;
892
    }
893
    if (!path_converter(args[0], &path)) {
894
        goto exit;
895
    }
896
    mode = PyLong_AsInt(args[1]);
897
    if (mode == -1 && PyErr_Occurred()) {
898
        goto exit;
899
    }
900
    return_value = os_lchmod_impl(module, &path, mode);
901
902
exit:
903
    /* Cleanup for path */
904
    path_cleanup(&path);
905
906
    return return_value;
907
}
908
909
#endif /* (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) */
910
911
#if defined(HAVE_CHFLAGS)
912
913
PyDoc_STRVAR(os_chflags__doc__,
914
"chflags($module, /, path, flags, follow_symlinks=True)\n"
915
"--\n"
916
"\n"
917
"Set file flags.\n"
918
"\n"
919
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
920
"  link, chflags will change flags on the symbolic link itself instead of the\n"
921
"  file the link points to.\n"
922
"follow_symlinks may not be implemented on your platform.  If it is\n"
923
"unavailable, using it will raise a NotImplementedError.");
924
925
#define OS_CHFLAGS_METHODDEF    \
926
    {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
927
928
static PyObject *
929
os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
930
                int follow_symlinks);
931
932
static PyObject *
933
os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
934
{
935
    PyObject *return_value = NULL;
936
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
937
938
    #define NUM_KEYWORDS 3
939
    static struct {
940
        PyGC_Head _this_is_not_used;
941
        PyObject_VAR_HEAD
942
        Py_hash_t ob_hash;
943
        PyObject *ob_item[NUM_KEYWORDS];
944
    } _kwtuple = {
945
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
946
        .ob_hash = -1,
947
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
948
    };
949
    #undef NUM_KEYWORDS
950
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
951
952
    #else  // !Py_BUILD_CORE
953
    #  define KWTUPLE NULL
954
    #endif  // !Py_BUILD_CORE
955
956
    static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
957
    static _PyArg_Parser _parser = {
958
        .keywords = _keywords,
959
        .fname = "chflags",
960
        .kwtuple = KWTUPLE,
961
    };
962
    #undef KWTUPLE
963
    PyObject *argsbuf[3];
964
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
965
    path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0);
966
    unsigned long flags;
967
    int follow_symlinks = 1;
968
969
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
970
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
971
    if (!args) {
972
        goto exit;
973
    }
974
    if (!path_converter(args[0], &path)) {
975
        goto exit;
976
    }
977
    if (!PyIndex_Check(args[1])) {
978
        _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]);
979
        goto exit;
980
    }
981
    {
982
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long),
983
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
984
                Py_ASNATIVEBYTES_ALLOW_INDEX |
985
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
986
        if (_bytes < 0) {
987
            goto exit;
988
        }
989
        if ((size_t)_bytes > sizeof(unsigned long)) {
990
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
991
                "integer value out of range", 1) < 0)
992
            {
993
                goto exit;
994
            }
995
        }
996
    }
997
    if (!noptargs) {
998
        goto skip_optional_pos;
999
    }
1000
    follow_symlinks = PyObject_IsTrue(args[2]);
1001
    if (follow_symlinks < 0) {
1002
        goto exit;
1003
    }
1004
skip_optional_pos:
1005
    return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
1006
1007
exit:
1008
    /* Cleanup for path */
1009
    path_cleanup(&path);
1010
1011
    return return_value;
1012
}
1013
1014
#endif /* defined(HAVE_CHFLAGS) */
1015
1016
#if defined(HAVE_LCHFLAGS)
1017
1018
PyDoc_STRVAR(os_lchflags__doc__,
1019
"lchflags($module, /, path, flags)\n"
1020
"--\n"
1021
"\n"
1022
"Set file flags.\n"
1023
"\n"
1024
"This function will not follow symbolic links.\n"
1025
"Equivalent to chflags(path, flags, follow_symlinks=False).");
1026
1027
#define OS_LCHFLAGS_METHODDEF    \
1028
    {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
1029
1030
static PyObject *
1031
os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
1032
1033
static PyObject *
1034
os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1035
{
1036
    PyObject *return_value = NULL;
1037
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1038
1039
    #define NUM_KEYWORDS 2
1040
    static struct {
1041
        PyGC_Head _this_is_not_used;
1042
        PyObject_VAR_HEAD
1043
        Py_hash_t ob_hash;
1044
        PyObject *ob_item[NUM_KEYWORDS];
1045
    } _kwtuple = {
1046
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1047
        .ob_hash = -1,
1048
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), },
1049
    };
1050
    #undef NUM_KEYWORDS
1051
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1052
1053
    #else  // !Py_BUILD_CORE
1054
    #  define KWTUPLE NULL
1055
    #endif  // !Py_BUILD_CORE
1056
1057
    static const char * const _keywords[] = {"path", "flags", NULL};
1058
    static _PyArg_Parser _parser = {
1059
        .keywords = _keywords,
1060
        .fname = "lchflags",
1061
        .kwtuple = KWTUPLE,
1062
    };
1063
    #undef KWTUPLE
1064
    PyObject *argsbuf[2];
1065
    path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0);
1066
    unsigned long flags;
1067
1068
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1069
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1070
    if (!args) {
1071
        goto exit;
1072
    }
1073
    if (!path_converter(args[0], &path)) {
1074
        goto exit;
1075
    }
1076
    if (!PyIndex_Check(args[1])) {
1077
        _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]);
1078
        goto exit;
1079
    }
1080
    {
1081
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long),
1082
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
1083
                Py_ASNATIVEBYTES_ALLOW_INDEX |
1084
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
1085
        if (_bytes < 0) {
1086
            goto exit;
1087
        }
1088
        if ((size_t)_bytes > sizeof(unsigned long)) {
1089
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
1090
                "integer value out of range", 1) < 0)
1091
            {
1092
                goto exit;
1093
            }
1094
        }
1095
    }
1096
    return_value = os_lchflags_impl(module, &path, flags);
1097
1098
exit:
1099
    /* Cleanup for path */
1100
    path_cleanup(&path);
1101
1102
    return return_value;
1103
}
1104
1105
#endif /* defined(HAVE_LCHFLAGS) */
1106
1107
#if defined(HAVE_CHROOT)
1108
1109
PyDoc_STRVAR(os_chroot__doc__,
1110
"chroot($module, /, path)\n"
1111
"--\n"
1112
"\n"
1113
"Change root directory to path.");
1114
1115
#define OS_CHROOT_METHODDEF    \
1116
    {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
1117
1118
static PyObject *
1119
os_chroot_impl(PyObject *module, path_t *path);
1120
1121
static PyObject *
1122
os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1123
0
{
1124
0
    PyObject *return_value = NULL;
1125
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1126
1127
0
    #define NUM_KEYWORDS 1
1128
0
    static struct {
1129
0
        PyGC_Head _this_is_not_used;
1130
0
        PyObject_VAR_HEAD
1131
0
        Py_hash_t ob_hash;
1132
0
        PyObject *ob_item[NUM_KEYWORDS];
1133
0
    } _kwtuple = {
1134
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1135
0
        .ob_hash = -1,
1136
0
        .ob_item = { &_Py_ID(path), },
1137
0
    };
1138
0
    #undef NUM_KEYWORDS
1139
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1140
1141
    #else  // !Py_BUILD_CORE
1142
    #  define KWTUPLE NULL
1143
    #endif  // !Py_BUILD_CORE
1144
1145
0
    static const char * const _keywords[] = {"path", NULL};
1146
0
    static _PyArg_Parser _parser = {
1147
0
        .keywords = _keywords,
1148
0
        .fname = "chroot",
1149
0
        .kwtuple = KWTUPLE,
1150
0
    };
1151
0
    #undef KWTUPLE
1152
0
    PyObject *argsbuf[1];
1153
0
    path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0);
1154
1155
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1156
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1157
0
    if (!args) {
1158
0
        goto exit;
1159
0
    }
1160
0
    if (!path_converter(args[0], &path)) {
1161
0
        goto exit;
1162
0
    }
1163
0
    return_value = os_chroot_impl(module, &path);
1164
1165
0
exit:
1166
    /* Cleanup for path */
1167
0
    path_cleanup(&path);
1168
1169
0
    return return_value;
1170
0
}
1171
1172
#endif /* defined(HAVE_CHROOT) */
1173
1174
#if defined(HAVE_FSYNC)
1175
1176
PyDoc_STRVAR(os_fsync__doc__,
1177
"fsync($module, /, fd)\n"
1178
"--\n"
1179
"\n"
1180
"Force write of fd to disk.");
1181
1182
#define OS_FSYNC_METHODDEF    \
1183
    {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
1184
1185
static PyObject *
1186
os_fsync_impl(PyObject *module, int fd);
1187
1188
static PyObject *
1189
os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1190
0
{
1191
0
    PyObject *return_value = NULL;
1192
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1193
1194
0
    #define NUM_KEYWORDS 1
1195
0
    static struct {
1196
0
        PyGC_Head _this_is_not_used;
1197
0
        PyObject_VAR_HEAD
1198
0
        Py_hash_t ob_hash;
1199
0
        PyObject *ob_item[NUM_KEYWORDS];
1200
0
    } _kwtuple = {
1201
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1202
0
        .ob_hash = -1,
1203
0
        .ob_item = { &_Py_ID(fd), },
1204
0
    };
1205
0
    #undef NUM_KEYWORDS
1206
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1207
1208
    #else  // !Py_BUILD_CORE
1209
    #  define KWTUPLE NULL
1210
    #endif  // !Py_BUILD_CORE
1211
1212
0
    static const char * const _keywords[] = {"fd", NULL};
1213
0
    static _PyArg_Parser _parser = {
1214
0
        .keywords = _keywords,
1215
0
        .fname = "fsync",
1216
0
        .kwtuple = KWTUPLE,
1217
0
    };
1218
0
    #undef KWTUPLE
1219
0
    PyObject *argsbuf[1];
1220
0
    int fd;
1221
1222
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1223
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1224
0
    if (!args) {
1225
0
        goto exit;
1226
0
    }
1227
0
    fd = PyObject_AsFileDescriptor(args[0]);
1228
0
    if (fd < 0) {
1229
0
        goto exit;
1230
0
    }
1231
0
    return_value = os_fsync_impl(module, fd);
1232
1233
0
exit:
1234
0
    return return_value;
1235
0
}
1236
1237
#endif /* defined(HAVE_FSYNC) */
1238
1239
#if defined(HAVE_SYNC)
1240
1241
PyDoc_STRVAR(os_sync__doc__,
1242
"sync($module, /)\n"
1243
"--\n"
1244
"\n"
1245
"Force write of everything to disk.");
1246
1247
#define OS_SYNC_METHODDEF    \
1248
    {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
1249
1250
static PyObject *
1251
os_sync_impl(PyObject *module);
1252
1253
static PyObject *
1254
os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
1255
0
{
1256
0
    return os_sync_impl(module);
1257
0
}
1258
1259
#endif /* defined(HAVE_SYNC) */
1260
1261
#if defined(HAVE_FDATASYNC)
1262
1263
PyDoc_STRVAR(os_fdatasync__doc__,
1264
"fdatasync($module, /, fd)\n"
1265
"--\n"
1266
"\n"
1267
"Force write of fd to disk without forcing update of metadata.");
1268
1269
#define OS_FDATASYNC_METHODDEF    \
1270
    {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
1271
1272
static PyObject *
1273
os_fdatasync_impl(PyObject *module, int fd);
1274
1275
static PyObject *
1276
os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1277
0
{
1278
0
    PyObject *return_value = NULL;
1279
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1280
1281
0
    #define NUM_KEYWORDS 1
1282
0
    static struct {
1283
0
        PyGC_Head _this_is_not_used;
1284
0
        PyObject_VAR_HEAD
1285
0
        Py_hash_t ob_hash;
1286
0
        PyObject *ob_item[NUM_KEYWORDS];
1287
0
    } _kwtuple = {
1288
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1289
0
        .ob_hash = -1,
1290
0
        .ob_item = { &_Py_ID(fd), },
1291
0
    };
1292
0
    #undef NUM_KEYWORDS
1293
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1294
1295
    #else  // !Py_BUILD_CORE
1296
    #  define KWTUPLE NULL
1297
    #endif  // !Py_BUILD_CORE
1298
1299
0
    static const char * const _keywords[] = {"fd", NULL};
1300
0
    static _PyArg_Parser _parser = {
1301
0
        .keywords = _keywords,
1302
0
        .fname = "fdatasync",
1303
0
        .kwtuple = KWTUPLE,
1304
0
    };
1305
0
    #undef KWTUPLE
1306
0
    PyObject *argsbuf[1];
1307
0
    int fd;
1308
1309
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1310
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1311
0
    if (!args) {
1312
0
        goto exit;
1313
0
    }
1314
0
    fd = PyObject_AsFileDescriptor(args[0]);
1315
0
    if (fd < 0) {
1316
0
        goto exit;
1317
0
    }
1318
0
    return_value = os_fdatasync_impl(module, fd);
1319
1320
0
exit:
1321
0
    return return_value;
1322
0
}
1323
1324
#endif /* defined(HAVE_FDATASYNC) */
1325
1326
#if defined(HAVE_CHOWN)
1327
1328
PyDoc_STRVAR(os_chown__doc__,
1329
"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
1330
"--\n"
1331
"\n"
1332
"Change the owner and group id of path to the numeric uid and gid.\\\n"
1333
"\n"
1334
"  path\n"
1335
"    Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
1336
"  dir_fd\n"
1337
"    If not None, it should be a file descriptor open to a directory,\n"
1338
"    and path should be relative; path will then be relative to that\n"
1339
"    directory.\n"
1340
"  follow_symlinks\n"
1341
"    If False, and the last element of the path is a symbolic link,\n"
1342
"    stat will examine the symbolic link itself instead of the file\n"
1343
"    the link points to.\n"
1344
"\n"
1345
"path may always be specified as a string.\n"
1346
"On some platforms, path may also be specified as an open file descriptor.\n"
1347
"  If this functionality is unavailable, using it raises an exception.\n"
1348
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1349
"  and path should be relative; path will then be relative to that directory.\n"
1350
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1351
"  link, chown will modify the symbolic link itself instead of the file the\n"
1352
"  link points to.\n"
1353
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
1354
"  an open file descriptor.\n"
1355
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
1356
"  If they are unavailable, using them will raise a NotImplementedError.");
1357
1358
#define OS_CHOWN_METHODDEF    \
1359
    {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
1360
1361
static PyObject *
1362
os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
1363
              int dir_fd, int follow_symlinks);
1364
1365
static PyObject *
1366
os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1367
0
{
1368
0
    PyObject *return_value = NULL;
1369
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1370
1371
0
    #define NUM_KEYWORDS 5
1372
0
    static struct {
1373
0
        PyGC_Head _this_is_not_used;
1374
0
        PyObject_VAR_HEAD
1375
0
        Py_hash_t ob_hash;
1376
0
        PyObject *ob_item[NUM_KEYWORDS];
1377
0
    } _kwtuple = {
1378
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1379
0
        .ob_hash = -1,
1380
0
        .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
1381
0
    };
1382
0
    #undef NUM_KEYWORDS
1383
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1384
1385
    #else  // !Py_BUILD_CORE
1386
    #  define KWTUPLE NULL
1387
    #endif  // !Py_BUILD_CORE
1388
1389
0
    static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
1390
0
    static _PyArg_Parser _parser = {
1391
0
        .keywords = _keywords,
1392
0
        .fname = "chown",
1393
0
        .kwtuple = KWTUPLE,
1394
0
    };
1395
0
    #undef KWTUPLE
1396
0
    PyObject *argsbuf[5];
1397
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
1398
0
    path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN);
1399
0
    uid_t uid;
1400
0
    gid_t gid;
1401
0
    int dir_fd = DEFAULT_DIR_FD;
1402
0
    int follow_symlinks = 1;
1403
1404
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1405
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1406
0
    if (!args) {
1407
0
        goto exit;
1408
0
    }
1409
0
    if (!path_converter(args[0], &path)) {
1410
0
        goto exit;
1411
0
    }
1412
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1413
0
        goto exit;
1414
0
    }
1415
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1416
0
        goto exit;
1417
0
    }
1418
0
    if (!noptargs) {
1419
0
        goto skip_optional_kwonly;
1420
0
    }
1421
0
    if (args[3]) {
1422
0
        if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
1423
0
            goto exit;
1424
0
        }
1425
0
        if (!--noptargs) {
1426
0
            goto skip_optional_kwonly;
1427
0
        }
1428
0
    }
1429
0
    follow_symlinks = PyObject_IsTrue(args[4]);
1430
0
    if (follow_symlinks < 0) {
1431
0
        goto exit;
1432
0
    }
1433
0
skip_optional_kwonly:
1434
0
    return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
1435
1436
0
exit:
1437
    /* Cleanup for path */
1438
0
    path_cleanup(&path);
1439
1440
0
    return return_value;
1441
0
}
1442
1443
#endif /* defined(HAVE_CHOWN) */
1444
1445
#if defined(HAVE_FCHOWN)
1446
1447
PyDoc_STRVAR(os_fchown__doc__,
1448
"fchown($module, /, fd, uid, gid)\n"
1449
"--\n"
1450
"\n"
1451
"Change the owner and group id of the file specified by file descriptor.\n"
1452
"\n"
1453
"Equivalent to os.chown(fd, uid, gid).");
1454
1455
#define OS_FCHOWN_METHODDEF    \
1456
    {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
1457
1458
static PyObject *
1459
os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
1460
1461
static PyObject *
1462
os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1463
0
{
1464
0
    PyObject *return_value = NULL;
1465
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1466
1467
0
    #define NUM_KEYWORDS 3
1468
0
    static struct {
1469
0
        PyGC_Head _this_is_not_used;
1470
0
        PyObject_VAR_HEAD
1471
0
        Py_hash_t ob_hash;
1472
0
        PyObject *ob_item[NUM_KEYWORDS];
1473
0
    } _kwtuple = {
1474
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1475
0
        .ob_hash = -1,
1476
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), },
1477
0
    };
1478
0
    #undef NUM_KEYWORDS
1479
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1480
1481
    #else  // !Py_BUILD_CORE
1482
    #  define KWTUPLE NULL
1483
    #endif  // !Py_BUILD_CORE
1484
1485
0
    static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
1486
0
    static _PyArg_Parser _parser = {
1487
0
        .keywords = _keywords,
1488
0
        .fname = "fchown",
1489
0
        .kwtuple = KWTUPLE,
1490
0
    };
1491
0
    #undef KWTUPLE
1492
0
    PyObject *argsbuf[3];
1493
0
    int fd;
1494
0
    uid_t uid;
1495
0
    gid_t gid;
1496
1497
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1498
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1499
0
    if (!args) {
1500
0
        goto exit;
1501
0
    }
1502
0
    fd = PyLong_AsInt(args[0]);
1503
0
    if (fd == -1 && PyErr_Occurred()) {
1504
0
        goto exit;
1505
0
    }
1506
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1507
0
        goto exit;
1508
0
    }
1509
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1510
0
        goto exit;
1511
0
    }
1512
0
    return_value = os_fchown_impl(module, fd, uid, gid);
1513
1514
0
exit:
1515
0
    return return_value;
1516
0
}
1517
1518
#endif /* defined(HAVE_FCHOWN) */
1519
1520
#if defined(HAVE_LCHOWN)
1521
1522
PyDoc_STRVAR(os_lchown__doc__,
1523
"lchown($module, /, path, uid, gid)\n"
1524
"--\n"
1525
"\n"
1526
"Change the owner and group id of path to the numeric uid and gid.\n"
1527
"\n"
1528
"This function will not follow symbolic links.\n"
1529
"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
1530
1531
#define OS_LCHOWN_METHODDEF    \
1532
    {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
1533
1534
static PyObject *
1535
os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
1536
1537
static PyObject *
1538
os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1539
0
{
1540
0
    PyObject *return_value = NULL;
1541
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1542
1543
0
    #define NUM_KEYWORDS 3
1544
0
    static struct {
1545
0
        PyGC_Head _this_is_not_used;
1546
0
        PyObject_VAR_HEAD
1547
0
        Py_hash_t ob_hash;
1548
0
        PyObject *ob_item[NUM_KEYWORDS];
1549
0
    } _kwtuple = {
1550
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1551
0
        .ob_hash = -1,
1552
0
        .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), },
1553
0
    };
1554
0
    #undef NUM_KEYWORDS
1555
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1556
1557
    #else  // !Py_BUILD_CORE
1558
    #  define KWTUPLE NULL
1559
    #endif  // !Py_BUILD_CORE
1560
1561
0
    static const char * const _keywords[] = {"path", "uid", "gid", NULL};
1562
0
    static _PyArg_Parser _parser = {
1563
0
        .keywords = _keywords,
1564
0
        .fname = "lchown",
1565
0
        .kwtuple = KWTUPLE,
1566
0
    };
1567
0
    #undef KWTUPLE
1568
0
    PyObject *argsbuf[3];
1569
0
    path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0);
1570
0
    uid_t uid;
1571
0
    gid_t gid;
1572
1573
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1574
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1575
0
    if (!args) {
1576
0
        goto exit;
1577
0
    }
1578
0
    if (!path_converter(args[0], &path)) {
1579
0
        goto exit;
1580
0
    }
1581
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1582
0
        goto exit;
1583
0
    }
1584
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1585
0
        goto exit;
1586
0
    }
1587
0
    return_value = os_lchown_impl(module, &path, uid, gid);
1588
1589
0
exit:
1590
    /* Cleanup for path */
1591
0
    path_cleanup(&path);
1592
1593
0
    return return_value;
1594
0
}
1595
1596
#endif /* defined(HAVE_LCHOWN) */
1597
1598
PyDoc_STRVAR(os_getcwd__doc__,
1599
"getcwd($module, /)\n"
1600
"--\n"
1601
"\n"
1602
"Return a unicode string representing the current working directory.");
1603
1604
#define OS_GETCWD_METHODDEF    \
1605
    {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
1606
1607
static PyObject *
1608
os_getcwd_impl(PyObject *module);
1609
1610
static PyObject *
1611
os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
1612
0
{
1613
0
    return os_getcwd_impl(module);
1614
0
}
1615
1616
PyDoc_STRVAR(os_getcwdb__doc__,
1617
"getcwdb($module, /)\n"
1618
"--\n"
1619
"\n"
1620
"Return a bytes string representing the current working directory.");
1621
1622
#define OS_GETCWDB_METHODDEF    \
1623
    {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
1624
1625
static PyObject *
1626
os_getcwdb_impl(PyObject *module);
1627
1628
static PyObject *
1629
os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
1630
0
{
1631
0
    return os_getcwdb_impl(module);
1632
0
}
1633
1634
#if defined(HAVE_LINK)
1635
1636
PyDoc_STRVAR(os_link__doc__,
1637
"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
1638
"     follow_symlinks=(os.name != \'nt\'))\n"
1639
"--\n"
1640
"\n"
1641
"Create a hard link to a file.\n"
1642
"\n"
1643
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1644
"  descriptor open to a directory, and the respective path string (src or dst)\n"
1645
"  should be relative; the path will then be relative to that directory.\n"
1646
"If follow_symlinks is False, and the last element of src is a symbolic\n"
1647
"  link, link will create a link to the symbolic link itself instead of the\n"
1648
"  file the link points to.\n"
1649
"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
1650
"  platform.  If they are unavailable, using them will raise a\n"
1651
"  NotImplementedError.");
1652
1653
#define OS_LINK_METHODDEF    \
1654
    {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
1655
1656
static PyObject *
1657
os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1658
             int dst_dir_fd, int follow_symlinks);
1659
1660
static PyObject *
1661
os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1662
0
{
1663
0
    PyObject *return_value = NULL;
1664
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1665
1666
0
    #define NUM_KEYWORDS 5
1667
0
    static struct {
1668
0
        PyGC_Head _this_is_not_used;
1669
0
        PyObject_VAR_HEAD
1670
0
        Py_hash_t ob_hash;
1671
0
        PyObject *ob_item[NUM_KEYWORDS];
1672
0
    } _kwtuple = {
1673
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1674
0
        .ob_hash = -1,
1675
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), },
1676
0
    };
1677
0
    #undef NUM_KEYWORDS
1678
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1679
1680
    #else  // !Py_BUILD_CORE
1681
    #  define KWTUPLE NULL
1682
    #endif  // !Py_BUILD_CORE
1683
1684
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
1685
0
    static _PyArg_Parser _parser = {
1686
0
        .keywords = _keywords,
1687
0
        .fname = "link",
1688
0
        .kwtuple = KWTUPLE,
1689
0
    };
1690
0
    #undef KWTUPLE
1691
0
    PyObject *argsbuf[5];
1692
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1693
0
    path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0);
1694
0
    path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0);
1695
0
    int src_dir_fd = DEFAULT_DIR_FD;
1696
0
    int dst_dir_fd = DEFAULT_DIR_FD;
1697
0
    int follow_symlinks = -1;
1698
1699
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1700
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1701
0
    if (!args) {
1702
0
        goto exit;
1703
0
    }
1704
0
    if (!path_converter(args[0], &src)) {
1705
0
        goto exit;
1706
0
    }
1707
0
    if (!path_converter(args[1], &dst)) {
1708
0
        goto exit;
1709
0
    }
1710
0
    if (!noptargs) {
1711
0
        goto skip_optional_kwonly;
1712
0
    }
1713
0
    if (args[2]) {
1714
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
1715
0
            goto exit;
1716
0
        }
1717
0
        if (!--noptargs) {
1718
0
            goto skip_optional_kwonly;
1719
0
        }
1720
0
    }
1721
0
    if (args[3]) {
1722
0
        if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1723
0
            goto exit;
1724
0
        }
1725
0
        if (!--noptargs) {
1726
0
            goto skip_optional_kwonly;
1727
0
        }
1728
0
    }
1729
0
    follow_symlinks = PyObject_IsTrue(args[4]);
1730
0
    if (follow_symlinks < 0) {
1731
0
        goto exit;
1732
0
    }
1733
0
skip_optional_kwonly:
1734
0
    return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
1735
1736
0
exit:
1737
    /* Cleanup for src */
1738
0
    path_cleanup(&src);
1739
    /* Cleanup for dst */
1740
0
    path_cleanup(&dst);
1741
1742
0
    return return_value;
1743
0
}
1744
1745
#endif /* defined(HAVE_LINK) */
1746
1747
PyDoc_STRVAR(os_listdir__doc__,
1748
"listdir($module, /, path=None)\n"
1749
"--\n"
1750
"\n"
1751
"Return a list containing the names of the files in the directory.\n"
1752
"\n"
1753
"path can be specified as either str, bytes, or a path-like object.  If path is bytes,\n"
1754
"  the filenames returned will also be bytes; in all other circumstances\n"
1755
"  the filenames returned will be str.\n"
1756
"If path is None, uses the path=\'.\'.\n"
1757
"On some platforms, path may also be specified as an open file descriptor;\\\n"
1758
"  the file descriptor must refer to a directory.\n"
1759
"  If this functionality is unavailable, using it raises NotImplementedError.\n"
1760
"\n"
1761
"The list is in arbitrary order.  It does not include the special\n"
1762
"entries \'.\' and \'..\' even if they are present in the directory.");
1763
1764
#define OS_LISTDIR_METHODDEF    \
1765
    {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
1766
1767
static PyObject *
1768
os_listdir_impl(PyObject *module, path_t *path);
1769
1770
static PyObject *
1771
os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1772
120
{
1773
120
    PyObject *return_value = NULL;
1774
120
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1775
1776
120
    #define NUM_KEYWORDS 1
1777
120
    static struct {
1778
120
        PyGC_Head _this_is_not_used;
1779
120
        PyObject_VAR_HEAD
1780
120
        Py_hash_t ob_hash;
1781
120
        PyObject *ob_item[NUM_KEYWORDS];
1782
120
    } _kwtuple = {
1783
120
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1784
120
        .ob_hash = -1,
1785
120
        .ob_item = { &_Py_ID(path), },
1786
120
    };
1787
120
    #undef NUM_KEYWORDS
1788
120
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1789
1790
    #else  // !Py_BUILD_CORE
1791
    #  define KWTUPLE NULL
1792
    #endif  // !Py_BUILD_CORE
1793
1794
120
    static const char * const _keywords[] = {"path", NULL};
1795
120
    static _PyArg_Parser _parser = {
1796
120
        .keywords = _keywords,
1797
120
        .fname = "listdir",
1798
120
        .kwtuple = KWTUPLE,
1799
120
    };
1800
120
    #undef KWTUPLE
1801
120
    PyObject *argsbuf[1];
1802
120
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1803
120
    path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
1804
1805
120
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1806
120
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1807
120
    if (!args) {
1808
0
        goto exit;
1809
0
    }
1810
120
    if (!noptargs) {
1811
0
        goto skip_optional_pos;
1812
0
    }
1813
120
    if (!path_converter(args[0], &path)) {
1814
0
        goto exit;
1815
0
    }
1816
120
skip_optional_pos:
1817
120
    return_value = os_listdir_impl(module, &path);
1818
1819
120
exit:
1820
    /* Cleanup for path */
1821
120
    path_cleanup(&path);
1822
1823
120
    return return_value;
1824
120
}
1825
1826
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
1827
1828
PyDoc_STRVAR(os_listdrives__doc__,
1829
"listdrives($module, /)\n"
1830
"--\n"
1831
"\n"
1832
"Return a list containing the names of drives in the system.\n"
1833
"\n"
1834
"A drive name typically looks like \'C:\\\\\'.");
1835
1836
#define OS_LISTDRIVES_METHODDEF    \
1837
    {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__},
1838
1839
static PyObject *
1840
os_listdrives_impl(PyObject *module);
1841
1842
static PyObject *
1843
os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored))
1844
{
1845
    return os_listdrives_impl(module);
1846
}
1847
1848
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
1849
1850
#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
1851
1852
PyDoc_STRVAR(os_listvolumes__doc__,
1853
"listvolumes($module, /)\n"
1854
"--\n"
1855
"\n"
1856
"Return a list containing the volumes in the system.\n"
1857
"\n"
1858
"Volumes are typically represented as a GUID path.");
1859
1860
#define OS_LISTVOLUMES_METHODDEF    \
1861
    {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__},
1862
1863
static PyObject *
1864
os_listvolumes_impl(PyObject *module);
1865
1866
static PyObject *
1867
os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored))
1868
{
1869
    return os_listvolumes_impl(module);
1870
}
1871
1872
#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
1873
1874
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
1875
1876
PyDoc_STRVAR(os_listmounts__doc__,
1877
"listmounts($module, /, volume)\n"
1878
"--\n"
1879
"\n"
1880
"Return a list containing mount points for a particular volume.\n"
1881
"\n"
1882
"\'volume\' should be a GUID path as returned from os.listvolumes.");
1883
1884
#define OS_LISTMOUNTS_METHODDEF    \
1885
    {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__},
1886
1887
static PyObject *
1888
os_listmounts_impl(PyObject *module, path_t *volume);
1889
1890
static PyObject *
1891
os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1892
{
1893
    PyObject *return_value = NULL;
1894
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1895
1896
    #define NUM_KEYWORDS 1
1897
    static struct {
1898
        PyGC_Head _this_is_not_used;
1899
        PyObject_VAR_HEAD
1900
        Py_hash_t ob_hash;
1901
        PyObject *ob_item[NUM_KEYWORDS];
1902
    } _kwtuple = {
1903
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1904
        .ob_hash = -1,
1905
        .ob_item = { &_Py_ID(volume), },
1906
    };
1907
    #undef NUM_KEYWORDS
1908
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1909
1910
    #else  // !Py_BUILD_CORE
1911
    #  define KWTUPLE NULL
1912
    #endif  // !Py_BUILD_CORE
1913
1914
    static const char * const _keywords[] = {"volume", NULL};
1915
    static _PyArg_Parser _parser = {
1916
        .keywords = _keywords,
1917
        .fname = "listmounts",
1918
        .kwtuple = KWTUPLE,
1919
    };
1920
    #undef KWTUPLE
1921
    PyObject *argsbuf[1];
1922
    path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0);
1923
1924
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1925
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1926
    if (!args) {
1927
        goto exit;
1928
    }
1929
    if (!path_converter(args[0], &volume)) {
1930
        goto exit;
1931
    }
1932
    return_value = os_listmounts_impl(module, &volume);
1933
1934
exit:
1935
    /* Cleanup for volume */
1936
    path_cleanup(&volume);
1937
1938
    return return_value;
1939
}
1940
1941
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
1942
1943
#if defined(MS_WINDOWS)
1944
1945
PyDoc_STRVAR(os__path_isdevdrive__doc__,
1946
"_path_isdevdrive($module, /, path)\n"
1947
"--\n"
1948
"\n"
1949
"Determines whether the specified path is on a Windows Dev Drive.");
1950
1951
#define OS__PATH_ISDEVDRIVE_METHODDEF    \
1952
    {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__},
1953
1954
static PyObject *
1955
os__path_isdevdrive_impl(PyObject *module, path_t *path);
1956
1957
static PyObject *
1958
os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1959
{
1960
    PyObject *return_value = NULL;
1961
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1962
1963
    #define NUM_KEYWORDS 1
1964
    static struct {
1965
        PyGC_Head _this_is_not_used;
1966
        PyObject_VAR_HEAD
1967
        Py_hash_t ob_hash;
1968
        PyObject *ob_item[NUM_KEYWORDS];
1969
    } _kwtuple = {
1970
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1971
        .ob_hash = -1,
1972
        .ob_item = { &_Py_ID(path), },
1973
    };
1974
    #undef NUM_KEYWORDS
1975
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1976
1977
    #else  // !Py_BUILD_CORE
1978
    #  define KWTUPLE NULL
1979
    #endif  // !Py_BUILD_CORE
1980
1981
    static const char * const _keywords[] = {"path", NULL};
1982
    static _PyArg_Parser _parser = {
1983
        .keywords = _keywords,
1984
        .fname = "_path_isdevdrive",
1985
        .kwtuple = KWTUPLE,
1986
    };
1987
    #undef KWTUPLE
1988
    PyObject *argsbuf[1];
1989
    path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0);
1990
1991
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1992
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1993
    if (!args) {
1994
        goto exit;
1995
    }
1996
    if (!path_converter(args[0], &path)) {
1997
        goto exit;
1998
    }
1999
    return_value = os__path_isdevdrive_impl(module, &path);
2000
2001
exit:
2002
    /* Cleanup for path */
2003
    path_cleanup(&path);
2004
2005
    return return_value;
2006
}
2007
2008
#endif /* defined(MS_WINDOWS) */
2009
2010
#if defined(MS_WINDOWS)
2011
2012
PyDoc_STRVAR(os__getfullpathname__doc__,
2013
"_getfullpathname($module, path, /)\n"
2014
"--\n"
2015
"\n");
2016
2017
#define OS__GETFULLPATHNAME_METHODDEF    \
2018
    {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
2019
2020
static PyObject *
2021
os__getfullpathname_impl(PyObject *module, path_t *path);
2022
2023
static PyObject *
2024
os__getfullpathname(PyObject *module, PyObject *arg)
2025
{
2026
    PyObject *return_value = NULL;
2027
    path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0);
2028
2029
    if (!path_converter(arg, &path)) {
2030
        goto exit;
2031
    }
2032
    return_value = os__getfullpathname_impl(module, &path);
2033
2034
exit:
2035
    /* Cleanup for path */
2036
    path_cleanup(&path);
2037
2038
    return return_value;
2039
}
2040
2041
#endif /* defined(MS_WINDOWS) */
2042
2043
#if defined(MS_WINDOWS)
2044
2045
PyDoc_STRVAR(os__getfinalpathname__doc__,
2046
"_getfinalpathname($module, path, /)\n"
2047
"--\n"
2048
"\n"
2049
"A helper function for samepath on windows.");
2050
2051
#define OS__GETFINALPATHNAME_METHODDEF    \
2052
    {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
2053
2054
static PyObject *
2055
os__getfinalpathname_impl(PyObject *module, path_t *path);
2056
2057
static PyObject *
2058
os__getfinalpathname(PyObject *module, PyObject *arg)
2059
{
2060
    PyObject *return_value = NULL;
2061
    path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0);
2062
2063
    if (!path_converter(arg, &path)) {
2064
        goto exit;
2065
    }
2066
    return_value = os__getfinalpathname_impl(module, &path);
2067
2068
exit:
2069
    /* Cleanup for path */
2070
    path_cleanup(&path);
2071
2072
    return return_value;
2073
}
2074
2075
#endif /* defined(MS_WINDOWS) */
2076
2077
#if defined(MS_WINDOWS)
2078
2079
PyDoc_STRVAR(os__findfirstfile__doc__,
2080
"_findfirstfile($module, path, /)\n"
2081
"--\n"
2082
"\n"
2083
"A function to get the real file name without accessing the file in Windows.");
2084
2085
#define OS__FINDFIRSTFILE_METHODDEF    \
2086
    {"_findfirstfile", (PyCFunction)os__findfirstfile, METH_O, os__findfirstfile__doc__},
2087
2088
static PyObject *
2089
os__findfirstfile_impl(PyObject *module, path_t *path);
2090
2091
static PyObject *
2092
os__findfirstfile(PyObject *module, PyObject *arg)
2093
{
2094
    PyObject *return_value = NULL;
2095
    path_t path = PATH_T_INITIALIZE_P("_findfirstfile", "path", 0, 0, 0, 0);
2096
2097
    if (!path_converter(arg, &path)) {
2098
        goto exit;
2099
    }
2100
    return_value = os__findfirstfile_impl(module, &path);
2101
2102
exit:
2103
    /* Cleanup for path */
2104
    path_cleanup(&path);
2105
2106
    return return_value;
2107
}
2108
2109
#endif /* defined(MS_WINDOWS) */
2110
2111
#if defined(MS_WINDOWS)
2112
2113
PyDoc_STRVAR(os__getvolumepathname__doc__,
2114
"_getvolumepathname($module, /, path)\n"
2115
"--\n"
2116
"\n"
2117
"A helper function for ismount on Win32.");
2118
2119
#define OS__GETVOLUMEPATHNAME_METHODDEF    \
2120
    {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
2121
2122
static PyObject *
2123
os__getvolumepathname_impl(PyObject *module, path_t *path);
2124
2125
static PyObject *
2126
os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2127
{
2128
    PyObject *return_value = NULL;
2129
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2130
2131
    #define NUM_KEYWORDS 1
2132
    static struct {
2133
        PyGC_Head _this_is_not_used;
2134
        PyObject_VAR_HEAD
2135
        Py_hash_t ob_hash;
2136
        PyObject *ob_item[NUM_KEYWORDS];
2137
    } _kwtuple = {
2138
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2139
        .ob_hash = -1,
2140
        .ob_item = { &_Py_ID(path), },
2141
    };
2142
    #undef NUM_KEYWORDS
2143
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2144
2145
    #else  // !Py_BUILD_CORE
2146
    #  define KWTUPLE NULL
2147
    #endif  // !Py_BUILD_CORE
2148
2149
    static const char * const _keywords[] = {"path", NULL};
2150
    static _PyArg_Parser _parser = {
2151
        .keywords = _keywords,
2152
        .fname = "_getvolumepathname",
2153
        .kwtuple = KWTUPLE,
2154
    };
2155
    #undef KWTUPLE
2156
    PyObject *argsbuf[1];
2157
    path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0);
2158
2159
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2160
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2161
    if (!args) {
2162
        goto exit;
2163
    }
2164
    if (!path_converter(args[0], &path)) {
2165
        goto exit;
2166
    }
2167
    return_value = os__getvolumepathname_impl(module, &path);
2168
2169
exit:
2170
    /* Cleanup for path */
2171
    path_cleanup(&path);
2172
2173
    return return_value;
2174
}
2175
2176
#endif /* defined(MS_WINDOWS) */
2177
2178
#if defined(MS_WINDOWS)
2179
2180
PyDoc_STRVAR(os__path_splitroot__doc__,
2181
"_path_splitroot($module, path, /)\n"
2182
"--\n"
2183
"\n"
2184
"Removes everything after the root on Win32.");
2185
2186
#define OS__PATH_SPLITROOT_METHODDEF    \
2187
    {"_path_splitroot", (PyCFunction)os__path_splitroot, METH_O, os__path_splitroot__doc__},
2188
2189
static PyObject *
2190
os__path_splitroot_impl(PyObject *module, path_t *path);
2191
2192
static PyObject *
2193
os__path_splitroot(PyObject *module, PyObject *arg)
2194
{
2195
    PyObject *return_value = NULL;
2196
    path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0);
2197
2198
    if (!path_converter(arg, &path)) {
2199
        goto exit;
2200
    }
2201
    return_value = os__path_splitroot_impl(module, &path);
2202
2203
exit:
2204
    /* Cleanup for path */
2205
    path_cleanup(&path);
2206
2207
    return return_value;
2208
}
2209
2210
#endif /* defined(MS_WINDOWS) */
2211
2212
#if defined(MS_WINDOWS)
2213
2214
PyDoc_STRVAR(os__path_exists__doc__,
2215
"_path_exists($module, /, path)\n"
2216
"--\n"
2217
"\n"
2218
"Test whether a path exists.  Returns False for broken symbolic links.");
2219
2220
#define OS__PATH_EXISTS_METHODDEF    \
2221
    {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__},
2222
2223
static int
2224
os__path_exists_impl(PyObject *module, path_t *path);
2225
2226
static PyObject *
2227
os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2228
{
2229
    PyObject *return_value = NULL;
2230
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2231
2232
    #define NUM_KEYWORDS 1
2233
    static struct {
2234
        PyGC_Head _this_is_not_used;
2235
        PyObject_VAR_HEAD
2236
        Py_hash_t ob_hash;
2237
        PyObject *ob_item[NUM_KEYWORDS];
2238
    } _kwtuple = {
2239
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2240
        .ob_hash = -1,
2241
        .ob_item = { &_Py_ID(path), },
2242
    };
2243
    #undef NUM_KEYWORDS
2244
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2245
2246
    #else  // !Py_BUILD_CORE
2247
    #  define KWTUPLE NULL
2248
    #endif  // !Py_BUILD_CORE
2249
2250
    static const char * const _keywords[] = {"path", NULL};
2251
    static _PyArg_Parser _parser = {
2252
        .keywords = _keywords,
2253
        .fname = "_path_exists",
2254
        .kwtuple = KWTUPLE,
2255
    };
2256
    #undef KWTUPLE
2257
    PyObject *argsbuf[1];
2258
    path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1);
2259
    int _return_value;
2260
2261
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2262
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2263
    if (!args) {
2264
        goto exit;
2265
    }
2266
    if (!path_converter(args[0], &path)) {
2267
        goto exit;
2268
    }
2269
    _return_value = os__path_exists_impl(module, &path);
2270
    if ((_return_value == -1) && PyErr_Occurred()) {
2271
        goto exit;
2272
    }
2273
    return_value = PyBool_FromLong((long)_return_value);
2274
2275
exit:
2276
    /* Cleanup for path */
2277
    path_cleanup(&path);
2278
2279
    return return_value;
2280
}
2281
2282
#endif /* defined(MS_WINDOWS) */
2283
2284
#if defined(MS_WINDOWS)
2285
2286
PyDoc_STRVAR(os__path_lexists__doc__,
2287
"_path_lexists($module, /, path)\n"
2288
"--\n"
2289
"\n"
2290
"Test whether a path exists.  Returns True for broken symbolic links.");
2291
2292
#define OS__PATH_LEXISTS_METHODDEF    \
2293
    {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__},
2294
2295
static int
2296
os__path_lexists_impl(PyObject *module, path_t *path);
2297
2298
static PyObject *
2299
os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2300
{
2301
    PyObject *return_value = NULL;
2302
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2303
2304
    #define NUM_KEYWORDS 1
2305
    static struct {
2306
        PyGC_Head _this_is_not_used;
2307
        PyObject_VAR_HEAD
2308
        Py_hash_t ob_hash;
2309
        PyObject *ob_item[NUM_KEYWORDS];
2310
    } _kwtuple = {
2311
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2312
        .ob_hash = -1,
2313
        .ob_item = { &_Py_ID(path), },
2314
    };
2315
    #undef NUM_KEYWORDS
2316
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2317
2318
    #else  // !Py_BUILD_CORE
2319
    #  define KWTUPLE NULL
2320
    #endif  // !Py_BUILD_CORE
2321
2322
    static const char * const _keywords[] = {"path", NULL};
2323
    static _PyArg_Parser _parser = {
2324
        .keywords = _keywords,
2325
        .fname = "_path_lexists",
2326
        .kwtuple = KWTUPLE,
2327
    };
2328
    #undef KWTUPLE
2329
    PyObject *argsbuf[1];
2330
    path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1);
2331
    int _return_value;
2332
2333
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2334
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2335
    if (!args) {
2336
        goto exit;
2337
    }
2338
    if (!path_converter(args[0], &path)) {
2339
        goto exit;
2340
    }
2341
    _return_value = os__path_lexists_impl(module, &path);
2342
    if ((_return_value == -1) && PyErr_Occurred()) {
2343
        goto exit;
2344
    }
2345
    return_value = PyBool_FromLong((long)_return_value);
2346
2347
exit:
2348
    /* Cleanup for path */
2349
    path_cleanup(&path);
2350
2351
    return return_value;
2352
}
2353
2354
#endif /* defined(MS_WINDOWS) */
2355
2356
#if defined(MS_WINDOWS)
2357
2358
PyDoc_STRVAR(os__path_isdir__doc__,
2359
"_path_isdir($module, path, /)\n"
2360
"--\n"
2361
"\n"
2362
"Return true if the pathname refers to an existing directory.");
2363
2364
#define OS__PATH_ISDIR_METHODDEF    \
2365
    {"_path_isdir", (PyCFunction)os__path_isdir, METH_O, os__path_isdir__doc__},
2366
2367
static int
2368
os__path_isdir_impl(PyObject *module, path_t *path);
2369
2370
static PyObject *
2371
os__path_isdir(PyObject *module, PyObject *arg)
2372
{
2373
    PyObject *return_value = NULL;
2374
    path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1);
2375
    int _return_value;
2376
2377
    if (!path_converter(arg, &path)) {
2378
        goto exit;
2379
    }
2380
    _return_value = os__path_isdir_impl(module, &path);
2381
    if ((_return_value == -1) && PyErr_Occurred()) {
2382
        goto exit;
2383
    }
2384
    return_value = PyBool_FromLong((long)_return_value);
2385
2386
exit:
2387
    /* Cleanup for path */
2388
    path_cleanup(&path);
2389
2390
    return return_value;
2391
}
2392
2393
#endif /* defined(MS_WINDOWS) */
2394
2395
#if defined(MS_WINDOWS)
2396
2397
PyDoc_STRVAR(os__path_isfile__doc__,
2398
"_path_isfile($module, /, path)\n"
2399
"--\n"
2400
"\n"
2401
"Test whether a path is a regular file");
2402
2403
#define OS__PATH_ISFILE_METHODDEF    \
2404
    {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
2405
2406
static int
2407
os__path_isfile_impl(PyObject *module, path_t *path);
2408
2409
static PyObject *
2410
os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2411
{
2412
    PyObject *return_value = NULL;
2413
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2414
2415
    #define NUM_KEYWORDS 1
2416
    static struct {
2417
        PyGC_Head _this_is_not_used;
2418
        PyObject_VAR_HEAD
2419
        Py_hash_t ob_hash;
2420
        PyObject *ob_item[NUM_KEYWORDS];
2421
    } _kwtuple = {
2422
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2423
        .ob_hash = -1,
2424
        .ob_item = { &_Py_ID(path), },
2425
    };
2426
    #undef NUM_KEYWORDS
2427
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2428
2429
    #else  // !Py_BUILD_CORE
2430
    #  define KWTUPLE NULL
2431
    #endif  // !Py_BUILD_CORE
2432
2433
    static const char * const _keywords[] = {"path", NULL};
2434
    static _PyArg_Parser _parser = {
2435
        .keywords = _keywords,
2436
        .fname = "_path_isfile",
2437
        .kwtuple = KWTUPLE,
2438
    };
2439
    #undef KWTUPLE
2440
    PyObject *argsbuf[1];
2441
    path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1);
2442
    int _return_value;
2443
2444
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2445
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2446
    if (!args) {
2447
        goto exit;
2448
    }
2449
    if (!path_converter(args[0], &path)) {
2450
        goto exit;
2451
    }
2452
    _return_value = os__path_isfile_impl(module, &path);
2453
    if ((_return_value == -1) && PyErr_Occurred()) {
2454
        goto exit;
2455
    }
2456
    return_value = PyBool_FromLong((long)_return_value);
2457
2458
exit:
2459
    /* Cleanup for path */
2460
    path_cleanup(&path);
2461
2462
    return return_value;
2463
}
2464
2465
#endif /* defined(MS_WINDOWS) */
2466
2467
#if defined(MS_WINDOWS)
2468
2469
PyDoc_STRVAR(os__path_islink__doc__,
2470
"_path_islink($module, /, path)\n"
2471
"--\n"
2472
"\n"
2473
"Test whether a path is a symbolic link");
2474
2475
#define OS__PATH_ISLINK_METHODDEF    \
2476
    {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
2477
2478
static int
2479
os__path_islink_impl(PyObject *module, path_t *path);
2480
2481
static PyObject *
2482
os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2483
{
2484
    PyObject *return_value = NULL;
2485
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2486
2487
    #define NUM_KEYWORDS 1
2488
    static struct {
2489
        PyGC_Head _this_is_not_used;
2490
        PyObject_VAR_HEAD
2491
        Py_hash_t ob_hash;
2492
        PyObject *ob_item[NUM_KEYWORDS];
2493
    } _kwtuple = {
2494
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2495
        .ob_hash = -1,
2496
        .ob_item = { &_Py_ID(path), },
2497
    };
2498
    #undef NUM_KEYWORDS
2499
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2500
2501
    #else  // !Py_BUILD_CORE
2502
    #  define KWTUPLE NULL
2503
    #endif  // !Py_BUILD_CORE
2504
2505
    static const char * const _keywords[] = {"path", NULL};
2506
    static _PyArg_Parser _parser = {
2507
        .keywords = _keywords,
2508
        .fname = "_path_islink",
2509
        .kwtuple = KWTUPLE,
2510
    };
2511
    #undef KWTUPLE
2512
    PyObject *argsbuf[1];
2513
    path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1);
2514
    int _return_value;
2515
2516
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2517
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2518
    if (!args) {
2519
        goto exit;
2520
    }
2521
    if (!path_converter(args[0], &path)) {
2522
        goto exit;
2523
    }
2524
    _return_value = os__path_islink_impl(module, &path);
2525
    if ((_return_value == -1) && PyErr_Occurred()) {
2526
        goto exit;
2527
    }
2528
    return_value = PyBool_FromLong((long)_return_value);
2529
2530
exit:
2531
    /* Cleanup for path */
2532
    path_cleanup(&path);
2533
2534
    return return_value;
2535
}
2536
2537
#endif /* defined(MS_WINDOWS) */
2538
2539
#if defined(MS_WINDOWS)
2540
2541
PyDoc_STRVAR(os__path_isjunction__doc__,
2542
"_path_isjunction($module, /, path)\n"
2543
"--\n"
2544
"\n"
2545
"Test whether a path is a junction");
2546
2547
#define OS__PATH_ISJUNCTION_METHODDEF    \
2548
    {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__},
2549
2550
static int
2551
os__path_isjunction_impl(PyObject *module, path_t *path);
2552
2553
static PyObject *
2554
os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2555
{
2556
    PyObject *return_value = NULL;
2557
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2558
2559
    #define NUM_KEYWORDS 1
2560
    static struct {
2561
        PyGC_Head _this_is_not_used;
2562
        PyObject_VAR_HEAD
2563
        Py_hash_t ob_hash;
2564
        PyObject *ob_item[NUM_KEYWORDS];
2565
    } _kwtuple = {
2566
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2567
        .ob_hash = -1,
2568
        .ob_item = { &_Py_ID(path), },
2569
    };
2570
    #undef NUM_KEYWORDS
2571
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2572
2573
    #else  // !Py_BUILD_CORE
2574
    #  define KWTUPLE NULL
2575
    #endif  // !Py_BUILD_CORE
2576
2577
    static const char * const _keywords[] = {"path", NULL};
2578
    static _PyArg_Parser _parser = {
2579
        .keywords = _keywords,
2580
        .fname = "_path_isjunction",
2581
        .kwtuple = KWTUPLE,
2582
    };
2583
    #undef KWTUPLE
2584
    PyObject *argsbuf[1];
2585
    path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1);
2586
    int _return_value;
2587
2588
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2589
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2590
    if (!args) {
2591
        goto exit;
2592
    }
2593
    if (!path_converter(args[0], &path)) {
2594
        goto exit;
2595
    }
2596
    _return_value = os__path_isjunction_impl(module, &path);
2597
    if ((_return_value == -1) && PyErr_Occurred()) {
2598
        goto exit;
2599
    }
2600
    return_value = PyBool_FromLong((long)_return_value);
2601
2602
exit:
2603
    /* Cleanup for path */
2604
    path_cleanup(&path);
2605
2606
    return return_value;
2607
}
2608
2609
#endif /* defined(MS_WINDOWS) */
2610
2611
PyDoc_STRVAR(os__path_splitroot_ex__doc__,
2612
"_path_splitroot_ex($module, path, /)\n"
2613
"--\n"
2614
"\n"
2615
"Split a pathname into drive, root and tail.\n"
2616
"\n"
2617
"The tail contains anything after the root.");
2618
2619
#define OS__PATH_SPLITROOT_EX_METHODDEF    \
2620
    {"_path_splitroot_ex", (PyCFunction)os__path_splitroot_ex, METH_O, os__path_splitroot_ex__doc__},
2621
2622
static PyObject *
2623
os__path_splitroot_ex_impl(PyObject *module, path_t *path);
2624
2625
static PyObject *
2626
os__path_splitroot_ex(PyObject *module, PyObject *arg)
2627
0
{
2628
0
    PyObject *return_value = NULL;
2629
0
    path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0);
2630
2631
0
    if (!path_converter(arg, &path)) {
2632
0
        goto exit;
2633
0
    }
2634
0
    return_value = os__path_splitroot_ex_impl(module, &path);
2635
2636
0
exit:
2637
    /* Cleanup for path */
2638
0
    path_cleanup(&path);
2639
2640
0
    return return_value;
2641
0
}
2642
2643
PyDoc_STRVAR(os__path_normpath__doc__,
2644
"_path_normpath($module, /, path)\n"
2645
"--\n"
2646
"\n"
2647
"Normalize path, eliminating double slashes, etc.");
2648
2649
#define OS__PATH_NORMPATH_METHODDEF    \
2650
    {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
2651
2652
static PyObject *
2653
os__path_normpath_impl(PyObject *module, path_t *path);
2654
2655
static PyObject *
2656
os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2657
110
{
2658
110
    PyObject *return_value = NULL;
2659
110
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2660
2661
110
    #define NUM_KEYWORDS 1
2662
110
    static struct {
2663
110
        PyGC_Head _this_is_not_used;
2664
110
        PyObject_VAR_HEAD
2665
110
        Py_hash_t ob_hash;
2666
110
        PyObject *ob_item[NUM_KEYWORDS];
2667
110
    } _kwtuple = {
2668
110
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2669
110
        .ob_hash = -1,
2670
110
        .ob_item = { &_Py_ID(path), },
2671
110
    };
2672
110
    #undef NUM_KEYWORDS
2673
110
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2674
2675
    #else  // !Py_BUILD_CORE
2676
    #  define KWTUPLE NULL
2677
    #endif  // !Py_BUILD_CORE
2678
2679
110
    static const char * const _keywords[] = {"path", NULL};
2680
110
    static _PyArg_Parser _parser = {
2681
110
        .keywords = _keywords,
2682
110
        .fname = "_path_normpath",
2683
110
        .kwtuple = KWTUPLE,
2684
110
    };
2685
110
    #undef KWTUPLE
2686
110
    PyObject *argsbuf[1];
2687
110
    path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0);
2688
2689
110
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2690
110
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2691
110
    if (!args) {
2692
0
        goto exit;
2693
0
    }
2694
110
    if (!path_converter(args[0], &path)) {
2695
0
        goto exit;
2696
0
    }
2697
110
    return_value = os__path_normpath_impl(module, &path);
2698
2699
110
exit:
2700
    /* Cleanup for path */
2701
110
    path_cleanup(&path);
2702
2703
110
    return return_value;
2704
110
}
2705
2706
PyDoc_STRVAR(os_mkdir__doc__,
2707
"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
2708
"--\n"
2709
"\n"
2710
"Create a directory.\n"
2711
"\n"
2712
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2713
"  and path should be relative; path will then be relative to that directory.\n"
2714
"dir_fd may not be implemented on your platform.\n"
2715
"  If it is unavailable, using it will raise a NotImplementedError.\n"
2716
"\n"
2717
"The mode argument is ignored on Windows. Where it is used, the current umask\n"
2718
"value is first masked out.");
2719
2720
#define OS_MKDIR_METHODDEF    \
2721
    {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
2722
2723
static PyObject *
2724
os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
2725
2726
static PyObject *
2727
os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2728
0
{
2729
0
    PyObject *return_value = NULL;
2730
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2731
2732
0
    #define NUM_KEYWORDS 3
2733
0
    static struct {
2734
0
        PyGC_Head _this_is_not_used;
2735
0
        PyObject_VAR_HEAD
2736
0
        Py_hash_t ob_hash;
2737
0
        PyObject *ob_item[NUM_KEYWORDS];
2738
0
    } _kwtuple = {
2739
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2740
0
        .ob_hash = -1,
2741
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
2742
0
    };
2743
0
    #undef NUM_KEYWORDS
2744
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2745
2746
    #else  // !Py_BUILD_CORE
2747
    #  define KWTUPLE NULL
2748
    #endif  // !Py_BUILD_CORE
2749
2750
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
2751
0
    static _PyArg_Parser _parser = {
2752
0
        .keywords = _keywords,
2753
0
        .fname = "mkdir",
2754
0
        .kwtuple = KWTUPLE,
2755
0
    };
2756
0
    #undef KWTUPLE
2757
0
    PyObject *argsbuf[3];
2758
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
2759
0
    path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0);
2760
0
    int mode = 511;
2761
0
    int dir_fd = DEFAULT_DIR_FD;
2762
2763
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2764
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2765
0
    if (!args) {
2766
0
        goto exit;
2767
0
    }
2768
0
    if (!path_converter(args[0], &path)) {
2769
0
        goto exit;
2770
0
    }
2771
0
    if (!noptargs) {
2772
0
        goto skip_optional_pos;
2773
0
    }
2774
0
    if (args[1]) {
2775
0
        mode = PyLong_AsInt(args[1]);
2776
0
        if (mode == -1 && PyErr_Occurred()) {
2777
0
            goto exit;
2778
0
        }
2779
0
        if (!--noptargs) {
2780
0
            goto skip_optional_pos;
2781
0
        }
2782
0
    }
2783
0
skip_optional_pos:
2784
0
    if (!noptargs) {
2785
0
        goto skip_optional_kwonly;
2786
0
    }
2787
0
    if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
2788
0
        goto exit;
2789
0
    }
2790
0
skip_optional_kwonly:
2791
0
    return_value = os_mkdir_impl(module, &path, mode, dir_fd);
2792
2793
0
exit:
2794
    /* Cleanup for path */
2795
0
    path_cleanup(&path);
2796
2797
0
    return return_value;
2798
0
}
2799
2800
#if defined(HAVE_NICE)
2801
2802
PyDoc_STRVAR(os_nice__doc__,
2803
"nice($module, increment, /)\n"
2804
"--\n"
2805
"\n"
2806
"Add increment to the priority of process and return the new priority.");
2807
2808
#define OS_NICE_METHODDEF    \
2809
    {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
2810
2811
static PyObject *
2812
os_nice_impl(PyObject *module, int increment);
2813
2814
static PyObject *
2815
os_nice(PyObject *module, PyObject *arg)
2816
0
{
2817
0
    PyObject *return_value = NULL;
2818
0
    int increment;
2819
2820
0
    increment = PyLong_AsInt(arg);
2821
0
    if (increment == -1 && PyErr_Occurred()) {
2822
0
        goto exit;
2823
0
    }
2824
0
    return_value = os_nice_impl(module, increment);
2825
2826
0
exit:
2827
0
    return return_value;
2828
0
}
2829
2830
#endif /* defined(HAVE_NICE) */
2831
2832
#if defined(HAVE_GETPRIORITY)
2833
2834
PyDoc_STRVAR(os_getpriority__doc__,
2835
"getpriority($module, /, which, who)\n"
2836
"--\n"
2837
"\n"
2838
"Return program scheduling priority.");
2839
2840
#define OS_GETPRIORITY_METHODDEF    \
2841
    {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
2842
2843
static PyObject *
2844
os_getpriority_impl(PyObject *module, int which, int who);
2845
2846
static PyObject *
2847
os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2848
0
{
2849
0
    PyObject *return_value = NULL;
2850
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2851
2852
0
    #define NUM_KEYWORDS 2
2853
0
    static struct {
2854
0
        PyGC_Head _this_is_not_used;
2855
0
        PyObject_VAR_HEAD
2856
0
        Py_hash_t ob_hash;
2857
0
        PyObject *ob_item[NUM_KEYWORDS];
2858
0
    } _kwtuple = {
2859
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2860
0
        .ob_hash = -1,
2861
0
        .ob_item = { &_Py_ID(which), &_Py_ID(who), },
2862
0
    };
2863
0
    #undef NUM_KEYWORDS
2864
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2865
2866
    #else  // !Py_BUILD_CORE
2867
    #  define KWTUPLE NULL
2868
    #endif  // !Py_BUILD_CORE
2869
2870
0
    static const char * const _keywords[] = {"which", "who", NULL};
2871
0
    static _PyArg_Parser _parser = {
2872
0
        .keywords = _keywords,
2873
0
        .fname = "getpriority",
2874
0
        .kwtuple = KWTUPLE,
2875
0
    };
2876
0
    #undef KWTUPLE
2877
0
    PyObject *argsbuf[2];
2878
0
    int which;
2879
0
    int who;
2880
2881
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2882
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2883
0
    if (!args) {
2884
0
        goto exit;
2885
0
    }
2886
0
    which = PyLong_AsInt(args[0]);
2887
0
    if (which == -1 && PyErr_Occurred()) {
2888
0
        goto exit;
2889
0
    }
2890
0
    who = PyLong_AsInt(args[1]);
2891
0
    if (who == -1 && PyErr_Occurred()) {
2892
0
        goto exit;
2893
0
    }
2894
0
    return_value = os_getpriority_impl(module, which, who);
2895
2896
0
exit:
2897
0
    return return_value;
2898
0
}
2899
2900
#endif /* defined(HAVE_GETPRIORITY) */
2901
2902
#if defined(HAVE_SETPRIORITY)
2903
2904
PyDoc_STRVAR(os_setpriority__doc__,
2905
"setpriority($module, /, which, who, priority)\n"
2906
"--\n"
2907
"\n"
2908
"Set program scheduling priority.");
2909
2910
#define OS_SETPRIORITY_METHODDEF    \
2911
    {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
2912
2913
static PyObject *
2914
os_setpriority_impl(PyObject *module, int which, int who, int priority);
2915
2916
static PyObject *
2917
os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2918
0
{
2919
0
    PyObject *return_value = NULL;
2920
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2921
2922
0
    #define NUM_KEYWORDS 3
2923
0
    static struct {
2924
0
        PyGC_Head _this_is_not_used;
2925
0
        PyObject_VAR_HEAD
2926
0
        Py_hash_t ob_hash;
2927
0
        PyObject *ob_item[NUM_KEYWORDS];
2928
0
    } _kwtuple = {
2929
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2930
0
        .ob_hash = -1,
2931
0
        .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), },
2932
0
    };
2933
0
    #undef NUM_KEYWORDS
2934
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2935
2936
    #else  // !Py_BUILD_CORE
2937
    #  define KWTUPLE NULL
2938
    #endif  // !Py_BUILD_CORE
2939
2940
0
    static const char * const _keywords[] = {"which", "who", "priority", NULL};
2941
0
    static _PyArg_Parser _parser = {
2942
0
        .keywords = _keywords,
2943
0
        .fname = "setpriority",
2944
0
        .kwtuple = KWTUPLE,
2945
0
    };
2946
0
    #undef KWTUPLE
2947
0
    PyObject *argsbuf[3];
2948
0
    int which;
2949
0
    int who;
2950
0
    int priority;
2951
2952
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2953
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2954
0
    if (!args) {
2955
0
        goto exit;
2956
0
    }
2957
0
    which = PyLong_AsInt(args[0]);
2958
0
    if (which == -1 && PyErr_Occurred()) {
2959
0
        goto exit;
2960
0
    }
2961
0
    who = PyLong_AsInt(args[1]);
2962
0
    if (who == -1 && PyErr_Occurred()) {
2963
0
        goto exit;
2964
0
    }
2965
0
    priority = PyLong_AsInt(args[2]);
2966
0
    if (priority == -1 && PyErr_Occurred()) {
2967
0
        goto exit;
2968
0
    }
2969
0
    return_value = os_setpriority_impl(module, which, who, priority);
2970
2971
0
exit:
2972
0
    return return_value;
2973
0
}
2974
2975
#endif /* defined(HAVE_SETPRIORITY) */
2976
2977
PyDoc_STRVAR(os_rename__doc__,
2978
"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
2979
"--\n"
2980
"\n"
2981
"Rename a file or directory.\n"
2982
"\n"
2983
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
2984
"  descriptor open to a directory, and the respective path string (src or dst)\n"
2985
"  should be relative; the path will then be relative to that directory.\n"
2986
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
2987
"  If they are unavailable, using them will raise a NotImplementedError.");
2988
2989
#define OS_RENAME_METHODDEF    \
2990
    {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
2991
2992
static PyObject *
2993
os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
2994
               int dst_dir_fd);
2995
2996
static PyObject *
2997
os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2998
0
{
2999
0
    PyObject *return_value = NULL;
3000
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3001
3002
0
    #define NUM_KEYWORDS 4
3003
0
    static struct {
3004
0
        PyGC_Head _this_is_not_used;
3005
0
        PyObject_VAR_HEAD
3006
0
        Py_hash_t ob_hash;
3007
0
        PyObject *ob_item[NUM_KEYWORDS];
3008
0
    } _kwtuple = {
3009
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3010
0
        .ob_hash = -1,
3011
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
3012
0
    };
3013
0
    #undef NUM_KEYWORDS
3014
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3015
3016
    #else  // !Py_BUILD_CORE
3017
    #  define KWTUPLE NULL
3018
    #endif  // !Py_BUILD_CORE
3019
3020
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
3021
0
    static _PyArg_Parser _parser = {
3022
0
        .keywords = _keywords,
3023
0
        .fname = "rename",
3024
0
        .kwtuple = KWTUPLE,
3025
0
    };
3026
0
    #undef KWTUPLE
3027
0
    PyObject *argsbuf[4];
3028
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
3029
0
    path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0);
3030
0
    path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0);
3031
0
    int src_dir_fd = DEFAULT_DIR_FD;
3032
0
    int dst_dir_fd = DEFAULT_DIR_FD;
3033
3034
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3035
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3036
0
    if (!args) {
3037
0
        goto exit;
3038
0
    }
3039
0
    if (!path_converter(args[0], &src)) {
3040
0
        goto exit;
3041
0
    }
3042
0
    if (!path_converter(args[1], &dst)) {
3043
0
        goto exit;
3044
0
    }
3045
0
    if (!noptargs) {
3046
0
        goto skip_optional_kwonly;
3047
0
    }
3048
0
    if (args[2]) {
3049
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
3050
0
            goto exit;
3051
0
        }
3052
0
        if (!--noptargs) {
3053
0
            goto skip_optional_kwonly;
3054
0
        }
3055
0
    }
3056
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
3057
0
        goto exit;
3058
0
    }
3059
0
skip_optional_kwonly:
3060
0
    return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
3061
3062
0
exit:
3063
    /* Cleanup for src */
3064
0
    path_cleanup(&src);
3065
    /* Cleanup for dst */
3066
0
    path_cleanup(&dst);
3067
3068
0
    return return_value;
3069
0
}
3070
3071
PyDoc_STRVAR(os_replace__doc__,
3072
"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
3073
"--\n"
3074
"\n"
3075
"Rename a file or directory, overwriting the destination.\n"
3076
"\n"
3077
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
3078
"  descriptor open to a directory, and the respective path string (src or dst)\n"
3079
"  should be relative; the path will then be relative to that directory.\n"
3080
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
3081
"  If they are unavailable, using them will raise a NotImplementedError.");
3082
3083
#define OS_REPLACE_METHODDEF    \
3084
    {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
3085
3086
static PyObject *
3087
os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
3088
                int dst_dir_fd);
3089
3090
static PyObject *
3091
os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3092
0
{
3093
0
    PyObject *return_value = NULL;
3094
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3095
3096
0
    #define NUM_KEYWORDS 4
3097
0
    static struct {
3098
0
        PyGC_Head _this_is_not_used;
3099
0
        PyObject_VAR_HEAD
3100
0
        Py_hash_t ob_hash;
3101
0
        PyObject *ob_item[NUM_KEYWORDS];
3102
0
    } _kwtuple = {
3103
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3104
0
        .ob_hash = -1,
3105
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
3106
0
    };
3107
0
    #undef NUM_KEYWORDS
3108
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3109
3110
    #else  // !Py_BUILD_CORE
3111
    #  define KWTUPLE NULL
3112
    #endif  // !Py_BUILD_CORE
3113
3114
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
3115
0
    static _PyArg_Parser _parser = {
3116
0
        .keywords = _keywords,
3117
0
        .fname = "replace",
3118
0
        .kwtuple = KWTUPLE,
3119
0
    };
3120
0
    #undef KWTUPLE
3121
0
    PyObject *argsbuf[4];
3122
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
3123
0
    path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0);
3124
0
    path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0);
3125
0
    int src_dir_fd = DEFAULT_DIR_FD;
3126
0
    int dst_dir_fd = DEFAULT_DIR_FD;
3127
3128
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3129
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3130
0
    if (!args) {
3131
0
        goto exit;
3132
0
    }
3133
0
    if (!path_converter(args[0], &src)) {
3134
0
        goto exit;
3135
0
    }
3136
0
    if (!path_converter(args[1], &dst)) {
3137
0
        goto exit;
3138
0
    }
3139
0
    if (!noptargs) {
3140
0
        goto skip_optional_kwonly;
3141
0
    }
3142
0
    if (args[2]) {
3143
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
3144
0
            goto exit;
3145
0
        }
3146
0
        if (!--noptargs) {
3147
0
            goto skip_optional_kwonly;
3148
0
        }
3149
0
    }
3150
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
3151
0
        goto exit;
3152
0
    }
3153
0
skip_optional_kwonly:
3154
0
    return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
3155
3156
0
exit:
3157
    /* Cleanup for src */
3158
0
    path_cleanup(&src);
3159
    /* Cleanup for dst */
3160
0
    path_cleanup(&dst);
3161
3162
0
    return return_value;
3163
0
}
3164
3165
PyDoc_STRVAR(os_rmdir__doc__,
3166
"rmdir($module, /, path, *, dir_fd=None)\n"
3167
"--\n"
3168
"\n"
3169
"Remove a directory.\n"
3170
"\n"
3171
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3172
"  and path should be relative; path will then be relative to that directory.\n"
3173
"dir_fd may not be implemented on your platform.\n"
3174
"  If it is unavailable, using it will raise a NotImplementedError.");
3175
3176
#define OS_RMDIR_METHODDEF    \
3177
    {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
3178
3179
static PyObject *
3180
os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
3181
3182
static PyObject *
3183
os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3184
0
{
3185
0
    PyObject *return_value = NULL;
3186
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3187
3188
0
    #define NUM_KEYWORDS 2
3189
0
    static struct {
3190
0
        PyGC_Head _this_is_not_used;
3191
0
        PyObject_VAR_HEAD
3192
0
        Py_hash_t ob_hash;
3193
0
        PyObject *ob_item[NUM_KEYWORDS];
3194
0
    } _kwtuple = {
3195
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3196
0
        .ob_hash = -1,
3197
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3198
0
    };
3199
0
    #undef NUM_KEYWORDS
3200
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3201
3202
    #else  // !Py_BUILD_CORE
3203
    #  define KWTUPLE NULL
3204
    #endif  // !Py_BUILD_CORE
3205
3206
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3207
0
    static _PyArg_Parser _parser = {
3208
0
        .keywords = _keywords,
3209
0
        .fname = "rmdir",
3210
0
        .kwtuple = KWTUPLE,
3211
0
    };
3212
0
    #undef KWTUPLE
3213
0
    PyObject *argsbuf[2];
3214
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3215
0
    path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0);
3216
0
    int dir_fd = DEFAULT_DIR_FD;
3217
3218
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3219
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3220
0
    if (!args) {
3221
0
        goto exit;
3222
0
    }
3223
0
    if (!path_converter(args[0], &path)) {
3224
0
        goto exit;
3225
0
    }
3226
0
    if (!noptargs) {
3227
0
        goto skip_optional_kwonly;
3228
0
    }
3229
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3230
0
        goto exit;
3231
0
    }
3232
0
skip_optional_kwonly:
3233
0
    return_value = os_rmdir_impl(module, &path, dir_fd);
3234
3235
0
exit:
3236
    /* Cleanup for path */
3237
0
    path_cleanup(&path);
3238
3239
0
    return return_value;
3240
0
}
3241
3242
#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
3243
3244
PyDoc_STRVAR(os_system__doc__,
3245
"system($module, /, command)\n"
3246
"--\n"
3247
"\n"
3248
"Execute the command in a subshell.");
3249
3250
#define OS_SYSTEM_METHODDEF    \
3251
    {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3252
3253
static long
3254
os_system_impl(PyObject *module, const wchar_t *command);
3255
3256
static PyObject *
3257
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3258
{
3259
    PyObject *return_value = NULL;
3260
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3261
3262
    #define NUM_KEYWORDS 1
3263
    static struct {
3264
        PyGC_Head _this_is_not_used;
3265
        PyObject_VAR_HEAD
3266
        Py_hash_t ob_hash;
3267
        PyObject *ob_item[NUM_KEYWORDS];
3268
    } _kwtuple = {
3269
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3270
        .ob_hash = -1,
3271
        .ob_item = { &_Py_ID(command), },
3272
    };
3273
    #undef NUM_KEYWORDS
3274
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3275
3276
    #else  // !Py_BUILD_CORE
3277
    #  define KWTUPLE NULL
3278
    #endif  // !Py_BUILD_CORE
3279
3280
    static const char * const _keywords[] = {"command", NULL};
3281
    static _PyArg_Parser _parser = {
3282
        .keywords = _keywords,
3283
        .fname = "system",
3284
        .kwtuple = KWTUPLE,
3285
    };
3286
    #undef KWTUPLE
3287
    PyObject *argsbuf[1];
3288
    const wchar_t *command = NULL;
3289
    long _return_value;
3290
3291
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3292
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3293
    if (!args) {
3294
        goto exit;
3295
    }
3296
    if (!PyUnicode_Check(args[0])) {
3297
        _PyArg_BadArgument("system", "argument 'command'", "str", args[0]);
3298
        goto exit;
3299
    }
3300
    command = PyUnicode_AsWideCharString(args[0], NULL);
3301
    if (command == NULL) {
3302
        goto exit;
3303
    }
3304
    _return_value = os_system_impl(module, command);
3305
    if ((_return_value == -1) && PyErr_Occurred()) {
3306
        goto exit;
3307
    }
3308
    return_value = PyLong_FromLong(_return_value);
3309
3310
exit:
3311
    /* Cleanup for command */
3312
    PyMem_Free((void *)command);
3313
3314
    return return_value;
3315
}
3316
3317
#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
3318
3319
#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
3320
3321
PyDoc_STRVAR(os_system__doc__,
3322
"system($module, /, command)\n"
3323
"--\n"
3324
"\n"
3325
"Execute the command in a subshell.");
3326
3327
#define OS_SYSTEM_METHODDEF    \
3328
    {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3329
3330
static long
3331
os_system_impl(PyObject *module, PyObject *command);
3332
3333
static PyObject *
3334
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3335
0
{
3336
0
    PyObject *return_value = NULL;
3337
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3338
3339
0
    #define NUM_KEYWORDS 1
3340
0
    static struct {
3341
0
        PyGC_Head _this_is_not_used;
3342
0
        PyObject_VAR_HEAD
3343
0
        Py_hash_t ob_hash;
3344
0
        PyObject *ob_item[NUM_KEYWORDS];
3345
0
    } _kwtuple = {
3346
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3347
0
        .ob_hash = -1,
3348
0
        .ob_item = { &_Py_ID(command), },
3349
0
    };
3350
0
    #undef NUM_KEYWORDS
3351
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3352
3353
    #else  // !Py_BUILD_CORE
3354
    #  define KWTUPLE NULL
3355
    #endif  // !Py_BUILD_CORE
3356
3357
0
    static const char * const _keywords[] = {"command", NULL};
3358
0
    static _PyArg_Parser _parser = {
3359
0
        .keywords = _keywords,
3360
0
        .fname = "system",
3361
0
        .kwtuple = KWTUPLE,
3362
0
    };
3363
0
    #undef KWTUPLE
3364
0
    PyObject *argsbuf[1];
3365
0
    PyObject *command = NULL;
3366
0
    long _return_value;
3367
3368
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3369
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3370
0
    if (!args) {
3371
0
        goto exit;
3372
0
    }
3373
0
    if (!PyUnicode_FSConverter(args[0], &command)) {
3374
0
        goto exit;
3375
0
    }
3376
0
    _return_value = os_system_impl(module, command);
3377
0
    if ((_return_value == -1) && PyErr_Occurred()) {
3378
0
        goto exit;
3379
0
    }
3380
0
    return_value = PyLong_FromLong(_return_value);
3381
3382
0
exit:
3383
    /* Cleanup for command */
3384
0
    Py_XDECREF(command);
3385
3386
0
    return return_value;
3387
0
}
3388
3389
#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
3390
3391
#if defined(HAVE_UMASK)
3392
3393
PyDoc_STRVAR(os_umask__doc__,
3394
"umask($module, mask, /)\n"
3395
"--\n"
3396
"\n"
3397
"Set the current numeric umask and return the previous umask.");
3398
3399
#define OS_UMASK_METHODDEF    \
3400
    {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
3401
3402
static PyObject *
3403
os_umask_impl(PyObject *module, int mask);
3404
3405
static PyObject *
3406
os_umask(PyObject *module, PyObject *arg)
3407
0
{
3408
0
    PyObject *return_value = NULL;
3409
0
    int mask;
3410
3411
0
    mask = PyLong_AsInt(arg);
3412
0
    if (mask == -1 && PyErr_Occurred()) {
3413
0
        goto exit;
3414
0
    }
3415
0
    return_value = os_umask_impl(module, mask);
3416
3417
0
exit:
3418
0
    return return_value;
3419
0
}
3420
3421
#endif /* defined(HAVE_UMASK) */
3422
3423
PyDoc_STRVAR(os_unlink__doc__,
3424
"unlink($module, /, path, *, dir_fd=None)\n"
3425
"--\n"
3426
"\n"
3427
"Remove a file (same as remove()).\n"
3428
"\n"
3429
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3430
"  and path should be relative; path will then be relative to that directory.\n"
3431
"dir_fd may not be implemented on your platform.\n"
3432
"  If it is unavailable, using it will raise a NotImplementedError.");
3433
3434
#define OS_UNLINK_METHODDEF    \
3435
    {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
3436
3437
static PyObject *
3438
os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
3439
3440
static PyObject *
3441
os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3442
0
{
3443
0
    PyObject *return_value = NULL;
3444
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3445
3446
0
    #define NUM_KEYWORDS 2
3447
0
    static struct {
3448
0
        PyGC_Head _this_is_not_used;
3449
0
        PyObject_VAR_HEAD
3450
0
        Py_hash_t ob_hash;
3451
0
        PyObject *ob_item[NUM_KEYWORDS];
3452
0
    } _kwtuple = {
3453
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3454
0
        .ob_hash = -1,
3455
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3456
0
    };
3457
0
    #undef NUM_KEYWORDS
3458
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3459
3460
    #else  // !Py_BUILD_CORE
3461
    #  define KWTUPLE NULL
3462
    #endif  // !Py_BUILD_CORE
3463
3464
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3465
0
    static _PyArg_Parser _parser = {
3466
0
        .keywords = _keywords,
3467
0
        .fname = "unlink",
3468
0
        .kwtuple = KWTUPLE,
3469
0
    };
3470
0
    #undef KWTUPLE
3471
0
    PyObject *argsbuf[2];
3472
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3473
0
    path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0);
3474
0
    int dir_fd = DEFAULT_DIR_FD;
3475
3476
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3477
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3478
0
    if (!args) {
3479
0
        goto exit;
3480
0
    }
3481
0
    if (!path_converter(args[0], &path)) {
3482
0
        goto exit;
3483
0
    }
3484
0
    if (!noptargs) {
3485
0
        goto skip_optional_kwonly;
3486
0
    }
3487
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3488
0
        goto exit;
3489
0
    }
3490
0
skip_optional_kwonly:
3491
0
    return_value = os_unlink_impl(module, &path, dir_fd);
3492
3493
0
exit:
3494
    /* Cleanup for path */
3495
0
    path_cleanup(&path);
3496
3497
0
    return return_value;
3498
0
}
3499
3500
PyDoc_STRVAR(os_remove__doc__,
3501
"remove($module, /, path, *, dir_fd=None)\n"
3502
"--\n"
3503
"\n"
3504
"Remove a file (same as unlink()).\n"
3505
"\n"
3506
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3507
"  and path should be relative; path will then be relative to that directory.\n"
3508
"dir_fd may not be implemented on your platform.\n"
3509
"  If it is unavailable, using it will raise a NotImplementedError.");
3510
3511
#define OS_REMOVE_METHODDEF    \
3512
    {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
3513
3514
static PyObject *
3515
os_remove_impl(PyObject *module, path_t *path, int dir_fd);
3516
3517
static PyObject *
3518
os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3519
0
{
3520
0
    PyObject *return_value = NULL;
3521
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3522
3523
0
    #define NUM_KEYWORDS 2
3524
0
    static struct {
3525
0
        PyGC_Head _this_is_not_used;
3526
0
        PyObject_VAR_HEAD
3527
0
        Py_hash_t ob_hash;
3528
0
        PyObject *ob_item[NUM_KEYWORDS];
3529
0
    } _kwtuple = {
3530
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3531
0
        .ob_hash = -1,
3532
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3533
0
    };
3534
0
    #undef NUM_KEYWORDS
3535
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3536
3537
    #else  // !Py_BUILD_CORE
3538
    #  define KWTUPLE NULL
3539
    #endif  // !Py_BUILD_CORE
3540
3541
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3542
0
    static _PyArg_Parser _parser = {
3543
0
        .keywords = _keywords,
3544
0
        .fname = "remove",
3545
0
        .kwtuple = KWTUPLE,
3546
0
    };
3547
0
    #undef KWTUPLE
3548
0
    PyObject *argsbuf[2];
3549
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3550
0
    path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0);
3551
0
    int dir_fd = DEFAULT_DIR_FD;
3552
3553
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3554
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3555
0
    if (!args) {
3556
0
        goto exit;
3557
0
    }
3558
0
    if (!path_converter(args[0], &path)) {
3559
0
        goto exit;
3560
0
    }
3561
0
    if (!noptargs) {
3562
0
        goto skip_optional_kwonly;
3563
0
    }
3564
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3565
0
        goto exit;
3566
0
    }
3567
0
skip_optional_kwonly:
3568
0
    return_value = os_remove_impl(module, &path, dir_fd);
3569
3570
0
exit:
3571
    /* Cleanup for path */
3572
0
    path_cleanup(&path);
3573
3574
0
    return return_value;
3575
0
}
3576
3577
#if defined(HAVE_UNAME)
3578
3579
PyDoc_STRVAR(os_uname__doc__,
3580
"uname($module, /)\n"
3581
"--\n"
3582
"\n"
3583
"Return an object identifying the current operating system.\n"
3584
"\n"
3585
"The object behaves like a named tuple with the following fields:\n"
3586
"  (sysname, nodename, release, version, machine)");
3587
3588
#define OS_UNAME_METHODDEF    \
3589
    {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
3590
3591
static PyObject *
3592
os_uname_impl(PyObject *module);
3593
3594
static PyObject *
3595
os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
3596
0
{
3597
0
    return os_uname_impl(module);
3598
0
}
3599
3600
#endif /* defined(HAVE_UNAME) */
3601
3602
PyDoc_STRVAR(os_utime__doc__,
3603
"utime($module, /, path, times=None, *, ns=<unrepresentable>,\n"
3604
"      dir_fd=None, follow_symlinks=True)\n"
3605
"--\n"
3606
"\n"
3607
"Set the access and modified time of path.\n"
3608
"\n"
3609
"path may always be specified as a string.\n"
3610
"On some platforms, path may also be specified as an open file descriptor.\n"
3611
"  If this functionality is unavailable, using it raises an exception.\n"
3612
"\n"
3613
"If times is not None, it must be a tuple (atime, mtime);\n"
3614
"    atime and mtime should be expressed as float seconds since the epoch.\n"
3615
"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
3616
"    atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
3617
"    since the epoch.\n"
3618
"If times is None and ns is unspecified, utime uses the current time.\n"
3619
"Specifying tuples for both times and ns is an error.\n"
3620
"\n"
3621
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3622
"  and path should be relative; path will then be relative to that directory.\n"
3623
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
3624
"  link, utime will modify the symbolic link itself instead of the file the\n"
3625
"  link points to.\n"
3626
"It is an error to use dir_fd or follow_symlinks when specifying path\n"
3627
"  as an open file descriptor.\n"
3628
"dir_fd and follow_symlinks may not be available on your platform.\n"
3629
"  If they are unavailable, using them will raise a NotImplementedError.");
3630
3631
#define OS_UTIME_METHODDEF    \
3632
    {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
3633
3634
static PyObject *
3635
os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
3636
              int dir_fd, int follow_symlinks);
3637
3638
static PyObject *
3639
os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3640
0
{
3641
0
    PyObject *return_value = NULL;
3642
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3643
3644
0
    #define NUM_KEYWORDS 5
3645
0
    static struct {
3646
0
        PyGC_Head _this_is_not_used;
3647
0
        PyObject_VAR_HEAD
3648
0
        Py_hash_t ob_hash;
3649
0
        PyObject *ob_item[NUM_KEYWORDS];
3650
0
    } _kwtuple = {
3651
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3652
0
        .ob_hash = -1,
3653
0
        .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
3654
0
    };
3655
0
    #undef NUM_KEYWORDS
3656
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3657
3658
    #else  // !Py_BUILD_CORE
3659
    #  define KWTUPLE NULL
3660
    #endif  // !Py_BUILD_CORE
3661
3662
0
    static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
3663
0
    static _PyArg_Parser _parser = {
3664
0
        .keywords = _keywords,
3665
0
        .fname = "utime",
3666
0
        .kwtuple = KWTUPLE,
3667
0
    };
3668
0
    #undef KWTUPLE
3669
0
    PyObject *argsbuf[5];
3670
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3671
0
    path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD);
3672
0
    PyObject *times = Py_None;
3673
0
    PyObject *ns = NULL;
3674
0
    int dir_fd = DEFAULT_DIR_FD;
3675
0
    int follow_symlinks = 1;
3676
3677
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3678
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3679
0
    if (!args) {
3680
0
        goto exit;
3681
0
    }
3682
0
    if (!path_converter(args[0], &path)) {
3683
0
        goto exit;
3684
0
    }
3685
0
    if (!noptargs) {
3686
0
        goto skip_optional_pos;
3687
0
    }
3688
0
    if (args[1]) {
3689
0
        times = args[1];
3690
0
        if (!--noptargs) {
3691
0
            goto skip_optional_pos;
3692
0
        }
3693
0
    }
3694
0
skip_optional_pos:
3695
0
    if (!noptargs) {
3696
0
        goto skip_optional_kwonly;
3697
0
    }
3698
0
    if (args[2]) {
3699
0
        ns = args[2];
3700
0
        if (!--noptargs) {
3701
0
            goto skip_optional_kwonly;
3702
0
        }
3703
0
    }
3704
0
    if (args[3]) {
3705
0
        if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
3706
0
            goto exit;
3707
0
        }
3708
0
        if (!--noptargs) {
3709
0
            goto skip_optional_kwonly;
3710
0
        }
3711
0
    }
3712
0
    follow_symlinks = PyObject_IsTrue(args[4]);
3713
0
    if (follow_symlinks < 0) {
3714
0
        goto exit;
3715
0
    }
3716
0
skip_optional_kwonly:
3717
0
    return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
3718
3719
0
exit:
3720
    /* Cleanup for path */
3721
0
    path_cleanup(&path);
3722
3723
0
    return return_value;
3724
0
}
3725
3726
PyDoc_STRVAR(os__exit__doc__,
3727
"_exit($module, /, status)\n"
3728
"--\n"
3729
"\n"
3730
"Exit to the system with specified status, without normal exit processing.");
3731
3732
#define OS__EXIT_METHODDEF    \
3733
    {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
3734
3735
static PyObject *
3736
os__exit_impl(PyObject *module, int status);
3737
3738
static PyObject *
3739
os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3740
0
{
3741
0
    PyObject *return_value = NULL;
3742
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3743
3744
0
    #define NUM_KEYWORDS 1
3745
0
    static struct {
3746
0
        PyGC_Head _this_is_not_used;
3747
0
        PyObject_VAR_HEAD
3748
0
        Py_hash_t ob_hash;
3749
0
        PyObject *ob_item[NUM_KEYWORDS];
3750
0
    } _kwtuple = {
3751
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3752
0
        .ob_hash = -1,
3753
0
        .ob_item = { &_Py_ID(status), },
3754
0
    };
3755
0
    #undef NUM_KEYWORDS
3756
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3757
3758
    #else  // !Py_BUILD_CORE
3759
    #  define KWTUPLE NULL
3760
    #endif  // !Py_BUILD_CORE
3761
3762
0
    static const char * const _keywords[] = {"status", NULL};
3763
0
    static _PyArg_Parser _parser = {
3764
0
        .keywords = _keywords,
3765
0
        .fname = "_exit",
3766
0
        .kwtuple = KWTUPLE,
3767
0
    };
3768
0
    #undef KWTUPLE
3769
0
    PyObject *argsbuf[1];
3770
0
    int status;
3771
3772
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3773
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3774
0
    if (!args) {
3775
0
        goto exit;
3776
0
    }
3777
0
    status = PyLong_AsInt(args[0]);
3778
0
    if (status == -1 && PyErr_Occurred()) {
3779
0
        goto exit;
3780
0
    }
3781
0
    return_value = os__exit_impl(module, status);
3782
3783
0
exit:
3784
0
    return return_value;
3785
0
}
3786
3787
#if defined(HAVE_EXECV)
3788
3789
PyDoc_STRVAR(os_execv__doc__,
3790
"execv($module, path, argv, /)\n"
3791
"--\n"
3792
"\n"
3793
"Execute an executable path with arguments, replacing current process.\n"
3794
"\n"
3795
"  path\n"
3796
"    Path of executable file.\n"
3797
"  argv\n"
3798
"    Tuple or list of strings.");
3799
3800
#define OS_EXECV_METHODDEF    \
3801
    {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__},
3802
3803
static PyObject *
3804
os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
3805
3806
static PyObject *
3807
os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3808
0
{
3809
0
    PyObject *return_value = NULL;
3810
0
    path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0);
3811
0
    PyObject *argv;
3812
3813
0
    if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
3814
0
        goto exit;
3815
0
    }
3816
0
    if (!path_converter(args[0], &path)) {
3817
0
        goto exit;
3818
0
    }
3819
0
    argv = args[1];
3820
0
    return_value = os_execv_impl(module, &path, argv);
3821
3822
0
exit:
3823
    /* Cleanup for path */
3824
0
    path_cleanup(&path);
3825
3826
0
    return return_value;
3827
0
}
3828
3829
#endif /* defined(HAVE_EXECV) */
3830
3831
#if defined(HAVE_EXECV)
3832
3833
PyDoc_STRVAR(os_execve__doc__,
3834
"execve($module, /, path, argv, env)\n"
3835
"--\n"
3836
"\n"
3837
"Execute an executable path with arguments, replacing current process.\n"
3838
"\n"
3839
"  path\n"
3840
"    Path of executable file.\n"
3841
"  argv\n"
3842
"    Tuple or list of strings.\n"
3843
"  env\n"
3844
"    Dictionary of strings mapping to strings.");
3845
3846
#define OS_EXECVE_METHODDEF    \
3847
    {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
3848
3849
static PyObject *
3850
os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
3851
3852
static PyObject *
3853
os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3854
0
{
3855
0
    PyObject *return_value = NULL;
3856
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3857
3858
0
    #define NUM_KEYWORDS 3
3859
0
    static struct {
3860
0
        PyGC_Head _this_is_not_used;
3861
0
        PyObject_VAR_HEAD
3862
0
        Py_hash_t ob_hash;
3863
0
        PyObject *ob_item[NUM_KEYWORDS];
3864
0
    } _kwtuple = {
3865
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3866
0
        .ob_hash = -1,
3867
0
        .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), },
3868
0
    };
3869
0
    #undef NUM_KEYWORDS
3870
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3871
3872
    #else  // !Py_BUILD_CORE
3873
    #  define KWTUPLE NULL
3874
    #endif  // !Py_BUILD_CORE
3875
3876
0
    static const char * const _keywords[] = {"path", "argv", "env", NULL};
3877
0
    static _PyArg_Parser _parser = {
3878
0
        .keywords = _keywords,
3879
0
        .fname = "execve",
3880
0
        .kwtuple = KWTUPLE,
3881
0
    };
3882
0
    #undef KWTUPLE
3883
0
    PyObject *argsbuf[3];
3884
0
    path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE);
3885
0
    PyObject *argv;
3886
0
    PyObject *env;
3887
3888
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3889
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3890
0
    if (!args) {
3891
0
        goto exit;
3892
0
    }
3893
0
    if (!path_converter(args[0], &path)) {
3894
0
        goto exit;
3895
0
    }
3896
0
    argv = args[1];
3897
0
    env = args[2];
3898
0
    return_value = os_execve_impl(module, &path, argv, env);
3899
3900
0
exit:
3901
    /* Cleanup for path */
3902
0
    path_cleanup(&path);
3903
3904
0
    return return_value;
3905
0
}
3906
3907
#endif /* defined(HAVE_EXECV) */
3908
3909
#if defined(HAVE_POSIX_SPAWN)
3910
3911
PyDoc_STRVAR(os_posix_spawn__doc__,
3912
"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
3913
"            setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
3914
"            setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
3915
"--\n"
3916
"\n"
3917
"Execute the program specified by path in a new process.\n"
3918
"\n"
3919
"  path\n"
3920
"    Path of executable file.\n"
3921
"  argv\n"
3922
"    Tuple or list of strings.\n"
3923
"  env\n"
3924
"    Dictionary of strings mapping to strings.\n"
3925
"  file_actions\n"
3926
"    A sequence of file action tuples.\n"
3927
"  setpgroup\n"
3928
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
3929
"  resetids\n"
3930
"    If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
3931
"  setsid\n"
3932
"    If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
3933
"  setsigmask\n"
3934
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
3935
"  setsigdef\n"
3936
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
3937
"  scheduler\n"
3938
"    A tuple with the scheduler policy (optional) and parameters.");
3939
3940
#define OS_POSIX_SPAWN_METHODDEF    \
3941
    {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
3942
3943
static PyObject *
3944
os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
3945
                    PyObject *env, PyObject *file_actions,
3946
                    PyObject *setpgroup, int resetids, int setsid,
3947
                    PyObject *setsigmask, PyObject *setsigdef,
3948
                    PyObject *scheduler);
3949
3950
static PyObject *
3951
os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3952
0
{
3953
0
    PyObject *return_value = NULL;
3954
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3955
3956
0
    #define NUM_KEYWORDS 7
3957
0
    static struct {
3958
0
        PyGC_Head _this_is_not_used;
3959
0
        PyObject_VAR_HEAD
3960
0
        Py_hash_t ob_hash;
3961
0
        PyObject *ob_item[NUM_KEYWORDS];
3962
0
    } _kwtuple = {
3963
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3964
0
        .ob_hash = -1,
3965
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), },
3966
0
    };
3967
0
    #undef NUM_KEYWORDS
3968
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3969
3970
    #else  // !Py_BUILD_CORE
3971
    #  define KWTUPLE NULL
3972
    #endif  // !Py_BUILD_CORE
3973
3974
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
3975
0
    static _PyArg_Parser _parser = {
3976
0
        .keywords = _keywords,
3977
0
        .fname = "posix_spawn",
3978
0
        .kwtuple = KWTUPLE,
3979
0
    };
3980
0
    #undef KWTUPLE
3981
0
    PyObject *argsbuf[10];
3982
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
3983
0
    path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0);
3984
0
    PyObject *argv;
3985
0
    PyObject *env;
3986
0
    PyObject *file_actions = NULL;
3987
0
    PyObject *setpgroup = NULL;
3988
0
    int resetids = 0;
3989
0
    int setsid = 0;
3990
0
    PyObject *setsigmask = NULL;
3991
0
    PyObject *setsigdef = NULL;
3992
0
    PyObject *scheduler = NULL;
3993
3994
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3995
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3996
0
    if (!args) {
3997
0
        goto exit;
3998
0
    }
3999
0
    if (!path_converter(args[0], &path)) {
4000
0
        goto exit;
4001
0
    }
4002
0
    argv = args[1];
4003
0
    env = args[2];
4004
0
    if (!noptargs) {
4005
0
        goto skip_optional_kwonly;
4006
0
    }
4007
0
    if (args[3]) {
4008
0
        file_actions = args[3];
4009
0
        if (!--noptargs) {
4010
0
            goto skip_optional_kwonly;
4011
0
        }
4012
0
    }
4013
0
    if (args[4]) {
4014
0
        setpgroup = args[4];
4015
0
        if (!--noptargs) {
4016
0
            goto skip_optional_kwonly;
4017
0
        }
4018
0
    }
4019
0
    if (args[5]) {
4020
0
        resetids = PyObject_IsTrue(args[5]);
4021
0
        if (resetids < 0) {
4022
0
            goto exit;
4023
0
        }
4024
0
        if (!--noptargs) {
4025
0
            goto skip_optional_kwonly;
4026
0
        }
4027
0
    }
4028
0
    if (args[6]) {
4029
0
        setsid = PyObject_IsTrue(args[6]);
4030
0
        if (setsid < 0) {
4031
0
            goto exit;
4032
0
        }
4033
0
        if (!--noptargs) {
4034
0
            goto skip_optional_kwonly;
4035
0
        }
4036
0
    }
4037
0
    if (args[7]) {
4038
0
        setsigmask = args[7];
4039
0
        if (!--noptargs) {
4040
0
            goto skip_optional_kwonly;
4041
0
        }
4042
0
    }
4043
0
    if (args[8]) {
4044
0
        setsigdef = args[8];
4045
0
        if (!--noptargs) {
4046
0
            goto skip_optional_kwonly;
4047
0
        }
4048
0
    }
4049
0
    scheduler = args[9];
4050
0
skip_optional_kwonly:
4051
0
    return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
4052
4053
0
exit:
4054
    /* Cleanup for path */
4055
0
    path_cleanup(&path);
4056
4057
0
    return return_value;
4058
0
}
4059
4060
#endif /* defined(HAVE_POSIX_SPAWN) */
4061
4062
#if defined(HAVE_POSIX_SPAWNP)
4063
4064
PyDoc_STRVAR(os_posix_spawnp__doc__,
4065
"posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
4066
"             setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
4067
"             setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
4068
"--\n"
4069
"\n"
4070
"Execute the program specified by path in a new process.\n"
4071
"\n"
4072
"  path\n"
4073
"    Path of executable file.\n"
4074
"  argv\n"
4075
"    Tuple or list of strings.\n"
4076
"  env\n"
4077
"    Dictionary of strings mapping to strings.\n"
4078
"  file_actions\n"
4079
"    A sequence of file action tuples.\n"
4080
"  setpgroup\n"
4081
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
4082
"  resetids\n"
4083
"    If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
4084
"  setsid\n"
4085
"    If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
4086
"  setsigmask\n"
4087
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
4088
"  setsigdef\n"
4089
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
4090
"  scheduler\n"
4091
"    A tuple with the scheduler policy (optional) and parameters.");
4092
4093
#define OS_POSIX_SPAWNP_METHODDEF    \
4094
    {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
4095
4096
static PyObject *
4097
os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
4098
                     PyObject *env, PyObject *file_actions,
4099
                     PyObject *setpgroup, int resetids, int setsid,
4100
                     PyObject *setsigmask, PyObject *setsigdef,
4101
                     PyObject *scheduler);
4102
4103
static PyObject *
4104
os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4105
0
{
4106
0
    PyObject *return_value = NULL;
4107
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4108
4109
0
    #define NUM_KEYWORDS 7
4110
0
    static struct {
4111
0
        PyGC_Head _this_is_not_used;
4112
0
        PyObject_VAR_HEAD
4113
0
        Py_hash_t ob_hash;
4114
0
        PyObject *ob_item[NUM_KEYWORDS];
4115
0
    } _kwtuple = {
4116
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4117
0
        .ob_hash = -1,
4118
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), },
4119
0
    };
4120
0
    #undef NUM_KEYWORDS
4121
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4122
4123
    #else  // !Py_BUILD_CORE
4124
    #  define KWTUPLE NULL
4125
    #endif  // !Py_BUILD_CORE
4126
4127
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
4128
0
    static _PyArg_Parser _parser = {
4129
0
        .keywords = _keywords,
4130
0
        .fname = "posix_spawnp",
4131
0
        .kwtuple = KWTUPLE,
4132
0
    };
4133
0
    #undef KWTUPLE
4134
0
    PyObject *argsbuf[10];
4135
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
4136
0
    path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0);
4137
0
    PyObject *argv;
4138
0
    PyObject *env;
4139
0
    PyObject *file_actions = NULL;
4140
0
    PyObject *setpgroup = NULL;
4141
0
    int resetids = 0;
4142
0
    int setsid = 0;
4143
0
    PyObject *setsigmask = NULL;
4144
0
    PyObject *setsigdef = NULL;
4145
0
    PyObject *scheduler = NULL;
4146
4147
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4148
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4149
0
    if (!args) {
4150
0
        goto exit;
4151
0
    }
4152
0
    if (!path_converter(args[0], &path)) {
4153
0
        goto exit;
4154
0
    }
4155
0
    argv = args[1];
4156
0
    env = args[2];
4157
0
    if (!noptargs) {
4158
0
        goto skip_optional_kwonly;
4159
0
    }
4160
0
    if (args[3]) {
4161
0
        file_actions = args[3];
4162
0
        if (!--noptargs) {
4163
0
            goto skip_optional_kwonly;
4164
0
        }
4165
0
    }
4166
0
    if (args[4]) {
4167
0
        setpgroup = args[4];
4168
0
        if (!--noptargs) {
4169
0
            goto skip_optional_kwonly;
4170
0
        }
4171
0
    }
4172
0
    if (args[5]) {
4173
0
        resetids = PyObject_IsTrue(args[5]);
4174
0
        if (resetids < 0) {
4175
0
            goto exit;
4176
0
        }
4177
0
        if (!--noptargs) {
4178
0
            goto skip_optional_kwonly;
4179
0
        }
4180
0
    }
4181
0
    if (args[6]) {
4182
0
        setsid = PyObject_IsTrue(args[6]);
4183
0
        if (setsid < 0) {
4184
0
            goto exit;
4185
0
        }
4186
0
        if (!--noptargs) {
4187
0
            goto skip_optional_kwonly;
4188
0
        }
4189
0
    }
4190
0
    if (args[7]) {
4191
0
        setsigmask = args[7];
4192
0
        if (!--noptargs) {
4193
0
            goto skip_optional_kwonly;
4194
0
        }
4195
0
    }
4196
0
    if (args[8]) {
4197
0
        setsigdef = args[8];
4198
0
        if (!--noptargs) {
4199
0
            goto skip_optional_kwonly;
4200
0
        }
4201
0
    }
4202
0
    scheduler = args[9];
4203
0
skip_optional_kwonly:
4204
0
    return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
4205
4206
0
exit:
4207
    /* Cleanup for path */
4208
0
    path_cleanup(&path);
4209
4210
0
    return return_value;
4211
0
}
4212
4213
#endif /* defined(HAVE_POSIX_SPAWNP) */
4214
4215
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4216
4217
PyDoc_STRVAR(os_spawnv__doc__,
4218
"spawnv($module, mode, path, argv, /)\n"
4219
"--\n"
4220
"\n"
4221
"Execute the program specified by path in a new process.\n"
4222
"\n"
4223
"  mode\n"
4224
"    Mode of process creation.\n"
4225
"  path\n"
4226
"    Path of executable file.\n"
4227
"  argv\n"
4228
"    Tuple or list of strings.");
4229
4230
#define OS_SPAWNV_METHODDEF    \
4231
    {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__},
4232
4233
static PyObject *
4234
os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
4235
4236
static PyObject *
4237
os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4238
{
4239
    PyObject *return_value = NULL;
4240
    int mode;
4241
    path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0);
4242
    PyObject *argv;
4243
4244
    if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
4245
        goto exit;
4246
    }
4247
    mode = PyLong_AsInt(args[0]);
4248
    if (mode == -1 && PyErr_Occurred()) {
4249
        goto exit;
4250
    }
4251
    if (!path_converter(args[1], &path)) {
4252
        goto exit;
4253
    }
4254
    argv = args[2];
4255
    return_value = os_spawnv_impl(module, mode, &path, argv);
4256
4257
exit:
4258
    /* Cleanup for path */
4259
    path_cleanup(&path);
4260
4261
    return return_value;
4262
}
4263
4264
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4265
4266
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4267
4268
PyDoc_STRVAR(os_spawnve__doc__,
4269
"spawnve($module, mode, path, argv, env, /)\n"
4270
"--\n"
4271
"\n"
4272
"Execute the program specified by path in a new process.\n"
4273
"\n"
4274
"  mode\n"
4275
"    Mode of process creation.\n"
4276
"  path\n"
4277
"    Path of executable file.\n"
4278
"  argv\n"
4279
"    Tuple or list of strings.\n"
4280
"  env\n"
4281
"    Dictionary of strings mapping to strings.");
4282
4283
#define OS_SPAWNVE_METHODDEF    \
4284
    {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__},
4285
4286
static PyObject *
4287
os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
4288
                PyObject *env);
4289
4290
static PyObject *
4291
os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4292
{
4293
    PyObject *return_value = NULL;
4294
    int mode;
4295
    path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0);
4296
    PyObject *argv;
4297
    PyObject *env;
4298
4299
    if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
4300
        goto exit;
4301
    }
4302
    mode = PyLong_AsInt(args[0]);
4303
    if (mode == -1 && PyErr_Occurred()) {
4304
        goto exit;
4305
    }
4306
    if (!path_converter(args[1], &path)) {
4307
        goto exit;
4308
    }
4309
    argv = args[2];
4310
    env = args[3];
4311
    return_value = os_spawnve_impl(module, mode, &path, argv, env);
4312
4313
exit:
4314
    /* Cleanup for path */
4315
    path_cleanup(&path);
4316
4317
    return return_value;
4318
}
4319
4320
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4321
4322
#if defined(HAVE_FORK)
4323
4324
PyDoc_STRVAR(os_register_at_fork__doc__,
4325
"register_at_fork($module, /, *, before=<unrepresentable>,\n"
4326
"                 after_in_child=<unrepresentable>,\n"
4327
"                 after_in_parent=<unrepresentable>)\n"
4328
"--\n"
4329
"\n"
4330
"Register callables to be called when forking a new process.\n"
4331
"\n"
4332
"  before\n"
4333
"    A callable to be called in the parent before the fork() syscall.\n"
4334
"  after_in_child\n"
4335
"    A callable to be called in the child after fork().\n"
4336
"  after_in_parent\n"
4337
"    A callable to be called in the parent after fork().\n"
4338
"\n"
4339
"\'before\' callbacks are called in reverse order.\n"
4340
"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
4341
4342
#define OS_REGISTER_AT_FORK_METHODDEF    \
4343
    {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
4344
4345
static PyObject *
4346
os_register_at_fork_impl(PyObject *module, PyObject *before,
4347
                         PyObject *after_in_child, PyObject *after_in_parent);
4348
4349
static PyObject *
4350
os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4351
0
{
4352
0
    PyObject *return_value = NULL;
4353
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4354
4355
0
    #define NUM_KEYWORDS 3
4356
0
    static struct {
4357
0
        PyGC_Head _this_is_not_used;
4358
0
        PyObject_VAR_HEAD
4359
0
        Py_hash_t ob_hash;
4360
0
        PyObject *ob_item[NUM_KEYWORDS];
4361
0
    } _kwtuple = {
4362
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4363
0
        .ob_hash = -1,
4364
0
        .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), },
4365
0
    };
4366
0
    #undef NUM_KEYWORDS
4367
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4368
4369
    #else  // !Py_BUILD_CORE
4370
    #  define KWTUPLE NULL
4371
    #endif  // !Py_BUILD_CORE
4372
4373
0
    static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
4374
0
    static _PyArg_Parser _parser = {
4375
0
        .keywords = _keywords,
4376
0
        .fname = "register_at_fork",
4377
0
        .kwtuple = KWTUPLE,
4378
0
    };
4379
0
    #undef KWTUPLE
4380
0
    PyObject *argsbuf[3];
4381
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
4382
0
    PyObject *before = NULL;
4383
0
    PyObject *after_in_child = NULL;
4384
0
    PyObject *after_in_parent = NULL;
4385
4386
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4387
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4388
0
    if (!args) {
4389
0
        goto exit;
4390
0
    }
4391
0
    if (!noptargs) {
4392
0
        goto skip_optional_kwonly;
4393
0
    }
4394
0
    if (args[0]) {
4395
0
        before = args[0];
4396
0
        if (!--noptargs) {
4397
0
            goto skip_optional_kwonly;
4398
0
        }
4399
0
    }
4400
0
    if (args[1]) {
4401
0
        after_in_child = args[1];
4402
0
        if (!--noptargs) {
4403
0
            goto skip_optional_kwonly;
4404
0
        }
4405
0
    }
4406
0
    after_in_parent = args[2];
4407
0
skip_optional_kwonly:
4408
0
    return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
4409
4410
0
exit:
4411
0
    return return_value;
4412
0
}
4413
4414
#endif /* defined(HAVE_FORK) */
4415
4416
#if defined(HAVE_FORK1)
4417
4418
PyDoc_STRVAR(os_fork1__doc__,
4419
"fork1($module, /)\n"
4420
"--\n"
4421
"\n"
4422
"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
4423
"\n"
4424
"Return 0 to child process and PID of child to parent process.");
4425
4426
#define OS_FORK1_METHODDEF    \
4427
    {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
4428
4429
static PyObject *
4430
os_fork1_impl(PyObject *module);
4431
4432
static PyObject *
4433
os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
4434
{
4435
    return os_fork1_impl(module);
4436
}
4437
4438
#endif /* defined(HAVE_FORK1) */
4439
4440
#if defined(HAVE_FORK)
4441
4442
PyDoc_STRVAR(os_fork__doc__,
4443
"fork($module, /)\n"
4444
"--\n"
4445
"\n"
4446
"Fork a child process.\n"
4447
"\n"
4448
"Return 0 to child process and PID of child to parent process.");
4449
4450
#define OS_FORK_METHODDEF    \
4451
    {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
4452
4453
static PyObject *
4454
os_fork_impl(PyObject *module);
4455
4456
static PyObject *
4457
os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
4458
0
{
4459
0
    return os_fork_impl(module);
4460
0
}
4461
4462
#endif /* defined(HAVE_FORK) */
4463
4464
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4465
4466
PyDoc_STRVAR(os_sched_get_priority_max__doc__,
4467
"sched_get_priority_max($module, /, policy)\n"
4468
"--\n"
4469
"\n"
4470
"Get the maximum scheduling priority for policy.");
4471
4472
#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF    \
4473
    {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
4474
4475
static PyObject *
4476
os_sched_get_priority_max_impl(PyObject *module, int policy);
4477
4478
static PyObject *
4479
os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4480
0
{
4481
0
    PyObject *return_value = NULL;
4482
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4483
4484
0
    #define NUM_KEYWORDS 1
4485
0
    static struct {
4486
0
        PyGC_Head _this_is_not_used;
4487
0
        PyObject_VAR_HEAD
4488
0
        Py_hash_t ob_hash;
4489
0
        PyObject *ob_item[NUM_KEYWORDS];
4490
0
    } _kwtuple = {
4491
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4492
0
        .ob_hash = -1,
4493
0
        .ob_item = { &_Py_ID(policy), },
4494
0
    };
4495
0
    #undef NUM_KEYWORDS
4496
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4497
4498
    #else  // !Py_BUILD_CORE
4499
    #  define KWTUPLE NULL
4500
    #endif  // !Py_BUILD_CORE
4501
4502
0
    static const char * const _keywords[] = {"policy", NULL};
4503
0
    static _PyArg_Parser _parser = {
4504
0
        .keywords = _keywords,
4505
0
        .fname = "sched_get_priority_max",
4506
0
        .kwtuple = KWTUPLE,
4507
0
    };
4508
0
    #undef KWTUPLE
4509
0
    PyObject *argsbuf[1];
4510
0
    int policy;
4511
4512
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4513
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4514
0
    if (!args) {
4515
0
        goto exit;
4516
0
    }
4517
0
    policy = PyLong_AsInt(args[0]);
4518
0
    if (policy == -1 && PyErr_Occurred()) {
4519
0
        goto exit;
4520
0
    }
4521
0
    return_value = os_sched_get_priority_max_impl(module, policy);
4522
4523
0
exit:
4524
0
    return return_value;
4525
0
}
4526
4527
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4528
4529
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4530
4531
PyDoc_STRVAR(os_sched_get_priority_min__doc__,
4532
"sched_get_priority_min($module, /, policy)\n"
4533
"--\n"
4534
"\n"
4535
"Get the minimum scheduling priority for policy.");
4536
4537
#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF    \
4538
    {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
4539
4540
static PyObject *
4541
os_sched_get_priority_min_impl(PyObject *module, int policy);
4542
4543
static PyObject *
4544
os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4545
0
{
4546
0
    PyObject *return_value = NULL;
4547
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4548
4549
0
    #define NUM_KEYWORDS 1
4550
0
    static struct {
4551
0
        PyGC_Head _this_is_not_used;
4552
0
        PyObject_VAR_HEAD
4553
0
        Py_hash_t ob_hash;
4554
0
        PyObject *ob_item[NUM_KEYWORDS];
4555
0
    } _kwtuple = {
4556
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4557
0
        .ob_hash = -1,
4558
0
        .ob_item = { &_Py_ID(policy), },
4559
0
    };
4560
0
    #undef NUM_KEYWORDS
4561
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4562
4563
    #else  // !Py_BUILD_CORE
4564
    #  define KWTUPLE NULL
4565
    #endif  // !Py_BUILD_CORE
4566
4567
0
    static const char * const _keywords[] = {"policy", NULL};
4568
0
    static _PyArg_Parser _parser = {
4569
0
        .keywords = _keywords,
4570
0
        .fname = "sched_get_priority_min",
4571
0
        .kwtuple = KWTUPLE,
4572
0
    };
4573
0
    #undef KWTUPLE
4574
0
    PyObject *argsbuf[1];
4575
0
    int policy;
4576
4577
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4578
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4579
0
    if (!args) {
4580
0
        goto exit;
4581
0
    }
4582
0
    policy = PyLong_AsInt(args[0]);
4583
0
    if (policy == -1 && PyErr_Occurred()) {
4584
0
        goto exit;
4585
0
    }
4586
0
    return_value = os_sched_get_priority_min_impl(module, policy);
4587
4588
0
exit:
4589
0
    return return_value;
4590
0
}
4591
4592
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4593
4594
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4595
4596
PyDoc_STRVAR(os_sched_getscheduler__doc__,
4597
"sched_getscheduler($module, pid, /)\n"
4598
"--\n"
4599
"\n"
4600
"Get the scheduling policy for the process identified by pid.\n"
4601
"\n"
4602
"Passing 0 for pid returns the scheduling policy for the calling process.");
4603
4604
#define OS_SCHED_GETSCHEDULER_METHODDEF    \
4605
    {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
4606
4607
static PyObject *
4608
os_sched_getscheduler_impl(PyObject *module, pid_t pid);
4609
4610
static PyObject *
4611
os_sched_getscheduler(PyObject *module, PyObject *arg)
4612
0
{
4613
0
    PyObject *return_value = NULL;
4614
0
    pid_t pid;
4615
4616
0
    pid = PyLong_AsPid(arg);
4617
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4618
0
        goto exit;
4619
0
    }
4620
0
    return_value = os_sched_getscheduler_impl(module, pid);
4621
4622
0
exit:
4623
0
    return return_value;
4624
0
}
4625
4626
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4627
4628
#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
4629
4630
PyDoc_STRVAR(os_sched_param__doc__,
4631
"sched_param(sched_priority)\n"
4632
"--\n"
4633
"\n"
4634
"Currently has only one field: sched_priority\n"
4635
"\n"
4636
"  sched_priority\n"
4637
"    A scheduling parameter.");
4638
4639
static PyObject *
4640
os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
4641
4642
static PyObject *
4643
os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
4644
0
{
4645
0
    PyObject *return_value = NULL;
4646
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4647
4648
0
    #define NUM_KEYWORDS 1
4649
0
    static struct {
4650
0
        PyGC_Head _this_is_not_used;
4651
0
        PyObject_VAR_HEAD
4652
0
        Py_hash_t ob_hash;
4653
0
        PyObject *ob_item[NUM_KEYWORDS];
4654
0
    } _kwtuple = {
4655
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4656
0
        .ob_hash = -1,
4657
0
        .ob_item = { &_Py_ID(sched_priority), },
4658
0
    };
4659
0
    #undef NUM_KEYWORDS
4660
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4661
4662
    #else  // !Py_BUILD_CORE
4663
    #  define KWTUPLE NULL
4664
    #endif  // !Py_BUILD_CORE
4665
4666
0
    static const char * const _keywords[] = {"sched_priority", NULL};
4667
0
    static _PyArg_Parser _parser = {
4668
0
        .keywords = _keywords,
4669
0
        .fname = "sched_param",
4670
0
        .kwtuple = KWTUPLE,
4671
0
    };
4672
0
    #undef KWTUPLE
4673
0
    PyObject *argsbuf[1];
4674
0
    PyObject * const *fastargs;
4675
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
4676
0
    PyObject *sched_priority;
4677
4678
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
4679
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4680
0
    if (!fastargs) {
4681
0
        goto exit;
4682
0
    }
4683
0
    sched_priority = fastargs[0];
4684
0
    return_value = os_sched_param_impl(type, sched_priority);
4685
4686
0
exit:
4687
0
    return return_value;
4688
0
}
4689
4690
#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
4691
4692
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4693
4694
PyDoc_STRVAR(os_sched_setscheduler__doc__,
4695
"sched_setscheduler($module, pid, policy, param, /)\n"
4696
"--\n"
4697
"\n"
4698
"Set the scheduling policy for the process identified by pid.\n"
4699
"\n"
4700
"If pid is 0, the calling process is changed.\n"
4701
"param is an instance of sched_param.");
4702
4703
#define OS_SCHED_SETSCHEDULER_METHODDEF    \
4704
    {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__},
4705
4706
static PyObject *
4707
os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
4708
                           PyObject *param_obj);
4709
4710
static PyObject *
4711
os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4712
0
{
4713
0
    PyObject *return_value = NULL;
4714
0
    pid_t pid;
4715
0
    int policy;
4716
0
    PyObject *param_obj;
4717
4718
0
    if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) {
4719
0
        goto exit;
4720
0
    }
4721
0
    pid = PyLong_AsPid(args[0]);
4722
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4723
0
        goto exit;
4724
0
    }
4725
0
    policy = PyLong_AsInt(args[1]);
4726
0
    if (policy == -1 && PyErr_Occurred()) {
4727
0
        goto exit;
4728
0
    }
4729
0
    param_obj = args[2];
4730
0
    return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj);
4731
4732
0
exit:
4733
0
    return return_value;
4734
0
}
4735
4736
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4737
4738
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4739
4740
PyDoc_STRVAR(os_sched_getparam__doc__,
4741
"sched_getparam($module, pid, /)\n"
4742
"--\n"
4743
"\n"
4744
"Returns scheduling parameters for the process identified by pid.\n"
4745
"\n"
4746
"If pid is 0, returns parameters for the calling process.\n"
4747
"Return value is an instance of sched_param.");
4748
4749
#define OS_SCHED_GETPARAM_METHODDEF    \
4750
    {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
4751
4752
static PyObject *
4753
os_sched_getparam_impl(PyObject *module, pid_t pid);
4754
4755
static PyObject *
4756
os_sched_getparam(PyObject *module, PyObject *arg)
4757
0
{
4758
0
    PyObject *return_value = NULL;
4759
0
    pid_t pid;
4760
4761
0
    pid = PyLong_AsPid(arg);
4762
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4763
0
        goto exit;
4764
0
    }
4765
0
    return_value = os_sched_getparam_impl(module, pid);
4766
4767
0
exit:
4768
0
    return return_value;
4769
0
}
4770
4771
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4772
4773
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4774
4775
PyDoc_STRVAR(os_sched_setparam__doc__,
4776
"sched_setparam($module, pid, param, /)\n"
4777
"--\n"
4778
"\n"
4779
"Set scheduling parameters for the process identified by pid.\n"
4780
"\n"
4781
"If pid is 0, sets parameters for the calling process.\n"
4782
"param should be an instance of sched_param.");
4783
4784
#define OS_SCHED_SETPARAM_METHODDEF    \
4785
    {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__},
4786
4787
static PyObject *
4788
os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj);
4789
4790
static PyObject *
4791
os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4792
0
{
4793
0
    PyObject *return_value = NULL;
4794
0
    pid_t pid;
4795
0
    PyObject *param_obj;
4796
4797
0
    if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) {
4798
0
        goto exit;
4799
0
    }
4800
0
    pid = PyLong_AsPid(args[0]);
4801
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4802
0
        goto exit;
4803
0
    }
4804
0
    param_obj = args[1];
4805
0
    return_value = os_sched_setparam_impl(module, pid, param_obj);
4806
4807
0
exit:
4808
0
    return return_value;
4809
0
}
4810
4811
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4812
4813
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
4814
4815
PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
4816
"sched_rr_get_interval($module, pid, /)\n"
4817
"--\n"
4818
"\n"
4819
"Return the round-robin quantum for the process identified by pid, in seconds.\n"
4820
"\n"
4821
"Value returned is a float.");
4822
4823
#define OS_SCHED_RR_GET_INTERVAL_METHODDEF    \
4824
    {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
4825
4826
static double
4827
os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
4828
4829
static PyObject *
4830
os_sched_rr_get_interval(PyObject *module, PyObject *arg)
4831
0
{
4832
0
    PyObject *return_value = NULL;
4833
0
    pid_t pid;
4834
0
    double _return_value;
4835
4836
0
    pid = PyLong_AsPid(arg);
4837
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4838
0
        goto exit;
4839
0
    }
4840
0
    _return_value = os_sched_rr_get_interval_impl(module, pid);
4841
0
    if ((_return_value == -1.0) && PyErr_Occurred()) {
4842
0
        goto exit;
4843
0
    }
4844
0
    return_value = PyFloat_FromDouble(_return_value);
4845
4846
0
exit:
4847
0
    return return_value;
4848
0
}
4849
4850
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
4851
4852
#if defined(HAVE_SCHED_H)
4853
4854
PyDoc_STRVAR(os_sched_yield__doc__,
4855
"sched_yield($module, /)\n"
4856
"--\n"
4857
"\n"
4858
"Voluntarily relinquish the CPU.");
4859
4860
#define OS_SCHED_YIELD_METHODDEF    \
4861
    {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
4862
4863
static PyObject *
4864
os_sched_yield_impl(PyObject *module);
4865
4866
static PyObject *
4867
os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
4868
0
{
4869
0
    return os_sched_yield_impl(module);
4870
0
}
4871
4872
#endif /* defined(HAVE_SCHED_H) */
4873
4874
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4875
4876
PyDoc_STRVAR(os_sched_setaffinity__doc__,
4877
"sched_setaffinity($module, pid, mask, /)\n"
4878
"--\n"
4879
"\n"
4880
"Set the CPU affinity of the process identified by pid to mask.\n"
4881
"\n"
4882
"mask should be an iterable of integers identifying CPUs.");
4883
4884
#define OS_SCHED_SETAFFINITY_METHODDEF    \
4885
    {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__},
4886
4887
static PyObject *
4888
os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
4889
4890
static PyObject *
4891
os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4892
0
{
4893
0
    PyObject *return_value = NULL;
4894
0
    pid_t pid;
4895
0
    PyObject *mask;
4896
4897
0
    if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) {
4898
0
        goto exit;
4899
0
    }
4900
0
    pid = PyLong_AsPid(args[0]);
4901
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4902
0
        goto exit;
4903
0
    }
4904
0
    mask = args[1];
4905
0
    return_value = os_sched_setaffinity_impl(module, pid, mask);
4906
4907
0
exit:
4908
0
    return return_value;
4909
0
}
4910
4911
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4912
4913
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4914
4915
PyDoc_STRVAR(os_sched_getaffinity__doc__,
4916
"sched_getaffinity($module, pid, /)\n"
4917
"--\n"
4918
"\n"
4919
"Return the affinity of the process identified by pid (or the current process if zero).\n"
4920
"\n"
4921
"The affinity is returned as a set of CPU identifiers.");
4922
4923
#define OS_SCHED_GETAFFINITY_METHODDEF    \
4924
    {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
4925
4926
static PyObject *
4927
os_sched_getaffinity_impl(PyObject *module, pid_t pid);
4928
4929
static PyObject *
4930
os_sched_getaffinity(PyObject *module, PyObject *arg)
4931
0
{
4932
0
    PyObject *return_value = NULL;
4933
0
    pid_t pid;
4934
4935
0
    pid = PyLong_AsPid(arg);
4936
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4937
0
        goto exit;
4938
0
    }
4939
0
    return_value = os_sched_getaffinity_impl(module, pid);
4940
4941
0
exit:
4942
0
    return return_value;
4943
0
}
4944
4945
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4946
4947
#if defined(HAVE_POSIX_OPENPT)
4948
4949
PyDoc_STRVAR(os_posix_openpt__doc__,
4950
"posix_openpt($module, oflag, /)\n"
4951
"--\n"
4952
"\n"
4953
"Open and return a file descriptor for a master pseudo-terminal device.\n"
4954
"\n"
4955
"Performs a posix_openpt() C function call. The oflag argument is used to\n"
4956
"set file status flags and file access modes as specified in the manual page\n"
4957
"of posix_openpt() of your system.");
4958
4959
#define OS_POSIX_OPENPT_METHODDEF    \
4960
    {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__},
4961
4962
static int
4963
os_posix_openpt_impl(PyObject *module, int oflag);
4964
4965
static PyObject *
4966
os_posix_openpt(PyObject *module, PyObject *arg)
4967
0
{
4968
0
    PyObject *return_value = NULL;
4969
0
    int oflag;
4970
0
    int _return_value;
4971
4972
0
    oflag = PyLong_AsInt(arg);
4973
0
    if (oflag == -1 && PyErr_Occurred()) {
4974
0
        goto exit;
4975
0
    }
4976
0
    _return_value = os_posix_openpt_impl(module, oflag);
4977
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4978
0
        goto exit;
4979
0
    }
4980
0
    return_value = PyLong_FromLong((long)_return_value);
4981
4982
0
exit:
4983
0
    return return_value;
4984
0
}
4985
4986
#endif /* defined(HAVE_POSIX_OPENPT) */
4987
4988
#if defined(HAVE_GRANTPT)
4989
4990
PyDoc_STRVAR(os_grantpt__doc__,
4991
"grantpt($module, fd, /)\n"
4992
"--\n"
4993
"\n"
4994
"Grant access to the slave pseudo-terminal device.\n"
4995
"\n"
4996
"  fd\n"
4997
"    File descriptor of a master pseudo-terminal device.\n"
4998
"\n"
4999
"Performs a grantpt() C function call.");
5000
5001
#define OS_GRANTPT_METHODDEF    \
5002
    {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__},
5003
5004
static PyObject *
5005
os_grantpt_impl(PyObject *module, int fd);
5006
5007
static PyObject *
5008
os_grantpt(PyObject *module, PyObject *arg)
5009
0
{
5010
0
    PyObject *return_value = NULL;
5011
0
    int fd;
5012
5013
0
    fd = PyObject_AsFileDescriptor(arg);
5014
0
    if (fd < 0) {
5015
0
        goto exit;
5016
0
    }
5017
0
    return_value = os_grantpt_impl(module, fd);
5018
5019
0
exit:
5020
0
    return return_value;
5021
0
}
5022
5023
#endif /* defined(HAVE_GRANTPT) */
5024
5025
#if defined(HAVE_UNLOCKPT)
5026
5027
PyDoc_STRVAR(os_unlockpt__doc__,
5028
"unlockpt($module, fd, /)\n"
5029
"--\n"
5030
"\n"
5031
"Unlock a pseudo-terminal master/slave pair.\n"
5032
"\n"
5033
"  fd\n"
5034
"    File descriptor of a master pseudo-terminal device.\n"
5035
"\n"
5036
"Performs an unlockpt() C function call.");
5037
5038
#define OS_UNLOCKPT_METHODDEF    \
5039
    {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__},
5040
5041
static PyObject *
5042
os_unlockpt_impl(PyObject *module, int fd);
5043
5044
static PyObject *
5045
os_unlockpt(PyObject *module, PyObject *arg)
5046
0
{
5047
0
    PyObject *return_value = NULL;
5048
0
    int fd;
5049
5050
0
    fd = PyObject_AsFileDescriptor(arg);
5051
0
    if (fd < 0) {
5052
0
        goto exit;
5053
0
    }
5054
0
    return_value = os_unlockpt_impl(module, fd);
5055
5056
0
exit:
5057
0
    return return_value;
5058
0
}
5059
5060
#endif /* defined(HAVE_UNLOCKPT) */
5061
5062
#if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R))
5063
5064
PyDoc_STRVAR(os_ptsname__doc__,
5065
"ptsname($module, fd, /)\n"
5066
"--\n"
5067
"\n"
5068
"Return the name of the slave pseudo-terminal device.\n"
5069
"\n"
5070
"  fd\n"
5071
"    File descriptor of a master pseudo-terminal device.\n"
5072
"\n"
5073
"If the ptsname_r() C function is available, it is called;\n"
5074
"otherwise, performs a ptsname() C function call.");
5075
5076
#define OS_PTSNAME_METHODDEF    \
5077
    {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__},
5078
5079
static PyObject *
5080
os_ptsname_impl(PyObject *module, int fd);
5081
5082
static PyObject *
5083
os_ptsname(PyObject *module, PyObject *arg)
5084
0
{
5085
0
    PyObject *return_value = NULL;
5086
0
    int fd;
5087
5088
0
    fd = PyObject_AsFileDescriptor(arg);
5089
0
    if (fd < 0) {
5090
0
        goto exit;
5091
0
    }
5092
0
    return_value = os_ptsname_impl(module, fd);
5093
5094
0
exit:
5095
0
    return return_value;
5096
0
}
5097
5098
#endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */
5099
5100
#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
5101
5102
PyDoc_STRVAR(os_openpty__doc__,
5103
"openpty($module, /)\n"
5104
"--\n"
5105
"\n"
5106
"Open a pseudo-terminal.\n"
5107
"\n"
5108
"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
5109
"for both the master and slave ends.");
5110
5111
#define OS_OPENPTY_METHODDEF    \
5112
    {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
5113
5114
static PyObject *
5115
os_openpty_impl(PyObject *module);
5116
5117
static PyObject *
5118
os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
5119
0
{
5120
0
    return os_openpty_impl(module);
5121
0
}
5122
5123
#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
5124
5125
#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY))
5126
5127
PyDoc_STRVAR(os_login_tty__doc__,
5128
"login_tty($module, fd, /)\n"
5129
"--\n"
5130
"\n"
5131
"Prepare the tty of which fd is a file descriptor for a new login session.\n"
5132
"\n"
5133
"Make the calling process a session leader; make the tty the\n"
5134
"controlling tty, the stdin, the stdout, and the stderr of the\n"
5135
"calling process; close fd.");
5136
5137
#define OS_LOGIN_TTY_METHODDEF    \
5138
    {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__},
5139
5140
static PyObject *
5141
os_login_tty_impl(PyObject *module, int fd);
5142
5143
static PyObject *
5144
os_login_tty(PyObject *module, PyObject *arg)
5145
0
{
5146
0
    PyObject *return_value = NULL;
5147
0
    int fd;
5148
5149
0
    fd = PyObject_AsFileDescriptor(arg);
5150
0
    if (fd < 0) {
5151
0
        goto exit;
5152
0
    }
5153
0
    return_value = os_login_tty_impl(module, fd);
5154
5155
0
exit:
5156
0
    return return_value;
5157
0
}
5158
5159
#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */
5160
5161
#if defined(HAVE_FORKPTY)
5162
5163
PyDoc_STRVAR(os_forkpty__doc__,
5164
"forkpty($module, /)\n"
5165
"--\n"
5166
"\n"
5167
"Fork a new process with a new pseudo-terminal as controlling tty.\n"
5168
"\n"
5169
"Returns a tuple of (pid, master_fd).\n"
5170
"Like fork(), return pid of 0 to the child process,\n"
5171
"and pid of child to the parent process.\n"
5172
"To both, return fd of newly opened pseudo-terminal.\n"
5173
"The master_fd is non-inheritable.");
5174
5175
#define OS_FORKPTY_METHODDEF    \
5176
    {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
5177
5178
static PyObject *
5179
os_forkpty_impl(PyObject *module);
5180
5181
static PyObject *
5182
os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
5183
0
{
5184
0
    return os_forkpty_impl(module);
5185
0
}
5186
5187
#endif /* defined(HAVE_FORKPTY) */
5188
5189
#if defined(HAVE_GETEGID)
5190
5191
PyDoc_STRVAR(os_getegid__doc__,
5192
"getegid($module, /)\n"
5193
"--\n"
5194
"\n"
5195
"Return the current process\'s effective group id.");
5196
5197
#define OS_GETEGID_METHODDEF    \
5198
    {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
5199
5200
static PyObject *
5201
os_getegid_impl(PyObject *module);
5202
5203
static PyObject *
5204
os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
5205
22
{
5206
22
    return os_getegid_impl(module);
5207
22
}
5208
5209
#endif /* defined(HAVE_GETEGID) */
5210
5211
#if defined(HAVE_GETEUID)
5212
5213
PyDoc_STRVAR(os_geteuid__doc__,
5214
"geteuid($module, /)\n"
5215
"--\n"
5216
"\n"
5217
"Return the current process\'s effective user id.");
5218
5219
#define OS_GETEUID_METHODDEF    \
5220
    {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
5221
5222
static PyObject *
5223
os_geteuid_impl(PyObject *module);
5224
5225
static PyObject *
5226
os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5227
22
{
5228
22
    return os_geteuid_impl(module);
5229
22
}
5230
5231
#endif /* defined(HAVE_GETEUID) */
5232
5233
#if defined(HAVE_GETGID)
5234
5235
PyDoc_STRVAR(os_getgid__doc__,
5236
"getgid($module, /)\n"
5237
"--\n"
5238
"\n"
5239
"Return the current process\'s group id.");
5240
5241
#define OS_GETGID_METHODDEF    \
5242
    {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
5243
5244
static PyObject *
5245
os_getgid_impl(PyObject *module);
5246
5247
static PyObject *
5248
os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
5249
22
{
5250
22
    return os_getgid_impl(module);
5251
22
}
5252
5253
#endif /* defined(HAVE_GETGID) */
5254
5255
#if defined(HAVE_GETPID)
5256
5257
PyDoc_STRVAR(os_getpid__doc__,
5258
"getpid($module, /)\n"
5259
"--\n"
5260
"\n"
5261
"Return the current process id.");
5262
5263
#define OS_GETPID_METHODDEF    \
5264
    {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
5265
5266
static PyObject *
5267
os_getpid_impl(PyObject *module);
5268
5269
static PyObject *
5270
os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
5271
0
{
5272
0
    return os_getpid_impl(module);
5273
0
}
5274
5275
#endif /* defined(HAVE_GETPID) */
5276
5277
#if defined(HAVE_GETGROUPLIST) && defined(__APPLE__)
5278
5279
PyDoc_STRVAR(os_getgrouplist__doc__,
5280
"getgrouplist($module, user, group, /)\n"
5281
"--\n"
5282
"\n"
5283
"Returns a list of groups to which a user belongs.\n"
5284
"\n"
5285
"  user\n"
5286
"    username to lookup\n"
5287
"  group\n"
5288
"    base group id of the user");
5289
5290
#define OS_GETGROUPLIST_METHODDEF    \
5291
    {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5292
5293
static PyObject *
5294
os_getgrouplist_impl(PyObject *module, const char *user, int basegid);
5295
5296
static PyObject *
5297
os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5298
{
5299
    PyObject *return_value = NULL;
5300
    const char *user;
5301
    int basegid;
5302
5303
    if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5304
        goto exit;
5305
    }
5306
    if (!PyUnicode_Check(args[0])) {
5307
        _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5308
        goto exit;
5309
    }
5310
    Py_ssize_t user_length;
5311
    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5312
    if (user == NULL) {
5313
        goto exit;
5314
    }
5315
    if (strlen(user) != (size_t)user_length) {
5316
        PyErr_SetString(PyExc_ValueError, "embedded null character");
5317
        goto exit;
5318
    }
5319
    basegid = PyLong_AsInt(args[1]);
5320
    if (basegid == -1 && PyErr_Occurred()) {
5321
        goto exit;
5322
    }
5323
    return_value = os_getgrouplist_impl(module, user, basegid);
5324
5325
exit:
5326
    return return_value;
5327
}
5328
5329
#endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */
5330
5331
#if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__)
5332
5333
PyDoc_STRVAR(os_getgrouplist__doc__,
5334
"getgrouplist($module, user, group, /)\n"
5335
"--\n"
5336
"\n"
5337
"Returns a list of groups to which a user belongs.\n"
5338
"\n"
5339
"  user\n"
5340
"    username to lookup\n"
5341
"  group\n"
5342
"    base group id of the user");
5343
5344
#define OS_GETGROUPLIST_METHODDEF    \
5345
    {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5346
5347
static PyObject *
5348
os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid);
5349
5350
static PyObject *
5351
os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5352
0
{
5353
0
    PyObject *return_value = NULL;
5354
0
    const char *user;
5355
0
    gid_t basegid;
5356
5357
0
    if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5358
0
        goto exit;
5359
0
    }
5360
0
    if (!PyUnicode_Check(args[0])) {
5361
0
        _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5362
0
        goto exit;
5363
0
    }
5364
0
    Py_ssize_t user_length;
5365
0
    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5366
0
    if (user == NULL) {
5367
0
        goto exit;
5368
0
    }
5369
0
    if (strlen(user) != (size_t)user_length) {
5370
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
5371
0
        goto exit;
5372
0
    }
5373
0
    if (!_Py_Gid_Converter(args[1], &basegid)) {
5374
0
        goto exit;
5375
0
    }
5376
0
    return_value = os_getgrouplist_impl(module, user, basegid);
5377
5378
0
exit:
5379
0
    return return_value;
5380
0
}
5381
5382
#endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */
5383
5384
#if defined(HAVE_GETGROUPS)
5385
5386
PyDoc_STRVAR(os_getgroups__doc__,
5387
"getgroups($module, /)\n"
5388
"--\n"
5389
"\n"
5390
"Return list of supplemental group IDs for the process.");
5391
5392
#define OS_GETGROUPS_METHODDEF    \
5393
    {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
5394
5395
static PyObject *
5396
os_getgroups_impl(PyObject *module);
5397
5398
static PyObject *
5399
os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
5400
0
{
5401
0
    return os_getgroups_impl(module);
5402
0
}
5403
5404
#endif /* defined(HAVE_GETGROUPS) */
5405
5406
#if defined(HAVE_INITGROUPS) && defined(__APPLE__)
5407
5408
PyDoc_STRVAR(os_initgroups__doc__,
5409
"initgroups($module, username, gid, /)\n"
5410
"--\n"
5411
"\n"
5412
"Initialize the group access list.\n"
5413
"\n"
5414
"Call the system initgroups() to initialize the group access list with all of\n"
5415
"the groups of which the specified username is a member, plus the specified\n"
5416
"group id.");
5417
5418
#define OS_INITGROUPS_METHODDEF    \
5419
    {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5420
5421
static PyObject *
5422
os_initgroups_impl(PyObject *module, PyObject *oname, int gid);
5423
5424
static PyObject *
5425
os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5426
{
5427
    PyObject *return_value = NULL;
5428
    PyObject *oname = NULL;
5429
    int gid;
5430
5431
    if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5432
        goto exit;
5433
    }
5434
    if (!PyUnicode_FSConverter(args[0], &oname)) {
5435
        goto exit;
5436
    }
5437
    gid = PyLong_AsInt(args[1]);
5438
    if (gid == -1 && PyErr_Occurred()) {
5439
        goto exit;
5440
    }
5441
    return_value = os_initgroups_impl(module, oname, gid);
5442
5443
exit:
5444
    /* Cleanup for oname */
5445
    Py_XDECREF(oname);
5446
5447
    return return_value;
5448
}
5449
5450
#endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */
5451
5452
#if defined(HAVE_INITGROUPS) && !defined(__APPLE__)
5453
5454
PyDoc_STRVAR(os_initgroups__doc__,
5455
"initgroups($module, username, gid, /)\n"
5456
"--\n"
5457
"\n"
5458
"Initialize the group access list.\n"
5459
"\n"
5460
"Call the system initgroups() to initialize the group access list with all of\n"
5461
"the groups of which the specified username is a member, plus the specified\n"
5462
"group id.");
5463
5464
#define OS_INITGROUPS_METHODDEF    \
5465
    {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5466
5467
static PyObject *
5468
os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid);
5469
5470
static PyObject *
5471
os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5472
0
{
5473
0
    PyObject *return_value = NULL;
5474
0
    PyObject *oname = NULL;
5475
0
    gid_t gid;
5476
5477
0
    if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5478
0
        goto exit;
5479
0
    }
5480
0
    if (!PyUnicode_FSConverter(args[0], &oname)) {
5481
0
        goto exit;
5482
0
    }
5483
0
    if (!_Py_Gid_Converter(args[1], &gid)) {
5484
0
        goto exit;
5485
0
    }
5486
0
    return_value = os_initgroups_impl(module, oname, gid);
5487
5488
0
exit:
5489
    /* Cleanup for oname */
5490
0
    Py_XDECREF(oname);
5491
5492
0
    return return_value;
5493
0
}
5494
5495
#endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */
5496
5497
#if defined(HAVE_GETPGID)
5498
5499
PyDoc_STRVAR(os_getpgid__doc__,
5500
"getpgid($module, /, pid)\n"
5501
"--\n"
5502
"\n"
5503
"Call the system call getpgid(), and return the result.");
5504
5505
#define OS_GETPGID_METHODDEF    \
5506
    {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
5507
5508
static PyObject *
5509
os_getpgid_impl(PyObject *module, pid_t pid);
5510
5511
static PyObject *
5512
os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5513
0
{
5514
0
    PyObject *return_value = NULL;
5515
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5516
5517
0
    #define NUM_KEYWORDS 1
5518
0
    static struct {
5519
0
        PyGC_Head _this_is_not_used;
5520
0
        PyObject_VAR_HEAD
5521
0
        Py_hash_t ob_hash;
5522
0
        PyObject *ob_item[NUM_KEYWORDS];
5523
0
    } _kwtuple = {
5524
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5525
0
        .ob_hash = -1,
5526
0
        .ob_item = { &_Py_ID(pid), },
5527
0
    };
5528
0
    #undef NUM_KEYWORDS
5529
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5530
5531
    #else  // !Py_BUILD_CORE
5532
    #  define KWTUPLE NULL
5533
    #endif  // !Py_BUILD_CORE
5534
5535
0
    static const char * const _keywords[] = {"pid", NULL};
5536
0
    static _PyArg_Parser _parser = {
5537
0
        .keywords = _keywords,
5538
0
        .fname = "getpgid",
5539
0
        .kwtuple = KWTUPLE,
5540
0
    };
5541
0
    #undef KWTUPLE
5542
0
    PyObject *argsbuf[1];
5543
0
    pid_t pid;
5544
5545
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
5546
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
5547
0
    if (!args) {
5548
0
        goto exit;
5549
0
    }
5550
0
    pid = PyLong_AsPid(args[0]);
5551
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5552
0
        goto exit;
5553
0
    }
5554
0
    return_value = os_getpgid_impl(module, pid);
5555
5556
0
exit:
5557
0
    return return_value;
5558
0
}
5559
5560
#endif /* defined(HAVE_GETPGID) */
5561
5562
#if defined(HAVE_GETPGRP)
5563
5564
PyDoc_STRVAR(os_getpgrp__doc__,
5565
"getpgrp($module, /)\n"
5566
"--\n"
5567
"\n"
5568
"Return the current process group id.");
5569
5570
#define OS_GETPGRP_METHODDEF    \
5571
    {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
5572
5573
static PyObject *
5574
os_getpgrp_impl(PyObject *module);
5575
5576
static PyObject *
5577
os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5578
0
{
5579
0
    return os_getpgrp_impl(module);
5580
0
}
5581
5582
#endif /* defined(HAVE_GETPGRP) */
5583
5584
#if defined(HAVE_SETPGRP)
5585
5586
PyDoc_STRVAR(os_setpgrp__doc__,
5587
"setpgrp($module, /)\n"
5588
"--\n"
5589
"\n"
5590
"Make the current process the leader of its process group.");
5591
5592
#define OS_SETPGRP_METHODDEF    \
5593
    {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
5594
5595
static PyObject *
5596
os_setpgrp_impl(PyObject *module);
5597
5598
static PyObject *
5599
os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5600
0
{
5601
0
    return os_setpgrp_impl(module);
5602
0
}
5603
5604
#endif /* defined(HAVE_SETPGRP) */
5605
5606
#if defined(HAVE_GETPPID)
5607
5608
PyDoc_STRVAR(os_getppid__doc__,
5609
"getppid($module, /)\n"
5610
"--\n"
5611
"\n"
5612
"Return the parent\'s process id.\n"
5613
"\n"
5614
"If the parent process has already exited, Windows machines will still\n"
5615
"return its id; others systems will return the id of the \'init\' process (1).");
5616
5617
#define OS_GETPPID_METHODDEF    \
5618
    {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
5619
5620
static PyObject *
5621
os_getppid_impl(PyObject *module);
5622
5623
static PyObject *
5624
os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
5625
0
{
5626
0
    return os_getppid_impl(module);
5627
0
}
5628
5629
#endif /* defined(HAVE_GETPPID) */
5630
5631
#if defined(HAVE_GETLOGIN)
5632
5633
PyDoc_STRVAR(os_getlogin__doc__,
5634
"getlogin($module, /)\n"
5635
"--\n"
5636
"\n"
5637
"Return the actual login name.");
5638
5639
#define OS_GETLOGIN_METHODDEF    \
5640
    {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
5641
5642
static PyObject *
5643
os_getlogin_impl(PyObject *module);
5644
5645
static PyObject *
5646
os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
5647
0
{
5648
0
    return os_getlogin_impl(module);
5649
0
}
5650
5651
#endif /* defined(HAVE_GETLOGIN) */
5652
5653
#if defined(HAVE_GETUID)
5654
5655
PyDoc_STRVAR(os_getuid__doc__,
5656
"getuid($module, /)\n"
5657
"--\n"
5658
"\n"
5659
"Return the current process\'s user id.");
5660
5661
#define OS_GETUID_METHODDEF    \
5662
    {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
5663
5664
static PyObject *
5665
os_getuid_impl(PyObject *module);
5666
5667
static PyObject *
5668
os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5669
22
{
5670
22
    return os_getuid_impl(module);
5671
22
}
5672
5673
#endif /* defined(HAVE_GETUID) */
5674
5675
#if defined(HAVE_KILL)
5676
5677
PyDoc_STRVAR(os_kill__doc__,
5678
"kill($module, pid, signal, /)\n"
5679
"--\n"
5680
"\n"
5681
"Kill a process with a signal.");
5682
5683
#define OS_KILL_METHODDEF    \
5684
    {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__},
5685
5686
static PyObject *
5687
os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
5688
5689
static PyObject *
5690
os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5691
0
{
5692
0
    PyObject *return_value = NULL;
5693
0
    pid_t pid;
5694
0
    Py_ssize_t signal;
5695
5696
0
    if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) {
5697
0
        goto exit;
5698
0
    }
5699
0
    pid = PyLong_AsPid(args[0]);
5700
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5701
0
        goto exit;
5702
0
    }
5703
0
    {
5704
0
        Py_ssize_t ival = -1;
5705
0
        PyObject *iobj = _PyNumber_Index(args[1]);
5706
0
        if (iobj != NULL) {
5707
0
            ival = PyLong_AsSsize_t(iobj);
5708
0
            Py_DECREF(iobj);
5709
0
        }
5710
0
        if (ival == -1 && PyErr_Occurred()) {
5711
0
            goto exit;
5712
0
        }
5713
0
        signal = ival;
5714
0
    }
5715
0
    return_value = os_kill_impl(module, pid, signal);
5716
5717
0
exit:
5718
0
    return return_value;
5719
0
}
5720
5721
#endif /* defined(HAVE_KILL) */
5722
5723
#if defined(HAVE_KILLPG)
5724
5725
PyDoc_STRVAR(os_killpg__doc__,
5726
"killpg($module, pgid, signal, /)\n"
5727
"--\n"
5728
"\n"
5729
"Kill a process group with a signal.");
5730
5731
#define OS_KILLPG_METHODDEF    \
5732
    {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__},
5733
5734
static PyObject *
5735
os_killpg_impl(PyObject *module, pid_t pgid, int signal);
5736
5737
static PyObject *
5738
os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5739
0
{
5740
0
    PyObject *return_value = NULL;
5741
0
    pid_t pgid;
5742
0
    int signal;
5743
5744
0
    if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) {
5745
0
        goto exit;
5746
0
    }
5747
0
    pgid = PyLong_AsPid(args[0]);
5748
0
    if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
5749
0
        goto exit;
5750
0
    }
5751
0
    signal = PyLong_AsInt(args[1]);
5752
0
    if (signal == -1 && PyErr_Occurred()) {
5753
0
        goto exit;
5754
0
    }
5755
0
    return_value = os_killpg_impl(module, pgid, signal);
5756
5757
0
exit:
5758
0
    return return_value;
5759
0
}
5760
5761
#endif /* defined(HAVE_KILLPG) */
5762
5763
#if defined(HAVE_PLOCK)
5764
5765
PyDoc_STRVAR(os_plock__doc__,
5766
"plock($module, op, /)\n"
5767
"--\n"
5768
"\n"
5769
"Lock program segments into memory.\");");
5770
5771
#define OS_PLOCK_METHODDEF    \
5772
    {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
5773
5774
static PyObject *
5775
os_plock_impl(PyObject *module, int op);
5776
5777
static PyObject *
5778
os_plock(PyObject *module, PyObject *arg)
5779
{
5780
    PyObject *return_value = NULL;
5781
    int op;
5782
5783
    op = PyLong_AsInt(arg);
5784
    if (op == -1 && PyErr_Occurred()) {
5785
        goto exit;
5786
    }
5787
    return_value = os_plock_impl(module, op);
5788
5789
exit:
5790
    return return_value;
5791
}
5792
5793
#endif /* defined(HAVE_PLOCK) */
5794
5795
#if defined(HAVE_SETUID)
5796
5797
PyDoc_STRVAR(os_setuid__doc__,
5798
"setuid($module, uid, /)\n"
5799
"--\n"
5800
"\n"
5801
"Set the current process\'s user id.");
5802
5803
#define OS_SETUID_METHODDEF    \
5804
    {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
5805
5806
static PyObject *
5807
os_setuid_impl(PyObject *module, uid_t uid);
5808
5809
static PyObject *
5810
os_setuid(PyObject *module, PyObject *arg)
5811
0
{
5812
0
    PyObject *return_value = NULL;
5813
0
    uid_t uid;
5814
5815
0
    if (!_Py_Uid_Converter(arg, &uid)) {
5816
0
        goto exit;
5817
0
    }
5818
0
    return_value = os_setuid_impl(module, uid);
5819
5820
0
exit:
5821
0
    return return_value;
5822
0
}
5823
5824
#endif /* defined(HAVE_SETUID) */
5825
5826
#if defined(HAVE_SETEUID)
5827
5828
PyDoc_STRVAR(os_seteuid__doc__,
5829
"seteuid($module, euid, /)\n"
5830
"--\n"
5831
"\n"
5832
"Set the current process\'s effective user id.");
5833
5834
#define OS_SETEUID_METHODDEF    \
5835
    {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
5836
5837
static PyObject *
5838
os_seteuid_impl(PyObject *module, uid_t euid);
5839
5840
static PyObject *
5841
os_seteuid(PyObject *module, PyObject *arg)
5842
0
{
5843
0
    PyObject *return_value = NULL;
5844
0
    uid_t euid;
5845
5846
0
    if (!_Py_Uid_Converter(arg, &euid)) {
5847
0
        goto exit;
5848
0
    }
5849
0
    return_value = os_seteuid_impl(module, euid);
5850
5851
0
exit:
5852
0
    return return_value;
5853
0
}
5854
5855
#endif /* defined(HAVE_SETEUID) */
5856
5857
#if defined(HAVE_SETEGID)
5858
5859
PyDoc_STRVAR(os_setegid__doc__,
5860
"setegid($module, egid, /)\n"
5861
"--\n"
5862
"\n"
5863
"Set the current process\'s effective group id.");
5864
5865
#define OS_SETEGID_METHODDEF    \
5866
    {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
5867
5868
static PyObject *
5869
os_setegid_impl(PyObject *module, gid_t egid);
5870
5871
static PyObject *
5872
os_setegid(PyObject *module, PyObject *arg)
5873
0
{
5874
0
    PyObject *return_value = NULL;
5875
0
    gid_t egid;
5876
5877
0
    if (!_Py_Gid_Converter(arg, &egid)) {
5878
0
        goto exit;
5879
0
    }
5880
0
    return_value = os_setegid_impl(module, egid);
5881
5882
0
exit:
5883
0
    return return_value;
5884
0
}
5885
5886
#endif /* defined(HAVE_SETEGID) */
5887
5888
#if defined(HAVE_SETREUID)
5889
5890
PyDoc_STRVAR(os_setreuid__doc__,
5891
"setreuid($module, ruid, euid, /)\n"
5892
"--\n"
5893
"\n"
5894
"Set the current process\'s real and effective user ids.");
5895
5896
#define OS_SETREUID_METHODDEF    \
5897
    {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__},
5898
5899
static PyObject *
5900
os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
5901
5902
static PyObject *
5903
os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5904
0
{
5905
0
    PyObject *return_value = NULL;
5906
0
    uid_t ruid;
5907
0
    uid_t euid;
5908
5909
0
    if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
5910
0
        goto exit;
5911
0
    }
5912
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
5913
0
        goto exit;
5914
0
    }
5915
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
5916
0
        goto exit;
5917
0
    }
5918
0
    return_value = os_setreuid_impl(module, ruid, euid);
5919
5920
0
exit:
5921
0
    return return_value;
5922
0
}
5923
5924
#endif /* defined(HAVE_SETREUID) */
5925
5926
#if defined(HAVE_SETREGID)
5927
5928
PyDoc_STRVAR(os_setregid__doc__,
5929
"setregid($module, rgid, egid, /)\n"
5930
"--\n"
5931
"\n"
5932
"Set the current process\'s real and effective group ids.");
5933
5934
#define OS_SETREGID_METHODDEF    \
5935
    {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__},
5936
5937
static PyObject *
5938
os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
5939
5940
static PyObject *
5941
os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5942
0
{
5943
0
    PyObject *return_value = NULL;
5944
0
    gid_t rgid;
5945
0
    gid_t egid;
5946
5947
0
    if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
5948
0
        goto exit;
5949
0
    }
5950
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
5951
0
        goto exit;
5952
0
    }
5953
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
5954
0
        goto exit;
5955
0
    }
5956
0
    return_value = os_setregid_impl(module, rgid, egid);
5957
5958
0
exit:
5959
0
    return return_value;
5960
0
}
5961
5962
#endif /* defined(HAVE_SETREGID) */
5963
5964
#if defined(HAVE_SETGID)
5965
5966
PyDoc_STRVAR(os_setgid__doc__,
5967
"setgid($module, gid, /)\n"
5968
"--\n"
5969
"\n"
5970
"Set the current process\'s group id.");
5971
5972
#define OS_SETGID_METHODDEF    \
5973
    {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
5974
5975
static PyObject *
5976
os_setgid_impl(PyObject *module, gid_t gid);
5977
5978
static PyObject *
5979
os_setgid(PyObject *module, PyObject *arg)
5980
0
{
5981
0
    PyObject *return_value = NULL;
5982
0
    gid_t gid;
5983
5984
0
    if (!_Py_Gid_Converter(arg, &gid)) {
5985
0
        goto exit;
5986
0
    }
5987
0
    return_value = os_setgid_impl(module, gid);
5988
5989
0
exit:
5990
0
    return return_value;
5991
0
}
5992
5993
#endif /* defined(HAVE_SETGID) */
5994
5995
#if defined(HAVE_SETGROUPS)
5996
5997
PyDoc_STRVAR(os_setgroups__doc__,
5998
"setgroups($module, groups, /)\n"
5999
"--\n"
6000
"\n"
6001
"Set the groups of the current process to list.");
6002
6003
#define OS_SETGROUPS_METHODDEF    \
6004
    {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
6005
6006
#endif /* defined(HAVE_SETGROUPS) */
6007
6008
#if defined(HAVE_WAIT3)
6009
6010
PyDoc_STRVAR(os_wait3__doc__,
6011
"wait3($module, /, options)\n"
6012
"--\n"
6013
"\n"
6014
"Wait for completion of a child process.\n"
6015
"\n"
6016
"Returns a tuple of information about the child process:\n"
6017
"  (pid, status, rusage)");
6018
6019
#define OS_WAIT3_METHODDEF    \
6020
    {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
6021
6022
static PyObject *
6023
os_wait3_impl(PyObject *module, int options);
6024
6025
static PyObject *
6026
os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6027
0
{
6028
0
    PyObject *return_value = NULL;
6029
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6030
6031
0
    #define NUM_KEYWORDS 1
6032
0
    static struct {
6033
0
        PyGC_Head _this_is_not_used;
6034
0
        PyObject_VAR_HEAD
6035
0
        Py_hash_t ob_hash;
6036
0
        PyObject *ob_item[NUM_KEYWORDS];
6037
0
    } _kwtuple = {
6038
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6039
0
        .ob_hash = -1,
6040
0
        .ob_item = { &_Py_ID(options), },
6041
0
    };
6042
0
    #undef NUM_KEYWORDS
6043
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6044
6045
    #else  // !Py_BUILD_CORE
6046
    #  define KWTUPLE NULL
6047
    #endif  // !Py_BUILD_CORE
6048
6049
0
    static const char * const _keywords[] = {"options", NULL};
6050
0
    static _PyArg_Parser _parser = {
6051
0
        .keywords = _keywords,
6052
0
        .fname = "wait3",
6053
0
        .kwtuple = KWTUPLE,
6054
0
    };
6055
0
    #undef KWTUPLE
6056
0
    PyObject *argsbuf[1];
6057
0
    int options;
6058
6059
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6060
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6061
0
    if (!args) {
6062
0
        goto exit;
6063
0
    }
6064
0
    options = PyLong_AsInt(args[0]);
6065
0
    if (options == -1 && PyErr_Occurred()) {
6066
0
        goto exit;
6067
0
    }
6068
0
    return_value = os_wait3_impl(module, options);
6069
6070
0
exit:
6071
0
    return return_value;
6072
0
}
6073
6074
#endif /* defined(HAVE_WAIT3) */
6075
6076
#if defined(HAVE_WAIT4)
6077
6078
PyDoc_STRVAR(os_wait4__doc__,
6079
"wait4($module, /, pid, options)\n"
6080
"--\n"
6081
"\n"
6082
"Wait for completion of a specific child process.\n"
6083
"\n"
6084
"Returns a tuple of information about the child process:\n"
6085
"  (pid, status, rusage)");
6086
6087
#define OS_WAIT4_METHODDEF    \
6088
    {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
6089
6090
static PyObject *
6091
os_wait4_impl(PyObject *module, pid_t pid, int options);
6092
6093
static PyObject *
6094
os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6095
0
{
6096
0
    PyObject *return_value = NULL;
6097
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6098
6099
0
    #define NUM_KEYWORDS 2
6100
0
    static struct {
6101
0
        PyGC_Head _this_is_not_used;
6102
0
        PyObject_VAR_HEAD
6103
0
        Py_hash_t ob_hash;
6104
0
        PyObject *ob_item[NUM_KEYWORDS];
6105
0
    } _kwtuple = {
6106
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6107
0
        .ob_hash = -1,
6108
0
        .ob_item = { &_Py_ID(pid), &_Py_ID(options), },
6109
0
    };
6110
0
    #undef NUM_KEYWORDS
6111
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6112
6113
    #else  // !Py_BUILD_CORE
6114
    #  define KWTUPLE NULL
6115
    #endif  // !Py_BUILD_CORE
6116
6117
0
    static const char * const _keywords[] = {"pid", "options", NULL};
6118
0
    static _PyArg_Parser _parser = {
6119
0
        .keywords = _keywords,
6120
0
        .fname = "wait4",
6121
0
        .kwtuple = KWTUPLE,
6122
0
    };
6123
0
    #undef KWTUPLE
6124
0
    PyObject *argsbuf[2];
6125
0
    pid_t pid;
6126
0
    int options;
6127
6128
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6129
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6130
0
    if (!args) {
6131
0
        goto exit;
6132
0
    }
6133
0
    pid = PyLong_AsPid(args[0]);
6134
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6135
0
        goto exit;
6136
0
    }
6137
0
    options = PyLong_AsInt(args[1]);
6138
0
    if (options == -1 && PyErr_Occurred()) {
6139
0
        goto exit;
6140
0
    }
6141
0
    return_value = os_wait4_impl(module, pid, options);
6142
6143
0
exit:
6144
0
    return return_value;
6145
0
}
6146
6147
#endif /* defined(HAVE_WAIT4) */
6148
6149
#if defined(HAVE_WAITID)
6150
6151
PyDoc_STRVAR(os_waitid__doc__,
6152
"waitid($module, idtype, id, options, /)\n"
6153
"--\n"
6154
"\n"
6155
"Returns the result of waiting for a process or processes.\n"
6156
"\n"
6157
"  idtype\n"
6158
"    Must be one of be P_PID, P_PGID or P_ALL.\n"
6159
"  id\n"
6160
"    The id to wait on.\n"
6161
"  options\n"
6162
"    Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
6163
"    or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
6164
"\n"
6165
"Returns either waitid_result or None if WNOHANG is specified and there are\n"
6166
"no children in a waitable state.");
6167
6168
#define OS_WAITID_METHODDEF    \
6169
    {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__},
6170
6171
static PyObject *
6172
os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
6173
6174
static PyObject *
6175
os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6176
0
{
6177
0
    PyObject *return_value = NULL;
6178
0
    idtype_t idtype;
6179
0
    id_t id;
6180
0
    int options;
6181
6182
0
    if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) {
6183
0
        goto exit;
6184
0
    }
6185
0
    if (!idtype_t_converter(args[0], &idtype)) {
6186
0
        goto exit;
6187
0
    }
6188
0
    id = (id_t)PyLong_AsPid(args[1]);
6189
0
    if (id == (id_t)(-1) && PyErr_Occurred()) {
6190
0
        goto exit;
6191
0
    }
6192
0
    options = PyLong_AsInt(args[2]);
6193
0
    if (options == -1 && PyErr_Occurred()) {
6194
0
        goto exit;
6195
0
    }
6196
0
    return_value = os_waitid_impl(module, idtype, id, options);
6197
6198
0
exit:
6199
0
    return return_value;
6200
0
}
6201
6202
#endif /* defined(HAVE_WAITID) */
6203
6204
#if defined(HAVE_WAITPID)
6205
6206
PyDoc_STRVAR(os_waitpid__doc__,
6207
"waitpid($module, pid, options, /)\n"
6208
"--\n"
6209
"\n"
6210
"Wait for completion of a given child process.\n"
6211
"\n"
6212
"Returns a tuple of information regarding the child process:\n"
6213
"    (pid, status)\n"
6214
"\n"
6215
"The options argument is ignored on Windows.");
6216
6217
#define OS_WAITPID_METHODDEF    \
6218
    {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6219
6220
static PyObject *
6221
os_waitpid_impl(PyObject *module, pid_t pid, int options);
6222
6223
static PyObject *
6224
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6225
0
{
6226
0
    PyObject *return_value = NULL;
6227
0
    pid_t pid;
6228
0
    int options;
6229
6230
0
    if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6231
0
        goto exit;
6232
0
    }
6233
0
    pid = PyLong_AsPid(args[0]);
6234
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6235
0
        goto exit;
6236
0
    }
6237
0
    options = PyLong_AsInt(args[1]);
6238
0
    if (options == -1 && PyErr_Occurred()) {
6239
0
        goto exit;
6240
0
    }
6241
0
    return_value = os_waitpid_impl(module, pid, options);
6242
6243
0
exit:
6244
0
    return return_value;
6245
0
}
6246
6247
#endif /* defined(HAVE_WAITPID) */
6248
6249
#if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT)
6250
6251
PyDoc_STRVAR(os_waitpid__doc__,
6252
"waitpid($module, pid, options, /)\n"
6253
"--\n"
6254
"\n"
6255
"Wait for completion of a given process.\n"
6256
"\n"
6257
"Returns a tuple of information regarding the process:\n"
6258
"    (pid, status << 8)\n"
6259
"\n"
6260
"The options argument is ignored on Windows.");
6261
6262
#define OS_WAITPID_METHODDEF    \
6263
    {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6264
6265
static PyObject *
6266
os_waitpid_impl(PyObject *module, intptr_t pid, int options);
6267
6268
static PyObject *
6269
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6270
{
6271
    PyObject *return_value = NULL;
6272
    intptr_t pid;
6273
    int options;
6274
6275
    if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6276
        goto exit;
6277
    }
6278
    pid = (intptr_t)PyLong_AsVoidPtr(args[0]);
6279
    if (!pid && PyErr_Occurred()) {
6280
        goto exit;
6281
    }
6282
    options = PyLong_AsInt(args[1]);
6283
    if (options == -1 && PyErr_Occurred()) {
6284
        goto exit;
6285
    }
6286
    return_value = os_waitpid_impl(module, pid, options);
6287
6288
exit:
6289
    return return_value;
6290
}
6291
6292
#endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */
6293
6294
#if defined(HAVE_WAIT)
6295
6296
PyDoc_STRVAR(os_wait__doc__,
6297
"wait($module, /)\n"
6298
"--\n"
6299
"\n"
6300
"Wait for completion of a child process.\n"
6301
"\n"
6302
"Returns a tuple of information about the child process:\n"
6303
"    (pid, status)");
6304
6305
#define OS_WAIT_METHODDEF    \
6306
    {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
6307
6308
static PyObject *
6309
os_wait_impl(PyObject *module);
6310
6311
static PyObject *
6312
os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
6313
0
{
6314
0
    return os_wait_impl(module);
6315
0
}
6316
6317
#endif /* defined(HAVE_WAIT) */
6318
6319
#if (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))
6320
6321
PyDoc_STRVAR(os_pidfd_open__doc__,
6322
"pidfd_open($module, /, pid, flags=0)\n"
6323
"--\n"
6324
"\n"
6325
"Return a file descriptor referring to the process *pid*.\n"
6326
"\n"
6327
"The descriptor can be used to perform process management without races and\n"
6328
"signals.");
6329
6330
#define OS_PIDFD_OPEN_METHODDEF    \
6331
    {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__},
6332
6333
static PyObject *
6334
os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags);
6335
6336
static PyObject *
6337
os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6338
0
{
6339
0
    PyObject *return_value = NULL;
6340
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6341
6342
0
    #define NUM_KEYWORDS 2
6343
0
    static struct {
6344
0
        PyGC_Head _this_is_not_used;
6345
0
        PyObject_VAR_HEAD
6346
0
        Py_hash_t ob_hash;
6347
0
        PyObject *ob_item[NUM_KEYWORDS];
6348
0
    } _kwtuple = {
6349
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6350
0
        .ob_hash = -1,
6351
0
        .ob_item = { &_Py_ID(pid), &_Py_ID(flags), },
6352
0
    };
6353
0
    #undef NUM_KEYWORDS
6354
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6355
6356
    #else  // !Py_BUILD_CORE
6357
    #  define KWTUPLE NULL
6358
    #endif  // !Py_BUILD_CORE
6359
6360
0
    static const char * const _keywords[] = {"pid", "flags", NULL};
6361
0
    static _PyArg_Parser _parser = {
6362
0
        .keywords = _keywords,
6363
0
        .fname = "pidfd_open",
6364
0
        .kwtuple = KWTUPLE,
6365
0
    };
6366
0
    #undef KWTUPLE
6367
0
    PyObject *argsbuf[2];
6368
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6369
0
    pid_t pid;
6370
0
    unsigned int flags = 0;
6371
6372
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6373
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6374
0
    if (!args) {
6375
0
        goto exit;
6376
0
    }
6377
0
    pid = PyLong_AsPid(args[0]);
6378
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6379
0
        goto exit;
6380
0
    }
6381
0
    if (!noptargs) {
6382
0
        goto skip_optional_pos;
6383
0
    }
6384
0
    if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) {
6385
0
        goto exit;
6386
0
    }
6387
0
skip_optional_pos:
6388
0
    return_value = os_pidfd_open_impl(module, pid, flags);
6389
6390
0
exit:
6391
0
    return return_value;
6392
0
}
6393
6394
#endif /* (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */
6395
6396
#if defined(HAVE_SETNS)
6397
6398
PyDoc_STRVAR(os_setns__doc__,
6399
"setns($module, /, fd, nstype=0)\n"
6400
"--\n"
6401
"\n"
6402
"Move the calling thread into different namespaces.\n"
6403
"\n"
6404
"  fd\n"
6405
"    A file descriptor to a namespace.\n"
6406
"  nstype\n"
6407
"    Type of namespace.");
6408
6409
#define OS_SETNS_METHODDEF    \
6410
    {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__},
6411
6412
static PyObject *
6413
os_setns_impl(PyObject *module, int fd, int nstype);
6414
6415
static PyObject *
6416
os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6417
0
{
6418
0
    PyObject *return_value = NULL;
6419
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6420
6421
0
    #define NUM_KEYWORDS 2
6422
0
    static struct {
6423
0
        PyGC_Head _this_is_not_used;
6424
0
        PyObject_VAR_HEAD
6425
0
        Py_hash_t ob_hash;
6426
0
        PyObject *ob_item[NUM_KEYWORDS];
6427
0
    } _kwtuple = {
6428
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6429
0
        .ob_hash = -1,
6430
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), },
6431
0
    };
6432
0
    #undef NUM_KEYWORDS
6433
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6434
6435
    #else  // !Py_BUILD_CORE
6436
    #  define KWTUPLE NULL
6437
    #endif  // !Py_BUILD_CORE
6438
6439
0
    static const char * const _keywords[] = {"fd", "nstype", NULL};
6440
0
    static _PyArg_Parser _parser = {
6441
0
        .keywords = _keywords,
6442
0
        .fname = "setns",
6443
0
        .kwtuple = KWTUPLE,
6444
0
    };
6445
0
    #undef KWTUPLE
6446
0
    PyObject *argsbuf[2];
6447
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6448
0
    int fd;
6449
0
    int nstype = 0;
6450
6451
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6452
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6453
0
    if (!args) {
6454
0
        goto exit;
6455
0
    }
6456
0
    fd = PyObject_AsFileDescriptor(args[0]);
6457
0
    if (fd < 0) {
6458
0
        goto exit;
6459
0
    }
6460
0
    if (!noptargs) {
6461
0
        goto skip_optional_pos;
6462
0
    }
6463
0
    nstype = PyLong_AsInt(args[1]);
6464
0
    if (nstype == -1 && PyErr_Occurred()) {
6465
0
        goto exit;
6466
0
    }
6467
0
skip_optional_pos:
6468
0
    return_value = os_setns_impl(module, fd, nstype);
6469
6470
0
exit:
6471
0
    return return_value;
6472
0
}
6473
6474
#endif /* defined(HAVE_SETNS) */
6475
6476
#if defined(HAVE_UNSHARE)
6477
6478
PyDoc_STRVAR(os_unshare__doc__,
6479
"unshare($module, /, flags)\n"
6480
"--\n"
6481
"\n"
6482
"Disassociate parts of a process (or thread) execution context.\n"
6483
"\n"
6484
"  flags\n"
6485
"    Namespaces to be unshared.");
6486
6487
#define OS_UNSHARE_METHODDEF    \
6488
    {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__},
6489
6490
static PyObject *
6491
os_unshare_impl(PyObject *module, int flags);
6492
6493
static PyObject *
6494
os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6495
0
{
6496
0
    PyObject *return_value = NULL;
6497
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6498
6499
0
    #define NUM_KEYWORDS 1
6500
0
    static struct {
6501
0
        PyGC_Head _this_is_not_used;
6502
0
        PyObject_VAR_HEAD
6503
0
        Py_hash_t ob_hash;
6504
0
        PyObject *ob_item[NUM_KEYWORDS];
6505
0
    } _kwtuple = {
6506
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6507
0
        .ob_hash = -1,
6508
0
        .ob_item = { &_Py_ID(flags), },
6509
0
    };
6510
0
    #undef NUM_KEYWORDS
6511
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6512
6513
    #else  // !Py_BUILD_CORE
6514
    #  define KWTUPLE NULL
6515
    #endif  // !Py_BUILD_CORE
6516
6517
0
    static const char * const _keywords[] = {"flags", NULL};
6518
0
    static _PyArg_Parser _parser = {
6519
0
        .keywords = _keywords,
6520
0
        .fname = "unshare",
6521
0
        .kwtuple = KWTUPLE,
6522
0
    };
6523
0
    #undef KWTUPLE
6524
0
    PyObject *argsbuf[1];
6525
0
    int flags;
6526
6527
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6528
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6529
0
    if (!args) {
6530
0
        goto exit;
6531
0
    }
6532
0
    flags = PyLong_AsInt(args[0]);
6533
0
    if (flags == -1 && PyErr_Occurred()) {
6534
0
        goto exit;
6535
0
    }
6536
0
    return_value = os_unshare_impl(module, flags);
6537
6538
0
exit:
6539
0
    return return_value;
6540
0
}
6541
6542
#endif /* defined(HAVE_UNSHARE) */
6543
6544
#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
6545
6546
PyDoc_STRVAR(os_readlink__doc__,
6547
"readlink($module, /, path, *, dir_fd=None)\n"
6548
"--\n"
6549
"\n"
6550
"Return a string representing the path to which the symbolic link points.\n"
6551
"\n"
6552
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
6553
"and path should be relative; path will then be relative to that directory.\n"
6554
"\n"
6555
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
6556
"using it will raise a NotImplementedError.");
6557
6558
#define OS_READLINK_METHODDEF    \
6559
    {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
6560
6561
static PyObject *
6562
os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
6563
6564
static PyObject *
6565
os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6566
0
{
6567
0
    PyObject *return_value = NULL;
6568
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6569
6570
0
    #define NUM_KEYWORDS 2
6571
0
    static struct {
6572
0
        PyGC_Head _this_is_not_used;
6573
0
        PyObject_VAR_HEAD
6574
0
        Py_hash_t ob_hash;
6575
0
        PyObject *ob_item[NUM_KEYWORDS];
6576
0
    } _kwtuple = {
6577
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6578
0
        .ob_hash = -1,
6579
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
6580
0
    };
6581
0
    #undef NUM_KEYWORDS
6582
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6583
6584
    #else  // !Py_BUILD_CORE
6585
    #  define KWTUPLE NULL
6586
    #endif  // !Py_BUILD_CORE
6587
6588
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
6589
0
    static _PyArg_Parser _parser = {
6590
0
        .keywords = _keywords,
6591
0
        .fname = "readlink",
6592
0
        .kwtuple = KWTUPLE,
6593
0
    };
6594
0
    #undef KWTUPLE
6595
0
    PyObject *argsbuf[2];
6596
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6597
0
    path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0);
6598
0
    int dir_fd = DEFAULT_DIR_FD;
6599
6600
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6601
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6602
0
    if (!args) {
6603
0
        goto exit;
6604
0
    }
6605
0
    if (!path_converter(args[0], &path)) {
6606
0
        goto exit;
6607
0
    }
6608
0
    if (!noptargs) {
6609
0
        goto skip_optional_kwonly;
6610
0
    }
6611
0
    if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
6612
0
        goto exit;
6613
0
    }
6614
0
skip_optional_kwonly:
6615
0
    return_value = os_readlink_impl(module, &path, dir_fd);
6616
6617
0
exit:
6618
    /* Cleanup for path */
6619
0
    path_cleanup(&path);
6620
6621
0
    return return_value;
6622
0
}
6623
6624
#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
6625
6626
#if defined(HAVE_SYMLINK)
6627
6628
PyDoc_STRVAR(os_symlink__doc__,
6629
"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
6630
"--\n"
6631
"\n"
6632
"Create a symbolic link pointing to src named dst.\n"
6633
"\n"
6634
"target_is_directory is required on Windows if the target is to be\n"
6635
"  interpreted as a directory.  (On Windows, symlink requires\n"
6636
"  Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
6637
"  target_is_directory is ignored on non-Windows platforms.\n"
6638
"\n"
6639
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
6640
"  and path should be relative; path will then be relative to that directory.\n"
6641
"dir_fd may not be implemented on your platform.\n"
6642
"  If it is unavailable, using it will raise a NotImplementedError.");
6643
6644
#define OS_SYMLINK_METHODDEF    \
6645
    {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
6646
6647
static PyObject *
6648
os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
6649
                int target_is_directory, int dir_fd);
6650
6651
static PyObject *
6652
os_symlink(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 4
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(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), },
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[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
6676
0
    static _PyArg_Parser _parser = {
6677
0
        .keywords = _keywords,
6678
0
        .fname = "symlink",
6679
0
        .kwtuple = KWTUPLE,
6680
0
    };
6681
0
    #undef KWTUPLE
6682
0
    PyObject *argsbuf[4];
6683
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
6684
0
    path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0);
6685
0
    path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0);
6686
0
    int target_is_directory = 0;
6687
0
    int dir_fd = DEFAULT_DIR_FD;
6688
6689
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6690
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6691
0
    if (!args) {
6692
0
        goto exit;
6693
0
    }
6694
0
    if (!path_converter(args[0], &src)) {
6695
0
        goto exit;
6696
0
    }
6697
0
    if (!path_converter(args[1], &dst)) {
6698
0
        goto exit;
6699
0
    }
6700
0
    if (!noptargs) {
6701
0
        goto skip_optional_pos;
6702
0
    }
6703
0
    if (args[2]) {
6704
0
        target_is_directory = PyObject_IsTrue(args[2]);
6705
0
        if (target_is_directory < 0) {
6706
0
            goto exit;
6707
0
        }
6708
0
        if (!--noptargs) {
6709
0
            goto skip_optional_pos;
6710
0
        }
6711
0
    }
6712
0
skip_optional_pos:
6713
0
    if (!noptargs) {
6714
0
        goto skip_optional_kwonly;
6715
0
    }
6716
0
    if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
6717
0
        goto exit;
6718
0
    }
6719
0
skip_optional_kwonly:
6720
0
    return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
6721
6722
0
exit:
6723
    /* Cleanup for src */
6724
0
    path_cleanup(&src);
6725
    /* Cleanup for dst */
6726
0
    path_cleanup(&dst);
6727
6728
0
    return return_value;
6729
0
}
6730
6731
#endif /* defined(HAVE_SYMLINK) */
6732
6733
PyDoc_STRVAR(os_times__doc__,
6734
"times($module, /)\n"
6735
"--\n"
6736
"\n"
6737
"Return a collection containing process timing information.\n"
6738
"\n"
6739
"The object returned behaves like a named tuple with these fields:\n"
6740
"  (utime, stime, cutime, cstime, elapsed_time)\n"
6741
"All fields are floating-point numbers.");
6742
6743
#define OS_TIMES_METHODDEF    \
6744
    {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
6745
6746
static PyObject *
6747
os_times_impl(PyObject *module);
6748
6749
static PyObject *
6750
os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
6751
0
{
6752
0
    return os_times_impl(module);
6753
0
}
6754
6755
#if defined(HAVE_TIMERFD_CREATE)
6756
6757
PyDoc_STRVAR(os_timerfd_create__doc__,
6758
"timerfd_create($module, clockid, /, *, flags=0)\n"
6759
"--\n"
6760
"\n"
6761
"Create and return a timer file descriptor.\n"
6762
"\n"
6763
"  clockid\n"
6764
"    A valid clock ID constant as timer file descriptor.\n"
6765
"\n"
6766
"    time.CLOCK_REALTIME\n"
6767
"    time.CLOCK_MONOTONIC\n"
6768
"    time.CLOCK_BOOTTIME\n"
6769
"  flags\n"
6770
"    0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n"
6771
"\n"
6772
"    os.TFD_NONBLOCK\n"
6773
"        If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n"
6774
"        If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n"
6775
"\n"
6776
"    os.TFD_CLOEXEC\n"
6777
"        If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag");
6778
6779
#define OS_TIMERFD_CREATE_METHODDEF    \
6780
    {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__},
6781
6782
static PyObject *
6783
os_timerfd_create_impl(PyObject *module, int clockid, int flags);
6784
6785
static PyObject *
6786
os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6787
0
{
6788
0
    PyObject *return_value = NULL;
6789
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6790
6791
0
    #define NUM_KEYWORDS 1
6792
0
    static struct {
6793
0
        PyGC_Head _this_is_not_used;
6794
0
        PyObject_VAR_HEAD
6795
0
        Py_hash_t ob_hash;
6796
0
        PyObject *ob_item[NUM_KEYWORDS];
6797
0
    } _kwtuple = {
6798
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6799
0
        .ob_hash = -1,
6800
0
        .ob_item = { &_Py_ID(flags), },
6801
0
    };
6802
0
    #undef NUM_KEYWORDS
6803
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6804
6805
    #else  // !Py_BUILD_CORE
6806
    #  define KWTUPLE NULL
6807
    #endif  // !Py_BUILD_CORE
6808
6809
0
    static const char * const _keywords[] = {"", "flags", NULL};
6810
0
    static _PyArg_Parser _parser = {
6811
0
        .keywords = _keywords,
6812
0
        .fname = "timerfd_create",
6813
0
        .kwtuple = KWTUPLE,
6814
0
    };
6815
0
    #undef KWTUPLE
6816
0
    PyObject *argsbuf[2];
6817
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6818
0
    int clockid;
6819
0
    int flags = 0;
6820
6821
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6822
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6823
0
    if (!args) {
6824
0
        goto exit;
6825
0
    }
6826
0
    clockid = PyLong_AsInt(args[0]);
6827
0
    if (clockid == -1 && PyErr_Occurred()) {
6828
0
        goto exit;
6829
0
    }
6830
0
    if (!noptargs) {
6831
0
        goto skip_optional_kwonly;
6832
0
    }
6833
0
    flags = PyLong_AsInt(args[1]);
6834
0
    if (flags == -1 && PyErr_Occurred()) {
6835
0
        goto exit;
6836
0
    }
6837
0
skip_optional_kwonly:
6838
0
    return_value = os_timerfd_create_impl(module, clockid, flags);
6839
6840
0
exit:
6841
0
    return return_value;
6842
0
}
6843
6844
#endif /* defined(HAVE_TIMERFD_CREATE) */
6845
6846
#if defined(HAVE_TIMERFD_CREATE)
6847
6848
PyDoc_STRVAR(os_timerfd_settime__doc__,
6849
"timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n"
6850
"--\n"
6851
"\n"
6852
"Alter a timer file descriptor\'s internal timer in seconds.\n"
6853
"\n"
6854
"  fd\n"
6855
"    A timer file descriptor.\n"
6856
"  flags\n"
6857
"    0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
6858
"  initial\n"
6859
"    The initial expiration time, in seconds.\n"
6860
"  interval\n"
6861
"    The timer\'s interval, in seconds.");
6862
6863
#define OS_TIMERFD_SETTIME_METHODDEF    \
6864
    {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__},
6865
6866
static PyObject *
6867
os_timerfd_settime_impl(PyObject *module, int fd, int flags,
6868
                        double initial_double, double interval_double);
6869
6870
static PyObject *
6871
os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6872
0
{
6873
0
    PyObject *return_value = NULL;
6874
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6875
6876
0
    #define NUM_KEYWORDS 3
6877
0
    static struct {
6878
0
        PyGC_Head _this_is_not_used;
6879
0
        PyObject_VAR_HEAD
6880
0
        Py_hash_t ob_hash;
6881
0
        PyObject *ob_item[NUM_KEYWORDS];
6882
0
    } _kwtuple = {
6883
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6884
0
        .ob_hash = -1,
6885
0
        .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
6886
0
    };
6887
0
    #undef NUM_KEYWORDS
6888
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6889
6890
    #else  // !Py_BUILD_CORE
6891
    #  define KWTUPLE NULL
6892
    #endif  // !Py_BUILD_CORE
6893
6894
0
    static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
6895
0
    static _PyArg_Parser _parser = {
6896
0
        .keywords = _keywords,
6897
0
        .fname = "timerfd_settime",
6898
0
        .kwtuple = KWTUPLE,
6899
0
    };
6900
0
    #undef KWTUPLE
6901
0
    PyObject *argsbuf[4];
6902
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6903
0
    int fd;
6904
0
    int flags = 0;
6905
0
    double initial_double = 0.0;
6906
0
    double interval_double = 0.0;
6907
6908
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6909
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6910
0
    if (!args) {
6911
0
        goto exit;
6912
0
    }
6913
0
    fd = PyObject_AsFileDescriptor(args[0]);
6914
0
    if (fd < 0) {
6915
0
        goto exit;
6916
0
    }
6917
0
    if (!noptargs) {
6918
0
        goto skip_optional_kwonly;
6919
0
    }
6920
0
    if (args[1]) {
6921
0
        flags = PyLong_AsInt(args[1]);
6922
0
        if (flags == -1 && PyErr_Occurred()) {
6923
0
            goto exit;
6924
0
        }
6925
0
        if (!--noptargs) {
6926
0
            goto skip_optional_kwonly;
6927
0
        }
6928
0
    }
6929
0
    if (args[2]) {
6930
0
        if (PyFloat_CheckExact(args[2])) {
6931
0
            initial_double = PyFloat_AS_DOUBLE(args[2]);
6932
0
        }
6933
0
        else
6934
0
        {
6935
0
            initial_double = PyFloat_AsDouble(args[2]);
6936
0
            if (initial_double == -1.0 && PyErr_Occurred()) {
6937
0
                goto exit;
6938
0
            }
6939
0
        }
6940
0
        if (!--noptargs) {
6941
0
            goto skip_optional_kwonly;
6942
0
        }
6943
0
    }
6944
0
    if (PyFloat_CheckExact(args[3])) {
6945
0
        interval_double = PyFloat_AS_DOUBLE(args[3]);
6946
0
    }
6947
0
    else
6948
0
    {
6949
0
        interval_double = PyFloat_AsDouble(args[3]);
6950
0
        if (interval_double == -1.0 && PyErr_Occurred()) {
6951
0
            goto exit;
6952
0
        }
6953
0
    }
6954
0
skip_optional_kwonly:
6955
0
    return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double);
6956
6957
0
exit:
6958
0
    return return_value;
6959
0
}
6960
6961
#endif /* defined(HAVE_TIMERFD_CREATE) */
6962
6963
#if defined(HAVE_TIMERFD_CREATE)
6964
6965
PyDoc_STRVAR(os_timerfd_settime_ns__doc__,
6966
"timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n"
6967
"--\n"
6968
"\n"
6969
"Alter a timer file descriptor\'s internal timer in nanoseconds.\n"
6970
"\n"
6971
"  fd\n"
6972
"    A timer file descriptor.\n"
6973
"  flags\n"
6974
"    0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
6975
"  initial\n"
6976
"    initial expiration timing in seconds.\n"
6977
"  interval\n"
6978
"    interval for the timer in seconds.");
6979
6980
#define OS_TIMERFD_SETTIME_NS_METHODDEF    \
6981
    {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__},
6982
6983
static PyObject *
6984
os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags,
6985
                           long long initial, long long interval);
6986
6987
static PyObject *
6988
os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6989
0
{
6990
0
    PyObject *return_value = NULL;
6991
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6992
6993
0
    #define NUM_KEYWORDS 3
6994
0
    static struct {
6995
0
        PyGC_Head _this_is_not_used;
6996
0
        PyObject_VAR_HEAD
6997
0
        Py_hash_t ob_hash;
6998
0
        PyObject *ob_item[NUM_KEYWORDS];
6999
0
    } _kwtuple = {
7000
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7001
0
        .ob_hash = -1,
7002
0
        .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
7003
0
    };
7004
0
    #undef NUM_KEYWORDS
7005
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7006
7007
    #else  // !Py_BUILD_CORE
7008
    #  define KWTUPLE NULL
7009
    #endif  // !Py_BUILD_CORE
7010
7011
0
    static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
7012
0
    static _PyArg_Parser _parser = {
7013
0
        .keywords = _keywords,
7014
0
        .fname = "timerfd_settime_ns",
7015
0
        .kwtuple = KWTUPLE,
7016
0
    };
7017
0
    #undef KWTUPLE
7018
0
    PyObject *argsbuf[4];
7019
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
7020
0
    int fd;
7021
0
    int flags = 0;
7022
0
    long long initial = 0;
7023
0
    long long interval = 0;
7024
7025
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7026
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7027
0
    if (!args) {
7028
0
        goto exit;
7029
0
    }
7030
0
    fd = PyObject_AsFileDescriptor(args[0]);
7031
0
    if (fd < 0) {
7032
0
        goto exit;
7033
0
    }
7034
0
    if (!noptargs) {
7035
0
        goto skip_optional_kwonly;
7036
0
    }
7037
0
    if (args[1]) {
7038
0
        flags = PyLong_AsInt(args[1]);
7039
0
        if (flags == -1 && PyErr_Occurred()) {
7040
0
            goto exit;
7041
0
        }
7042
0
        if (!--noptargs) {
7043
0
            goto skip_optional_kwonly;
7044
0
        }
7045
0
    }
7046
0
    if (args[2]) {
7047
0
        initial = PyLong_AsLongLong(args[2]);
7048
0
        if (initial == -1 && PyErr_Occurred()) {
7049
0
            goto exit;
7050
0
        }
7051
0
        if (!--noptargs) {
7052
0
            goto skip_optional_kwonly;
7053
0
        }
7054
0
    }
7055
0
    interval = PyLong_AsLongLong(args[3]);
7056
0
    if (interval == -1 && PyErr_Occurred()) {
7057
0
        goto exit;
7058
0
    }
7059
0
skip_optional_kwonly:
7060
0
    return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval);
7061
7062
0
exit:
7063
0
    return return_value;
7064
0
}
7065
7066
#endif /* defined(HAVE_TIMERFD_CREATE) */
7067
7068
#if defined(HAVE_TIMERFD_CREATE)
7069
7070
PyDoc_STRVAR(os_timerfd_gettime__doc__,
7071
"timerfd_gettime($module, fd, /)\n"
7072
"--\n"
7073
"\n"
7074
"Return a tuple of a timer file descriptor\'s (interval, next expiration) in float seconds.\n"
7075
"\n"
7076
"  fd\n"
7077
"    A timer file descriptor.");
7078
7079
#define OS_TIMERFD_GETTIME_METHODDEF    \
7080
    {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__},
7081
7082
static PyObject *
7083
os_timerfd_gettime_impl(PyObject *module, int fd);
7084
7085
static PyObject *
7086
os_timerfd_gettime(PyObject *module, PyObject *arg)
7087
0
{
7088
0
    PyObject *return_value = NULL;
7089
0
    int fd;
7090
7091
0
    fd = PyObject_AsFileDescriptor(arg);
7092
0
    if (fd < 0) {
7093
0
        goto exit;
7094
0
    }
7095
0
    return_value = os_timerfd_gettime_impl(module, fd);
7096
7097
0
exit:
7098
0
    return return_value;
7099
0
}
7100
7101
#endif /* defined(HAVE_TIMERFD_CREATE) */
7102
7103
#if defined(HAVE_TIMERFD_CREATE)
7104
7105
PyDoc_STRVAR(os_timerfd_gettime_ns__doc__,
7106
"timerfd_gettime_ns($module, fd, /)\n"
7107
"--\n"
7108
"\n"
7109
"Return a tuple of a timer file descriptor\'s (interval, next expiration) in nanoseconds.\n"
7110
"\n"
7111
"  fd\n"
7112
"    A timer file descriptor.");
7113
7114
#define OS_TIMERFD_GETTIME_NS_METHODDEF    \
7115
    {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__},
7116
7117
static PyObject *
7118
os_timerfd_gettime_ns_impl(PyObject *module, int fd);
7119
7120
static PyObject *
7121
os_timerfd_gettime_ns(PyObject *module, PyObject *arg)
7122
0
{
7123
0
    PyObject *return_value = NULL;
7124
0
    int fd;
7125
7126
0
    fd = PyObject_AsFileDescriptor(arg);
7127
0
    if (fd < 0) {
7128
0
        goto exit;
7129
0
    }
7130
0
    return_value = os_timerfd_gettime_ns_impl(module, fd);
7131
7132
0
exit:
7133
0
    return return_value;
7134
0
}
7135
7136
#endif /* defined(HAVE_TIMERFD_CREATE) */
7137
7138
#if defined(HAVE_GETSID)
7139
7140
PyDoc_STRVAR(os_getsid__doc__,
7141
"getsid($module, pid, /)\n"
7142
"--\n"
7143
"\n"
7144
"Call the system call getsid(pid) and return the result.");
7145
7146
#define OS_GETSID_METHODDEF    \
7147
    {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
7148
7149
static PyObject *
7150
os_getsid_impl(PyObject *module, pid_t pid);
7151
7152
static PyObject *
7153
os_getsid(PyObject *module, PyObject *arg)
7154
0
{
7155
0
    PyObject *return_value = NULL;
7156
0
    pid_t pid;
7157
7158
0
    pid = PyLong_AsPid(arg);
7159
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7160
0
        goto exit;
7161
0
    }
7162
0
    return_value = os_getsid_impl(module, pid);
7163
7164
0
exit:
7165
0
    return return_value;
7166
0
}
7167
7168
#endif /* defined(HAVE_GETSID) */
7169
7170
#if defined(HAVE_SETSID)
7171
7172
PyDoc_STRVAR(os_setsid__doc__,
7173
"setsid($module, /)\n"
7174
"--\n"
7175
"\n"
7176
"Call the system call setsid().");
7177
7178
#define OS_SETSID_METHODDEF    \
7179
    {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
7180
7181
static PyObject *
7182
os_setsid_impl(PyObject *module);
7183
7184
static PyObject *
7185
os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
7186
0
{
7187
0
    return os_setsid_impl(module);
7188
0
}
7189
7190
#endif /* defined(HAVE_SETSID) */
7191
7192
#if defined(HAVE_SETPGID)
7193
7194
PyDoc_STRVAR(os_setpgid__doc__,
7195
"setpgid($module, pid, pgrp, /)\n"
7196
"--\n"
7197
"\n"
7198
"Call the system call setpgid(pid, pgrp).");
7199
7200
#define OS_SETPGID_METHODDEF    \
7201
    {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__},
7202
7203
static PyObject *
7204
os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
7205
7206
static PyObject *
7207
os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7208
0
{
7209
0
    PyObject *return_value = NULL;
7210
0
    pid_t pid;
7211
0
    pid_t pgrp;
7212
7213
0
    if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) {
7214
0
        goto exit;
7215
0
    }
7216
0
    pid = PyLong_AsPid(args[0]);
7217
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7218
0
        goto exit;
7219
0
    }
7220
0
    pgrp = PyLong_AsPid(args[1]);
7221
0
    if (pgrp == (pid_t)(-1) && PyErr_Occurred()) {
7222
0
        goto exit;
7223
0
    }
7224
0
    return_value = os_setpgid_impl(module, pid, pgrp);
7225
7226
0
exit:
7227
0
    return return_value;
7228
0
}
7229
7230
#endif /* defined(HAVE_SETPGID) */
7231
7232
#if defined(HAVE_TCGETPGRP)
7233
7234
PyDoc_STRVAR(os_tcgetpgrp__doc__,
7235
"tcgetpgrp($module, fd, /)\n"
7236
"--\n"
7237
"\n"
7238
"Return the process group associated with the terminal specified by fd.");
7239
7240
#define OS_TCGETPGRP_METHODDEF    \
7241
    {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
7242
7243
static PyObject *
7244
os_tcgetpgrp_impl(PyObject *module, int fd);
7245
7246
static PyObject *
7247
os_tcgetpgrp(PyObject *module, PyObject *arg)
7248
0
{
7249
0
    PyObject *return_value = NULL;
7250
0
    int fd;
7251
7252
0
    fd = PyLong_AsInt(arg);
7253
0
    if (fd == -1 && PyErr_Occurred()) {
7254
0
        goto exit;
7255
0
    }
7256
0
    return_value = os_tcgetpgrp_impl(module, fd);
7257
7258
0
exit:
7259
0
    return return_value;
7260
0
}
7261
7262
#endif /* defined(HAVE_TCGETPGRP) */
7263
7264
#if defined(HAVE_TCSETPGRP)
7265
7266
PyDoc_STRVAR(os_tcsetpgrp__doc__,
7267
"tcsetpgrp($module, fd, pgid, /)\n"
7268
"--\n"
7269
"\n"
7270
"Set the process group associated with the terminal specified by fd.");
7271
7272
#define OS_TCSETPGRP_METHODDEF    \
7273
    {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__},
7274
7275
static PyObject *
7276
os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
7277
7278
static PyObject *
7279
os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7280
0
{
7281
0
    PyObject *return_value = NULL;
7282
0
    int fd;
7283
0
    pid_t pgid;
7284
7285
0
    if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) {
7286
0
        goto exit;
7287
0
    }
7288
0
    fd = PyLong_AsInt(args[0]);
7289
0
    if (fd == -1 && PyErr_Occurred()) {
7290
0
        goto exit;
7291
0
    }
7292
0
    pgid = PyLong_AsPid(args[1]);
7293
0
    if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
7294
0
        goto exit;
7295
0
    }
7296
0
    return_value = os_tcsetpgrp_impl(module, fd, pgid);
7297
7298
0
exit:
7299
0
    return return_value;
7300
0
}
7301
7302
#endif /* defined(HAVE_TCSETPGRP) */
7303
7304
PyDoc_STRVAR(os_open__doc__,
7305
"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
7306
"--\n"
7307
"\n"
7308
"Open a file for low level IO.  Returns a file descriptor (integer).\n"
7309
"\n"
7310
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
7311
"  and path should be relative; path will then be relative to that directory.\n"
7312
"dir_fd may not be implemented on your platform.\n"
7313
"  If it is unavailable, using it will raise a NotImplementedError.");
7314
7315
#define OS_OPEN_METHODDEF    \
7316
    {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
7317
7318
static int
7319
os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
7320
7321
static PyObject *
7322
os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7323
0
{
7324
0
    PyObject *return_value = NULL;
7325
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7326
7327
0
    #define NUM_KEYWORDS 4
7328
0
    static struct {
7329
0
        PyGC_Head _this_is_not_used;
7330
0
        PyObject_VAR_HEAD
7331
0
        Py_hash_t ob_hash;
7332
0
        PyObject *ob_item[NUM_KEYWORDS];
7333
0
    } _kwtuple = {
7334
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7335
0
        .ob_hash = -1,
7336
0
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), },
7337
0
    };
7338
0
    #undef NUM_KEYWORDS
7339
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7340
7341
    #else  // !Py_BUILD_CORE
7342
    #  define KWTUPLE NULL
7343
    #endif  // !Py_BUILD_CORE
7344
7345
0
    static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
7346
0
    static _PyArg_Parser _parser = {
7347
0
        .keywords = _keywords,
7348
0
        .fname = "open",
7349
0
        .kwtuple = KWTUPLE,
7350
0
    };
7351
0
    #undef KWTUPLE
7352
0
    PyObject *argsbuf[4];
7353
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7354
0
    path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0);
7355
0
    int flags;
7356
0
    int mode = 511;
7357
0
    int dir_fd = DEFAULT_DIR_FD;
7358
0
    int _return_value;
7359
7360
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7361
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7362
0
    if (!args) {
7363
0
        goto exit;
7364
0
    }
7365
0
    if (!path_converter(args[0], &path)) {
7366
0
        goto exit;
7367
0
    }
7368
0
    flags = PyLong_AsInt(args[1]);
7369
0
    if (flags == -1 && PyErr_Occurred()) {
7370
0
        goto exit;
7371
0
    }
7372
0
    if (!noptargs) {
7373
0
        goto skip_optional_pos;
7374
0
    }
7375
0
    if (args[2]) {
7376
0
        mode = PyLong_AsInt(args[2]);
7377
0
        if (mode == -1 && PyErr_Occurred()) {
7378
0
            goto exit;
7379
0
        }
7380
0
        if (!--noptargs) {
7381
0
            goto skip_optional_pos;
7382
0
        }
7383
0
    }
7384
0
skip_optional_pos:
7385
0
    if (!noptargs) {
7386
0
        goto skip_optional_kwonly;
7387
0
    }
7388
0
    if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
7389
0
        goto exit;
7390
0
    }
7391
0
skip_optional_kwonly:
7392
0
    _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
7393
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7394
0
        goto exit;
7395
0
    }
7396
0
    return_value = PyLong_FromLong((long)_return_value);
7397
7398
0
exit:
7399
    /* Cleanup for path */
7400
0
    path_cleanup(&path);
7401
7402
0
    return return_value;
7403
0
}
7404
7405
PyDoc_STRVAR(os_close__doc__,
7406
"close($module, /, fd)\n"
7407
"--\n"
7408
"\n"
7409
"Close a file descriptor.");
7410
7411
#define OS_CLOSE_METHODDEF    \
7412
    {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
7413
7414
static PyObject *
7415
os_close_impl(PyObject *module, int fd);
7416
7417
static PyObject *
7418
os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7419
0
{
7420
0
    PyObject *return_value = NULL;
7421
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7422
7423
0
    #define NUM_KEYWORDS 1
7424
0
    static struct {
7425
0
        PyGC_Head _this_is_not_used;
7426
0
        PyObject_VAR_HEAD
7427
0
        Py_hash_t ob_hash;
7428
0
        PyObject *ob_item[NUM_KEYWORDS];
7429
0
    } _kwtuple = {
7430
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7431
0
        .ob_hash = -1,
7432
0
        .ob_item = { &_Py_ID(fd), },
7433
0
    };
7434
0
    #undef NUM_KEYWORDS
7435
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7436
7437
    #else  // !Py_BUILD_CORE
7438
    #  define KWTUPLE NULL
7439
    #endif  // !Py_BUILD_CORE
7440
7441
0
    static const char * const _keywords[] = {"fd", NULL};
7442
0
    static _PyArg_Parser _parser = {
7443
0
        .keywords = _keywords,
7444
0
        .fname = "close",
7445
0
        .kwtuple = KWTUPLE,
7446
0
    };
7447
0
    #undef KWTUPLE
7448
0
    PyObject *argsbuf[1];
7449
0
    int fd;
7450
7451
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7452
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7453
0
    if (!args) {
7454
0
        goto exit;
7455
0
    }
7456
0
    fd = PyLong_AsInt(args[0]);
7457
0
    if (fd == -1 && PyErr_Occurred()) {
7458
0
        goto exit;
7459
0
    }
7460
0
    return_value = os_close_impl(module, fd);
7461
7462
0
exit:
7463
0
    return return_value;
7464
0
}
7465
7466
PyDoc_STRVAR(os_closerange__doc__,
7467
"closerange($module, fd_low, fd_high, /)\n"
7468
"--\n"
7469
"\n"
7470
"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
7471
7472
#define OS_CLOSERANGE_METHODDEF    \
7473
    {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__},
7474
7475
static PyObject *
7476
os_closerange_impl(PyObject *module, int fd_low, int fd_high);
7477
7478
static PyObject *
7479
os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7480
0
{
7481
0
    PyObject *return_value = NULL;
7482
0
    int fd_low;
7483
0
    int fd_high;
7484
7485
0
    if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
7486
0
        goto exit;
7487
0
    }
7488
0
    fd_low = PyLong_AsInt(args[0]);
7489
0
    if (fd_low == -1 && PyErr_Occurred()) {
7490
0
        goto exit;
7491
0
    }
7492
0
    fd_high = PyLong_AsInt(args[1]);
7493
0
    if (fd_high == -1 && PyErr_Occurred()) {
7494
0
        goto exit;
7495
0
    }
7496
0
    return_value = os_closerange_impl(module, fd_low, fd_high);
7497
7498
0
exit:
7499
0
    return return_value;
7500
0
}
7501
7502
PyDoc_STRVAR(os_dup__doc__,
7503
"dup($module, fd, /)\n"
7504
"--\n"
7505
"\n"
7506
"Return a duplicate of a file descriptor.");
7507
7508
#define OS_DUP_METHODDEF    \
7509
    {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
7510
7511
static int
7512
os_dup_impl(PyObject *module, int fd);
7513
7514
static PyObject *
7515
os_dup(PyObject *module, PyObject *arg)
7516
0
{
7517
0
    PyObject *return_value = NULL;
7518
0
    int fd;
7519
0
    int _return_value;
7520
7521
0
    fd = PyLong_AsInt(arg);
7522
0
    if (fd == -1 && PyErr_Occurred()) {
7523
0
        goto exit;
7524
0
    }
7525
0
    _return_value = os_dup_impl(module, fd);
7526
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7527
0
        goto exit;
7528
0
    }
7529
0
    return_value = PyLong_FromLong((long)_return_value);
7530
7531
0
exit:
7532
0
    return return_value;
7533
0
}
7534
7535
#if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
7536
7537
PyDoc_STRVAR(os_dup2__doc__,
7538
"dup2($module, /, fd, fd2, inheritable=True)\n"
7539
"--\n"
7540
"\n"
7541
"Duplicate file descriptor.");
7542
7543
#define OS_DUP2_METHODDEF    \
7544
    {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
7545
7546
static int
7547
os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
7548
7549
static PyObject *
7550
os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7551
0
{
7552
0
    PyObject *return_value = NULL;
7553
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7554
7555
0
    #define NUM_KEYWORDS 3
7556
0
    static struct {
7557
0
        PyGC_Head _this_is_not_used;
7558
0
        PyObject_VAR_HEAD
7559
0
        Py_hash_t ob_hash;
7560
0
        PyObject *ob_item[NUM_KEYWORDS];
7561
0
    } _kwtuple = {
7562
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7563
0
        .ob_hash = -1,
7564
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), },
7565
0
    };
7566
0
    #undef NUM_KEYWORDS
7567
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7568
7569
    #else  // !Py_BUILD_CORE
7570
    #  define KWTUPLE NULL
7571
    #endif  // !Py_BUILD_CORE
7572
7573
0
    static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
7574
0
    static _PyArg_Parser _parser = {
7575
0
        .keywords = _keywords,
7576
0
        .fname = "dup2",
7577
0
        .kwtuple = KWTUPLE,
7578
0
    };
7579
0
    #undef KWTUPLE
7580
0
    PyObject *argsbuf[3];
7581
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7582
0
    int fd;
7583
0
    int fd2;
7584
0
    int inheritable = 1;
7585
0
    int _return_value;
7586
7587
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7588
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7589
0
    if (!args) {
7590
0
        goto exit;
7591
0
    }
7592
0
    fd = PyLong_AsInt(args[0]);
7593
0
    if (fd == -1 && PyErr_Occurred()) {
7594
0
        goto exit;
7595
0
    }
7596
0
    fd2 = PyLong_AsInt(args[1]);
7597
0
    if (fd2 == -1 && PyErr_Occurred()) {
7598
0
        goto exit;
7599
0
    }
7600
0
    if (!noptargs) {
7601
0
        goto skip_optional_pos;
7602
0
    }
7603
0
    inheritable = PyObject_IsTrue(args[2]);
7604
0
    if (inheritable < 0) {
7605
0
        goto exit;
7606
0
    }
7607
0
skip_optional_pos:
7608
0
    _return_value = os_dup2_impl(module, fd, fd2, inheritable);
7609
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7610
0
        goto exit;
7611
0
    }
7612
0
    return_value = PyLong_FromLong((long)_return_value);
7613
7614
0
exit:
7615
0
    return return_value;
7616
0
}
7617
7618
#endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
7619
7620
#if defined(HAVE_LOCKF)
7621
7622
PyDoc_STRVAR(os_lockf__doc__,
7623
"lockf($module, fd, command, length, /)\n"
7624
"--\n"
7625
"\n"
7626
"Apply, test or remove a POSIX lock on an open file descriptor.\n"
7627
"\n"
7628
"  fd\n"
7629
"    An open file descriptor.\n"
7630
"  command\n"
7631
"    One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
7632
"  length\n"
7633
"    The number of bytes to lock, starting at the current position.");
7634
7635
#define OS_LOCKF_METHODDEF    \
7636
    {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__},
7637
7638
static PyObject *
7639
os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
7640
7641
static PyObject *
7642
os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7643
0
{
7644
0
    PyObject *return_value = NULL;
7645
0
    int fd;
7646
0
    int command;
7647
0
    Py_off_t length;
7648
7649
0
    if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
7650
0
        goto exit;
7651
0
    }
7652
0
    fd = PyLong_AsInt(args[0]);
7653
0
    if (fd == -1 && PyErr_Occurred()) {
7654
0
        goto exit;
7655
0
    }
7656
0
    command = PyLong_AsInt(args[1]);
7657
0
    if (command == -1 && PyErr_Occurred()) {
7658
0
        goto exit;
7659
0
    }
7660
0
    if (!Py_off_t_converter(args[2], &length)) {
7661
0
        goto exit;
7662
0
    }
7663
0
    return_value = os_lockf_impl(module, fd, command, length);
7664
7665
0
exit:
7666
0
    return return_value;
7667
0
}
7668
7669
#endif /* defined(HAVE_LOCKF) */
7670
7671
PyDoc_STRVAR(os_lseek__doc__,
7672
"lseek($module, fd, position, whence, /)\n"
7673
"--\n"
7674
"\n"
7675
"Set the position of a file descriptor.  Return the new position.\n"
7676
"\n"
7677
"  fd\n"
7678
"    An open file descriptor, as returned by os.open().\n"
7679
"  position\n"
7680
"    Position, interpreted relative to \'whence\'.\n"
7681
"  whence\n"
7682
"    The relative position to seek from. Valid values are:\n"
7683
"    - SEEK_SET: seek from the start of the file.\n"
7684
"    - SEEK_CUR: seek from the current file position.\n"
7685
"    - SEEK_END: seek from the end of the file.\n"
7686
"\n"
7687
"The return value is the number of bytes relative to the beginning of the file.");
7688
7689
#define OS_LSEEK_METHODDEF    \
7690
    {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__},
7691
7692
static Py_off_t
7693
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
7694
7695
static PyObject *
7696
os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7697
0
{
7698
0
    PyObject *return_value = NULL;
7699
0
    int fd;
7700
0
    Py_off_t position;
7701
0
    int how;
7702
0
    Py_off_t _return_value;
7703
7704
0
    if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
7705
0
        goto exit;
7706
0
    }
7707
0
    fd = PyLong_AsInt(args[0]);
7708
0
    if (fd == -1 && PyErr_Occurred()) {
7709
0
        goto exit;
7710
0
    }
7711
0
    if (!Py_off_t_converter(args[1], &position)) {
7712
0
        goto exit;
7713
0
    }
7714
0
    how = PyLong_AsInt(args[2]);
7715
0
    if (how == -1 && PyErr_Occurred()) {
7716
0
        goto exit;
7717
0
    }
7718
0
    _return_value = os_lseek_impl(module, fd, position, how);
7719
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7720
0
        goto exit;
7721
0
    }
7722
0
    return_value = PyLong_FromPy_off_t(_return_value);
7723
7724
0
exit:
7725
0
    return return_value;
7726
0
}
7727
7728
PyDoc_STRVAR(os_read__doc__,
7729
"read($module, fd, length, /)\n"
7730
"--\n"
7731
"\n"
7732
"Read from a file descriptor.  Returns a bytes object.");
7733
7734
#define OS_READ_METHODDEF    \
7735
    {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__},
7736
7737
static PyObject *
7738
os_read_impl(PyObject *module, int fd, Py_ssize_t length);
7739
7740
static PyObject *
7741
os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7742
0
{
7743
0
    PyObject *return_value = NULL;
7744
0
    int fd;
7745
0
    Py_ssize_t length;
7746
7747
0
    if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
7748
0
        goto exit;
7749
0
    }
7750
0
    fd = PyLong_AsInt(args[0]);
7751
0
    if (fd == -1 && PyErr_Occurred()) {
7752
0
        goto exit;
7753
0
    }
7754
0
    {
7755
0
        Py_ssize_t ival = -1;
7756
0
        PyObject *iobj = _PyNumber_Index(args[1]);
7757
0
        if (iobj != NULL) {
7758
0
            ival = PyLong_AsSsize_t(iobj);
7759
0
            Py_DECREF(iobj);
7760
0
        }
7761
0
        if (ival == -1 && PyErr_Occurred()) {
7762
0
            goto exit;
7763
0
        }
7764
0
        length = ival;
7765
0
    }
7766
0
    return_value = os_read_impl(module, fd, length);
7767
7768
0
exit:
7769
0
    return return_value;
7770
0
}
7771
7772
PyDoc_STRVAR(os_readinto__doc__,
7773
"readinto($module, fd, buffer, /)\n"
7774
"--\n"
7775
"\n"
7776
"Read into a buffer object from a file descriptor.\n"
7777
"\n"
7778
"The buffer should be mutable and bytes-like. On success, returns the number of\n"
7779
"bytes read. Less bytes may be read than the size of the buffer. The underlying\n"
7780
"system call will be retried when interrupted by a signal, unless the signal\n"
7781
"handler raises an exception. Other errors will not be retried and an error will\n"
7782
"be raised.\n"
7783
"\n"
7784
"Returns 0 if *fd* is at end of file or if the provided *buffer* has length 0\n"
7785
"(which can be used to check for errors without reading data). Never returns\n"
7786
"negative.");
7787
7788
#define OS_READINTO_METHODDEF    \
7789
    {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__},
7790
7791
static Py_ssize_t
7792
os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer);
7793
7794
static PyObject *
7795
os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7796
0
{
7797
0
    PyObject *return_value = NULL;
7798
0
    int fd;
7799
0
    Py_buffer buffer = {NULL, NULL};
7800
0
    Py_ssize_t _return_value;
7801
7802
0
    if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) {
7803
0
        goto exit;
7804
0
    }
7805
0
    fd = PyLong_AsInt(args[0]);
7806
0
    if (fd == -1 && PyErr_Occurred()) {
7807
0
        goto exit;
7808
0
    }
7809
0
    if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) {
7810
0
        _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]);
7811
0
        goto exit;
7812
0
    }
7813
0
    _return_value = os_readinto_impl(module, fd, &buffer);
7814
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7815
0
        goto exit;
7816
0
    }
7817
0
    return_value = PyLong_FromSsize_t(_return_value);
7818
7819
0
exit:
7820
    /* Cleanup for buffer */
7821
0
    if (buffer.obj) {
7822
0
       PyBuffer_Release(&buffer);
7823
0
    }
7824
7825
0
    return return_value;
7826
0
}
7827
7828
#if defined(HAVE_READV)
7829
7830
PyDoc_STRVAR(os_readv__doc__,
7831
"readv($module, fd, buffers, /)\n"
7832
"--\n"
7833
"\n"
7834
"Read from a file descriptor fd into an iterable of buffers.\n"
7835
"\n"
7836
"The buffers should be mutable buffers accepting bytes.\n"
7837
"readv will transfer data into each buffer until it is full\n"
7838
"and then move on to the next buffer in the sequence to hold\n"
7839
"the rest of the data.\n"
7840
"\n"
7841
"readv returns the total number of bytes read,\n"
7842
"which may be less than the total capacity of all the buffers.");
7843
7844
#define OS_READV_METHODDEF    \
7845
    {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__},
7846
7847
static Py_ssize_t
7848
os_readv_impl(PyObject *module, int fd, PyObject *buffers);
7849
7850
static PyObject *
7851
os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7852
0
{
7853
0
    PyObject *return_value = NULL;
7854
0
    int fd;
7855
0
    PyObject *buffers;
7856
0
    Py_ssize_t _return_value;
7857
7858
0
    if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
7859
0
        goto exit;
7860
0
    }
7861
0
    fd = PyLong_AsInt(args[0]);
7862
0
    if (fd == -1 && PyErr_Occurred()) {
7863
0
        goto exit;
7864
0
    }
7865
0
    buffers = args[1];
7866
0
    _return_value = os_readv_impl(module, fd, buffers);
7867
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7868
0
        goto exit;
7869
0
    }
7870
0
    return_value = PyLong_FromSsize_t(_return_value);
7871
7872
0
exit:
7873
0
    return return_value;
7874
0
}
7875
7876
#endif /* defined(HAVE_READV) */
7877
7878
#if defined(HAVE_PREAD)
7879
7880
PyDoc_STRVAR(os_pread__doc__,
7881
"pread($module, fd, length, offset, /)\n"
7882
"--\n"
7883
"\n"
7884
"Read a number of bytes from a file descriptor starting at a particular offset.\n"
7885
"\n"
7886
"Read length bytes from file descriptor fd, starting at offset bytes from\n"
7887
"the beginning of the file.  The file offset remains unchanged.");
7888
7889
#define OS_PREAD_METHODDEF    \
7890
    {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__},
7891
7892
static PyObject *
7893
os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset);
7894
7895
static PyObject *
7896
os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7897
0
{
7898
0
    PyObject *return_value = NULL;
7899
0
    int fd;
7900
0
    Py_ssize_t length;
7901
0
    Py_off_t offset;
7902
7903
0
    if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
7904
0
        goto exit;
7905
0
    }
7906
0
    fd = PyLong_AsInt(args[0]);
7907
0
    if (fd == -1 && PyErr_Occurred()) {
7908
0
        goto exit;
7909
0
    }
7910
0
    {
7911
0
        Py_ssize_t ival = -1;
7912
0
        PyObject *iobj = _PyNumber_Index(args[1]);
7913
0
        if (iobj != NULL) {
7914
0
            ival = PyLong_AsSsize_t(iobj);
7915
0
            Py_DECREF(iobj);
7916
0
        }
7917
0
        if (ival == -1 && PyErr_Occurred()) {
7918
0
            goto exit;
7919
0
        }
7920
0
        length = ival;
7921
0
    }
7922
0
    if (!Py_off_t_converter(args[2], &offset)) {
7923
0
        goto exit;
7924
0
    }
7925
0
    return_value = os_pread_impl(module, fd, length, offset);
7926
7927
0
exit:
7928
0
    return return_value;
7929
0
}
7930
7931
#endif /* defined(HAVE_PREAD) */
7932
7933
#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
7934
7935
PyDoc_STRVAR(os_preadv__doc__,
7936
"preadv($module, fd, buffers, offset, flags=0, /)\n"
7937
"--\n"
7938
"\n"
7939
"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
7940
"\n"
7941
"Combines the functionality of readv() and pread(). As readv(), it will\n"
7942
"transfer data into each buffer until it is full and then move on to the next\n"
7943
"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
7944
"specifies the file offset at which the input operation is to be performed. It\n"
7945
"will return the total number of bytes read (which can be less than the total\n"
7946
"capacity of all the objects).\n"
7947
"\n"
7948
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
7949
"\n"
7950
"- RWF_HIPRI\n"
7951
"- RWF_NOWAIT\n"
7952
"- RWF_DONTCACHE\n"
7953
"\n"
7954
"Using non-zero flags requires Linux 4.6 or newer.");
7955
7956
#define OS_PREADV_METHODDEF    \
7957
    {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__},
7958
7959
static Py_ssize_t
7960
os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
7961
               int flags);
7962
7963
static PyObject *
7964
os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7965
0
{
7966
0
    PyObject *return_value = NULL;
7967
0
    int fd;
7968
0
    PyObject *buffers;
7969
0
    Py_off_t offset;
7970
0
    int flags = 0;
7971
0
    Py_ssize_t _return_value;
7972
7973
0
    if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
7974
0
        goto exit;
7975
0
    }
7976
0
    fd = PyLong_AsInt(args[0]);
7977
0
    if (fd == -1 && PyErr_Occurred()) {
7978
0
        goto exit;
7979
0
    }
7980
0
    buffers = args[1];
7981
0
    if (!Py_off_t_converter(args[2], &offset)) {
7982
0
        goto exit;
7983
0
    }
7984
0
    if (nargs < 4) {
7985
0
        goto skip_optional;
7986
0
    }
7987
0
    flags = PyLong_AsInt(args[3]);
7988
0
    if (flags == -1 && PyErr_Occurred()) {
7989
0
        goto exit;
7990
0
    }
7991
0
skip_optional:
7992
0
    _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
7993
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7994
0
        goto exit;
7995
0
    }
7996
0
    return_value = PyLong_FromSsize_t(_return_value);
7997
7998
0
exit:
7999
0
    return return_value;
8000
0
}
8001
8002
#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
8003
8004
PyDoc_STRVAR(os_write__doc__,
8005
"write($module, fd, data, /)\n"
8006
"--\n"
8007
"\n"
8008
"Write a bytes object to a file descriptor.");
8009
8010
#define OS_WRITE_METHODDEF    \
8011
    {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__},
8012
8013
static Py_ssize_t
8014
os_write_impl(PyObject *module, int fd, Py_buffer *data);
8015
8016
static PyObject *
8017
os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8018
0
{
8019
0
    PyObject *return_value = NULL;
8020
0
    int fd;
8021
0
    Py_buffer data = {NULL, NULL};
8022
0
    Py_ssize_t _return_value;
8023
8024
0
    if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
8025
0
        goto exit;
8026
0
    }
8027
0
    fd = PyLong_AsInt(args[0]);
8028
0
    if (fd == -1 && PyErr_Occurred()) {
8029
0
        goto exit;
8030
0
    }
8031
0
    if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
8032
0
        goto exit;
8033
0
    }
8034
0
    _return_value = os_write_impl(module, fd, &data);
8035
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8036
0
        goto exit;
8037
0
    }
8038
0
    return_value = PyLong_FromSsize_t(_return_value);
8039
8040
0
exit:
8041
    /* Cleanup for data */
8042
0
    if (data.obj) {
8043
0
       PyBuffer_Release(&data);
8044
0
    }
8045
8046
0
    return return_value;
8047
0
}
8048
8049
#if defined(HAVE_SENDFILE) && defined(__APPLE__)
8050
8051
PyDoc_STRVAR(os_sendfile__doc__,
8052
"sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
8053
"         trailers=(), flags=0)\n"
8054
"--\n"
8055
"\n"
8056
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8057
8058
#define OS_SENDFILE_METHODDEF    \
8059
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8060
8061
static PyObject *
8062
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
8063
                 Py_off_t sbytes, PyObject *headers, PyObject *trailers,
8064
                 int flags);
8065
8066
static PyObject *
8067
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8068
{
8069
    PyObject *return_value = NULL;
8070
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8071
8072
    #define NUM_KEYWORDS 7
8073
    static struct {
8074
        PyGC_Head _this_is_not_used;
8075
        PyObject_VAR_HEAD
8076
        Py_hash_t ob_hash;
8077
        PyObject *ob_item[NUM_KEYWORDS];
8078
    } _kwtuple = {
8079
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8080
        .ob_hash = -1,
8081
        .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), },
8082
    };
8083
    #undef NUM_KEYWORDS
8084
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8085
8086
    #else  // !Py_BUILD_CORE
8087
    #  define KWTUPLE NULL
8088
    #endif  // !Py_BUILD_CORE
8089
8090
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
8091
    static _PyArg_Parser _parser = {
8092
        .keywords = _keywords,
8093
        .fname = "sendfile",
8094
        .kwtuple = KWTUPLE,
8095
    };
8096
    #undef KWTUPLE
8097
    PyObject *argsbuf[7];
8098
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
8099
    int out_fd;
8100
    int in_fd;
8101
    Py_off_t offset;
8102
    Py_off_t sbytes;
8103
    PyObject *headers = NULL;
8104
    PyObject *trailers = NULL;
8105
    int flags = 0;
8106
8107
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8108
            /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8109
    if (!args) {
8110
        goto exit;
8111
    }
8112
    out_fd = PyLong_AsInt(args[0]);
8113
    if (out_fd == -1 && PyErr_Occurred()) {
8114
        goto exit;
8115
    }
8116
    in_fd = PyLong_AsInt(args[1]);
8117
    if (in_fd == -1 && PyErr_Occurred()) {
8118
        goto exit;
8119
    }
8120
    if (!Py_off_t_converter(args[2], &offset)) {
8121
        goto exit;
8122
    }
8123
    if (!Py_off_t_converter(args[3], &sbytes)) {
8124
        goto exit;
8125
    }
8126
    if (!noptargs) {
8127
        goto skip_optional_pos;
8128
    }
8129
    if (args[4]) {
8130
        headers = args[4];
8131
        if (!--noptargs) {
8132
            goto skip_optional_pos;
8133
        }
8134
    }
8135
    if (args[5]) {
8136
        trailers = args[5];
8137
        if (!--noptargs) {
8138
            goto skip_optional_pos;
8139
        }
8140
    }
8141
    flags = PyLong_AsInt(args[6]);
8142
    if (flags == -1 && PyErr_Occurred()) {
8143
        goto exit;
8144
    }
8145
skip_optional_pos:
8146
    return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags);
8147
8148
exit:
8149
    return return_value;
8150
}
8151
8152
#endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */
8153
8154
#if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__))
8155
8156
PyDoc_STRVAR(os_sendfile__doc__,
8157
"sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
8158
"         trailers=(), flags=0)\n"
8159
"--\n"
8160
"\n"
8161
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8162
8163
#define OS_SENDFILE_METHODDEF    \
8164
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8165
8166
static PyObject *
8167
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
8168
                 Py_ssize_t count, PyObject *headers, PyObject *trailers,
8169
                 int flags);
8170
8171
static PyObject *
8172
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8173
{
8174
    PyObject *return_value = NULL;
8175
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8176
8177
    #define NUM_KEYWORDS 7
8178
    static struct {
8179
        PyGC_Head _this_is_not_used;
8180
        PyObject_VAR_HEAD
8181
        Py_hash_t ob_hash;
8182
        PyObject *ob_item[NUM_KEYWORDS];
8183
    } _kwtuple = {
8184
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8185
        .ob_hash = -1,
8186
        .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), },
8187
    };
8188
    #undef NUM_KEYWORDS
8189
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8190
8191
    #else  // !Py_BUILD_CORE
8192
    #  define KWTUPLE NULL
8193
    #endif  // !Py_BUILD_CORE
8194
8195
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
8196
    static _PyArg_Parser _parser = {
8197
        .keywords = _keywords,
8198
        .fname = "sendfile",
8199
        .kwtuple = KWTUPLE,
8200
    };
8201
    #undef KWTUPLE
8202
    PyObject *argsbuf[7];
8203
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
8204
    int out_fd;
8205
    int in_fd;
8206
    Py_off_t offset;
8207
    Py_ssize_t count;
8208
    PyObject *headers = NULL;
8209
    PyObject *trailers = NULL;
8210
    int flags = 0;
8211
8212
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8213
            /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8214
    if (!args) {
8215
        goto exit;
8216
    }
8217
    out_fd = PyLong_AsInt(args[0]);
8218
    if (out_fd == -1 && PyErr_Occurred()) {
8219
        goto exit;
8220
    }
8221
    in_fd = PyLong_AsInt(args[1]);
8222
    if (in_fd == -1 && PyErr_Occurred()) {
8223
        goto exit;
8224
    }
8225
    if (!Py_off_t_converter(args[2], &offset)) {
8226
        goto exit;
8227
    }
8228
    {
8229
        Py_ssize_t ival = -1;
8230
        PyObject *iobj = _PyNumber_Index(args[3]);
8231
        if (iobj != NULL) {
8232
            ival = PyLong_AsSsize_t(iobj);
8233
            Py_DECREF(iobj);
8234
        }
8235
        if (ival == -1 && PyErr_Occurred()) {
8236
            goto exit;
8237
        }
8238
        count = ival;
8239
        if (count < 0) {
8240
            PyErr_SetString(PyExc_ValueError,
8241
                            "count cannot be negative");
8242
            goto exit;
8243
        }
8244
    }
8245
    if (!noptargs) {
8246
        goto skip_optional_pos;
8247
    }
8248
    if (args[4]) {
8249
        headers = args[4];
8250
        if (!--noptargs) {
8251
            goto skip_optional_pos;
8252
        }
8253
    }
8254
    if (args[5]) {
8255
        trailers = args[5];
8256
        if (!--noptargs) {
8257
            goto skip_optional_pos;
8258
        }
8259
    }
8260
    flags = PyLong_AsInt(args[6]);
8261
    if (flags == -1 && PyErr_Occurred()) {
8262
        goto exit;
8263
    }
8264
skip_optional_pos:
8265
    return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags);
8266
8267
exit:
8268
    return return_value;
8269
}
8270
8271
#endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */
8272
8273
#if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__))
8274
8275
PyDoc_STRVAR(os_sendfile__doc__,
8276
"sendfile($module, /, out_fd, in_fd, offset, count)\n"
8277
"--\n"
8278
"\n"
8279
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8280
8281
#define OS_SENDFILE_METHODDEF    \
8282
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8283
8284
static PyObject *
8285
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
8286
                 Py_ssize_t count);
8287
8288
static PyObject *
8289
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8290
0
{
8291
0
    PyObject *return_value = NULL;
8292
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8293
8294
0
    #define NUM_KEYWORDS 4
8295
0
    static struct {
8296
0
        PyGC_Head _this_is_not_used;
8297
0
        PyObject_VAR_HEAD
8298
0
        Py_hash_t ob_hash;
8299
0
        PyObject *ob_item[NUM_KEYWORDS];
8300
0
    } _kwtuple = {
8301
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8302
0
        .ob_hash = -1,
8303
0
        .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), },
8304
0
    };
8305
0
    #undef NUM_KEYWORDS
8306
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8307
8308
    #else  // !Py_BUILD_CORE
8309
    #  define KWTUPLE NULL
8310
    #endif  // !Py_BUILD_CORE
8311
8312
0
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL};
8313
0
    static _PyArg_Parser _parser = {
8314
0
        .keywords = _keywords,
8315
0
        .fname = "sendfile",
8316
0
        .kwtuple = KWTUPLE,
8317
0
    };
8318
0
    #undef KWTUPLE
8319
0
    PyObject *argsbuf[4];
8320
0
    int out_fd;
8321
0
    int in_fd;
8322
0
    PyObject *offobj;
8323
0
    Py_ssize_t count;
8324
8325
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8326
0
            /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8327
0
    if (!args) {
8328
0
        goto exit;
8329
0
    }
8330
0
    out_fd = PyLong_AsInt(args[0]);
8331
0
    if (out_fd == -1 && PyErr_Occurred()) {
8332
0
        goto exit;
8333
0
    }
8334
0
    in_fd = PyLong_AsInt(args[1]);
8335
0
    if (in_fd == -1 && PyErr_Occurred()) {
8336
0
        goto exit;
8337
0
    }
8338
0
    offobj = args[2];
8339
0
    {
8340
0
        Py_ssize_t ival = -1;
8341
0
        PyObject *iobj = _PyNumber_Index(args[3]);
8342
0
        if (iobj != NULL) {
8343
0
            ival = PyLong_AsSsize_t(iobj);
8344
0
            Py_DECREF(iobj);
8345
0
        }
8346
0
        if (ival == -1 && PyErr_Occurred()) {
8347
0
            goto exit;
8348
0
        }
8349
0
        count = ival;
8350
0
        if (count < 0) {
8351
0
            PyErr_SetString(PyExc_ValueError,
8352
0
                            "count cannot be negative");
8353
0
            goto exit;
8354
0
        }
8355
0
    }
8356
0
    return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count);
8357
8358
0
exit:
8359
0
    return return_value;
8360
0
}
8361
8362
#endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */
8363
8364
#if defined(__APPLE__)
8365
8366
PyDoc_STRVAR(os__fcopyfile__doc__,
8367
"_fcopyfile($module, in_fd, out_fd, flags, /)\n"
8368
"--\n"
8369
"\n"
8370
"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
8371
8372
#define OS__FCOPYFILE_METHODDEF    \
8373
    {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__},
8374
8375
static PyObject *
8376
os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags);
8377
8378
static PyObject *
8379
os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8380
{
8381
    PyObject *return_value = NULL;
8382
    int in_fd;
8383
    int out_fd;
8384
    int flags;
8385
8386
    if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
8387
        goto exit;
8388
    }
8389
    in_fd = PyLong_AsInt(args[0]);
8390
    if (in_fd == -1 && PyErr_Occurred()) {
8391
        goto exit;
8392
    }
8393
    out_fd = PyLong_AsInt(args[1]);
8394
    if (out_fd == -1 && PyErr_Occurred()) {
8395
        goto exit;
8396
    }
8397
    flags = PyLong_AsInt(args[2]);
8398
    if (flags == -1 && PyErr_Occurred()) {
8399
        goto exit;
8400
    }
8401
    return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags);
8402
8403
exit:
8404
    return return_value;
8405
}
8406
8407
#endif /* defined(__APPLE__) */
8408
8409
PyDoc_STRVAR(os_fstat__doc__,
8410
"fstat($module, /, fd)\n"
8411
"--\n"
8412
"\n"
8413
"Perform a stat system call on the given file descriptor.\n"
8414
"\n"
8415
"Like stat(), but for an open file descriptor.\n"
8416
"Equivalent to os.stat(fd).");
8417
8418
#define OS_FSTAT_METHODDEF    \
8419
    {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
8420
8421
static PyObject *
8422
os_fstat_impl(PyObject *module, int fd);
8423
8424
static PyObject *
8425
os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8426
0
{
8427
0
    PyObject *return_value = NULL;
8428
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8429
8430
0
    #define NUM_KEYWORDS 1
8431
0
    static struct {
8432
0
        PyGC_Head _this_is_not_used;
8433
0
        PyObject_VAR_HEAD
8434
0
        Py_hash_t ob_hash;
8435
0
        PyObject *ob_item[NUM_KEYWORDS];
8436
0
    } _kwtuple = {
8437
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8438
0
        .ob_hash = -1,
8439
0
        .ob_item = { &_Py_ID(fd), },
8440
0
    };
8441
0
    #undef NUM_KEYWORDS
8442
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8443
8444
    #else  // !Py_BUILD_CORE
8445
    #  define KWTUPLE NULL
8446
    #endif  // !Py_BUILD_CORE
8447
8448
0
    static const char * const _keywords[] = {"fd", NULL};
8449
0
    static _PyArg_Parser _parser = {
8450
0
        .keywords = _keywords,
8451
0
        .fname = "fstat",
8452
0
        .kwtuple = KWTUPLE,
8453
0
    };
8454
0
    #undef KWTUPLE
8455
0
    PyObject *argsbuf[1];
8456
0
    int fd;
8457
8458
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8459
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8460
0
    if (!args) {
8461
0
        goto exit;
8462
0
    }
8463
0
    fd = PyLong_AsInt(args[0]);
8464
0
    if (fd == -1 && PyErr_Occurred()) {
8465
0
        goto exit;
8466
0
    }
8467
0
    return_value = os_fstat_impl(module, fd);
8468
8469
0
exit:
8470
0
    return return_value;
8471
0
}
8472
8473
PyDoc_STRVAR(os_isatty__doc__,
8474
"isatty($module, fd, /)\n"
8475
"--\n"
8476
"\n"
8477
"Return True if the fd is connected to a terminal.\n"
8478
"\n"
8479
"Return True if the file descriptor is an open file descriptor\n"
8480
"connected to the slave end of a terminal.");
8481
8482
#define OS_ISATTY_METHODDEF    \
8483
    {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
8484
8485
static int
8486
os_isatty_impl(PyObject *module, int fd);
8487
8488
static PyObject *
8489
os_isatty(PyObject *module, PyObject *arg)
8490
0
{
8491
0
    PyObject *return_value = NULL;
8492
0
    int fd;
8493
0
    int _return_value;
8494
8495
0
    fd = PyLong_AsInt(arg);
8496
0
    if (fd == -1 && PyErr_Occurred()) {
8497
0
        goto exit;
8498
0
    }
8499
0
    _return_value = os_isatty_impl(module, fd);
8500
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8501
0
        goto exit;
8502
0
    }
8503
0
    return_value = PyBool_FromLong((long)_return_value);
8504
8505
0
exit:
8506
0
    return return_value;
8507
0
}
8508
8509
#if defined(HAVE_PIPE)
8510
8511
PyDoc_STRVAR(os_pipe__doc__,
8512
"pipe($module, /)\n"
8513
"--\n"
8514
"\n"
8515
"Create a pipe.\n"
8516
"\n"
8517
"Returns a tuple of two file descriptors:\n"
8518
"  (read_fd, write_fd)");
8519
8520
#define OS_PIPE_METHODDEF    \
8521
    {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
8522
8523
static PyObject *
8524
os_pipe_impl(PyObject *module);
8525
8526
static PyObject *
8527
os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
8528
0
{
8529
0
    return os_pipe_impl(module);
8530
0
}
8531
8532
#endif /* defined(HAVE_PIPE) */
8533
8534
#if defined(HAVE_PIPE2)
8535
8536
PyDoc_STRVAR(os_pipe2__doc__,
8537
"pipe2($module, flags, /)\n"
8538
"--\n"
8539
"\n"
8540
"Create a pipe with flags set atomically.\n"
8541
"\n"
8542
"Returns a tuple of two file descriptors:\n"
8543
"  (read_fd, write_fd)\n"
8544
"\n"
8545
"flags can be constructed by ORing together one or more of these values:\n"
8546
"O_NONBLOCK, O_CLOEXEC.");
8547
8548
#define OS_PIPE2_METHODDEF    \
8549
    {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
8550
8551
static PyObject *
8552
os_pipe2_impl(PyObject *module, int flags);
8553
8554
static PyObject *
8555
os_pipe2(PyObject *module, PyObject *arg)
8556
0
{
8557
0
    PyObject *return_value = NULL;
8558
0
    int flags;
8559
8560
0
    flags = PyLong_AsInt(arg);
8561
0
    if (flags == -1 && PyErr_Occurred()) {
8562
0
        goto exit;
8563
0
    }
8564
0
    return_value = os_pipe2_impl(module, flags);
8565
8566
0
exit:
8567
0
    return return_value;
8568
0
}
8569
8570
#endif /* defined(HAVE_PIPE2) */
8571
8572
#if defined(HAVE_WRITEV)
8573
8574
PyDoc_STRVAR(os_writev__doc__,
8575
"writev($module, fd, buffers, /)\n"
8576
"--\n"
8577
"\n"
8578
"Iterate over buffers, and write the contents of each to a file descriptor.\n"
8579
"\n"
8580
"Returns the total number of bytes written.\n"
8581
"buffers must be a sequence of bytes-like objects.");
8582
8583
#define OS_WRITEV_METHODDEF    \
8584
    {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__},
8585
8586
static Py_ssize_t
8587
os_writev_impl(PyObject *module, int fd, PyObject *buffers);
8588
8589
static PyObject *
8590
os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8591
0
{
8592
0
    PyObject *return_value = NULL;
8593
0
    int fd;
8594
0
    PyObject *buffers;
8595
0
    Py_ssize_t _return_value;
8596
8597
0
    if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
8598
0
        goto exit;
8599
0
    }
8600
0
    fd = PyLong_AsInt(args[0]);
8601
0
    if (fd == -1 && PyErr_Occurred()) {
8602
0
        goto exit;
8603
0
    }
8604
0
    buffers = args[1];
8605
0
    _return_value = os_writev_impl(module, fd, buffers);
8606
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8607
0
        goto exit;
8608
0
    }
8609
0
    return_value = PyLong_FromSsize_t(_return_value);
8610
8611
0
exit:
8612
0
    return return_value;
8613
0
}
8614
8615
#endif /* defined(HAVE_WRITEV) */
8616
8617
#if defined(HAVE_PWRITE)
8618
8619
PyDoc_STRVAR(os_pwrite__doc__,
8620
"pwrite($module, fd, buffer, offset, /)\n"
8621
"--\n"
8622
"\n"
8623
"Write bytes to a file descriptor starting at a particular offset.\n"
8624
"\n"
8625
"Write buffer to fd, starting at offset bytes from the beginning of\n"
8626
"the file.  Returns the number of bytes written.  Does not change the\n"
8627
"current file offset.");
8628
8629
#define OS_PWRITE_METHODDEF    \
8630
    {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__},
8631
8632
static Py_ssize_t
8633
os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
8634
8635
static PyObject *
8636
os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8637
0
{
8638
0
    PyObject *return_value = NULL;
8639
0
    int fd;
8640
0
    Py_buffer buffer = {NULL, NULL};
8641
0
    Py_off_t offset;
8642
0
    Py_ssize_t _return_value;
8643
8644
0
    if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
8645
0
        goto exit;
8646
0
    }
8647
0
    fd = PyLong_AsInt(args[0]);
8648
0
    if (fd == -1 && PyErr_Occurred()) {
8649
0
        goto exit;
8650
0
    }
8651
0
    if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
8652
0
        goto exit;
8653
0
    }
8654
0
    if (!Py_off_t_converter(args[2], &offset)) {
8655
0
        goto exit;
8656
0
    }
8657
0
    _return_value = os_pwrite_impl(module, fd, &buffer, offset);
8658
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8659
0
        goto exit;
8660
0
    }
8661
0
    return_value = PyLong_FromSsize_t(_return_value);
8662
8663
0
exit:
8664
    /* Cleanup for buffer */
8665
0
    if (buffer.obj) {
8666
0
       PyBuffer_Release(&buffer);
8667
0
    }
8668
8669
0
    return return_value;
8670
0
}
8671
8672
#endif /* defined(HAVE_PWRITE) */
8673
8674
#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
8675
8676
PyDoc_STRVAR(os_pwritev__doc__,
8677
"pwritev($module, fd, buffers, offset, flags=0, /)\n"
8678
"--\n"
8679
"\n"
8680
"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
8681
"\n"
8682
"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
8683
"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
8684
"buffer is written before proceeding to second, and so on. The operating system may\n"
8685
"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
8686
"This function writes the contents of each object to the file descriptor and returns\n"
8687
"the total number of bytes written.\n"
8688
"\n"
8689
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
8690
"\n"
8691
"- RWF_DSYNC\n"
8692
"- RWF_SYNC\n"
8693
"- RWF_APPEND\n"
8694
"- RWF_DONTCACHE\n"
8695
"- RWF_ATOMIC\n"
8696
"\n"
8697
"Using non-zero flags requires Linux 4.7 or newer.");
8698
8699
#define OS_PWRITEV_METHODDEF    \
8700
    {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__},
8701
8702
static Py_ssize_t
8703
os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
8704
                int flags);
8705
8706
static PyObject *
8707
os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8708
0
{
8709
0
    PyObject *return_value = NULL;
8710
0
    int fd;
8711
0
    PyObject *buffers;
8712
0
    Py_off_t offset;
8713
0
    int flags = 0;
8714
0
    Py_ssize_t _return_value;
8715
8716
0
    if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
8717
0
        goto exit;
8718
0
    }
8719
0
    fd = PyLong_AsInt(args[0]);
8720
0
    if (fd == -1 && PyErr_Occurred()) {
8721
0
        goto exit;
8722
0
    }
8723
0
    buffers = args[1];
8724
0
    if (!Py_off_t_converter(args[2], &offset)) {
8725
0
        goto exit;
8726
0
    }
8727
0
    if (nargs < 4) {
8728
0
        goto skip_optional;
8729
0
    }
8730
0
    flags = PyLong_AsInt(args[3]);
8731
0
    if (flags == -1 && PyErr_Occurred()) {
8732
0
        goto exit;
8733
0
    }
8734
0
skip_optional:
8735
0
    _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
8736
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8737
0
        goto exit;
8738
0
    }
8739
0
    return_value = PyLong_FromSsize_t(_return_value);
8740
8741
0
exit:
8742
0
    return return_value;
8743
0
}
8744
8745
#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
8746
8747
#if defined(HAVE_COPY_FILE_RANGE)
8748
8749
PyDoc_STRVAR(os_copy_file_range__doc__,
8750
"copy_file_range($module, /, src, dst, count, offset_src=None,\n"
8751
"                offset_dst=None)\n"
8752
"--\n"
8753
"\n"
8754
"Copy count bytes from one file descriptor to another.\n"
8755
"\n"
8756
"  src\n"
8757
"    Source file descriptor.\n"
8758
"  dst\n"
8759
"    Destination file descriptor.\n"
8760
"  count\n"
8761
"    Number of bytes to copy.\n"
8762
"  offset_src\n"
8763
"    Starting offset in src.\n"
8764
"  offset_dst\n"
8765
"    Starting offset in dst.\n"
8766
"\n"
8767
"If offset_src is None, then src is read from the current position;\n"
8768
"respectively for offset_dst.");
8769
8770
#define OS_COPY_FILE_RANGE_METHODDEF    \
8771
    {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__},
8772
8773
static PyObject *
8774
os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count,
8775
                        PyObject *offset_src, PyObject *offset_dst);
8776
8777
static PyObject *
8778
os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8779
0
{
8780
0
    PyObject *return_value = NULL;
8781
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8782
8783
0
    #define NUM_KEYWORDS 5
8784
0
    static struct {
8785
0
        PyGC_Head _this_is_not_used;
8786
0
        PyObject_VAR_HEAD
8787
0
        Py_hash_t ob_hash;
8788
0
        PyObject *ob_item[NUM_KEYWORDS];
8789
0
    } _kwtuple = {
8790
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8791
0
        .ob_hash = -1,
8792
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), },
8793
0
    };
8794
0
    #undef NUM_KEYWORDS
8795
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8796
8797
    #else  // !Py_BUILD_CORE
8798
    #  define KWTUPLE NULL
8799
    #endif  // !Py_BUILD_CORE
8800
8801
0
    static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL};
8802
0
    static _PyArg_Parser _parser = {
8803
0
        .keywords = _keywords,
8804
0
        .fname = "copy_file_range",
8805
0
        .kwtuple = KWTUPLE,
8806
0
    };
8807
0
    #undef KWTUPLE
8808
0
    PyObject *argsbuf[5];
8809
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
8810
0
    int src;
8811
0
    int dst;
8812
0
    Py_ssize_t count;
8813
0
    PyObject *offset_src = Py_None;
8814
0
    PyObject *offset_dst = Py_None;
8815
8816
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8817
0
            /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8818
0
    if (!args) {
8819
0
        goto exit;
8820
0
    }
8821
0
    src = PyLong_AsInt(args[0]);
8822
0
    if (src == -1 && PyErr_Occurred()) {
8823
0
        goto exit;
8824
0
    }
8825
0
    dst = PyLong_AsInt(args[1]);
8826
0
    if (dst == -1 && PyErr_Occurred()) {
8827
0
        goto exit;
8828
0
    }
8829
0
    {
8830
0
        Py_ssize_t ival = -1;
8831
0
        PyObject *iobj = _PyNumber_Index(args[2]);
8832
0
        if (iobj != NULL) {
8833
0
            ival = PyLong_AsSsize_t(iobj);
8834
0
            Py_DECREF(iobj);
8835
0
        }
8836
0
        if (ival == -1 && PyErr_Occurred()) {
8837
0
            goto exit;
8838
0
        }
8839
0
        count = ival;
8840
0
        if (count < 0) {
8841
0
            PyErr_SetString(PyExc_ValueError,
8842
0
                            "count cannot be negative");
8843
0
            goto exit;
8844
0
        }
8845
0
    }
8846
0
    if (!noptargs) {
8847
0
        goto skip_optional_pos;
8848
0
    }
8849
0
    if (args[3]) {
8850
0
        offset_src = args[3];
8851
0
        if (!--noptargs) {
8852
0
            goto skip_optional_pos;
8853
0
        }
8854
0
    }
8855
0
    offset_dst = args[4];
8856
0
skip_optional_pos:
8857
0
    return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst);
8858
8859
0
exit:
8860
0
    return return_value;
8861
0
}
8862
8863
#endif /* defined(HAVE_COPY_FILE_RANGE) */
8864
8865
#if ((defined(HAVE_SPLICE) && !defined(_AIX)))
8866
8867
PyDoc_STRVAR(os_splice__doc__,
8868
"splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n"
8869
"       flags=0)\n"
8870
"--\n"
8871
"\n"
8872
"Transfer count bytes from one pipe to a descriptor or vice versa.\n"
8873
"\n"
8874
"  src\n"
8875
"    Source file descriptor.\n"
8876
"  dst\n"
8877
"    Destination file descriptor.\n"
8878
"  count\n"
8879
"    Number of bytes to copy.\n"
8880
"  offset_src\n"
8881
"    Starting offset in src.\n"
8882
"  offset_dst\n"
8883
"    Starting offset in dst.\n"
8884
"  flags\n"
8885
"    Flags to modify the semantics of the call.\n"
8886
"\n"
8887
"If offset_src is None, then src is read from the current position;\n"
8888
"respectively for offset_dst. The offset associated to the file\n"
8889
"descriptor that refers to a pipe must be None.");
8890
8891
#define OS_SPLICE_METHODDEF    \
8892
    {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__},
8893
8894
static PyObject *
8895
os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
8896
               PyObject *offset_src, PyObject *offset_dst,
8897
               unsigned int flags);
8898
8899
static PyObject *
8900
os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8901
0
{
8902
0
    PyObject *return_value = NULL;
8903
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8904
8905
0
    #define NUM_KEYWORDS 6
8906
0
    static struct {
8907
0
        PyGC_Head _this_is_not_used;
8908
0
        PyObject_VAR_HEAD
8909
0
        Py_hash_t ob_hash;
8910
0
        PyObject *ob_item[NUM_KEYWORDS];
8911
0
    } _kwtuple = {
8912
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8913
0
        .ob_hash = -1,
8914
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), },
8915
0
    };
8916
0
    #undef NUM_KEYWORDS
8917
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8918
8919
    #else  // !Py_BUILD_CORE
8920
    #  define KWTUPLE NULL
8921
    #endif  // !Py_BUILD_CORE
8922
8923
0
    static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL};
8924
0
    static _PyArg_Parser _parser = {
8925
0
        .keywords = _keywords,
8926
0
        .fname = "splice",
8927
0
        .kwtuple = KWTUPLE,
8928
0
    };
8929
0
    #undef KWTUPLE
8930
0
    PyObject *argsbuf[6];
8931
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
8932
0
    int src;
8933
0
    int dst;
8934
0
    Py_ssize_t count;
8935
0
    PyObject *offset_src = Py_None;
8936
0
    PyObject *offset_dst = Py_None;
8937
0
    unsigned int flags = 0;
8938
8939
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8940
0
            /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8941
0
    if (!args) {
8942
0
        goto exit;
8943
0
    }
8944
0
    src = PyLong_AsInt(args[0]);
8945
0
    if (src == -1 && PyErr_Occurred()) {
8946
0
        goto exit;
8947
0
    }
8948
0
    dst = PyLong_AsInt(args[1]);
8949
0
    if (dst == -1 && PyErr_Occurred()) {
8950
0
        goto exit;
8951
0
    }
8952
0
    {
8953
0
        Py_ssize_t ival = -1;
8954
0
        PyObject *iobj = _PyNumber_Index(args[2]);
8955
0
        if (iobj != NULL) {
8956
0
            ival = PyLong_AsSsize_t(iobj);
8957
0
            Py_DECREF(iobj);
8958
0
        }
8959
0
        if (ival == -1 && PyErr_Occurred()) {
8960
0
            goto exit;
8961
0
        }
8962
0
        count = ival;
8963
0
        if (count < 0) {
8964
0
            PyErr_SetString(PyExc_ValueError,
8965
0
                            "count cannot be negative");
8966
0
            goto exit;
8967
0
        }
8968
0
    }
8969
0
    if (!noptargs) {
8970
0
        goto skip_optional_pos;
8971
0
    }
8972
0
    if (args[3]) {
8973
0
        offset_src = args[3];
8974
0
        if (!--noptargs) {
8975
0
            goto skip_optional_pos;
8976
0
        }
8977
0
    }
8978
0
    if (args[4]) {
8979
0
        offset_dst = args[4];
8980
0
        if (!--noptargs) {
8981
0
            goto skip_optional_pos;
8982
0
        }
8983
0
    }
8984
0
    if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) {
8985
0
        goto exit;
8986
0
    }
8987
0
skip_optional_pos:
8988
0
    return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags);
8989
8990
0
exit:
8991
0
    return return_value;
8992
0
}
8993
8994
#endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */
8995
8996
#if defined(HAVE_MKFIFO)
8997
8998
PyDoc_STRVAR(os_mkfifo__doc__,
8999
"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
9000
"--\n"
9001
"\n"
9002
"Create a \"fifo\" (a POSIX named pipe).\n"
9003
"\n"
9004
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
9005
"  and path should be relative; path will then be relative to that directory.\n"
9006
"dir_fd may not be implemented on your platform.\n"
9007
"  If it is unavailable, using it will raise a NotImplementedError.");
9008
9009
#define OS_MKFIFO_METHODDEF    \
9010
    {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
9011
9012
static PyObject *
9013
os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
9014
9015
static PyObject *
9016
os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9017
0
{
9018
0
    PyObject *return_value = NULL;
9019
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9020
9021
0
    #define NUM_KEYWORDS 3
9022
0
    static struct {
9023
0
        PyGC_Head _this_is_not_used;
9024
0
        PyObject_VAR_HEAD
9025
0
        Py_hash_t ob_hash;
9026
0
        PyObject *ob_item[NUM_KEYWORDS];
9027
0
    } _kwtuple = {
9028
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9029
0
        .ob_hash = -1,
9030
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
9031
0
    };
9032
0
    #undef NUM_KEYWORDS
9033
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9034
9035
    #else  // !Py_BUILD_CORE
9036
    #  define KWTUPLE NULL
9037
    #endif  // !Py_BUILD_CORE
9038
9039
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
9040
0
    static _PyArg_Parser _parser = {
9041
0
        .keywords = _keywords,
9042
0
        .fname = "mkfifo",
9043
0
        .kwtuple = KWTUPLE,
9044
0
    };
9045
0
    #undef KWTUPLE
9046
0
    PyObject *argsbuf[3];
9047
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
9048
0
    path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0);
9049
0
    int mode = 438;
9050
0
    int dir_fd = DEFAULT_DIR_FD;
9051
9052
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9053
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9054
0
    if (!args) {
9055
0
        goto exit;
9056
0
    }
9057
0
    if (!path_converter(args[0], &path)) {
9058
0
        goto exit;
9059
0
    }
9060
0
    if (!noptargs) {
9061
0
        goto skip_optional_pos;
9062
0
    }
9063
0
    if (args[1]) {
9064
0
        mode = PyLong_AsInt(args[1]);
9065
0
        if (mode == -1 && PyErr_Occurred()) {
9066
0
            goto exit;
9067
0
        }
9068
0
        if (!--noptargs) {
9069
0
            goto skip_optional_pos;
9070
0
        }
9071
0
    }
9072
0
skip_optional_pos:
9073
0
    if (!noptargs) {
9074
0
        goto skip_optional_kwonly;
9075
0
    }
9076
0
    if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
9077
0
        goto exit;
9078
0
    }
9079
0
skip_optional_kwonly:
9080
0
    return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
9081
9082
0
exit:
9083
    /* Cleanup for path */
9084
0
    path_cleanup(&path);
9085
9086
0
    return return_value;
9087
0
}
9088
9089
#endif /* defined(HAVE_MKFIFO) */
9090
9091
#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
9092
9093
PyDoc_STRVAR(os_mknod__doc__,
9094
"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
9095
"--\n"
9096
"\n"
9097
"Create a node in the file system.\n"
9098
"\n"
9099
"Create a node in the file system (file, device special file or named pipe)\n"
9100
"at path.  mode specifies both the permissions to use and the\n"
9101
"type of node to be created, being combined (bitwise OR) with one of\n"
9102
"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO.  If S_IFCHR or S_IFBLK is set on mode,\n"
9103
"device defines the newly created device special file (probably using\n"
9104
"os.makedev()).  Otherwise device is ignored.\n"
9105
"\n"
9106
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
9107
"  and path should be relative; path will then be relative to that directory.\n"
9108
"dir_fd may not be implemented on your platform.\n"
9109
"  If it is unavailable, using it will raise a NotImplementedError.");
9110
9111
#define OS_MKNOD_METHODDEF    \
9112
    {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
9113
9114
static PyObject *
9115
os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
9116
              int dir_fd);
9117
9118
static PyObject *
9119
os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9120
0
{
9121
0
    PyObject *return_value = NULL;
9122
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9123
9124
0
    #define NUM_KEYWORDS 4
9125
0
    static struct {
9126
0
        PyGC_Head _this_is_not_used;
9127
0
        PyObject_VAR_HEAD
9128
0
        Py_hash_t ob_hash;
9129
0
        PyObject *ob_item[NUM_KEYWORDS];
9130
0
    } _kwtuple = {
9131
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9132
0
        .ob_hash = -1,
9133
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), },
9134
0
    };
9135
0
    #undef NUM_KEYWORDS
9136
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9137
9138
    #else  // !Py_BUILD_CORE
9139
    #  define KWTUPLE NULL
9140
    #endif  // !Py_BUILD_CORE
9141
9142
0
    static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
9143
0
    static _PyArg_Parser _parser = {
9144
0
        .keywords = _keywords,
9145
0
        .fname = "mknod",
9146
0
        .kwtuple = KWTUPLE,
9147
0
    };
9148
0
    #undef KWTUPLE
9149
0
    PyObject *argsbuf[4];
9150
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
9151
0
    path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0);
9152
0
    int mode = 384;
9153
0
    dev_t device = 0;
9154
0
    int dir_fd = DEFAULT_DIR_FD;
9155
9156
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9157
0
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9158
0
    if (!args) {
9159
0
        goto exit;
9160
0
    }
9161
0
    if (!path_converter(args[0], &path)) {
9162
0
        goto exit;
9163
0
    }
9164
0
    if (!noptargs) {
9165
0
        goto skip_optional_pos;
9166
0
    }
9167
0
    if (args[1]) {
9168
0
        mode = PyLong_AsInt(args[1]);
9169
0
        if (mode == -1 && PyErr_Occurred()) {
9170
0
            goto exit;
9171
0
        }
9172
0
        if (!--noptargs) {
9173
0
            goto skip_optional_pos;
9174
0
        }
9175
0
    }
9176
0
    if (args[2]) {
9177
0
        if (!_Py_Dev_Converter(args[2], &device)) {
9178
0
            goto exit;
9179
0
        }
9180
0
        if (!--noptargs) {
9181
0
            goto skip_optional_pos;
9182
0
        }
9183
0
    }
9184
0
skip_optional_pos:
9185
0
    if (!noptargs) {
9186
0
        goto skip_optional_kwonly;
9187
0
    }
9188
0
    if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
9189
0
        goto exit;
9190
0
    }
9191
0
skip_optional_kwonly:
9192
0
    return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
9193
9194
0
exit:
9195
    /* Cleanup for path */
9196
0
    path_cleanup(&path);
9197
9198
0
    return return_value;
9199
0
}
9200
9201
#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
9202
9203
#if defined(HAVE_DEVICE_MACROS)
9204
9205
PyDoc_STRVAR(os_major__doc__,
9206
"major($module, device, /)\n"
9207
"--\n"
9208
"\n"
9209
"Extracts a device major number from a raw device number.");
9210
9211
#define OS_MAJOR_METHODDEF    \
9212
    {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
9213
9214
static PyObject *
9215
os_major_impl(PyObject *module, dev_t device);
9216
9217
static PyObject *
9218
os_major(PyObject *module, PyObject *arg)
9219
0
{
9220
0
    PyObject *return_value = NULL;
9221
0
    dev_t device;
9222
9223
0
    if (!_Py_Dev_Converter(arg, &device)) {
9224
0
        goto exit;
9225
0
    }
9226
0
    return_value = os_major_impl(module, device);
9227
9228
0
exit:
9229
0
    return return_value;
9230
0
}
9231
9232
#endif /* defined(HAVE_DEVICE_MACROS) */
9233
9234
#if defined(HAVE_DEVICE_MACROS)
9235
9236
PyDoc_STRVAR(os_minor__doc__,
9237
"minor($module, device, /)\n"
9238
"--\n"
9239
"\n"
9240
"Extracts a device minor number from a raw device number.");
9241
9242
#define OS_MINOR_METHODDEF    \
9243
    {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
9244
9245
static PyObject *
9246
os_minor_impl(PyObject *module, dev_t device);
9247
9248
static PyObject *
9249
os_minor(PyObject *module, PyObject *arg)
9250
0
{
9251
0
    PyObject *return_value = NULL;
9252
0
    dev_t device;
9253
9254
0
    if (!_Py_Dev_Converter(arg, &device)) {
9255
0
        goto exit;
9256
0
    }
9257
0
    return_value = os_minor_impl(module, device);
9258
9259
0
exit:
9260
0
    return return_value;
9261
0
}
9262
9263
#endif /* defined(HAVE_DEVICE_MACROS) */
9264
9265
#if defined(HAVE_DEVICE_MACROS)
9266
9267
PyDoc_STRVAR(os_makedev__doc__,
9268
"makedev($module, major, minor, /)\n"
9269
"--\n"
9270
"\n"
9271
"Composes a raw device number from the major and minor device numbers.");
9272
9273
#define OS_MAKEDEV_METHODDEF    \
9274
    {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__},
9275
9276
static dev_t
9277
os_makedev_impl(PyObject *module, dev_t major, dev_t minor);
9278
9279
static PyObject *
9280
os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9281
0
{
9282
0
    PyObject *return_value = NULL;
9283
0
    dev_t major;
9284
0
    dev_t minor;
9285
0
    dev_t _return_value;
9286
9287
0
    if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
9288
0
        goto exit;
9289
0
    }
9290
0
    if (!_Py_Dev_Converter(args[0], &major)) {
9291
0
        goto exit;
9292
0
    }
9293
0
    if (!_Py_Dev_Converter(args[1], &minor)) {
9294
0
        goto exit;
9295
0
    }
9296
0
    _return_value = os_makedev_impl(module, major, minor);
9297
0
    if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
9298
0
        goto exit;
9299
0
    }
9300
0
    return_value = _PyLong_FromDev(_return_value);
9301
9302
0
exit:
9303
0
    return return_value;
9304
0
}
9305
9306
#endif /* defined(HAVE_DEVICE_MACROS) */
9307
9308
#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
9309
9310
PyDoc_STRVAR(os_ftruncate__doc__,
9311
"ftruncate($module, fd, length, /)\n"
9312
"--\n"
9313
"\n"
9314
"Truncate a file, specified by file descriptor, to a specific length.");
9315
9316
#define OS_FTRUNCATE_METHODDEF    \
9317
    {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__},
9318
9319
static PyObject *
9320
os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
9321
9322
static PyObject *
9323
os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9324
0
{
9325
0
    PyObject *return_value = NULL;
9326
0
    int fd;
9327
0
    Py_off_t length;
9328
9329
0
    if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
9330
0
        goto exit;
9331
0
    }
9332
0
    fd = PyLong_AsInt(args[0]);
9333
0
    if (fd == -1 && PyErr_Occurred()) {
9334
0
        goto exit;
9335
0
    }
9336
0
    if (!Py_off_t_converter(args[1], &length)) {
9337
0
        goto exit;
9338
0
    }
9339
0
    return_value = os_ftruncate_impl(module, fd, length);
9340
9341
0
exit:
9342
0
    return return_value;
9343
0
}
9344
9345
#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
9346
9347
#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
9348
9349
PyDoc_STRVAR(os_truncate__doc__,
9350
"truncate($module, /, path, length)\n"
9351
"--\n"
9352
"\n"
9353
"Truncate a file, specified by path, to a specific length.\n"
9354
"\n"
9355
"On some platforms, path may also be specified as an open file descriptor.\n"
9356
"  If this functionality is unavailable, using it raises an exception.");
9357
9358
#define OS_TRUNCATE_METHODDEF    \
9359
    {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
9360
9361
static PyObject *
9362
os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
9363
9364
static PyObject *
9365
os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9366
0
{
9367
0
    PyObject *return_value = NULL;
9368
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9369
9370
0
    #define NUM_KEYWORDS 2
9371
0
    static struct {
9372
0
        PyGC_Head _this_is_not_used;
9373
0
        PyObject_VAR_HEAD
9374
0
        Py_hash_t ob_hash;
9375
0
        PyObject *ob_item[NUM_KEYWORDS];
9376
0
    } _kwtuple = {
9377
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9378
0
        .ob_hash = -1,
9379
0
        .ob_item = { &_Py_ID(path), &_Py_ID(length), },
9380
0
    };
9381
0
    #undef NUM_KEYWORDS
9382
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9383
9384
    #else  // !Py_BUILD_CORE
9385
    #  define KWTUPLE NULL
9386
    #endif  // !Py_BUILD_CORE
9387
9388
0
    static const char * const _keywords[] = {"path", "length", NULL};
9389
0
    static _PyArg_Parser _parser = {
9390
0
        .keywords = _keywords,
9391
0
        .fname = "truncate",
9392
0
        .kwtuple = KWTUPLE,
9393
0
    };
9394
0
    #undef KWTUPLE
9395
0
    PyObject *argsbuf[2];
9396
0
    path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE);
9397
0
    Py_off_t length;
9398
9399
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9400
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9401
0
    if (!args) {
9402
0
        goto exit;
9403
0
    }
9404
0
    if (!path_converter(args[0], &path)) {
9405
0
        goto exit;
9406
0
    }
9407
0
    if (!Py_off_t_converter(args[1], &length)) {
9408
0
        goto exit;
9409
0
    }
9410
0
    return_value = os_truncate_impl(module, &path, length);
9411
9412
0
exit:
9413
    /* Cleanup for path */
9414
0
    path_cleanup(&path);
9415
9416
0
    return return_value;
9417
0
}
9418
9419
#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
9420
9421
#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__))
9422
9423
PyDoc_STRVAR(os_posix_fallocate__doc__,
9424
"posix_fallocate($module, fd, offset, length, /)\n"
9425
"--\n"
9426
"\n"
9427
"Ensure a file has allocated at least a particular number of bytes on disk.\n"
9428
"\n"
9429
"Ensure that the file specified by fd encompasses a range of bytes\n"
9430
"starting at offset bytes from the beginning and continuing for length bytes.");
9431
9432
#define OS_POSIX_FALLOCATE_METHODDEF    \
9433
    {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__},
9434
9435
static PyObject *
9436
os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
9437
                        Py_off_t length);
9438
9439
static PyObject *
9440
os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9441
0
{
9442
0
    PyObject *return_value = NULL;
9443
0
    int fd;
9444
0
    Py_off_t offset;
9445
0
    Py_off_t length;
9446
9447
0
    if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
9448
0
        goto exit;
9449
0
    }
9450
0
    fd = PyLong_AsInt(args[0]);
9451
0
    if (fd == -1 && PyErr_Occurred()) {
9452
0
        goto exit;
9453
0
    }
9454
0
    if (!Py_off_t_converter(args[1], &offset)) {
9455
0
        goto exit;
9456
0
    }
9457
0
    if (!Py_off_t_converter(args[2], &length)) {
9458
0
        goto exit;
9459
0
    }
9460
0
    return_value = os_posix_fallocate_impl(module, fd, offset, length);
9461
9462
0
exit:
9463
0
    return return_value;
9464
0
}
9465
9466
#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */
9467
9468
#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
9469
9470
PyDoc_STRVAR(os_posix_fadvise__doc__,
9471
"posix_fadvise($module, fd, offset, length, advice, /)\n"
9472
"--\n"
9473
"\n"
9474
"Announce an intention to access data in a specific pattern.\n"
9475
"\n"
9476
"Announce an intention to access data in a specific pattern, thus allowing\n"
9477
"the kernel to make optimizations.\n"
9478
"The advice applies to the region of the file specified by fd starting at\n"
9479
"offset and continuing for length bytes.\n"
9480
"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
9481
"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
9482
"POSIX_FADV_DONTNEED.");
9483
9484
#define OS_POSIX_FADVISE_METHODDEF    \
9485
    {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__},
9486
9487
static PyObject *
9488
os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
9489
                      Py_off_t length, int advice);
9490
9491
static PyObject *
9492
os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9493
0
{
9494
0
    PyObject *return_value = NULL;
9495
0
    int fd;
9496
0
    Py_off_t offset;
9497
0
    Py_off_t length;
9498
0
    int advice;
9499
9500
0
    if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
9501
0
        goto exit;
9502
0
    }
9503
0
    fd = PyLong_AsInt(args[0]);
9504
0
    if (fd == -1 && PyErr_Occurred()) {
9505
0
        goto exit;
9506
0
    }
9507
0
    if (!Py_off_t_converter(args[1], &offset)) {
9508
0
        goto exit;
9509
0
    }
9510
0
    if (!Py_off_t_converter(args[2], &length)) {
9511
0
        goto exit;
9512
0
    }
9513
0
    advice = PyLong_AsInt(args[3]);
9514
0
    if (advice == -1 && PyErr_Occurred()) {
9515
0
        goto exit;
9516
0
    }
9517
0
    return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
9518
9519
0
exit:
9520
0
    return return_value;
9521
0
}
9522
9523
#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
9524
9525
#if defined(MS_WINDOWS)
9526
9527
PyDoc_STRVAR(os_putenv__doc__,
9528
"putenv($module, name, value, /)\n"
9529
"--\n"
9530
"\n"
9531
"Change or add an environment variable.");
9532
9533
#define OS_PUTENV_METHODDEF    \
9534
    {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9535
9536
static PyObject *
9537
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9538
9539
static PyObject *
9540
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9541
{
9542
    PyObject *return_value = NULL;
9543
    PyObject *name;
9544
    PyObject *value;
9545
9546
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9547
        goto exit;
9548
    }
9549
    if (!PyUnicode_Check(args[0])) {
9550
        _PyArg_BadArgument("putenv", "argument 1", "str", args[0]);
9551
        goto exit;
9552
    }
9553
    name = args[0];
9554
    if (!PyUnicode_Check(args[1])) {
9555
        _PyArg_BadArgument("putenv", "argument 2", "str", args[1]);
9556
        goto exit;
9557
    }
9558
    value = args[1];
9559
    return_value = os_putenv_impl(module, name, value);
9560
9561
exit:
9562
    return return_value;
9563
}
9564
9565
#endif /* defined(MS_WINDOWS) */
9566
9567
#if !defined(MS_WINDOWS)
9568
9569
PyDoc_STRVAR(os_putenv__doc__,
9570
"putenv($module, name, value, /)\n"
9571
"--\n"
9572
"\n"
9573
"Change or add an environment variable.");
9574
9575
#define OS_PUTENV_METHODDEF    \
9576
    {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9577
9578
static PyObject *
9579
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9580
9581
static PyObject *
9582
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9583
0
{
9584
0
    PyObject *return_value = NULL;
9585
0
    PyObject *name = NULL;
9586
0
    PyObject *value = NULL;
9587
9588
0
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9589
0
        goto exit;
9590
0
    }
9591
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
9592
0
        goto exit;
9593
0
    }
9594
0
    if (!PyUnicode_FSConverter(args[1], &value)) {
9595
0
        goto exit;
9596
0
    }
9597
0
    return_value = os_putenv_impl(module, name, value);
9598
9599
0
exit:
9600
    /* Cleanup for name */
9601
0
    Py_XDECREF(name);
9602
    /* Cleanup for value */
9603
0
    Py_XDECREF(value);
9604
9605
0
    return return_value;
9606
0
}
9607
9608
#endif /* !defined(MS_WINDOWS) */
9609
9610
#if defined(MS_WINDOWS)
9611
9612
PyDoc_STRVAR(os_unsetenv__doc__,
9613
"unsetenv($module, name, /)\n"
9614
"--\n"
9615
"\n"
9616
"Delete an environment variable.");
9617
9618
#define OS_UNSETENV_METHODDEF    \
9619
    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9620
9621
static PyObject *
9622
os_unsetenv_impl(PyObject *module, PyObject *name);
9623
9624
static PyObject *
9625
os_unsetenv(PyObject *module, PyObject *arg)
9626
{
9627
    PyObject *return_value = NULL;
9628
    PyObject *name;
9629
9630
    if (!PyUnicode_Check(arg)) {
9631
        _PyArg_BadArgument("unsetenv", "argument", "str", arg);
9632
        goto exit;
9633
    }
9634
    name = arg;
9635
    return_value = os_unsetenv_impl(module, name);
9636
9637
exit:
9638
    return return_value;
9639
}
9640
9641
#endif /* defined(MS_WINDOWS) */
9642
9643
#if !defined(MS_WINDOWS)
9644
9645
PyDoc_STRVAR(os_unsetenv__doc__,
9646
"unsetenv($module, name, /)\n"
9647
"--\n"
9648
"\n"
9649
"Delete an environment variable.");
9650
9651
#define OS_UNSETENV_METHODDEF    \
9652
    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9653
9654
static PyObject *
9655
os_unsetenv_impl(PyObject *module, PyObject *name);
9656
9657
static PyObject *
9658
os_unsetenv(PyObject *module, PyObject *arg)
9659
0
{
9660
0
    PyObject *return_value = NULL;
9661
0
    PyObject *name = NULL;
9662
9663
0
    if (!PyUnicode_FSConverter(arg, &name)) {
9664
0
        goto exit;
9665
0
    }
9666
0
    return_value = os_unsetenv_impl(module, name);
9667
9668
0
exit:
9669
    /* Cleanup for name */
9670
0
    Py_XDECREF(name);
9671
9672
0
    return return_value;
9673
0
}
9674
9675
#endif /* !defined(MS_WINDOWS) */
9676
9677
#if defined(HAVE_CLEARENV)
9678
9679
PyDoc_STRVAR(os__clearenv__doc__,
9680
"_clearenv($module, /)\n"
9681
"--\n"
9682
"\n");
9683
9684
#define OS__CLEARENV_METHODDEF    \
9685
    {"_clearenv", (PyCFunction)os__clearenv, METH_NOARGS, os__clearenv__doc__},
9686
9687
static PyObject *
9688
os__clearenv_impl(PyObject *module);
9689
9690
static PyObject *
9691
os__clearenv(PyObject *module, PyObject *Py_UNUSED(ignored))
9692
0
{
9693
0
    return os__clearenv_impl(module);
9694
0
}
9695
9696
#endif /* defined(HAVE_CLEARENV) */
9697
9698
PyDoc_STRVAR(os_strerror__doc__,
9699
"strerror($module, code, /)\n"
9700
"--\n"
9701
"\n"
9702
"Translate an error code to a message string.");
9703
9704
#define OS_STRERROR_METHODDEF    \
9705
    {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
9706
9707
static PyObject *
9708
os_strerror_impl(PyObject *module, int code);
9709
9710
static PyObject *
9711
os_strerror(PyObject *module, PyObject *arg)
9712
0
{
9713
0
    PyObject *return_value = NULL;
9714
0
    int code;
9715
9716
0
    code = PyLong_AsInt(arg);
9717
0
    if (code == -1 && PyErr_Occurred()) {
9718
0
        goto exit;
9719
0
    }
9720
0
    return_value = os_strerror_impl(module, code);
9721
9722
0
exit:
9723
0
    return return_value;
9724
0
}
9725
9726
#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
9727
9728
PyDoc_STRVAR(os_WCOREDUMP__doc__,
9729
"WCOREDUMP($module, status, /)\n"
9730
"--\n"
9731
"\n"
9732
"Return True if the process returning status was dumped to a core file.");
9733
9734
#define OS_WCOREDUMP_METHODDEF    \
9735
    {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
9736
9737
static int
9738
os_WCOREDUMP_impl(PyObject *module, int status);
9739
9740
static PyObject *
9741
os_WCOREDUMP(PyObject *module, PyObject *arg)
9742
0
{
9743
0
    PyObject *return_value = NULL;
9744
0
    int status;
9745
0
    int _return_value;
9746
9747
0
    status = PyLong_AsInt(arg);
9748
0
    if (status == -1 && PyErr_Occurred()) {
9749
0
        goto exit;
9750
0
    }
9751
0
    _return_value = os_WCOREDUMP_impl(module, status);
9752
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9753
0
        goto exit;
9754
0
    }
9755
0
    return_value = PyBool_FromLong((long)_return_value);
9756
9757
0
exit:
9758
0
    return return_value;
9759
0
}
9760
9761
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
9762
9763
#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
9764
9765
PyDoc_STRVAR(os_WIFCONTINUED__doc__,
9766
"WIFCONTINUED($module, /, status)\n"
9767
"--\n"
9768
"\n"
9769
"Return True if a particular process was continued from a job control stop.\n"
9770
"\n"
9771
"Return True if the process returning status was continued from a\n"
9772
"job control stop.");
9773
9774
#define OS_WIFCONTINUED_METHODDEF    \
9775
    {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
9776
9777
static int
9778
os_WIFCONTINUED_impl(PyObject *module, int status);
9779
9780
static PyObject *
9781
os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9782
0
{
9783
0
    PyObject *return_value = NULL;
9784
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9785
9786
0
    #define NUM_KEYWORDS 1
9787
0
    static struct {
9788
0
        PyGC_Head _this_is_not_used;
9789
0
        PyObject_VAR_HEAD
9790
0
        Py_hash_t ob_hash;
9791
0
        PyObject *ob_item[NUM_KEYWORDS];
9792
0
    } _kwtuple = {
9793
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9794
0
        .ob_hash = -1,
9795
0
        .ob_item = { &_Py_ID(status), },
9796
0
    };
9797
0
    #undef NUM_KEYWORDS
9798
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9799
9800
    #else  // !Py_BUILD_CORE
9801
    #  define KWTUPLE NULL
9802
    #endif  // !Py_BUILD_CORE
9803
9804
0
    static const char * const _keywords[] = {"status", NULL};
9805
0
    static _PyArg_Parser _parser = {
9806
0
        .keywords = _keywords,
9807
0
        .fname = "WIFCONTINUED",
9808
0
        .kwtuple = KWTUPLE,
9809
0
    };
9810
0
    #undef KWTUPLE
9811
0
    PyObject *argsbuf[1];
9812
0
    int status;
9813
0
    int _return_value;
9814
9815
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9816
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9817
0
    if (!args) {
9818
0
        goto exit;
9819
0
    }
9820
0
    status = PyLong_AsInt(args[0]);
9821
0
    if (status == -1 && PyErr_Occurred()) {
9822
0
        goto exit;
9823
0
    }
9824
0
    _return_value = os_WIFCONTINUED_impl(module, status);
9825
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9826
0
        goto exit;
9827
0
    }
9828
0
    return_value = PyBool_FromLong((long)_return_value);
9829
9830
0
exit:
9831
0
    return return_value;
9832
0
}
9833
9834
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
9835
9836
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
9837
9838
PyDoc_STRVAR(os_WIFSTOPPED__doc__,
9839
"WIFSTOPPED($module, /, status)\n"
9840
"--\n"
9841
"\n"
9842
"Return True if the process returning status was stopped.");
9843
9844
#define OS_WIFSTOPPED_METHODDEF    \
9845
    {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
9846
9847
static int
9848
os_WIFSTOPPED_impl(PyObject *module, int status);
9849
9850
static PyObject *
9851
os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9852
0
{
9853
0
    PyObject *return_value = NULL;
9854
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9855
9856
0
    #define NUM_KEYWORDS 1
9857
0
    static struct {
9858
0
        PyGC_Head _this_is_not_used;
9859
0
        PyObject_VAR_HEAD
9860
0
        Py_hash_t ob_hash;
9861
0
        PyObject *ob_item[NUM_KEYWORDS];
9862
0
    } _kwtuple = {
9863
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9864
0
        .ob_hash = -1,
9865
0
        .ob_item = { &_Py_ID(status), },
9866
0
    };
9867
0
    #undef NUM_KEYWORDS
9868
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9869
9870
    #else  // !Py_BUILD_CORE
9871
    #  define KWTUPLE NULL
9872
    #endif  // !Py_BUILD_CORE
9873
9874
0
    static const char * const _keywords[] = {"status", NULL};
9875
0
    static _PyArg_Parser _parser = {
9876
0
        .keywords = _keywords,
9877
0
        .fname = "WIFSTOPPED",
9878
0
        .kwtuple = KWTUPLE,
9879
0
    };
9880
0
    #undef KWTUPLE
9881
0
    PyObject *argsbuf[1];
9882
0
    int status;
9883
0
    int _return_value;
9884
9885
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9886
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9887
0
    if (!args) {
9888
0
        goto exit;
9889
0
    }
9890
0
    status = PyLong_AsInt(args[0]);
9891
0
    if (status == -1 && PyErr_Occurred()) {
9892
0
        goto exit;
9893
0
    }
9894
0
    _return_value = os_WIFSTOPPED_impl(module, status);
9895
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9896
0
        goto exit;
9897
0
    }
9898
0
    return_value = PyBool_FromLong((long)_return_value);
9899
9900
0
exit:
9901
0
    return return_value;
9902
0
}
9903
9904
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
9905
9906
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
9907
9908
PyDoc_STRVAR(os_WIFSIGNALED__doc__,
9909
"WIFSIGNALED($module, /, status)\n"
9910
"--\n"
9911
"\n"
9912
"Return True if the process returning status was terminated by a signal.");
9913
9914
#define OS_WIFSIGNALED_METHODDEF    \
9915
    {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
9916
9917
static int
9918
os_WIFSIGNALED_impl(PyObject *module, int status);
9919
9920
static PyObject *
9921
os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9922
0
{
9923
0
    PyObject *return_value = NULL;
9924
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9925
9926
0
    #define NUM_KEYWORDS 1
9927
0
    static struct {
9928
0
        PyGC_Head _this_is_not_used;
9929
0
        PyObject_VAR_HEAD
9930
0
        Py_hash_t ob_hash;
9931
0
        PyObject *ob_item[NUM_KEYWORDS];
9932
0
    } _kwtuple = {
9933
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9934
0
        .ob_hash = -1,
9935
0
        .ob_item = { &_Py_ID(status), },
9936
0
    };
9937
0
    #undef NUM_KEYWORDS
9938
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9939
9940
    #else  // !Py_BUILD_CORE
9941
    #  define KWTUPLE NULL
9942
    #endif  // !Py_BUILD_CORE
9943
9944
0
    static const char * const _keywords[] = {"status", NULL};
9945
0
    static _PyArg_Parser _parser = {
9946
0
        .keywords = _keywords,
9947
0
        .fname = "WIFSIGNALED",
9948
0
        .kwtuple = KWTUPLE,
9949
0
    };
9950
0
    #undef KWTUPLE
9951
0
    PyObject *argsbuf[1];
9952
0
    int status;
9953
0
    int _return_value;
9954
9955
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9956
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9957
0
    if (!args) {
9958
0
        goto exit;
9959
0
    }
9960
0
    status = PyLong_AsInt(args[0]);
9961
0
    if (status == -1 && PyErr_Occurred()) {
9962
0
        goto exit;
9963
0
    }
9964
0
    _return_value = os_WIFSIGNALED_impl(module, status);
9965
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9966
0
        goto exit;
9967
0
    }
9968
0
    return_value = PyBool_FromLong((long)_return_value);
9969
9970
0
exit:
9971
0
    return return_value;
9972
0
}
9973
9974
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
9975
9976
#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
9977
9978
PyDoc_STRVAR(os_WIFEXITED__doc__,
9979
"WIFEXITED($module, /, status)\n"
9980
"--\n"
9981
"\n"
9982
"Return True if the process returning status exited via the exit() system call.");
9983
9984
#define OS_WIFEXITED_METHODDEF    \
9985
    {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
9986
9987
static int
9988
os_WIFEXITED_impl(PyObject *module, int status);
9989
9990
static PyObject *
9991
os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9992
0
{
9993
0
    PyObject *return_value = NULL;
9994
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9995
9996
0
    #define NUM_KEYWORDS 1
9997
0
    static struct {
9998
0
        PyGC_Head _this_is_not_used;
9999
0
        PyObject_VAR_HEAD
10000
0
        Py_hash_t ob_hash;
10001
0
        PyObject *ob_item[NUM_KEYWORDS];
10002
0
    } _kwtuple = {
10003
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10004
0
        .ob_hash = -1,
10005
0
        .ob_item = { &_Py_ID(status), },
10006
0
    };
10007
0
    #undef NUM_KEYWORDS
10008
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10009
10010
    #else  // !Py_BUILD_CORE
10011
    #  define KWTUPLE NULL
10012
    #endif  // !Py_BUILD_CORE
10013
10014
0
    static const char * const _keywords[] = {"status", NULL};
10015
0
    static _PyArg_Parser _parser = {
10016
0
        .keywords = _keywords,
10017
0
        .fname = "WIFEXITED",
10018
0
        .kwtuple = KWTUPLE,
10019
0
    };
10020
0
    #undef KWTUPLE
10021
0
    PyObject *argsbuf[1];
10022
0
    int status;
10023
0
    int _return_value;
10024
10025
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10026
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10027
0
    if (!args) {
10028
0
        goto exit;
10029
0
    }
10030
0
    status = PyLong_AsInt(args[0]);
10031
0
    if (status == -1 && PyErr_Occurred()) {
10032
0
        goto exit;
10033
0
    }
10034
0
    _return_value = os_WIFEXITED_impl(module, status);
10035
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10036
0
        goto exit;
10037
0
    }
10038
0
    return_value = PyBool_FromLong((long)_return_value);
10039
10040
0
exit:
10041
0
    return return_value;
10042
0
}
10043
10044
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
10045
10046
#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
10047
10048
PyDoc_STRVAR(os_WEXITSTATUS__doc__,
10049
"WEXITSTATUS($module, /, status)\n"
10050
"--\n"
10051
"\n"
10052
"Return the process return code from status.");
10053
10054
#define OS_WEXITSTATUS_METHODDEF    \
10055
    {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
10056
10057
static int
10058
os_WEXITSTATUS_impl(PyObject *module, int status);
10059
10060
static PyObject *
10061
os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10062
0
{
10063
0
    PyObject *return_value = NULL;
10064
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10065
10066
0
    #define NUM_KEYWORDS 1
10067
0
    static struct {
10068
0
        PyGC_Head _this_is_not_used;
10069
0
        PyObject_VAR_HEAD
10070
0
        Py_hash_t ob_hash;
10071
0
        PyObject *ob_item[NUM_KEYWORDS];
10072
0
    } _kwtuple = {
10073
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10074
0
        .ob_hash = -1,
10075
0
        .ob_item = { &_Py_ID(status), },
10076
0
    };
10077
0
    #undef NUM_KEYWORDS
10078
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10079
10080
    #else  // !Py_BUILD_CORE
10081
    #  define KWTUPLE NULL
10082
    #endif  // !Py_BUILD_CORE
10083
10084
0
    static const char * const _keywords[] = {"status", NULL};
10085
0
    static _PyArg_Parser _parser = {
10086
0
        .keywords = _keywords,
10087
0
        .fname = "WEXITSTATUS",
10088
0
        .kwtuple = KWTUPLE,
10089
0
    };
10090
0
    #undef KWTUPLE
10091
0
    PyObject *argsbuf[1];
10092
0
    int status;
10093
0
    int _return_value;
10094
10095
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10096
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10097
0
    if (!args) {
10098
0
        goto exit;
10099
0
    }
10100
0
    status = PyLong_AsInt(args[0]);
10101
0
    if (status == -1 && PyErr_Occurred()) {
10102
0
        goto exit;
10103
0
    }
10104
0
    _return_value = os_WEXITSTATUS_impl(module, status);
10105
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10106
0
        goto exit;
10107
0
    }
10108
0
    return_value = PyLong_FromLong((long)_return_value);
10109
10110
0
exit:
10111
0
    return return_value;
10112
0
}
10113
10114
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
10115
10116
#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
10117
10118
PyDoc_STRVAR(os_WTERMSIG__doc__,
10119
"WTERMSIG($module, /, status)\n"
10120
"--\n"
10121
"\n"
10122
"Return the signal that terminated the process that provided the status value.");
10123
10124
#define OS_WTERMSIG_METHODDEF    \
10125
    {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
10126
10127
static int
10128
os_WTERMSIG_impl(PyObject *module, int status);
10129
10130
static PyObject *
10131
os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10132
0
{
10133
0
    PyObject *return_value = NULL;
10134
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10135
10136
0
    #define NUM_KEYWORDS 1
10137
0
    static struct {
10138
0
        PyGC_Head _this_is_not_used;
10139
0
        PyObject_VAR_HEAD
10140
0
        Py_hash_t ob_hash;
10141
0
        PyObject *ob_item[NUM_KEYWORDS];
10142
0
    } _kwtuple = {
10143
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10144
0
        .ob_hash = -1,
10145
0
        .ob_item = { &_Py_ID(status), },
10146
0
    };
10147
0
    #undef NUM_KEYWORDS
10148
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10149
10150
    #else  // !Py_BUILD_CORE
10151
    #  define KWTUPLE NULL
10152
    #endif  // !Py_BUILD_CORE
10153
10154
0
    static const char * const _keywords[] = {"status", NULL};
10155
0
    static _PyArg_Parser _parser = {
10156
0
        .keywords = _keywords,
10157
0
        .fname = "WTERMSIG",
10158
0
        .kwtuple = KWTUPLE,
10159
0
    };
10160
0
    #undef KWTUPLE
10161
0
    PyObject *argsbuf[1];
10162
0
    int status;
10163
0
    int _return_value;
10164
10165
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10166
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10167
0
    if (!args) {
10168
0
        goto exit;
10169
0
    }
10170
0
    status = PyLong_AsInt(args[0]);
10171
0
    if (status == -1 && PyErr_Occurred()) {
10172
0
        goto exit;
10173
0
    }
10174
0
    _return_value = os_WTERMSIG_impl(module, status);
10175
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10176
0
        goto exit;
10177
0
    }
10178
0
    return_value = PyLong_FromLong((long)_return_value);
10179
10180
0
exit:
10181
0
    return return_value;
10182
0
}
10183
10184
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
10185
10186
#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
10187
10188
PyDoc_STRVAR(os_WSTOPSIG__doc__,
10189
"WSTOPSIG($module, /, status)\n"
10190
"--\n"
10191
"\n"
10192
"Return the signal that stopped the process that provided the status value.");
10193
10194
#define OS_WSTOPSIG_METHODDEF    \
10195
    {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
10196
10197
static int
10198
os_WSTOPSIG_impl(PyObject *module, int status);
10199
10200
static PyObject *
10201
os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10202
0
{
10203
0
    PyObject *return_value = NULL;
10204
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10205
10206
0
    #define NUM_KEYWORDS 1
10207
0
    static struct {
10208
0
        PyGC_Head _this_is_not_used;
10209
0
        PyObject_VAR_HEAD
10210
0
        Py_hash_t ob_hash;
10211
0
        PyObject *ob_item[NUM_KEYWORDS];
10212
0
    } _kwtuple = {
10213
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10214
0
        .ob_hash = -1,
10215
0
        .ob_item = { &_Py_ID(status), },
10216
0
    };
10217
0
    #undef NUM_KEYWORDS
10218
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10219
10220
    #else  // !Py_BUILD_CORE
10221
    #  define KWTUPLE NULL
10222
    #endif  // !Py_BUILD_CORE
10223
10224
0
    static const char * const _keywords[] = {"status", NULL};
10225
0
    static _PyArg_Parser _parser = {
10226
0
        .keywords = _keywords,
10227
0
        .fname = "WSTOPSIG",
10228
0
        .kwtuple = KWTUPLE,
10229
0
    };
10230
0
    #undef KWTUPLE
10231
0
    PyObject *argsbuf[1];
10232
0
    int status;
10233
0
    int _return_value;
10234
10235
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10236
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10237
0
    if (!args) {
10238
0
        goto exit;
10239
0
    }
10240
0
    status = PyLong_AsInt(args[0]);
10241
0
    if (status == -1 && PyErr_Occurred()) {
10242
0
        goto exit;
10243
0
    }
10244
0
    _return_value = os_WSTOPSIG_impl(module, status);
10245
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10246
0
        goto exit;
10247
0
    }
10248
0
    return_value = PyLong_FromLong((long)_return_value);
10249
10250
0
exit:
10251
0
    return return_value;
10252
0
}
10253
10254
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
10255
10256
#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
10257
10258
PyDoc_STRVAR(os_fstatvfs__doc__,
10259
"fstatvfs($module, fd, /)\n"
10260
"--\n"
10261
"\n"
10262
"Perform an fstatvfs system call on the given fd.\n"
10263
"\n"
10264
"Equivalent to statvfs(fd).");
10265
10266
#define OS_FSTATVFS_METHODDEF    \
10267
    {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
10268
10269
static PyObject *
10270
os_fstatvfs_impl(PyObject *module, int fd);
10271
10272
static PyObject *
10273
os_fstatvfs(PyObject *module, PyObject *arg)
10274
0
{
10275
0
    PyObject *return_value = NULL;
10276
0
    int fd;
10277
10278
0
    fd = PyLong_AsInt(arg);
10279
0
    if (fd == -1 && PyErr_Occurred()) {
10280
0
        goto exit;
10281
0
    }
10282
0
    return_value = os_fstatvfs_impl(module, fd);
10283
10284
0
exit:
10285
0
    return return_value;
10286
0
}
10287
10288
#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10289
10290
#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
10291
10292
PyDoc_STRVAR(os_statvfs__doc__,
10293
"statvfs($module, /, path)\n"
10294
"--\n"
10295
"\n"
10296
"Perform a statvfs system call on the given path.\n"
10297
"\n"
10298
"path may always be specified as a string.\n"
10299
"On some platforms, path may also be specified as an open file descriptor.\n"
10300
"  If this functionality is unavailable, using it raises an exception.");
10301
10302
#define OS_STATVFS_METHODDEF    \
10303
    {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
10304
10305
static PyObject *
10306
os_statvfs_impl(PyObject *module, path_t *path);
10307
10308
static PyObject *
10309
os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10310
0
{
10311
0
    PyObject *return_value = NULL;
10312
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10313
10314
0
    #define NUM_KEYWORDS 1
10315
0
    static struct {
10316
0
        PyGC_Head _this_is_not_used;
10317
0
        PyObject_VAR_HEAD
10318
0
        Py_hash_t ob_hash;
10319
0
        PyObject *ob_item[NUM_KEYWORDS];
10320
0
    } _kwtuple = {
10321
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10322
0
        .ob_hash = -1,
10323
0
        .ob_item = { &_Py_ID(path), },
10324
0
    };
10325
0
    #undef NUM_KEYWORDS
10326
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10327
10328
    #else  // !Py_BUILD_CORE
10329
    #  define KWTUPLE NULL
10330
    #endif  // !Py_BUILD_CORE
10331
10332
0
    static const char * const _keywords[] = {"path", NULL};
10333
0
    static _PyArg_Parser _parser = {
10334
0
        .keywords = _keywords,
10335
0
        .fname = "statvfs",
10336
0
        .kwtuple = KWTUPLE,
10337
0
    };
10338
0
    #undef KWTUPLE
10339
0
    PyObject *argsbuf[1];
10340
0
    path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS);
10341
10342
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10343
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10344
0
    if (!args) {
10345
0
        goto exit;
10346
0
    }
10347
0
    if (!path_converter(args[0], &path)) {
10348
0
        goto exit;
10349
0
    }
10350
0
    return_value = os_statvfs_impl(module, &path);
10351
10352
0
exit:
10353
    /* Cleanup for path */
10354
0
    path_cleanup(&path);
10355
10356
0
    return return_value;
10357
0
}
10358
10359
#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10360
10361
#if defined(MS_WINDOWS)
10362
10363
PyDoc_STRVAR(os__getdiskusage__doc__,
10364
"_getdiskusage($module, /, path)\n"
10365
"--\n"
10366
"\n"
10367
"Return disk usage statistics about the given path as a (total, free) tuple.");
10368
10369
#define OS__GETDISKUSAGE_METHODDEF    \
10370
    {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
10371
10372
static PyObject *
10373
os__getdiskusage_impl(PyObject *module, path_t *path);
10374
10375
static PyObject *
10376
os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10377
{
10378
    PyObject *return_value = NULL;
10379
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10380
10381
    #define NUM_KEYWORDS 1
10382
    static struct {
10383
        PyGC_Head _this_is_not_used;
10384
        PyObject_VAR_HEAD
10385
        Py_hash_t ob_hash;
10386
        PyObject *ob_item[NUM_KEYWORDS];
10387
    } _kwtuple = {
10388
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10389
        .ob_hash = -1,
10390
        .ob_item = { &_Py_ID(path), },
10391
    };
10392
    #undef NUM_KEYWORDS
10393
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10394
10395
    #else  // !Py_BUILD_CORE
10396
    #  define KWTUPLE NULL
10397
    #endif  // !Py_BUILD_CORE
10398
10399
    static const char * const _keywords[] = {"path", NULL};
10400
    static _PyArg_Parser _parser = {
10401
        .keywords = _keywords,
10402
        .fname = "_getdiskusage",
10403
        .kwtuple = KWTUPLE,
10404
    };
10405
    #undef KWTUPLE
10406
    PyObject *argsbuf[1];
10407
    path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0);
10408
10409
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10410
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10411
    if (!args) {
10412
        goto exit;
10413
    }
10414
    if (!path_converter(args[0], &path)) {
10415
        goto exit;
10416
    }
10417
    return_value = os__getdiskusage_impl(module, &path);
10418
10419
exit:
10420
    /* Cleanup for path */
10421
    path_cleanup(&path);
10422
10423
    return return_value;
10424
}
10425
10426
#endif /* defined(MS_WINDOWS) */
10427
10428
#if defined(HAVE_FPATHCONF)
10429
10430
PyDoc_STRVAR(os_fpathconf__doc__,
10431
"fpathconf($module, fd, name, /)\n"
10432
"--\n"
10433
"\n"
10434
"Return the configuration limit name for the file descriptor fd.\n"
10435
"\n"
10436
"If there is no limit, return -1.");
10437
10438
#define OS_FPATHCONF_METHODDEF    \
10439
    {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__},
10440
10441
static long
10442
os_fpathconf_impl(PyObject *module, int fd, int name);
10443
10444
static PyObject *
10445
os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10446
0
{
10447
0
    PyObject *return_value = NULL;
10448
0
    int fd;
10449
0
    int name;
10450
0
    long _return_value;
10451
10452
0
    if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
10453
0
        goto exit;
10454
0
    }
10455
0
    fd = PyObject_AsFileDescriptor(args[0]);
10456
0
    if (fd < 0) {
10457
0
        goto exit;
10458
0
    }
10459
0
    if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10460
0
        goto exit;
10461
0
    }
10462
0
    _return_value = os_fpathconf_impl(module, fd, name);
10463
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10464
0
        goto exit;
10465
0
    }
10466
0
    return_value = PyLong_FromLong(_return_value);
10467
10468
0
exit:
10469
0
    return return_value;
10470
0
}
10471
10472
#endif /* defined(HAVE_FPATHCONF) */
10473
10474
#if defined(HAVE_PATHCONF)
10475
10476
PyDoc_STRVAR(os_pathconf__doc__,
10477
"pathconf($module, /, path, name)\n"
10478
"--\n"
10479
"\n"
10480
"Return the configuration limit name for the file or directory path.\n"
10481
"\n"
10482
"If there is no limit, return -1.\n"
10483
"On some platforms, path may also be specified as an open file descriptor.\n"
10484
"  If this functionality is unavailable, using it raises an exception.");
10485
10486
#define OS_PATHCONF_METHODDEF    \
10487
    {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
10488
10489
static long
10490
os_pathconf_impl(PyObject *module, path_t *path, int name);
10491
10492
static PyObject *
10493
os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10494
0
{
10495
0
    PyObject *return_value = NULL;
10496
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10497
10498
0
    #define NUM_KEYWORDS 2
10499
0
    static struct {
10500
0
        PyGC_Head _this_is_not_used;
10501
0
        PyObject_VAR_HEAD
10502
0
        Py_hash_t ob_hash;
10503
0
        PyObject *ob_item[NUM_KEYWORDS];
10504
0
    } _kwtuple = {
10505
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10506
0
        .ob_hash = -1,
10507
0
        .ob_item = { &_Py_ID(path), &_Py_ID(name), },
10508
0
    };
10509
0
    #undef NUM_KEYWORDS
10510
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10511
10512
    #else  // !Py_BUILD_CORE
10513
    #  define KWTUPLE NULL
10514
    #endif  // !Py_BUILD_CORE
10515
10516
0
    static const char * const _keywords[] = {"path", "name", NULL};
10517
0
    static _PyArg_Parser _parser = {
10518
0
        .keywords = _keywords,
10519
0
        .fname = "pathconf",
10520
0
        .kwtuple = KWTUPLE,
10521
0
    };
10522
0
    #undef KWTUPLE
10523
0
    PyObject *argsbuf[2];
10524
0
    path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF);
10525
0
    int name;
10526
0
    long _return_value;
10527
10528
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10529
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10530
0
    if (!args) {
10531
0
        goto exit;
10532
0
    }
10533
0
    if (!path_converter(args[0], &path)) {
10534
0
        goto exit;
10535
0
    }
10536
0
    if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10537
0
        goto exit;
10538
0
    }
10539
0
    _return_value = os_pathconf_impl(module, &path, name);
10540
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10541
0
        goto exit;
10542
0
    }
10543
0
    return_value = PyLong_FromLong(_return_value);
10544
10545
0
exit:
10546
    /* Cleanup for path */
10547
0
    path_cleanup(&path);
10548
10549
0
    return return_value;
10550
0
}
10551
10552
#endif /* defined(HAVE_PATHCONF) */
10553
10554
#if defined(HAVE_CONFSTR)
10555
10556
PyDoc_STRVAR(os_confstr__doc__,
10557
"confstr($module, name, /)\n"
10558
"--\n"
10559
"\n"
10560
"Return a string-valued system configuration variable.");
10561
10562
#define OS_CONFSTR_METHODDEF    \
10563
    {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
10564
10565
static PyObject *
10566
os_confstr_impl(PyObject *module, int name);
10567
10568
static PyObject *
10569
os_confstr(PyObject *module, PyObject *arg)
10570
0
{
10571
0
    PyObject *return_value = NULL;
10572
0
    int name;
10573
10574
0
    if (!conv_confname(module, arg, &name, "confstr_names")) {
10575
0
        goto exit;
10576
0
    }
10577
0
    return_value = os_confstr_impl(module, name);
10578
10579
0
exit:
10580
0
    return return_value;
10581
0
}
10582
10583
#endif /* defined(HAVE_CONFSTR) */
10584
10585
#if defined(HAVE_SYSCONF)
10586
10587
PyDoc_STRVAR(os_sysconf__doc__,
10588
"sysconf($module, name, /)\n"
10589
"--\n"
10590
"\n"
10591
"Return an integer-valued system configuration variable.");
10592
10593
#define OS_SYSCONF_METHODDEF    \
10594
    {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
10595
10596
static long
10597
os_sysconf_impl(PyObject *module, int name);
10598
10599
static PyObject *
10600
os_sysconf(PyObject *module, PyObject *arg)
10601
0
{
10602
0
    PyObject *return_value = NULL;
10603
0
    int name;
10604
0
    long _return_value;
10605
10606
0
    if (!conv_confname(module, arg, &name, "sysconf_names")) {
10607
0
        goto exit;
10608
0
    }
10609
0
    _return_value = os_sysconf_impl(module, name);
10610
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10611
0
        goto exit;
10612
0
    }
10613
0
    return_value = PyLong_FromLong(_return_value);
10614
10615
0
exit:
10616
0
    return return_value;
10617
0
}
10618
10619
#endif /* defined(HAVE_SYSCONF) */
10620
10621
PyDoc_STRVAR(os_abort__doc__,
10622
"abort($module, /)\n"
10623
"--\n"
10624
"\n"
10625
"Abort the interpreter immediately.\n"
10626
"\n"
10627
"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
10628
"on the hosting operating system.  This function never returns.");
10629
10630
#define OS_ABORT_METHODDEF    \
10631
    {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
10632
10633
static PyObject *
10634
os_abort_impl(PyObject *module);
10635
10636
static PyObject *
10637
os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
10638
0
{
10639
0
    return os_abort_impl(module);
10640
0
}
10641
10642
#if defined(MS_WINDOWS)
10643
10644
PyDoc_STRVAR(os_startfile__doc__,
10645
"startfile($module, /, filepath, operation=<unrepresentable>,\n"
10646
"          arguments=<unrepresentable>, cwd=None, show_cmd=1)\n"
10647
"--\n"
10648
"\n"
10649
"Start a file with its associated application.\n"
10650
"\n"
10651
"When \"operation\" is not specified or \"open\", this acts like\n"
10652
"double-clicking the file in Explorer, or giving the file name as an\n"
10653
"argument to the DOS \"start\" command: the file is opened with whatever\n"
10654
"application (if any) its extension is associated.\n"
10655
"When another \"operation\" is given, it specifies what should be done with\n"
10656
"the file.  A typical operation is \"print\".\n"
10657
"\n"
10658
"\"arguments\" is passed to the application, but should be omitted if the\n"
10659
"file is a document.\n"
10660
"\n"
10661
"\"cwd\" is the working directory for the operation. If \"filepath\" is\n"
10662
"relative, it will be resolved against this directory. This argument\n"
10663
"should usually be an absolute path.\n"
10664
"\n"
10665
"\"show_cmd\" can be used to override the recommended visibility option.\n"
10666
"See the Windows ShellExecute documentation for values.\n"
10667
"\n"
10668
"startfile returns as soon as the associated application is launched.\n"
10669
"There is no option to wait for the application to close, and no way\n"
10670
"to retrieve the application\'s exit status.\n"
10671
"\n"
10672
"The filepath is relative to the current directory.  If you want to use\n"
10673
"an absolute path, make sure the first character is not a slash (\"/\");\n"
10674
"the underlying Win32 ShellExecute function doesn\'t work if it is.");
10675
10676
#define OS_STARTFILE_METHODDEF    \
10677
    {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
10678
10679
static PyObject *
10680
os_startfile_impl(PyObject *module, path_t *filepath,
10681
                  const wchar_t *operation, const wchar_t *arguments,
10682
                  path_t *cwd, int show_cmd);
10683
10684
static PyObject *
10685
os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10686
{
10687
    PyObject *return_value = NULL;
10688
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10689
10690
    #define NUM_KEYWORDS 5
10691
    static struct {
10692
        PyGC_Head _this_is_not_used;
10693
        PyObject_VAR_HEAD
10694
        Py_hash_t ob_hash;
10695
        PyObject *ob_item[NUM_KEYWORDS];
10696
    } _kwtuple = {
10697
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10698
        .ob_hash = -1,
10699
        .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), },
10700
    };
10701
    #undef NUM_KEYWORDS
10702
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10703
10704
    #else  // !Py_BUILD_CORE
10705
    #  define KWTUPLE NULL
10706
    #endif  // !Py_BUILD_CORE
10707
10708
    static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL};
10709
    static _PyArg_Parser _parser = {
10710
        .keywords = _keywords,
10711
        .fname = "startfile",
10712
        .kwtuple = KWTUPLE,
10713
    };
10714
    #undef KWTUPLE
10715
    PyObject *argsbuf[5];
10716
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
10717
    path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0);
10718
    const wchar_t *operation = NULL;
10719
    const wchar_t *arguments = NULL;
10720
    path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0);
10721
    int show_cmd = 1;
10722
10723
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10724
            /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10725
    if (!args) {
10726
        goto exit;
10727
    }
10728
    if (!path_converter(args[0], &filepath)) {
10729
        goto exit;
10730
    }
10731
    if (!noptargs) {
10732
        goto skip_optional_pos;
10733
    }
10734
    if (args[1]) {
10735
        if (!PyUnicode_Check(args[1])) {
10736
            _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]);
10737
            goto exit;
10738
        }
10739
        operation = PyUnicode_AsWideCharString(args[1], NULL);
10740
        if (operation == NULL) {
10741
            goto exit;
10742
        }
10743
        if (!--noptargs) {
10744
            goto skip_optional_pos;
10745
        }
10746
    }
10747
    if (args[2]) {
10748
        if (!PyUnicode_Check(args[2])) {
10749
            _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]);
10750
            goto exit;
10751
        }
10752
        arguments = PyUnicode_AsWideCharString(args[2], NULL);
10753
        if (arguments == NULL) {
10754
            goto exit;
10755
        }
10756
        if (!--noptargs) {
10757
            goto skip_optional_pos;
10758
        }
10759
    }
10760
    if (args[3]) {
10761
        if (!path_converter(args[3], &cwd)) {
10762
            goto exit;
10763
        }
10764
        if (!--noptargs) {
10765
            goto skip_optional_pos;
10766
        }
10767
    }
10768
    show_cmd = PyLong_AsInt(args[4]);
10769
    if (show_cmd == -1 && PyErr_Occurred()) {
10770
        goto exit;
10771
    }
10772
skip_optional_pos:
10773
    return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd);
10774
10775
exit:
10776
    /* Cleanup for filepath */
10777
    path_cleanup(&filepath);
10778
    /* Cleanup for operation */
10779
    PyMem_Free((void *)operation);
10780
    /* Cleanup for arguments */
10781
    PyMem_Free((void *)arguments);
10782
    /* Cleanup for cwd */
10783
    path_cleanup(&cwd);
10784
10785
    return return_value;
10786
}
10787
10788
#endif /* defined(MS_WINDOWS) */
10789
10790
#if defined(HAVE_GETLOADAVG)
10791
10792
PyDoc_STRVAR(os_getloadavg__doc__,
10793
"getloadavg($module, /)\n"
10794
"--\n"
10795
"\n"
10796
"Return average recent system load information.\n"
10797
"\n"
10798
"Return the number of processes in the system run queue averaged over\n"
10799
"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
10800
"Raises OSError if the load average was unobtainable.");
10801
10802
#define OS_GETLOADAVG_METHODDEF    \
10803
    {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
10804
10805
static PyObject *
10806
os_getloadavg_impl(PyObject *module);
10807
10808
static PyObject *
10809
os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
10810
0
{
10811
0
    return os_getloadavg_impl(module);
10812
0
}
10813
10814
#endif /* defined(HAVE_GETLOADAVG) */
10815
10816
PyDoc_STRVAR(os_device_encoding__doc__,
10817
"device_encoding($module, /, fd)\n"
10818
"--\n"
10819
"\n"
10820
"Return a string describing the encoding of a terminal\'s file descriptor.\n"
10821
"\n"
10822
"The file descriptor must be attached to a terminal.\n"
10823
"If the device is not a terminal, return None.");
10824
10825
#define OS_DEVICE_ENCODING_METHODDEF    \
10826
    {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
10827
10828
static PyObject *
10829
os_device_encoding_impl(PyObject *module, int fd);
10830
10831
static PyObject *
10832
os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10833
0
{
10834
0
    PyObject *return_value = NULL;
10835
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10836
10837
0
    #define NUM_KEYWORDS 1
10838
0
    static struct {
10839
0
        PyGC_Head _this_is_not_used;
10840
0
        PyObject_VAR_HEAD
10841
0
        Py_hash_t ob_hash;
10842
0
        PyObject *ob_item[NUM_KEYWORDS];
10843
0
    } _kwtuple = {
10844
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10845
0
        .ob_hash = -1,
10846
0
        .ob_item = { &_Py_ID(fd), },
10847
0
    };
10848
0
    #undef NUM_KEYWORDS
10849
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10850
10851
    #else  // !Py_BUILD_CORE
10852
    #  define KWTUPLE NULL
10853
    #endif  // !Py_BUILD_CORE
10854
10855
0
    static const char * const _keywords[] = {"fd", NULL};
10856
0
    static _PyArg_Parser _parser = {
10857
0
        .keywords = _keywords,
10858
0
        .fname = "device_encoding",
10859
0
        .kwtuple = KWTUPLE,
10860
0
    };
10861
0
    #undef KWTUPLE
10862
0
    PyObject *argsbuf[1];
10863
0
    int fd;
10864
10865
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10866
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10867
0
    if (!args) {
10868
0
        goto exit;
10869
0
    }
10870
0
    fd = PyLong_AsInt(args[0]);
10871
0
    if (fd == -1 && PyErr_Occurred()) {
10872
0
        goto exit;
10873
0
    }
10874
0
    return_value = os_device_encoding_impl(module, fd);
10875
10876
0
exit:
10877
0
    return return_value;
10878
0
}
10879
10880
#if defined(HAVE_SETRESUID)
10881
10882
PyDoc_STRVAR(os_setresuid__doc__,
10883
"setresuid($module, ruid, euid, suid, /)\n"
10884
"--\n"
10885
"\n"
10886
"Set the current process\'s real, effective, and saved user ids.");
10887
10888
#define OS_SETRESUID_METHODDEF    \
10889
    {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__},
10890
10891
static PyObject *
10892
os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
10893
10894
static PyObject *
10895
os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10896
0
{
10897
0
    PyObject *return_value = NULL;
10898
0
    uid_t ruid;
10899
0
    uid_t euid;
10900
0
    uid_t suid;
10901
10902
0
    if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
10903
0
        goto exit;
10904
0
    }
10905
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
10906
0
        goto exit;
10907
0
    }
10908
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
10909
0
        goto exit;
10910
0
    }
10911
0
    if (!_Py_Uid_Converter(args[2], &suid)) {
10912
0
        goto exit;
10913
0
    }
10914
0
    return_value = os_setresuid_impl(module, ruid, euid, suid);
10915
10916
0
exit:
10917
0
    return return_value;
10918
0
}
10919
10920
#endif /* defined(HAVE_SETRESUID) */
10921
10922
#if defined(HAVE_SETRESGID)
10923
10924
PyDoc_STRVAR(os_setresgid__doc__,
10925
"setresgid($module, rgid, egid, sgid, /)\n"
10926
"--\n"
10927
"\n"
10928
"Set the current process\'s real, effective, and saved group ids.");
10929
10930
#define OS_SETRESGID_METHODDEF    \
10931
    {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__},
10932
10933
static PyObject *
10934
os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
10935
10936
static PyObject *
10937
os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10938
0
{
10939
0
    PyObject *return_value = NULL;
10940
0
    gid_t rgid;
10941
0
    gid_t egid;
10942
0
    gid_t sgid;
10943
10944
0
    if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
10945
0
        goto exit;
10946
0
    }
10947
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
10948
0
        goto exit;
10949
0
    }
10950
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
10951
0
        goto exit;
10952
0
    }
10953
0
    if (!_Py_Gid_Converter(args[2], &sgid)) {
10954
0
        goto exit;
10955
0
    }
10956
0
    return_value = os_setresgid_impl(module, rgid, egid, sgid);
10957
10958
0
exit:
10959
0
    return return_value;
10960
0
}
10961
10962
#endif /* defined(HAVE_SETRESGID) */
10963
10964
#if defined(HAVE_GETRESUID)
10965
10966
PyDoc_STRVAR(os_getresuid__doc__,
10967
"getresuid($module, /)\n"
10968
"--\n"
10969
"\n"
10970
"Return a tuple of the current process\'s real, effective, and saved user ids.");
10971
10972
#define OS_GETRESUID_METHODDEF    \
10973
    {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
10974
10975
static PyObject *
10976
os_getresuid_impl(PyObject *module);
10977
10978
static PyObject *
10979
os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
10980
0
{
10981
0
    return os_getresuid_impl(module);
10982
0
}
10983
10984
#endif /* defined(HAVE_GETRESUID) */
10985
10986
#if defined(HAVE_GETRESGID)
10987
10988
PyDoc_STRVAR(os_getresgid__doc__,
10989
"getresgid($module, /)\n"
10990
"--\n"
10991
"\n"
10992
"Return a tuple of the current process\'s real, effective, and saved group ids.");
10993
10994
#define OS_GETRESGID_METHODDEF    \
10995
    {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
10996
10997
static PyObject *
10998
os_getresgid_impl(PyObject *module);
10999
11000
static PyObject *
11001
os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
11002
0
{
11003
0
    return os_getresgid_impl(module);
11004
0
}
11005
11006
#endif /* defined(HAVE_GETRESGID) */
11007
11008
#if defined(USE_XATTRS)
11009
11010
PyDoc_STRVAR(os_getxattr__doc__,
11011
"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
11012
"--\n"
11013
"\n"
11014
"Return the value of extended attribute attribute on path.\n"
11015
"\n"
11016
"path may be either a string, a path-like object, or an open file descriptor.\n"
11017
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
11018
"  link, getxattr will examine the symbolic link itself instead of the file\n"
11019
"  the link points to.");
11020
11021
#define OS_GETXATTR_METHODDEF    \
11022
    {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
11023
11024
static PyObject *
11025
os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
11026
                 int follow_symlinks);
11027
11028
static PyObject *
11029
os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11030
0
{
11031
0
    PyObject *return_value = NULL;
11032
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11033
11034
0
    #define NUM_KEYWORDS 3
11035
0
    static struct {
11036
0
        PyGC_Head _this_is_not_used;
11037
0
        PyObject_VAR_HEAD
11038
0
        Py_hash_t ob_hash;
11039
0
        PyObject *ob_item[NUM_KEYWORDS];
11040
0
    } _kwtuple = {
11041
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11042
0
        .ob_hash = -1,
11043
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
11044
0
    };
11045
0
    #undef NUM_KEYWORDS
11046
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11047
11048
    #else  // !Py_BUILD_CORE
11049
    #  define KWTUPLE NULL
11050
    #endif  // !Py_BUILD_CORE
11051
11052
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
11053
0
    static _PyArg_Parser _parser = {
11054
0
        .keywords = _keywords,
11055
0
        .fname = "getxattr",
11056
0
        .kwtuple = KWTUPLE,
11057
0
    };
11058
0
    #undef KWTUPLE
11059
0
    PyObject *argsbuf[3];
11060
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
11061
0
    path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1);
11062
0
    path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0);
11063
0
    int follow_symlinks = 1;
11064
11065
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11066
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11067
0
    if (!args) {
11068
0
        goto exit;
11069
0
    }
11070
0
    if (!path_converter(args[0], &path)) {
11071
0
        goto exit;
11072
0
    }
11073
0
    if (!path_converter(args[1], &attribute)) {
11074
0
        goto exit;
11075
0
    }
11076
0
    if (!noptargs) {
11077
0
        goto skip_optional_kwonly;
11078
0
    }
11079
0
    follow_symlinks = PyObject_IsTrue(args[2]);
11080
0
    if (follow_symlinks < 0) {
11081
0
        goto exit;
11082
0
    }
11083
0
skip_optional_kwonly:
11084
0
    return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
11085
11086
0
exit:
11087
    /* Cleanup for path */
11088
0
    path_cleanup(&path);
11089
    /* Cleanup for attribute */
11090
0
    path_cleanup(&attribute);
11091
11092
0
    return return_value;
11093
0
}
11094
11095
#endif /* defined(USE_XATTRS) */
11096
11097
#if defined(USE_XATTRS)
11098
11099
PyDoc_STRVAR(os_setxattr__doc__,
11100
"setxattr($module, /, path, attribute, value, flags=0, *,\n"
11101
"         follow_symlinks=True)\n"
11102
"--\n"
11103
"\n"
11104
"Set extended attribute attribute on path to value.\n"
11105
"\n"
11106
"path may be either a string, a path-like object,  or an open file descriptor.\n"
11107
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
11108
"  link, setxattr will modify the symbolic link itself instead of the file\n"
11109
"  the link points to.");
11110
11111
#define OS_SETXATTR_METHODDEF    \
11112
    {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
11113
11114
static PyObject *
11115
os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
11116
                 Py_buffer *value, int flags, int follow_symlinks);
11117
11118
static PyObject *
11119
os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11120
0
{
11121
0
    PyObject *return_value = NULL;
11122
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11123
11124
0
    #define NUM_KEYWORDS 5
11125
0
    static struct {
11126
0
        PyGC_Head _this_is_not_used;
11127
0
        PyObject_VAR_HEAD
11128
0
        Py_hash_t ob_hash;
11129
0
        PyObject *ob_item[NUM_KEYWORDS];
11130
0
    } _kwtuple = {
11131
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11132
0
        .ob_hash = -1,
11133
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
11134
0
    };
11135
0
    #undef NUM_KEYWORDS
11136
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11137
11138
    #else  // !Py_BUILD_CORE
11139
    #  define KWTUPLE NULL
11140
    #endif  // !Py_BUILD_CORE
11141
11142
0
    static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
11143
0
    static _PyArg_Parser _parser = {
11144
0
        .keywords = _keywords,
11145
0
        .fname = "setxattr",
11146
0
        .kwtuple = KWTUPLE,
11147
0
    };
11148
0
    #undef KWTUPLE
11149
0
    PyObject *argsbuf[5];
11150
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
11151
0
    path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1);
11152
0
    path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0);
11153
0
    Py_buffer value = {NULL, NULL};
11154
0
    int flags = 0;
11155
0
    int follow_symlinks = 1;
11156
11157
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11158
0
            /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11159
0
    if (!args) {
11160
0
        goto exit;
11161
0
    }
11162
0
    if (!path_converter(args[0], &path)) {
11163
0
        goto exit;
11164
0
    }
11165
0
    if (!path_converter(args[1], &attribute)) {
11166
0
        goto exit;
11167
0
    }
11168
0
    if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
11169
0
        goto exit;
11170
0
    }
11171
0
    if (!noptargs) {
11172
0
        goto skip_optional_pos;
11173
0
    }
11174
0
    if (args[3]) {
11175
0
        flags = PyLong_AsInt(args[3]);
11176
0
        if (flags == -1 && PyErr_Occurred()) {
11177
0
            goto exit;
11178
0
        }
11179
0
        if (!--noptargs) {
11180
0
            goto skip_optional_pos;
11181
0
        }
11182
0
    }
11183
0
skip_optional_pos:
11184
0
    if (!noptargs) {
11185
0
        goto skip_optional_kwonly;
11186
0
    }
11187
0
    follow_symlinks = PyObject_IsTrue(args[4]);
11188
0
    if (follow_symlinks < 0) {
11189
0
        goto exit;
11190
0
    }
11191
0
skip_optional_kwonly:
11192
0
    return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
11193
11194
0
exit:
11195
    /* Cleanup for path */
11196
0
    path_cleanup(&path);
11197
    /* Cleanup for attribute */
11198
0
    path_cleanup(&attribute);
11199
    /* Cleanup for value */
11200
0
    if (value.obj) {
11201
0
       PyBuffer_Release(&value);
11202
0
    }
11203
11204
0
    return return_value;
11205
0
}
11206
11207
#endif /* defined(USE_XATTRS) */
11208
11209
#if defined(USE_XATTRS)
11210
11211
PyDoc_STRVAR(os_removexattr__doc__,
11212
"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
11213
"--\n"
11214
"\n"
11215
"Remove extended attribute attribute on path.\n"
11216
"\n"
11217
"path may be either a string, a path-like object, or an open file descriptor.\n"
11218
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
11219
"  link, removexattr will modify the symbolic link itself instead of the file\n"
11220
"  the link points to.");
11221
11222
#define OS_REMOVEXATTR_METHODDEF    \
11223
    {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
11224
11225
static PyObject *
11226
os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
11227
                    int follow_symlinks);
11228
11229
static PyObject *
11230
os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11231
0
{
11232
0
    PyObject *return_value = NULL;
11233
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11234
11235
0
    #define NUM_KEYWORDS 3
11236
0
    static struct {
11237
0
        PyGC_Head _this_is_not_used;
11238
0
        PyObject_VAR_HEAD
11239
0
        Py_hash_t ob_hash;
11240
0
        PyObject *ob_item[NUM_KEYWORDS];
11241
0
    } _kwtuple = {
11242
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11243
0
        .ob_hash = -1,
11244
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
11245
0
    };
11246
0
    #undef NUM_KEYWORDS
11247
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11248
11249
    #else  // !Py_BUILD_CORE
11250
    #  define KWTUPLE NULL
11251
    #endif  // !Py_BUILD_CORE
11252
11253
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
11254
0
    static _PyArg_Parser _parser = {
11255
0
        .keywords = _keywords,
11256
0
        .fname = "removexattr",
11257
0
        .kwtuple = KWTUPLE,
11258
0
    };
11259
0
    #undef KWTUPLE
11260
0
    PyObject *argsbuf[3];
11261
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
11262
0
    path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1);
11263
0
    path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0);
11264
0
    int follow_symlinks = 1;
11265
11266
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11267
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11268
0
    if (!args) {
11269
0
        goto exit;
11270
0
    }
11271
0
    if (!path_converter(args[0], &path)) {
11272
0
        goto exit;
11273
0
    }
11274
0
    if (!path_converter(args[1], &attribute)) {
11275
0
        goto exit;
11276
0
    }
11277
0
    if (!noptargs) {
11278
0
        goto skip_optional_kwonly;
11279
0
    }
11280
0
    follow_symlinks = PyObject_IsTrue(args[2]);
11281
0
    if (follow_symlinks < 0) {
11282
0
        goto exit;
11283
0
    }
11284
0
skip_optional_kwonly:
11285
0
    return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
11286
11287
0
exit:
11288
    /* Cleanup for path */
11289
0
    path_cleanup(&path);
11290
    /* Cleanup for attribute */
11291
0
    path_cleanup(&attribute);
11292
11293
0
    return return_value;
11294
0
}
11295
11296
#endif /* defined(USE_XATTRS) */
11297
11298
#if defined(USE_XATTRS)
11299
11300
PyDoc_STRVAR(os_listxattr__doc__,
11301
"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
11302
"--\n"
11303
"\n"
11304
"Return a list of extended attributes on path.\n"
11305
"\n"
11306
"path may be either None, a string, a path-like object, or an open file descriptor.\n"
11307
"if path is None, listxattr will examine the current directory.\n"
11308
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
11309
"  link, listxattr will examine the symbolic link itself instead of the file\n"
11310
"  the link points to.");
11311
11312
#define OS_LISTXATTR_METHODDEF    \
11313
    {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
11314
11315
static PyObject *
11316
os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
11317
11318
static PyObject *
11319
os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11320
0
{
11321
0
    PyObject *return_value = NULL;
11322
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11323
11324
0
    #define NUM_KEYWORDS 2
11325
0
    static struct {
11326
0
        PyGC_Head _this_is_not_used;
11327
0
        PyObject_VAR_HEAD
11328
0
        Py_hash_t ob_hash;
11329
0
        PyObject *ob_item[NUM_KEYWORDS];
11330
0
    } _kwtuple = {
11331
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11332
0
        .ob_hash = -1,
11333
0
        .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), },
11334
0
    };
11335
0
    #undef NUM_KEYWORDS
11336
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11337
11338
    #else  // !Py_BUILD_CORE
11339
    #  define KWTUPLE NULL
11340
    #endif  // !Py_BUILD_CORE
11341
11342
0
    static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
11343
0
    static _PyArg_Parser _parser = {
11344
0
        .keywords = _keywords,
11345
0
        .fname = "listxattr",
11346
0
        .kwtuple = KWTUPLE,
11347
0
    };
11348
0
    #undef KWTUPLE
11349
0
    PyObject *argsbuf[2];
11350
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
11351
0
    path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1);
11352
0
    int follow_symlinks = 1;
11353
11354
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11355
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11356
0
    if (!args) {
11357
0
        goto exit;
11358
0
    }
11359
0
    if (!noptargs) {
11360
0
        goto skip_optional_pos;
11361
0
    }
11362
0
    if (args[0]) {
11363
0
        if (!path_converter(args[0], &path)) {
11364
0
            goto exit;
11365
0
        }
11366
0
        if (!--noptargs) {
11367
0
            goto skip_optional_pos;
11368
0
        }
11369
0
    }
11370
0
skip_optional_pos:
11371
0
    if (!noptargs) {
11372
0
        goto skip_optional_kwonly;
11373
0
    }
11374
0
    follow_symlinks = PyObject_IsTrue(args[1]);
11375
0
    if (follow_symlinks < 0) {
11376
0
        goto exit;
11377
0
    }
11378
0
skip_optional_kwonly:
11379
0
    return_value = os_listxattr_impl(module, &path, follow_symlinks);
11380
11381
0
exit:
11382
    /* Cleanup for path */
11383
0
    path_cleanup(&path);
11384
11385
0
    return return_value;
11386
0
}
11387
11388
#endif /* defined(USE_XATTRS) */
11389
11390
PyDoc_STRVAR(os_urandom__doc__,
11391
"urandom($module, size, /)\n"
11392
"--\n"
11393
"\n"
11394
"Return a bytes object containing random bytes suitable for cryptographic use.");
11395
11396
#define OS_URANDOM_METHODDEF    \
11397
    {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
11398
11399
static PyObject *
11400
os_urandom_impl(PyObject *module, Py_ssize_t size);
11401
11402
static PyObject *
11403
os_urandom(PyObject *module, PyObject *arg)
11404
0
{
11405
0
    PyObject *return_value = NULL;
11406
0
    Py_ssize_t size;
11407
11408
0
    {
11409
0
        Py_ssize_t ival = -1;
11410
0
        PyObject *iobj = _PyNumber_Index(arg);
11411
0
        if (iobj != NULL) {
11412
0
            ival = PyLong_AsSsize_t(iobj);
11413
0
            Py_DECREF(iobj);
11414
0
        }
11415
0
        if (ival == -1 && PyErr_Occurred()) {
11416
0
            goto exit;
11417
0
        }
11418
0
        size = ival;
11419
0
        if (size < 0) {
11420
0
            PyErr_SetString(PyExc_ValueError,
11421
0
                            "size cannot be negative");
11422
0
            goto exit;
11423
0
        }
11424
0
    }
11425
0
    return_value = os_urandom_impl(module, size);
11426
11427
0
exit:
11428
0
    return return_value;
11429
0
}
11430
11431
#if defined(HAVE_MEMFD_CREATE)
11432
11433
PyDoc_STRVAR(os_memfd_create__doc__,
11434
"memfd_create($module, /, name, flags=MFD_CLOEXEC)\n"
11435
"--\n"
11436
"\n");
11437
11438
#define OS_MEMFD_CREATE_METHODDEF    \
11439
    {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__},
11440
11441
static PyObject *
11442
os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags);
11443
11444
static PyObject *
11445
os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11446
0
{
11447
0
    PyObject *return_value = NULL;
11448
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11449
11450
0
    #define NUM_KEYWORDS 2
11451
0
    static struct {
11452
0
        PyGC_Head _this_is_not_used;
11453
0
        PyObject_VAR_HEAD
11454
0
        Py_hash_t ob_hash;
11455
0
        PyObject *ob_item[NUM_KEYWORDS];
11456
0
    } _kwtuple = {
11457
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11458
0
        .ob_hash = -1,
11459
0
        .ob_item = { &_Py_ID(name), &_Py_ID(flags), },
11460
0
    };
11461
0
    #undef NUM_KEYWORDS
11462
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11463
11464
    #else  // !Py_BUILD_CORE
11465
    #  define KWTUPLE NULL
11466
    #endif  // !Py_BUILD_CORE
11467
11468
0
    static const char * const _keywords[] = {"name", "flags", NULL};
11469
0
    static _PyArg_Parser _parser = {
11470
0
        .keywords = _keywords,
11471
0
        .fname = "memfd_create",
11472
0
        .kwtuple = KWTUPLE,
11473
0
    };
11474
0
    #undef KWTUPLE
11475
0
    PyObject *argsbuf[2];
11476
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11477
0
    PyObject *name = NULL;
11478
0
    unsigned int flags = MFD_CLOEXEC;
11479
11480
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11481
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11482
0
    if (!args) {
11483
0
        goto exit;
11484
0
    }
11485
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
11486
0
        goto exit;
11487
0
    }
11488
0
    if (!noptargs) {
11489
0
        goto skip_optional_pos;
11490
0
    }
11491
0
    {
11492
0
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned int),
11493
0
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
11494
0
                Py_ASNATIVEBYTES_ALLOW_INDEX |
11495
0
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
11496
0
        if (_bytes < 0) {
11497
0
            goto exit;
11498
0
        }
11499
0
        if ((size_t)_bytes > sizeof(unsigned int)) {
11500
0
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
11501
0
                "integer value out of range", 1) < 0)
11502
0
            {
11503
0
                goto exit;
11504
0
            }
11505
0
        }
11506
0
    }
11507
0
skip_optional_pos:
11508
0
    return_value = os_memfd_create_impl(module, name, flags);
11509
11510
0
exit:
11511
    /* Cleanup for name */
11512
0
    Py_XDECREF(name);
11513
11514
0
    return return_value;
11515
0
}
11516
11517
#endif /* defined(HAVE_MEMFD_CREATE) */
11518
11519
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11520
11521
PyDoc_STRVAR(os_eventfd__doc__,
11522
"eventfd($module, /, initval, flags=EFD_CLOEXEC)\n"
11523
"--\n"
11524
"\n"
11525
"Creates and returns an event notification file descriptor.");
11526
11527
#define OS_EVENTFD_METHODDEF    \
11528
    {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__},
11529
11530
static PyObject *
11531
os_eventfd_impl(PyObject *module, unsigned int initval, int flags);
11532
11533
static PyObject *
11534
os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11535
0
{
11536
0
    PyObject *return_value = NULL;
11537
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11538
11539
0
    #define NUM_KEYWORDS 2
11540
0
    static struct {
11541
0
        PyGC_Head _this_is_not_used;
11542
0
        PyObject_VAR_HEAD
11543
0
        Py_hash_t ob_hash;
11544
0
        PyObject *ob_item[NUM_KEYWORDS];
11545
0
    } _kwtuple = {
11546
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11547
0
        .ob_hash = -1,
11548
0
        .ob_item = { &_Py_ID(initval), &_Py_ID(flags), },
11549
0
    };
11550
0
    #undef NUM_KEYWORDS
11551
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11552
11553
    #else  // !Py_BUILD_CORE
11554
    #  define KWTUPLE NULL
11555
    #endif  // !Py_BUILD_CORE
11556
11557
0
    static const char * const _keywords[] = {"initval", "flags", NULL};
11558
0
    static _PyArg_Parser _parser = {
11559
0
        .keywords = _keywords,
11560
0
        .fname = "eventfd",
11561
0
        .kwtuple = KWTUPLE,
11562
0
    };
11563
0
    #undef KWTUPLE
11564
0
    PyObject *argsbuf[2];
11565
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11566
0
    unsigned int initval;
11567
0
    int flags = EFD_CLOEXEC;
11568
11569
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11570
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11571
0
    if (!args) {
11572
0
        goto exit;
11573
0
    }
11574
0
    if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) {
11575
0
        goto exit;
11576
0
    }
11577
0
    if (!noptargs) {
11578
0
        goto skip_optional_pos;
11579
0
    }
11580
0
    flags = PyLong_AsInt(args[1]);
11581
0
    if (flags == -1 && PyErr_Occurred()) {
11582
0
        goto exit;
11583
0
    }
11584
0
skip_optional_pos:
11585
0
    return_value = os_eventfd_impl(module, initval, flags);
11586
11587
0
exit:
11588
0
    return return_value;
11589
0
}
11590
11591
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11592
11593
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11594
11595
PyDoc_STRVAR(os_eventfd_read__doc__,
11596
"eventfd_read($module, /, fd)\n"
11597
"--\n"
11598
"\n"
11599
"Read eventfd value");
11600
11601
#define OS_EVENTFD_READ_METHODDEF    \
11602
    {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__},
11603
11604
static PyObject *
11605
os_eventfd_read_impl(PyObject *module, int fd);
11606
11607
static PyObject *
11608
os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11609
0
{
11610
0
    PyObject *return_value = NULL;
11611
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11612
11613
0
    #define NUM_KEYWORDS 1
11614
0
    static struct {
11615
0
        PyGC_Head _this_is_not_used;
11616
0
        PyObject_VAR_HEAD
11617
0
        Py_hash_t ob_hash;
11618
0
        PyObject *ob_item[NUM_KEYWORDS];
11619
0
    } _kwtuple = {
11620
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11621
0
        .ob_hash = -1,
11622
0
        .ob_item = { &_Py_ID(fd), },
11623
0
    };
11624
0
    #undef NUM_KEYWORDS
11625
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11626
11627
    #else  // !Py_BUILD_CORE
11628
    #  define KWTUPLE NULL
11629
    #endif  // !Py_BUILD_CORE
11630
11631
0
    static const char * const _keywords[] = {"fd", NULL};
11632
0
    static _PyArg_Parser _parser = {
11633
0
        .keywords = _keywords,
11634
0
        .fname = "eventfd_read",
11635
0
        .kwtuple = KWTUPLE,
11636
0
    };
11637
0
    #undef KWTUPLE
11638
0
    PyObject *argsbuf[1];
11639
0
    int fd;
11640
11641
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11642
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11643
0
    if (!args) {
11644
0
        goto exit;
11645
0
    }
11646
0
    fd = PyObject_AsFileDescriptor(args[0]);
11647
0
    if (fd < 0) {
11648
0
        goto exit;
11649
0
    }
11650
0
    return_value = os_eventfd_read_impl(module, fd);
11651
11652
0
exit:
11653
0
    return return_value;
11654
0
}
11655
11656
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11657
11658
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11659
11660
PyDoc_STRVAR(os_eventfd_write__doc__,
11661
"eventfd_write($module, /, fd, value)\n"
11662
"--\n"
11663
"\n"
11664
"Write eventfd value.");
11665
11666
#define OS_EVENTFD_WRITE_METHODDEF    \
11667
    {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__},
11668
11669
static PyObject *
11670
os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value);
11671
11672
static PyObject *
11673
os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11674
0
{
11675
0
    PyObject *return_value = NULL;
11676
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11677
11678
0
    #define NUM_KEYWORDS 2
11679
0
    static struct {
11680
0
        PyGC_Head _this_is_not_used;
11681
0
        PyObject_VAR_HEAD
11682
0
        Py_hash_t ob_hash;
11683
0
        PyObject *ob_item[NUM_KEYWORDS];
11684
0
    } _kwtuple = {
11685
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11686
0
        .ob_hash = -1,
11687
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(value), },
11688
0
    };
11689
0
    #undef NUM_KEYWORDS
11690
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11691
11692
    #else  // !Py_BUILD_CORE
11693
    #  define KWTUPLE NULL
11694
    #endif  // !Py_BUILD_CORE
11695
11696
0
    static const char * const _keywords[] = {"fd", "value", NULL};
11697
0
    static _PyArg_Parser _parser = {
11698
0
        .keywords = _keywords,
11699
0
        .fname = "eventfd_write",
11700
0
        .kwtuple = KWTUPLE,
11701
0
    };
11702
0
    #undef KWTUPLE
11703
0
    PyObject *argsbuf[2];
11704
0
    int fd;
11705
0
    unsigned long long value;
11706
11707
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11708
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11709
0
    if (!args) {
11710
0
        goto exit;
11711
0
    }
11712
0
    fd = PyObject_AsFileDescriptor(args[0]);
11713
0
    if (fd < 0) {
11714
0
        goto exit;
11715
0
    }
11716
0
    if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) {
11717
0
        goto exit;
11718
0
    }
11719
0
    return_value = os_eventfd_write_impl(module, fd, value);
11720
11721
0
exit:
11722
0
    return return_value;
11723
0
}
11724
11725
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11726
11727
#if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL))
11728
11729
PyDoc_STRVAR(os_get_terminal_size__doc__,
11730
"get_terminal_size($module, fd=<unrepresentable>, /)\n"
11731
"--\n"
11732
"\n"
11733
"Return the size of the terminal window as (columns, lines).\n"
11734
"\n"
11735
"The optional argument fd (default standard output) specifies\n"
11736
"which file descriptor should be queried.\n"
11737
"\n"
11738
"If the file descriptor is not connected to a terminal, an OSError\n"
11739
"is thrown.\n"
11740
"\n"
11741
"This function will only be defined if an implementation is\n"
11742
"available for this system.\n"
11743
"\n"
11744
"shutil.get_terminal_size is the high-level function which should\n"
11745
"normally be used, os.get_terminal_size is the low-level implementation.");
11746
11747
#define OS_GET_TERMINAL_SIZE_METHODDEF    \
11748
    {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__},
11749
11750
static PyObject *
11751
os_get_terminal_size_impl(PyObject *module, int fd);
11752
11753
static PyObject *
11754
os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11755
0
{
11756
0
    PyObject *return_value = NULL;
11757
0
    int fd = fileno(stdout);
11758
11759
0
    if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) {
11760
0
        goto exit;
11761
0
    }
11762
0
    if (nargs < 1) {
11763
0
        goto skip_optional;
11764
0
    }
11765
0
    fd = PyLong_AsInt(args[0]);
11766
0
    if (fd == -1 && PyErr_Occurred()) {
11767
0
        goto exit;
11768
0
    }
11769
0
skip_optional:
11770
0
    return_value = os_get_terminal_size_impl(module, fd);
11771
11772
0
exit:
11773
0
    return return_value;
11774
0
}
11775
11776
#endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */
11777
11778
PyDoc_STRVAR(os_cpu_count__doc__,
11779
"cpu_count($module, /)\n"
11780
"--\n"
11781
"\n"
11782
"Return the number of logical CPUs in the system.\n"
11783
"\n"
11784
"Return None if indeterminable.");
11785
11786
#define OS_CPU_COUNT_METHODDEF    \
11787
    {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
11788
11789
static PyObject *
11790
os_cpu_count_impl(PyObject *module);
11791
11792
static PyObject *
11793
os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
11794
0
{
11795
0
    return os_cpu_count_impl(module);
11796
0
}
11797
11798
PyDoc_STRVAR(os_get_inheritable__doc__,
11799
"get_inheritable($module, fd, /)\n"
11800
"--\n"
11801
"\n"
11802
"Get the close-on-exe flag of the specified file descriptor.");
11803
11804
#define OS_GET_INHERITABLE_METHODDEF    \
11805
    {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
11806
11807
static int
11808
os_get_inheritable_impl(PyObject *module, int fd);
11809
11810
static PyObject *
11811
os_get_inheritable(PyObject *module, PyObject *arg)
11812
0
{
11813
0
    PyObject *return_value = NULL;
11814
0
    int fd;
11815
0
    int _return_value;
11816
11817
0
    fd = PyLong_AsInt(arg);
11818
0
    if (fd == -1 && PyErr_Occurred()) {
11819
0
        goto exit;
11820
0
    }
11821
0
    _return_value = os_get_inheritable_impl(module, fd);
11822
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11823
0
        goto exit;
11824
0
    }
11825
0
    return_value = PyBool_FromLong((long)_return_value);
11826
11827
0
exit:
11828
0
    return return_value;
11829
0
}
11830
11831
PyDoc_STRVAR(os_set_inheritable__doc__,
11832
"set_inheritable($module, fd, inheritable, /)\n"
11833
"--\n"
11834
"\n"
11835
"Set the inheritable flag of the specified file descriptor.");
11836
11837
#define OS_SET_INHERITABLE_METHODDEF    \
11838
    {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__},
11839
11840
static PyObject *
11841
os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
11842
11843
static PyObject *
11844
os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11845
0
{
11846
0
    PyObject *return_value = NULL;
11847
0
    int fd;
11848
0
    int inheritable;
11849
11850
0
    if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
11851
0
        goto exit;
11852
0
    }
11853
0
    fd = PyLong_AsInt(args[0]);
11854
0
    if (fd == -1 && PyErr_Occurred()) {
11855
0
        goto exit;
11856
0
    }
11857
0
    inheritable = PyLong_AsInt(args[1]);
11858
0
    if (inheritable == -1 && PyErr_Occurred()) {
11859
0
        goto exit;
11860
0
    }
11861
0
    return_value = os_set_inheritable_impl(module, fd, inheritable);
11862
11863
0
exit:
11864
0
    return return_value;
11865
0
}
11866
11867
#if defined(MS_WINDOWS)
11868
11869
PyDoc_STRVAR(os_get_handle_inheritable__doc__,
11870
"get_handle_inheritable($module, handle, /)\n"
11871
"--\n"
11872
"\n"
11873
"Get the close-on-exe flag of the specified file descriptor.");
11874
11875
#define OS_GET_HANDLE_INHERITABLE_METHODDEF    \
11876
    {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
11877
11878
static int
11879
os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
11880
11881
static PyObject *
11882
os_get_handle_inheritable(PyObject *module, PyObject *arg)
11883
{
11884
    PyObject *return_value = NULL;
11885
    intptr_t handle;
11886
    int _return_value;
11887
11888
    handle = (intptr_t)PyLong_AsVoidPtr(arg);
11889
    if (!handle && PyErr_Occurred()) {
11890
        goto exit;
11891
    }
11892
    _return_value = os_get_handle_inheritable_impl(module, handle);
11893
    if ((_return_value == -1) && PyErr_Occurred()) {
11894
        goto exit;
11895
    }
11896
    return_value = PyBool_FromLong((long)_return_value);
11897
11898
exit:
11899
    return return_value;
11900
}
11901
11902
#endif /* defined(MS_WINDOWS) */
11903
11904
#if defined(MS_WINDOWS)
11905
11906
PyDoc_STRVAR(os_set_handle_inheritable__doc__,
11907
"set_handle_inheritable($module, handle, inheritable, /)\n"
11908
"--\n"
11909
"\n"
11910
"Set the inheritable flag of the specified handle.");
11911
11912
#define OS_SET_HANDLE_INHERITABLE_METHODDEF    \
11913
    {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__},
11914
11915
static PyObject *
11916
os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
11917
                               int inheritable);
11918
11919
static PyObject *
11920
os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11921
{
11922
    PyObject *return_value = NULL;
11923
    intptr_t handle;
11924
    int inheritable;
11925
11926
    if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) {
11927
        goto exit;
11928
    }
11929
    handle = (intptr_t)PyLong_AsVoidPtr(args[0]);
11930
    if (!handle && PyErr_Occurred()) {
11931
        goto exit;
11932
    }
11933
    inheritable = PyObject_IsTrue(args[1]);
11934
    if (inheritable < 0) {
11935
        goto exit;
11936
    }
11937
    return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
11938
11939
exit:
11940
    return return_value;
11941
}
11942
11943
#endif /* defined(MS_WINDOWS) */
11944
11945
PyDoc_STRVAR(os_get_blocking__doc__,
11946
"get_blocking($module, fd, /)\n"
11947
"--\n"
11948
"\n"
11949
"Get the blocking mode of the file descriptor.\n"
11950
"\n"
11951
"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
11952
11953
#define OS_GET_BLOCKING_METHODDEF    \
11954
    {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
11955
11956
static int
11957
os_get_blocking_impl(PyObject *module, int fd);
11958
11959
static PyObject *
11960
os_get_blocking(PyObject *module, PyObject *arg)
11961
0
{
11962
0
    PyObject *return_value = NULL;
11963
0
    int fd;
11964
0
    int _return_value;
11965
11966
0
    fd = PyLong_AsInt(arg);
11967
0
    if (fd == -1 && PyErr_Occurred()) {
11968
0
        goto exit;
11969
0
    }
11970
0
    _return_value = os_get_blocking_impl(module, fd);
11971
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11972
0
        goto exit;
11973
0
    }
11974
0
    return_value = PyBool_FromLong((long)_return_value);
11975
11976
0
exit:
11977
0
    return return_value;
11978
0
}
11979
11980
PyDoc_STRVAR(os_set_blocking__doc__,
11981
"set_blocking($module, fd, blocking, /)\n"
11982
"--\n"
11983
"\n"
11984
"Set the blocking mode of the specified file descriptor.\n"
11985
"\n"
11986
"Set the O_NONBLOCK flag if blocking is False,\n"
11987
"clear the O_NONBLOCK flag otherwise.");
11988
11989
#define OS_SET_BLOCKING_METHODDEF    \
11990
    {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__},
11991
11992
static PyObject *
11993
os_set_blocking_impl(PyObject *module, int fd, int blocking);
11994
11995
static PyObject *
11996
os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11997
0
{
11998
0
    PyObject *return_value = NULL;
11999
0
    int fd;
12000
0
    int blocking;
12001
12002
0
    if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
12003
0
        goto exit;
12004
0
    }
12005
0
    fd = PyLong_AsInt(args[0]);
12006
0
    if (fd == -1 && PyErr_Occurred()) {
12007
0
        goto exit;
12008
0
    }
12009
0
    blocking = PyObject_IsTrue(args[1]);
12010
0
    if (blocking < 0) {
12011
0
        goto exit;
12012
0
    }
12013
0
    return_value = os_set_blocking_impl(module, fd, blocking);
12014
12015
0
exit:
12016
0
    return return_value;
12017
0
}
12018
12019
PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
12020
"is_symlink($self, /)\n"
12021
"--\n"
12022
"\n"
12023
"Return True if the entry is a symbolic link; cached per entry.");
12024
12025
#define OS_DIRENTRY_IS_SYMLINK_METHODDEF    \
12026
    {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__},
12027
12028
static int
12029
os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class);
12030
12031
static PyObject *
12032
os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12033
0
{
12034
0
    PyObject *return_value = NULL;
12035
0
    int _return_value;
12036
12037
0
    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
12038
0
        PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
12039
0
        goto exit;
12040
0
    }
12041
0
    _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class);
12042
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12043
0
        goto exit;
12044
0
    }
12045
0
    return_value = PyBool_FromLong((long)_return_value);
12046
12047
0
exit:
12048
0
    return return_value;
12049
0
}
12050
12051
PyDoc_STRVAR(os_DirEntry_is_junction__doc__,
12052
"is_junction($self, /)\n"
12053
"--\n"
12054
"\n"
12055
"Return True if the entry is a junction; cached per entry.");
12056
12057
#define OS_DIRENTRY_IS_JUNCTION_METHODDEF    \
12058
    {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__},
12059
12060
static int
12061
os_DirEntry_is_junction_impl(DirEntry *self);
12062
12063
static PyObject *
12064
os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored))
12065
0
{
12066
0
    PyObject *return_value = NULL;
12067
0
    int _return_value;
12068
12069
0
    _return_value = os_DirEntry_is_junction_impl((DirEntry *)self);
12070
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12071
0
        goto exit;
12072
0
    }
12073
0
    return_value = PyBool_FromLong((long)_return_value);
12074
12075
0
exit:
12076
0
    return return_value;
12077
0
}
12078
12079
PyDoc_STRVAR(os_DirEntry_stat__doc__,
12080
"stat($self, /, *, follow_symlinks=True)\n"
12081
"--\n"
12082
"\n"
12083
"Return stat_result object for the entry; cached per entry.");
12084
12085
#define OS_DIRENTRY_STAT_METHODDEF    \
12086
    {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
12087
12088
static PyObject *
12089
os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class,
12090
                      int follow_symlinks);
12091
12092
static PyObject *
12093
os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12094
0
{
12095
0
    PyObject *return_value = NULL;
12096
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12097
12098
0
    #define NUM_KEYWORDS 1
12099
0
    static struct {
12100
0
        PyGC_Head _this_is_not_used;
12101
0
        PyObject_VAR_HEAD
12102
0
        Py_hash_t ob_hash;
12103
0
        PyObject *ob_item[NUM_KEYWORDS];
12104
0
    } _kwtuple = {
12105
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12106
0
        .ob_hash = -1,
12107
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12108
0
    };
12109
0
    #undef NUM_KEYWORDS
12110
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12111
12112
    #else  // !Py_BUILD_CORE
12113
    #  define KWTUPLE NULL
12114
    #endif  // !Py_BUILD_CORE
12115
12116
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12117
0
    static _PyArg_Parser _parser = {
12118
0
        .keywords = _keywords,
12119
0
        .fname = "stat",
12120
0
        .kwtuple = KWTUPLE,
12121
0
    };
12122
0
    #undef KWTUPLE
12123
0
    PyObject *argsbuf[1];
12124
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12125
0
    int follow_symlinks = 1;
12126
12127
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12128
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12129
0
    if (!args) {
12130
0
        goto exit;
12131
0
    }
12132
0
    if (!noptargs) {
12133
0
        goto skip_optional_kwonly;
12134
0
    }
12135
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12136
0
    if (follow_symlinks < 0) {
12137
0
        goto exit;
12138
0
    }
12139
0
skip_optional_kwonly:
12140
0
    return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks);
12141
12142
0
exit:
12143
0
    return return_value;
12144
0
}
12145
12146
PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
12147
"is_dir($self, /, *, follow_symlinks=True)\n"
12148
"--\n"
12149
"\n"
12150
"Return True if the entry is a directory; cached per entry.");
12151
12152
#define OS_DIRENTRY_IS_DIR_METHODDEF    \
12153
    {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
12154
12155
static int
12156
os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class,
12157
                        int follow_symlinks);
12158
12159
static PyObject *
12160
os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12161
0
{
12162
0
    PyObject *return_value = NULL;
12163
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12164
12165
0
    #define NUM_KEYWORDS 1
12166
0
    static struct {
12167
0
        PyGC_Head _this_is_not_used;
12168
0
        PyObject_VAR_HEAD
12169
0
        Py_hash_t ob_hash;
12170
0
        PyObject *ob_item[NUM_KEYWORDS];
12171
0
    } _kwtuple = {
12172
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12173
0
        .ob_hash = -1,
12174
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12175
0
    };
12176
0
    #undef NUM_KEYWORDS
12177
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12178
12179
    #else  // !Py_BUILD_CORE
12180
    #  define KWTUPLE NULL
12181
    #endif  // !Py_BUILD_CORE
12182
12183
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12184
0
    static _PyArg_Parser _parser = {
12185
0
        .keywords = _keywords,
12186
0
        .fname = "is_dir",
12187
0
        .kwtuple = KWTUPLE,
12188
0
    };
12189
0
    #undef KWTUPLE
12190
0
    PyObject *argsbuf[1];
12191
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12192
0
    int follow_symlinks = 1;
12193
0
    int _return_value;
12194
12195
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12196
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12197
0
    if (!args) {
12198
0
        goto exit;
12199
0
    }
12200
0
    if (!noptargs) {
12201
0
        goto skip_optional_kwonly;
12202
0
    }
12203
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12204
0
    if (follow_symlinks < 0) {
12205
0
        goto exit;
12206
0
    }
12207
0
skip_optional_kwonly:
12208
0
    _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks);
12209
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12210
0
        goto exit;
12211
0
    }
12212
0
    return_value = PyBool_FromLong((long)_return_value);
12213
12214
0
exit:
12215
0
    return return_value;
12216
0
}
12217
12218
PyDoc_STRVAR(os_DirEntry_is_file__doc__,
12219
"is_file($self, /, *, follow_symlinks=True)\n"
12220
"--\n"
12221
"\n"
12222
"Return True if the entry is a file; cached per entry.");
12223
12224
#define OS_DIRENTRY_IS_FILE_METHODDEF    \
12225
    {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
12226
12227
static int
12228
os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class,
12229
                         int follow_symlinks);
12230
12231
static PyObject *
12232
os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12233
0
{
12234
0
    PyObject *return_value = NULL;
12235
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12236
12237
0
    #define NUM_KEYWORDS 1
12238
0
    static struct {
12239
0
        PyGC_Head _this_is_not_used;
12240
0
        PyObject_VAR_HEAD
12241
0
        Py_hash_t ob_hash;
12242
0
        PyObject *ob_item[NUM_KEYWORDS];
12243
0
    } _kwtuple = {
12244
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12245
0
        .ob_hash = -1,
12246
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12247
0
    };
12248
0
    #undef NUM_KEYWORDS
12249
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12250
12251
    #else  // !Py_BUILD_CORE
12252
    #  define KWTUPLE NULL
12253
    #endif  // !Py_BUILD_CORE
12254
12255
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12256
0
    static _PyArg_Parser _parser = {
12257
0
        .keywords = _keywords,
12258
0
        .fname = "is_file",
12259
0
        .kwtuple = KWTUPLE,
12260
0
    };
12261
0
    #undef KWTUPLE
12262
0
    PyObject *argsbuf[1];
12263
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12264
0
    int follow_symlinks = 1;
12265
0
    int _return_value;
12266
12267
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12268
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12269
0
    if (!args) {
12270
0
        goto exit;
12271
0
    }
12272
0
    if (!noptargs) {
12273
0
        goto skip_optional_kwonly;
12274
0
    }
12275
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12276
0
    if (follow_symlinks < 0) {
12277
0
        goto exit;
12278
0
    }
12279
0
skip_optional_kwonly:
12280
0
    _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks);
12281
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12282
0
        goto exit;
12283
0
    }
12284
0
    return_value = PyBool_FromLong((long)_return_value);
12285
12286
0
exit:
12287
0
    return return_value;
12288
0
}
12289
12290
PyDoc_STRVAR(os_DirEntry_inode__doc__,
12291
"inode($self, /)\n"
12292
"--\n"
12293
"\n"
12294
"Return inode of the entry; cached per entry.");
12295
12296
#define OS_DIRENTRY_INODE_METHODDEF    \
12297
    {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
12298
12299
static PyObject *
12300
os_DirEntry_inode_impl(DirEntry *self);
12301
12302
static PyObject *
12303
os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored))
12304
0
{
12305
0
    return os_DirEntry_inode_impl((DirEntry *)self);
12306
0
}
12307
12308
PyDoc_STRVAR(os_DirEntry___fspath____doc__,
12309
"__fspath__($self, /)\n"
12310
"--\n"
12311
"\n"
12312
"Returns the path for the entry.");
12313
12314
#define OS_DIRENTRY___FSPATH___METHODDEF    \
12315
    {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
12316
12317
static PyObject *
12318
os_DirEntry___fspath___impl(DirEntry *self);
12319
12320
static PyObject *
12321
os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored))
12322
0
{
12323
0
    return os_DirEntry___fspath___impl((DirEntry *)self);
12324
0
}
12325
12326
PyDoc_STRVAR(os_scandir__doc__,
12327
"scandir($module, /, path=None)\n"
12328
"--\n"
12329
"\n"
12330
"Return an iterator of DirEntry objects for given path.\n"
12331
"\n"
12332
"path can be specified as either str, bytes, or a path-like object.  If path\n"
12333
"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
12334
"all other circumstances they will be str.\n"
12335
"\n"
12336
"If path is None, uses the path=\'.\'.");
12337
12338
#define OS_SCANDIR_METHODDEF    \
12339
    {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
12340
12341
static PyObject *
12342
os_scandir_impl(PyObject *module, path_t *path);
12343
12344
static PyObject *
12345
os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12346
0
{
12347
0
    PyObject *return_value = NULL;
12348
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12349
12350
0
    #define NUM_KEYWORDS 1
12351
0
    static struct {
12352
0
        PyGC_Head _this_is_not_used;
12353
0
        PyObject_VAR_HEAD
12354
0
        Py_hash_t ob_hash;
12355
0
        PyObject *ob_item[NUM_KEYWORDS];
12356
0
    } _kwtuple = {
12357
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12358
0
        .ob_hash = -1,
12359
0
        .ob_item = { &_Py_ID(path), },
12360
0
    };
12361
0
    #undef NUM_KEYWORDS
12362
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12363
12364
    #else  // !Py_BUILD_CORE
12365
    #  define KWTUPLE NULL
12366
    #endif  // !Py_BUILD_CORE
12367
12368
0
    static const char * const _keywords[] = {"path", NULL};
12369
0
    static _PyArg_Parser _parser = {
12370
0
        .keywords = _keywords,
12371
0
        .fname = "scandir",
12372
0
        .kwtuple = KWTUPLE,
12373
0
    };
12374
0
    #undef KWTUPLE
12375
0
    PyObject *argsbuf[1];
12376
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12377
0
    path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
12378
12379
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12380
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12381
0
    if (!args) {
12382
0
        goto exit;
12383
0
    }
12384
0
    if (!noptargs) {
12385
0
        goto skip_optional_pos;
12386
0
    }
12387
0
    if (!path_converter(args[0], &path)) {
12388
0
        goto exit;
12389
0
    }
12390
0
skip_optional_pos:
12391
0
    return_value = os_scandir_impl(module, &path);
12392
12393
0
exit:
12394
    /* Cleanup for path */
12395
0
    path_cleanup(&path);
12396
12397
0
    return return_value;
12398
0
}
12399
12400
PyDoc_STRVAR(os_fspath__doc__,
12401
"fspath($module, /, path)\n"
12402
"--\n"
12403
"\n"
12404
"Return the file system path representation of the object.\n"
12405
"\n"
12406
"If the object is str or bytes, then allow it to pass through as-is. If the\n"
12407
"object defines __fspath__(), then return the result of that method. All other\n"
12408
"types raise a TypeError.");
12409
12410
#define OS_FSPATH_METHODDEF    \
12411
    {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
12412
12413
static PyObject *
12414
os_fspath_impl(PyObject *module, PyObject *path);
12415
12416
static PyObject *
12417
os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12418
1.59k
{
12419
1.59k
    PyObject *return_value = NULL;
12420
1.59k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12421
12422
1.59k
    #define NUM_KEYWORDS 1
12423
1.59k
    static struct {
12424
1.59k
        PyGC_Head _this_is_not_used;
12425
1.59k
        PyObject_VAR_HEAD
12426
1.59k
        Py_hash_t ob_hash;
12427
1.59k
        PyObject *ob_item[NUM_KEYWORDS];
12428
1.59k
    } _kwtuple = {
12429
1.59k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12430
1.59k
        .ob_hash = -1,
12431
1.59k
        .ob_item = { &_Py_ID(path), },
12432
1.59k
    };
12433
1.59k
    #undef NUM_KEYWORDS
12434
1.59k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12435
12436
    #else  // !Py_BUILD_CORE
12437
    #  define KWTUPLE NULL
12438
    #endif  // !Py_BUILD_CORE
12439
12440
1.59k
    static const char * const _keywords[] = {"path", NULL};
12441
1.59k
    static _PyArg_Parser _parser = {
12442
1.59k
        .keywords = _keywords,
12443
1.59k
        .fname = "fspath",
12444
1.59k
        .kwtuple = KWTUPLE,
12445
1.59k
    };
12446
1.59k
    #undef KWTUPLE
12447
1.59k
    PyObject *argsbuf[1];
12448
1.59k
    PyObject *path;
12449
12450
1.59k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12451
1.59k
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12452
1.59k
    if (!args) {
12453
0
        goto exit;
12454
0
    }
12455
1.59k
    path = args[0];
12456
1.59k
    return_value = os_fspath_impl(module, path);
12457
12458
1.59k
exit:
12459
1.59k
    return return_value;
12460
1.59k
}
12461
12462
#if defined(HAVE_GETRANDOM_SYSCALL)
12463
12464
PyDoc_STRVAR(os_getrandom__doc__,
12465
"getrandom($module, /, size, flags=0)\n"
12466
"--\n"
12467
"\n"
12468
"Obtain a series of random bytes.");
12469
12470
#define OS_GETRANDOM_METHODDEF    \
12471
    {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
12472
12473
static PyObject *
12474
os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
12475
12476
static PyObject *
12477
os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12478
0
{
12479
0
    PyObject *return_value = NULL;
12480
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12481
12482
0
    #define NUM_KEYWORDS 2
12483
0
    static struct {
12484
0
        PyGC_Head _this_is_not_used;
12485
0
        PyObject_VAR_HEAD
12486
0
        Py_hash_t ob_hash;
12487
0
        PyObject *ob_item[NUM_KEYWORDS];
12488
0
    } _kwtuple = {
12489
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12490
0
        .ob_hash = -1,
12491
0
        .ob_item = { &_Py_ID(size), &_Py_ID(flags), },
12492
0
    };
12493
0
    #undef NUM_KEYWORDS
12494
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12495
12496
    #else  // !Py_BUILD_CORE
12497
    #  define KWTUPLE NULL
12498
    #endif  // !Py_BUILD_CORE
12499
12500
0
    static const char * const _keywords[] = {"size", "flags", NULL};
12501
0
    static _PyArg_Parser _parser = {
12502
0
        .keywords = _keywords,
12503
0
        .fname = "getrandom",
12504
0
        .kwtuple = KWTUPLE,
12505
0
    };
12506
0
    #undef KWTUPLE
12507
0
    PyObject *argsbuf[2];
12508
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
12509
0
    Py_ssize_t size;
12510
0
    int flags = 0;
12511
12512
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12513
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12514
0
    if (!args) {
12515
0
        goto exit;
12516
0
    }
12517
0
    {
12518
0
        Py_ssize_t ival = -1;
12519
0
        PyObject *iobj = _PyNumber_Index(args[0]);
12520
0
        if (iobj != NULL) {
12521
0
            ival = PyLong_AsSsize_t(iobj);
12522
0
            Py_DECREF(iobj);
12523
0
        }
12524
0
        if (ival == -1 && PyErr_Occurred()) {
12525
0
            goto exit;
12526
0
        }
12527
0
        size = ival;
12528
0
    }
12529
0
    if (!noptargs) {
12530
0
        goto skip_optional_pos;
12531
0
    }
12532
0
    flags = PyLong_AsInt(args[1]);
12533
0
    if (flags == -1 && PyErr_Occurred()) {
12534
0
        goto exit;
12535
0
    }
12536
0
skip_optional_pos:
12537
0
    return_value = os_getrandom_impl(module, size, flags);
12538
12539
0
exit:
12540
0
    return return_value;
12541
0
}
12542
12543
#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
12544
12545
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12546
12547
PyDoc_STRVAR(os__add_dll_directory__doc__,
12548
"_add_dll_directory($module, /, path)\n"
12549
"--\n"
12550
"\n"
12551
"Add a path to the DLL search path.\n"
12552
"\n"
12553
"This search path is used when resolving dependencies for imported\n"
12554
"extension modules (the module itself is resolved through sys.path),\n"
12555
"and also by ctypes.\n"
12556
"\n"
12557
"Returns an opaque value that may be passed to os.remove_dll_directory\n"
12558
"to remove this directory from the search path.");
12559
12560
#define OS__ADD_DLL_DIRECTORY_METHODDEF    \
12561
    {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
12562
12563
static PyObject *
12564
os__add_dll_directory_impl(PyObject *module, path_t *path);
12565
12566
static PyObject *
12567
os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12568
{
12569
    PyObject *return_value = NULL;
12570
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12571
12572
    #define NUM_KEYWORDS 1
12573
    static struct {
12574
        PyGC_Head _this_is_not_used;
12575
        PyObject_VAR_HEAD
12576
        Py_hash_t ob_hash;
12577
        PyObject *ob_item[NUM_KEYWORDS];
12578
    } _kwtuple = {
12579
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12580
        .ob_hash = -1,
12581
        .ob_item = { &_Py_ID(path), },
12582
    };
12583
    #undef NUM_KEYWORDS
12584
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12585
12586
    #else  // !Py_BUILD_CORE
12587
    #  define KWTUPLE NULL
12588
    #endif  // !Py_BUILD_CORE
12589
12590
    static const char * const _keywords[] = {"path", NULL};
12591
    static _PyArg_Parser _parser = {
12592
        .keywords = _keywords,
12593
        .fname = "_add_dll_directory",
12594
        .kwtuple = KWTUPLE,
12595
    };
12596
    #undef KWTUPLE
12597
    PyObject *argsbuf[1];
12598
    path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0);
12599
12600
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12601
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12602
    if (!args) {
12603
        goto exit;
12604
    }
12605
    if (!path_converter(args[0], &path)) {
12606
        goto exit;
12607
    }
12608
    return_value = os__add_dll_directory_impl(module, &path);
12609
12610
exit:
12611
    /* Cleanup for path */
12612
    path_cleanup(&path);
12613
12614
    return return_value;
12615
}
12616
12617
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12618
12619
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12620
12621
PyDoc_STRVAR(os__remove_dll_directory__doc__,
12622
"_remove_dll_directory($module, /, cookie)\n"
12623
"--\n"
12624
"\n"
12625
"Removes a path from the DLL search path.\n"
12626
"\n"
12627
"The parameter is an opaque value that was returned from\n"
12628
"os.add_dll_directory. You can only remove directories that you added\n"
12629
"yourself.");
12630
12631
#define OS__REMOVE_DLL_DIRECTORY_METHODDEF    \
12632
    {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
12633
12634
static PyObject *
12635
os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
12636
12637
static PyObject *
12638
os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12639
{
12640
    PyObject *return_value = NULL;
12641
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12642
12643
    #define NUM_KEYWORDS 1
12644
    static struct {
12645
        PyGC_Head _this_is_not_used;
12646
        PyObject_VAR_HEAD
12647
        Py_hash_t ob_hash;
12648
        PyObject *ob_item[NUM_KEYWORDS];
12649
    } _kwtuple = {
12650
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12651
        .ob_hash = -1,
12652
        .ob_item = { &_Py_ID(cookie), },
12653
    };
12654
    #undef NUM_KEYWORDS
12655
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12656
12657
    #else  // !Py_BUILD_CORE
12658
    #  define KWTUPLE NULL
12659
    #endif  // !Py_BUILD_CORE
12660
12661
    static const char * const _keywords[] = {"cookie", NULL};
12662
    static _PyArg_Parser _parser = {
12663
        .keywords = _keywords,
12664
        .fname = "_remove_dll_directory",
12665
        .kwtuple = KWTUPLE,
12666
    };
12667
    #undef KWTUPLE
12668
    PyObject *argsbuf[1];
12669
    PyObject *cookie;
12670
12671
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12672
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12673
    if (!args) {
12674
        goto exit;
12675
    }
12676
    cookie = args[0];
12677
    return_value = os__remove_dll_directory_impl(module, cookie);
12678
12679
exit:
12680
    return return_value;
12681
}
12682
12683
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12684
12685
#if (defined(WIFEXITED) || defined(MS_WINDOWS))
12686
12687
PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__,
12688
"waitstatus_to_exitcode($module, /, status)\n"
12689
"--\n"
12690
"\n"
12691
"Convert a wait status to an exit code.\n"
12692
"\n"
12693
"On Unix:\n"
12694
"\n"
12695
"* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n"
12696
"* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n"
12697
"* Otherwise, raise a ValueError.\n"
12698
"\n"
12699
"On Windows, return status shifted right by 8 bits.\n"
12700
"\n"
12701
"On Unix, if the process is being traced or if waitpid() was called with\n"
12702
"WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n"
12703
"This function must not be called if WIFSTOPPED(status) is true.");
12704
12705
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF    \
12706
    {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__},
12707
12708
static PyObject *
12709
os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj);
12710
12711
static PyObject *
12712
os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12713
0
{
12714
0
    PyObject *return_value = NULL;
12715
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12716
12717
0
    #define NUM_KEYWORDS 1
12718
0
    static struct {
12719
0
        PyGC_Head _this_is_not_used;
12720
0
        PyObject_VAR_HEAD
12721
0
        Py_hash_t ob_hash;
12722
0
        PyObject *ob_item[NUM_KEYWORDS];
12723
0
    } _kwtuple = {
12724
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12725
0
        .ob_hash = -1,
12726
0
        .ob_item = { &_Py_ID(status), },
12727
0
    };
12728
0
    #undef NUM_KEYWORDS
12729
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12730
12731
    #else  // !Py_BUILD_CORE
12732
    #  define KWTUPLE NULL
12733
    #endif  // !Py_BUILD_CORE
12734
12735
0
    static const char * const _keywords[] = {"status", NULL};
12736
0
    static _PyArg_Parser _parser = {
12737
0
        .keywords = _keywords,
12738
0
        .fname = "waitstatus_to_exitcode",
12739
0
        .kwtuple = KWTUPLE,
12740
0
    };
12741
0
    #undef KWTUPLE
12742
0
    PyObject *argsbuf[1];
12743
0
    PyObject *status_obj;
12744
12745
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12746
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12747
0
    if (!args) {
12748
0
        goto exit;
12749
0
    }
12750
0
    status_obj = args[0];
12751
0
    return_value = os_waitstatus_to_exitcode_impl(module, status_obj);
12752
12753
0
exit:
12754
0
    return return_value;
12755
0
}
12756
12757
#endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */
12758
12759
#if defined(MS_WINDOWS)
12760
12761
PyDoc_STRVAR(os__supports_virtual_terminal__doc__,
12762
"_supports_virtual_terminal($module, /)\n"
12763
"--\n"
12764
"\n"
12765
"Checks if virtual terminal is supported in windows");
12766
12767
#define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF    \
12768
    {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__},
12769
12770
static PyObject *
12771
os__supports_virtual_terminal_impl(PyObject *module);
12772
12773
static PyObject *
12774
os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored))
12775
{
12776
    return os__supports_virtual_terminal_impl(module);
12777
}
12778
12779
#endif /* defined(MS_WINDOWS) */
12780
12781
PyDoc_STRVAR(os__inputhook__doc__,
12782
"_inputhook($module, /)\n"
12783
"--\n"
12784
"\n"
12785
"Calls PyOS_InputHook dropping the GIL first");
12786
12787
#define OS__INPUTHOOK_METHODDEF    \
12788
    {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__},
12789
12790
static PyObject *
12791
os__inputhook_impl(PyObject *module);
12792
12793
static PyObject *
12794
os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored))
12795
0
{
12796
0
    return os__inputhook_impl(module);
12797
0
}
12798
12799
PyDoc_STRVAR(os__is_inputhook_installed__doc__,
12800
"_is_inputhook_installed($module, /)\n"
12801
"--\n"
12802
"\n"
12803
"Checks if PyOS_InputHook is set");
12804
12805
#define OS__IS_INPUTHOOK_INSTALLED_METHODDEF    \
12806
    {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__},
12807
12808
static PyObject *
12809
os__is_inputhook_installed_impl(PyObject *module);
12810
12811
static PyObject *
12812
os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored))
12813
0
{
12814
0
    return os__is_inputhook_installed_impl(module);
12815
0
}
12816
12817
PyDoc_STRVAR(os__create_environ__doc__,
12818
"_create_environ($module, /)\n"
12819
"--\n"
12820
"\n"
12821
"Create the environment dictionary.");
12822
12823
#define OS__CREATE_ENVIRON_METHODDEF    \
12824
    {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__},
12825
12826
static PyObject *
12827
os__create_environ_impl(PyObject *module);
12828
12829
static PyObject *
12830
os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored))
12831
0
{
12832
0
    return os__create_environ_impl(module);
12833
0
}
12834
12835
#if defined(__EMSCRIPTEN__)
12836
12837
PyDoc_STRVAR(os__emscripten_debugger__doc__,
12838
"_emscripten_debugger($module, /)\n"
12839
"--\n"
12840
"\n"
12841
"Create a breakpoint for the JavaScript debugger. Emscripten only.");
12842
12843
#define OS__EMSCRIPTEN_DEBUGGER_METHODDEF    \
12844
    {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__},
12845
12846
static PyObject *
12847
os__emscripten_debugger_impl(PyObject *module);
12848
12849
static PyObject *
12850
os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored))
12851
{
12852
    return os__emscripten_debugger_impl(module);
12853
}
12854
12855
#endif /* defined(__EMSCRIPTEN__) */
12856
12857
#if defined(__EMSCRIPTEN__)
12858
12859
PyDoc_STRVAR(os__emscripten_log__doc__,
12860
"_emscripten_log($module, /, arg)\n"
12861
"--\n"
12862
"\n"
12863
"Log something to the JS console. Emscripten only.");
12864
12865
#define OS__EMSCRIPTEN_LOG_METHODDEF    \
12866
    {"_emscripten_log", _PyCFunction_CAST(os__emscripten_log), METH_FASTCALL|METH_KEYWORDS, os__emscripten_log__doc__},
12867
12868
static PyObject *
12869
os__emscripten_log_impl(PyObject *module, const char *arg);
12870
12871
static PyObject *
12872
os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12873
{
12874
    PyObject *return_value = NULL;
12875
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12876
12877
    #define NUM_KEYWORDS 1
12878
    static struct {
12879
        PyGC_Head _this_is_not_used;
12880
        PyObject_VAR_HEAD
12881
        Py_hash_t ob_hash;
12882
        PyObject *ob_item[NUM_KEYWORDS];
12883
    } _kwtuple = {
12884
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12885
        .ob_hash = -1,
12886
        .ob_item = { &_Py_ID(arg), },
12887
    };
12888
    #undef NUM_KEYWORDS
12889
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12890
12891
    #else  // !Py_BUILD_CORE
12892
    #  define KWTUPLE NULL
12893
    #endif  // !Py_BUILD_CORE
12894
12895
    static const char * const _keywords[] = {"arg", NULL};
12896
    static _PyArg_Parser _parser = {
12897
        .keywords = _keywords,
12898
        .fname = "_emscripten_log",
12899
        .kwtuple = KWTUPLE,
12900
    };
12901
    #undef KWTUPLE
12902
    PyObject *argsbuf[1];
12903
    const char *arg;
12904
12905
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12906
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12907
    if (!args) {
12908
        goto exit;
12909
    }
12910
    if (!PyUnicode_Check(args[0])) {
12911
        _PyArg_BadArgument("_emscripten_log", "argument 'arg'", "str", args[0]);
12912
        goto exit;
12913
    }
12914
    Py_ssize_t arg_length;
12915
    arg = PyUnicode_AsUTF8AndSize(args[0], &arg_length);
12916
    if (arg == NULL) {
12917
        goto exit;
12918
    }
12919
    if (strlen(arg) != (size_t)arg_length) {
12920
        PyErr_SetString(PyExc_ValueError, "embedded null character");
12921
        goto exit;
12922
    }
12923
    return_value = os__emscripten_log_impl(module, arg);
12924
12925
exit:
12926
    return return_value;
12927
}
12928
12929
#endif /* defined(__EMSCRIPTEN__) */
12930
12931
#ifndef OS_STATX_METHODDEF
12932
    #define OS_STATX_METHODDEF
12933
#endif /* !defined(OS_STATX_METHODDEF) */
12934
12935
#ifndef OS_TTYNAME_METHODDEF
12936
    #define OS_TTYNAME_METHODDEF
12937
#endif /* !defined(OS_TTYNAME_METHODDEF) */
12938
12939
#ifndef OS_CTERMID_METHODDEF
12940
    #define OS_CTERMID_METHODDEF
12941
#endif /* !defined(OS_CTERMID_METHODDEF) */
12942
12943
#ifndef OS_FCHDIR_METHODDEF
12944
    #define OS_FCHDIR_METHODDEF
12945
#endif /* !defined(OS_FCHDIR_METHODDEF) */
12946
12947
#ifndef OS_FCHMOD_METHODDEF
12948
    #define OS_FCHMOD_METHODDEF
12949
#endif /* !defined(OS_FCHMOD_METHODDEF) */
12950
12951
#ifndef OS_LCHMOD_METHODDEF
12952
    #define OS_LCHMOD_METHODDEF
12953
#endif /* !defined(OS_LCHMOD_METHODDEF) */
12954
12955
#ifndef OS_CHFLAGS_METHODDEF
12956
    #define OS_CHFLAGS_METHODDEF
12957
#endif /* !defined(OS_CHFLAGS_METHODDEF) */
12958
12959
#ifndef OS_LCHFLAGS_METHODDEF
12960
    #define OS_LCHFLAGS_METHODDEF
12961
#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
12962
12963
#ifndef OS_CHROOT_METHODDEF
12964
    #define OS_CHROOT_METHODDEF
12965
#endif /* !defined(OS_CHROOT_METHODDEF) */
12966
12967
#ifndef OS_FSYNC_METHODDEF
12968
    #define OS_FSYNC_METHODDEF
12969
#endif /* !defined(OS_FSYNC_METHODDEF) */
12970
12971
#ifndef OS_SYNC_METHODDEF
12972
    #define OS_SYNC_METHODDEF
12973
#endif /* !defined(OS_SYNC_METHODDEF) */
12974
12975
#ifndef OS_FDATASYNC_METHODDEF
12976
    #define OS_FDATASYNC_METHODDEF
12977
#endif /* !defined(OS_FDATASYNC_METHODDEF) */
12978
12979
#ifndef OS_CHOWN_METHODDEF
12980
    #define OS_CHOWN_METHODDEF
12981
#endif /* !defined(OS_CHOWN_METHODDEF) */
12982
12983
#ifndef OS_FCHOWN_METHODDEF
12984
    #define OS_FCHOWN_METHODDEF
12985
#endif /* !defined(OS_FCHOWN_METHODDEF) */
12986
12987
#ifndef OS_LCHOWN_METHODDEF
12988
    #define OS_LCHOWN_METHODDEF
12989
#endif /* !defined(OS_LCHOWN_METHODDEF) */
12990
12991
#ifndef OS_LINK_METHODDEF
12992
    #define OS_LINK_METHODDEF
12993
#endif /* !defined(OS_LINK_METHODDEF) */
12994
12995
#ifndef OS_LISTDRIVES_METHODDEF
12996
    #define OS_LISTDRIVES_METHODDEF
12997
#endif /* !defined(OS_LISTDRIVES_METHODDEF) */
12998
12999
#ifndef OS_LISTVOLUMES_METHODDEF
13000
    #define OS_LISTVOLUMES_METHODDEF
13001
#endif /* !defined(OS_LISTVOLUMES_METHODDEF) */
13002
13003
#ifndef OS_LISTMOUNTS_METHODDEF
13004
    #define OS_LISTMOUNTS_METHODDEF
13005
#endif /* !defined(OS_LISTMOUNTS_METHODDEF) */
13006
13007
#ifndef OS__PATH_ISDEVDRIVE_METHODDEF
13008
    #define OS__PATH_ISDEVDRIVE_METHODDEF
13009
#endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */
13010
13011
#ifndef OS__GETFULLPATHNAME_METHODDEF
13012
    #define OS__GETFULLPATHNAME_METHODDEF
13013
#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
13014
13015
#ifndef OS__GETFINALPATHNAME_METHODDEF
13016
    #define OS__GETFINALPATHNAME_METHODDEF
13017
#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
13018
13019
#ifndef OS__FINDFIRSTFILE_METHODDEF
13020
    #define OS__FINDFIRSTFILE_METHODDEF
13021
#endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */
13022
13023
#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
13024
    #define OS__GETVOLUMEPATHNAME_METHODDEF
13025
#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
13026
13027
#ifndef OS__PATH_SPLITROOT_METHODDEF
13028
    #define OS__PATH_SPLITROOT_METHODDEF
13029
#endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */
13030
13031
#ifndef OS__PATH_EXISTS_METHODDEF
13032
    #define OS__PATH_EXISTS_METHODDEF
13033
#endif /* !defined(OS__PATH_EXISTS_METHODDEF) */
13034
13035
#ifndef OS__PATH_LEXISTS_METHODDEF
13036
    #define OS__PATH_LEXISTS_METHODDEF
13037
#endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */
13038
13039
#ifndef OS__PATH_ISDIR_METHODDEF
13040
    #define OS__PATH_ISDIR_METHODDEF
13041
#endif /* !defined(OS__PATH_ISDIR_METHODDEF) */
13042
13043
#ifndef OS__PATH_ISFILE_METHODDEF
13044
    #define OS__PATH_ISFILE_METHODDEF
13045
#endif /* !defined(OS__PATH_ISFILE_METHODDEF) */
13046
13047
#ifndef OS__PATH_ISLINK_METHODDEF
13048
    #define OS__PATH_ISLINK_METHODDEF
13049
#endif /* !defined(OS__PATH_ISLINK_METHODDEF) */
13050
13051
#ifndef OS__PATH_ISJUNCTION_METHODDEF
13052
    #define OS__PATH_ISJUNCTION_METHODDEF
13053
#endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */
13054
13055
#ifndef OS_NICE_METHODDEF
13056
    #define OS_NICE_METHODDEF
13057
#endif /* !defined(OS_NICE_METHODDEF) */
13058
13059
#ifndef OS_GETPRIORITY_METHODDEF
13060
    #define OS_GETPRIORITY_METHODDEF
13061
#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
13062
13063
#ifndef OS_SETPRIORITY_METHODDEF
13064
    #define OS_SETPRIORITY_METHODDEF
13065
#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
13066
13067
#ifndef OS_SYSTEM_METHODDEF
13068
    #define OS_SYSTEM_METHODDEF
13069
#endif /* !defined(OS_SYSTEM_METHODDEF) */
13070
13071
#ifndef OS_UMASK_METHODDEF
13072
    #define OS_UMASK_METHODDEF
13073
#endif /* !defined(OS_UMASK_METHODDEF) */
13074
13075
#ifndef OS_UNAME_METHODDEF
13076
    #define OS_UNAME_METHODDEF
13077
#endif /* !defined(OS_UNAME_METHODDEF) */
13078
13079
#ifndef OS_EXECV_METHODDEF
13080
    #define OS_EXECV_METHODDEF
13081
#endif /* !defined(OS_EXECV_METHODDEF) */
13082
13083
#ifndef OS_EXECVE_METHODDEF
13084
    #define OS_EXECVE_METHODDEF
13085
#endif /* !defined(OS_EXECVE_METHODDEF) */
13086
13087
#ifndef OS_POSIX_SPAWN_METHODDEF
13088
    #define OS_POSIX_SPAWN_METHODDEF
13089
#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
13090
13091
#ifndef OS_POSIX_SPAWNP_METHODDEF
13092
    #define OS_POSIX_SPAWNP_METHODDEF
13093
#endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
13094
13095
#ifndef OS_SPAWNV_METHODDEF
13096
    #define OS_SPAWNV_METHODDEF
13097
#endif /* !defined(OS_SPAWNV_METHODDEF) */
13098
13099
#ifndef OS_SPAWNVE_METHODDEF
13100
    #define OS_SPAWNVE_METHODDEF
13101
#endif /* !defined(OS_SPAWNVE_METHODDEF) */
13102
13103
#ifndef OS_REGISTER_AT_FORK_METHODDEF
13104
    #define OS_REGISTER_AT_FORK_METHODDEF
13105
#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
13106
13107
#ifndef OS_FORK1_METHODDEF
13108
    #define OS_FORK1_METHODDEF
13109
#endif /* !defined(OS_FORK1_METHODDEF) */
13110
13111
#ifndef OS_FORK_METHODDEF
13112
    #define OS_FORK_METHODDEF
13113
#endif /* !defined(OS_FORK_METHODDEF) */
13114
13115
#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
13116
    #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
13117
#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
13118
13119
#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
13120
    #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
13121
#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
13122
13123
#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
13124
    #define OS_SCHED_GETSCHEDULER_METHODDEF
13125
#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
13126
13127
#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
13128
    #define OS_SCHED_SETSCHEDULER_METHODDEF
13129
#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
13130
13131
#ifndef OS_SCHED_GETPARAM_METHODDEF
13132
    #define OS_SCHED_GETPARAM_METHODDEF
13133
#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
13134
13135
#ifndef OS_SCHED_SETPARAM_METHODDEF
13136
    #define OS_SCHED_SETPARAM_METHODDEF
13137
#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
13138
13139
#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
13140
    #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
13141
#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
13142
13143
#ifndef OS_SCHED_YIELD_METHODDEF
13144
    #define OS_SCHED_YIELD_METHODDEF
13145
#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
13146
13147
#ifndef OS_SCHED_SETAFFINITY_METHODDEF
13148
    #define OS_SCHED_SETAFFINITY_METHODDEF
13149
#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
13150
13151
#ifndef OS_SCHED_GETAFFINITY_METHODDEF
13152
    #define OS_SCHED_GETAFFINITY_METHODDEF
13153
#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
13154
13155
#ifndef OS_POSIX_OPENPT_METHODDEF
13156
    #define OS_POSIX_OPENPT_METHODDEF
13157
#endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */
13158
13159
#ifndef OS_GRANTPT_METHODDEF
13160
    #define OS_GRANTPT_METHODDEF
13161
#endif /* !defined(OS_GRANTPT_METHODDEF) */
13162
13163
#ifndef OS_UNLOCKPT_METHODDEF
13164
    #define OS_UNLOCKPT_METHODDEF
13165
#endif /* !defined(OS_UNLOCKPT_METHODDEF) */
13166
13167
#ifndef OS_PTSNAME_METHODDEF
13168
    #define OS_PTSNAME_METHODDEF
13169
#endif /* !defined(OS_PTSNAME_METHODDEF) */
13170
13171
#ifndef OS_OPENPTY_METHODDEF
13172
    #define OS_OPENPTY_METHODDEF
13173
#endif /* !defined(OS_OPENPTY_METHODDEF) */
13174
13175
#ifndef OS_LOGIN_TTY_METHODDEF
13176
    #define OS_LOGIN_TTY_METHODDEF
13177
#endif /* !defined(OS_LOGIN_TTY_METHODDEF) */
13178
13179
#ifndef OS_FORKPTY_METHODDEF
13180
    #define OS_FORKPTY_METHODDEF
13181
#endif /* !defined(OS_FORKPTY_METHODDEF) */
13182
13183
#ifndef OS_GETEGID_METHODDEF
13184
    #define OS_GETEGID_METHODDEF
13185
#endif /* !defined(OS_GETEGID_METHODDEF) */
13186
13187
#ifndef OS_GETEUID_METHODDEF
13188
    #define OS_GETEUID_METHODDEF
13189
#endif /* !defined(OS_GETEUID_METHODDEF) */
13190
13191
#ifndef OS_GETGID_METHODDEF
13192
    #define OS_GETGID_METHODDEF
13193
#endif /* !defined(OS_GETGID_METHODDEF) */
13194
13195
#ifndef OS_GETPID_METHODDEF
13196
    #define OS_GETPID_METHODDEF
13197
#endif /* !defined(OS_GETPID_METHODDEF) */
13198
13199
#ifndef OS_GETGROUPLIST_METHODDEF
13200
    #define OS_GETGROUPLIST_METHODDEF
13201
#endif /* !defined(OS_GETGROUPLIST_METHODDEF) */
13202
13203
#ifndef OS_GETGROUPS_METHODDEF
13204
    #define OS_GETGROUPS_METHODDEF
13205
#endif /* !defined(OS_GETGROUPS_METHODDEF) */
13206
13207
#ifndef OS_INITGROUPS_METHODDEF
13208
    #define OS_INITGROUPS_METHODDEF
13209
#endif /* !defined(OS_INITGROUPS_METHODDEF) */
13210
13211
#ifndef OS_GETPGID_METHODDEF
13212
    #define OS_GETPGID_METHODDEF
13213
#endif /* !defined(OS_GETPGID_METHODDEF) */
13214
13215
#ifndef OS_GETPGRP_METHODDEF
13216
    #define OS_GETPGRP_METHODDEF
13217
#endif /* !defined(OS_GETPGRP_METHODDEF) */
13218
13219
#ifndef OS_SETPGRP_METHODDEF
13220
    #define OS_SETPGRP_METHODDEF
13221
#endif /* !defined(OS_SETPGRP_METHODDEF) */
13222
13223
#ifndef OS_GETPPID_METHODDEF
13224
    #define OS_GETPPID_METHODDEF
13225
#endif /* !defined(OS_GETPPID_METHODDEF) */
13226
13227
#ifndef OS_GETLOGIN_METHODDEF
13228
    #define OS_GETLOGIN_METHODDEF
13229
#endif /* !defined(OS_GETLOGIN_METHODDEF) */
13230
13231
#ifndef OS_GETUID_METHODDEF
13232
    #define OS_GETUID_METHODDEF
13233
#endif /* !defined(OS_GETUID_METHODDEF) */
13234
13235
#ifndef OS_KILL_METHODDEF
13236
    #define OS_KILL_METHODDEF
13237
#endif /* !defined(OS_KILL_METHODDEF) */
13238
13239
#ifndef OS_KILLPG_METHODDEF
13240
    #define OS_KILLPG_METHODDEF
13241
#endif /* !defined(OS_KILLPG_METHODDEF) */
13242
13243
#ifndef OS_PLOCK_METHODDEF
13244
    #define OS_PLOCK_METHODDEF
13245
#endif /* !defined(OS_PLOCK_METHODDEF) */
13246
13247
#ifndef OS_SETUID_METHODDEF
13248
    #define OS_SETUID_METHODDEF
13249
#endif /* !defined(OS_SETUID_METHODDEF) */
13250
13251
#ifndef OS_SETEUID_METHODDEF
13252
    #define OS_SETEUID_METHODDEF
13253
#endif /* !defined(OS_SETEUID_METHODDEF) */
13254
13255
#ifndef OS_SETEGID_METHODDEF
13256
    #define OS_SETEGID_METHODDEF
13257
#endif /* !defined(OS_SETEGID_METHODDEF) */
13258
13259
#ifndef OS_SETREUID_METHODDEF
13260
    #define OS_SETREUID_METHODDEF
13261
#endif /* !defined(OS_SETREUID_METHODDEF) */
13262
13263
#ifndef OS_SETREGID_METHODDEF
13264
    #define OS_SETREGID_METHODDEF
13265
#endif /* !defined(OS_SETREGID_METHODDEF) */
13266
13267
#ifndef OS_SETGID_METHODDEF
13268
    #define OS_SETGID_METHODDEF
13269
#endif /* !defined(OS_SETGID_METHODDEF) */
13270
13271
#ifndef OS_SETGROUPS_METHODDEF
13272
    #define OS_SETGROUPS_METHODDEF
13273
#endif /* !defined(OS_SETGROUPS_METHODDEF) */
13274
13275
#ifndef OS_WAIT3_METHODDEF
13276
    #define OS_WAIT3_METHODDEF
13277
#endif /* !defined(OS_WAIT3_METHODDEF) */
13278
13279
#ifndef OS_WAIT4_METHODDEF
13280
    #define OS_WAIT4_METHODDEF
13281
#endif /* !defined(OS_WAIT4_METHODDEF) */
13282
13283
#ifndef OS_WAITID_METHODDEF
13284
    #define OS_WAITID_METHODDEF
13285
#endif /* !defined(OS_WAITID_METHODDEF) */
13286
13287
#ifndef OS_WAITPID_METHODDEF
13288
    #define OS_WAITPID_METHODDEF
13289
#endif /* !defined(OS_WAITPID_METHODDEF) */
13290
13291
#ifndef OS_WAIT_METHODDEF
13292
    #define OS_WAIT_METHODDEF
13293
#endif /* !defined(OS_WAIT_METHODDEF) */
13294
13295
#ifndef OS_PIDFD_OPEN_METHODDEF
13296
    #define OS_PIDFD_OPEN_METHODDEF
13297
#endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */
13298
13299
#ifndef OS_SETNS_METHODDEF
13300
    #define OS_SETNS_METHODDEF
13301
#endif /* !defined(OS_SETNS_METHODDEF) */
13302
13303
#ifndef OS_UNSHARE_METHODDEF
13304
    #define OS_UNSHARE_METHODDEF
13305
#endif /* !defined(OS_UNSHARE_METHODDEF) */
13306
13307
#ifndef OS_READLINK_METHODDEF
13308
    #define OS_READLINK_METHODDEF
13309
#endif /* !defined(OS_READLINK_METHODDEF) */
13310
13311
#ifndef OS_SYMLINK_METHODDEF
13312
    #define OS_SYMLINK_METHODDEF
13313
#endif /* !defined(OS_SYMLINK_METHODDEF) */
13314
13315
#ifndef OS_TIMERFD_CREATE_METHODDEF
13316
    #define OS_TIMERFD_CREATE_METHODDEF
13317
#endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */
13318
13319
#ifndef OS_TIMERFD_SETTIME_METHODDEF
13320
    #define OS_TIMERFD_SETTIME_METHODDEF
13321
#endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */
13322
13323
#ifndef OS_TIMERFD_SETTIME_NS_METHODDEF
13324
    #define OS_TIMERFD_SETTIME_NS_METHODDEF
13325
#endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */
13326
13327
#ifndef OS_TIMERFD_GETTIME_METHODDEF
13328
    #define OS_TIMERFD_GETTIME_METHODDEF
13329
#endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */
13330
13331
#ifndef OS_TIMERFD_GETTIME_NS_METHODDEF
13332
    #define OS_TIMERFD_GETTIME_NS_METHODDEF
13333
#endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */
13334
13335
#ifndef OS_GETSID_METHODDEF
13336
    #define OS_GETSID_METHODDEF
13337
#endif /* !defined(OS_GETSID_METHODDEF) */
13338
13339
#ifndef OS_SETSID_METHODDEF
13340
    #define OS_SETSID_METHODDEF
13341
#endif /* !defined(OS_SETSID_METHODDEF) */
13342
13343
#ifndef OS_SETPGID_METHODDEF
13344
    #define OS_SETPGID_METHODDEF
13345
#endif /* !defined(OS_SETPGID_METHODDEF) */
13346
13347
#ifndef OS_TCGETPGRP_METHODDEF
13348
    #define OS_TCGETPGRP_METHODDEF
13349
#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
13350
13351
#ifndef OS_TCSETPGRP_METHODDEF
13352
    #define OS_TCSETPGRP_METHODDEF
13353
#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
13354
13355
#ifndef OS_DUP2_METHODDEF
13356
    #define OS_DUP2_METHODDEF
13357
#endif /* !defined(OS_DUP2_METHODDEF) */
13358
13359
#ifndef OS_LOCKF_METHODDEF
13360
    #define OS_LOCKF_METHODDEF
13361
#endif /* !defined(OS_LOCKF_METHODDEF) */
13362
13363
#ifndef OS_READV_METHODDEF
13364
    #define OS_READV_METHODDEF
13365
#endif /* !defined(OS_READV_METHODDEF) */
13366
13367
#ifndef OS_PREAD_METHODDEF
13368
    #define OS_PREAD_METHODDEF
13369
#endif /* !defined(OS_PREAD_METHODDEF) */
13370
13371
#ifndef OS_PREADV_METHODDEF
13372
    #define OS_PREADV_METHODDEF
13373
#endif /* !defined(OS_PREADV_METHODDEF) */
13374
13375
#ifndef OS_SENDFILE_METHODDEF
13376
    #define OS_SENDFILE_METHODDEF
13377
#endif /* !defined(OS_SENDFILE_METHODDEF) */
13378
13379
#ifndef OS__FCOPYFILE_METHODDEF
13380
    #define OS__FCOPYFILE_METHODDEF
13381
#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
13382
13383
#ifndef OS_PIPE_METHODDEF
13384
    #define OS_PIPE_METHODDEF
13385
#endif /* !defined(OS_PIPE_METHODDEF) */
13386
13387
#ifndef OS_PIPE2_METHODDEF
13388
    #define OS_PIPE2_METHODDEF
13389
#endif /* !defined(OS_PIPE2_METHODDEF) */
13390
13391
#ifndef OS_WRITEV_METHODDEF
13392
    #define OS_WRITEV_METHODDEF
13393
#endif /* !defined(OS_WRITEV_METHODDEF) */
13394
13395
#ifndef OS_PWRITE_METHODDEF
13396
    #define OS_PWRITE_METHODDEF
13397
#endif /* !defined(OS_PWRITE_METHODDEF) */
13398
13399
#ifndef OS_PWRITEV_METHODDEF
13400
    #define OS_PWRITEV_METHODDEF
13401
#endif /* !defined(OS_PWRITEV_METHODDEF) */
13402
13403
#ifndef OS_COPY_FILE_RANGE_METHODDEF
13404
    #define OS_COPY_FILE_RANGE_METHODDEF
13405
#endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
13406
13407
#ifndef OS_SPLICE_METHODDEF
13408
    #define OS_SPLICE_METHODDEF
13409
#endif /* !defined(OS_SPLICE_METHODDEF) */
13410
13411
#ifndef OS_MKFIFO_METHODDEF
13412
    #define OS_MKFIFO_METHODDEF
13413
#endif /* !defined(OS_MKFIFO_METHODDEF) */
13414
13415
#ifndef OS_MKNOD_METHODDEF
13416
    #define OS_MKNOD_METHODDEF
13417
#endif /* !defined(OS_MKNOD_METHODDEF) */
13418
13419
#ifndef OS_MAJOR_METHODDEF
13420
    #define OS_MAJOR_METHODDEF
13421
#endif /* !defined(OS_MAJOR_METHODDEF) */
13422
13423
#ifndef OS_MINOR_METHODDEF
13424
    #define OS_MINOR_METHODDEF
13425
#endif /* !defined(OS_MINOR_METHODDEF) */
13426
13427
#ifndef OS_MAKEDEV_METHODDEF
13428
    #define OS_MAKEDEV_METHODDEF
13429
#endif /* !defined(OS_MAKEDEV_METHODDEF) */
13430
13431
#ifndef OS_FTRUNCATE_METHODDEF
13432
    #define OS_FTRUNCATE_METHODDEF
13433
#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
13434
13435
#ifndef OS_TRUNCATE_METHODDEF
13436
    #define OS_TRUNCATE_METHODDEF
13437
#endif /* !defined(OS_TRUNCATE_METHODDEF) */
13438
13439
#ifndef OS_POSIX_FALLOCATE_METHODDEF
13440
    #define OS_POSIX_FALLOCATE_METHODDEF
13441
#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
13442
13443
#ifndef OS_POSIX_FADVISE_METHODDEF
13444
    #define OS_POSIX_FADVISE_METHODDEF
13445
#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
13446
13447
#ifndef OS_PUTENV_METHODDEF
13448
    #define OS_PUTENV_METHODDEF
13449
#endif /* !defined(OS_PUTENV_METHODDEF) */
13450
13451
#ifndef OS_UNSETENV_METHODDEF
13452
    #define OS_UNSETENV_METHODDEF
13453
#endif /* !defined(OS_UNSETENV_METHODDEF) */
13454
13455
#ifndef OS__CLEARENV_METHODDEF
13456
    #define OS__CLEARENV_METHODDEF
13457
#endif /* !defined(OS__CLEARENV_METHODDEF) */
13458
13459
#ifndef OS_WCOREDUMP_METHODDEF
13460
    #define OS_WCOREDUMP_METHODDEF
13461
#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
13462
13463
#ifndef OS_WIFCONTINUED_METHODDEF
13464
    #define OS_WIFCONTINUED_METHODDEF
13465
#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
13466
13467
#ifndef OS_WIFSTOPPED_METHODDEF
13468
    #define OS_WIFSTOPPED_METHODDEF
13469
#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
13470
13471
#ifndef OS_WIFSIGNALED_METHODDEF
13472
    #define OS_WIFSIGNALED_METHODDEF
13473
#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
13474
13475
#ifndef OS_WIFEXITED_METHODDEF
13476
    #define OS_WIFEXITED_METHODDEF
13477
#endif /* !defined(OS_WIFEXITED_METHODDEF) */
13478
13479
#ifndef OS_WEXITSTATUS_METHODDEF
13480
    #define OS_WEXITSTATUS_METHODDEF
13481
#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
13482
13483
#ifndef OS_WTERMSIG_METHODDEF
13484
    #define OS_WTERMSIG_METHODDEF
13485
#endif /* !defined(OS_WTERMSIG_METHODDEF) */
13486
13487
#ifndef OS_WSTOPSIG_METHODDEF
13488
    #define OS_WSTOPSIG_METHODDEF
13489
#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
13490
13491
#ifndef OS_FSTATVFS_METHODDEF
13492
    #define OS_FSTATVFS_METHODDEF
13493
#endif /* !defined(OS_FSTATVFS_METHODDEF) */
13494
13495
#ifndef OS_STATVFS_METHODDEF
13496
    #define OS_STATVFS_METHODDEF
13497
#endif /* !defined(OS_STATVFS_METHODDEF) */
13498
13499
#ifndef OS__GETDISKUSAGE_METHODDEF
13500
    #define OS__GETDISKUSAGE_METHODDEF
13501
#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
13502
13503
#ifndef OS_FPATHCONF_METHODDEF
13504
    #define OS_FPATHCONF_METHODDEF
13505
#endif /* !defined(OS_FPATHCONF_METHODDEF) */
13506
13507
#ifndef OS_PATHCONF_METHODDEF
13508
    #define OS_PATHCONF_METHODDEF
13509
#endif /* !defined(OS_PATHCONF_METHODDEF) */
13510
13511
#ifndef OS_CONFSTR_METHODDEF
13512
    #define OS_CONFSTR_METHODDEF
13513
#endif /* !defined(OS_CONFSTR_METHODDEF) */
13514
13515
#ifndef OS_SYSCONF_METHODDEF
13516
    #define OS_SYSCONF_METHODDEF
13517
#endif /* !defined(OS_SYSCONF_METHODDEF) */
13518
13519
#ifndef OS_STARTFILE_METHODDEF
13520
    #define OS_STARTFILE_METHODDEF
13521
#endif /* !defined(OS_STARTFILE_METHODDEF) */
13522
13523
#ifndef OS_GETLOADAVG_METHODDEF
13524
    #define OS_GETLOADAVG_METHODDEF
13525
#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
13526
13527
#ifndef OS_SETRESUID_METHODDEF
13528
    #define OS_SETRESUID_METHODDEF
13529
#endif /* !defined(OS_SETRESUID_METHODDEF) */
13530
13531
#ifndef OS_SETRESGID_METHODDEF
13532
    #define OS_SETRESGID_METHODDEF
13533
#endif /* !defined(OS_SETRESGID_METHODDEF) */
13534
13535
#ifndef OS_GETRESUID_METHODDEF
13536
    #define OS_GETRESUID_METHODDEF
13537
#endif /* !defined(OS_GETRESUID_METHODDEF) */
13538
13539
#ifndef OS_GETRESGID_METHODDEF
13540
    #define OS_GETRESGID_METHODDEF
13541
#endif /* !defined(OS_GETRESGID_METHODDEF) */
13542
13543
#ifndef OS_GETXATTR_METHODDEF
13544
    #define OS_GETXATTR_METHODDEF
13545
#endif /* !defined(OS_GETXATTR_METHODDEF) */
13546
13547
#ifndef OS_SETXATTR_METHODDEF
13548
    #define OS_SETXATTR_METHODDEF
13549
#endif /* !defined(OS_SETXATTR_METHODDEF) */
13550
13551
#ifndef OS_REMOVEXATTR_METHODDEF
13552
    #define OS_REMOVEXATTR_METHODDEF
13553
#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
13554
13555
#ifndef OS_LISTXATTR_METHODDEF
13556
    #define OS_LISTXATTR_METHODDEF
13557
#endif /* !defined(OS_LISTXATTR_METHODDEF) */
13558
13559
#ifndef OS_MEMFD_CREATE_METHODDEF
13560
    #define OS_MEMFD_CREATE_METHODDEF
13561
#endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */
13562
13563
#ifndef OS_EVENTFD_METHODDEF
13564
    #define OS_EVENTFD_METHODDEF
13565
#endif /* !defined(OS_EVENTFD_METHODDEF) */
13566
13567
#ifndef OS_EVENTFD_READ_METHODDEF
13568
    #define OS_EVENTFD_READ_METHODDEF
13569
#endif /* !defined(OS_EVENTFD_READ_METHODDEF) */
13570
13571
#ifndef OS_EVENTFD_WRITE_METHODDEF
13572
    #define OS_EVENTFD_WRITE_METHODDEF
13573
#endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */
13574
13575
#ifndef OS_GET_TERMINAL_SIZE_METHODDEF
13576
    #define OS_GET_TERMINAL_SIZE_METHODDEF
13577
#endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */
13578
13579
#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
13580
    #define OS_GET_HANDLE_INHERITABLE_METHODDEF
13581
#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
13582
13583
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
13584
    #define OS_SET_HANDLE_INHERITABLE_METHODDEF
13585
#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
13586
13587
#ifndef OS_GETRANDOM_METHODDEF
13588
    #define OS_GETRANDOM_METHODDEF
13589
#endif /* !defined(OS_GETRANDOM_METHODDEF) */
13590
13591
#ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
13592
    #define OS__ADD_DLL_DIRECTORY_METHODDEF
13593
#endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
13594
13595
#ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
13596
    #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
13597
#endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
13598
13599
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13600
    #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13601
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
13602
13603
#ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13604
    #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13605
#endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */
13606
13607
#ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13608
    #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13609
#endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */
13610
13611
#ifndef OS__EMSCRIPTEN_LOG_METHODDEF
13612
    #define OS__EMSCRIPTEN_LOG_METHODDEF
13613
#endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */
13614
/*[clinic end generated code: output=5fd2aeb6ba9a5df8 input=a9049054013a1b77]*/