Coverage Report

Created: 2026-06-01 06:14

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
1.66k
{
47
1.66k
    PyObject *return_value = NULL;
48
1.66k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
49
50
1.66k
    #define NUM_KEYWORDS 3
51
1.66k
    static struct {
52
1.66k
        PyGC_Head _this_is_not_used;
53
1.66k
        PyObject_VAR_HEAD
54
1.66k
        Py_hash_t ob_hash;
55
1.66k
        PyObject *ob_item[NUM_KEYWORDS];
56
1.66k
    } _kwtuple = {
57
1.66k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
58
1.66k
        .ob_hash = -1,
59
1.66k
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
60
1.66k
    };
61
1.66k
    #undef NUM_KEYWORDS
62
1.66k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
63
64
    #else  // !Py_BUILD_CORE
65
    #  define KWTUPLE NULL
66
    #endif  // !Py_BUILD_CORE
67
68
1.66k
    static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
69
1.66k
    static _PyArg_Parser _parser = {
70
1.66k
        .keywords = _keywords,
71
1.66k
        .fname = "stat",
72
1.66k
        .kwtuple = KWTUPLE,
73
1.66k
    };
74
1.66k
    #undef KWTUPLE
75
1.66k
    PyObject *argsbuf[3];
76
1.66k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
77
1.66k
    path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1);
78
1.66k
    int dir_fd = DEFAULT_DIR_FD;
79
1.66k
    int follow_symlinks = 1;
80
81
1.66k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
82
1.66k
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
83
1.66k
    if (!args) {
84
0
        goto exit;
85
0
    }
86
1.66k
    if (!path_converter(args[0], &path)) {
87
0
        goto exit;
88
0
    }
89
1.66k
    if (!noptargs) {
90
1.66k
        goto skip_optional_kwonly;
91
1.66k
    }
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
1.66k
skip_optional_kwonly:
105
1.66k
    return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
106
107
1.66k
exit:
108
    /* Cleanup for path */
109
1.66k
    path_cleanup(&path);
110
111
1.66k
    return return_value;
112
1.66k
}
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.  On some platforms, path may\n"
516
"also be specified as an open file descriptor.  If this functionality is\n"
517
"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\n"
653
"    a path-like object.  On some platforms, path may also be specified\n"
654
"    as an open file descriptor.  If this functionality is unavailable,\n"
655
"    using it raises an exception.\n"
656
"  mode\n"
657
"    Operating-system mode bitfield.\n"
658
"    Be careful when using number literals for *mode*. The conventional\n"
659
"    UNIX notation for numeric modes uses an octal base, which needs to\n"
660
"    be indicated with a ``0o`` prefix in Python.\n"
661
"  dir_fd\n"
662
"    If not None, it should be a file descriptor open to a directory,\n"
663
"    and path should be relative; path will then be relative to that\n"
664
"    directory.\n"
665
"  follow_symlinks\n"
666
"    If False, and the last element of the path is a symbolic link,\n"
667
"    chmod will modify the symbolic link itself instead of the file\n"
668
"    the link points to.\n"
669
"\n"
670
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
671
"  an open file descriptor.\n"
672
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
673
"  If they are unavailable, using them will raise a NotImplementedError.");
674
675
#define OS_CHMOD_METHODDEF    \
676
    {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
677
678
static PyObject *
679
os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
680
              int follow_symlinks);
681
682
static PyObject *
683
os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
684
0
{
685
0
    PyObject *return_value = NULL;
686
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
687
688
0
    #define NUM_KEYWORDS 4
689
0
    static struct {
690
0
        PyGC_Head _this_is_not_used;
691
0
        PyObject_VAR_HEAD
692
0
        Py_hash_t ob_hash;
693
0
        PyObject *ob_item[NUM_KEYWORDS];
694
0
    } _kwtuple = {
695
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
696
0
        .ob_hash = -1,
697
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
698
0
    };
699
0
    #undef NUM_KEYWORDS
700
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
701
702
    #else  // !Py_BUILD_CORE
703
    #  define KWTUPLE NULL
704
    #endif  // !Py_BUILD_CORE
705
706
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
707
0
    static _PyArg_Parser _parser = {
708
0
        .keywords = _keywords,
709
0
        .fname = "chmod",
710
0
        .kwtuple = KWTUPLE,
711
0
    };
712
0
    #undef KWTUPLE
713
0
    PyObject *argsbuf[4];
714
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
715
0
    path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD);
716
0
    int mode;
717
0
    int dir_fd = DEFAULT_DIR_FD;
718
0
    int follow_symlinks = CHMOD_DEFAULT_FOLLOW_SYMLINKS;
719
720
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
721
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
722
0
    if (!args) {
723
0
        goto exit;
724
0
    }
725
0
    if (!path_converter(args[0], &path)) {
726
0
        goto exit;
727
0
    }
728
0
    mode = PyLong_AsInt(args[1]);
729
0
    if (mode == -1 && PyErr_Occurred()) {
730
0
        goto exit;
731
0
    }
732
0
    if (!noptargs) {
733
0
        goto skip_optional_kwonly;
734
0
    }
735
0
    if (args[2]) {
736
0
        if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
737
0
            goto exit;
738
0
        }
739
0
        if (!--noptargs) {
740
0
            goto skip_optional_kwonly;
741
0
        }
742
0
    }
743
0
    follow_symlinks = PyObject_IsTrue(args[3]);
744
0
    if (follow_symlinks < 0) {
745
0
        goto exit;
746
0
    }
747
0
skip_optional_kwonly:
748
0
    return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
749
750
0
exit:
751
    /* Cleanup for path */
752
0
    path_cleanup(&path);
753
754
0
    return return_value;
755
0
}
756
757
#if (defined(HAVE_FCHMOD) || defined(MS_WINDOWS))
758
759
PyDoc_STRVAR(os_fchmod__doc__,
760
"fchmod($module, /, fd, mode)\n"
761
"--\n"
762
"\n"
763
"Change the access permissions of the file given by file descriptor fd.\n"
764
"\n"
765
"  fd\n"
766
"    The file descriptor of the file to be modified.\n"
767
"  mode\n"
768
"    Operating-system mode bitfield.\n"
769
"    Be careful when using number literals for *mode*.  The conventional\n"
770
"    UNIX notation for numeric modes uses an octal base, which needs to\n"
771
"    be indicated with a ``0o`` prefix in Python.\n"
772
"\n"
773
"Equivalent to os.chmod(fd, mode).");
774
775
#define OS_FCHMOD_METHODDEF    \
776
    {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
777
778
static PyObject *
779
os_fchmod_impl(PyObject *module, int fd, int mode);
780
781
static PyObject *
782
os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
783
0
{
784
0
    PyObject *return_value = NULL;
785
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
786
787
0
    #define NUM_KEYWORDS 2
788
0
    static struct {
789
0
        PyGC_Head _this_is_not_used;
790
0
        PyObject_VAR_HEAD
791
0
        Py_hash_t ob_hash;
792
0
        PyObject *ob_item[NUM_KEYWORDS];
793
0
    } _kwtuple = {
794
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
795
0
        .ob_hash = -1,
796
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(mode), },
797
0
    };
798
0
    #undef NUM_KEYWORDS
799
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
800
801
    #else  // !Py_BUILD_CORE
802
    #  define KWTUPLE NULL
803
    #endif  // !Py_BUILD_CORE
804
805
0
    static const char * const _keywords[] = {"fd", "mode", NULL};
806
0
    static _PyArg_Parser _parser = {
807
0
        .keywords = _keywords,
808
0
        .fname = "fchmod",
809
0
        .kwtuple = KWTUPLE,
810
0
    };
811
0
    #undef KWTUPLE
812
0
    PyObject *argsbuf[2];
813
0
    int fd;
814
0
    int mode;
815
816
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
817
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
818
0
    if (!args) {
819
0
        goto exit;
820
0
    }
821
0
    fd = PyLong_AsInt(args[0]);
822
0
    if (fd == -1 && PyErr_Occurred()) {
823
0
        goto exit;
824
0
    }
825
0
    mode = PyLong_AsInt(args[1]);
826
0
    if (mode == -1 && PyErr_Occurred()) {
827
0
        goto exit;
828
0
    }
829
0
    return_value = os_fchmod_impl(module, fd, mode);
830
831
0
exit:
832
0
    return return_value;
833
0
}
834
835
#endif /* (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) */
836
837
#if (defined(HAVE_LCHMOD) || defined(MS_WINDOWS))
838
839
PyDoc_STRVAR(os_lchmod__doc__,
840
"lchmod($module, /, path, mode)\n"
841
"--\n"
842
"\n"
843
"Change the access permissions of a file, without following symbolic links.\n"
844
"\n"
845
"If path is a symlink, this affects the link itself rather than the\n"
846
"target.  Equivalent to chmod(path, mode, follow_symlinks=False).");
847
848
#define OS_LCHMOD_METHODDEF    \
849
    {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
850
851
static PyObject *
852
os_lchmod_impl(PyObject *module, path_t *path, int mode);
853
854
static PyObject *
855
os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
856
{
857
    PyObject *return_value = NULL;
858
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
859
860
    #define NUM_KEYWORDS 2
861
    static struct {
862
        PyGC_Head _this_is_not_used;
863
        PyObject_VAR_HEAD
864
        Py_hash_t ob_hash;
865
        PyObject *ob_item[NUM_KEYWORDS];
866
    } _kwtuple = {
867
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
868
        .ob_hash = -1,
869
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), },
870
    };
871
    #undef NUM_KEYWORDS
872
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
873
874
    #else  // !Py_BUILD_CORE
875
    #  define KWTUPLE NULL
876
    #endif  // !Py_BUILD_CORE
877
878
    static const char * const _keywords[] = {"path", "mode", NULL};
879
    static _PyArg_Parser _parser = {
880
        .keywords = _keywords,
881
        .fname = "lchmod",
882
        .kwtuple = KWTUPLE,
883
    };
884
    #undef KWTUPLE
885
    PyObject *argsbuf[2];
886
    path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0);
887
    int mode;
888
889
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
890
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
891
    if (!args) {
892
        goto exit;
893
    }
894
    if (!path_converter(args[0], &path)) {
895
        goto exit;
896
    }
897
    mode = PyLong_AsInt(args[1]);
898
    if (mode == -1 && PyErr_Occurred()) {
899
        goto exit;
900
    }
901
    return_value = os_lchmod_impl(module, &path, mode);
902
903
exit:
904
    /* Cleanup for path */
905
    path_cleanup(&path);
906
907
    return return_value;
908
}
909
910
#endif /* (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) */
911
912
#if defined(HAVE_CHFLAGS)
913
914
PyDoc_STRVAR(os_chflags__doc__,
915
"chflags($module, /, path, flags, follow_symlinks=True)\n"
916
"--\n"
917
"\n"
918
"Set file flags.\n"
919
"\n"
920
"If follow_symlinks is False, and the last element of the path is\n"
921
"a symbolic link, chflags() will change flags on the symbolic link itself\n"
922
"instead of the file the link points to.\n"
923
"follow_symlinks may not be implemented on your platform.  If it is\n"
924
"unavailable, using it will raise a NotImplementedError.");
925
926
#define OS_CHFLAGS_METHODDEF    \
927
    {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
928
929
static PyObject *
930
os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
931
                int follow_symlinks);
932
933
static PyObject *
934
os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
935
{
936
    PyObject *return_value = NULL;
937
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
938
939
    #define NUM_KEYWORDS 3
940
    static struct {
941
        PyGC_Head _this_is_not_used;
942
        PyObject_VAR_HEAD
943
        Py_hash_t ob_hash;
944
        PyObject *ob_item[NUM_KEYWORDS];
945
    } _kwtuple = {
946
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
947
        .ob_hash = -1,
948
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
949
    };
950
    #undef NUM_KEYWORDS
951
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
952
953
    #else  // !Py_BUILD_CORE
954
    #  define KWTUPLE NULL
955
    #endif  // !Py_BUILD_CORE
956
957
    static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
958
    static _PyArg_Parser _parser = {
959
        .keywords = _keywords,
960
        .fname = "chflags",
961
        .kwtuple = KWTUPLE,
962
    };
963
    #undef KWTUPLE
964
    PyObject *argsbuf[3];
965
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
966
    path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0);
967
    unsigned long flags;
968
    int follow_symlinks = 1;
969
970
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
971
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
972
    if (!args) {
973
        goto exit;
974
    }
975
    if (!path_converter(args[0], &path)) {
976
        goto exit;
977
    }
978
    if (!PyIndex_Check(args[1])) {
979
        _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]);
980
        goto exit;
981
    }
982
    {
983
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long),
984
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
985
                Py_ASNATIVEBYTES_ALLOW_INDEX |
986
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
987
        if (_bytes < 0) {
988
            goto exit;
989
        }
990
        if ((size_t)_bytes > sizeof(unsigned long)) {
991
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
992
                "integer value out of range", 1) < 0)
993
            {
994
                goto exit;
995
            }
996
        }
997
    }
998
    if (!noptargs) {
999
        goto skip_optional_pos;
1000
    }
1001
    follow_symlinks = PyObject_IsTrue(args[2]);
1002
    if (follow_symlinks < 0) {
1003
        goto exit;
1004
    }
1005
skip_optional_pos:
1006
    return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
1007
1008
exit:
1009
    /* Cleanup for path */
1010
    path_cleanup(&path);
1011
1012
    return return_value;
1013
}
1014
1015
#endif /* defined(HAVE_CHFLAGS) */
1016
1017
#if defined(HAVE_LCHFLAGS)
1018
1019
PyDoc_STRVAR(os_lchflags__doc__,
1020
"lchflags($module, /, path, flags)\n"
1021
"--\n"
1022
"\n"
1023
"Set file flags.\n"
1024
"\n"
1025
"This function will not follow symbolic links.\n"
1026
"Equivalent to chflags(path, flags, follow_symlinks=False).");
1027
1028
#define OS_LCHFLAGS_METHODDEF    \
1029
    {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
1030
1031
static PyObject *
1032
os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
1033
1034
static PyObject *
1035
os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1036
{
1037
    PyObject *return_value = NULL;
1038
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1039
1040
    #define NUM_KEYWORDS 2
1041
    static struct {
1042
        PyGC_Head _this_is_not_used;
1043
        PyObject_VAR_HEAD
1044
        Py_hash_t ob_hash;
1045
        PyObject *ob_item[NUM_KEYWORDS];
1046
    } _kwtuple = {
1047
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1048
        .ob_hash = -1,
1049
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), },
1050
    };
1051
    #undef NUM_KEYWORDS
1052
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1053
1054
    #else  // !Py_BUILD_CORE
1055
    #  define KWTUPLE NULL
1056
    #endif  // !Py_BUILD_CORE
1057
1058
    static const char * const _keywords[] = {"path", "flags", NULL};
1059
    static _PyArg_Parser _parser = {
1060
        .keywords = _keywords,
1061
        .fname = "lchflags",
1062
        .kwtuple = KWTUPLE,
1063
    };
1064
    #undef KWTUPLE
1065
    PyObject *argsbuf[2];
1066
    path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0);
1067
    unsigned long flags;
1068
1069
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1070
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1071
    if (!args) {
1072
        goto exit;
1073
    }
1074
    if (!path_converter(args[0], &path)) {
1075
        goto exit;
1076
    }
1077
    if (!PyIndex_Check(args[1])) {
1078
        _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]);
1079
        goto exit;
1080
    }
1081
    {
1082
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long),
1083
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
1084
                Py_ASNATIVEBYTES_ALLOW_INDEX |
1085
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
1086
        if (_bytes < 0) {
1087
            goto exit;
1088
        }
1089
        if ((size_t)_bytes > sizeof(unsigned long)) {
1090
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
1091
                "integer value out of range", 1) < 0)
1092
            {
1093
                goto exit;
1094
            }
1095
        }
1096
    }
1097
    return_value = os_lchflags_impl(module, &path, flags);
1098
1099
exit:
1100
    /* Cleanup for path */
1101
    path_cleanup(&path);
1102
1103
    return return_value;
1104
}
1105
1106
#endif /* defined(HAVE_LCHFLAGS) */
1107
1108
#if defined(HAVE_CHROOT)
1109
1110
PyDoc_STRVAR(os_chroot__doc__,
1111
"chroot($module, /, path)\n"
1112
"--\n"
1113
"\n"
1114
"Change root directory to path.");
1115
1116
#define OS_CHROOT_METHODDEF    \
1117
    {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
1118
1119
static PyObject *
1120
os_chroot_impl(PyObject *module, path_t *path);
1121
1122
static PyObject *
1123
os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1124
0
{
1125
0
    PyObject *return_value = NULL;
1126
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1127
1128
0
    #define NUM_KEYWORDS 1
1129
0
    static struct {
1130
0
        PyGC_Head _this_is_not_used;
1131
0
        PyObject_VAR_HEAD
1132
0
        Py_hash_t ob_hash;
1133
0
        PyObject *ob_item[NUM_KEYWORDS];
1134
0
    } _kwtuple = {
1135
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1136
0
        .ob_hash = -1,
1137
0
        .ob_item = { &_Py_ID(path), },
1138
0
    };
1139
0
    #undef NUM_KEYWORDS
1140
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1141
1142
    #else  // !Py_BUILD_CORE
1143
    #  define KWTUPLE NULL
1144
    #endif  // !Py_BUILD_CORE
1145
1146
0
    static const char * const _keywords[] = {"path", NULL};
1147
0
    static _PyArg_Parser _parser = {
1148
0
        .keywords = _keywords,
1149
0
        .fname = "chroot",
1150
0
        .kwtuple = KWTUPLE,
1151
0
    };
1152
0
    #undef KWTUPLE
1153
0
    PyObject *argsbuf[1];
1154
0
    path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0);
1155
1156
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1157
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1158
0
    if (!args) {
1159
0
        goto exit;
1160
0
    }
1161
0
    if (!path_converter(args[0], &path)) {
1162
0
        goto exit;
1163
0
    }
1164
0
    return_value = os_chroot_impl(module, &path);
1165
1166
0
exit:
1167
    /* Cleanup for path */
1168
0
    path_cleanup(&path);
1169
1170
0
    return return_value;
1171
0
}
1172
1173
#endif /* defined(HAVE_CHROOT) */
1174
1175
#if defined(HAVE_FSYNC)
1176
1177
PyDoc_STRVAR(os_fsync__doc__,
1178
"fsync($module, /, fd)\n"
1179
"--\n"
1180
"\n"
1181
"Force write of fd to disk.");
1182
1183
#define OS_FSYNC_METHODDEF    \
1184
    {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
1185
1186
static PyObject *
1187
os_fsync_impl(PyObject *module, int fd);
1188
1189
static PyObject *
1190
os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1191
0
{
1192
0
    PyObject *return_value = NULL;
1193
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1194
1195
0
    #define NUM_KEYWORDS 1
1196
0
    static struct {
1197
0
        PyGC_Head _this_is_not_used;
1198
0
        PyObject_VAR_HEAD
1199
0
        Py_hash_t ob_hash;
1200
0
        PyObject *ob_item[NUM_KEYWORDS];
1201
0
    } _kwtuple = {
1202
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1203
0
        .ob_hash = -1,
1204
0
        .ob_item = { &_Py_ID(fd), },
1205
0
    };
1206
0
    #undef NUM_KEYWORDS
1207
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1208
1209
    #else  // !Py_BUILD_CORE
1210
    #  define KWTUPLE NULL
1211
    #endif  // !Py_BUILD_CORE
1212
1213
0
    static const char * const _keywords[] = {"fd", NULL};
1214
0
    static _PyArg_Parser _parser = {
1215
0
        .keywords = _keywords,
1216
0
        .fname = "fsync",
1217
0
        .kwtuple = KWTUPLE,
1218
0
    };
1219
0
    #undef KWTUPLE
1220
0
    PyObject *argsbuf[1];
1221
0
    int fd;
1222
1223
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1224
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1225
0
    if (!args) {
1226
0
        goto exit;
1227
0
    }
1228
0
    fd = PyObject_AsFileDescriptor(args[0]);
1229
0
    if (fd < 0) {
1230
0
        goto exit;
1231
0
    }
1232
0
    return_value = os_fsync_impl(module, fd);
1233
1234
0
exit:
1235
0
    return return_value;
1236
0
}
1237
1238
#endif /* defined(HAVE_FSYNC) */
1239
1240
#if defined(HAVE_SYNC)
1241
1242
PyDoc_STRVAR(os_sync__doc__,
1243
"sync($module, /)\n"
1244
"--\n"
1245
"\n"
1246
"Force write of everything to disk.");
1247
1248
#define OS_SYNC_METHODDEF    \
1249
    {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
1250
1251
static PyObject *
1252
os_sync_impl(PyObject *module);
1253
1254
static PyObject *
1255
os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
1256
0
{
1257
0
    return os_sync_impl(module);
1258
0
}
1259
1260
#endif /* defined(HAVE_SYNC) */
1261
1262
#if defined(HAVE_FDATASYNC)
1263
1264
PyDoc_STRVAR(os_fdatasync__doc__,
1265
"fdatasync($module, /, fd)\n"
1266
"--\n"
1267
"\n"
1268
"Force write of fd to disk without forcing update of metadata.");
1269
1270
#define OS_FDATASYNC_METHODDEF    \
1271
    {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
1272
1273
static PyObject *
1274
os_fdatasync_impl(PyObject *module, int fd);
1275
1276
static PyObject *
1277
os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1278
0
{
1279
0
    PyObject *return_value = NULL;
1280
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1281
1282
0
    #define NUM_KEYWORDS 1
1283
0
    static struct {
1284
0
        PyGC_Head _this_is_not_used;
1285
0
        PyObject_VAR_HEAD
1286
0
        Py_hash_t ob_hash;
1287
0
        PyObject *ob_item[NUM_KEYWORDS];
1288
0
    } _kwtuple = {
1289
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1290
0
        .ob_hash = -1,
1291
0
        .ob_item = { &_Py_ID(fd), },
1292
0
    };
1293
0
    #undef NUM_KEYWORDS
1294
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1295
1296
    #else  // !Py_BUILD_CORE
1297
    #  define KWTUPLE NULL
1298
    #endif  // !Py_BUILD_CORE
1299
1300
0
    static const char * const _keywords[] = {"fd", NULL};
1301
0
    static _PyArg_Parser _parser = {
1302
0
        .keywords = _keywords,
1303
0
        .fname = "fdatasync",
1304
0
        .kwtuple = KWTUPLE,
1305
0
    };
1306
0
    #undef KWTUPLE
1307
0
    PyObject *argsbuf[1];
1308
0
    int fd;
1309
1310
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1311
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1312
0
    if (!args) {
1313
0
        goto exit;
1314
0
    }
1315
0
    fd = PyObject_AsFileDescriptor(args[0]);
1316
0
    if (fd < 0) {
1317
0
        goto exit;
1318
0
    }
1319
0
    return_value = os_fdatasync_impl(module, fd);
1320
1321
0
exit:
1322
0
    return return_value;
1323
0
}
1324
1325
#endif /* defined(HAVE_FDATASYNC) */
1326
1327
#if defined(HAVE_CHOWN)
1328
1329
PyDoc_STRVAR(os_chown__doc__,
1330
"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
1331
"--\n"
1332
"\n"
1333
"Change the owner and group id of path to the numeric uid and gid.\n"
1334
"\n"
1335
"  path\n"
1336
"    Path to be examined; can be string, bytes, a path-like object, or\n"
1337
"    open-file-descriptor int.\n"
1338
"  dir_fd\n"
1339
"    If not None, it should be a file descriptor open to a directory,\n"
1340
"    and path should be relative; path will then be relative to that\n"
1341
"    directory.\n"
1342
"  follow_symlinks\n"
1343
"    If False, and the last element of the path is a symbolic link,\n"
1344
"    stat will examine the symbolic link itself instead of the file\n"
1345
"    the link points to.\n"
1346
"\n"
1347
"path may always be specified as a string.  On some platforms, path may\n"
1348
"also be specified as an open file descriptor.  If this functionality is\n"
1349
"unavailable, using it raises an exception.\n"
1350
"If dir_fd is not None, it should be a file descriptor open to\n"
1351
"a directory, and path should be relative; path will then be relative to\n"
1352
"that directory.\n"
1353
"If follow_symlinks is False, and the last element of the path is\n"
1354
"a symbolic link, chown will modify the symbolic link itself instead of\n"
1355
"the file the link points to.\n"
1356
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
1357
"an open file descriptor.\n"
1358
"dir_fd and follow_symlinks may not be implemented on your platform.  If\n"
1359
"they are unavailable, using them will raise a NotImplementedError.");
1360
1361
#define OS_CHOWN_METHODDEF    \
1362
    {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
1363
1364
static PyObject *
1365
os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
1366
              int dir_fd, int follow_symlinks);
1367
1368
static PyObject *
1369
os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1370
0
{
1371
0
    PyObject *return_value = NULL;
1372
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1373
1374
0
    #define NUM_KEYWORDS 5
1375
0
    static struct {
1376
0
        PyGC_Head _this_is_not_used;
1377
0
        PyObject_VAR_HEAD
1378
0
        Py_hash_t ob_hash;
1379
0
        PyObject *ob_item[NUM_KEYWORDS];
1380
0
    } _kwtuple = {
1381
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1382
0
        .ob_hash = -1,
1383
0
        .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
1384
0
    };
1385
0
    #undef NUM_KEYWORDS
1386
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1387
1388
    #else  // !Py_BUILD_CORE
1389
    #  define KWTUPLE NULL
1390
    #endif  // !Py_BUILD_CORE
1391
1392
0
    static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
1393
0
    static _PyArg_Parser _parser = {
1394
0
        .keywords = _keywords,
1395
0
        .fname = "chown",
1396
0
        .kwtuple = KWTUPLE,
1397
0
    };
1398
0
    #undef KWTUPLE
1399
0
    PyObject *argsbuf[5];
1400
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
1401
0
    path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN);
1402
0
    uid_t uid;
1403
0
    gid_t gid;
1404
0
    int dir_fd = DEFAULT_DIR_FD;
1405
0
    int follow_symlinks = 1;
1406
1407
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1408
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1409
0
    if (!args) {
1410
0
        goto exit;
1411
0
    }
1412
0
    if (!path_converter(args[0], &path)) {
1413
0
        goto exit;
1414
0
    }
1415
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1416
0
        goto exit;
1417
0
    }
1418
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1419
0
        goto exit;
1420
0
    }
1421
0
    if (!noptargs) {
1422
0
        goto skip_optional_kwonly;
1423
0
    }
1424
0
    if (args[3]) {
1425
0
        if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
1426
0
            goto exit;
1427
0
        }
1428
0
        if (!--noptargs) {
1429
0
            goto skip_optional_kwonly;
1430
0
        }
1431
0
    }
1432
0
    follow_symlinks = PyObject_IsTrue(args[4]);
1433
0
    if (follow_symlinks < 0) {
1434
0
        goto exit;
1435
0
    }
1436
0
skip_optional_kwonly:
1437
0
    return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
1438
1439
0
exit:
1440
    /* Cleanup for path */
1441
0
    path_cleanup(&path);
1442
1443
0
    return return_value;
1444
0
}
1445
1446
#endif /* defined(HAVE_CHOWN) */
1447
1448
#if defined(HAVE_FCHOWN)
1449
1450
PyDoc_STRVAR(os_fchown__doc__,
1451
"fchown($module, /, fd, uid, gid)\n"
1452
"--\n"
1453
"\n"
1454
"Change the owner and group id of the file specified by file descriptor.\n"
1455
"\n"
1456
"Equivalent to os.chown(fd, uid, gid).");
1457
1458
#define OS_FCHOWN_METHODDEF    \
1459
    {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
1460
1461
static PyObject *
1462
os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
1463
1464
static PyObject *
1465
os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1466
0
{
1467
0
    PyObject *return_value = NULL;
1468
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1469
1470
0
    #define NUM_KEYWORDS 3
1471
0
    static struct {
1472
0
        PyGC_Head _this_is_not_used;
1473
0
        PyObject_VAR_HEAD
1474
0
        Py_hash_t ob_hash;
1475
0
        PyObject *ob_item[NUM_KEYWORDS];
1476
0
    } _kwtuple = {
1477
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1478
0
        .ob_hash = -1,
1479
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), },
1480
0
    };
1481
0
    #undef NUM_KEYWORDS
1482
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1483
1484
    #else  // !Py_BUILD_CORE
1485
    #  define KWTUPLE NULL
1486
    #endif  // !Py_BUILD_CORE
1487
1488
0
    static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
1489
0
    static _PyArg_Parser _parser = {
1490
0
        .keywords = _keywords,
1491
0
        .fname = "fchown",
1492
0
        .kwtuple = KWTUPLE,
1493
0
    };
1494
0
    #undef KWTUPLE
1495
0
    PyObject *argsbuf[3];
1496
0
    int fd;
1497
0
    uid_t uid;
1498
0
    gid_t gid;
1499
1500
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1501
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1502
0
    if (!args) {
1503
0
        goto exit;
1504
0
    }
1505
0
    fd = PyLong_AsInt(args[0]);
1506
0
    if (fd == -1 && PyErr_Occurred()) {
1507
0
        goto exit;
1508
0
    }
1509
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1510
0
        goto exit;
1511
0
    }
1512
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1513
0
        goto exit;
1514
0
    }
1515
0
    return_value = os_fchown_impl(module, fd, uid, gid);
1516
1517
0
exit:
1518
0
    return return_value;
1519
0
}
1520
1521
#endif /* defined(HAVE_FCHOWN) */
1522
1523
#if defined(HAVE_LCHOWN)
1524
1525
PyDoc_STRVAR(os_lchown__doc__,
1526
"lchown($module, /, path, uid, gid)\n"
1527
"--\n"
1528
"\n"
1529
"Change the owner and group id of path to the numeric uid and gid.\n"
1530
"\n"
1531
"This function will not follow symbolic links.\n"
1532
"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
1533
1534
#define OS_LCHOWN_METHODDEF    \
1535
    {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
1536
1537
static PyObject *
1538
os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
1539
1540
static PyObject *
1541
os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1542
0
{
1543
0
    PyObject *return_value = NULL;
1544
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1545
1546
0
    #define NUM_KEYWORDS 3
1547
0
    static struct {
1548
0
        PyGC_Head _this_is_not_used;
1549
0
        PyObject_VAR_HEAD
1550
0
        Py_hash_t ob_hash;
1551
0
        PyObject *ob_item[NUM_KEYWORDS];
1552
0
    } _kwtuple = {
1553
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1554
0
        .ob_hash = -1,
1555
0
        .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), },
1556
0
    };
1557
0
    #undef NUM_KEYWORDS
1558
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1559
1560
    #else  // !Py_BUILD_CORE
1561
    #  define KWTUPLE NULL
1562
    #endif  // !Py_BUILD_CORE
1563
1564
0
    static const char * const _keywords[] = {"path", "uid", "gid", NULL};
1565
0
    static _PyArg_Parser _parser = {
1566
0
        .keywords = _keywords,
1567
0
        .fname = "lchown",
1568
0
        .kwtuple = KWTUPLE,
1569
0
    };
1570
0
    #undef KWTUPLE
1571
0
    PyObject *argsbuf[3];
1572
0
    path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0);
1573
0
    uid_t uid;
1574
0
    gid_t gid;
1575
1576
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1577
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1578
0
    if (!args) {
1579
0
        goto exit;
1580
0
    }
1581
0
    if (!path_converter(args[0], &path)) {
1582
0
        goto exit;
1583
0
    }
1584
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1585
0
        goto exit;
1586
0
    }
1587
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1588
0
        goto exit;
1589
0
    }
1590
0
    return_value = os_lchown_impl(module, &path, uid, gid);
1591
1592
0
exit:
1593
    /* Cleanup for path */
1594
0
    path_cleanup(&path);
1595
1596
0
    return return_value;
1597
0
}
1598
1599
#endif /* defined(HAVE_LCHOWN) */
1600
1601
PyDoc_STRVAR(os_getcwd__doc__,
1602
"getcwd($module, /)\n"
1603
"--\n"
1604
"\n"
1605
"Return a unicode string representing the current working directory.");
1606
1607
#define OS_GETCWD_METHODDEF    \
1608
    {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
1609
1610
static PyObject *
1611
os_getcwd_impl(PyObject *module);
1612
1613
static PyObject *
1614
os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
1615
0
{
1616
0
    return os_getcwd_impl(module);
1617
0
}
1618
1619
PyDoc_STRVAR(os_getcwdb__doc__,
1620
"getcwdb($module, /)\n"
1621
"--\n"
1622
"\n"
1623
"Return a bytes string representing the current working directory.");
1624
1625
#define OS_GETCWDB_METHODDEF    \
1626
    {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
1627
1628
static PyObject *
1629
os_getcwdb_impl(PyObject *module);
1630
1631
static PyObject *
1632
os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
1633
0
{
1634
0
    return os_getcwdb_impl(module);
1635
0
}
1636
1637
#if defined(HAVE_LINK)
1638
1639
PyDoc_STRVAR(os_link__doc__,
1640
"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
1641
"     follow_symlinks=(os.name != \'nt\'))\n"
1642
"--\n"
1643
"\n"
1644
"Create a hard link to a file.\n"
1645
"\n"
1646
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1647
"descriptor open to a directory, and the respective path string (src or\n"
1648
"dst) should be relative; the path will then be relative to that\n"
1649
"directory.\n"
1650
"If follow_symlinks is False, and the last element of src is a symbolic\n"
1651
"link, link will create a link to the symbolic link itself instead of the\n"
1652
"file the link points to.\n"
1653
"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on\n"
1654
"your platform.  If they are unavailable, using them will raise\n"
1655
"a NotImplementedError.");
1656
1657
#define OS_LINK_METHODDEF    \
1658
    {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
1659
1660
static PyObject *
1661
os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1662
             int dst_dir_fd, int follow_symlinks);
1663
1664
static PyObject *
1665
os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1666
0
{
1667
0
    PyObject *return_value = NULL;
1668
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1669
1670
0
    #define NUM_KEYWORDS 5
1671
0
    static struct {
1672
0
        PyGC_Head _this_is_not_used;
1673
0
        PyObject_VAR_HEAD
1674
0
        Py_hash_t ob_hash;
1675
0
        PyObject *ob_item[NUM_KEYWORDS];
1676
0
    } _kwtuple = {
1677
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1678
0
        .ob_hash = -1,
1679
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), },
1680
0
    };
1681
0
    #undef NUM_KEYWORDS
1682
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1683
1684
    #else  // !Py_BUILD_CORE
1685
    #  define KWTUPLE NULL
1686
    #endif  // !Py_BUILD_CORE
1687
1688
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
1689
0
    static _PyArg_Parser _parser = {
1690
0
        .keywords = _keywords,
1691
0
        .fname = "link",
1692
0
        .kwtuple = KWTUPLE,
1693
0
    };
1694
0
    #undef KWTUPLE
1695
0
    PyObject *argsbuf[5];
1696
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1697
0
    path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0);
1698
0
    path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0);
1699
0
    int src_dir_fd = DEFAULT_DIR_FD;
1700
0
    int dst_dir_fd = DEFAULT_DIR_FD;
1701
0
    int follow_symlinks = -1;
1702
1703
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1704
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1705
0
    if (!args) {
1706
0
        goto exit;
1707
0
    }
1708
0
    if (!path_converter(args[0], &src)) {
1709
0
        goto exit;
1710
0
    }
1711
0
    if (!path_converter(args[1], &dst)) {
1712
0
        goto exit;
1713
0
    }
1714
0
    if (!noptargs) {
1715
0
        goto skip_optional_kwonly;
1716
0
    }
1717
0
    if (args[2]) {
1718
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
1719
0
            goto exit;
1720
0
        }
1721
0
        if (!--noptargs) {
1722
0
            goto skip_optional_kwonly;
1723
0
        }
1724
0
    }
1725
0
    if (args[3]) {
1726
0
        if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1727
0
            goto exit;
1728
0
        }
1729
0
        if (!--noptargs) {
1730
0
            goto skip_optional_kwonly;
1731
0
        }
1732
0
    }
1733
0
    follow_symlinks = PyObject_IsTrue(args[4]);
1734
0
    if (follow_symlinks < 0) {
1735
0
        goto exit;
1736
0
    }
1737
0
skip_optional_kwonly:
1738
0
    return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
1739
1740
0
exit:
1741
    /* Cleanup for src */
1742
0
    path_cleanup(&src);
1743
    /* Cleanup for dst */
1744
0
    path_cleanup(&dst);
1745
1746
0
    return return_value;
1747
0
}
1748
1749
#endif /* defined(HAVE_LINK) */
1750
1751
PyDoc_STRVAR(os_listdir__doc__,
1752
"listdir($module, /, path=None)\n"
1753
"--\n"
1754
"\n"
1755
"Return a list containing the names of the files in the directory.\n"
1756
"\n"
1757
"path can be specified as either str, bytes, or a path-like object.  If\n"
1758
"path is bytes, the filenames returned will also be bytes; in all other\n"
1759
"circumstances the filenames returned will be str.\n"
1760
"If path is None, uses the path=\'.\'.\n"
1761
"On some platforms, path may also be specified as an open file\n"
1762
"descriptor; the file descriptor must refer to a directory.  If this\n"
1763
"functionality is unavailable, using it raises NotImplementedError.\n"
1764
"\n"
1765
"The list is in arbitrary order.  It does not include the special\n"
1766
"entries \'.\' and \'..\' even if they are present in the directory.");
1767
1768
#define OS_LISTDIR_METHODDEF    \
1769
    {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
1770
1771
static PyObject *
1772
os_listdir_impl(PyObject *module, path_t *path);
1773
1774
static PyObject *
1775
os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1776
92
{
1777
92
    PyObject *return_value = NULL;
1778
92
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1779
1780
92
    #define NUM_KEYWORDS 1
1781
92
    static struct {
1782
92
        PyGC_Head _this_is_not_used;
1783
92
        PyObject_VAR_HEAD
1784
92
        Py_hash_t ob_hash;
1785
92
        PyObject *ob_item[NUM_KEYWORDS];
1786
92
    } _kwtuple = {
1787
92
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1788
92
        .ob_hash = -1,
1789
92
        .ob_item = { &_Py_ID(path), },
1790
92
    };
1791
92
    #undef NUM_KEYWORDS
1792
92
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1793
1794
    #else  // !Py_BUILD_CORE
1795
    #  define KWTUPLE NULL
1796
    #endif  // !Py_BUILD_CORE
1797
1798
92
    static const char * const _keywords[] = {"path", NULL};
1799
92
    static _PyArg_Parser _parser = {
1800
92
        .keywords = _keywords,
1801
92
        .fname = "listdir",
1802
92
        .kwtuple = KWTUPLE,
1803
92
    };
1804
92
    #undef KWTUPLE
1805
92
    PyObject *argsbuf[1];
1806
92
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1807
92
    path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
1808
1809
92
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1810
92
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1811
92
    if (!args) {
1812
0
        goto exit;
1813
0
    }
1814
92
    if (!noptargs) {
1815
0
        goto skip_optional_pos;
1816
0
    }
1817
92
    if (!path_converter(args[0], &path)) {
1818
0
        goto exit;
1819
0
    }
1820
92
skip_optional_pos:
1821
92
    return_value = os_listdir_impl(module, &path);
1822
1823
92
exit:
1824
    /* Cleanup for path */
1825
92
    path_cleanup(&path);
1826
1827
92
    return return_value;
1828
92
}
1829
1830
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
1831
1832
PyDoc_STRVAR(os_listdrives__doc__,
1833
"listdrives($module, /)\n"
1834
"--\n"
1835
"\n"
1836
"Return a list containing the names of drives in the system.\n"
1837
"\n"
1838
"A drive name typically looks like \'C:\\\\\'.");
1839
1840
#define OS_LISTDRIVES_METHODDEF    \
1841
    {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__},
1842
1843
static PyObject *
1844
os_listdrives_impl(PyObject *module);
1845
1846
static PyObject *
1847
os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored))
1848
{
1849
    return os_listdrives_impl(module);
1850
}
1851
1852
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
1853
1854
#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
1855
1856
PyDoc_STRVAR(os_listvolumes__doc__,
1857
"listvolumes($module, /)\n"
1858
"--\n"
1859
"\n"
1860
"Return a list containing the volumes in the system.\n"
1861
"\n"
1862
"Volumes are typically represented as a GUID path.");
1863
1864
#define OS_LISTVOLUMES_METHODDEF    \
1865
    {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__},
1866
1867
static PyObject *
1868
os_listvolumes_impl(PyObject *module);
1869
1870
static PyObject *
1871
os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored))
1872
{
1873
    return os_listvolumes_impl(module);
1874
}
1875
1876
#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
1877
1878
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
1879
1880
PyDoc_STRVAR(os_listmounts__doc__,
1881
"listmounts($module, /, volume)\n"
1882
"--\n"
1883
"\n"
1884
"Return a list containing mount points for a particular volume.\n"
1885
"\n"
1886
"\'volume\' should be a GUID path as returned from os.listvolumes.");
1887
1888
#define OS_LISTMOUNTS_METHODDEF    \
1889
    {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__},
1890
1891
static PyObject *
1892
os_listmounts_impl(PyObject *module, path_t *volume);
1893
1894
static PyObject *
1895
os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1896
{
1897
    PyObject *return_value = NULL;
1898
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1899
1900
    #define NUM_KEYWORDS 1
1901
    static struct {
1902
        PyGC_Head _this_is_not_used;
1903
        PyObject_VAR_HEAD
1904
        Py_hash_t ob_hash;
1905
        PyObject *ob_item[NUM_KEYWORDS];
1906
    } _kwtuple = {
1907
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1908
        .ob_hash = -1,
1909
        .ob_item = { &_Py_ID(volume), },
1910
    };
1911
    #undef NUM_KEYWORDS
1912
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1913
1914
    #else  // !Py_BUILD_CORE
1915
    #  define KWTUPLE NULL
1916
    #endif  // !Py_BUILD_CORE
1917
1918
    static const char * const _keywords[] = {"volume", NULL};
1919
    static _PyArg_Parser _parser = {
1920
        .keywords = _keywords,
1921
        .fname = "listmounts",
1922
        .kwtuple = KWTUPLE,
1923
    };
1924
    #undef KWTUPLE
1925
    PyObject *argsbuf[1];
1926
    path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0);
1927
1928
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1929
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1930
    if (!args) {
1931
        goto exit;
1932
    }
1933
    if (!path_converter(args[0], &volume)) {
1934
        goto exit;
1935
    }
1936
    return_value = os_listmounts_impl(module, &volume);
1937
1938
exit:
1939
    /* Cleanup for volume */
1940
    path_cleanup(&volume);
1941
1942
    return return_value;
1943
}
1944
1945
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
1946
1947
#if defined(MS_WINDOWS)
1948
1949
PyDoc_STRVAR(os__path_isdevdrive__doc__,
1950
"_path_isdevdrive($module, /, path)\n"
1951
"--\n"
1952
"\n"
1953
"Determines whether the specified path is on a Windows Dev Drive.");
1954
1955
#define OS__PATH_ISDEVDRIVE_METHODDEF    \
1956
    {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__},
1957
1958
static PyObject *
1959
os__path_isdevdrive_impl(PyObject *module, path_t *path);
1960
1961
static PyObject *
1962
os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1963
{
1964
    PyObject *return_value = NULL;
1965
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1966
1967
    #define NUM_KEYWORDS 1
1968
    static struct {
1969
        PyGC_Head _this_is_not_used;
1970
        PyObject_VAR_HEAD
1971
        Py_hash_t ob_hash;
1972
        PyObject *ob_item[NUM_KEYWORDS];
1973
    } _kwtuple = {
1974
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1975
        .ob_hash = -1,
1976
        .ob_item = { &_Py_ID(path), },
1977
    };
1978
    #undef NUM_KEYWORDS
1979
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1980
1981
    #else  // !Py_BUILD_CORE
1982
    #  define KWTUPLE NULL
1983
    #endif  // !Py_BUILD_CORE
1984
1985
    static const char * const _keywords[] = {"path", NULL};
1986
    static _PyArg_Parser _parser = {
1987
        .keywords = _keywords,
1988
        .fname = "_path_isdevdrive",
1989
        .kwtuple = KWTUPLE,
1990
    };
1991
    #undef KWTUPLE
1992
    PyObject *argsbuf[1];
1993
    path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0);
1994
1995
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1996
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1997
    if (!args) {
1998
        goto exit;
1999
    }
2000
    if (!path_converter(args[0], &path)) {
2001
        goto exit;
2002
    }
2003
    return_value = os__path_isdevdrive_impl(module, &path);
2004
2005
exit:
2006
    /* Cleanup for path */
2007
    path_cleanup(&path);
2008
2009
    return return_value;
2010
}
2011
2012
#endif /* defined(MS_WINDOWS) */
2013
2014
#if defined(MS_WINDOWS)
2015
2016
PyDoc_STRVAR(os__getfullpathname__doc__,
2017
"_getfullpathname($module, path, /)\n"
2018
"--\n"
2019
"\n");
2020
2021
#define OS__GETFULLPATHNAME_METHODDEF    \
2022
    {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
2023
2024
static PyObject *
2025
os__getfullpathname_impl(PyObject *module, path_t *path);
2026
2027
static PyObject *
2028
os__getfullpathname(PyObject *module, PyObject *arg)
2029
{
2030
    PyObject *return_value = NULL;
2031
    path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0);
2032
2033
    if (!path_converter(arg, &path)) {
2034
        goto exit;
2035
    }
2036
    return_value = os__getfullpathname_impl(module, &path);
2037
2038
exit:
2039
    /* Cleanup for path */
2040
    path_cleanup(&path);
2041
2042
    return return_value;
2043
}
2044
2045
#endif /* defined(MS_WINDOWS) */
2046
2047
#if defined(MS_WINDOWS)
2048
2049
PyDoc_STRVAR(os__getfinalpathname__doc__,
2050
"_getfinalpathname($module, path, /)\n"
2051
"--\n"
2052
"\n"
2053
"A helper function for samepath on windows.");
2054
2055
#define OS__GETFINALPATHNAME_METHODDEF    \
2056
    {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
2057
2058
static PyObject *
2059
os__getfinalpathname_impl(PyObject *module, path_t *path);
2060
2061
static PyObject *
2062
os__getfinalpathname(PyObject *module, PyObject *arg)
2063
{
2064
    PyObject *return_value = NULL;
2065
    path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0);
2066
2067
    if (!path_converter(arg, &path)) {
2068
        goto exit;
2069
    }
2070
    return_value = os__getfinalpathname_impl(module, &path);
2071
2072
exit:
2073
    /* Cleanup for path */
2074
    path_cleanup(&path);
2075
2076
    return return_value;
2077
}
2078
2079
#endif /* defined(MS_WINDOWS) */
2080
2081
#if defined(MS_WINDOWS)
2082
2083
PyDoc_STRVAR(os__findfirstfile__doc__,
2084
"_findfirstfile($module, path, /)\n"
2085
"--\n"
2086
"\n"
2087
"A function to get the real file name without accessing the file in Windows.");
2088
2089
#define OS__FINDFIRSTFILE_METHODDEF    \
2090
    {"_findfirstfile", (PyCFunction)os__findfirstfile, METH_O, os__findfirstfile__doc__},
2091
2092
static PyObject *
2093
os__findfirstfile_impl(PyObject *module, path_t *path);
2094
2095
static PyObject *
2096
os__findfirstfile(PyObject *module, PyObject *arg)
2097
{
2098
    PyObject *return_value = NULL;
2099
    path_t path = PATH_T_INITIALIZE_P("_findfirstfile", "path", 0, 0, 0, 0);
2100
2101
    if (!path_converter(arg, &path)) {
2102
        goto exit;
2103
    }
2104
    return_value = os__findfirstfile_impl(module, &path);
2105
2106
exit:
2107
    /* Cleanup for path */
2108
    path_cleanup(&path);
2109
2110
    return return_value;
2111
}
2112
2113
#endif /* defined(MS_WINDOWS) */
2114
2115
#if defined(MS_WINDOWS)
2116
2117
PyDoc_STRVAR(os__getvolumepathname__doc__,
2118
"_getvolumepathname($module, /, path)\n"
2119
"--\n"
2120
"\n"
2121
"A helper function for ismount on Win32.");
2122
2123
#define OS__GETVOLUMEPATHNAME_METHODDEF    \
2124
    {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
2125
2126
static PyObject *
2127
os__getvolumepathname_impl(PyObject *module, path_t *path);
2128
2129
static PyObject *
2130
os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2131
{
2132
    PyObject *return_value = NULL;
2133
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2134
2135
    #define NUM_KEYWORDS 1
2136
    static struct {
2137
        PyGC_Head _this_is_not_used;
2138
        PyObject_VAR_HEAD
2139
        Py_hash_t ob_hash;
2140
        PyObject *ob_item[NUM_KEYWORDS];
2141
    } _kwtuple = {
2142
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2143
        .ob_hash = -1,
2144
        .ob_item = { &_Py_ID(path), },
2145
    };
2146
    #undef NUM_KEYWORDS
2147
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2148
2149
    #else  // !Py_BUILD_CORE
2150
    #  define KWTUPLE NULL
2151
    #endif  // !Py_BUILD_CORE
2152
2153
    static const char * const _keywords[] = {"path", NULL};
2154
    static _PyArg_Parser _parser = {
2155
        .keywords = _keywords,
2156
        .fname = "_getvolumepathname",
2157
        .kwtuple = KWTUPLE,
2158
    };
2159
    #undef KWTUPLE
2160
    PyObject *argsbuf[1];
2161
    path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0);
2162
2163
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2164
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2165
    if (!args) {
2166
        goto exit;
2167
    }
2168
    if (!path_converter(args[0], &path)) {
2169
        goto exit;
2170
    }
2171
    return_value = os__getvolumepathname_impl(module, &path);
2172
2173
exit:
2174
    /* Cleanup for path */
2175
    path_cleanup(&path);
2176
2177
    return return_value;
2178
}
2179
2180
#endif /* defined(MS_WINDOWS) */
2181
2182
#if defined(MS_WINDOWS)
2183
2184
PyDoc_STRVAR(os__path_splitroot__doc__,
2185
"_path_splitroot($module, path, /)\n"
2186
"--\n"
2187
"\n"
2188
"Removes everything after the root on Win32.");
2189
2190
#define OS__PATH_SPLITROOT_METHODDEF    \
2191
    {"_path_splitroot", (PyCFunction)os__path_splitroot, METH_O, os__path_splitroot__doc__},
2192
2193
static PyObject *
2194
os__path_splitroot_impl(PyObject *module, path_t *path);
2195
2196
static PyObject *
2197
os__path_splitroot(PyObject *module, PyObject *arg)
2198
{
2199
    PyObject *return_value = NULL;
2200
    path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0);
2201
2202
    if (!path_converter(arg, &path)) {
2203
        goto exit;
2204
    }
2205
    return_value = os__path_splitroot_impl(module, &path);
2206
2207
exit:
2208
    /* Cleanup for path */
2209
    path_cleanup(&path);
2210
2211
    return return_value;
2212
}
2213
2214
#endif /* defined(MS_WINDOWS) */
2215
2216
#if defined(MS_WINDOWS)
2217
2218
PyDoc_STRVAR(os__path_exists__doc__,
2219
"_path_exists($module, /, path)\n"
2220
"--\n"
2221
"\n"
2222
"Test whether a path exists.  Returns False for broken symbolic links.");
2223
2224
#define OS__PATH_EXISTS_METHODDEF    \
2225
    {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__},
2226
2227
static int
2228
os__path_exists_impl(PyObject *module, path_t *path);
2229
2230
static PyObject *
2231
os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2232
{
2233
    PyObject *return_value = NULL;
2234
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2235
2236
    #define NUM_KEYWORDS 1
2237
    static struct {
2238
        PyGC_Head _this_is_not_used;
2239
        PyObject_VAR_HEAD
2240
        Py_hash_t ob_hash;
2241
        PyObject *ob_item[NUM_KEYWORDS];
2242
    } _kwtuple = {
2243
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2244
        .ob_hash = -1,
2245
        .ob_item = { &_Py_ID(path), },
2246
    };
2247
    #undef NUM_KEYWORDS
2248
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2249
2250
    #else  // !Py_BUILD_CORE
2251
    #  define KWTUPLE NULL
2252
    #endif  // !Py_BUILD_CORE
2253
2254
    static const char * const _keywords[] = {"path", NULL};
2255
    static _PyArg_Parser _parser = {
2256
        .keywords = _keywords,
2257
        .fname = "_path_exists",
2258
        .kwtuple = KWTUPLE,
2259
    };
2260
    #undef KWTUPLE
2261
    PyObject *argsbuf[1];
2262
    path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1);
2263
    int _return_value;
2264
2265
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2266
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2267
    if (!args) {
2268
        goto exit;
2269
    }
2270
    if (!path_converter(args[0], &path)) {
2271
        goto exit;
2272
    }
2273
    _return_value = os__path_exists_impl(module, &path);
2274
    if ((_return_value == -1) && PyErr_Occurred()) {
2275
        goto exit;
2276
    }
2277
    return_value = PyBool_FromLong((long)_return_value);
2278
2279
exit:
2280
    /* Cleanup for path */
2281
    path_cleanup(&path);
2282
2283
    return return_value;
2284
}
2285
2286
#endif /* defined(MS_WINDOWS) */
2287
2288
#if defined(MS_WINDOWS)
2289
2290
PyDoc_STRVAR(os__path_lexists__doc__,
2291
"_path_lexists($module, /, path)\n"
2292
"--\n"
2293
"\n"
2294
"Test whether a path exists.  Returns True for broken symbolic links.");
2295
2296
#define OS__PATH_LEXISTS_METHODDEF    \
2297
    {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__},
2298
2299
static int
2300
os__path_lexists_impl(PyObject *module, path_t *path);
2301
2302
static PyObject *
2303
os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2304
{
2305
    PyObject *return_value = NULL;
2306
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2307
2308
    #define NUM_KEYWORDS 1
2309
    static struct {
2310
        PyGC_Head _this_is_not_used;
2311
        PyObject_VAR_HEAD
2312
        Py_hash_t ob_hash;
2313
        PyObject *ob_item[NUM_KEYWORDS];
2314
    } _kwtuple = {
2315
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2316
        .ob_hash = -1,
2317
        .ob_item = { &_Py_ID(path), },
2318
    };
2319
    #undef NUM_KEYWORDS
2320
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2321
2322
    #else  // !Py_BUILD_CORE
2323
    #  define KWTUPLE NULL
2324
    #endif  // !Py_BUILD_CORE
2325
2326
    static const char * const _keywords[] = {"path", NULL};
2327
    static _PyArg_Parser _parser = {
2328
        .keywords = _keywords,
2329
        .fname = "_path_lexists",
2330
        .kwtuple = KWTUPLE,
2331
    };
2332
    #undef KWTUPLE
2333
    PyObject *argsbuf[1];
2334
    path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1);
2335
    int _return_value;
2336
2337
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2338
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2339
    if (!args) {
2340
        goto exit;
2341
    }
2342
    if (!path_converter(args[0], &path)) {
2343
        goto exit;
2344
    }
2345
    _return_value = os__path_lexists_impl(module, &path);
2346
    if ((_return_value == -1) && PyErr_Occurred()) {
2347
        goto exit;
2348
    }
2349
    return_value = PyBool_FromLong((long)_return_value);
2350
2351
exit:
2352
    /* Cleanup for path */
2353
    path_cleanup(&path);
2354
2355
    return return_value;
2356
}
2357
2358
#endif /* defined(MS_WINDOWS) */
2359
2360
#if defined(MS_WINDOWS)
2361
2362
PyDoc_STRVAR(os__path_isdir__doc__,
2363
"_path_isdir($module, path, /)\n"
2364
"--\n"
2365
"\n"
2366
"Return true if the pathname refers to an existing directory.");
2367
2368
#define OS__PATH_ISDIR_METHODDEF    \
2369
    {"_path_isdir", (PyCFunction)os__path_isdir, METH_O, os__path_isdir__doc__},
2370
2371
static int
2372
os__path_isdir_impl(PyObject *module, path_t *path);
2373
2374
static PyObject *
2375
os__path_isdir(PyObject *module, PyObject *arg)
2376
{
2377
    PyObject *return_value = NULL;
2378
    path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1);
2379
    int _return_value;
2380
2381
    if (!path_converter(arg, &path)) {
2382
        goto exit;
2383
    }
2384
    _return_value = os__path_isdir_impl(module, &path);
2385
    if ((_return_value == -1) && PyErr_Occurred()) {
2386
        goto exit;
2387
    }
2388
    return_value = PyBool_FromLong((long)_return_value);
2389
2390
exit:
2391
    /* Cleanup for path */
2392
    path_cleanup(&path);
2393
2394
    return return_value;
2395
}
2396
2397
#endif /* defined(MS_WINDOWS) */
2398
2399
#if defined(MS_WINDOWS)
2400
2401
PyDoc_STRVAR(os__path_isfile__doc__,
2402
"_path_isfile($module, /, path)\n"
2403
"--\n"
2404
"\n"
2405
"Test whether a path is a regular file");
2406
2407
#define OS__PATH_ISFILE_METHODDEF    \
2408
    {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
2409
2410
static int
2411
os__path_isfile_impl(PyObject *module, path_t *path);
2412
2413
static PyObject *
2414
os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2415
{
2416
    PyObject *return_value = NULL;
2417
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2418
2419
    #define NUM_KEYWORDS 1
2420
    static struct {
2421
        PyGC_Head _this_is_not_used;
2422
        PyObject_VAR_HEAD
2423
        Py_hash_t ob_hash;
2424
        PyObject *ob_item[NUM_KEYWORDS];
2425
    } _kwtuple = {
2426
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2427
        .ob_hash = -1,
2428
        .ob_item = { &_Py_ID(path), },
2429
    };
2430
    #undef NUM_KEYWORDS
2431
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2432
2433
    #else  // !Py_BUILD_CORE
2434
    #  define KWTUPLE NULL
2435
    #endif  // !Py_BUILD_CORE
2436
2437
    static const char * const _keywords[] = {"path", NULL};
2438
    static _PyArg_Parser _parser = {
2439
        .keywords = _keywords,
2440
        .fname = "_path_isfile",
2441
        .kwtuple = KWTUPLE,
2442
    };
2443
    #undef KWTUPLE
2444
    PyObject *argsbuf[1];
2445
    path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1);
2446
    int _return_value;
2447
2448
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2449
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2450
    if (!args) {
2451
        goto exit;
2452
    }
2453
    if (!path_converter(args[0], &path)) {
2454
        goto exit;
2455
    }
2456
    _return_value = os__path_isfile_impl(module, &path);
2457
    if ((_return_value == -1) && PyErr_Occurred()) {
2458
        goto exit;
2459
    }
2460
    return_value = PyBool_FromLong((long)_return_value);
2461
2462
exit:
2463
    /* Cleanup for path */
2464
    path_cleanup(&path);
2465
2466
    return return_value;
2467
}
2468
2469
#endif /* defined(MS_WINDOWS) */
2470
2471
#if defined(MS_WINDOWS)
2472
2473
PyDoc_STRVAR(os__path_islink__doc__,
2474
"_path_islink($module, /, path)\n"
2475
"--\n"
2476
"\n"
2477
"Test whether a path is a symbolic link");
2478
2479
#define OS__PATH_ISLINK_METHODDEF    \
2480
    {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
2481
2482
static int
2483
os__path_islink_impl(PyObject *module, path_t *path);
2484
2485
static PyObject *
2486
os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2487
{
2488
    PyObject *return_value = NULL;
2489
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2490
2491
    #define NUM_KEYWORDS 1
2492
    static struct {
2493
        PyGC_Head _this_is_not_used;
2494
        PyObject_VAR_HEAD
2495
        Py_hash_t ob_hash;
2496
        PyObject *ob_item[NUM_KEYWORDS];
2497
    } _kwtuple = {
2498
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2499
        .ob_hash = -1,
2500
        .ob_item = { &_Py_ID(path), },
2501
    };
2502
    #undef NUM_KEYWORDS
2503
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2504
2505
    #else  // !Py_BUILD_CORE
2506
    #  define KWTUPLE NULL
2507
    #endif  // !Py_BUILD_CORE
2508
2509
    static const char * const _keywords[] = {"path", NULL};
2510
    static _PyArg_Parser _parser = {
2511
        .keywords = _keywords,
2512
        .fname = "_path_islink",
2513
        .kwtuple = KWTUPLE,
2514
    };
2515
    #undef KWTUPLE
2516
    PyObject *argsbuf[1];
2517
    path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1);
2518
    int _return_value;
2519
2520
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2521
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2522
    if (!args) {
2523
        goto exit;
2524
    }
2525
    if (!path_converter(args[0], &path)) {
2526
        goto exit;
2527
    }
2528
    _return_value = os__path_islink_impl(module, &path);
2529
    if ((_return_value == -1) && PyErr_Occurred()) {
2530
        goto exit;
2531
    }
2532
    return_value = PyBool_FromLong((long)_return_value);
2533
2534
exit:
2535
    /* Cleanup for path */
2536
    path_cleanup(&path);
2537
2538
    return return_value;
2539
}
2540
2541
#endif /* defined(MS_WINDOWS) */
2542
2543
#if defined(MS_WINDOWS)
2544
2545
PyDoc_STRVAR(os__path_isjunction__doc__,
2546
"_path_isjunction($module, /, path)\n"
2547
"--\n"
2548
"\n"
2549
"Test whether a path is a junction");
2550
2551
#define OS__PATH_ISJUNCTION_METHODDEF    \
2552
    {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__},
2553
2554
static int
2555
os__path_isjunction_impl(PyObject *module, path_t *path);
2556
2557
static PyObject *
2558
os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2559
{
2560
    PyObject *return_value = NULL;
2561
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2562
2563
    #define NUM_KEYWORDS 1
2564
    static struct {
2565
        PyGC_Head _this_is_not_used;
2566
        PyObject_VAR_HEAD
2567
        Py_hash_t ob_hash;
2568
        PyObject *ob_item[NUM_KEYWORDS];
2569
    } _kwtuple = {
2570
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2571
        .ob_hash = -1,
2572
        .ob_item = { &_Py_ID(path), },
2573
    };
2574
    #undef NUM_KEYWORDS
2575
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2576
2577
    #else  // !Py_BUILD_CORE
2578
    #  define KWTUPLE NULL
2579
    #endif  // !Py_BUILD_CORE
2580
2581
    static const char * const _keywords[] = {"path", NULL};
2582
    static _PyArg_Parser _parser = {
2583
        .keywords = _keywords,
2584
        .fname = "_path_isjunction",
2585
        .kwtuple = KWTUPLE,
2586
    };
2587
    #undef KWTUPLE
2588
    PyObject *argsbuf[1];
2589
    path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1);
2590
    int _return_value;
2591
2592
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2593
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2594
    if (!args) {
2595
        goto exit;
2596
    }
2597
    if (!path_converter(args[0], &path)) {
2598
        goto exit;
2599
    }
2600
    _return_value = os__path_isjunction_impl(module, &path);
2601
    if ((_return_value == -1) && PyErr_Occurred()) {
2602
        goto exit;
2603
    }
2604
    return_value = PyBool_FromLong((long)_return_value);
2605
2606
exit:
2607
    /* Cleanup for path */
2608
    path_cleanup(&path);
2609
2610
    return return_value;
2611
}
2612
2613
#endif /* defined(MS_WINDOWS) */
2614
2615
PyDoc_STRVAR(os__path_splitroot_ex__doc__,
2616
"_path_splitroot_ex($module, path, /)\n"
2617
"--\n"
2618
"\n"
2619
"Split a pathname into drive, root and tail.\n"
2620
"\n"
2621
"The tail contains anything after the root.");
2622
2623
#define OS__PATH_SPLITROOT_EX_METHODDEF    \
2624
    {"_path_splitroot_ex", (PyCFunction)os__path_splitroot_ex, METH_O, os__path_splitroot_ex__doc__},
2625
2626
static PyObject *
2627
os__path_splitroot_ex_impl(PyObject *module, path_t *path);
2628
2629
static PyObject *
2630
os__path_splitroot_ex(PyObject *module, PyObject *arg)
2631
0
{
2632
0
    PyObject *return_value = NULL;
2633
0
    path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0);
2634
2635
0
    if (!path_converter(arg, &path)) {
2636
0
        goto exit;
2637
0
    }
2638
0
    return_value = os__path_splitroot_ex_impl(module, &path);
2639
2640
0
exit:
2641
    /* Cleanup for path */
2642
0
    path_cleanup(&path);
2643
2644
0
    return return_value;
2645
0
}
2646
2647
PyDoc_STRVAR(os__path_normpath__doc__,
2648
"_path_normpath($module, /, path)\n"
2649
"--\n"
2650
"\n"
2651
"Normalize path, eliminating double slashes, etc.");
2652
2653
#define OS__PATH_NORMPATH_METHODDEF    \
2654
    {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
2655
2656
static PyObject *
2657
os__path_normpath_impl(PyObject *module, path_t *path);
2658
2659
static PyObject *
2660
os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2661
100
{
2662
100
    PyObject *return_value = NULL;
2663
100
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2664
2665
100
    #define NUM_KEYWORDS 1
2666
100
    static struct {
2667
100
        PyGC_Head _this_is_not_used;
2668
100
        PyObject_VAR_HEAD
2669
100
        Py_hash_t ob_hash;
2670
100
        PyObject *ob_item[NUM_KEYWORDS];
2671
100
    } _kwtuple = {
2672
100
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2673
100
        .ob_hash = -1,
2674
100
        .ob_item = { &_Py_ID(path), },
2675
100
    };
2676
100
    #undef NUM_KEYWORDS
2677
100
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2678
2679
    #else  // !Py_BUILD_CORE
2680
    #  define KWTUPLE NULL
2681
    #endif  // !Py_BUILD_CORE
2682
2683
100
    static const char * const _keywords[] = {"path", NULL};
2684
100
    static _PyArg_Parser _parser = {
2685
100
        .keywords = _keywords,
2686
100
        .fname = "_path_normpath",
2687
100
        .kwtuple = KWTUPLE,
2688
100
    };
2689
100
    #undef KWTUPLE
2690
100
    PyObject *argsbuf[1];
2691
100
    path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0);
2692
2693
100
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2694
100
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2695
100
    if (!args) {
2696
0
        goto exit;
2697
0
    }
2698
100
    if (!path_converter(args[0], &path)) {
2699
0
        goto exit;
2700
0
    }
2701
100
    return_value = os__path_normpath_impl(module, &path);
2702
2703
100
exit:
2704
    /* Cleanup for path */
2705
100
    path_cleanup(&path);
2706
2707
100
    return return_value;
2708
100
}
2709
2710
PyDoc_STRVAR(os_mkdir__doc__,
2711
"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
2712
"--\n"
2713
"\n"
2714
"Create a directory.\n"
2715
"\n"
2716
"If dir_fd is not None, it should be a file descriptor open to\n"
2717
"a directory, and path should be relative; path will then be relative to\n"
2718
"that directory.\n"
2719
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
2720
"using it will raise a NotImplementedError.\n"
2721
"\n"
2722
"The mode argument is ignored on Windows.  Where it is used, the current\n"
2723
"umask value is first masked out.");
2724
2725
#define OS_MKDIR_METHODDEF    \
2726
    {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
2727
2728
static PyObject *
2729
os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
2730
2731
static PyObject *
2732
os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2733
0
{
2734
0
    PyObject *return_value = NULL;
2735
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2736
2737
0
    #define NUM_KEYWORDS 3
2738
0
    static struct {
2739
0
        PyGC_Head _this_is_not_used;
2740
0
        PyObject_VAR_HEAD
2741
0
        Py_hash_t ob_hash;
2742
0
        PyObject *ob_item[NUM_KEYWORDS];
2743
0
    } _kwtuple = {
2744
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2745
0
        .ob_hash = -1,
2746
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
2747
0
    };
2748
0
    #undef NUM_KEYWORDS
2749
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2750
2751
    #else  // !Py_BUILD_CORE
2752
    #  define KWTUPLE NULL
2753
    #endif  // !Py_BUILD_CORE
2754
2755
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
2756
0
    static _PyArg_Parser _parser = {
2757
0
        .keywords = _keywords,
2758
0
        .fname = "mkdir",
2759
0
        .kwtuple = KWTUPLE,
2760
0
    };
2761
0
    #undef KWTUPLE
2762
0
    PyObject *argsbuf[3];
2763
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
2764
0
    path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0);
2765
0
    int mode = 511;
2766
0
    int dir_fd = DEFAULT_DIR_FD;
2767
2768
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2769
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2770
0
    if (!args) {
2771
0
        goto exit;
2772
0
    }
2773
0
    if (!path_converter(args[0], &path)) {
2774
0
        goto exit;
2775
0
    }
2776
0
    if (!noptargs) {
2777
0
        goto skip_optional_pos;
2778
0
    }
2779
0
    if (args[1]) {
2780
0
        mode = PyLong_AsInt(args[1]);
2781
0
        if (mode == -1 && PyErr_Occurred()) {
2782
0
            goto exit;
2783
0
        }
2784
0
        if (!--noptargs) {
2785
0
            goto skip_optional_pos;
2786
0
        }
2787
0
    }
2788
0
skip_optional_pos:
2789
0
    if (!noptargs) {
2790
0
        goto skip_optional_kwonly;
2791
0
    }
2792
0
    if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
2793
0
        goto exit;
2794
0
    }
2795
0
skip_optional_kwonly:
2796
0
    return_value = os_mkdir_impl(module, &path, mode, dir_fd);
2797
2798
0
exit:
2799
    /* Cleanup for path */
2800
0
    path_cleanup(&path);
2801
2802
0
    return return_value;
2803
0
}
2804
2805
#if defined(HAVE_NICE)
2806
2807
PyDoc_STRVAR(os_nice__doc__,
2808
"nice($module, increment, /)\n"
2809
"--\n"
2810
"\n"
2811
"Add increment to the priority of process and return the new priority.");
2812
2813
#define OS_NICE_METHODDEF    \
2814
    {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
2815
2816
static PyObject *
2817
os_nice_impl(PyObject *module, int increment);
2818
2819
static PyObject *
2820
os_nice(PyObject *module, PyObject *arg)
2821
0
{
2822
0
    PyObject *return_value = NULL;
2823
0
    int increment;
2824
2825
0
    increment = PyLong_AsInt(arg);
2826
0
    if (increment == -1 && PyErr_Occurred()) {
2827
0
        goto exit;
2828
0
    }
2829
0
    return_value = os_nice_impl(module, increment);
2830
2831
0
exit:
2832
0
    return return_value;
2833
0
}
2834
2835
#endif /* defined(HAVE_NICE) */
2836
2837
#if defined(HAVE_GETPRIORITY)
2838
2839
PyDoc_STRVAR(os_getpriority__doc__,
2840
"getpriority($module, /, which, who)\n"
2841
"--\n"
2842
"\n"
2843
"Return program scheduling priority.");
2844
2845
#define OS_GETPRIORITY_METHODDEF    \
2846
    {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
2847
2848
static PyObject *
2849
os_getpriority_impl(PyObject *module, int which, int who);
2850
2851
static PyObject *
2852
os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2853
0
{
2854
0
    PyObject *return_value = NULL;
2855
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2856
2857
0
    #define NUM_KEYWORDS 2
2858
0
    static struct {
2859
0
        PyGC_Head _this_is_not_used;
2860
0
        PyObject_VAR_HEAD
2861
0
        Py_hash_t ob_hash;
2862
0
        PyObject *ob_item[NUM_KEYWORDS];
2863
0
    } _kwtuple = {
2864
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2865
0
        .ob_hash = -1,
2866
0
        .ob_item = { &_Py_ID(which), &_Py_ID(who), },
2867
0
    };
2868
0
    #undef NUM_KEYWORDS
2869
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2870
2871
    #else  // !Py_BUILD_CORE
2872
    #  define KWTUPLE NULL
2873
    #endif  // !Py_BUILD_CORE
2874
2875
0
    static const char * const _keywords[] = {"which", "who", NULL};
2876
0
    static _PyArg_Parser _parser = {
2877
0
        .keywords = _keywords,
2878
0
        .fname = "getpriority",
2879
0
        .kwtuple = KWTUPLE,
2880
0
    };
2881
0
    #undef KWTUPLE
2882
0
    PyObject *argsbuf[2];
2883
0
    int which;
2884
0
    int who;
2885
2886
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2887
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2888
0
    if (!args) {
2889
0
        goto exit;
2890
0
    }
2891
0
    which = PyLong_AsInt(args[0]);
2892
0
    if (which == -1 && PyErr_Occurred()) {
2893
0
        goto exit;
2894
0
    }
2895
0
    who = PyLong_AsInt(args[1]);
2896
0
    if (who == -1 && PyErr_Occurred()) {
2897
0
        goto exit;
2898
0
    }
2899
0
    return_value = os_getpriority_impl(module, which, who);
2900
2901
0
exit:
2902
0
    return return_value;
2903
0
}
2904
2905
#endif /* defined(HAVE_GETPRIORITY) */
2906
2907
#if defined(HAVE_SETPRIORITY)
2908
2909
PyDoc_STRVAR(os_setpriority__doc__,
2910
"setpriority($module, /, which, who, priority)\n"
2911
"--\n"
2912
"\n"
2913
"Set program scheduling priority.");
2914
2915
#define OS_SETPRIORITY_METHODDEF    \
2916
    {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
2917
2918
static PyObject *
2919
os_setpriority_impl(PyObject *module, int which, int who, int priority);
2920
2921
static PyObject *
2922
os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2923
0
{
2924
0
    PyObject *return_value = NULL;
2925
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2926
2927
0
    #define NUM_KEYWORDS 3
2928
0
    static struct {
2929
0
        PyGC_Head _this_is_not_used;
2930
0
        PyObject_VAR_HEAD
2931
0
        Py_hash_t ob_hash;
2932
0
        PyObject *ob_item[NUM_KEYWORDS];
2933
0
    } _kwtuple = {
2934
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2935
0
        .ob_hash = -1,
2936
0
        .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), },
2937
0
    };
2938
0
    #undef NUM_KEYWORDS
2939
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2940
2941
    #else  // !Py_BUILD_CORE
2942
    #  define KWTUPLE NULL
2943
    #endif  // !Py_BUILD_CORE
2944
2945
0
    static const char * const _keywords[] = {"which", "who", "priority", NULL};
2946
0
    static _PyArg_Parser _parser = {
2947
0
        .keywords = _keywords,
2948
0
        .fname = "setpriority",
2949
0
        .kwtuple = KWTUPLE,
2950
0
    };
2951
0
    #undef KWTUPLE
2952
0
    PyObject *argsbuf[3];
2953
0
    int which;
2954
0
    int who;
2955
0
    int priority;
2956
2957
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2958
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2959
0
    if (!args) {
2960
0
        goto exit;
2961
0
    }
2962
0
    which = PyLong_AsInt(args[0]);
2963
0
    if (which == -1 && PyErr_Occurred()) {
2964
0
        goto exit;
2965
0
    }
2966
0
    who = PyLong_AsInt(args[1]);
2967
0
    if (who == -1 && PyErr_Occurred()) {
2968
0
        goto exit;
2969
0
    }
2970
0
    priority = PyLong_AsInt(args[2]);
2971
0
    if (priority == -1 && PyErr_Occurred()) {
2972
0
        goto exit;
2973
0
    }
2974
0
    return_value = os_setpriority_impl(module, which, who, priority);
2975
2976
0
exit:
2977
0
    return return_value;
2978
0
}
2979
2980
#endif /* defined(HAVE_SETPRIORITY) */
2981
2982
PyDoc_STRVAR(os_rename__doc__,
2983
"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
2984
"--\n"
2985
"\n"
2986
"Rename a file or directory.\n"
2987
"\n"
2988
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
2989
"descriptor open to a directory, and the respective path string (src or\n"
2990
"dst) should be relative; the path will then be relative to that\n"
2991
"directory.\n"
2992
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
2993
"If they are unavailable, using them will raise a NotImplementedError.");
2994
2995
#define OS_RENAME_METHODDEF    \
2996
    {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
2997
2998
static PyObject *
2999
os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
3000
               int dst_dir_fd);
3001
3002
static PyObject *
3003
os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3004
0
{
3005
0
    PyObject *return_value = NULL;
3006
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3007
3008
0
    #define NUM_KEYWORDS 4
3009
0
    static struct {
3010
0
        PyGC_Head _this_is_not_used;
3011
0
        PyObject_VAR_HEAD
3012
0
        Py_hash_t ob_hash;
3013
0
        PyObject *ob_item[NUM_KEYWORDS];
3014
0
    } _kwtuple = {
3015
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3016
0
        .ob_hash = -1,
3017
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
3018
0
    };
3019
0
    #undef NUM_KEYWORDS
3020
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3021
3022
    #else  // !Py_BUILD_CORE
3023
    #  define KWTUPLE NULL
3024
    #endif  // !Py_BUILD_CORE
3025
3026
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
3027
0
    static _PyArg_Parser _parser = {
3028
0
        .keywords = _keywords,
3029
0
        .fname = "rename",
3030
0
        .kwtuple = KWTUPLE,
3031
0
    };
3032
0
    #undef KWTUPLE
3033
0
    PyObject *argsbuf[4];
3034
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
3035
0
    path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0);
3036
0
    path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0);
3037
0
    int src_dir_fd = DEFAULT_DIR_FD;
3038
0
    int dst_dir_fd = DEFAULT_DIR_FD;
3039
3040
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3041
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3042
0
    if (!args) {
3043
0
        goto exit;
3044
0
    }
3045
0
    if (!path_converter(args[0], &src)) {
3046
0
        goto exit;
3047
0
    }
3048
0
    if (!path_converter(args[1], &dst)) {
3049
0
        goto exit;
3050
0
    }
3051
0
    if (!noptargs) {
3052
0
        goto skip_optional_kwonly;
3053
0
    }
3054
0
    if (args[2]) {
3055
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
3056
0
            goto exit;
3057
0
        }
3058
0
        if (!--noptargs) {
3059
0
            goto skip_optional_kwonly;
3060
0
        }
3061
0
    }
3062
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
3063
0
        goto exit;
3064
0
    }
3065
0
skip_optional_kwonly:
3066
0
    return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
3067
3068
0
exit:
3069
    /* Cleanup for src */
3070
0
    path_cleanup(&src);
3071
    /* Cleanup for dst */
3072
0
    path_cleanup(&dst);
3073
3074
0
    return return_value;
3075
0
}
3076
3077
PyDoc_STRVAR(os_replace__doc__,
3078
"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
3079
"--\n"
3080
"\n"
3081
"Rename a file or directory, overwriting the destination.\n"
3082
"\n"
3083
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
3084
"descriptor open to a directory, and the respective path string (src or\n"
3085
"dst) should be relative; the path will then be relative to that\n"
3086
"directory.\n"
3087
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
3088
"If they are unavailable, using them will raise a NotImplementedError.");
3089
3090
#define OS_REPLACE_METHODDEF    \
3091
    {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
3092
3093
static PyObject *
3094
os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
3095
                int dst_dir_fd);
3096
3097
static PyObject *
3098
os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3099
0
{
3100
0
    PyObject *return_value = NULL;
3101
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3102
3103
0
    #define NUM_KEYWORDS 4
3104
0
    static struct {
3105
0
        PyGC_Head _this_is_not_used;
3106
0
        PyObject_VAR_HEAD
3107
0
        Py_hash_t ob_hash;
3108
0
        PyObject *ob_item[NUM_KEYWORDS];
3109
0
    } _kwtuple = {
3110
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3111
0
        .ob_hash = -1,
3112
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
3113
0
    };
3114
0
    #undef NUM_KEYWORDS
3115
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3116
3117
    #else  // !Py_BUILD_CORE
3118
    #  define KWTUPLE NULL
3119
    #endif  // !Py_BUILD_CORE
3120
3121
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
3122
0
    static _PyArg_Parser _parser = {
3123
0
        .keywords = _keywords,
3124
0
        .fname = "replace",
3125
0
        .kwtuple = KWTUPLE,
3126
0
    };
3127
0
    #undef KWTUPLE
3128
0
    PyObject *argsbuf[4];
3129
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
3130
0
    path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0);
3131
0
    path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0);
3132
0
    int src_dir_fd = DEFAULT_DIR_FD;
3133
0
    int dst_dir_fd = DEFAULT_DIR_FD;
3134
3135
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3136
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3137
0
    if (!args) {
3138
0
        goto exit;
3139
0
    }
3140
0
    if (!path_converter(args[0], &src)) {
3141
0
        goto exit;
3142
0
    }
3143
0
    if (!path_converter(args[1], &dst)) {
3144
0
        goto exit;
3145
0
    }
3146
0
    if (!noptargs) {
3147
0
        goto skip_optional_kwonly;
3148
0
    }
3149
0
    if (args[2]) {
3150
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
3151
0
            goto exit;
3152
0
        }
3153
0
        if (!--noptargs) {
3154
0
            goto skip_optional_kwonly;
3155
0
        }
3156
0
    }
3157
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
3158
0
        goto exit;
3159
0
    }
3160
0
skip_optional_kwonly:
3161
0
    return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
3162
3163
0
exit:
3164
    /* Cleanup for src */
3165
0
    path_cleanup(&src);
3166
    /* Cleanup for dst */
3167
0
    path_cleanup(&dst);
3168
3169
0
    return return_value;
3170
0
}
3171
3172
PyDoc_STRVAR(os_rmdir__doc__,
3173
"rmdir($module, /, path, *, dir_fd=None)\n"
3174
"--\n"
3175
"\n"
3176
"Remove a directory.\n"
3177
"\n"
3178
"If dir_fd is not None, it should be a file descriptor open to\n"
3179
"a directory, and path should be relative; path will then be relative\n"
3180
"to that directory.\n"
3181
"dir_fd may not be implemented on your platform.\n"
3182
"If it is unavailable, using it will raise a NotImplementedError.");
3183
3184
#define OS_RMDIR_METHODDEF    \
3185
    {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
3186
3187
static PyObject *
3188
os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
3189
3190
static PyObject *
3191
os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3192
0
{
3193
0
    PyObject *return_value = NULL;
3194
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3195
3196
0
    #define NUM_KEYWORDS 2
3197
0
    static struct {
3198
0
        PyGC_Head _this_is_not_used;
3199
0
        PyObject_VAR_HEAD
3200
0
        Py_hash_t ob_hash;
3201
0
        PyObject *ob_item[NUM_KEYWORDS];
3202
0
    } _kwtuple = {
3203
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3204
0
        .ob_hash = -1,
3205
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3206
0
    };
3207
0
    #undef NUM_KEYWORDS
3208
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3209
3210
    #else  // !Py_BUILD_CORE
3211
    #  define KWTUPLE NULL
3212
    #endif  // !Py_BUILD_CORE
3213
3214
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3215
0
    static _PyArg_Parser _parser = {
3216
0
        .keywords = _keywords,
3217
0
        .fname = "rmdir",
3218
0
        .kwtuple = KWTUPLE,
3219
0
    };
3220
0
    #undef KWTUPLE
3221
0
    PyObject *argsbuf[2];
3222
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3223
0
    path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0);
3224
0
    int dir_fd = DEFAULT_DIR_FD;
3225
3226
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3227
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3228
0
    if (!args) {
3229
0
        goto exit;
3230
0
    }
3231
0
    if (!path_converter(args[0], &path)) {
3232
0
        goto exit;
3233
0
    }
3234
0
    if (!noptargs) {
3235
0
        goto skip_optional_kwonly;
3236
0
    }
3237
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3238
0
        goto exit;
3239
0
    }
3240
0
skip_optional_kwonly:
3241
0
    return_value = os_rmdir_impl(module, &path, dir_fd);
3242
3243
0
exit:
3244
    /* Cleanup for path */
3245
0
    path_cleanup(&path);
3246
3247
0
    return return_value;
3248
0
}
3249
3250
#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
3251
3252
PyDoc_STRVAR(os_system__doc__,
3253
"system($module, /, command)\n"
3254
"--\n"
3255
"\n"
3256
"Execute the command in a subshell.");
3257
3258
#define OS_SYSTEM_METHODDEF    \
3259
    {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3260
3261
static long
3262
os_system_impl(PyObject *module, const wchar_t *command);
3263
3264
static PyObject *
3265
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3266
{
3267
    PyObject *return_value = NULL;
3268
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3269
3270
    #define NUM_KEYWORDS 1
3271
    static struct {
3272
        PyGC_Head _this_is_not_used;
3273
        PyObject_VAR_HEAD
3274
        Py_hash_t ob_hash;
3275
        PyObject *ob_item[NUM_KEYWORDS];
3276
    } _kwtuple = {
3277
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3278
        .ob_hash = -1,
3279
        .ob_item = { &_Py_ID(command), },
3280
    };
3281
    #undef NUM_KEYWORDS
3282
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3283
3284
    #else  // !Py_BUILD_CORE
3285
    #  define KWTUPLE NULL
3286
    #endif  // !Py_BUILD_CORE
3287
3288
    static const char * const _keywords[] = {"command", NULL};
3289
    static _PyArg_Parser _parser = {
3290
        .keywords = _keywords,
3291
        .fname = "system",
3292
        .kwtuple = KWTUPLE,
3293
    };
3294
    #undef KWTUPLE
3295
    PyObject *argsbuf[1];
3296
    const wchar_t *command = NULL;
3297
    long _return_value;
3298
3299
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3300
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3301
    if (!args) {
3302
        goto exit;
3303
    }
3304
    if (!PyUnicode_Check(args[0])) {
3305
        _PyArg_BadArgument("system", "argument 'command'", "str", args[0]);
3306
        goto exit;
3307
    }
3308
    command = PyUnicode_AsWideCharString(args[0], NULL);
3309
    if (command == NULL) {
3310
        goto exit;
3311
    }
3312
    _return_value = os_system_impl(module, command);
3313
    if ((_return_value == -1) && PyErr_Occurred()) {
3314
        goto exit;
3315
    }
3316
    return_value = PyLong_FromLong(_return_value);
3317
3318
exit:
3319
    /* Cleanup for command */
3320
    PyMem_Free((void *)command);
3321
3322
    return return_value;
3323
}
3324
3325
#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
3326
3327
#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
3328
3329
PyDoc_STRVAR(os_system__doc__,
3330
"system($module, /, command)\n"
3331
"--\n"
3332
"\n"
3333
"Execute the command in a subshell.");
3334
3335
#define OS_SYSTEM_METHODDEF    \
3336
    {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3337
3338
static long
3339
os_system_impl(PyObject *module, PyObject *command);
3340
3341
static PyObject *
3342
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3343
0
{
3344
0
    PyObject *return_value = NULL;
3345
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3346
3347
0
    #define NUM_KEYWORDS 1
3348
0
    static struct {
3349
0
        PyGC_Head _this_is_not_used;
3350
0
        PyObject_VAR_HEAD
3351
0
        Py_hash_t ob_hash;
3352
0
        PyObject *ob_item[NUM_KEYWORDS];
3353
0
    } _kwtuple = {
3354
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3355
0
        .ob_hash = -1,
3356
0
        .ob_item = { &_Py_ID(command), },
3357
0
    };
3358
0
    #undef NUM_KEYWORDS
3359
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3360
3361
    #else  // !Py_BUILD_CORE
3362
    #  define KWTUPLE NULL
3363
    #endif  // !Py_BUILD_CORE
3364
3365
0
    static const char * const _keywords[] = {"command", NULL};
3366
0
    static _PyArg_Parser _parser = {
3367
0
        .keywords = _keywords,
3368
0
        .fname = "system",
3369
0
        .kwtuple = KWTUPLE,
3370
0
    };
3371
0
    #undef KWTUPLE
3372
0
    PyObject *argsbuf[1];
3373
0
    PyObject *command = NULL;
3374
0
    long _return_value;
3375
3376
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3377
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3378
0
    if (!args) {
3379
0
        goto exit;
3380
0
    }
3381
0
    if (!PyUnicode_FSConverter(args[0], &command)) {
3382
0
        goto exit;
3383
0
    }
3384
0
    _return_value = os_system_impl(module, command);
3385
0
    if ((_return_value == -1) && PyErr_Occurred()) {
3386
0
        goto exit;
3387
0
    }
3388
0
    return_value = PyLong_FromLong(_return_value);
3389
3390
0
exit:
3391
    /* Cleanup for command */
3392
0
    Py_XDECREF(command);
3393
3394
0
    return return_value;
3395
0
}
3396
3397
#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
3398
3399
#if defined(HAVE_UMASK)
3400
3401
PyDoc_STRVAR(os_umask__doc__,
3402
"umask($module, mask, /)\n"
3403
"--\n"
3404
"\n"
3405
"Set the current numeric umask and return the previous umask.");
3406
3407
#define OS_UMASK_METHODDEF    \
3408
    {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
3409
3410
static PyObject *
3411
os_umask_impl(PyObject *module, int mask);
3412
3413
static PyObject *
3414
os_umask(PyObject *module, PyObject *arg)
3415
0
{
3416
0
    PyObject *return_value = NULL;
3417
0
    int mask;
3418
3419
0
    mask = PyLong_AsInt(arg);
3420
0
    if (mask == -1 && PyErr_Occurred()) {
3421
0
        goto exit;
3422
0
    }
3423
0
    return_value = os_umask_impl(module, mask);
3424
3425
0
exit:
3426
0
    return return_value;
3427
0
}
3428
3429
#endif /* defined(HAVE_UMASK) */
3430
3431
PyDoc_STRVAR(os_unlink__doc__,
3432
"unlink($module, /, path, *, dir_fd=None)\n"
3433
"--\n"
3434
"\n"
3435
"Remove a file (same as remove()).\n"
3436
"\n"
3437
"If dir_fd is not None, it should be a file descriptor open to\n"
3438
"a directory, and path should be relative; path will then be relative to\n"
3439
"that directory.\n"
3440
"dir_fd may not be implemented on your platform.\n"
3441
"If it is unavailable, using it will raise a NotImplementedError.");
3442
3443
#define OS_UNLINK_METHODDEF    \
3444
    {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
3445
3446
static PyObject *
3447
os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
3448
3449
static PyObject *
3450
os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3451
0
{
3452
0
    PyObject *return_value = NULL;
3453
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3454
3455
0
    #define NUM_KEYWORDS 2
3456
0
    static struct {
3457
0
        PyGC_Head _this_is_not_used;
3458
0
        PyObject_VAR_HEAD
3459
0
        Py_hash_t ob_hash;
3460
0
        PyObject *ob_item[NUM_KEYWORDS];
3461
0
    } _kwtuple = {
3462
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3463
0
        .ob_hash = -1,
3464
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3465
0
    };
3466
0
    #undef NUM_KEYWORDS
3467
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3468
3469
    #else  // !Py_BUILD_CORE
3470
    #  define KWTUPLE NULL
3471
    #endif  // !Py_BUILD_CORE
3472
3473
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3474
0
    static _PyArg_Parser _parser = {
3475
0
        .keywords = _keywords,
3476
0
        .fname = "unlink",
3477
0
        .kwtuple = KWTUPLE,
3478
0
    };
3479
0
    #undef KWTUPLE
3480
0
    PyObject *argsbuf[2];
3481
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3482
0
    path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0);
3483
0
    int dir_fd = DEFAULT_DIR_FD;
3484
3485
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3486
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3487
0
    if (!args) {
3488
0
        goto exit;
3489
0
    }
3490
0
    if (!path_converter(args[0], &path)) {
3491
0
        goto exit;
3492
0
    }
3493
0
    if (!noptargs) {
3494
0
        goto skip_optional_kwonly;
3495
0
    }
3496
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3497
0
        goto exit;
3498
0
    }
3499
0
skip_optional_kwonly:
3500
0
    return_value = os_unlink_impl(module, &path, dir_fd);
3501
3502
0
exit:
3503
    /* Cleanup for path */
3504
0
    path_cleanup(&path);
3505
3506
0
    return return_value;
3507
0
}
3508
3509
PyDoc_STRVAR(os_remove__doc__,
3510
"remove($module, /, path, *, dir_fd=None)\n"
3511
"--\n"
3512
"\n"
3513
"Remove a file (same as unlink()).\n"
3514
"\n"
3515
"If dir_fd is not None, it should be a file descriptor open to\n"
3516
"a directory, and path should be relative; path will then be relative\n"
3517
"to that directory.\n"
3518
"dir_fd may not be implemented on your platform.\n"
3519
"If it is unavailable, using it will raise a NotImplementedError.");
3520
3521
#define OS_REMOVE_METHODDEF    \
3522
    {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
3523
3524
static PyObject *
3525
os_remove_impl(PyObject *module, path_t *path, int dir_fd);
3526
3527
static PyObject *
3528
os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3529
0
{
3530
0
    PyObject *return_value = NULL;
3531
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3532
3533
0
    #define NUM_KEYWORDS 2
3534
0
    static struct {
3535
0
        PyGC_Head _this_is_not_used;
3536
0
        PyObject_VAR_HEAD
3537
0
        Py_hash_t ob_hash;
3538
0
        PyObject *ob_item[NUM_KEYWORDS];
3539
0
    } _kwtuple = {
3540
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3541
0
        .ob_hash = -1,
3542
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3543
0
    };
3544
0
    #undef NUM_KEYWORDS
3545
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3546
3547
    #else  // !Py_BUILD_CORE
3548
    #  define KWTUPLE NULL
3549
    #endif  // !Py_BUILD_CORE
3550
3551
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3552
0
    static _PyArg_Parser _parser = {
3553
0
        .keywords = _keywords,
3554
0
        .fname = "remove",
3555
0
        .kwtuple = KWTUPLE,
3556
0
    };
3557
0
    #undef KWTUPLE
3558
0
    PyObject *argsbuf[2];
3559
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3560
0
    path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0);
3561
0
    int dir_fd = DEFAULT_DIR_FD;
3562
3563
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3564
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3565
0
    if (!args) {
3566
0
        goto exit;
3567
0
    }
3568
0
    if (!path_converter(args[0], &path)) {
3569
0
        goto exit;
3570
0
    }
3571
0
    if (!noptargs) {
3572
0
        goto skip_optional_kwonly;
3573
0
    }
3574
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3575
0
        goto exit;
3576
0
    }
3577
0
skip_optional_kwonly:
3578
0
    return_value = os_remove_impl(module, &path, dir_fd);
3579
3580
0
exit:
3581
    /* Cleanup for path */
3582
0
    path_cleanup(&path);
3583
3584
0
    return return_value;
3585
0
}
3586
3587
#if defined(HAVE_UNAME)
3588
3589
PyDoc_STRVAR(os_uname__doc__,
3590
"uname($module, /)\n"
3591
"--\n"
3592
"\n"
3593
"Return an object identifying the current operating system.\n"
3594
"\n"
3595
"The object behaves like a named tuple with the following fields:\n"
3596
"  (sysname, nodename, release, version, machine)");
3597
3598
#define OS_UNAME_METHODDEF    \
3599
    {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
3600
3601
static PyObject *
3602
os_uname_impl(PyObject *module);
3603
3604
static PyObject *
3605
os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
3606
0
{
3607
0
    return os_uname_impl(module);
3608
0
}
3609
3610
#endif /* defined(HAVE_UNAME) */
3611
3612
PyDoc_STRVAR(os_utime__doc__,
3613
"utime($module, /, path, times=None, *, ns=<unrepresentable>,\n"
3614
"      dir_fd=None, follow_symlinks=True)\n"
3615
"--\n"
3616
"\n"
3617
"Set the access and modified time of path.\n"
3618
"\n"
3619
"path may always be specified as a string.  On some platforms, path may\n"
3620
"also be specified as an open file descriptor.  If this functionality is\n"
3621
"unavailable, using it raises an exception.\n"
3622
"\n"
3623
"If times is not None, it must be a tuple (atime, mtime);\n"
3624
"atime and mtime should be expressed as float seconds since the epoch.\n"
3625
"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
3626
"atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
3627
"since the epoch.\n"
3628
"If times is None and ns is unspecified, utime uses the current time.\n"
3629
"Specifying tuples for both times and ns is an error.\n"
3630
"\n"
3631
"If dir_fd is not None, it should be a file descriptor open to\n"
3632
"a directory, and path should be relative; path will then be relative to\n"
3633
"that directory.\n"
3634
"If follow_symlinks is False, and the last element of the path is\n"
3635
"a symbolic link, utime will modify the symbolic link itself instead of\n"
3636
"the file the link points to.\n"
3637
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
3638
"an open file descriptor.\n"
3639
"dir_fd and follow_symlinks may not be available on your platform.\n"
3640
"If they are unavailable, using them will raise a NotImplementedError.");
3641
3642
#define OS_UTIME_METHODDEF    \
3643
    {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
3644
3645
static PyObject *
3646
os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
3647
              int dir_fd, int follow_symlinks);
3648
3649
static PyObject *
3650
os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3651
0
{
3652
0
    PyObject *return_value = NULL;
3653
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3654
3655
0
    #define NUM_KEYWORDS 5
3656
0
    static struct {
3657
0
        PyGC_Head _this_is_not_used;
3658
0
        PyObject_VAR_HEAD
3659
0
        Py_hash_t ob_hash;
3660
0
        PyObject *ob_item[NUM_KEYWORDS];
3661
0
    } _kwtuple = {
3662
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3663
0
        .ob_hash = -1,
3664
0
        .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
3665
0
    };
3666
0
    #undef NUM_KEYWORDS
3667
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3668
3669
    #else  // !Py_BUILD_CORE
3670
    #  define KWTUPLE NULL
3671
    #endif  // !Py_BUILD_CORE
3672
3673
0
    static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
3674
0
    static _PyArg_Parser _parser = {
3675
0
        .keywords = _keywords,
3676
0
        .fname = "utime",
3677
0
        .kwtuple = KWTUPLE,
3678
0
    };
3679
0
    #undef KWTUPLE
3680
0
    PyObject *argsbuf[5];
3681
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3682
0
    path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD);
3683
0
    PyObject *times = Py_None;
3684
0
    PyObject *ns = NULL;
3685
0
    int dir_fd = DEFAULT_DIR_FD;
3686
0
    int follow_symlinks = 1;
3687
3688
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3689
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3690
0
    if (!args) {
3691
0
        goto exit;
3692
0
    }
3693
0
    if (!path_converter(args[0], &path)) {
3694
0
        goto exit;
3695
0
    }
3696
0
    if (!noptargs) {
3697
0
        goto skip_optional_pos;
3698
0
    }
3699
0
    if (args[1]) {
3700
0
        times = args[1];
3701
0
        if (!--noptargs) {
3702
0
            goto skip_optional_pos;
3703
0
        }
3704
0
    }
3705
0
skip_optional_pos:
3706
0
    if (!noptargs) {
3707
0
        goto skip_optional_kwonly;
3708
0
    }
3709
0
    if (args[2]) {
3710
0
        ns = args[2];
3711
0
        if (!--noptargs) {
3712
0
            goto skip_optional_kwonly;
3713
0
        }
3714
0
    }
3715
0
    if (args[3]) {
3716
0
        if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
3717
0
            goto exit;
3718
0
        }
3719
0
        if (!--noptargs) {
3720
0
            goto skip_optional_kwonly;
3721
0
        }
3722
0
    }
3723
0
    follow_symlinks = PyObject_IsTrue(args[4]);
3724
0
    if (follow_symlinks < 0) {
3725
0
        goto exit;
3726
0
    }
3727
0
skip_optional_kwonly:
3728
0
    return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
3729
3730
0
exit:
3731
    /* Cleanup for path */
3732
0
    path_cleanup(&path);
3733
3734
0
    return return_value;
3735
0
}
3736
3737
PyDoc_STRVAR(os__exit__doc__,
3738
"_exit($module, /, status)\n"
3739
"--\n"
3740
"\n"
3741
"Exit to the system with specified status, without normal exit processing.");
3742
3743
#define OS__EXIT_METHODDEF    \
3744
    {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
3745
3746
static PyObject *
3747
os__exit_impl(PyObject *module, int status);
3748
3749
static PyObject *
3750
os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3751
0
{
3752
0
    PyObject *return_value = NULL;
3753
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3754
3755
0
    #define NUM_KEYWORDS 1
3756
0
    static struct {
3757
0
        PyGC_Head _this_is_not_used;
3758
0
        PyObject_VAR_HEAD
3759
0
        Py_hash_t ob_hash;
3760
0
        PyObject *ob_item[NUM_KEYWORDS];
3761
0
    } _kwtuple = {
3762
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3763
0
        .ob_hash = -1,
3764
0
        .ob_item = { &_Py_ID(status), },
3765
0
    };
3766
0
    #undef NUM_KEYWORDS
3767
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3768
3769
    #else  // !Py_BUILD_CORE
3770
    #  define KWTUPLE NULL
3771
    #endif  // !Py_BUILD_CORE
3772
3773
0
    static const char * const _keywords[] = {"status", NULL};
3774
0
    static _PyArg_Parser _parser = {
3775
0
        .keywords = _keywords,
3776
0
        .fname = "_exit",
3777
0
        .kwtuple = KWTUPLE,
3778
0
    };
3779
0
    #undef KWTUPLE
3780
0
    PyObject *argsbuf[1];
3781
0
    int status;
3782
3783
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3784
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3785
0
    if (!args) {
3786
0
        goto exit;
3787
0
    }
3788
0
    status = PyLong_AsInt(args[0]);
3789
0
    if (status == -1 && PyErr_Occurred()) {
3790
0
        goto exit;
3791
0
    }
3792
0
    return_value = os__exit_impl(module, status);
3793
3794
0
exit:
3795
0
    return return_value;
3796
0
}
3797
3798
#if defined(HAVE_EXECV)
3799
3800
PyDoc_STRVAR(os_execv__doc__,
3801
"execv($module, path, argv, /)\n"
3802
"--\n"
3803
"\n"
3804
"Execute an executable path with arguments, replacing current process.\n"
3805
"\n"
3806
"  path\n"
3807
"    Path of executable file.\n"
3808
"  argv\n"
3809
"    Tuple or list of strings.");
3810
3811
#define OS_EXECV_METHODDEF    \
3812
    {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__},
3813
3814
static PyObject *
3815
os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
3816
3817
static PyObject *
3818
os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3819
0
{
3820
0
    PyObject *return_value = NULL;
3821
0
    path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0);
3822
0
    PyObject *argv;
3823
3824
0
    if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
3825
0
        goto exit;
3826
0
    }
3827
0
    if (!path_converter(args[0], &path)) {
3828
0
        goto exit;
3829
0
    }
3830
0
    argv = args[1];
3831
0
    return_value = os_execv_impl(module, &path, argv);
3832
3833
0
exit:
3834
    /* Cleanup for path */
3835
0
    path_cleanup(&path);
3836
3837
0
    return return_value;
3838
0
}
3839
3840
#endif /* defined(HAVE_EXECV) */
3841
3842
#if defined(HAVE_EXECV)
3843
3844
PyDoc_STRVAR(os_execve__doc__,
3845
"execve($module, /, path, argv, env)\n"
3846
"--\n"
3847
"\n"
3848
"Execute an executable path with arguments, replacing current process.\n"
3849
"\n"
3850
"  path\n"
3851
"    Path of executable file.\n"
3852
"  argv\n"
3853
"    Tuple or list of strings.\n"
3854
"  env\n"
3855
"    Dictionary of strings mapping to strings.");
3856
3857
#define OS_EXECVE_METHODDEF    \
3858
    {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
3859
3860
static PyObject *
3861
os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
3862
3863
static PyObject *
3864
os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3865
0
{
3866
0
    PyObject *return_value = NULL;
3867
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3868
3869
0
    #define NUM_KEYWORDS 3
3870
0
    static struct {
3871
0
        PyGC_Head _this_is_not_used;
3872
0
        PyObject_VAR_HEAD
3873
0
        Py_hash_t ob_hash;
3874
0
        PyObject *ob_item[NUM_KEYWORDS];
3875
0
    } _kwtuple = {
3876
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3877
0
        .ob_hash = -1,
3878
0
        .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), },
3879
0
    };
3880
0
    #undef NUM_KEYWORDS
3881
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3882
3883
    #else  // !Py_BUILD_CORE
3884
    #  define KWTUPLE NULL
3885
    #endif  // !Py_BUILD_CORE
3886
3887
0
    static const char * const _keywords[] = {"path", "argv", "env", NULL};
3888
0
    static _PyArg_Parser _parser = {
3889
0
        .keywords = _keywords,
3890
0
        .fname = "execve",
3891
0
        .kwtuple = KWTUPLE,
3892
0
    };
3893
0
    #undef KWTUPLE
3894
0
    PyObject *argsbuf[3];
3895
0
    path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE);
3896
0
    PyObject *argv;
3897
0
    PyObject *env;
3898
3899
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3900
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3901
0
    if (!args) {
3902
0
        goto exit;
3903
0
    }
3904
0
    if (!path_converter(args[0], &path)) {
3905
0
        goto exit;
3906
0
    }
3907
0
    argv = args[1];
3908
0
    env = args[2];
3909
0
    return_value = os_execve_impl(module, &path, argv, env);
3910
3911
0
exit:
3912
    /* Cleanup for path */
3913
0
    path_cleanup(&path);
3914
3915
0
    return return_value;
3916
0
}
3917
3918
#endif /* defined(HAVE_EXECV) */
3919
3920
#if defined(HAVE_POSIX_SPAWN)
3921
3922
PyDoc_STRVAR(os_posix_spawn__doc__,
3923
"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
3924
"            setpgroup=None, resetids=False, setsid=False,\n"
3925
"            setsigmask=(), setsigdef=(), scheduler=None)\n"
3926
"--\n"
3927
"\n"
3928
"Execute the program specified by path in a new process.\n"
3929
"\n"
3930
"  path\n"
3931
"    Path of executable file.\n"
3932
"  argv\n"
3933
"    Tuple or list of strings.\n"
3934
"  env\n"
3935
"    Dictionary of strings mapping to strings.\n"
3936
"  file_actions\n"
3937
"    A sequence of file action tuples.\n"
3938
"  setpgroup\n"
3939
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
3940
"  resetids\n"
3941
"    If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
3942
"  setsid\n"
3943
"    If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP\n"
3944
"    will be activated.\n"
3945
"  setsigmask\n"
3946
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
3947
"  setsigdef\n"
3948
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
3949
"  scheduler\n"
3950
"    A tuple with the scheduler policy (optional) and parameters.");
3951
3952
#define OS_POSIX_SPAWN_METHODDEF    \
3953
    {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
3954
3955
static PyObject *
3956
os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
3957
                    PyObject *env, PyObject *file_actions,
3958
                    PyObject *setpgroup, int resetids, int setsid,
3959
                    PyObject *setsigmask, PyObject *setsigdef,
3960
                    PyObject *scheduler);
3961
3962
static PyObject *
3963
os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3964
0
{
3965
0
    PyObject *return_value = NULL;
3966
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3967
3968
0
    #define NUM_KEYWORDS 7
3969
0
    static struct {
3970
0
        PyGC_Head _this_is_not_used;
3971
0
        PyObject_VAR_HEAD
3972
0
        Py_hash_t ob_hash;
3973
0
        PyObject *ob_item[NUM_KEYWORDS];
3974
0
    } _kwtuple = {
3975
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3976
0
        .ob_hash = -1,
3977
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), },
3978
0
    };
3979
0
    #undef NUM_KEYWORDS
3980
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3981
3982
    #else  // !Py_BUILD_CORE
3983
    #  define KWTUPLE NULL
3984
    #endif  // !Py_BUILD_CORE
3985
3986
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
3987
0
    static _PyArg_Parser _parser = {
3988
0
        .keywords = _keywords,
3989
0
        .fname = "posix_spawn",
3990
0
        .kwtuple = KWTUPLE,
3991
0
    };
3992
0
    #undef KWTUPLE
3993
0
    PyObject *argsbuf[10];
3994
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
3995
0
    path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0);
3996
0
    PyObject *argv;
3997
0
    PyObject *env;
3998
0
    PyObject *file_actions = NULL;
3999
0
    PyObject *setpgroup = NULL;
4000
0
    int resetids = 0;
4001
0
    int setsid = 0;
4002
0
    PyObject *setsigmask = NULL;
4003
0
    PyObject *setsigdef = NULL;
4004
0
    PyObject *scheduler = NULL;
4005
4006
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4007
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4008
0
    if (!args) {
4009
0
        goto exit;
4010
0
    }
4011
0
    if (!path_converter(args[0], &path)) {
4012
0
        goto exit;
4013
0
    }
4014
0
    argv = args[1];
4015
0
    env = args[2];
4016
0
    if (!noptargs) {
4017
0
        goto skip_optional_kwonly;
4018
0
    }
4019
0
    if (args[3]) {
4020
0
        file_actions = args[3];
4021
0
        if (!--noptargs) {
4022
0
            goto skip_optional_kwonly;
4023
0
        }
4024
0
    }
4025
0
    if (args[4]) {
4026
0
        setpgroup = args[4];
4027
0
        if (!--noptargs) {
4028
0
            goto skip_optional_kwonly;
4029
0
        }
4030
0
    }
4031
0
    if (args[5]) {
4032
0
        resetids = PyObject_IsTrue(args[5]);
4033
0
        if (resetids < 0) {
4034
0
            goto exit;
4035
0
        }
4036
0
        if (!--noptargs) {
4037
0
            goto skip_optional_kwonly;
4038
0
        }
4039
0
    }
4040
0
    if (args[6]) {
4041
0
        setsid = PyObject_IsTrue(args[6]);
4042
0
        if (setsid < 0) {
4043
0
            goto exit;
4044
0
        }
4045
0
        if (!--noptargs) {
4046
0
            goto skip_optional_kwonly;
4047
0
        }
4048
0
    }
4049
0
    if (args[7]) {
4050
0
        setsigmask = args[7];
4051
0
        if (!--noptargs) {
4052
0
            goto skip_optional_kwonly;
4053
0
        }
4054
0
    }
4055
0
    if (args[8]) {
4056
0
        setsigdef = args[8];
4057
0
        if (!--noptargs) {
4058
0
            goto skip_optional_kwonly;
4059
0
        }
4060
0
    }
4061
0
    scheduler = args[9];
4062
0
skip_optional_kwonly:
4063
0
    return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
4064
4065
0
exit:
4066
    /* Cleanup for path */
4067
0
    path_cleanup(&path);
4068
4069
0
    return return_value;
4070
0
}
4071
4072
#endif /* defined(HAVE_POSIX_SPAWN) */
4073
4074
#if defined(HAVE_POSIX_SPAWNP)
4075
4076
PyDoc_STRVAR(os_posix_spawnp__doc__,
4077
"posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
4078
"             setpgroup=None, resetids=False, setsid=False,\n"
4079
"             setsigmask=(), setsigdef=(), scheduler=None)\n"
4080
"--\n"
4081
"\n"
4082
"Execute the program specified by path in a new process.\n"
4083
"\n"
4084
"  path\n"
4085
"    Path of executable file.\n"
4086
"  argv\n"
4087
"    Tuple or list of strings.\n"
4088
"  env\n"
4089
"    Dictionary of strings mapping to strings.\n"
4090
"  file_actions\n"
4091
"    A sequence of file action tuples.\n"
4092
"  setpgroup\n"
4093
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
4094
"  resetids\n"
4095
"    If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
4096
"  setsid\n"
4097
"    If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP\n"
4098
"    will be activated.\n"
4099
"  setsigmask\n"
4100
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
4101
"  setsigdef\n"
4102
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
4103
"  scheduler\n"
4104
"    A tuple with the scheduler policy (optional) and parameters.");
4105
4106
#define OS_POSIX_SPAWNP_METHODDEF    \
4107
    {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
4108
4109
static PyObject *
4110
os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
4111
                     PyObject *env, PyObject *file_actions,
4112
                     PyObject *setpgroup, int resetids, int setsid,
4113
                     PyObject *setsigmask, PyObject *setsigdef,
4114
                     PyObject *scheduler);
4115
4116
static PyObject *
4117
os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4118
0
{
4119
0
    PyObject *return_value = NULL;
4120
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4121
4122
0
    #define NUM_KEYWORDS 7
4123
0
    static struct {
4124
0
        PyGC_Head _this_is_not_used;
4125
0
        PyObject_VAR_HEAD
4126
0
        Py_hash_t ob_hash;
4127
0
        PyObject *ob_item[NUM_KEYWORDS];
4128
0
    } _kwtuple = {
4129
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4130
0
        .ob_hash = -1,
4131
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), },
4132
0
    };
4133
0
    #undef NUM_KEYWORDS
4134
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4135
4136
    #else  // !Py_BUILD_CORE
4137
    #  define KWTUPLE NULL
4138
    #endif  // !Py_BUILD_CORE
4139
4140
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
4141
0
    static _PyArg_Parser _parser = {
4142
0
        .keywords = _keywords,
4143
0
        .fname = "posix_spawnp",
4144
0
        .kwtuple = KWTUPLE,
4145
0
    };
4146
0
    #undef KWTUPLE
4147
0
    PyObject *argsbuf[10];
4148
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
4149
0
    path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0);
4150
0
    PyObject *argv;
4151
0
    PyObject *env;
4152
0
    PyObject *file_actions = NULL;
4153
0
    PyObject *setpgroup = NULL;
4154
0
    int resetids = 0;
4155
0
    int setsid = 0;
4156
0
    PyObject *setsigmask = NULL;
4157
0
    PyObject *setsigdef = NULL;
4158
0
    PyObject *scheduler = NULL;
4159
4160
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4161
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4162
0
    if (!args) {
4163
0
        goto exit;
4164
0
    }
4165
0
    if (!path_converter(args[0], &path)) {
4166
0
        goto exit;
4167
0
    }
4168
0
    argv = args[1];
4169
0
    env = args[2];
4170
0
    if (!noptargs) {
4171
0
        goto skip_optional_kwonly;
4172
0
    }
4173
0
    if (args[3]) {
4174
0
        file_actions = args[3];
4175
0
        if (!--noptargs) {
4176
0
            goto skip_optional_kwonly;
4177
0
        }
4178
0
    }
4179
0
    if (args[4]) {
4180
0
        setpgroup = args[4];
4181
0
        if (!--noptargs) {
4182
0
            goto skip_optional_kwonly;
4183
0
        }
4184
0
    }
4185
0
    if (args[5]) {
4186
0
        resetids = PyObject_IsTrue(args[5]);
4187
0
        if (resetids < 0) {
4188
0
            goto exit;
4189
0
        }
4190
0
        if (!--noptargs) {
4191
0
            goto skip_optional_kwonly;
4192
0
        }
4193
0
    }
4194
0
    if (args[6]) {
4195
0
        setsid = PyObject_IsTrue(args[6]);
4196
0
        if (setsid < 0) {
4197
0
            goto exit;
4198
0
        }
4199
0
        if (!--noptargs) {
4200
0
            goto skip_optional_kwonly;
4201
0
        }
4202
0
    }
4203
0
    if (args[7]) {
4204
0
        setsigmask = args[7];
4205
0
        if (!--noptargs) {
4206
0
            goto skip_optional_kwonly;
4207
0
        }
4208
0
    }
4209
0
    if (args[8]) {
4210
0
        setsigdef = args[8];
4211
0
        if (!--noptargs) {
4212
0
            goto skip_optional_kwonly;
4213
0
        }
4214
0
    }
4215
0
    scheduler = args[9];
4216
0
skip_optional_kwonly:
4217
0
    return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
4218
4219
0
exit:
4220
    /* Cleanup for path */
4221
0
    path_cleanup(&path);
4222
4223
0
    return return_value;
4224
0
}
4225
4226
#endif /* defined(HAVE_POSIX_SPAWNP) */
4227
4228
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4229
4230
PyDoc_STRVAR(os_spawnv__doc__,
4231
"spawnv($module, mode, path, argv, /)\n"
4232
"--\n"
4233
"\n"
4234
"Execute the program specified by path in a new process.\n"
4235
"\n"
4236
"  mode\n"
4237
"    Mode of process creation.\n"
4238
"  path\n"
4239
"    Path of executable file.\n"
4240
"  argv\n"
4241
"    Tuple or list of strings.");
4242
4243
#define OS_SPAWNV_METHODDEF    \
4244
    {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__},
4245
4246
static PyObject *
4247
os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
4248
4249
static PyObject *
4250
os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4251
{
4252
    PyObject *return_value = NULL;
4253
    int mode;
4254
    path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0);
4255
    PyObject *argv;
4256
4257
    if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
4258
        goto exit;
4259
    }
4260
    mode = PyLong_AsInt(args[0]);
4261
    if (mode == -1 && PyErr_Occurred()) {
4262
        goto exit;
4263
    }
4264
    if (!path_converter(args[1], &path)) {
4265
        goto exit;
4266
    }
4267
    argv = args[2];
4268
    return_value = os_spawnv_impl(module, mode, &path, argv);
4269
4270
exit:
4271
    /* Cleanup for path */
4272
    path_cleanup(&path);
4273
4274
    return return_value;
4275
}
4276
4277
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4278
4279
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4280
4281
PyDoc_STRVAR(os_spawnve__doc__,
4282
"spawnve($module, mode, path, argv, env, /)\n"
4283
"--\n"
4284
"\n"
4285
"Execute the program specified by path in a new process.\n"
4286
"\n"
4287
"  mode\n"
4288
"    Mode of process creation.\n"
4289
"  path\n"
4290
"    Path of executable file.\n"
4291
"  argv\n"
4292
"    Tuple or list of strings.\n"
4293
"  env\n"
4294
"    Dictionary of strings mapping to strings.");
4295
4296
#define OS_SPAWNVE_METHODDEF    \
4297
    {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__},
4298
4299
static PyObject *
4300
os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
4301
                PyObject *env);
4302
4303
static PyObject *
4304
os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4305
{
4306
    PyObject *return_value = NULL;
4307
    int mode;
4308
    path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0);
4309
    PyObject *argv;
4310
    PyObject *env;
4311
4312
    if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
4313
        goto exit;
4314
    }
4315
    mode = PyLong_AsInt(args[0]);
4316
    if (mode == -1 && PyErr_Occurred()) {
4317
        goto exit;
4318
    }
4319
    if (!path_converter(args[1], &path)) {
4320
        goto exit;
4321
    }
4322
    argv = args[2];
4323
    env = args[3];
4324
    return_value = os_spawnve_impl(module, mode, &path, argv, env);
4325
4326
exit:
4327
    /* Cleanup for path */
4328
    path_cleanup(&path);
4329
4330
    return return_value;
4331
}
4332
4333
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4334
4335
#if defined(HAVE_FORK)
4336
4337
PyDoc_STRVAR(os_register_at_fork__doc__,
4338
"register_at_fork($module, /, *, before=<unrepresentable>,\n"
4339
"                 after_in_child=<unrepresentable>,\n"
4340
"                 after_in_parent=<unrepresentable>)\n"
4341
"--\n"
4342
"\n"
4343
"Register callables to be called when forking a new process.\n"
4344
"\n"
4345
"  before\n"
4346
"    A callable to be called in the parent before the fork() syscall.\n"
4347
"  after_in_child\n"
4348
"    A callable to be called in the child after fork().\n"
4349
"  after_in_parent\n"
4350
"    A callable to be called in the parent after fork().\n"
4351
"\n"
4352
"\'before\' callbacks are called in reverse order.\n"
4353
"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
4354
4355
#define OS_REGISTER_AT_FORK_METHODDEF    \
4356
    {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
4357
4358
static PyObject *
4359
os_register_at_fork_impl(PyObject *module, PyObject *before,
4360
                         PyObject *after_in_child, PyObject *after_in_parent);
4361
4362
static PyObject *
4363
os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4364
0
{
4365
0
    PyObject *return_value = NULL;
4366
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4367
4368
0
    #define NUM_KEYWORDS 3
4369
0
    static struct {
4370
0
        PyGC_Head _this_is_not_used;
4371
0
        PyObject_VAR_HEAD
4372
0
        Py_hash_t ob_hash;
4373
0
        PyObject *ob_item[NUM_KEYWORDS];
4374
0
    } _kwtuple = {
4375
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4376
0
        .ob_hash = -1,
4377
0
        .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), },
4378
0
    };
4379
0
    #undef NUM_KEYWORDS
4380
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4381
4382
    #else  // !Py_BUILD_CORE
4383
    #  define KWTUPLE NULL
4384
    #endif  // !Py_BUILD_CORE
4385
4386
0
    static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
4387
0
    static _PyArg_Parser _parser = {
4388
0
        .keywords = _keywords,
4389
0
        .fname = "register_at_fork",
4390
0
        .kwtuple = KWTUPLE,
4391
0
    };
4392
0
    #undef KWTUPLE
4393
0
    PyObject *argsbuf[3];
4394
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
4395
0
    PyObject *before = NULL;
4396
0
    PyObject *after_in_child = NULL;
4397
0
    PyObject *after_in_parent = NULL;
4398
4399
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4400
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4401
0
    if (!args) {
4402
0
        goto exit;
4403
0
    }
4404
0
    if (!noptargs) {
4405
0
        goto skip_optional_kwonly;
4406
0
    }
4407
0
    if (args[0]) {
4408
0
        before = args[0];
4409
0
        if (!--noptargs) {
4410
0
            goto skip_optional_kwonly;
4411
0
        }
4412
0
    }
4413
0
    if (args[1]) {
4414
0
        after_in_child = args[1];
4415
0
        if (!--noptargs) {
4416
0
            goto skip_optional_kwonly;
4417
0
        }
4418
0
    }
4419
0
    after_in_parent = args[2];
4420
0
skip_optional_kwonly:
4421
0
    return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
4422
4423
0
exit:
4424
0
    return return_value;
4425
0
}
4426
4427
#endif /* defined(HAVE_FORK) */
4428
4429
#if defined(HAVE_FORK1)
4430
4431
PyDoc_STRVAR(os_fork1__doc__,
4432
"fork1($module, /)\n"
4433
"--\n"
4434
"\n"
4435
"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
4436
"\n"
4437
"Return 0 to child process and PID of child to parent process.");
4438
4439
#define OS_FORK1_METHODDEF    \
4440
    {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
4441
4442
static PyObject *
4443
os_fork1_impl(PyObject *module);
4444
4445
static PyObject *
4446
os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
4447
{
4448
    return os_fork1_impl(module);
4449
}
4450
4451
#endif /* defined(HAVE_FORK1) */
4452
4453
#if defined(HAVE_FORK)
4454
4455
PyDoc_STRVAR(os_fork__doc__,
4456
"fork($module, /)\n"
4457
"--\n"
4458
"\n"
4459
"Fork a child process.\n"
4460
"\n"
4461
"Return 0 to child process and PID of child to parent process.");
4462
4463
#define OS_FORK_METHODDEF    \
4464
    {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
4465
4466
static PyObject *
4467
os_fork_impl(PyObject *module);
4468
4469
static PyObject *
4470
os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
4471
0
{
4472
0
    return os_fork_impl(module);
4473
0
}
4474
4475
#endif /* defined(HAVE_FORK) */
4476
4477
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4478
4479
PyDoc_STRVAR(os_sched_get_priority_max__doc__,
4480
"sched_get_priority_max($module, /, policy)\n"
4481
"--\n"
4482
"\n"
4483
"Get the maximum scheduling priority for policy.");
4484
4485
#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF    \
4486
    {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
4487
4488
static PyObject *
4489
os_sched_get_priority_max_impl(PyObject *module, int policy);
4490
4491
static PyObject *
4492
os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4493
0
{
4494
0
    PyObject *return_value = NULL;
4495
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4496
4497
0
    #define NUM_KEYWORDS 1
4498
0
    static struct {
4499
0
        PyGC_Head _this_is_not_used;
4500
0
        PyObject_VAR_HEAD
4501
0
        Py_hash_t ob_hash;
4502
0
        PyObject *ob_item[NUM_KEYWORDS];
4503
0
    } _kwtuple = {
4504
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4505
0
        .ob_hash = -1,
4506
0
        .ob_item = { &_Py_ID(policy), },
4507
0
    };
4508
0
    #undef NUM_KEYWORDS
4509
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4510
4511
    #else  // !Py_BUILD_CORE
4512
    #  define KWTUPLE NULL
4513
    #endif  // !Py_BUILD_CORE
4514
4515
0
    static const char * const _keywords[] = {"policy", NULL};
4516
0
    static _PyArg_Parser _parser = {
4517
0
        .keywords = _keywords,
4518
0
        .fname = "sched_get_priority_max",
4519
0
        .kwtuple = KWTUPLE,
4520
0
    };
4521
0
    #undef KWTUPLE
4522
0
    PyObject *argsbuf[1];
4523
0
    int policy;
4524
4525
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4526
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4527
0
    if (!args) {
4528
0
        goto exit;
4529
0
    }
4530
0
    policy = PyLong_AsInt(args[0]);
4531
0
    if (policy == -1 && PyErr_Occurred()) {
4532
0
        goto exit;
4533
0
    }
4534
0
    return_value = os_sched_get_priority_max_impl(module, policy);
4535
4536
0
exit:
4537
0
    return return_value;
4538
0
}
4539
4540
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4541
4542
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4543
4544
PyDoc_STRVAR(os_sched_get_priority_min__doc__,
4545
"sched_get_priority_min($module, /, policy)\n"
4546
"--\n"
4547
"\n"
4548
"Get the minimum scheduling priority for policy.");
4549
4550
#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF    \
4551
    {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
4552
4553
static PyObject *
4554
os_sched_get_priority_min_impl(PyObject *module, int policy);
4555
4556
static PyObject *
4557
os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4558
0
{
4559
0
    PyObject *return_value = NULL;
4560
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4561
4562
0
    #define NUM_KEYWORDS 1
4563
0
    static struct {
4564
0
        PyGC_Head _this_is_not_used;
4565
0
        PyObject_VAR_HEAD
4566
0
        Py_hash_t ob_hash;
4567
0
        PyObject *ob_item[NUM_KEYWORDS];
4568
0
    } _kwtuple = {
4569
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4570
0
        .ob_hash = -1,
4571
0
        .ob_item = { &_Py_ID(policy), },
4572
0
    };
4573
0
    #undef NUM_KEYWORDS
4574
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4575
4576
    #else  // !Py_BUILD_CORE
4577
    #  define KWTUPLE NULL
4578
    #endif  // !Py_BUILD_CORE
4579
4580
0
    static const char * const _keywords[] = {"policy", NULL};
4581
0
    static _PyArg_Parser _parser = {
4582
0
        .keywords = _keywords,
4583
0
        .fname = "sched_get_priority_min",
4584
0
        .kwtuple = KWTUPLE,
4585
0
    };
4586
0
    #undef KWTUPLE
4587
0
    PyObject *argsbuf[1];
4588
0
    int policy;
4589
4590
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4591
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4592
0
    if (!args) {
4593
0
        goto exit;
4594
0
    }
4595
0
    policy = PyLong_AsInt(args[0]);
4596
0
    if (policy == -1 && PyErr_Occurred()) {
4597
0
        goto exit;
4598
0
    }
4599
0
    return_value = os_sched_get_priority_min_impl(module, policy);
4600
4601
0
exit:
4602
0
    return return_value;
4603
0
}
4604
4605
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4606
4607
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4608
4609
PyDoc_STRVAR(os_sched_getscheduler__doc__,
4610
"sched_getscheduler($module, pid, /)\n"
4611
"--\n"
4612
"\n"
4613
"Get the scheduling policy for the process identified by pid.\n"
4614
"\n"
4615
"Passing 0 for pid returns the scheduling policy for the calling process.");
4616
4617
#define OS_SCHED_GETSCHEDULER_METHODDEF    \
4618
    {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
4619
4620
static PyObject *
4621
os_sched_getscheduler_impl(PyObject *module, pid_t pid);
4622
4623
static PyObject *
4624
os_sched_getscheduler(PyObject *module, PyObject *arg)
4625
0
{
4626
0
    PyObject *return_value = NULL;
4627
0
    pid_t pid;
4628
4629
0
    pid = PyLong_AsPid(arg);
4630
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4631
0
        goto exit;
4632
0
    }
4633
0
    return_value = os_sched_getscheduler_impl(module, pid);
4634
4635
0
exit:
4636
0
    return return_value;
4637
0
}
4638
4639
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4640
4641
#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
4642
4643
PyDoc_STRVAR(os_sched_param__doc__,
4644
"sched_param(sched_priority)\n"
4645
"--\n"
4646
"\n"
4647
"Currently has only one field: sched_priority\n"
4648
"\n"
4649
"  sched_priority\n"
4650
"    A scheduling parameter.");
4651
4652
static PyObject *
4653
os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
4654
4655
static PyObject *
4656
os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
4657
0
{
4658
0
    PyObject *return_value = NULL;
4659
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4660
4661
0
    #define NUM_KEYWORDS 1
4662
0
    static struct {
4663
0
        PyGC_Head _this_is_not_used;
4664
0
        PyObject_VAR_HEAD
4665
0
        Py_hash_t ob_hash;
4666
0
        PyObject *ob_item[NUM_KEYWORDS];
4667
0
    } _kwtuple = {
4668
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4669
0
        .ob_hash = -1,
4670
0
        .ob_item = { &_Py_ID(sched_priority), },
4671
0
    };
4672
0
    #undef NUM_KEYWORDS
4673
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4674
4675
    #else  // !Py_BUILD_CORE
4676
    #  define KWTUPLE NULL
4677
    #endif  // !Py_BUILD_CORE
4678
4679
0
    static const char * const _keywords[] = {"sched_priority", NULL};
4680
0
    static _PyArg_Parser _parser = {
4681
0
        .keywords = _keywords,
4682
0
        .fname = "sched_param",
4683
0
        .kwtuple = KWTUPLE,
4684
0
    };
4685
0
    #undef KWTUPLE
4686
0
    PyObject *argsbuf[1];
4687
0
    PyObject * const *fastargs;
4688
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
4689
0
    PyObject *sched_priority;
4690
4691
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
4692
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4693
0
    if (!fastargs) {
4694
0
        goto exit;
4695
0
    }
4696
0
    sched_priority = fastargs[0];
4697
0
    return_value = os_sched_param_impl(type, sched_priority);
4698
4699
0
exit:
4700
0
    return return_value;
4701
0
}
4702
4703
#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
4704
4705
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4706
4707
PyDoc_STRVAR(os_sched_setscheduler__doc__,
4708
"sched_setscheduler($module, pid, policy, param, /)\n"
4709
"--\n"
4710
"\n"
4711
"Set the scheduling policy for the process identified by pid.\n"
4712
"\n"
4713
"If pid is 0, the calling process is changed.\n"
4714
"param is an instance of sched_param.");
4715
4716
#define OS_SCHED_SETSCHEDULER_METHODDEF    \
4717
    {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__},
4718
4719
static PyObject *
4720
os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
4721
                           PyObject *param_obj);
4722
4723
static PyObject *
4724
os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4725
0
{
4726
0
    PyObject *return_value = NULL;
4727
0
    pid_t pid;
4728
0
    int policy;
4729
0
    PyObject *param_obj;
4730
4731
0
    if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) {
4732
0
        goto exit;
4733
0
    }
4734
0
    pid = PyLong_AsPid(args[0]);
4735
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4736
0
        goto exit;
4737
0
    }
4738
0
    policy = PyLong_AsInt(args[1]);
4739
0
    if (policy == -1 && PyErr_Occurred()) {
4740
0
        goto exit;
4741
0
    }
4742
0
    param_obj = args[2];
4743
0
    return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj);
4744
4745
0
exit:
4746
0
    return return_value;
4747
0
}
4748
4749
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4750
4751
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4752
4753
PyDoc_STRVAR(os_sched_getparam__doc__,
4754
"sched_getparam($module, pid, /)\n"
4755
"--\n"
4756
"\n"
4757
"Returns scheduling parameters for the process identified by pid.\n"
4758
"\n"
4759
"If pid is 0, returns parameters for the calling process.\n"
4760
"Return value is an instance of sched_param.");
4761
4762
#define OS_SCHED_GETPARAM_METHODDEF    \
4763
    {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
4764
4765
static PyObject *
4766
os_sched_getparam_impl(PyObject *module, pid_t pid);
4767
4768
static PyObject *
4769
os_sched_getparam(PyObject *module, PyObject *arg)
4770
0
{
4771
0
    PyObject *return_value = NULL;
4772
0
    pid_t pid;
4773
4774
0
    pid = PyLong_AsPid(arg);
4775
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4776
0
        goto exit;
4777
0
    }
4778
0
    return_value = os_sched_getparam_impl(module, pid);
4779
4780
0
exit:
4781
0
    return return_value;
4782
0
}
4783
4784
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4785
4786
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4787
4788
PyDoc_STRVAR(os_sched_setparam__doc__,
4789
"sched_setparam($module, pid, param, /)\n"
4790
"--\n"
4791
"\n"
4792
"Set scheduling parameters for the process identified by pid.\n"
4793
"\n"
4794
"If pid is 0, sets parameters for the calling process.\n"
4795
"param should be an instance of sched_param.");
4796
4797
#define OS_SCHED_SETPARAM_METHODDEF    \
4798
    {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__},
4799
4800
static PyObject *
4801
os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj);
4802
4803
static PyObject *
4804
os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4805
0
{
4806
0
    PyObject *return_value = NULL;
4807
0
    pid_t pid;
4808
0
    PyObject *param_obj;
4809
4810
0
    if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) {
4811
0
        goto exit;
4812
0
    }
4813
0
    pid = PyLong_AsPid(args[0]);
4814
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4815
0
        goto exit;
4816
0
    }
4817
0
    param_obj = args[1];
4818
0
    return_value = os_sched_setparam_impl(module, pid, param_obj);
4819
4820
0
exit:
4821
0
    return return_value;
4822
0
}
4823
4824
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4825
4826
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
4827
4828
PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
4829
"sched_rr_get_interval($module, pid, /)\n"
4830
"--\n"
4831
"\n"
4832
"Return the round-robin quantum for the process identified by pid, in seconds.\n"
4833
"\n"
4834
"Value returned is a float.");
4835
4836
#define OS_SCHED_RR_GET_INTERVAL_METHODDEF    \
4837
    {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
4838
4839
static double
4840
os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
4841
4842
static PyObject *
4843
os_sched_rr_get_interval(PyObject *module, PyObject *arg)
4844
0
{
4845
0
    PyObject *return_value = NULL;
4846
0
    pid_t pid;
4847
0
    double _return_value;
4848
4849
0
    pid = PyLong_AsPid(arg);
4850
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4851
0
        goto exit;
4852
0
    }
4853
0
    _return_value = os_sched_rr_get_interval_impl(module, pid);
4854
0
    if ((_return_value == -1.0) && PyErr_Occurred()) {
4855
0
        goto exit;
4856
0
    }
4857
0
    return_value = PyFloat_FromDouble(_return_value);
4858
4859
0
exit:
4860
0
    return return_value;
4861
0
}
4862
4863
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
4864
4865
#if defined(HAVE_SCHED_H)
4866
4867
PyDoc_STRVAR(os_sched_yield__doc__,
4868
"sched_yield($module, /)\n"
4869
"--\n"
4870
"\n"
4871
"Voluntarily relinquish the CPU.");
4872
4873
#define OS_SCHED_YIELD_METHODDEF    \
4874
    {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
4875
4876
static PyObject *
4877
os_sched_yield_impl(PyObject *module);
4878
4879
static PyObject *
4880
os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
4881
0
{
4882
0
    return os_sched_yield_impl(module);
4883
0
}
4884
4885
#endif /* defined(HAVE_SCHED_H) */
4886
4887
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4888
4889
PyDoc_STRVAR(os_sched_setaffinity__doc__,
4890
"sched_setaffinity($module, pid, mask, /)\n"
4891
"--\n"
4892
"\n"
4893
"Set the CPU affinity of the process identified by pid to mask.\n"
4894
"\n"
4895
"mask should be an iterable of integers identifying CPUs.");
4896
4897
#define OS_SCHED_SETAFFINITY_METHODDEF    \
4898
    {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__},
4899
4900
static PyObject *
4901
os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
4902
4903
static PyObject *
4904
os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4905
0
{
4906
0
    PyObject *return_value = NULL;
4907
0
    pid_t pid;
4908
0
    PyObject *mask;
4909
4910
0
    if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) {
4911
0
        goto exit;
4912
0
    }
4913
0
    pid = PyLong_AsPid(args[0]);
4914
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4915
0
        goto exit;
4916
0
    }
4917
0
    mask = args[1];
4918
0
    return_value = os_sched_setaffinity_impl(module, pid, mask);
4919
4920
0
exit:
4921
0
    return return_value;
4922
0
}
4923
4924
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4925
4926
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4927
4928
PyDoc_STRVAR(os_sched_getaffinity__doc__,
4929
"sched_getaffinity($module, pid, /)\n"
4930
"--\n"
4931
"\n"
4932
"Return the affinity of the process identified by pid (or the current process if zero).\n"
4933
"\n"
4934
"The affinity is returned as a set of CPU identifiers.");
4935
4936
#define OS_SCHED_GETAFFINITY_METHODDEF    \
4937
    {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
4938
4939
static PyObject *
4940
os_sched_getaffinity_impl(PyObject *module, pid_t pid);
4941
4942
static PyObject *
4943
os_sched_getaffinity(PyObject *module, PyObject *arg)
4944
0
{
4945
0
    PyObject *return_value = NULL;
4946
0
    pid_t pid;
4947
4948
0
    pid = PyLong_AsPid(arg);
4949
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4950
0
        goto exit;
4951
0
    }
4952
0
    return_value = os_sched_getaffinity_impl(module, pid);
4953
4954
0
exit:
4955
0
    return return_value;
4956
0
}
4957
4958
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4959
4960
#if defined(HAVE_POSIX_OPENPT)
4961
4962
PyDoc_STRVAR(os_posix_openpt__doc__,
4963
"posix_openpt($module, oflag, /)\n"
4964
"--\n"
4965
"\n"
4966
"Open and return a file descriptor for a master pseudo-terminal device.\n"
4967
"\n"
4968
"Performs a posix_openpt() C function call. The oflag argument is used to\n"
4969
"set file status flags and file access modes as specified in the manual\n"
4970
"page of posix_openpt() of your system.");
4971
4972
#define OS_POSIX_OPENPT_METHODDEF    \
4973
    {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__},
4974
4975
static int
4976
os_posix_openpt_impl(PyObject *module, int oflag);
4977
4978
static PyObject *
4979
os_posix_openpt(PyObject *module, PyObject *arg)
4980
0
{
4981
0
    PyObject *return_value = NULL;
4982
0
    int oflag;
4983
0
    int _return_value;
4984
4985
0
    oflag = PyLong_AsInt(arg);
4986
0
    if (oflag == -1 && PyErr_Occurred()) {
4987
0
        goto exit;
4988
0
    }
4989
0
    _return_value = os_posix_openpt_impl(module, oflag);
4990
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4991
0
        goto exit;
4992
0
    }
4993
0
    return_value = PyLong_FromLong((long)_return_value);
4994
4995
0
exit:
4996
0
    return return_value;
4997
0
}
4998
4999
#endif /* defined(HAVE_POSIX_OPENPT) */
5000
5001
#if defined(HAVE_GRANTPT)
5002
5003
PyDoc_STRVAR(os_grantpt__doc__,
5004
"grantpt($module, fd, /)\n"
5005
"--\n"
5006
"\n"
5007
"Grant access to the slave pseudo-terminal device.\n"
5008
"\n"
5009
"  fd\n"
5010
"    File descriptor of a master pseudo-terminal device.\n"
5011
"\n"
5012
"Performs a grantpt() C function call.");
5013
5014
#define OS_GRANTPT_METHODDEF    \
5015
    {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__},
5016
5017
static PyObject *
5018
os_grantpt_impl(PyObject *module, int fd);
5019
5020
static PyObject *
5021
os_grantpt(PyObject *module, PyObject *arg)
5022
0
{
5023
0
    PyObject *return_value = NULL;
5024
0
    int fd;
5025
5026
0
    fd = PyObject_AsFileDescriptor(arg);
5027
0
    if (fd < 0) {
5028
0
        goto exit;
5029
0
    }
5030
0
    return_value = os_grantpt_impl(module, fd);
5031
5032
0
exit:
5033
0
    return return_value;
5034
0
}
5035
5036
#endif /* defined(HAVE_GRANTPT) */
5037
5038
#if defined(HAVE_UNLOCKPT)
5039
5040
PyDoc_STRVAR(os_unlockpt__doc__,
5041
"unlockpt($module, fd, /)\n"
5042
"--\n"
5043
"\n"
5044
"Unlock a pseudo-terminal master/slave pair.\n"
5045
"\n"
5046
"  fd\n"
5047
"    File descriptor of a master pseudo-terminal device.\n"
5048
"\n"
5049
"Performs an unlockpt() C function call.");
5050
5051
#define OS_UNLOCKPT_METHODDEF    \
5052
    {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__},
5053
5054
static PyObject *
5055
os_unlockpt_impl(PyObject *module, int fd);
5056
5057
static PyObject *
5058
os_unlockpt(PyObject *module, PyObject *arg)
5059
0
{
5060
0
    PyObject *return_value = NULL;
5061
0
    int fd;
5062
5063
0
    fd = PyObject_AsFileDescriptor(arg);
5064
0
    if (fd < 0) {
5065
0
        goto exit;
5066
0
    }
5067
0
    return_value = os_unlockpt_impl(module, fd);
5068
5069
0
exit:
5070
0
    return return_value;
5071
0
}
5072
5073
#endif /* defined(HAVE_UNLOCKPT) */
5074
5075
#if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R))
5076
5077
PyDoc_STRVAR(os_ptsname__doc__,
5078
"ptsname($module, fd, /)\n"
5079
"--\n"
5080
"\n"
5081
"Return the name of the slave pseudo-terminal device.\n"
5082
"\n"
5083
"  fd\n"
5084
"    File descriptor of a master pseudo-terminal device.\n"
5085
"\n"
5086
"If the ptsname_r() C function is available, it is called;\n"
5087
"otherwise, performs a ptsname() C function call.");
5088
5089
#define OS_PTSNAME_METHODDEF    \
5090
    {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__},
5091
5092
static PyObject *
5093
os_ptsname_impl(PyObject *module, int fd);
5094
5095
static PyObject *
5096
os_ptsname(PyObject *module, PyObject *arg)
5097
0
{
5098
0
    PyObject *return_value = NULL;
5099
0
    int fd;
5100
5101
0
    fd = PyObject_AsFileDescriptor(arg);
5102
0
    if (fd < 0) {
5103
0
        goto exit;
5104
0
    }
5105
0
    return_value = os_ptsname_impl(module, fd);
5106
5107
0
exit:
5108
0
    return return_value;
5109
0
}
5110
5111
#endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */
5112
5113
#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
5114
5115
PyDoc_STRVAR(os_openpty__doc__,
5116
"openpty($module, /)\n"
5117
"--\n"
5118
"\n"
5119
"Open a pseudo-terminal.\n"
5120
"\n"
5121
"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
5122
"for both the master and slave ends.");
5123
5124
#define OS_OPENPTY_METHODDEF    \
5125
    {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
5126
5127
static PyObject *
5128
os_openpty_impl(PyObject *module);
5129
5130
static PyObject *
5131
os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
5132
0
{
5133
0
    return os_openpty_impl(module);
5134
0
}
5135
5136
#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
5137
5138
#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY))
5139
5140
PyDoc_STRVAR(os_login_tty__doc__,
5141
"login_tty($module, fd, /)\n"
5142
"--\n"
5143
"\n"
5144
"Prepare the tty of which fd is a file descriptor for a new login session.\n"
5145
"\n"
5146
"Make the calling process a session leader; make the tty the\n"
5147
"controlling tty, the stdin, the stdout, and the stderr of the\n"
5148
"calling process; close fd.");
5149
5150
#define OS_LOGIN_TTY_METHODDEF    \
5151
    {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__},
5152
5153
static PyObject *
5154
os_login_tty_impl(PyObject *module, int fd);
5155
5156
static PyObject *
5157
os_login_tty(PyObject *module, PyObject *arg)
5158
0
{
5159
0
    PyObject *return_value = NULL;
5160
0
    int fd;
5161
5162
0
    fd = PyObject_AsFileDescriptor(arg);
5163
0
    if (fd < 0) {
5164
0
        goto exit;
5165
0
    }
5166
0
    return_value = os_login_tty_impl(module, fd);
5167
5168
0
exit:
5169
0
    return return_value;
5170
0
}
5171
5172
#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */
5173
5174
#if defined(HAVE_FORKPTY)
5175
5176
PyDoc_STRVAR(os_forkpty__doc__,
5177
"forkpty($module, /)\n"
5178
"--\n"
5179
"\n"
5180
"Fork a new process with a new pseudo-terminal as controlling tty.\n"
5181
"\n"
5182
"Returns a tuple of (pid, master_fd).\n"
5183
"Like fork(), return pid of 0 to the child process,\n"
5184
"and pid of child to the parent process.\n"
5185
"To both, return fd of newly opened pseudo-terminal.\n"
5186
"The master_fd is non-inheritable.");
5187
5188
#define OS_FORKPTY_METHODDEF    \
5189
    {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
5190
5191
static PyObject *
5192
os_forkpty_impl(PyObject *module);
5193
5194
static PyObject *
5195
os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
5196
0
{
5197
0
    return os_forkpty_impl(module);
5198
0
}
5199
5200
#endif /* defined(HAVE_FORKPTY) */
5201
5202
#if defined(HAVE_GETEGID)
5203
5204
PyDoc_STRVAR(os_getegid__doc__,
5205
"getegid($module, /)\n"
5206
"--\n"
5207
"\n"
5208
"Return the current process\'s effective group id.");
5209
5210
#define OS_GETEGID_METHODDEF    \
5211
    {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
5212
5213
static PyObject *
5214
os_getegid_impl(PyObject *module);
5215
5216
static PyObject *
5217
os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
5218
20
{
5219
20
    return os_getegid_impl(module);
5220
20
}
5221
5222
#endif /* defined(HAVE_GETEGID) */
5223
5224
#if defined(HAVE_GETEUID)
5225
5226
PyDoc_STRVAR(os_geteuid__doc__,
5227
"geteuid($module, /)\n"
5228
"--\n"
5229
"\n"
5230
"Return the current process\'s effective user id.");
5231
5232
#define OS_GETEUID_METHODDEF    \
5233
    {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
5234
5235
static PyObject *
5236
os_geteuid_impl(PyObject *module);
5237
5238
static PyObject *
5239
os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5240
20
{
5241
20
    return os_geteuid_impl(module);
5242
20
}
5243
5244
#endif /* defined(HAVE_GETEUID) */
5245
5246
#if defined(HAVE_GETGID)
5247
5248
PyDoc_STRVAR(os_getgid__doc__,
5249
"getgid($module, /)\n"
5250
"--\n"
5251
"\n"
5252
"Return the current process\'s group id.");
5253
5254
#define OS_GETGID_METHODDEF    \
5255
    {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
5256
5257
static PyObject *
5258
os_getgid_impl(PyObject *module);
5259
5260
static PyObject *
5261
os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
5262
20
{
5263
20
    return os_getgid_impl(module);
5264
20
}
5265
5266
#endif /* defined(HAVE_GETGID) */
5267
5268
#if defined(HAVE_GETPID)
5269
5270
PyDoc_STRVAR(os_getpid__doc__,
5271
"getpid($module, /)\n"
5272
"--\n"
5273
"\n"
5274
"Return the current process id.");
5275
5276
#define OS_GETPID_METHODDEF    \
5277
    {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
5278
5279
static PyObject *
5280
os_getpid_impl(PyObject *module);
5281
5282
static PyObject *
5283
os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
5284
0
{
5285
0
    return os_getpid_impl(module);
5286
0
}
5287
5288
#endif /* defined(HAVE_GETPID) */
5289
5290
#if defined(HAVE_GETGROUPLIST) && defined(__APPLE__)
5291
5292
PyDoc_STRVAR(os_getgrouplist__doc__,
5293
"getgrouplist($module, user, group, /)\n"
5294
"--\n"
5295
"\n"
5296
"Returns a list of groups to which a user belongs.\n"
5297
"\n"
5298
"  user\n"
5299
"    username to lookup\n"
5300
"  group\n"
5301
"    base group id of the user");
5302
5303
#define OS_GETGROUPLIST_METHODDEF    \
5304
    {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5305
5306
static PyObject *
5307
os_getgrouplist_impl(PyObject *module, const char *user, int basegid);
5308
5309
static PyObject *
5310
os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5311
{
5312
    PyObject *return_value = NULL;
5313
    const char *user;
5314
    int basegid;
5315
5316
    if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5317
        goto exit;
5318
    }
5319
    if (!PyUnicode_Check(args[0])) {
5320
        _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5321
        goto exit;
5322
    }
5323
    Py_ssize_t user_length;
5324
    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5325
    if (user == NULL) {
5326
        goto exit;
5327
    }
5328
    if (strlen(user) != (size_t)user_length) {
5329
        PyErr_SetString(PyExc_ValueError, "embedded null character");
5330
        goto exit;
5331
    }
5332
    basegid = PyLong_AsInt(args[1]);
5333
    if (basegid == -1 && PyErr_Occurred()) {
5334
        goto exit;
5335
    }
5336
    return_value = os_getgrouplist_impl(module, user, basegid);
5337
5338
exit:
5339
    return return_value;
5340
}
5341
5342
#endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */
5343
5344
#if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__)
5345
5346
PyDoc_STRVAR(os_getgrouplist__doc__,
5347
"getgrouplist($module, user, group, /)\n"
5348
"--\n"
5349
"\n"
5350
"Returns a list of groups to which a user belongs.\n"
5351
"\n"
5352
"  user\n"
5353
"    username to lookup\n"
5354
"  group\n"
5355
"    base group id of the user");
5356
5357
#define OS_GETGROUPLIST_METHODDEF    \
5358
    {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5359
5360
static PyObject *
5361
os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid);
5362
5363
static PyObject *
5364
os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5365
0
{
5366
0
    PyObject *return_value = NULL;
5367
0
    const char *user;
5368
0
    gid_t basegid;
5369
5370
0
    if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5371
0
        goto exit;
5372
0
    }
5373
0
    if (!PyUnicode_Check(args[0])) {
5374
0
        _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5375
0
        goto exit;
5376
0
    }
5377
0
    Py_ssize_t user_length;
5378
0
    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5379
0
    if (user == NULL) {
5380
0
        goto exit;
5381
0
    }
5382
0
    if (strlen(user) != (size_t)user_length) {
5383
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
5384
0
        goto exit;
5385
0
    }
5386
0
    if (!_Py_Gid_Converter(args[1], &basegid)) {
5387
0
        goto exit;
5388
0
    }
5389
0
    return_value = os_getgrouplist_impl(module, user, basegid);
5390
5391
0
exit:
5392
0
    return return_value;
5393
0
}
5394
5395
#endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */
5396
5397
#if defined(HAVE_GETGROUPS)
5398
5399
PyDoc_STRVAR(os_getgroups__doc__,
5400
"getgroups($module, /)\n"
5401
"--\n"
5402
"\n"
5403
"Return list of supplemental group IDs for the process.");
5404
5405
#define OS_GETGROUPS_METHODDEF    \
5406
    {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
5407
5408
static PyObject *
5409
os_getgroups_impl(PyObject *module);
5410
5411
static PyObject *
5412
os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
5413
0
{
5414
0
    return os_getgroups_impl(module);
5415
0
}
5416
5417
#endif /* defined(HAVE_GETGROUPS) */
5418
5419
#if defined(HAVE_INITGROUPS) && defined(__APPLE__)
5420
5421
PyDoc_STRVAR(os_initgroups__doc__,
5422
"initgroups($module, username, gid, /)\n"
5423
"--\n"
5424
"\n"
5425
"Initialize the group access list.\n"
5426
"\n"
5427
"Call the system initgroups() to initialize the group access list with\n"
5428
"all of the groups of which the specified username is a member, plus the\n"
5429
"specified group id.");
5430
5431
#define OS_INITGROUPS_METHODDEF    \
5432
    {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5433
5434
static PyObject *
5435
os_initgroups_impl(PyObject *module, PyObject *oname, int gid);
5436
5437
static PyObject *
5438
os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5439
{
5440
    PyObject *return_value = NULL;
5441
    PyObject *oname = NULL;
5442
    int gid;
5443
5444
    if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5445
        goto exit;
5446
    }
5447
    if (!PyUnicode_FSConverter(args[0], &oname)) {
5448
        goto exit;
5449
    }
5450
    gid = PyLong_AsInt(args[1]);
5451
    if (gid == -1 && PyErr_Occurred()) {
5452
        goto exit;
5453
    }
5454
    return_value = os_initgroups_impl(module, oname, gid);
5455
5456
exit:
5457
    /* Cleanup for oname */
5458
    Py_XDECREF(oname);
5459
5460
    return return_value;
5461
}
5462
5463
#endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */
5464
5465
#if defined(HAVE_INITGROUPS) && !defined(__APPLE__)
5466
5467
PyDoc_STRVAR(os_initgroups__doc__,
5468
"initgroups($module, username, gid, /)\n"
5469
"--\n"
5470
"\n"
5471
"Initialize the group access list.\n"
5472
"\n"
5473
"Call the system initgroups() to initialize the group access list with\n"
5474
"all of the groups of which the specified username is a member, plus the\n"
5475
"specified group id.");
5476
5477
#define OS_INITGROUPS_METHODDEF    \
5478
    {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5479
5480
static PyObject *
5481
os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid);
5482
5483
static PyObject *
5484
os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5485
0
{
5486
0
    PyObject *return_value = NULL;
5487
0
    PyObject *oname = NULL;
5488
0
    gid_t gid;
5489
5490
0
    if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5491
0
        goto exit;
5492
0
    }
5493
0
    if (!PyUnicode_FSConverter(args[0], &oname)) {
5494
0
        goto exit;
5495
0
    }
5496
0
    if (!_Py_Gid_Converter(args[1], &gid)) {
5497
0
        goto exit;
5498
0
    }
5499
0
    return_value = os_initgroups_impl(module, oname, gid);
5500
5501
0
exit:
5502
    /* Cleanup for oname */
5503
0
    Py_XDECREF(oname);
5504
5505
0
    return return_value;
5506
0
}
5507
5508
#endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */
5509
5510
#if defined(HAVE_GETPGID)
5511
5512
PyDoc_STRVAR(os_getpgid__doc__,
5513
"getpgid($module, /, pid)\n"
5514
"--\n"
5515
"\n"
5516
"Call the system call getpgid(), and return the result.");
5517
5518
#define OS_GETPGID_METHODDEF    \
5519
    {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
5520
5521
static PyObject *
5522
os_getpgid_impl(PyObject *module, pid_t pid);
5523
5524
static PyObject *
5525
os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5526
0
{
5527
0
    PyObject *return_value = NULL;
5528
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5529
5530
0
    #define NUM_KEYWORDS 1
5531
0
    static struct {
5532
0
        PyGC_Head _this_is_not_used;
5533
0
        PyObject_VAR_HEAD
5534
0
        Py_hash_t ob_hash;
5535
0
        PyObject *ob_item[NUM_KEYWORDS];
5536
0
    } _kwtuple = {
5537
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5538
0
        .ob_hash = -1,
5539
0
        .ob_item = { &_Py_ID(pid), },
5540
0
    };
5541
0
    #undef NUM_KEYWORDS
5542
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5543
5544
    #else  // !Py_BUILD_CORE
5545
    #  define KWTUPLE NULL
5546
    #endif  // !Py_BUILD_CORE
5547
5548
0
    static const char * const _keywords[] = {"pid", NULL};
5549
0
    static _PyArg_Parser _parser = {
5550
0
        .keywords = _keywords,
5551
0
        .fname = "getpgid",
5552
0
        .kwtuple = KWTUPLE,
5553
0
    };
5554
0
    #undef KWTUPLE
5555
0
    PyObject *argsbuf[1];
5556
0
    pid_t pid;
5557
5558
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
5559
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
5560
0
    if (!args) {
5561
0
        goto exit;
5562
0
    }
5563
0
    pid = PyLong_AsPid(args[0]);
5564
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5565
0
        goto exit;
5566
0
    }
5567
0
    return_value = os_getpgid_impl(module, pid);
5568
5569
0
exit:
5570
0
    return return_value;
5571
0
}
5572
5573
#endif /* defined(HAVE_GETPGID) */
5574
5575
#if defined(HAVE_GETPGRP)
5576
5577
PyDoc_STRVAR(os_getpgrp__doc__,
5578
"getpgrp($module, /)\n"
5579
"--\n"
5580
"\n"
5581
"Return the current process group id.");
5582
5583
#define OS_GETPGRP_METHODDEF    \
5584
    {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
5585
5586
static PyObject *
5587
os_getpgrp_impl(PyObject *module);
5588
5589
static PyObject *
5590
os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5591
0
{
5592
0
    return os_getpgrp_impl(module);
5593
0
}
5594
5595
#endif /* defined(HAVE_GETPGRP) */
5596
5597
#if defined(HAVE_SETPGRP)
5598
5599
PyDoc_STRVAR(os_setpgrp__doc__,
5600
"setpgrp($module, /)\n"
5601
"--\n"
5602
"\n"
5603
"Make the current process the leader of its process group.");
5604
5605
#define OS_SETPGRP_METHODDEF    \
5606
    {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
5607
5608
static PyObject *
5609
os_setpgrp_impl(PyObject *module);
5610
5611
static PyObject *
5612
os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5613
0
{
5614
0
    return os_setpgrp_impl(module);
5615
0
}
5616
5617
#endif /* defined(HAVE_SETPGRP) */
5618
5619
#if defined(HAVE_GETPPID)
5620
5621
PyDoc_STRVAR(os_getppid__doc__,
5622
"getppid($module, /)\n"
5623
"--\n"
5624
"\n"
5625
"Return the parent\'s process id.\n"
5626
"\n"
5627
"If the parent process has already exited, Windows machines will still\n"
5628
"return its id; others systems will return the id of the \'init\' proces\n"
5629
"(1).");
5630
5631
#define OS_GETPPID_METHODDEF    \
5632
    {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
5633
5634
static PyObject *
5635
os_getppid_impl(PyObject *module);
5636
5637
static PyObject *
5638
os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
5639
0
{
5640
0
    return os_getppid_impl(module);
5641
0
}
5642
5643
#endif /* defined(HAVE_GETPPID) */
5644
5645
#if defined(HAVE_GETLOGIN)
5646
5647
PyDoc_STRVAR(os_getlogin__doc__,
5648
"getlogin($module, /)\n"
5649
"--\n"
5650
"\n"
5651
"Return the actual login name.");
5652
5653
#define OS_GETLOGIN_METHODDEF    \
5654
    {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
5655
5656
static PyObject *
5657
os_getlogin_impl(PyObject *module);
5658
5659
static PyObject *
5660
os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
5661
0
{
5662
0
    return os_getlogin_impl(module);
5663
0
}
5664
5665
#endif /* defined(HAVE_GETLOGIN) */
5666
5667
#if defined(HAVE_GETUID)
5668
5669
PyDoc_STRVAR(os_getuid__doc__,
5670
"getuid($module, /)\n"
5671
"--\n"
5672
"\n"
5673
"Return the current process\'s user id.");
5674
5675
#define OS_GETUID_METHODDEF    \
5676
    {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
5677
5678
static PyObject *
5679
os_getuid_impl(PyObject *module);
5680
5681
static PyObject *
5682
os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5683
20
{
5684
20
    return os_getuid_impl(module);
5685
20
}
5686
5687
#endif /* defined(HAVE_GETUID) */
5688
5689
#if defined(HAVE_KILL)
5690
5691
PyDoc_STRVAR(os_kill__doc__,
5692
"kill($module, pid, signal, /)\n"
5693
"--\n"
5694
"\n"
5695
"Kill a process with a signal.");
5696
5697
#define OS_KILL_METHODDEF    \
5698
    {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__},
5699
5700
static PyObject *
5701
os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
5702
5703
static PyObject *
5704
os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5705
0
{
5706
0
    PyObject *return_value = NULL;
5707
0
    pid_t pid;
5708
0
    Py_ssize_t signal;
5709
5710
0
    if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) {
5711
0
        goto exit;
5712
0
    }
5713
0
    pid = PyLong_AsPid(args[0]);
5714
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5715
0
        goto exit;
5716
0
    }
5717
0
    {
5718
0
        Py_ssize_t ival = -1;
5719
0
        PyObject *iobj = _PyNumber_Index(args[1]);
5720
0
        if (iobj != NULL) {
5721
0
            ival = PyLong_AsSsize_t(iobj);
5722
0
            Py_DECREF(iobj);
5723
0
        }
5724
0
        if (ival == -1 && PyErr_Occurred()) {
5725
0
            goto exit;
5726
0
        }
5727
0
        signal = ival;
5728
0
    }
5729
0
    return_value = os_kill_impl(module, pid, signal);
5730
5731
0
exit:
5732
0
    return return_value;
5733
0
}
5734
5735
#endif /* defined(HAVE_KILL) */
5736
5737
#if defined(HAVE_KILLPG)
5738
5739
PyDoc_STRVAR(os_killpg__doc__,
5740
"killpg($module, pgid, signal, /)\n"
5741
"--\n"
5742
"\n"
5743
"Kill a process group with a signal.");
5744
5745
#define OS_KILLPG_METHODDEF    \
5746
    {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__},
5747
5748
static PyObject *
5749
os_killpg_impl(PyObject *module, pid_t pgid, int signal);
5750
5751
static PyObject *
5752
os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5753
0
{
5754
0
    PyObject *return_value = NULL;
5755
0
    pid_t pgid;
5756
0
    int signal;
5757
5758
0
    if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) {
5759
0
        goto exit;
5760
0
    }
5761
0
    pgid = PyLong_AsPid(args[0]);
5762
0
    if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
5763
0
        goto exit;
5764
0
    }
5765
0
    signal = PyLong_AsInt(args[1]);
5766
0
    if (signal == -1 && PyErr_Occurred()) {
5767
0
        goto exit;
5768
0
    }
5769
0
    return_value = os_killpg_impl(module, pgid, signal);
5770
5771
0
exit:
5772
0
    return return_value;
5773
0
}
5774
5775
#endif /* defined(HAVE_KILLPG) */
5776
5777
#if defined(HAVE_PLOCK)
5778
5779
PyDoc_STRVAR(os_plock__doc__,
5780
"plock($module, op, /)\n"
5781
"--\n"
5782
"\n"
5783
"Lock program segments into memory.\");");
5784
5785
#define OS_PLOCK_METHODDEF    \
5786
    {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
5787
5788
static PyObject *
5789
os_plock_impl(PyObject *module, int op);
5790
5791
static PyObject *
5792
os_plock(PyObject *module, PyObject *arg)
5793
{
5794
    PyObject *return_value = NULL;
5795
    int op;
5796
5797
    op = PyLong_AsInt(arg);
5798
    if (op == -1 && PyErr_Occurred()) {
5799
        goto exit;
5800
    }
5801
    return_value = os_plock_impl(module, op);
5802
5803
exit:
5804
    return return_value;
5805
}
5806
5807
#endif /* defined(HAVE_PLOCK) */
5808
5809
#if defined(HAVE_SETUID)
5810
5811
PyDoc_STRVAR(os_setuid__doc__,
5812
"setuid($module, uid, /)\n"
5813
"--\n"
5814
"\n"
5815
"Set the current process\'s user id.");
5816
5817
#define OS_SETUID_METHODDEF    \
5818
    {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
5819
5820
static PyObject *
5821
os_setuid_impl(PyObject *module, uid_t uid);
5822
5823
static PyObject *
5824
os_setuid(PyObject *module, PyObject *arg)
5825
0
{
5826
0
    PyObject *return_value = NULL;
5827
0
    uid_t uid;
5828
5829
0
    if (!_Py_Uid_Converter(arg, &uid)) {
5830
0
        goto exit;
5831
0
    }
5832
0
    return_value = os_setuid_impl(module, uid);
5833
5834
0
exit:
5835
0
    return return_value;
5836
0
}
5837
5838
#endif /* defined(HAVE_SETUID) */
5839
5840
#if defined(HAVE_SETEUID)
5841
5842
PyDoc_STRVAR(os_seteuid__doc__,
5843
"seteuid($module, euid, /)\n"
5844
"--\n"
5845
"\n"
5846
"Set the current process\'s effective user id.");
5847
5848
#define OS_SETEUID_METHODDEF    \
5849
    {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
5850
5851
static PyObject *
5852
os_seteuid_impl(PyObject *module, uid_t euid);
5853
5854
static PyObject *
5855
os_seteuid(PyObject *module, PyObject *arg)
5856
0
{
5857
0
    PyObject *return_value = NULL;
5858
0
    uid_t euid;
5859
5860
0
    if (!_Py_Uid_Converter(arg, &euid)) {
5861
0
        goto exit;
5862
0
    }
5863
0
    return_value = os_seteuid_impl(module, euid);
5864
5865
0
exit:
5866
0
    return return_value;
5867
0
}
5868
5869
#endif /* defined(HAVE_SETEUID) */
5870
5871
#if defined(HAVE_SETEGID)
5872
5873
PyDoc_STRVAR(os_setegid__doc__,
5874
"setegid($module, egid, /)\n"
5875
"--\n"
5876
"\n"
5877
"Set the current process\'s effective group id.");
5878
5879
#define OS_SETEGID_METHODDEF    \
5880
    {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
5881
5882
static PyObject *
5883
os_setegid_impl(PyObject *module, gid_t egid);
5884
5885
static PyObject *
5886
os_setegid(PyObject *module, PyObject *arg)
5887
0
{
5888
0
    PyObject *return_value = NULL;
5889
0
    gid_t egid;
5890
5891
0
    if (!_Py_Gid_Converter(arg, &egid)) {
5892
0
        goto exit;
5893
0
    }
5894
0
    return_value = os_setegid_impl(module, egid);
5895
5896
0
exit:
5897
0
    return return_value;
5898
0
}
5899
5900
#endif /* defined(HAVE_SETEGID) */
5901
5902
#if defined(HAVE_SETREUID)
5903
5904
PyDoc_STRVAR(os_setreuid__doc__,
5905
"setreuid($module, ruid, euid, /)\n"
5906
"--\n"
5907
"\n"
5908
"Set the current process\'s real and effective user ids.");
5909
5910
#define OS_SETREUID_METHODDEF    \
5911
    {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__},
5912
5913
static PyObject *
5914
os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
5915
5916
static PyObject *
5917
os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5918
0
{
5919
0
    PyObject *return_value = NULL;
5920
0
    uid_t ruid;
5921
0
    uid_t euid;
5922
5923
0
    if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
5924
0
        goto exit;
5925
0
    }
5926
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
5927
0
        goto exit;
5928
0
    }
5929
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
5930
0
        goto exit;
5931
0
    }
5932
0
    return_value = os_setreuid_impl(module, ruid, euid);
5933
5934
0
exit:
5935
0
    return return_value;
5936
0
}
5937
5938
#endif /* defined(HAVE_SETREUID) */
5939
5940
#if defined(HAVE_SETREGID)
5941
5942
PyDoc_STRVAR(os_setregid__doc__,
5943
"setregid($module, rgid, egid, /)\n"
5944
"--\n"
5945
"\n"
5946
"Set the current process\'s real and effective group ids.");
5947
5948
#define OS_SETREGID_METHODDEF    \
5949
    {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__},
5950
5951
static PyObject *
5952
os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
5953
5954
static PyObject *
5955
os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5956
0
{
5957
0
    PyObject *return_value = NULL;
5958
0
    gid_t rgid;
5959
0
    gid_t egid;
5960
5961
0
    if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
5962
0
        goto exit;
5963
0
    }
5964
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
5965
0
        goto exit;
5966
0
    }
5967
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
5968
0
        goto exit;
5969
0
    }
5970
0
    return_value = os_setregid_impl(module, rgid, egid);
5971
5972
0
exit:
5973
0
    return return_value;
5974
0
}
5975
5976
#endif /* defined(HAVE_SETREGID) */
5977
5978
#if defined(HAVE_SETGID)
5979
5980
PyDoc_STRVAR(os_setgid__doc__,
5981
"setgid($module, gid, /)\n"
5982
"--\n"
5983
"\n"
5984
"Set the current process\'s group id.");
5985
5986
#define OS_SETGID_METHODDEF    \
5987
    {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
5988
5989
static PyObject *
5990
os_setgid_impl(PyObject *module, gid_t gid);
5991
5992
static PyObject *
5993
os_setgid(PyObject *module, PyObject *arg)
5994
0
{
5995
0
    PyObject *return_value = NULL;
5996
0
    gid_t gid;
5997
5998
0
    if (!_Py_Gid_Converter(arg, &gid)) {
5999
0
        goto exit;
6000
0
    }
6001
0
    return_value = os_setgid_impl(module, gid);
6002
6003
0
exit:
6004
0
    return return_value;
6005
0
}
6006
6007
#endif /* defined(HAVE_SETGID) */
6008
6009
#if defined(HAVE_SETGROUPS)
6010
6011
PyDoc_STRVAR(os_setgroups__doc__,
6012
"setgroups($module, groups, /)\n"
6013
"--\n"
6014
"\n"
6015
"Set the groups of the current process to list.");
6016
6017
#define OS_SETGROUPS_METHODDEF    \
6018
    {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
6019
6020
#endif /* defined(HAVE_SETGROUPS) */
6021
6022
#if defined(HAVE_WAIT3)
6023
6024
PyDoc_STRVAR(os_wait3__doc__,
6025
"wait3($module, /, options)\n"
6026
"--\n"
6027
"\n"
6028
"Wait for completion of a child process.\n"
6029
"\n"
6030
"Returns a tuple of information about the child process:\n"
6031
"  (pid, status, rusage)");
6032
6033
#define OS_WAIT3_METHODDEF    \
6034
    {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
6035
6036
static PyObject *
6037
os_wait3_impl(PyObject *module, int options);
6038
6039
static PyObject *
6040
os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6041
0
{
6042
0
    PyObject *return_value = NULL;
6043
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6044
6045
0
    #define NUM_KEYWORDS 1
6046
0
    static struct {
6047
0
        PyGC_Head _this_is_not_used;
6048
0
        PyObject_VAR_HEAD
6049
0
        Py_hash_t ob_hash;
6050
0
        PyObject *ob_item[NUM_KEYWORDS];
6051
0
    } _kwtuple = {
6052
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6053
0
        .ob_hash = -1,
6054
0
        .ob_item = { &_Py_ID(options), },
6055
0
    };
6056
0
    #undef NUM_KEYWORDS
6057
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6058
6059
    #else  // !Py_BUILD_CORE
6060
    #  define KWTUPLE NULL
6061
    #endif  // !Py_BUILD_CORE
6062
6063
0
    static const char * const _keywords[] = {"options", NULL};
6064
0
    static _PyArg_Parser _parser = {
6065
0
        .keywords = _keywords,
6066
0
        .fname = "wait3",
6067
0
        .kwtuple = KWTUPLE,
6068
0
    };
6069
0
    #undef KWTUPLE
6070
0
    PyObject *argsbuf[1];
6071
0
    int options;
6072
6073
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6074
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6075
0
    if (!args) {
6076
0
        goto exit;
6077
0
    }
6078
0
    options = PyLong_AsInt(args[0]);
6079
0
    if (options == -1 && PyErr_Occurred()) {
6080
0
        goto exit;
6081
0
    }
6082
0
    return_value = os_wait3_impl(module, options);
6083
6084
0
exit:
6085
0
    return return_value;
6086
0
}
6087
6088
#endif /* defined(HAVE_WAIT3) */
6089
6090
#if defined(HAVE_WAIT4)
6091
6092
PyDoc_STRVAR(os_wait4__doc__,
6093
"wait4($module, /, pid, options)\n"
6094
"--\n"
6095
"\n"
6096
"Wait for completion of a specific child process.\n"
6097
"\n"
6098
"Returns a tuple of information about the child process:\n"
6099
"  (pid, status, rusage)");
6100
6101
#define OS_WAIT4_METHODDEF    \
6102
    {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
6103
6104
static PyObject *
6105
os_wait4_impl(PyObject *module, pid_t pid, int options);
6106
6107
static PyObject *
6108
os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6109
0
{
6110
0
    PyObject *return_value = NULL;
6111
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6112
6113
0
    #define NUM_KEYWORDS 2
6114
0
    static struct {
6115
0
        PyGC_Head _this_is_not_used;
6116
0
        PyObject_VAR_HEAD
6117
0
        Py_hash_t ob_hash;
6118
0
        PyObject *ob_item[NUM_KEYWORDS];
6119
0
    } _kwtuple = {
6120
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6121
0
        .ob_hash = -1,
6122
0
        .ob_item = { &_Py_ID(pid), &_Py_ID(options), },
6123
0
    };
6124
0
    #undef NUM_KEYWORDS
6125
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6126
6127
    #else  // !Py_BUILD_CORE
6128
    #  define KWTUPLE NULL
6129
    #endif  // !Py_BUILD_CORE
6130
6131
0
    static const char * const _keywords[] = {"pid", "options", NULL};
6132
0
    static _PyArg_Parser _parser = {
6133
0
        .keywords = _keywords,
6134
0
        .fname = "wait4",
6135
0
        .kwtuple = KWTUPLE,
6136
0
    };
6137
0
    #undef KWTUPLE
6138
0
    PyObject *argsbuf[2];
6139
0
    pid_t pid;
6140
0
    int options;
6141
6142
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6143
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6144
0
    if (!args) {
6145
0
        goto exit;
6146
0
    }
6147
0
    pid = PyLong_AsPid(args[0]);
6148
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6149
0
        goto exit;
6150
0
    }
6151
0
    options = PyLong_AsInt(args[1]);
6152
0
    if (options == -1 && PyErr_Occurred()) {
6153
0
        goto exit;
6154
0
    }
6155
0
    return_value = os_wait4_impl(module, pid, options);
6156
6157
0
exit:
6158
0
    return return_value;
6159
0
}
6160
6161
#endif /* defined(HAVE_WAIT4) */
6162
6163
#if defined(HAVE_WAITID)
6164
6165
PyDoc_STRVAR(os_waitid__doc__,
6166
"waitid($module, idtype, id, options, /)\n"
6167
"--\n"
6168
"\n"
6169
"Returns the result of waiting for a process or processes.\n"
6170
"\n"
6171
"  idtype\n"
6172
"    Must be one of be P_PID, P_PGID or P_ALL.\n"
6173
"  id\n"
6174
"    The id to wait on.\n"
6175
"  options\n"
6176
"    Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
6177
"    or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
6178
"\n"
6179
"Returns either waitid_result or None if WNOHANG is specified and there\n"
6180
"are no children in a waitable state.");
6181
6182
#define OS_WAITID_METHODDEF    \
6183
    {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__},
6184
6185
static PyObject *
6186
os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
6187
6188
static PyObject *
6189
os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6190
0
{
6191
0
    PyObject *return_value = NULL;
6192
0
    idtype_t idtype;
6193
0
    id_t id;
6194
0
    int options;
6195
6196
0
    if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) {
6197
0
        goto exit;
6198
0
    }
6199
0
    if (!idtype_t_converter(args[0], &idtype)) {
6200
0
        goto exit;
6201
0
    }
6202
0
    id = (id_t)PyLong_AsPid(args[1]);
6203
0
    if (id == (id_t)(-1) && PyErr_Occurred()) {
6204
0
        goto exit;
6205
0
    }
6206
0
    options = PyLong_AsInt(args[2]);
6207
0
    if (options == -1 && PyErr_Occurred()) {
6208
0
        goto exit;
6209
0
    }
6210
0
    return_value = os_waitid_impl(module, idtype, id, options);
6211
6212
0
exit:
6213
0
    return return_value;
6214
0
}
6215
6216
#endif /* defined(HAVE_WAITID) */
6217
6218
#if defined(HAVE_WAITPID)
6219
6220
PyDoc_STRVAR(os_waitpid__doc__,
6221
"waitpid($module, pid, options, /)\n"
6222
"--\n"
6223
"\n"
6224
"Wait for completion of a given child process.\n"
6225
"\n"
6226
"Returns a tuple of information regarding the child process:\n"
6227
"    (pid, status)\n"
6228
"\n"
6229
"The options argument is ignored on Windows.");
6230
6231
#define OS_WAITPID_METHODDEF    \
6232
    {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6233
6234
static PyObject *
6235
os_waitpid_impl(PyObject *module, pid_t pid, int options);
6236
6237
static PyObject *
6238
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6239
0
{
6240
0
    PyObject *return_value = NULL;
6241
0
    pid_t pid;
6242
0
    int options;
6243
6244
0
    if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6245
0
        goto exit;
6246
0
    }
6247
0
    pid = PyLong_AsPid(args[0]);
6248
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6249
0
        goto exit;
6250
0
    }
6251
0
    options = PyLong_AsInt(args[1]);
6252
0
    if (options == -1 && PyErr_Occurred()) {
6253
0
        goto exit;
6254
0
    }
6255
0
    return_value = os_waitpid_impl(module, pid, options);
6256
6257
0
exit:
6258
0
    return return_value;
6259
0
}
6260
6261
#endif /* defined(HAVE_WAITPID) */
6262
6263
#if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT)
6264
6265
PyDoc_STRVAR(os_waitpid__doc__,
6266
"waitpid($module, pid, options, /)\n"
6267
"--\n"
6268
"\n"
6269
"Wait for completion of a given process.\n"
6270
"\n"
6271
"Returns a tuple of information regarding the process:\n"
6272
"    (pid, status << 8)\n"
6273
"\n"
6274
"The options argument is ignored on Windows.");
6275
6276
#define OS_WAITPID_METHODDEF    \
6277
    {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6278
6279
static PyObject *
6280
os_waitpid_impl(PyObject *module, intptr_t pid, int options);
6281
6282
static PyObject *
6283
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6284
{
6285
    PyObject *return_value = NULL;
6286
    intptr_t pid;
6287
    int options;
6288
6289
    if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6290
        goto exit;
6291
    }
6292
    pid = (intptr_t)PyLong_AsVoidPtr(args[0]);
6293
    if (!pid && PyErr_Occurred()) {
6294
        goto exit;
6295
    }
6296
    options = PyLong_AsInt(args[1]);
6297
    if (options == -1 && PyErr_Occurred()) {
6298
        goto exit;
6299
    }
6300
    return_value = os_waitpid_impl(module, pid, options);
6301
6302
exit:
6303
    return return_value;
6304
}
6305
6306
#endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */
6307
6308
#if defined(HAVE_WAIT)
6309
6310
PyDoc_STRVAR(os_wait__doc__,
6311
"wait($module, /)\n"
6312
"--\n"
6313
"\n"
6314
"Wait for completion of a child process.\n"
6315
"\n"
6316
"Returns a tuple of information about the child process:\n"
6317
"    (pid, status)");
6318
6319
#define OS_WAIT_METHODDEF    \
6320
    {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
6321
6322
static PyObject *
6323
os_wait_impl(PyObject *module);
6324
6325
static PyObject *
6326
os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
6327
0
{
6328
0
    return os_wait_impl(module);
6329
0
}
6330
6331
#endif /* defined(HAVE_WAIT) */
6332
6333
#if (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))
6334
6335
PyDoc_STRVAR(os_pidfd_open__doc__,
6336
"pidfd_open($module, /, pid, flags=0)\n"
6337
"--\n"
6338
"\n"
6339
"Return a file descriptor referring to the process *pid*.\n"
6340
"\n"
6341
"The descriptor can be used to perform process management without races\n"
6342
"and signals.");
6343
6344
#define OS_PIDFD_OPEN_METHODDEF    \
6345
    {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__},
6346
6347
static PyObject *
6348
os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags);
6349
6350
static PyObject *
6351
os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6352
0
{
6353
0
    PyObject *return_value = NULL;
6354
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6355
6356
0
    #define NUM_KEYWORDS 2
6357
0
    static struct {
6358
0
        PyGC_Head _this_is_not_used;
6359
0
        PyObject_VAR_HEAD
6360
0
        Py_hash_t ob_hash;
6361
0
        PyObject *ob_item[NUM_KEYWORDS];
6362
0
    } _kwtuple = {
6363
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6364
0
        .ob_hash = -1,
6365
0
        .ob_item = { &_Py_ID(pid), &_Py_ID(flags), },
6366
0
    };
6367
0
    #undef NUM_KEYWORDS
6368
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6369
6370
    #else  // !Py_BUILD_CORE
6371
    #  define KWTUPLE NULL
6372
    #endif  // !Py_BUILD_CORE
6373
6374
0
    static const char * const _keywords[] = {"pid", "flags", NULL};
6375
0
    static _PyArg_Parser _parser = {
6376
0
        .keywords = _keywords,
6377
0
        .fname = "pidfd_open",
6378
0
        .kwtuple = KWTUPLE,
6379
0
    };
6380
0
    #undef KWTUPLE
6381
0
    PyObject *argsbuf[2];
6382
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6383
0
    pid_t pid;
6384
0
    unsigned int flags = 0;
6385
6386
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6387
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6388
0
    if (!args) {
6389
0
        goto exit;
6390
0
    }
6391
0
    pid = PyLong_AsPid(args[0]);
6392
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6393
0
        goto exit;
6394
0
    }
6395
0
    if (!noptargs) {
6396
0
        goto skip_optional_pos;
6397
0
    }
6398
0
    if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) {
6399
0
        goto exit;
6400
0
    }
6401
0
skip_optional_pos:
6402
0
    return_value = os_pidfd_open_impl(module, pid, flags);
6403
6404
0
exit:
6405
0
    return return_value;
6406
0
}
6407
6408
#endif /* (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */
6409
6410
#if (defined(__linux__) && defined(__NR_pidfd_getfd) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))
6411
6412
PyDoc_STRVAR(os_pidfd_getfd__doc__,
6413
"pidfd_getfd($module, /, pidfd, targetfd, *, flags=0)\n"
6414
"--\n"
6415
"\n"
6416
"Duplicate a file descriptor from the process referred to by *pidfd*.\n"
6417
"\n"
6418
"  pidfd\n"
6419
"    A process file descriptor.\n"
6420
"  targetfd\n"
6421
"    The file descriptor to duplicate from the target process.\n"
6422
"  flags\n"
6423
"    Reserved, must be 0.");
6424
6425
#define OS_PIDFD_GETFD_METHODDEF    \
6426
    {"pidfd_getfd", _PyCFunction_CAST(os_pidfd_getfd), METH_FASTCALL|METH_KEYWORDS, os_pidfd_getfd__doc__},
6427
6428
static PyObject *
6429
os_pidfd_getfd_impl(PyObject *module, int pidfd, int targetfd,
6430
                    unsigned int flags);
6431
6432
static PyObject *
6433
os_pidfd_getfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6434
{
6435
    PyObject *return_value = NULL;
6436
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6437
6438
    #define NUM_KEYWORDS 3
6439
    static struct {
6440
        PyGC_Head _this_is_not_used;
6441
        PyObject_VAR_HEAD
6442
        Py_hash_t ob_hash;
6443
        PyObject *ob_item[NUM_KEYWORDS];
6444
    } _kwtuple = {
6445
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6446
        .ob_hash = -1,
6447
        .ob_item = { &_Py_ID(pidfd), &_Py_ID(targetfd), &_Py_ID(flags), },
6448
    };
6449
    #undef NUM_KEYWORDS
6450
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6451
6452
    #else  // !Py_BUILD_CORE
6453
    #  define KWTUPLE NULL
6454
    #endif  // !Py_BUILD_CORE
6455
6456
    static const char * const _keywords[] = {"pidfd", "targetfd", "flags", NULL};
6457
    static _PyArg_Parser _parser = {
6458
        .keywords = _keywords,
6459
        .fname = "pidfd_getfd",
6460
        .kwtuple = KWTUPLE,
6461
    };
6462
    #undef KWTUPLE
6463
    PyObject *argsbuf[3];
6464
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
6465
    int pidfd;
6466
    int targetfd;
6467
    unsigned int flags = 0;
6468
6469
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6470
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6471
    if (!args) {
6472
        goto exit;
6473
    }
6474
    pidfd = PyLong_AsInt(args[0]);
6475
    if (pidfd == -1 && PyErr_Occurred()) {
6476
        goto exit;
6477
    }
6478
    targetfd = PyLong_AsInt(args[1]);
6479
    if (targetfd == -1 && PyErr_Occurred()) {
6480
        goto exit;
6481
    }
6482
    if (!noptargs) {
6483
        goto skip_optional_kwonly;
6484
    }
6485
    if (!_PyLong_UnsignedInt_Converter(args[2], &flags)) {
6486
        goto exit;
6487
    }
6488
skip_optional_kwonly:
6489
    return_value = os_pidfd_getfd_impl(module, pidfd, targetfd, flags);
6490
6491
exit:
6492
    return return_value;
6493
}
6494
6495
#endif /* (defined(__linux__) && defined(__NR_pidfd_getfd) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */
6496
6497
#if defined(HAVE_SETNS)
6498
6499
PyDoc_STRVAR(os_setns__doc__,
6500
"setns($module, /, fd, nstype=0)\n"
6501
"--\n"
6502
"\n"
6503
"Move the calling thread into different namespaces.\n"
6504
"\n"
6505
"  fd\n"
6506
"    A file descriptor to a namespace.\n"
6507
"  nstype\n"
6508
"    Type of namespace.");
6509
6510
#define OS_SETNS_METHODDEF    \
6511
    {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__},
6512
6513
static PyObject *
6514
os_setns_impl(PyObject *module, int fd, int nstype);
6515
6516
static PyObject *
6517
os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6518
0
{
6519
0
    PyObject *return_value = NULL;
6520
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6521
6522
0
    #define NUM_KEYWORDS 2
6523
0
    static struct {
6524
0
        PyGC_Head _this_is_not_used;
6525
0
        PyObject_VAR_HEAD
6526
0
        Py_hash_t ob_hash;
6527
0
        PyObject *ob_item[NUM_KEYWORDS];
6528
0
    } _kwtuple = {
6529
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6530
0
        .ob_hash = -1,
6531
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), },
6532
0
    };
6533
0
    #undef NUM_KEYWORDS
6534
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6535
6536
    #else  // !Py_BUILD_CORE
6537
    #  define KWTUPLE NULL
6538
    #endif  // !Py_BUILD_CORE
6539
6540
0
    static const char * const _keywords[] = {"fd", "nstype", NULL};
6541
0
    static _PyArg_Parser _parser = {
6542
0
        .keywords = _keywords,
6543
0
        .fname = "setns",
6544
0
        .kwtuple = KWTUPLE,
6545
0
    };
6546
0
    #undef KWTUPLE
6547
0
    PyObject *argsbuf[2];
6548
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6549
0
    int fd;
6550
0
    int nstype = 0;
6551
6552
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6553
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6554
0
    if (!args) {
6555
0
        goto exit;
6556
0
    }
6557
0
    fd = PyObject_AsFileDescriptor(args[0]);
6558
0
    if (fd < 0) {
6559
0
        goto exit;
6560
0
    }
6561
0
    if (!noptargs) {
6562
0
        goto skip_optional_pos;
6563
0
    }
6564
0
    nstype = PyLong_AsInt(args[1]);
6565
0
    if (nstype == -1 && PyErr_Occurred()) {
6566
0
        goto exit;
6567
0
    }
6568
0
skip_optional_pos:
6569
0
    return_value = os_setns_impl(module, fd, nstype);
6570
6571
0
exit:
6572
0
    return return_value;
6573
0
}
6574
6575
#endif /* defined(HAVE_SETNS) */
6576
6577
#if defined(HAVE_UNSHARE)
6578
6579
PyDoc_STRVAR(os_unshare__doc__,
6580
"unshare($module, /, flags)\n"
6581
"--\n"
6582
"\n"
6583
"Disassociate parts of a process (or thread) execution context.\n"
6584
"\n"
6585
"  flags\n"
6586
"    Namespaces to be unshared.");
6587
6588
#define OS_UNSHARE_METHODDEF    \
6589
    {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__},
6590
6591
static PyObject *
6592
os_unshare_impl(PyObject *module, int flags);
6593
6594
static PyObject *
6595
os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6596
0
{
6597
0
    PyObject *return_value = NULL;
6598
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6599
6600
0
    #define NUM_KEYWORDS 1
6601
0
    static struct {
6602
0
        PyGC_Head _this_is_not_used;
6603
0
        PyObject_VAR_HEAD
6604
0
        Py_hash_t ob_hash;
6605
0
        PyObject *ob_item[NUM_KEYWORDS];
6606
0
    } _kwtuple = {
6607
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6608
0
        .ob_hash = -1,
6609
0
        .ob_item = { &_Py_ID(flags), },
6610
0
    };
6611
0
    #undef NUM_KEYWORDS
6612
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6613
6614
    #else  // !Py_BUILD_CORE
6615
    #  define KWTUPLE NULL
6616
    #endif  // !Py_BUILD_CORE
6617
6618
0
    static const char * const _keywords[] = {"flags", NULL};
6619
0
    static _PyArg_Parser _parser = {
6620
0
        .keywords = _keywords,
6621
0
        .fname = "unshare",
6622
0
        .kwtuple = KWTUPLE,
6623
0
    };
6624
0
    #undef KWTUPLE
6625
0
    PyObject *argsbuf[1];
6626
0
    int flags;
6627
6628
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6629
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6630
0
    if (!args) {
6631
0
        goto exit;
6632
0
    }
6633
0
    flags = PyLong_AsInt(args[0]);
6634
0
    if (flags == -1 && PyErr_Occurred()) {
6635
0
        goto exit;
6636
0
    }
6637
0
    return_value = os_unshare_impl(module, flags);
6638
6639
0
exit:
6640
0
    return return_value;
6641
0
}
6642
6643
#endif /* defined(HAVE_UNSHARE) */
6644
6645
#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
6646
6647
PyDoc_STRVAR(os_readlink__doc__,
6648
"readlink($module, /, path, *, dir_fd=None)\n"
6649
"--\n"
6650
"\n"
6651
"Return a string representing the path to which the symbolic link points.\n"
6652
"\n"
6653
"If dir_fd is not None, it should be a file descriptor open to\n"
6654
"a directory, and path should be relative; path will then be relative to\n"
6655
"that directory.\n"
6656
"\n"
6657
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
6658
"using it will raise a NotImplementedError.");
6659
6660
#define OS_READLINK_METHODDEF    \
6661
    {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
6662
6663
static PyObject *
6664
os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
6665
6666
static PyObject *
6667
os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6668
0
{
6669
0
    PyObject *return_value = NULL;
6670
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6671
6672
0
    #define NUM_KEYWORDS 2
6673
0
    static struct {
6674
0
        PyGC_Head _this_is_not_used;
6675
0
        PyObject_VAR_HEAD
6676
0
        Py_hash_t ob_hash;
6677
0
        PyObject *ob_item[NUM_KEYWORDS];
6678
0
    } _kwtuple = {
6679
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6680
0
        .ob_hash = -1,
6681
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
6682
0
    };
6683
0
    #undef NUM_KEYWORDS
6684
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6685
6686
    #else  // !Py_BUILD_CORE
6687
    #  define KWTUPLE NULL
6688
    #endif  // !Py_BUILD_CORE
6689
6690
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
6691
0
    static _PyArg_Parser _parser = {
6692
0
        .keywords = _keywords,
6693
0
        .fname = "readlink",
6694
0
        .kwtuple = KWTUPLE,
6695
0
    };
6696
0
    #undef KWTUPLE
6697
0
    PyObject *argsbuf[2];
6698
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6699
0
    path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0);
6700
0
    int dir_fd = DEFAULT_DIR_FD;
6701
6702
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6703
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6704
0
    if (!args) {
6705
0
        goto exit;
6706
0
    }
6707
0
    if (!path_converter(args[0], &path)) {
6708
0
        goto exit;
6709
0
    }
6710
0
    if (!noptargs) {
6711
0
        goto skip_optional_kwonly;
6712
0
    }
6713
0
    if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
6714
0
        goto exit;
6715
0
    }
6716
0
skip_optional_kwonly:
6717
0
    return_value = os_readlink_impl(module, &path, dir_fd);
6718
6719
0
exit:
6720
    /* Cleanup for path */
6721
0
    path_cleanup(&path);
6722
6723
0
    return return_value;
6724
0
}
6725
6726
#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
6727
6728
#if defined(HAVE_SYMLINK)
6729
6730
PyDoc_STRVAR(os_symlink__doc__,
6731
"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
6732
"--\n"
6733
"\n"
6734
"Create a symbolic link pointing to src named dst.\n"
6735
"\n"
6736
"target_is_directory is required on Windows if the target is to be\n"
6737
"interpreted as a directory.  (On Windows, symlink requires Windows 6.0\n"
6738
"or greater, and raises a NotImplementedError otherwise.)\n"
6739
"target_is_directory is ignored on non-Windows platforms.\n"
6740
"\n"
6741
"If dir_fd is not None, it should be a file descriptor open to\n"
6742
"a directory, and path should be relative; path will then be relative\n"
6743
"to that directory.\n"
6744
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
6745
"using it will raise a NotImplementedError.");
6746
6747
#define OS_SYMLINK_METHODDEF    \
6748
    {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
6749
6750
static PyObject *
6751
os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
6752
                int target_is_directory, int dir_fd);
6753
6754
static PyObject *
6755
os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6756
0
{
6757
0
    PyObject *return_value = NULL;
6758
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6759
6760
0
    #define NUM_KEYWORDS 4
6761
0
    static struct {
6762
0
        PyGC_Head _this_is_not_used;
6763
0
        PyObject_VAR_HEAD
6764
0
        Py_hash_t ob_hash;
6765
0
        PyObject *ob_item[NUM_KEYWORDS];
6766
0
    } _kwtuple = {
6767
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6768
0
        .ob_hash = -1,
6769
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), },
6770
0
    };
6771
0
    #undef NUM_KEYWORDS
6772
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6773
6774
    #else  // !Py_BUILD_CORE
6775
    #  define KWTUPLE NULL
6776
    #endif  // !Py_BUILD_CORE
6777
6778
0
    static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
6779
0
    static _PyArg_Parser _parser = {
6780
0
        .keywords = _keywords,
6781
0
        .fname = "symlink",
6782
0
        .kwtuple = KWTUPLE,
6783
0
    };
6784
0
    #undef KWTUPLE
6785
0
    PyObject *argsbuf[4];
6786
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
6787
0
    path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0);
6788
0
    path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0);
6789
0
    int target_is_directory = 0;
6790
0
    int dir_fd = DEFAULT_DIR_FD;
6791
6792
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6793
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6794
0
    if (!args) {
6795
0
        goto exit;
6796
0
    }
6797
0
    if (!path_converter(args[0], &src)) {
6798
0
        goto exit;
6799
0
    }
6800
0
    if (!path_converter(args[1], &dst)) {
6801
0
        goto exit;
6802
0
    }
6803
0
    if (!noptargs) {
6804
0
        goto skip_optional_pos;
6805
0
    }
6806
0
    if (args[2]) {
6807
0
        target_is_directory = PyObject_IsTrue(args[2]);
6808
0
        if (target_is_directory < 0) {
6809
0
            goto exit;
6810
0
        }
6811
0
        if (!--noptargs) {
6812
0
            goto skip_optional_pos;
6813
0
        }
6814
0
    }
6815
0
skip_optional_pos:
6816
0
    if (!noptargs) {
6817
0
        goto skip_optional_kwonly;
6818
0
    }
6819
0
    if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
6820
0
        goto exit;
6821
0
    }
6822
0
skip_optional_kwonly:
6823
0
    return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
6824
6825
0
exit:
6826
    /* Cleanup for src */
6827
0
    path_cleanup(&src);
6828
    /* Cleanup for dst */
6829
0
    path_cleanup(&dst);
6830
6831
0
    return return_value;
6832
0
}
6833
6834
#endif /* defined(HAVE_SYMLINK) */
6835
6836
PyDoc_STRVAR(os_times__doc__,
6837
"times($module, /)\n"
6838
"--\n"
6839
"\n"
6840
"Return a collection containing process timing information.\n"
6841
"\n"
6842
"The object returned behaves like a named tuple with these fields:\n"
6843
"  (utime, stime, cutime, cstime, elapsed_time)\n"
6844
"All fields are floating-point numbers.");
6845
6846
#define OS_TIMES_METHODDEF    \
6847
    {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
6848
6849
static PyObject *
6850
os_times_impl(PyObject *module);
6851
6852
static PyObject *
6853
os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
6854
0
{
6855
0
    return os_times_impl(module);
6856
0
}
6857
6858
#if defined(HAVE_TIMERFD_CREATE)
6859
6860
PyDoc_STRVAR(os_timerfd_create__doc__,
6861
"timerfd_create($module, clockid, /, *, flags=0)\n"
6862
"--\n"
6863
"\n"
6864
"Create and return a timer file descriptor.\n"
6865
"\n"
6866
"  clockid\n"
6867
"    A valid clock ID constant as timer file descriptor.\n"
6868
"\n"
6869
"    time.CLOCK_REALTIME\n"
6870
"    time.CLOCK_MONOTONIC\n"
6871
"    time.CLOCK_BOOTTIME\n"
6872
"  flags\n"
6873
"    0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n"
6874
"\n"
6875
"    os.TFD_NONBLOCK\n"
6876
"        If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n"
6877
"        If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n"
6878
"\n"
6879
"    os.TFD_CLOEXEC\n"
6880
"        If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag");
6881
6882
#define OS_TIMERFD_CREATE_METHODDEF    \
6883
    {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__},
6884
6885
static PyObject *
6886
os_timerfd_create_impl(PyObject *module, int clockid, int flags);
6887
6888
static PyObject *
6889
os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6890
0
{
6891
0
    PyObject *return_value = NULL;
6892
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6893
6894
0
    #define NUM_KEYWORDS 1
6895
0
    static struct {
6896
0
        PyGC_Head _this_is_not_used;
6897
0
        PyObject_VAR_HEAD
6898
0
        Py_hash_t ob_hash;
6899
0
        PyObject *ob_item[NUM_KEYWORDS];
6900
0
    } _kwtuple = {
6901
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6902
0
        .ob_hash = -1,
6903
0
        .ob_item = { &_Py_ID(flags), },
6904
0
    };
6905
0
    #undef NUM_KEYWORDS
6906
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6907
6908
    #else  // !Py_BUILD_CORE
6909
    #  define KWTUPLE NULL
6910
    #endif  // !Py_BUILD_CORE
6911
6912
0
    static const char * const _keywords[] = {"", "flags", NULL};
6913
0
    static _PyArg_Parser _parser = {
6914
0
        .keywords = _keywords,
6915
0
        .fname = "timerfd_create",
6916
0
        .kwtuple = KWTUPLE,
6917
0
    };
6918
0
    #undef KWTUPLE
6919
0
    PyObject *argsbuf[2];
6920
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6921
0
    int clockid;
6922
0
    int flags = 0;
6923
6924
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6925
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6926
0
    if (!args) {
6927
0
        goto exit;
6928
0
    }
6929
0
    clockid = PyLong_AsInt(args[0]);
6930
0
    if (clockid == -1 && PyErr_Occurred()) {
6931
0
        goto exit;
6932
0
    }
6933
0
    if (!noptargs) {
6934
0
        goto skip_optional_kwonly;
6935
0
    }
6936
0
    flags = PyLong_AsInt(args[1]);
6937
0
    if (flags == -1 && PyErr_Occurred()) {
6938
0
        goto exit;
6939
0
    }
6940
0
skip_optional_kwonly:
6941
0
    return_value = os_timerfd_create_impl(module, clockid, flags);
6942
6943
0
exit:
6944
0
    return return_value;
6945
0
}
6946
6947
#endif /* defined(HAVE_TIMERFD_CREATE) */
6948
6949
#if defined(HAVE_TIMERFD_CREATE)
6950
6951
PyDoc_STRVAR(os_timerfd_settime__doc__,
6952
"timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n"
6953
"--\n"
6954
"\n"
6955
"Alter a timer file descriptor\'s internal timer in seconds.\n"
6956
"\n"
6957
"  fd\n"
6958
"    A timer file descriptor.\n"
6959
"  flags\n"
6960
"    0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
6961
"  initial\n"
6962
"    The initial expiration time, in seconds.\n"
6963
"  interval\n"
6964
"    The timer\'s interval, in seconds.");
6965
6966
#define OS_TIMERFD_SETTIME_METHODDEF    \
6967
    {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__},
6968
6969
static PyObject *
6970
os_timerfd_settime_impl(PyObject *module, int fd, int flags,
6971
                        double initial_double, double interval_double);
6972
6973
static PyObject *
6974
os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6975
0
{
6976
0
    PyObject *return_value = NULL;
6977
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6978
6979
0
    #define NUM_KEYWORDS 3
6980
0
    static struct {
6981
0
        PyGC_Head _this_is_not_used;
6982
0
        PyObject_VAR_HEAD
6983
0
        Py_hash_t ob_hash;
6984
0
        PyObject *ob_item[NUM_KEYWORDS];
6985
0
    } _kwtuple = {
6986
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6987
0
        .ob_hash = -1,
6988
0
        .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
6989
0
    };
6990
0
    #undef NUM_KEYWORDS
6991
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6992
6993
    #else  // !Py_BUILD_CORE
6994
    #  define KWTUPLE NULL
6995
    #endif  // !Py_BUILD_CORE
6996
6997
0
    static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
6998
0
    static _PyArg_Parser _parser = {
6999
0
        .keywords = _keywords,
7000
0
        .fname = "timerfd_settime",
7001
0
        .kwtuple = KWTUPLE,
7002
0
    };
7003
0
    #undef KWTUPLE
7004
0
    PyObject *argsbuf[4];
7005
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
7006
0
    int fd;
7007
0
    int flags = 0;
7008
0
    double initial_double = 0.0;
7009
0
    double interval_double = 0.0;
7010
7011
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7012
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7013
0
    if (!args) {
7014
0
        goto exit;
7015
0
    }
7016
0
    fd = PyObject_AsFileDescriptor(args[0]);
7017
0
    if (fd < 0) {
7018
0
        goto exit;
7019
0
    }
7020
0
    if (!noptargs) {
7021
0
        goto skip_optional_kwonly;
7022
0
    }
7023
0
    if (args[1]) {
7024
0
        flags = PyLong_AsInt(args[1]);
7025
0
        if (flags == -1 && PyErr_Occurred()) {
7026
0
            goto exit;
7027
0
        }
7028
0
        if (!--noptargs) {
7029
0
            goto skip_optional_kwonly;
7030
0
        }
7031
0
    }
7032
0
    if (args[2]) {
7033
0
        if (PyFloat_CheckExact(args[2])) {
7034
0
            initial_double = PyFloat_AS_DOUBLE(args[2]);
7035
0
        }
7036
0
        else
7037
0
        {
7038
0
            initial_double = PyFloat_AsDouble(args[2]);
7039
0
            if (initial_double == -1.0 && PyErr_Occurred()) {
7040
0
                goto exit;
7041
0
            }
7042
0
        }
7043
0
        if (!--noptargs) {
7044
0
            goto skip_optional_kwonly;
7045
0
        }
7046
0
    }
7047
0
    if (PyFloat_CheckExact(args[3])) {
7048
0
        interval_double = PyFloat_AS_DOUBLE(args[3]);
7049
0
    }
7050
0
    else
7051
0
    {
7052
0
        interval_double = PyFloat_AsDouble(args[3]);
7053
0
        if (interval_double == -1.0 && PyErr_Occurred()) {
7054
0
            goto exit;
7055
0
        }
7056
0
    }
7057
0
skip_optional_kwonly:
7058
0
    return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double);
7059
7060
0
exit:
7061
0
    return return_value;
7062
0
}
7063
7064
#endif /* defined(HAVE_TIMERFD_CREATE) */
7065
7066
#if defined(HAVE_TIMERFD_CREATE)
7067
7068
PyDoc_STRVAR(os_timerfd_settime_ns__doc__,
7069
"timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n"
7070
"--\n"
7071
"\n"
7072
"Alter a timer file descriptor\'s internal timer in nanoseconds.\n"
7073
"\n"
7074
"  fd\n"
7075
"    A timer file descriptor.\n"
7076
"  flags\n"
7077
"    0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
7078
"  initial\n"
7079
"    initial expiration timing in seconds.\n"
7080
"  interval\n"
7081
"    interval for the timer in seconds.");
7082
7083
#define OS_TIMERFD_SETTIME_NS_METHODDEF    \
7084
    {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__},
7085
7086
static PyObject *
7087
os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags,
7088
                           long long initial, long long interval);
7089
7090
static PyObject *
7091
os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7092
0
{
7093
0
    PyObject *return_value = NULL;
7094
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7095
7096
0
    #define NUM_KEYWORDS 3
7097
0
    static struct {
7098
0
        PyGC_Head _this_is_not_used;
7099
0
        PyObject_VAR_HEAD
7100
0
        Py_hash_t ob_hash;
7101
0
        PyObject *ob_item[NUM_KEYWORDS];
7102
0
    } _kwtuple = {
7103
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7104
0
        .ob_hash = -1,
7105
0
        .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
7106
0
    };
7107
0
    #undef NUM_KEYWORDS
7108
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7109
7110
    #else  // !Py_BUILD_CORE
7111
    #  define KWTUPLE NULL
7112
    #endif  // !Py_BUILD_CORE
7113
7114
0
    static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
7115
0
    static _PyArg_Parser _parser = {
7116
0
        .keywords = _keywords,
7117
0
        .fname = "timerfd_settime_ns",
7118
0
        .kwtuple = KWTUPLE,
7119
0
    };
7120
0
    #undef KWTUPLE
7121
0
    PyObject *argsbuf[4];
7122
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
7123
0
    int fd;
7124
0
    int flags = 0;
7125
0
    long long initial = 0;
7126
0
    long long interval = 0;
7127
7128
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7129
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7130
0
    if (!args) {
7131
0
        goto exit;
7132
0
    }
7133
0
    fd = PyObject_AsFileDescriptor(args[0]);
7134
0
    if (fd < 0) {
7135
0
        goto exit;
7136
0
    }
7137
0
    if (!noptargs) {
7138
0
        goto skip_optional_kwonly;
7139
0
    }
7140
0
    if (args[1]) {
7141
0
        flags = PyLong_AsInt(args[1]);
7142
0
        if (flags == -1 && PyErr_Occurred()) {
7143
0
            goto exit;
7144
0
        }
7145
0
        if (!--noptargs) {
7146
0
            goto skip_optional_kwonly;
7147
0
        }
7148
0
    }
7149
0
    if (args[2]) {
7150
0
        initial = PyLong_AsLongLong(args[2]);
7151
0
        if (initial == -1 && PyErr_Occurred()) {
7152
0
            goto exit;
7153
0
        }
7154
0
        if (!--noptargs) {
7155
0
            goto skip_optional_kwonly;
7156
0
        }
7157
0
    }
7158
0
    interval = PyLong_AsLongLong(args[3]);
7159
0
    if (interval == -1 && PyErr_Occurred()) {
7160
0
        goto exit;
7161
0
    }
7162
0
skip_optional_kwonly:
7163
0
    return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval);
7164
7165
0
exit:
7166
0
    return return_value;
7167
0
}
7168
7169
#endif /* defined(HAVE_TIMERFD_CREATE) */
7170
7171
#if defined(HAVE_TIMERFD_CREATE)
7172
7173
PyDoc_STRVAR(os_timerfd_gettime__doc__,
7174
"timerfd_gettime($module, fd, /)\n"
7175
"--\n"
7176
"\n"
7177
"Return a tuple of a timer file descriptor\'s (interval, next expiration) in float seconds.\n"
7178
"\n"
7179
"  fd\n"
7180
"    A timer file descriptor.");
7181
7182
#define OS_TIMERFD_GETTIME_METHODDEF    \
7183
    {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__},
7184
7185
static PyObject *
7186
os_timerfd_gettime_impl(PyObject *module, int fd);
7187
7188
static PyObject *
7189
os_timerfd_gettime(PyObject *module, PyObject *arg)
7190
0
{
7191
0
    PyObject *return_value = NULL;
7192
0
    int fd;
7193
7194
0
    fd = PyObject_AsFileDescriptor(arg);
7195
0
    if (fd < 0) {
7196
0
        goto exit;
7197
0
    }
7198
0
    return_value = os_timerfd_gettime_impl(module, fd);
7199
7200
0
exit:
7201
0
    return return_value;
7202
0
}
7203
7204
#endif /* defined(HAVE_TIMERFD_CREATE) */
7205
7206
#if defined(HAVE_TIMERFD_CREATE)
7207
7208
PyDoc_STRVAR(os_timerfd_gettime_ns__doc__,
7209
"timerfd_gettime_ns($module, fd, /)\n"
7210
"--\n"
7211
"\n"
7212
"Return a tuple of a timer file descriptor\'s (interval, next expiration) in nanoseconds.\n"
7213
"\n"
7214
"  fd\n"
7215
"    A timer file descriptor.");
7216
7217
#define OS_TIMERFD_GETTIME_NS_METHODDEF    \
7218
    {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__},
7219
7220
static PyObject *
7221
os_timerfd_gettime_ns_impl(PyObject *module, int fd);
7222
7223
static PyObject *
7224
os_timerfd_gettime_ns(PyObject *module, PyObject *arg)
7225
0
{
7226
0
    PyObject *return_value = NULL;
7227
0
    int fd;
7228
7229
0
    fd = PyObject_AsFileDescriptor(arg);
7230
0
    if (fd < 0) {
7231
0
        goto exit;
7232
0
    }
7233
0
    return_value = os_timerfd_gettime_ns_impl(module, fd);
7234
7235
0
exit:
7236
0
    return return_value;
7237
0
}
7238
7239
#endif /* defined(HAVE_TIMERFD_CREATE) */
7240
7241
#if defined(HAVE_GETSID)
7242
7243
PyDoc_STRVAR(os_getsid__doc__,
7244
"getsid($module, pid, /)\n"
7245
"--\n"
7246
"\n"
7247
"Call the system call getsid(pid) and return the result.");
7248
7249
#define OS_GETSID_METHODDEF    \
7250
    {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
7251
7252
static PyObject *
7253
os_getsid_impl(PyObject *module, pid_t pid);
7254
7255
static PyObject *
7256
os_getsid(PyObject *module, PyObject *arg)
7257
0
{
7258
0
    PyObject *return_value = NULL;
7259
0
    pid_t pid;
7260
7261
0
    pid = PyLong_AsPid(arg);
7262
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7263
0
        goto exit;
7264
0
    }
7265
0
    return_value = os_getsid_impl(module, pid);
7266
7267
0
exit:
7268
0
    return return_value;
7269
0
}
7270
7271
#endif /* defined(HAVE_GETSID) */
7272
7273
#if defined(HAVE_SETSID)
7274
7275
PyDoc_STRVAR(os_setsid__doc__,
7276
"setsid($module, /)\n"
7277
"--\n"
7278
"\n"
7279
"Call the system call setsid().");
7280
7281
#define OS_SETSID_METHODDEF    \
7282
    {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
7283
7284
static PyObject *
7285
os_setsid_impl(PyObject *module);
7286
7287
static PyObject *
7288
os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
7289
0
{
7290
0
    return os_setsid_impl(module);
7291
0
}
7292
7293
#endif /* defined(HAVE_SETSID) */
7294
7295
#if defined(HAVE_SETPGID)
7296
7297
PyDoc_STRVAR(os_setpgid__doc__,
7298
"setpgid($module, pid, pgrp, /)\n"
7299
"--\n"
7300
"\n"
7301
"Call the system call setpgid(pid, pgrp).");
7302
7303
#define OS_SETPGID_METHODDEF    \
7304
    {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__},
7305
7306
static PyObject *
7307
os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
7308
7309
static PyObject *
7310
os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7311
0
{
7312
0
    PyObject *return_value = NULL;
7313
0
    pid_t pid;
7314
0
    pid_t pgrp;
7315
7316
0
    if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) {
7317
0
        goto exit;
7318
0
    }
7319
0
    pid = PyLong_AsPid(args[0]);
7320
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7321
0
        goto exit;
7322
0
    }
7323
0
    pgrp = PyLong_AsPid(args[1]);
7324
0
    if (pgrp == (pid_t)(-1) && PyErr_Occurred()) {
7325
0
        goto exit;
7326
0
    }
7327
0
    return_value = os_setpgid_impl(module, pid, pgrp);
7328
7329
0
exit:
7330
0
    return return_value;
7331
0
}
7332
7333
#endif /* defined(HAVE_SETPGID) */
7334
7335
#if defined(HAVE_TCGETPGRP)
7336
7337
PyDoc_STRVAR(os_tcgetpgrp__doc__,
7338
"tcgetpgrp($module, fd, /)\n"
7339
"--\n"
7340
"\n"
7341
"Return the process group associated with the terminal specified by fd.");
7342
7343
#define OS_TCGETPGRP_METHODDEF    \
7344
    {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
7345
7346
static PyObject *
7347
os_tcgetpgrp_impl(PyObject *module, int fd);
7348
7349
static PyObject *
7350
os_tcgetpgrp(PyObject *module, PyObject *arg)
7351
0
{
7352
0
    PyObject *return_value = NULL;
7353
0
    int fd;
7354
7355
0
    fd = PyLong_AsInt(arg);
7356
0
    if (fd == -1 && PyErr_Occurred()) {
7357
0
        goto exit;
7358
0
    }
7359
0
    return_value = os_tcgetpgrp_impl(module, fd);
7360
7361
0
exit:
7362
0
    return return_value;
7363
0
}
7364
7365
#endif /* defined(HAVE_TCGETPGRP) */
7366
7367
#if defined(HAVE_TCSETPGRP)
7368
7369
PyDoc_STRVAR(os_tcsetpgrp__doc__,
7370
"tcsetpgrp($module, fd, pgid, /)\n"
7371
"--\n"
7372
"\n"
7373
"Set the process group associated with the terminal specified by fd.");
7374
7375
#define OS_TCSETPGRP_METHODDEF    \
7376
    {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__},
7377
7378
static PyObject *
7379
os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
7380
7381
static PyObject *
7382
os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7383
0
{
7384
0
    PyObject *return_value = NULL;
7385
0
    int fd;
7386
0
    pid_t pgid;
7387
7388
0
    if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) {
7389
0
        goto exit;
7390
0
    }
7391
0
    fd = PyLong_AsInt(args[0]);
7392
0
    if (fd == -1 && PyErr_Occurred()) {
7393
0
        goto exit;
7394
0
    }
7395
0
    pgid = PyLong_AsPid(args[1]);
7396
0
    if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
7397
0
        goto exit;
7398
0
    }
7399
0
    return_value = os_tcsetpgrp_impl(module, fd, pgid);
7400
7401
0
exit:
7402
0
    return return_value;
7403
0
}
7404
7405
#endif /* defined(HAVE_TCSETPGRP) */
7406
7407
PyDoc_STRVAR(os_open__doc__,
7408
"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
7409
"--\n"
7410
"\n"
7411
"Open a file for low level IO.  Returns a file descriptor (integer).\n"
7412
"\n"
7413
"If dir_fd is not None, it should be a file descriptor open to\n"
7414
"a directory, and path should be relative; path will then be relative to\n"
7415
"that directory.\n"
7416
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
7417
"using it will raise a NotImplementedError.");
7418
7419
#define OS_OPEN_METHODDEF    \
7420
    {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
7421
7422
static int
7423
os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
7424
7425
static PyObject *
7426
os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7427
0
{
7428
0
    PyObject *return_value = NULL;
7429
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7430
7431
0
    #define NUM_KEYWORDS 4
7432
0
    static struct {
7433
0
        PyGC_Head _this_is_not_used;
7434
0
        PyObject_VAR_HEAD
7435
0
        Py_hash_t ob_hash;
7436
0
        PyObject *ob_item[NUM_KEYWORDS];
7437
0
    } _kwtuple = {
7438
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7439
0
        .ob_hash = -1,
7440
0
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), },
7441
0
    };
7442
0
    #undef NUM_KEYWORDS
7443
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7444
7445
    #else  // !Py_BUILD_CORE
7446
    #  define KWTUPLE NULL
7447
    #endif  // !Py_BUILD_CORE
7448
7449
0
    static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
7450
0
    static _PyArg_Parser _parser = {
7451
0
        .keywords = _keywords,
7452
0
        .fname = "open",
7453
0
        .kwtuple = KWTUPLE,
7454
0
    };
7455
0
    #undef KWTUPLE
7456
0
    PyObject *argsbuf[4];
7457
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7458
0
    path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0);
7459
0
    int flags;
7460
0
    int mode = 511;
7461
0
    int dir_fd = DEFAULT_DIR_FD;
7462
0
    int _return_value;
7463
7464
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7465
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7466
0
    if (!args) {
7467
0
        goto exit;
7468
0
    }
7469
0
    if (!path_converter(args[0], &path)) {
7470
0
        goto exit;
7471
0
    }
7472
0
    flags = PyLong_AsInt(args[1]);
7473
0
    if (flags == -1 && PyErr_Occurred()) {
7474
0
        goto exit;
7475
0
    }
7476
0
    if (!noptargs) {
7477
0
        goto skip_optional_pos;
7478
0
    }
7479
0
    if (args[2]) {
7480
0
        mode = PyLong_AsInt(args[2]);
7481
0
        if (mode == -1 && PyErr_Occurred()) {
7482
0
            goto exit;
7483
0
        }
7484
0
        if (!--noptargs) {
7485
0
            goto skip_optional_pos;
7486
0
        }
7487
0
    }
7488
0
skip_optional_pos:
7489
0
    if (!noptargs) {
7490
0
        goto skip_optional_kwonly;
7491
0
    }
7492
0
    if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
7493
0
        goto exit;
7494
0
    }
7495
0
skip_optional_kwonly:
7496
0
    _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
7497
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7498
0
        goto exit;
7499
0
    }
7500
0
    return_value = PyLong_FromLong((long)_return_value);
7501
7502
0
exit:
7503
    /* Cleanup for path */
7504
0
    path_cleanup(&path);
7505
7506
0
    return return_value;
7507
0
}
7508
7509
PyDoc_STRVAR(os_close__doc__,
7510
"close($module, /, fd)\n"
7511
"--\n"
7512
"\n"
7513
"Close a file descriptor.");
7514
7515
#define OS_CLOSE_METHODDEF    \
7516
    {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
7517
7518
static PyObject *
7519
os_close_impl(PyObject *module, int fd);
7520
7521
static PyObject *
7522
os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7523
0
{
7524
0
    PyObject *return_value = NULL;
7525
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7526
7527
0
    #define NUM_KEYWORDS 1
7528
0
    static struct {
7529
0
        PyGC_Head _this_is_not_used;
7530
0
        PyObject_VAR_HEAD
7531
0
        Py_hash_t ob_hash;
7532
0
        PyObject *ob_item[NUM_KEYWORDS];
7533
0
    } _kwtuple = {
7534
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7535
0
        .ob_hash = -1,
7536
0
        .ob_item = { &_Py_ID(fd), },
7537
0
    };
7538
0
    #undef NUM_KEYWORDS
7539
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7540
7541
    #else  // !Py_BUILD_CORE
7542
    #  define KWTUPLE NULL
7543
    #endif  // !Py_BUILD_CORE
7544
7545
0
    static const char * const _keywords[] = {"fd", NULL};
7546
0
    static _PyArg_Parser _parser = {
7547
0
        .keywords = _keywords,
7548
0
        .fname = "close",
7549
0
        .kwtuple = KWTUPLE,
7550
0
    };
7551
0
    #undef KWTUPLE
7552
0
    PyObject *argsbuf[1];
7553
0
    int fd;
7554
7555
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7556
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7557
0
    if (!args) {
7558
0
        goto exit;
7559
0
    }
7560
0
    fd = PyLong_AsInt(args[0]);
7561
0
    if (fd == -1 && PyErr_Occurred()) {
7562
0
        goto exit;
7563
0
    }
7564
0
    return_value = os_close_impl(module, fd);
7565
7566
0
exit:
7567
0
    return return_value;
7568
0
}
7569
7570
PyDoc_STRVAR(os_closerange__doc__,
7571
"closerange($module, fd_low, fd_high, /)\n"
7572
"--\n"
7573
"\n"
7574
"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
7575
7576
#define OS_CLOSERANGE_METHODDEF    \
7577
    {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__},
7578
7579
static PyObject *
7580
os_closerange_impl(PyObject *module, int fd_low, int fd_high);
7581
7582
static PyObject *
7583
os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7584
0
{
7585
0
    PyObject *return_value = NULL;
7586
0
    int fd_low;
7587
0
    int fd_high;
7588
7589
0
    if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
7590
0
        goto exit;
7591
0
    }
7592
0
    fd_low = PyLong_AsInt(args[0]);
7593
0
    if (fd_low == -1 && PyErr_Occurred()) {
7594
0
        goto exit;
7595
0
    }
7596
0
    fd_high = PyLong_AsInt(args[1]);
7597
0
    if (fd_high == -1 && PyErr_Occurred()) {
7598
0
        goto exit;
7599
0
    }
7600
0
    return_value = os_closerange_impl(module, fd_low, fd_high);
7601
7602
0
exit:
7603
0
    return return_value;
7604
0
}
7605
7606
PyDoc_STRVAR(os_dup__doc__,
7607
"dup($module, fd, /)\n"
7608
"--\n"
7609
"\n"
7610
"Return a duplicate of a file descriptor.");
7611
7612
#define OS_DUP_METHODDEF    \
7613
    {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
7614
7615
static int
7616
os_dup_impl(PyObject *module, int fd);
7617
7618
static PyObject *
7619
os_dup(PyObject *module, PyObject *arg)
7620
0
{
7621
0
    PyObject *return_value = NULL;
7622
0
    int fd;
7623
0
    int _return_value;
7624
7625
0
    fd = PyLong_AsInt(arg);
7626
0
    if (fd == -1 && PyErr_Occurred()) {
7627
0
        goto exit;
7628
0
    }
7629
0
    _return_value = os_dup_impl(module, fd);
7630
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7631
0
        goto exit;
7632
0
    }
7633
0
    return_value = PyLong_FromLong((long)_return_value);
7634
7635
0
exit:
7636
0
    return return_value;
7637
0
}
7638
7639
#if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
7640
7641
PyDoc_STRVAR(os_dup2__doc__,
7642
"dup2($module, /, fd, fd2, inheritable=True)\n"
7643
"--\n"
7644
"\n"
7645
"Duplicate file descriptor.");
7646
7647
#define OS_DUP2_METHODDEF    \
7648
    {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
7649
7650
static int
7651
os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
7652
7653
static PyObject *
7654
os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7655
0
{
7656
0
    PyObject *return_value = NULL;
7657
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7658
7659
0
    #define NUM_KEYWORDS 3
7660
0
    static struct {
7661
0
        PyGC_Head _this_is_not_used;
7662
0
        PyObject_VAR_HEAD
7663
0
        Py_hash_t ob_hash;
7664
0
        PyObject *ob_item[NUM_KEYWORDS];
7665
0
    } _kwtuple = {
7666
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7667
0
        .ob_hash = -1,
7668
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), },
7669
0
    };
7670
0
    #undef NUM_KEYWORDS
7671
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7672
7673
    #else  // !Py_BUILD_CORE
7674
    #  define KWTUPLE NULL
7675
    #endif  // !Py_BUILD_CORE
7676
7677
0
    static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
7678
0
    static _PyArg_Parser _parser = {
7679
0
        .keywords = _keywords,
7680
0
        .fname = "dup2",
7681
0
        .kwtuple = KWTUPLE,
7682
0
    };
7683
0
    #undef KWTUPLE
7684
0
    PyObject *argsbuf[3];
7685
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7686
0
    int fd;
7687
0
    int fd2;
7688
0
    int inheritable = 1;
7689
0
    int _return_value;
7690
7691
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7692
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7693
0
    if (!args) {
7694
0
        goto exit;
7695
0
    }
7696
0
    fd = PyLong_AsInt(args[0]);
7697
0
    if (fd == -1 && PyErr_Occurred()) {
7698
0
        goto exit;
7699
0
    }
7700
0
    fd2 = PyLong_AsInt(args[1]);
7701
0
    if (fd2 == -1 && PyErr_Occurred()) {
7702
0
        goto exit;
7703
0
    }
7704
0
    if (!noptargs) {
7705
0
        goto skip_optional_pos;
7706
0
    }
7707
0
    inheritable = PyObject_IsTrue(args[2]);
7708
0
    if (inheritable < 0) {
7709
0
        goto exit;
7710
0
    }
7711
0
skip_optional_pos:
7712
0
    _return_value = os_dup2_impl(module, fd, fd2, inheritable);
7713
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7714
0
        goto exit;
7715
0
    }
7716
0
    return_value = PyLong_FromLong((long)_return_value);
7717
7718
0
exit:
7719
0
    return return_value;
7720
0
}
7721
7722
#endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
7723
7724
#if defined(HAVE_LOCKF)
7725
7726
PyDoc_STRVAR(os_lockf__doc__,
7727
"lockf($module, fd, command, length, /)\n"
7728
"--\n"
7729
"\n"
7730
"Apply, test or remove a POSIX lock on an open file descriptor.\n"
7731
"\n"
7732
"  fd\n"
7733
"    An open file descriptor.\n"
7734
"  command\n"
7735
"    One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
7736
"  length\n"
7737
"    The number of bytes to lock, starting at the current position.");
7738
7739
#define OS_LOCKF_METHODDEF    \
7740
    {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__},
7741
7742
static PyObject *
7743
os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
7744
7745
static PyObject *
7746
os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7747
0
{
7748
0
    PyObject *return_value = NULL;
7749
0
    int fd;
7750
0
    int command;
7751
0
    Py_off_t length;
7752
7753
0
    if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
7754
0
        goto exit;
7755
0
    }
7756
0
    fd = PyLong_AsInt(args[0]);
7757
0
    if (fd == -1 && PyErr_Occurred()) {
7758
0
        goto exit;
7759
0
    }
7760
0
    command = PyLong_AsInt(args[1]);
7761
0
    if (command == -1 && PyErr_Occurred()) {
7762
0
        goto exit;
7763
0
    }
7764
0
    if (!Py_off_t_converter(args[2], &length)) {
7765
0
        goto exit;
7766
0
    }
7767
0
    return_value = os_lockf_impl(module, fd, command, length);
7768
7769
0
exit:
7770
0
    return return_value;
7771
0
}
7772
7773
#endif /* defined(HAVE_LOCKF) */
7774
7775
PyDoc_STRVAR(os_lseek__doc__,
7776
"lseek($module, fd, position, whence, /)\n"
7777
"--\n"
7778
"\n"
7779
"Set the position of a file descriptor.  Return the new position.\n"
7780
"\n"
7781
"  fd\n"
7782
"    An open file descriptor, as returned by os.open().\n"
7783
"  position\n"
7784
"    Position, interpreted relative to \'whence\'.\n"
7785
"  whence\n"
7786
"    The relative position to seek from. Valid values are:\n"
7787
"    - SEEK_SET: seek from the start of the file.\n"
7788
"    - SEEK_CUR: seek from the current file position.\n"
7789
"    - SEEK_END: seek from the end of the file.\n"
7790
"\n"
7791
"The return value is the number of bytes relative to the beginning of\n"
7792
"the file.");
7793
7794
#define OS_LSEEK_METHODDEF    \
7795
    {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__},
7796
7797
static Py_off_t
7798
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
7799
7800
static PyObject *
7801
os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7802
0
{
7803
0
    PyObject *return_value = NULL;
7804
0
    int fd;
7805
0
    Py_off_t position;
7806
0
    int how;
7807
0
    Py_off_t _return_value;
7808
7809
0
    if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
7810
0
        goto exit;
7811
0
    }
7812
0
    fd = PyLong_AsInt(args[0]);
7813
0
    if (fd == -1 && PyErr_Occurred()) {
7814
0
        goto exit;
7815
0
    }
7816
0
    if (!Py_off_t_converter(args[1], &position)) {
7817
0
        goto exit;
7818
0
    }
7819
0
    how = PyLong_AsInt(args[2]);
7820
0
    if (how == -1 && PyErr_Occurred()) {
7821
0
        goto exit;
7822
0
    }
7823
0
    _return_value = os_lseek_impl(module, fd, position, how);
7824
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7825
0
        goto exit;
7826
0
    }
7827
0
    return_value = PyLong_FromPy_off_t(_return_value);
7828
7829
0
exit:
7830
0
    return return_value;
7831
0
}
7832
7833
PyDoc_STRVAR(os_read__doc__,
7834
"read($module, fd, length, /)\n"
7835
"--\n"
7836
"\n"
7837
"Read from a file descriptor.  Returns a bytes object.");
7838
7839
#define OS_READ_METHODDEF    \
7840
    {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__},
7841
7842
static PyObject *
7843
os_read_impl(PyObject *module, int fd, Py_ssize_t length);
7844
7845
static PyObject *
7846
os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7847
0
{
7848
0
    PyObject *return_value = NULL;
7849
0
    int fd;
7850
0
    Py_ssize_t length;
7851
7852
0
    if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
7853
0
        goto exit;
7854
0
    }
7855
0
    fd = PyLong_AsInt(args[0]);
7856
0
    if (fd == -1 && PyErr_Occurred()) {
7857
0
        goto exit;
7858
0
    }
7859
0
    {
7860
0
        Py_ssize_t ival = -1;
7861
0
        PyObject *iobj = _PyNumber_Index(args[1]);
7862
0
        if (iobj != NULL) {
7863
0
            ival = PyLong_AsSsize_t(iobj);
7864
0
            Py_DECREF(iobj);
7865
0
        }
7866
0
        if (ival == -1 && PyErr_Occurred()) {
7867
0
            goto exit;
7868
0
        }
7869
0
        length = ival;
7870
0
    }
7871
0
    return_value = os_read_impl(module, fd, length);
7872
7873
0
exit:
7874
0
    return return_value;
7875
0
}
7876
7877
PyDoc_STRVAR(os_readinto__doc__,
7878
"readinto($module, fd, buffer, /)\n"
7879
"--\n"
7880
"\n"
7881
"Read into a buffer object from a file descriptor.\n"
7882
"\n"
7883
"The buffer should be mutable and bytes-like.  On success, returns the\n"
7884
"number of bytes read.  Less bytes may be read than the size of the\n"
7885
"buffer.  The underlying system call will be retried when interrupted by\n"
7886
"a signal, unless the signal handler raises an exception.  Other errors\n"
7887
"will not be retried and an error will be raised.\n"
7888
"\n"
7889
"Returns 0 if *fd* is at end of file or if the provided *buffer* has\n"
7890
"length 0 (which can be used to check for errors without reading data).\n"
7891
"Never returns negative.");
7892
7893
#define OS_READINTO_METHODDEF    \
7894
    {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__},
7895
7896
static Py_ssize_t
7897
os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer);
7898
7899
static PyObject *
7900
os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7901
0
{
7902
0
    PyObject *return_value = NULL;
7903
0
    int fd;
7904
0
    Py_buffer buffer = {NULL, NULL};
7905
0
    Py_ssize_t _return_value;
7906
7907
0
    if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) {
7908
0
        goto exit;
7909
0
    }
7910
0
    fd = PyLong_AsInt(args[0]);
7911
0
    if (fd == -1 && PyErr_Occurred()) {
7912
0
        goto exit;
7913
0
    }
7914
0
    if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) {
7915
0
        _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]);
7916
0
        goto exit;
7917
0
    }
7918
0
    _return_value = os_readinto_impl(module, fd, &buffer);
7919
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7920
0
        goto exit;
7921
0
    }
7922
0
    return_value = PyLong_FromSsize_t(_return_value);
7923
7924
0
exit:
7925
    /* Cleanup for buffer */
7926
0
    if (buffer.obj) {
7927
0
       PyBuffer_Release(&buffer);
7928
0
    }
7929
7930
0
    return return_value;
7931
0
}
7932
7933
#if defined(HAVE_READV)
7934
7935
PyDoc_STRVAR(os_readv__doc__,
7936
"readv($module, fd, buffers, /)\n"
7937
"--\n"
7938
"\n"
7939
"Read from a file descriptor fd into an iterable of buffers.\n"
7940
"\n"
7941
"The buffers should be mutable buffers accepting bytes.\n"
7942
"readv will transfer data into each buffer until it is full\n"
7943
"and then move on to the next buffer in the sequence to hold\n"
7944
"the rest of the data.\n"
7945
"\n"
7946
"readv returns the total number of bytes read,\n"
7947
"which may be less than the total capacity of all the buffers.");
7948
7949
#define OS_READV_METHODDEF    \
7950
    {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__},
7951
7952
static Py_ssize_t
7953
os_readv_impl(PyObject *module, int fd, PyObject *buffers);
7954
7955
static PyObject *
7956
os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7957
0
{
7958
0
    PyObject *return_value = NULL;
7959
0
    int fd;
7960
0
    PyObject *buffers;
7961
0
    Py_ssize_t _return_value;
7962
7963
0
    if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
7964
0
        goto exit;
7965
0
    }
7966
0
    fd = PyLong_AsInt(args[0]);
7967
0
    if (fd == -1 && PyErr_Occurred()) {
7968
0
        goto exit;
7969
0
    }
7970
0
    buffers = args[1];
7971
0
    _return_value = os_readv_impl(module, fd, buffers);
7972
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7973
0
        goto exit;
7974
0
    }
7975
0
    return_value = PyLong_FromSsize_t(_return_value);
7976
7977
0
exit:
7978
0
    return return_value;
7979
0
}
7980
7981
#endif /* defined(HAVE_READV) */
7982
7983
#if defined(HAVE_PREAD)
7984
7985
PyDoc_STRVAR(os_pread__doc__,
7986
"pread($module, fd, length, offset, /)\n"
7987
"--\n"
7988
"\n"
7989
"Read a number of bytes from a file descriptor starting at a particular offset.\n"
7990
"\n"
7991
"Read length bytes from file descriptor fd, starting at offset bytes from\n"
7992
"the beginning of the file.  The file offset remains unchanged.");
7993
7994
#define OS_PREAD_METHODDEF    \
7995
    {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__},
7996
7997
static PyObject *
7998
os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset);
7999
8000
static PyObject *
8001
os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8002
0
{
8003
0
    PyObject *return_value = NULL;
8004
0
    int fd;
8005
0
    Py_ssize_t length;
8006
0
    Py_off_t offset;
8007
8008
0
    if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
8009
0
        goto exit;
8010
0
    }
8011
0
    fd = PyLong_AsInt(args[0]);
8012
0
    if (fd == -1 && PyErr_Occurred()) {
8013
0
        goto exit;
8014
0
    }
8015
0
    {
8016
0
        Py_ssize_t ival = -1;
8017
0
        PyObject *iobj = _PyNumber_Index(args[1]);
8018
0
        if (iobj != NULL) {
8019
0
            ival = PyLong_AsSsize_t(iobj);
8020
0
            Py_DECREF(iobj);
8021
0
        }
8022
0
        if (ival == -1 && PyErr_Occurred()) {
8023
0
            goto exit;
8024
0
        }
8025
0
        length = ival;
8026
0
    }
8027
0
    if (!Py_off_t_converter(args[2], &offset)) {
8028
0
        goto exit;
8029
0
    }
8030
0
    return_value = os_pread_impl(module, fd, length, offset);
8031
8032
0
exit:
8033
0
    return return_value;
8034
0
}
8035
8036
#endif /* defined(HAVE_PREAD) */
8037
8038
#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
8039
8040
PyDoc_STRVAR(os_preadv__doc__,
8041
"preadv($module, fd, buffers, offset, flags=0, /)\n"
8042
"--\n"
8043
"\n"
8044
"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
8045
"\n"
8046
"Combines the functionality of readv() and pread().  As readv(), it will\n"
8047
"transfer data into each buffer until it is full and then move on to the\n"
8048
"next buffer in the sequence to hold the rest of the data.  Its fourth\n"
8049
"argument, specifies the file offset at which the input operation is to\n"
8050
"be performed.  It will return the total number of bytes read (which can\n"
8051
"be less than the total capacity of all the objects).\n"
8052
"\n"
8053
"The flags argument contains a bitwise OR of zero or more of the\n"
8054
"following flags:\n"
8055
"\n"
8056
"- RWF_HIPRI\n"
8057
"- RWF_NOWAIT\n"
8058
"- RWF_DONTCACHE\n"
8059
"\n"
8060
"Using non-zero flags requires Linux 4.6 or newer.");
8061
8062
#define OS_PREADV_METHODDEF    \
8063
    {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__},
8064
8065
static Py_ssize_t
8066
os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
8067
               int flags);
8068
8069
static PyObject *
8070
os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8071
0
{
8072
0
    PyObject *return_value = NULL;
8073
0
    int fd;
8074
0
    PyObject *buffers;
8075
0
    Py_off_t offset;
8076
0
    int flags = 0;
8077
0
    Py_ssize_t _return_value;
8078
8079
0
    if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
8080
0
        goto exit;
8081
0
    }
8082
0
    fd = PyLong_AsInt(args[0]);
8083
0
    if (fd == -1 && PyErr_Occurred()) {
8084
0
        goto exit;
8085
0
    }
8086
0
    buffers = args[1];
8087
0
    if (!Py_off_t_converter(args[2], &offset)) {
8088
0
        goto exit;
8089
0
    }
8090
0
    if (nargs < 4) {
8091
0
        goto skip_optional;
8092
0
    }
8093
0
    flags = PyLong_AsInt(args[3]);
8094
0
    if (flags == -1 && PyErr_Occurred()) {
8095
0
        goto exit;
8096
0
    }
8097
0
skip_optional:
8098
0
    _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
8099
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8100
0
        goto exit;
8101
0
    }
8102
0
    return_value = PyLong_FromSsize_t(_return_value);
8103
8104
0
exit:
8105
0
    return return_value;
8106
0
}
8107
8108
#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
8109
8110
PyDoc_STRVAR(os_write__doc__,
8111
"write($module, fd, data, /)\n"
8112
"--\n"
8113
"\n"
8114
"Write a bytes object to a file descriptor.");
8115
8116
#define OS_WRITE_METHODDEF    \
8117
    {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__},
8118
8119
static Py_ssize_t
8120
os_write_impl(PyObject *module, int fd, Py_buffer *data);
8121
8122
static PyObject *
8123
os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8124
0
{
8125
0
    PyObject *return_value = NULL;
8126
0
    int fd;
8127
0
    Py_buffer data = {NULL, NULL};
8128
0
    Py_ssize_t _return_value;
8129
8130
0
    if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
8131
0
        goto exit;
8132
0
    }
8133
0
    fd = PyLong_AsInt(args[0]);
8134
0
    if (fd == -1 && PyErr_Occurred()) {
8135
0
        goto exit;
8136
0
    }
8137
0
    if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
8138
0
        goto exit;
8139
0
    }
8140
0
    _return_value = os_write_impl(module, fd, &data);
8141
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8142
0
        goto exit;
8143
0
    }
8144
0
    return_value = PyLong_FromSsize_t(_return_value);
8145
8146
0
exit:
8147
    /* Cleanup for data */
8148
0
    if (data.obj) {
8149
0
       PyBuffer_Release(&data);
8150
0
    }
8151
8152
0
    return return_value;
8153
0
}
8154
8155
#if defined(HAVE_SENDFILE) && defined(__APPLE__)
8156
8157
PyDoc_STRVAR(os_sendfile__doc__,
8158
"sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
8159
"         trailers=(), flags=0)\n"
8160
"--\n"
8161
"\n"
8162
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8163
8164
#define OS_SENDFILE_METHODDEF    \
8165
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8166
8167
static PyObject *
8168
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
8169
                 Py_off_t sbytes, PyObject *headers, PyObject *trailers,
8170
                 int flags);
8171
8172
static PyObject *
8173
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8174
{
8175
    PyObject *return_value = NULL;
8176
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8177
8178
    #define NUM_KEYWORDS 7
8179
    static struct {
8180
        PyGC_Head _this_is_not_used;
8181
        PyObject_VAR_HEAD
8182
        Py_hash_t ob_hash;
8183
        PyObject *ob_item[NUM_KEYWORDS];
8184
    } _kwtuple = {
8185
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8186
        .ob_hash = -1,
8187
        .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), },
8188
    };
8189
    #undef NUM_KEYWORDS
8190
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8191
8192
    #else  // !Py_BUILD_CORE
8193
    #  define KWTUPLE NULL
8194
    #endif  // !Py_BUILD_CORE
8195
8196
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
8197
    static _PyArg_Parser _parser = {
8198
        .keywords = _keywords,
8199
        .fname = "sendfile",
8200
        .kwtuple = KWTUPLE,
8201
    };
8202
    #undef KWTUPLE
8203
    PyObject *argsbuf[7];
8204
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
8205
    int out_fd;
8206
    int in_fd;
8207
    Py_off_t offset;
8208
    Py_off_t sbytes;
8209
    PyObject *headers = NULL;
8210
    PyObject *trailers = NULL;
8211
    int flags = 0;
8212
8213
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8214
            /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8215
    if (!args) {
8216
        goto exit;
8217
    }
8218
    out_fd = PyLong_AsInt(args[0]);
8219
    if (out_fd == -1 && PyErr_Occurred()) {
8220
        goto exit;
8221
    }
8222
    in_fd = PyLong_AsInt(args[1]);
8223
    if (in_fd == -1 && PyErr_Occurred()) {
8224
        goto exit;
8225
    }
8226
    if (!Py_off_t_converter(args[2], &offset)) {
8227
        goto exit;
8228
    }
8229
    if (!Py_off_t_converter(args[3], &sbytes)) {
8230
        goto exit;
8231
    }
8232
    if (!noptargs) {
8233
        goto skip_optional_pos;
8234
    }
8235
    if (args[4]) {
8236
        headers = args[4];
8237
        if (!--noptargs) {
8238
            goto skip_optional_pos;
8239
        }
8240
    }
8241
    if (args[5]) {
8242
        trailers = args[5];
8243
        if (!--noptargs) {
8244
            goto skip_optional_pos;
8245
        }
8246
    }
8247
    flags = PyLong_AsInt(args[6]);
8248
    if (flags == -1 && PyErr_Occurred()) {
8249
        goto exit;
8250
    }
8251
skip_optional_pos:
8252
    return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags);
8253
8254
exit:
8255
    return return_value;
8256
}
8257
8258
#endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */
8259
8260
#if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__))
8261
8262
PyDoc_STRVAR(os_sendfile__doc__,
8263
"sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
8264
"         trailers=(), flags=0)\n"
8265
"--\n"
8266
"\n"
8267
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8268
8269
#define OS_SENDFILE_METHODDEF    \
8270
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8271
8272
static PyObject *
8273
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
8274
                 Py_ssize_t count, PyObject *headers, PyObject *trailers,
8275
                 int flags);
8276
8277
static PyObject *
8278
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8279
{
8280
    PyObject *return_value = NULL;
8281
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8282
8283
    #define NUM_KEYWORDS 7
8284
    static struct {
8285
        PyGC_Head _this_is_not_used;
8286
        PyObject_VAR_HEAD
8287
        Py_hash_t ob_hash;
8288
        PyObject *ob_item[NUM_KEYWORDS];
8289
    } _kwtuple = {
8290
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8291
        .ob_hash = -1,
8292
        .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), },
8293
    };
8294
    #undef NUM_KEYWORDS
8295
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8296
8297
    #else  // !Py_BUILD_CORE
8298
    #  define KWTUPLE NULL
8299
    #endif  // !Py_BUILD_CORE
8300
8301
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
8302
    static _PyArg_Parser _parser = {
8303
        .keywords = _keywords,
8304
        .fname = "sendfile",
8305
        .kwtuple = KWTUPLE,
8306
    };
8307
    #undef KWTUPLE
8308
    PyObject *argsbuf[7];
8309
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
8310
    int out_fd;
8311
    int in_fd;
8312
    Py_off_t offset;
8313
    Py_ssize_t count;
8314
    PyObject *headers = NULL;
8315
    PyObject *trailers = NULL;
8316
    int flags = 0;
8317
8318
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8319
            /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8320
    if (!args) {
8321
        goto exit;
8322
    }
8323
    out_fd = PyLong_AsInt(args[0]);
8324
    if (out_fd == -1 && PyErr_Occurred()) {
8325
        goto exit;
8326
    }
8327
    in_fd = PyLong_AsInt(args[1]);
8328
    if (in_fd == -1 && PyErr_Occurred()) {
8329
        goto exit;
8330
    }
8331
    if (!Py_off_t_converter(args[2], &offset)) {
8332
        goto exit;
8333
    }
8334
    {
8335
        Py_ssize_t ival = -1;
8336
        PyObject *iobj = _PyNumber_Index(args[3]);
8337
        if (iobj != NULL) {
8338
            ival = PyLong_AsSsize_t(iobj);
8339
            Py_DECREF(iobj);
8340
        }
8341
        if (ival == -1 && PyErr_Occurred()) {
8342
            goto exit;
8343
        }
8344
        count = ival;
8345
        if (count < 0) {
8346
            PyErr_SetString(PyExc_ValueError,
8347
                            "count cannot be negative");
8348
            goto exit;
8349
        }
8350
    }
8351
    if (!noptargs) {
8352
        goto skip_optional_pos;
8353
    }
8354
    if (args[4]) {
8355
        headers = args[4];
8356
        if (!--noptargs) {
8357
            goto skip_optional_pos;
8358
        }
8359
    }
8360
    if (args[5]) {
8361
        trailers = args[5];
8362
        if (!--noptargs) {
8363
            goto skip_optional_pos;
8364
        }
8365
    }
8366
    flags = PyLong_AsInt(args[6]);
8367
    if (flags == -1 && PyErr_Occurred()) {
8368
        goto exit;
8369
    }
8370
skip_optional_pos:
8371
    return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags);
8372
8373
exit:
8374
    return return_value;
8375
}
8376
8377
#endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */
8378
8379
#if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__))
8380
8381
PyDoc_STRVAR(os_sendfile__doc__,
8382
"sendfile($module, /, out_fd, in_fd, offset, count)\n"
8383
"--\n"
8384
"\n"
8385
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8386
8387
#define OS_SENDFILE_METHODDEF    \
8388
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8389
8390
static PyObject *
8391
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
8392
                 Py_ssize_t count);
8393
8394
static PyObject *
8395
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8396
0
{
8397
0
    PyObject *return_value = NULL;
8398
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8399
8400
0
    #define NUM_KEYWORDS 4
8401
0
    static struct {
8402
0
        PyGC_Head _this_is_not_used;
8403
0
        PyObject_VAR_HEAD
8404
0
        Py_hash_t ob_hash;
8405
0
        PyObject *ob_item[NUM_KEYWORDS];
8406
0
    } _kwtuple = {
8407
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8408
0
        .ob_hash = -1,
8409
0
        .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), },
8410
0
    };
8411
0
    #undef NUM_KEYWORDS
8412
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8413
8414
    #else  // !Py_BUILD_CORE
8415
    #  define KWTUPLE NULL
8416
    #endif  // !Py_BUILD_CORE
8417
8418
0
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL};
8419
0
    static _PyArg_Parser _parser = {
8420
0
        .keywords = _keywords,
8421
0
        .fname = "sendfile",
8422
0
        .kwtuple = KWTUPLE,
8423
0
    };
8424
0
    #undef KWTUPLE
8425
0
    PyObject *argsbuf[4];
8426
0
    int out_fd;
8427
0
    int in_fd;
8428
0
    PyObject *offobj;
8429
0
    Py_ssize_t count;
8430
8431
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8432
0
            /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8433
0
    if (!args) {
8434
0
        goto exit;
8435
0
    }
8436
0
    out_fd = PyLong_AsInt(args[0]);
8437
0
    if (out_fd == -1 && PyErr_Occurred()) {
8438
0
        goto exit;
8439
0
    }
8440
0
    in_fd = PyLong_AsInt(args[1]);
8441
0
    if (in_fd == -1 && PyErr_Occurred()) {
8442
0
        goto exit;
8443
0
    }
8444
0
    offobj = args[2];
8445
0
    {
8446
0
        Py_ssize_t ival = -1;
8447
0
        PyObject *iobj = _PyNumber_Index(args[3]);
8448
0
        if (iobj != NULL) {
8449
0
            ival = PyLong_AsSsize_t(iobj);
8450
0
            Py_DECREF(iobj);
8451
0
        }
8452
0
        if (ival == -1 && PyErr_Occurred()) {
8453
0
            goto exit;
8454
0
        }
8455
0
        count = ival;
8456
0
        if (count < 0) {
8457
0
            PyErr_SetString(PyExc_ValueError,
8458
0
                            "count cannot be negative");
8459
0
            goto exit;
8460
0
        }
8461
0
    }
8462
0
    return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count);
8463
8464
0
exit:
8465
0
    return return_value;
8466
0
}
8467
8468
#endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */
8469
8470
#if defined(__APPLE__)
8471
8472
PyDoc_STRVAR(os__fcopyfile__doc__,
8473
"_fcopyfile($module, in_fd, out_fd, flags, /)\n"
8474
"--\n"
8475
"\n"
8476
"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
8477
8478
#define OS__FCOPYFILE_METHODDEF    \
8479
    {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__},
8480
8481
static PyObject *
8482
os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags);
8483
8484
static PyObject *
8485
os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8486
{
8487
    PyObject *return_value = NULL;
8488
    int in_fd;
8489
    int out_fd;
8490
    int flags;
8491
8492
    if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
8493
        goto exit;
8494
    }
8495
    in_fd = PyLong_AsInt(args[0]);
8496
    if (in_fd == -1 && PyErr_Occurred()) {
8497
        goto exit;
8498
    }
8499
    out_fd = PyLong_AsInt(args[1]);
8500
    if (out_fd == -1 && PyErr_Occurred()) {
8501
        goto exit;
8502
    }
8503
    flags = PyLong_AsInt(args[2]);
8504
    if (flags == -1 && PyErr_Occurred()) {
8505
        goto exit;
8506
    }
8507
    return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags);
8508
8509
exit:
8510
    return return_value;
8511
}
8512
8513
#endif /* defined(__APPLE__) */
8514
8515
PyDoc_STRVAR(os_fstat__doc__,
8516
"fstat($module, /, fd)\n"
8517
"--\n"
8518
"\n"
8519
"Perform a stat system call on the given file descriptor.\n"
8520
"\n"
8521
"Like stat(), but for an open file descriptor.\n"
8522
"Equivalent to os.stat(fd).");
8523
8524
#define OS_FSTAT_METHODDEF    \
8525
    {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
8526
8527
static PyObject *
8528
os_fstat_impl(PyObject *module, int fd);
8529
8530
static PyObject *
8531
os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8532
0
{
8533
0
    PyObject *return_value = NULL;
8534
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8535
8536
0
    #define NUM_KEYWORDS 1
8537
0
    static struct {
8538
0
        PyGC_Head _this_is_not_used;
8539
0
        PyObject_VAR_HEAD
8540
0
        Py_hash_t ob_hash;
8541
0
        PyObject *ob_item[NUM_KEYWORDS];
8542
0
    } _kwtuple = {
8543
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8544
0
        .ob_hash = -1,
8545
0
        .ob_item = { &_Py_ID(fd), },
8546
0
    };
8547
0
    #undef NUM_KEYWORDS
8548
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8549
8550
    #else  // !Py_BUILD_CORE
8551
    #  define KWTUPLE NULL
8552
    #endif  // !Py_BUILD_CORE
8553
8554
0
    static const char * const _keywords[] = {"fd", NULL};
8555
0
    static _PyArg_Parser _parser = {
8556
0
        .keywords = _keywords,
8557
0
        .fname = "fstat",
8558
0
        .kwtuple = KWTUPLE,
8559
0
    };
8560
0
    #undef KWTUPLE
8561
0
    PyObject *argsbuf[1];
8562
0
    int fd;
8563
8564
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8565
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8566
0
    if (!args) {
8567
0
        goto exit;
8568
0
    }
8569
0
    fd = PyLong_AsInt(args[0]);
8570
0
    if (fd == -1 && PyErr_Occurred()) {
8571
0
        goto exit;
8572
0
    }
8573
0
    return_value = os_fstat_impl(module, fd);
8574
8575
0
exit:
8576
0
    return return_value;
8577
0
}
8578
8579
PyDoc_STRVAR(os_isatty__doc__,
8580
"isatty($module, fd, /)\n"
8581
"--\n"
8582
"\n"
8583
"Return True if the fd is connected to a terminal.\n"
8584
"\n"
8585
"Return True if the file descriptor is an open file descriptor\n"
8586
"connected to the slave end of a terminal.");
8587
8588
#define OS_ISATTY_METHODDEF    \
8589
    {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
8590
8591
static int
8592
os_isatty_impl(PyObject *module, int fd);
8593
8594
static PyObject *
8595
os_isatty(PyObject *module, PyObject *arg)
8596
0
{
8597
0
    PyObject *return_value = NULL;
8598
0
    int fd;
8599
0
    int _return_value;
8600
8601
0
    fd = PyLong_AsInt(arg);
8602
0
    if (fd == -1 && PyErr_Occurred()) {
8603
0
        goto exit;
8604
0
    }
8605
0
    _return_value = os_isatty_impl(module, fd);
8606
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8607
0
        goto exit;
8608
0
    }
8609
0
    return_value = PyBool_FromLong((long)_return_value);
8610
8611
0
exit:
8612
0
    return return_value;
8613
0
}
8614
8615
#if defined(HAVE_PIPE)
8616
8617
PyDoc_STRVAR(os_pipe__doc__,
8618
"pipe($module, /)\n"
8619
"--\n"
8620
"\n"
8621
"Create a pipe.\n"
8622
"\n"
8623
"Returns a tuple of two file descriptors:\n"
8624
"  (read_fd, write_fd)");
8625
8626
#define OS_PIPE_METHODDEF    \
8627
    {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
8628
8629
static PyObject *
8630
os_pipe_impl(PyObject *module);
8631
8632
static PyObject *
8633
os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
8634
0
{
8635
0
    return os_pipe_impl(module);
8636
0
}
8637
8638
#endif /* defined(HAVE_PIPE) */
8639
8640
#if defined(HAVE_PIPE2)
8641
8642
PyDoc_STRVAR(os_pipe2__doc__,
8643
"pipe2($module, flags, /)\n"
8644
"--\n"
8645
"\n"
8646
"Create a pipe with flags set atomically.\n"
8647
"\n"
8648
"Returns a tuple of two file descriptors:\n"
8649
"  (read_fd, write_fd)\n"
8650
"\n"
8651
"flags can be constructed by ORing together one or more of these values:\n"
8652
"O_NONBLOCK, O_CLOEXEC.");
8653
8654
#define OS_PIPE2_METHODDEF    \
8655
    {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
8656
8657
static PyObject *
8658
os_pipe2_impl(PyObject *module, int flags);
8659
8660
static PyObject *
8661
os_pipe2(PyObject *module, PyObject *arg)
8662
0
{
8663
0
    PyObject *return_value = NULL;
8664
0
    int flags;
8665
8666
0
    flags = PyLong_AsInt(arg);
8667
0
    if (flags == -1 && PyErr_Occurred()) {
8668
0
        goto exit;
8669
0
    }
8670
0
    return_value = os_pipe2_impl(module, flags);
8671
8672
0
exit:
8673
0
    return return_value;
8674
0
}
8675
8676
#endif /* defined(HAVE_PIPE2) */
8677
8678
#if defined(HAVE_WRITEV)
8679
8680
PyDoc_STRVAR(os_writev__doc__,
8681
"writev($module, fd, buffers, /)\n"
8682
"--\n"
8683
"\n"
8684
"Iterate over buffers, and write the contents of each to a file descriptor.\n"
8685
"\n"
8686
"Returns the total number of bytes written.\n"
8687
"buffers must be a sequence of bytes-like objects.");
8688
8689
#define OS_WRITEV_METHODDEF    \
8690
    {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__},
8691
8692
static Py_ssize_t
8693
os_writev_impl(PyObject *module, int fd, PyObject *buffers);
8694
8695
static PyObject *
8696
os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8697
0
{
8698
0
    PyObject *return_value = NULL;
8699
0
    int fd;
8700
0
    PyObject *buffers;
8701
0
    Py_ssize_t _return_value;
8702
8703
0
    if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
8704
0
        goto exit;
8705
0
    }
8706
0
    fd = PyLong_AsInt(args[0]);
8707
0
    if (fd == -1 && PyErr_Occurred()) {
8708
0
        goto exit;
8709
0
    }
8710
0
    buffers = args[1];
8711
0
    _return_value = os_writev_impl(module, fd, buffers);
8712
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8713
0
        goto exit;
8714
0
    }
8715
0
    return_value = PyLong_FromSsize_t(_return_value);
8716
8717
0
exit:
8718
0
    return return_value;
8719
0
}
8720
8721
#endif /* defined(HAVE_WRITEV) */
8722
8723
#if defined(HAVE_PWRITE)
8724
8725
PyDoc_STRVAR(os_pwrite__doc__,
8726
"pwrite($module, fd, buffer, offset, /)\n"
8727
"--\n"
8728
"\n"
8729
"Write bytes to a file descriptor starting at a particular offset.\n"
8730
"\n"
8731
"Write buffer to fd, starting at offset bytes from the beginning of\n"
8732
"the file.  Returns the number of bytes written.  Does not change the\n"
8733
"current file offset.");
8734
8735
#define OS_PWRITE_METHODDEF    \
8736
    {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__},
8737
8738
static Py_ssize_t
8739
os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
8740
8741
static PyObject *
8742
os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8743
0
{
8744
0
    PyObject *return_value = NULL;
8745
0
    int fd;
8746
0
    Py_buffer buffer = {NULL, NULL};
8747
0
    Py_off_t offset;
8748
0
    Py_ssize_t _return_value;
8749
8750
0
    if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
8751
0
        goto exit;
8752
0
    }
8753
0
    fd = PyLong_AsInt(args[0]);
8754
0
    if (fd == -1 && PyErr_Occurred()) {
8755
0
        goto exit;
8756
0
    }
8757
0
    if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
8758
0
        goto exit;
8759
0
    }
8760
0
    if (!Py_off_t_converter(args[2], &offset)) {
8761
0
        goto exit;
8762
0
    }
8763
0
    _return_value = os_pwrite_impl(module, fd, &buffer, offset);
8764
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8765
0
        goto exit;
8766
0
    }
8767
0
    return_value = PyLong_FromSsize_t(_return_value);
8768
8769
0
exit:
8770
    /* Cleanup for buffer */
8771
0
    if (buffer.obj) {
8772
0
       PyBuffer_Release(&buffer);
8773
0
    }
8774
8775
0
    return return_value;
8776
0
}
8777
8778
#endif /* defined(HAVE_PWRITE) */
8779
8780
#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
8781
8782
PyDoc_STRVAR(os_pwritev__doc__,
8783
"pwritev($module, fd, buffers, offset, flags=0, /)\n"
8784
"--\n"
8785
"\n"
8786
"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
8787
"\n"
8788
"Combines the functionality of writev() and pwrite(). All buffers must be\n"
8789
"a sequence of bytes-like objects.  Buffers are processed in array order.\n"
8790
"Entire contents of first buffer is written before proceeding to second,\n"
8791
"and so on. The operating system may set a limit (sysconf() value\n"
8792
"SC_IOV_MAX) on the number of buffers that can be used.\n"
8793
"This function writes the contents of each object to the file descriptor\n"
8794
"and returns the total number of bytes written.\n"
8795
"\n"
8796
"The flags argument contains a bitwise OR of zero or more of the\n"
8797
"following flags:\n"
8798
"\n"
8799
"- RWF_DSYNC\n"
8800
"- RWF_SYNC\n"
8801
"- RWF_APPEND\n"
8802
"- RWF_DONTCACHE\n"
8803
"- RWF_ATOMIC\n"
8804
"\n"
8805
"Using non-zero flags requires Linux 4.7 or newer.");
8806
8807
#define OS_PWRITEV_METHODDEF    \
8808
    {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__},
8809
8810
static Py_ssize_t
8811
os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
8812
                int flags);
8813
8814
static PyObject *
8815
os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8816
0
{
8817
0
    PyObject *return_value = NULL;
8818
0
    int fd;
8819
0
    PyObject *buffers;
8820
0
    Py_off_t offset;
8821
0
    int flags = 0;
8822
0
    Py_ssize_t _return_value;
8823
8824
0
    if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
8825
0
        goto exit;
8826
0
    }
8827
0
    fd = PyLong_AsInt(args[0]);
8828
0
    if (fd == -1 && PyErr_Occurred()) {
8829
0
        goto exit;
8830
0
    }
8831
0
    buffers = args[1];
8832
0
    if (!Py_off_t_converter(args[2], &offset)) {
8833
0
        goto exit;
8834
0
    }
8835
0
    if (nargs < 4) {
8836
0
        goto skip_optional;
8837
0
    }
8838
0
    flags = PyLong_AsInt(args[3]);
8839
0
    if (flags == -1 && PyErr_Occurred()) {
8840
0
        goto exit;
8841
0
    }
8842
0
skip_optional:
8843
0
    _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
8844
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8845
0
        goto exit;
8846
0
    }
8847
0
    return_value = PyLong_FromSsize_t(_return_value);
8848
8849
0
exit:
8850
0
    return return_value;
8851
0
}
8852
8853
#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
8854
8855
#if defined(HAVE_COPY_FILE_RANGE)
8856
8857
PyDoc_STRVAR(os_copy_file_range__doc__,
8858
"copy_file_range($module, /, src, dst, count, offset_src=None,\n"
8859
"                offset_dst=None)\n"
8860
"--\n"
8861
"\n"
8862
"Copy count bytes from one file descriptor to another.\n"
8863
"\n"
8864
"  src\n"
8865
"    Source file descriptor.\n"
8866
"  dst\n"
8867
"    Destination file descriptor.\n"
8868
"  count\n"
8869
"    Number of bytes to copy.\n"
8870
"  offset_src\n"
8871
"    Starting offset in src.\n"
8872
"  offset_dst\n"
8873
"    Starting offset in dst.\n"
8874
"\n"
8875
"If offset_src is None, then src is read from the current position;\n"
8876
"respectively for offset_dst.");
8877
8878
#define OS_COPY_FILE_RANGE_METHODDEF    \
8879
    {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__},
8880
8881
static PyObject *
8882
os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count,
8883
                        PyObject *offset_src, PyObject *offset_dst);
8884
8885
static PyObject *
8886
os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8887
0
{
8888
0
    PyObject *return_value = NULL;
8889
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8890
8891
0
    #define NUM_KEYWORDS 5
8892
0
    static struct {
8893
0
        PyGC_Head _this_is_not_used;
8894
0
        PyObject_VAR_HEAD
8895
0
        Py_hash_t ob_hash;
8896
0
        PyObject *ob_item[NUM_KEYWORDS];
8897
0
    } _kwtuple = {
8898
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8899
0
        .ob_hash = -1,
8900
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), },
8901
0
    };
8902
0
    #undef NUM_KEYWORDS
8903
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8904
8905
    #else  // !Py_BUILD_CORE
8906
    #  define KWTUPLE NULL
8907
    #endif  // !Py_BUILD_CORE
8908
8909
0
    static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL};
8910
0
    static _PyArg_Parser _parser = {
8911
0
        .keywords = _keywords,
8912
0
        .fname = "copy_file_range",
8913
0
        .kwtuple = KWTUPLE,
8914
0
    };
8915
0
    #undef KWTUPLE
8916
0
    PyObject *argsbuf[5];
8917
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
8918
0
    int src;
8919
0
    int dst;
8920
0
    Py_ssize_t count;
8921
0
    PyObject *offset_src = Py_None;
8922
0
    PyObject *offset_dst = Py_None;
8923
8924
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8925
0
            /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8926
0
    if (!args) {
8927
0
        goto exit;
8928
0
    }
8929
0
    src = PyLong_AsInt(args[0]);
8930
0
    if (src == -1 && PyErr_Occurred()) {
8931
0
        goto exit;
8932
0
    }
8933
0
    dst = PyLong_AsInt(args[1]);
8934
0
    if (dst == -1 && PyErr_Occurred()) {
8935
0
        goto exit;
8936
0
    }
8937
0
    {
8938
0
        Py_ssize_t ival = -1;
8939
0
        PyObject *iobj = _PyNumber_Index(args[2]);
8940
0
        if (iobj != NULL) {
8941
0
            ival = PyLong_AsSsize_t(iobj);
8942
0
            Py_DECREF(iobj);
8943
0
        }
8944
0
        if (ival == -1 && PyErr_Occurred()) {
8945
0
            goto exit;
8946
0
        }
8947
0
        count = ival;
8948
0
        if (count < 0) {
8949
0
            PyErr_SetString(PyExc_ValueError,
8950
0
                            "count cannot be negative");
8951
0
            goto exit;
8952
0
        }
8953
0
    }
8954
0
    if (!noptargs) {
8955
0
        goto skip_optional_pos;
8956
0
    }
8957
0
    if (args[3]) {
8958
0
        offset_src = args[3];
8959
0
        if (!--noptargs) {
8960
0
            goto skip_optional_pos;
8961
0
        }
8962
0
    }
8963
0
    offset_dst = args[4];
8964
0
skip_optional_pos:
8965
0
    return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst);
8966
8967
0
exit:
8968
0
    return return_value;
8969
0
}
8970
8971
#endif /* defined(HAVE_COPY_FILE_RANGE) */
8972
8973
#if ((defined(HAVE_SPLICE) && !defined(_AIX)))
8974
8975
PyDoc_STRVAR(os_splice__doc__,
8976
"splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n"
8977
"       flags=0)\n"
8978
"--\n"
8979
"\n"
8980
"Transfer count bytes from one pipe to a descriptor or vice versa.\n"
8981
"\n"
8982
"  src\n"
8983
"    Source file descriptor.\n"
8984
"  dst\n"
8985
"    Destination file descriptor.\n"
8986
"  count\n"
8987
"    Number of bytes to copy.\n"
8988
"  offset_src\n"
8989
"    Starting offset in src.\n"
8990
"  offset_dst\n"
8991
"    Starting offset in dst.\n"
8992
"  flags\n"
8993
"    Flags to modify the semantics of the call.\n"
8994
"\n"
8995
"If offset_src is None, then src is read from the current position;\n"
8996
"respectively for offset_dst. The offset associated to the file\n"
8997
"descriptor that refers to a pipe must be None.");
8998
8999
#define OS_SPLICE_METHODDEF    \
9000
    {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__},
9001
9002
static PyObject *
9003
os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
9004
               PyObject *offset_src, PyObject *offset_dst,
9005
               unsigned int flags);
9006
9007
static PyObject *
9008
os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9009
0
{
9010
0
    PyObject *return_value = NULL;
9011
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9012
9013
0
    #define NUM_KEYWORDS 6
9014
0
    static struct {
9015
0
        PyGC_Head _this_is_not_used;
9016
0
        PyObject_VAR_HEAD
9017
0
        Py_hash_t ob_hash;
9018
0
        PyObject *ob_item[NUM_KEYWORDS];
9019
0
    } _kwtuple = {
9020
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9021
0
        .ob_hash = -1,
9022
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), },
9023
0
    };
9024
0
    #undef NUM_KEYWORDS
9025
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9026
9027
    #else  // !Py_BUILD_CORE
9028
    #  define KWTUPLE NULL
9029
    #endif  // !Py_BUILD_CORE
9030
9031
0
    static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL};
9032
0
    static _PyArg_Parser _parser = {
9033
0
        .keywords = _keywords,
9034
0
        .fname = "splice",
9035
0
        .kwtuple = KWTUPLE,
9036
0
    };
9037
0
    #undef KWTUPLE
9038
0
    PyObject *argsbuf[6];
9039
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
9040
0
    int src;
9041
0
    int dst;
9042
0
    Py_ssize_t count;
9043
0
    PyObject *offset_src = Py_None;
9044
0
    PyObject *offset_dst = Py_None;
9045
0
    unsigned int flags = 0;
9046
9047
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9048
0
            /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9049
0
    if (!args) {
9050
0
        goto exit;
9051
0
    }
9052
0
    src = PyLong_AsInt(args[0]);
9053
0
    if (src == -1 && PyErr_Occurred()) {
9054
0
        goto exit;
9055
0
    }
9056
0
    dst = PyLong_AsInt(args[1]);
9057
0
    if (dst == -1 && PyErr_Occurred()) {
9058
0
        goto exit;
9059
0
    }
9060
0
    {
9061
0
        Py_ssize_t ival = -1;
9062
0
        PyObject *iobj = _PyNumber_Index(args[2]);
9063
0
        if (iobj != NULL) {
9064
0
            ival = PyLong_AsSsize_t(iobj);
9065
0
            Py_DECREF(iobj);
9066
0
        }
9067
0
        if (ival == -1 && PyErr_Occurred()) {
9068
0
            goto exit;
9069
0
        }
9070
0
        count = ival;
9071
0
        if (count < 0) {
9072
0
            PyErr_SetString(PyExc_ValueError,
9073
0
                            "count cannot be negative");
9074
0
            goto exit;
9075
0
        }
9076
0
    }
9077
0
    if (!noptargs) {
9078
0
        goto skip_optional_pos;
9079
0
    }
9080
0
    if (args[3]) {
9081
0
        offset_src = args[3];
9082
0
        if (!--noptargs) {
9083
0
            goto skip_optional_pos;
9084
0
        }
9085
0
    }
9086
0
    if (args[4]) {
9087
0
        offset_dst = args[4];
9088
0
        if (!--noptargs) {
9089
0
            goto skip_optional_pos;
9090
0
        }
9091
0
    }
9092
0
    if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) {
9093
0
        goto exit;
9094
0
    }
9095
0
skip_optional_pos:
9096
0
    return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags);
9097
9098
0
exit:
9099
0
    return return_value;
9100
0
}
9101
9102
#endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */
9103
9104
#if defined(HAVE_MKFIFO)
9105
9106
PyDoc_STRVAR(os_mkfifo__doc__,
9107
"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
9108
"--\n"
9109
"\n"
9110
"Create a \"fifo\" (a POSIX named pipe).\n"
9111
"\n"
9112
"If dir_fd is not None, it should be a file descriptor open to\n"
9113
"a directory, and path should be relative; path will then be relative to\n"
9114
"that directory.\n"
9115
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
9116
"using it will raise a NotImplementedError.");
9117
9118
#define OS_MKFIFO_METHODDEF    \
9119
    {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
9120
9121
static PyObject *
9122
os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
9123
9124
static PyObject *
9125
os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9126
0
{
9127
0
    PyObject *return_value = NULL;
9128
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9129
9130
0
    #define NUM_KEYWORDS 3
9131
0
    static struct {
9132
0
        PyGC_Head _this_is_not_used;
9133
0
        PyObject_VAR_HEAD
9134
0
        Py_hash_t ob_hash;
9135
0
        PyObject *ob_item[NUM_KEYWORDS];
9136
0
    } _kwtuple = {
9137
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9138
0
        .ob_hash = -1,
9139
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
9140
0
    };
9141
0
    #undef NUM_KEYWORDS
9142
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9143
9144
    #else  // !Py_BUILD_CORE
9145
    #  define KWTUPLE NULL
9146
    #endif  // !Py_BUILD_CORE
9147
9148
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
9149
0
    static _PyArg_Parser _parser = {
9150
0
        .keywords = _keywords,
9151
0
        .fname = "mkfifo",
9152
0
        .kwtuple = KWTUPLE,
9153
0
    };
9154
0
    #undef KWTUPLE
9155
0
    PyObject *argsbuf[3];
9156
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
9157
0
    path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0);
9158
0
    int mode = 438;
9159
0
    int dir_fd = DEFAULT_DIR_FD;
9160
9161
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9162
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9163
0
    if (!args) {
9164
0
        goto exit;
9165
0
    }
9166
0
    if (!path_converter(args[0], &path)) {
9167
0
        goto exit;
9168
0
    }
9169
0
    if (!noptargs) {
9170
0
        goto skip_optional_pos;
9171
0
    }
9172
0
    if (args[1]) {
9173
0
        mode = PyLong_AsInt(args[1]);
9174
0
        if (mode == -1 && PyErr_Occurred()) {
9175
0
            goto exit;
9176
0
        }
9177
0
        if (!--noptargs) {
9178
0
            goto skip_optional_pos;
9179
0
        }
9180
0
    }
9181
0
skip_optional_pos:
9182
0
    if (!noptargs) {
9183
0
        goto skip_optional_kwonly;
9184
0
    }
9185
0
    if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
9186
0
        goto exit;
9187
0
    }
9188
0
skip_optional_kwonly:
9189
0
    return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
9190
9191
0
exit:
9192
    /* Cleanup for path */
9193
0
    path_cleanup(&path);
9194
9195
0
    return return_value;
9196
0
}
9197
9198
#endif /* defined(HAVE_MKFIFO) */
9199
9200
#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
9201
9202
PyDoc_STRVAR(os_mknod__doc__,
9203
"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
9204
"--\n"
9205
"\n"
9206
"Create a node in the file system.\n"
9207
"\n"
9208
"Create a node in the file system (file, device special file or named\n"
9209
"pipe) at path.  mode specifies both the permissions to use and the\n"
9210
"type of node to be created, being combined (bitwise OR) with one of\n"
9211
"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO.  If S_IFCHR or S_IFBLK is set\n"
9212
"on mode, device defines the newly created device special file (probably\n"
9213
"using os.makedev()).  Otherwise device is ignored.\n"
9214
"\n"
9215
"If dir_fd is not None, it should be a file descriptor open to\n"
9216
"a directory, and path should be relative; path will then be relative\n"
9217
"to that directory.\n"
9218
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
9219
"using it will raise a NotImplementedError.");
9220
9221
#define OS_MKNOD_METHODDEF    \
9222
    {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
9223
9224
static PyObject *
9225
os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
9226
              int dir_fd);
9227
9228
static PyObject *
9229
os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9230
0
{
9231
0
    PyObject *return_value = NULL;
9232
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9233
9234
0
    #define NUM_KEYWORDS 4
9235
0
    static struct {
9236
0
        PyGC_Head _this_is_not_used;
9237
0
        PyObject_VAR_HEAD
9238
0
        Py_hash_t ob_hash;
9239
0
        PyObject *ob_item[NUM_KEYWORDS];
9240
0
    } _kwtuple = {
9241
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9242
0
        .ob_hash = -1,
9243
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), },
9244
0
    };
9245
0
    #undef NUM_KEYWORDS
9246
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9247
9248
    #else  // !Py_BUILD_CORE
9249
    #  define KWTUPLE NULL
9250
    #endif  // !Py_BUILD_CORE
9251
9252
0
    static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
9253
0
    static _PyArg_Parser _parser = {
9254
0
        .keywords = _keywords,
9255
0
        .fname = "mknod",
9256
0
        .kwtuple = KWTUPLE,
9257
0
    };
9258
0
    #undef KWTUPLE
9259
0
    PyObject *argsbuf[4];
9260
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
9261
0
    path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0);
9262
0
    int mode = 384;
9263
0
    dev_t device = 0;
9264
0
    int dir_fd = DEFAULT_DIR_FD;
9265
9266
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9267
0
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9268
0
    if (!args) {
9269
0
        goto exit;
9270
0
    }
9271
0
    if (!path_converter(args[0], &path)) {
9272
0
        goto exit;
9273
0
    }
9274
0
    if (!noptargs) {
9275
0
        goto skip_optional_pos;
9276
0
    }
9277
0
    if (args[1]) {
9278
0
        mode = PyLong_AsInt(args[1]);
9279
0
        if (mode == -1 && PyErr_Occurred()) {
9280
0
            goto exit;
9281
0
        }
9282
0
        if (!--noptargs) {
9283
0
            goto skip_optional_pos;
9284
0
        }
9285
0
    }
9286
0
    if (args[2]) {
9287
0
        if (!_Py_Dev_Converter(args[2], &device)) {
9288
0
            goto exit;
9289
0
        }
9290
0
        if (!--noptargs) {
9291
0
            goto skip_optional_pos;
9292
0
        }
9293
0
    }
9294
0
skip_optional_pos:
9295
0
    if (!noptargs) {
9296
0
        goto skip_optional_kwonly;
9297
0
    }
9298
0
    if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
9299
0
        goto exit;
9300
0
    }
9301
0
skip_optional_kwonly:
9302
0
    return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
9303
9304
0
exit:
9305
    /* Cleanup for path */
9306
0
    path_cleanup(&path);
9307
9308
0
    return return_value;
9309
0
}
9310
9311
#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
9312
9313
#if defined(HAVE_DEVICE_MACROS)
9314
9315
PyDoc_STRVAR(os_major__doc__,
9316
"major($module, device, /)\n"
9317
"--\n"
9318
"\n"
9319
"Extracts a device major number from a raw device number.");
9320
9321
#define OS_MAJOR_METHODDEF    \
9322
    {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
9323
9324
static PyObject *
9325
os_major_impl(PyObject *module, dev_t device);
9326
9327
static PyObject *
9328
os_major(PyObject *module, PyObject *arg)
9329
0
{
9330
0
    PyObject *return_value = NULL;
9331
0
    dev_t device;
9332
9333
0
    if (!_Py_Dev_Converter(arg, &device)) {
9334
0
        goto exit;
9335
0
    }
9336
0
    return_value = os_major_impl(module, device);
9337
9338
0
exit:
9339
0
    return return_value;
9340
0
}
9341
9342
#endif /* defined(HAVE_DEVICE_MACROS) */
9343
9344
#if defined(HAVE_DEVICE_MACROS)
9345
9346
PyDoc_STRVAR(os_minor__doc__,
9347
"minor($module, device, /)\n"
9348
"--\n"
9349
"\n"
9350
"Extracts a device minor number from a raw device number.");
9351
9352
#define OS_MINOR_METHODDEF    \
9353
    {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
9354
9355
static PyObject *
9356
os_minor_impl(PyObject *module, dev_t device);
9357
9358
static PyObject *
9359
os_minor(PyObject *module, PyObject *arg)
9360
0
{
9361
0
    PyObject *return_value = NULL;
9362
0
    dev_t device;
9363
9364
0
    if (!_Py_Dev_Converter(arg, &device)) {
9365
0
        goto exit;
9366
0
    }
9367
0
    return_value = os_minor_impl(module, device);
9368
9369
0
exit:
9370
0
    return return_value;
9371
0
}
9372
9373
#endif /* defined(HAVE_DEVICE_MACROS) */
9374
9375
#if defined(HAVE_DEVICE_MACROS)
9376
9377
PyDoc_STRVAR(os_makedev__doc__,
9378
"makedev($module, major, minor, /)\n"
9379
"--\n"
9380
"\n"
9381
"Composes a raw device number from the major and minor device numbers.");
9382
9383
#define OS_MAKEDEV_METHODDEF    \
9384
    {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__},
9385
9386
static dev_t
9387
os_makedev_impl(PyObject *module, dev_t major, dev_t minor);
9388
9389
static PyObject *
9390
os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9391
0
{
9392
0
    PyObject *return_value = NULL;
9393
0
    dev_t major;
9394
0
    dev_t minor;
9395
0
    dev_t _return_value;
9396
9397
0
    if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
9398
0
        goto exit;
9399
0
    }
9400
0
    if (!_Py_Dev_Converter(args[0], &major)) {
9401
0
        goto exit;
9402
0
    }
9403
0
    if (!_Py_Dev_Converter(args[1], &minor)) {
9404
0
        goto exit;
9405
0
    }
9406
0
    _return_value = os_makedev_impl(module, major, minor);
9407
0
    if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
9408
0
        goto exit;
9409
0
    }
9410
0
    return_value = _PyLong_FromDev(_return_value);
9411
9412
0
exit:
9413
0
    return return_value;
9414
0
}
9415
9416
#endif /* defined(HAVE_DEVICE_MACROS) */
9417
9418
#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
9419
9420
PyDoc_STRVAR(os_ftruncate__doc__,
9421
"ftruncate($module, fd, length, /)\n"
9422
"--\n"
9423
"\n"
9424
"Truncate a file, specified by file descriptor, to a specific length.");
9425
9426
#define OS_FTRUNCATE_METHODDEF    \
9427
    {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__},
9428
9429
static PyObject *
9430
os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
9431
9432
static PyObject *
9433
os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9434
0
{
9435
0
    PyObject *return_value = NULL;
9436
0
    int fd;
9437
0
    Py_off_t length;
9438
9439
0
    if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
9440
0
        goto exit;
9441
0
    }
9442
0
    fd = PyLong_AsInt(args[0]);
9443
0
    if (fd == -1 && PyErr_Occurred()) {
9444
0
        goto exit;
9445
0
    }
9446
0
    if (!Py_off_t_converter(args[1], &length)) {
9447
0
        goto exit;
9448
0
    }
9449
0
    return_value = os_ftruncate_impl(module, fd, length);
9450
9451
0
exit:
9452
0
    return return_value;
9453
0
}
9454
9455
#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
9456
9457
#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
9458
9459
PyDoc_STRVAR(os_truncate__doc__,
9460
"truncate($module, /, path, length)\n"
9461
"--\n"
9462
"\n"
9463
"Truncate a file, specified by path, to a specific length.\n"
9464
"\n"
9465
"On some platforms, path may also be specified as an open file\n"
9466
"descriptor.  If this functionality is unavailable, using it raises\n"
9467
"an exception.");
9468
9469
#define OS_TRUNCATE_METHODDEF    \
9470
    {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
9471
9472
static PyObject *
9473
os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
9474
9475
static PyObject *
9476
os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9477
0
{
9478
0
    PyObject *return_value = NULL;
9479
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9480
9481
0
    #define NUM_KEYWORDS 2
9482
0
    static struct {
9483
0
        PyGC_Head _this_is_not_used;
9484
0
        PyObject_VAR_HEAD
9485
0
        Py_hash_t ob_hash;
9486
0
        PyObject *ob_item[NUM_KEYWORDS];
9487
0
    } _kwtuple = {
9488
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9489
0
        .ob_hash = -1,
9490
0
        .ob_item = { &_Py_ID(path), &_Py_ID(length), },
9491
0
    };
9492
0
    #undef NUM_KEYWORDS
9493
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9494
9495
    #else  // !Py_BUILD_CORE
9496
    #  define KWTUPLE NULL
9497
    #endif  // !Py_BUILD_CORE
9498
9499
0
    static const char * const _keywords[] = {"path", "length", NULL};
9500
0
    static _PyArg_Parser _parser = {
9501
0
        .keywords = _keywords,
9502
0
        .fname = "truncate",
9503
0
        .kwtuple = KWTUPLE,
9504
0
    };
9505
0
    #undef KWTUPLE
9506
0
    PyObject *argsbuf[2];
9507
0
    path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE);
9508
0
    Py_off_t length;
9509
9510
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9511
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9512
0
    if (!args) {
9513
0
        goto exit;
9514
0
    }
9515
0
    if (!path_converter(args[0], &path)) {
9516
0
        goto exit;
9517
0
    }
9518
0
    if (!Py_off_t_converter(args[1], &length)) {
9519
0
        goto exit;
9520
0
    }
9521
0
    return_value = os_truncate_impl(module, &path, length);
9522
9523
0
exit:
9524
    /* Cleanup for path */
9525
0
    path_cleanup(&path);
9526
9527
0
    return return_value;
9528
0
}
9529
9530
#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
9531
9532
#if (defined(HAVE_POSIX_FALLOCATE) && !defined(__wasi__))
9533
9534
PyDoc_STRVAR(os_posix_fallocate__doc__,
9535
"posix_fallocate($module, fd, offset, length, /)\n"
9536
"--\n"
9537
"\n"
9538
"Ensure a file has allocated at least a particular number of bytes on disk.\n"
9539
"\n"
9540
"Ensure that the file specified by fd encompasses a range of bytes\n"
9541
"starting at offset bytes from the beginning and continuing for length\n"
9542
"bytes.");
9543
9544
#define OS_POSIX_FALLOCATE_METHODDEF    \
9545
    {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__},
9546
9547
static PyObject *
9548
os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
9549
                        Py_off_t length);
9550
9551
static PyObject *
9552
os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9553
0
{
9554
0
    PyObject *return_value = NULL;
9555
0
    int fd;
9556
0
    Py_off_t offset;
9557
0
    Py_off_t length;
9558
9559
0
    if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
9560
0
        goto exit;
9561
0
    }
9562
0
    fd = PyLong_AsInt(args[0]);
9563
0
    if (fd == -1 && PyErr_Occurred()) {
9564
0
        goto exit;
9565
0
    }
9566
0
    if (!Py_off_t_converter(args[1], &offset)) {
9567
0
        goto exit;
9568
0
    }
9569
0
    if (!Py_off_t_converter(args[2], &length)) {
9570
0
        goto exit;
9571
0
    }
9572
0
    return_value = os_posix_fallocate_impl(module, fd, offset, length);
9573
9574
0
exit:
9575
0
    return return_value;
9576
0
}
9577
9578
#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(__wasi__)) */
9579
9580
#if defined(HAVE_POSIX_FADVISE)
9581
9582
PyDoc_STRVAR(os_posix_fadvise__doc__,
9583
"posix_fadvise($module, fd, offset, length, advice, /)\n"
9584
"--\n"
9585
"\n"
9586
"Announce an intention to access data in a specific pattern.\n"
9587
"\n"
9588
"Announce an intention to access data in a specific pattern, thus\n"
9589
"allowing the kernel to make optimizations.\n"
9590
"The advice applies to the region of the file specified by fd starting at\n"
9591
"offset and continuing for length bytes.\n"
9592
"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
9593
"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
9594
"POSIX_FADV_DONTNEED.");
9595
9596
#define OS_POSIX_FADVISE_METHODDEF    \
9597
    {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__},
9598
9599
static PyObject *
9600
os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
9601
                      Py_off_t length, int advice);
9602
9603
static PyObject *
9604
os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9605
0
{
9606
0
    PyObject *return_value = NULL;
9607
0
    int fd;
9608
0
    Py_off_t offset;
9609
0
    Py_off_t length;
9610
0
    int advice;
9611
9612
0
    if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
9613
0
        goto exit;
9614
0
    }
9615
0
    fd = PyLong_AsInt(args[0]);
9616
0
    if (fd == -1 && PyErr_Occurred()) {
9617
0
        goto exit;
9618
0
    }
9619
0
    if (!Py_off_t_converter(args[1], &offset)) {
9620
0
        goto exit;
9621
0
    }
9622
0
    if (!Py_off_t_converter(args[2], &length)) {
9623
0
        goto exit;
9624
0
    }
9625
0
    advice = PyLong_AsInt(args[3]);
9626
0
    if (advice == -1 && PyErr_Occurred()) {
9627
0
        goto exit;
9628
0
    }
9629
0
    return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
9630
9631
0
exit:
9632
0
    return return_value;
9633
0
}
9634
9635
#endif /* defined(HAVE_POSIX_FADVISE) */
9636
9637
#if defined(MS_WINDOWS)
9638
9639
PyDoc_STRVAR(os_putenv__doc__,
9640
"putenv($module, name, value, /)\n"
9641
"--\n"
9642
"\n"
9643
"Change or add an environment variable.");
9644
9645
#define OS_PUTENV_METHODDEF    \
9646
    {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9647
9648
static PyObject *
9649
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9650
9651
static PyObject *
9652
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9653
{
9654
    PyObject *return_value = NULL;
9655
    PyObject *name;
9656
    PyObject *value;
9657
9658
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9659
        goto exit;
9660
    }
9661
    if (!PyUnicode_Check(args[0])) {
9662
        _PyArg_BadArgument("putenv", "argument 1", "str", args[0]);
9663
        goto exit;
9664
    }
9665
    name = args[0];
9666
    if (!PyUnicode_Check(args[1])) {
9667
        _PyArg_BadArgument("putenv", "argument 2", "str", args[1]);
9668
        goto exit;
9669
    }
9670
    value = args[1];
9671
    return_value = os_putenv_impl(module, name, value);
9672
9673
exit:
9674
    return return_value;
9675
}
9676
9677
#endif /* defined(MS_WINDOWS) */
9678
9679
#if !defined(MS_WINDOWS)
9680
9681
PyDoc_STRVAR(os_putenv__doc__,
9682
"putenv($module, name, value, /)\n"
9683
"--\n"
9684
"\n"
9685
"Change or add an environment variable.");
9686
9687
#define OS_PUTENV_METHODDEF    \
9688
    {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9689
9690
static PyObject *
9691
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9692
9693
static PyObject *
9694
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9695
0
{
9696
0
    PyObject *return_value = NULL;
9697
0
    PyObject *name = NULL;
9698
0
    PyObject *value = NULL;
9699
9700
0
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9701
0
        goto exit;
9702
0
    }
9703
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
9704
0
        goto exit;
9705
0
    }
9706
0
    if (!PyUnicode_FSConverter(args[1], &value)) {
9707
0
        goto exit;
9708
0
    }
9709
0
    return_value = os_putenv_impl(module, name, value);
9710
9711
0
exit:
9712
    /* Cleanup for name */
9713
0
    Py_XDECREF(name);
9714
    /* Cleanup for value */
9715
0
    Py_XDECREF(value);
9716
9717
0
    return return_value;
9718
0
}
9719
9720
#endif /* !defined(MS_WINDOWS) */
9721
9722
#if defined(MS_WINDOWS)
9723
9724
PyDoc_STRVAR(os_unsetenv__doc__,
9725
"unsetenv($module, name, /)\n"
9726
"--\n"
9727
"\n"
9728
"Delete an environment variable.");
9729
9730
#define OS_UNSETENV_METHODDEF    \
9731
    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9732
9733
static PyObject *
9734
os_unsetenv_impl(PyObject *module, PyObject *name);
9735
9736
static PyObject *
9737
os_unsetenv(PyObject *module, PyObject *arg)
9738
{
9739
    PyObject *return_value = NULL;
9740
    PyObject *name;
9741
9742
    if (!PyUnicode_Check(arg)) {
9743
        _PyArg_BadArgument("unsetenv", "argument", "str", arg);
9744
        goto exit;
9745
    }
9746
    name = arg;
9747
    return_value = os_unsetenv_impl(module, name);
9748
9749
exit:
9750
    return return_value;
9751
}
9752
9753
#endif /* defined(MS_WINDOWS) */
9754
9755
#if !defined(MS_WINDOWS)
9756
9757
PyDoc_STRVAR(os_unsetenv__doc__,
9758
"unsetenv($module, name, /)\n"
9759
"--\n"
9760
"\n"
9761
"Delete an environment variable.");
9762
9763
#define OS_UNSETENV_METHODDEF    \
9764
    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9765
9766
static PyObject *
9767
os_unsetenv_impl(PyObject *module, PyObject *name);
9768
9769
static PyObject *
9770
os_unsetenv(PyObject *module, PyObject *arg)
9771
0
{
9772
0
    PyObject *return_value = NULL;
9773
0
    PyObject *name = NULL;
9774
9775
0
    if (!PyUnicode_FSConverter(arg, &name)) {
9776
0
        goto exit;
9777
0
    }
9778
0
    return_value = os_unsetenv_impl(module, name);
9779
9780
0
exit:
9781
    /* Cleanup for name */
9782
0
    Py_XDECREF(name);
9783
9784
0
    return return_value;
9785
0
}
9786
9787
#endif /* !defined(MS_WINDOWS) */
9788
9789
#if defined(HAVE_CLEARENV)
9790
9791
PyDoc_STRVAR(os__clearenv__doc__,
9792
"_clearenv($module, /)\n"
9793
"--\n"
9794
"\n");
9795
9796
#define OS__CLEARENV_METHODDEF    \
9797
    {"_clearenv", (PyCFunction)os__clearenv, METH_NOARGS, os__clearenv__doc__},
9798
9799
static PyObject *
9800
os__clearenv_impl(PyObject *module);
9801
9802
static PyObject *
9803
os__clearenv(PyObject *module, PyObject *Py_UNUSED(ignored))
9804
0
{
9805
0
    return os__clearenv_impl(module);
9806
0
}
9807
9808
#endif /* defined(HAVE_CLEARENV) */
9809
9810
PyDoc_STRVAR(os_strerror__doc__,
9811
"strerror($module, code, /)\n"
9812
"--\n"
9813
"\n"
9814
"Translate an error code to a message string.");
9815
9816
#define OS_STRERROR_METHODDEF    \
9817
    {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
9818
9819
static PyObject *
9820
os_strerror_impl(PyObject *module, int code);
9821
9822
static PyObject *
9823
os_strerror(PyObject *module, PyObject *arg)
9824
0
{
9825
0
    PyObject *return_value = NULL;
9826
0
    int code;
9827
9828
0
    code = PyLong_AsInt(arg);
9829
0
    if (code == -1 && PyErr_Occurred()) {
9830
0
        goto exit;
9831
0
    }
9832
0
    return_value = os_strerror_impl(module, code);
9833
9834
0
exit:
9835
0
    return return_value;
9836
0
}
9837
9838
#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
9839
9840
PyDoc_STRVAR(os_WCOREDUMP__doc__,
9841
"WCOREDUMP($module, status, /)\n"
9842
"--\n"
9843
"\n"
9844
"Return True if the process returning status was dumped to a core file.");
9845
9846
#define OS_WCOREDUMP_METHODDEF    \
9847
    {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
9848
9849
static int
9850
os_WCOREDUMP_impl(PyObject *module, int status);
9851
9852
static PyObject *
9853
os_WCOREDUMP(PyObject *module, PyObject *arg)
9854
0
{
9855
0
    PyObject *return_value = NULL;
9856
0
    int status;
9857
0
    int _return_value;
9858
9859
0
    status = PyLong_AsInt(arg);
9860
0
    if (status == -1 && PyErr_Occurred()) {
9861
0
        goto exit;
9862
0
    }
9863
0
    _return_value = os_WCOREDUMP_impl(module, status);
9864
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9865
0
        goto exit;
9866
0
    }
9867
0
    return_value = PyBool_FromLong((long)_return_value);
9868
9869
0
exit:
9870
0
    return return_value;
9871
0
}
9872
9873
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
9874
9875
#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
9876
9877
PyDoc_STRVAR(os_WIFCONTINUED__doc__,
9878
"WIFCONTINUED($module, /, status)\n"
9879
"--\n"
9880
"\n"
9881
"Return True if a particular process was continued from a job control stop.\n"
9882
"\n"
9883
"Return True if the process returning status was continued from a\n"
9884
"job control stop.");
9885
9886
#define OS_WIFCONTINUED_METHODDEF    \
9887
    {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
9888
9889
static int
9890
os_WIFCONTINUED_impl(PyObject *module, int status);
9891
9892
static PyObject *
9893
os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9894
0
{
9895
0
    PyObject *return_value = NULL;
9896
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9897
9898
0
    #define NUM_KEYWORDS 1
9899
0
    static struct {
9900
0
        PyGC_Head _this_is_not_used;
9901
0
        PyObject_VAR_HEAD
9902
0
        Py_hash_t ob_hash;
9903
0
        PyObject *ob_item[NUM_KEYWORDS];
9904
0
    } _kwtuple = {
9905
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9906
0
        .ob_hash = -1,
9907
0
        .ob_item = { &_Py_ID(status), },
9908
0
    };
9909
0
    #undef NUM_KEYWORDS
9910
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9911
9912
    #else  // !Py_BUILD_CORE
9913
    #  define KWTUPLE NULL
9914
    #endif  // !Py_BUILD_CORE
9915
9916
0
    static const char * const _keywords[] = {"status", NULL};
9917
0
    static _PyArg_Parser _parser = {
9918
0
        .keywords = _keywords,
9919
0
        .fname = "WIFCONTINUED",
9920
0
        .kwtuple = KWTUPLE,
9921
0
    };
9922
0
    #undef KWTUPLE
9923
0
    PyObject *argsbuf[1];
9924
0
    int status;
9925
0
    int _return_value;
9926
9927
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9928
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9929
0
    if (!args) {
9930
0
        goto exit;
9931
0
    }
9932
0
    status = PyLong_AsInt(args[0]);
9933
0
    if (status == -1 && PyErr_Occurred()) {
9934
0
        goto exit;
9935
0
    }
9936
0
    _return_value = os_WIFCONTINUED_impl(module, status);
9937
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9938
0
        goto exit;
9939
0
    }
9940
0
    return_value = PyBool_FromLong((long)_return_value);
9941
9942
0
exit:
9943
0
    return return_value;
9944
0
}
9945
9946
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
9947
9948
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
9949
9950
PyDoc_STRVAR(os_WIFSTOPPED__doc__,
9951
"WIFSTOPPED($module, /, status)\n"
9952
"--\n"
9953
"\n"
9954
"Return True if the process returning status was stopped.");
9955
9956
#define OS_WIFSTOPPED_METHODDEF    \
9957
    {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
9958
9959
static int
9960
os_WIFSTOPPED_impl(PyObject *module, int status);
9961
9962
static PyObject *
9963
os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9964
0
{
9965
0
    PyObject *return_value = NULL;
9966
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9967
9968
0
    #define NUM_KEYWORDS 1
9969
0
    static struct {
9970
0
        PyGC_Head _this_is_not_used;
9971
0
        PyObject_VAR_HEAD
9972
0
        Py_hash_t ob_hash;
9973
0
        PyObject *ob_item[NUM_KEYWORDS];
9974
0
    } _kwtuple = {
9975
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9976
0
        .ob_hash = -1,
9977
0
        .ob_item = { &_Py_ID(status), },
9978
0
    };
9979
0
    #undef NUM_KEYWORDS
9980
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9981
9982
    #else  // !Py_BUILD_CORE
9983
    #  define KWTUPLE NULL
9984
    #endif  // !Py_BUILD_CORE
9985
9986
0
    static const char * const _keywords[] = {"status", NULL};
9987
0
    static _PyArg_Parser _parser = {
9988
0
        .keywords = _keywords,
9989
0
        .fname = "WIFSTOPPED",
9990
0
        .kwtuple = KWTUPLE,
9991
0
    };
9992
0
    #undef KWTUPLE
9993
0
    PyObject *argsbuf[1];
9994
0
    int status;
9995
0
    int _return_value;
9996
9997
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9998
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9999
0
    if (!args) {
10000
0
        goto exit;
10001
0
    }
10002
0
    status = PyLong_AsInt(args[0]);
10003
0
    if (status == -1 && PyErr_Occurred()) {
10004
0
        goto exit;
10005
0
    }
10006
0
    _return_value = os_WIFSTOPPED_impl(module, status);
10007
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10008
0
        goto exit;
10009
0
    }
10010
0
    return_value = PyBool_FromLong((long)_return_value);
10011
10012
0
exit:
10013
0
    return return_value;
10014
0
}
10015
10016
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
10017
10018
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
10019
10020
PyDoc_STRVAR(os_WIFSIGNALED__doc__,
10021
"WIFSIGNALED($module, /, status)\n"
10022
"--\n"
10023
"\n"
10024
"Return True if the process returning status was terminated by a signal.");
10025
10026
#define OS_WIFSIGNALED_METHODDEF    \
10027
    {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
10028
10029
static int
10030
os_WIFSIGNALED_impl(PyObject *module, int status);
10031
10032
static PyObject *
10033
os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10034
0
{
10035
0
    PyObject *return_value = NULL;
10036
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10037
10038
0
    #define NUM_KEYWORDS 1
10039
0
    static struct {
10040
0
        PyGC_Head _this_is_not_used;
10041
0
        PyObject_VAR_HEAD
10042
0
        Py_hash_t ob_hash;
10043
0
        PyObject *ob_item[NUM_KEYWORDS];
10044
0
    } _kwtuple = {
10045
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10046
0
        .ob_hash = -1,
10047
0
        .ob_item = { &_Py_ID(status), },
10048
0
    };
10049
0
    #undef NUM_KEYWORDS
10050
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10051
10052
    #else  // !Py_BUILD_CORE
10053
    #  define KWTUPLE NULL
10054
    #endif  // !Py_BUILD_CORE
10055
10056
0
    static const char * const _keywords[] = {"status", NULL};
10057
0
    static _PyArg_Parser _parser = {
10058
0
        .keywords = _keywords,
10059
0
        .fname = "WIFSIGNALED",
10060
0
        .kwtuple = KWTUPLE,
10061
0
    };
10062
0
    #undef KWTUPLE
10063
0
    PyObject *argsbuf[1];
10064
0
    int status;
10065
0
    int _return_value;
10066
10067
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10068
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10069
0
    if (!args) {
10070
0
        goto exit;
10071
0
    }
10072
0
    status = PyLong_AsInt(args[0]);
10073
0
    if (status == -1 && PyErr_Occurred()) {
10074
0
        goto exit;
10075
0
    }
10076
0
    _return_value = os_WIFSIGNALED_impl(module, status);
10077
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10078
0
        goto exit;
10079
0
    }
10080
0
    return_value = PyBool_FromLong((long)_return_value);
10081
10082
0
exit:
10083
0
    return return_value;
10084
0
}
10085
10086
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
10087
10088
#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
10089
10090
PyDoc_STRVAR(os_WIFEXITED__doc__,
10091
"WIFEXITED($module, /, status)\n"
10092
"--\n"
10093
"\n"
10094
"Return True if the process returning status exited via the exit() system call.");
10095
10096
#define OS_WIFEXITED_METHODDEF    \
10097
    {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
10098
10099
static int
10100
os_WIFEXITED_impl(PyObject *module, int status);
10101
10102
static PyObject *
10103
os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10104
0
{
10105
0
    PyObject *return_value = NULL;
10106
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10107
10108
0
    #define NUM_KEYWORDS 1
10109
0
    static struct {
10110
0
        PyGC_Head _this_is_not_used;
10111
0
        PyObject_VAR_HEAD
10112
0
        Py_hash_t ob_hash;
10113
0
        PyObject *ob_item[NUM_KEYWORDS];
10114
0
    } _kwtuple = {
10115
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10116
0
        .ob_hash = -1,
10117
0
        .ob_item = { &_Py_ID(status), },
10118
0
    };
10119
0
    #undef NUM_KEYWORDS
10120
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10121
10122
    #else  // !Py_BUILD_CORE
10123
    #  define KWTUPLE NULL
10124
    #endif  // !Py_BUILD_CORE
10125
10126
0
    static const char * const _keywords[] = {"status", NULL};
10127
0
    static _PyArg_Parser _parser = {
10128
0
        .keywords = _keywords,
10129
0
        .fname = "WIFEXITED",
10130
0
        .kwtuple = KWTUPLE,
10131
0
    };
10132
0
    #undef KWTUPLE
10133
0
    PyObject *argsbuf[1];
10134
0
    int status;
10135
0
    int _return_value;
10136
10137
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10138
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10139
0
    if (!args) {
10140
0
        goto exit;
10141
0
    }
10142
0
    status = PyLong_AsInt(args[0]);
10143
0
    if (status == -1 && PyErr_Occurred()) {
10144
0
        goto exit;
10145
0
    }
10146
0
    _return_value = os_WIFEXITED_impl(module, status);
10147
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10148
0
        goto exit;
10149
0
    }
10150
0
    return_value = PyBool_FromLong((long)_return_value);
10151
10152
0
exit:
10153
0
    return return_value;
10154
0
}
10155
10156
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
10157
10158
#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
10159
10160
PyDoc_STRVAR(os_WEXITSTATUS__doc__,
10161
"WEXITSTATUS($module, /, status)\n"
10162
"--\n"
10163
"\n"
10164
"Return the process return code from status.");
10165
10166
#define OS_WEXITSTATUS_METHODDEF    \
10167
    {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
10168
10169
static int
10170
os_WEXITSTATUS_impl(PyObject *module, int status);
10171
10172
static PyObject *
10173
os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10174
0
{
10175
0
    PyObject *return_value = NULL;
10176
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10177
10178
0
    #define NUM_KEYWORDS 1
10179
0
    static struct {
10180
0
        PyGC_Head _this_is_not_used;
10181
0
        PyObject_VAR_HEAD
10182
0
        Py_hash_t ob_hash;
10183
0
        PyObject *ob_item[NUM_KEYWORDS];
10184
0
    } _kwtuple = {
10185
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10186
0
        .ob_hash = -1,
10187
0
        .ob_item = { &_Py_ID(status), },
10188
0
    };
10189
0
    #undef NUM_KEYWORDS
10190
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10191
10192
    #else  // !Py_BUILD_CORE
10193
    #  define KWTUPLE NULL
10194
    #endif  // !Py_BUILD_CORE
10195
10196
0
    static const char * const _keywords[] = {"status", NULL};
10197
0
    static _PyArg_Parser _parser = {
10198
0
        .keywords = _keywords,
10199
0
        .fname = "WEXITSTATUS",
10200
0
        .kwtuple = KWTUPLE,
10201
0
    };
10202
0
    #undef KWTUPLE
10203
0
    PyObject *argsbuf[1];
10204
0
    int status;
10205
0
    int _return_value;
10206
10207
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10208
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10209
0
    if (!args) {
10210
0
        goto exit;
10211
0
    }
10212
0
    status = PyLong_AsInt(args[0]);
10213
0
    if (status == -1 && PyErr_Occurred()) {
10214
0
        goto exit;
10215
0
    }
10216
0
    _return_value = os_WEXITSTATUS_impl(module, status);
10217
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10218
0
        goto exit;
10219
0
    }
10220
0
    return_value = PyLong_FromLong((long)_return_value);
10221
10222
0
exit:
10223
0
    return return_value;
10224
0
}
10225
10226
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
10227
10228
#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
10229
10230
PyDoc_STRVAR(os_WTERMSIG__doc__,
10231
"WTERMSIG($module, /, status)\n"
10232
"--\n"
10233
"\n"
10234
"Return the signal that terminated the process that provided the status value.");
10235
10236
#define OS_WTERMSIG_METHODDEF    \
10237
    {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
10238
10239
static int
10240
os_WTERMSIG_impl(PyObject *module, int status);
10241
10242
static PyObject *
10243
os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10244
0
{
10245
0
    PyObject *return_value = NULL;
10246
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10247
10248
0
    #define NUM_KEYWORDS 1
10249
0
    static struct {
10250
0
        PyGC_Head _this_is_not_used;
10251
0
        PyObject_VAR_HEAD
10252
0
        Py_hash_t ob_hash;
10253
0
        PyObject *ob_item[NUM_KEYWORDS];
10254
0
    } _kwtuple = {
10255
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10256
0
        .ob_hash = -1,
10257
0
        .ob_item = { &_Py_ID(status), },
10258
0
    };
10259
0
    #undef NUM_KEYWORDS
10260
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10261
10262
    #else  // !Py_BUILD_CORE
10263
    #  define KWTUPLE NULL
10264
    #endif  // !Py_BUILD_CORE
10265
10266
0
    static const char * const _keywords[] = {"status", NULL};
10267
0
    static _PyArg_Parser _parser = {
10268
0
        .keywords = _keywords,
10269
0
        .fname = "WTERMSIG",
10270
0
        .kwtuple = KWTUPLE,
10271
0
    };
10272
0
    #undef KWTUPLE
10273
0
    PyObject *argsbuf[1];
10274
0
    int status;
10275
0
    int _return_value;
10276
10277
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10278
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10279
0
    if (!args) {
10280
0
        goto exit;
10281
0
    }
10282
0
    status = PyLong_AsInt(args[0]);
10283
0
    if (status == -1 && PyErr_Occurred()) {
10284
0
        goto exit;
10285
0
    }
10286
0
    _return_value = os_WTERMSIG_impl(module, status);
10287
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10288
0
        goto exit;
10289
0
    }
10290
0
    return_value = PyLong_FromLong((long)_return_value);
10291
10292
0
exit:
10293
0
    return return_value;
10294
0
}
10295
10296
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
10297
10298
#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
10299
10300
PyDoc_STRVAR(os_WSTOPSIG__doc__,
10301
"WSTOPSIG($module, /, status)\n"
10302
"--\n"
10303
"\n"
10304
"Return the signal that stopped the process that provided the status value.");
10305
10306
#define OS_WSTOPSIG_METHODDEF    \
10307
    {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
10308
10309
static int
10310
os_WSTOPSIG_impl(PyObject *module, int status);
10311
10312
static PyObject *
10313
os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10314
0
{
10315
0
    PyObject *return_value = NULL;
10316
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10317
10318
0
    #define NUM_KEYWORDS 1
10319
0
    static struct {
10320
0
        PyGC_Head _this_is_not_used;
10321
0
        PyObject_VAR_HEAD
10322
0
        Py_hash_t ob_hash;
10323
0
        PyObject *ob_item[NUM_KEYWORDS];
10324
0
    } _kwtuple = {
10325
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10326
0
        .ob_hash = -1,
10327
0
        .ob_item = { &_Py_ID(status), },
10328
0
    };
10329
0
    #undef NUM_KEYWORDS
10330
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10331
10332
    #else  // !Py_BUILD_CORE
10333
    #  define KWTUPLE NULL
10334
    #endif  // !Py_BUILD_CORE
10335
10336
0
    static const char * const _keywords[] = {"status", NULL};
10337
0
    static _PyArg_Parser _parser = {
10338
0
        .keywords = _keywords,
10339
0
        .fname = "WSTOPSIG",
10340
0
        .kwtuple = KWTUPLE,
10341
0
    };
10342
0
    #undef KWTUPLE
10343
0
    PyObject *argsbuf[1];
10344
0
    int status;
10345
0
    int _return_value;
10346
10347
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10348
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10349
0
    if (!args) {
10350
0
        goto exit;
10351
0
    }
10352
0
    status = PyLong_AsInt(args[0]);
10353
0
    if (status == -1 && PyErr_Occurred()) {
10354
0
        goto exit;
10355
0
    }
10356
0
    _return_value = os_WSTOPSIG_impl(module, status);
10357
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10358
0
        goto exit;
10359
0
    }
10360
0
    return_value = PyLong_FromLong((long)_return_value);
10361
10362
0
exit:
10363
0
    return return_value;
10364
0
}
10365
10366
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
10367
10368
#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
10369
10370
PyDoc_STRVAR(os_fstatvfs__doc__,
10371
"fstatvfs($module, fd, /)\n"
10372
"--\n"
10373
"\n"
10374
"Perform an fstatvfs system call on the given fd.\n"
10375
"\n"
10376
"Equivalent to statvfs(fd).");
10377
10378
#define OS_FSTATVFS_METHODDEF    \
10379
    {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
10380
10381
static PyObject *
10382
os_fstatvfs_impl(PyObject *module, int fd);
10383
10384
static PyObject *
10385
os_fstatvfs(PyObject *module, PyObject *arg)
10386
0
{
10387
0
    PyObject *return_value = NULL;
10388
0
    int fd;
10389
10390
0
    fd = PyLong_AsInt(arg);
10391
0
    if (fd == -1 && PyErr_Occurred()) {
10392
0
        goto exit;
10393
0
    }
10394
0
    return_value = os_fstatvfs_impl(module, fd);
10395
10396
0
exit:
10397
0
    return return_value;
10398
0
}
10399
10400
#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10401
10402
#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
10403
10404
PyDoc_STRVAR(os_statvfs__doc__,
10405
"statvfs($module, /, path)\n"
10406
"--\n"
10407
"\n"
10408
"Perform a statvfs system call on the given path.\n"
10409
"\n"
10410
"path may always be specified as a string.\n"
10411
"On some platforms, path may also be specified as an open file\n"
10412
"descriptor.  If this functionality is unavailable, using it raises\n"
10413
"an exception.");
10414
10415
#define OS_STATVFS_METHODDEF    \
10416
    {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
10417
10418
static PyObject *
10419
os_statvfs_impl(PyObject *module, path_t *path);
10420
10421
static PyObject *
10422
os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10423
0
{
10424
0
    PyObject *return_value = NULL;
10425
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10426
10427
0
    #define NUM_KEYWORDS 1
10428
0
    static struct {
10429
0
        PyGC_Head _this_is_not_used;
10430
0
        PyObject_VAR_HEAD
10431
0
        Py_hash_t ob_hash;
10432
0
        PyObject *ob_item[NUM_KEYWORDS];
10433
0
    } _kwtuple = {
10434
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10435
0
        .ob_hash = -1,
10436
0
        .ob_item = { &_Py_ID(path), },
10437
0
    };
10438
0
    #undef NUM_KEYWORDS
10439
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10440
10441
    #else  // !Py_BUILD_CORE
10442
    #  define KWTUPLE NULL
10443
    #endif  // !Py_BUILD_CORE
10444
10445
0
    static const char * const _keywords[] = {"path", NULL};
10446
0
    static _PyArg_Parser _parser = {
10447
0
        .keywords = _keywords,
10448
0
        .fname = "statvfs",
10449
0
        .kwtuple = KWTUPLE,
10450
0
    };
10451
0
    #undef KWTUPLE
10452
0
    PyObject *argsbuf[1];
10453
0
    path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS);
10454
10455
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10456
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10457
0
    if (!args) {
10458
0
        goto exit;
10459
0
    }
10460
0
    if (!path_converter(args[0], &path)) {
10461
0
        goto exit;
10462
0
    }
10463
0
    return_value = os_statvfs_impl(module, &path);
10464
10465
0
exit:
10466
    /* Cleanup for path */
10467
0
    path_cleanup(&path);
10468
10469
0
    return return_value;
10470
0
}
10471
10472
#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10473
10474
#if defined(MS_WINDOWS)
10475
10476
PyDoc_STRVAR(os__getdiskusage__doc__,
10477
"_getdiskusage($module, /, path)\n"
10478
"--\n"
10479
"\n"
10480
"Return disk usage statistics about the given path as a (total, free) tuple.");
10481
10482
#define OS__GETDISKUSAGE_METHODDEF    \
10483
    {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
10484
10485
static PyObject *
10486
os__getdiskusage_impl(PyObject *module, path_t *path);
10487
10488
static PyObject *
10489
os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10490
{
10491
    PyObject *return_value = NULL;
10492
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10493
10494
    #define NUM_KEYWORDS 1
10495
    static struct {
10496
        PyGC_Head _this_is_not_used;
10497
        PyObject_VAR_HEAD
10498
        Py_hash_t ob_hash;
10499
        PyObject *ob_item[NUM_KEYWORDS];
10500
    } _kwtuple = {
10501
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10502
        .ob_hash = -1,
10503
        .ob_item = { &_Py_ID(path), },
10504
    };
10505
    #undef NUM_KEYWORDS
10506
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10507
10508
    #else  // !Py_BUILD_CORE
10509
    #  define KWTUPLE NULL
10510
    #endif  // !Py_BUILD_CORE
10511
10512
    static const char * const _keywords[] = {"path", NULL};
10513
    static _PyArg_Parser _parser = {
10514
        .keywords = _keywords,
10515
        .fname = "_getdiskusage",
10516
        .kwtuple = KWTUPLE,
10517
    };
10518
    #undef KWTUPLE
10519
    PyObject *argsbuf[1];
10520
    path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0);
10521
10522
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10523
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10524
    if (!args) {
10525
        goto exit;
10526
    }
10527
    if (!path_converter(args[0], &path)) {
10528
        goto exit;
10529
    }
10530
    return_value = os__getdiskusage_impl(module, &path);
10531
10532
exit:
10533
    /* Cleanup for path */
10534
    path_cleanup(&path);
10535
10536
    return return_value;
10537
}
10538
10539
#endif /* defined(MS_WINDOWS) */
10540
10541
#if defined(HAVE_FPATHCONF)
10542
10543
PyDoc_STRVAR(os_fpathconf__doc__,
10544
"fpathconf($module, fd, name, /)\n"
10545
"--\n"
10546
"\n"
10547
"Return the configuration limit name for the file descriptor fd.\n"
10548
"\n"
10549
"If there is no limit, return -1.");
10550
10551
#define OS_FPATHCONF_METHODDEF    \
10552
    {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__},
10553
10554
static long
10555
os_fpathconf_impl(PyObject *module, int fd, int name);
10556
10557
static PyObject *
10558
os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10559
0
{
10560
0
    PyObject *return_value = NULL;
10561
0
    int fd;
10562
0
    int name;
10563
0
    long _return_value;
10564
10565
0
    if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
10566
0
        goto exit;
10567
0
    }
10568
0
    fd = PyObject_AsFileDescriptor(args[0]);
10569
0
    if (fd < 0) {
10570
0
        goto exit;
10571
0
    }
10572
0
    if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10573
0
        goto exit;
10574
0
    }
10575
0
    _return_value = os_fpathconf_impl(module, fd, name);
10576
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10577
0
        goto exit;
10578
0
    }
10579
0
    return_value = PyLong_FromLong(_return_value);
10580
10581
0
exit:
10582
0
    return return_value;
10583
0
}
10584
10585
#endif /* defined(HAVE_FPATHCONF) */
10586
10587
#if defined(HAVE_PATHCONF)
10588
10589
PyDoc_STRVAR(os_pathconf__doc__,
10590
"pathconf($module, /, path, name)\n"
10591
"--\n"
10592
"\n"
10593
"Return the configuration limit name for the file or directory path.\n"
10594
"\n"
10595
"If there is no limit, return -1.\n"
10596
"On some platforms, path may also be specified as an open file\n"
10597
"descriptor.  If this functionality is unavailable, using it raises\n"
10598
"an exception.");
10599
10600
#define OS_PATHCONF_METHODDEF    \
10601
    {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
10602
10603
static long
10604
os_pathconf_impl(PyObject *module, path_t *path, int name);
10605
10606
static PyObject *
10607
os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10608
0
{
10609
0
    PyObject *return_value = NULL;
10610
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10611
10612
0
    #define NUM_KEYWORDS 2
10613
0
    static struct {
10614
0
        PyGC_Head _this_is_not_used;
10615
0
        PyObject_VAR_HEAD
10616
0
        Py_hash_t ob_hash;
10617
0
        PyObject *ob_item[NUM_KEYWORDS];
10618
0
    } _kwtuple = {
10619
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10620
0
        .ob_hash = -1,
10621
0
        .ob_item = { &_Py_ID(path), &_Py_ID(name), },
10622
0
    };
10623
0
    #undef NUM_KEYWORDS
10624
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10625
10626
    #else  // !Py_BUILD_CORE
10627
    #  define KWTUPLE NULL
10628
    #endif  // !Py_BUILD_CORE
10629
10630
0
    static const char * const _keywords[] = {"path", "name", NULL};
10631
0
    static _PyArg_Parser _parser = {
10632
0
        .keywords = _keywords,
10633
0
        .fname = "pathconf",
10634
0
        .kwtuple = KWTUPLE,
10635
0
    };
10636
0
    #undef KWTUPLE
10637
0
    PyObject *argsbuf[2];
10638
0
    path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF);
10639
0
    int name;
10640
0
    long _return_value;
10641
10642
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10643
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10644
0
    if (!args) {
10645
0
        goto exit;
10646
0
    }
10647
0
    if (!path_converter(args[0], &path)) {
10648
0
        goto exit;
10649
0
    }
10650
0
    if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10651
0
        goto exit;
10652
0
    }
10653
0
    _return_value = os_pathconf_impl(module, &path, name);
10654
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10655
0
        goto exit;
10656
0
    }
10657
0
    return_value = PyLong_FromLong(_return_value);
10658
10659
0
exit:
10660
    /* Cleanup for path */
10661
0
    path_cleanup(&path);
10662
10663
0
    return return_value;
10664
0
}
10665
10666
#endif /* defined(HAVE_PATHCONF) */
10667
10668
#if defined(HAVE_CONFSTR)
10669
10670
PyDoc_STRVAR(os_confstr__doc__,
10671
"confstr($module, name, /)\n"
10672
"--\n"
10673
"\n"
10674
"Return a string-valued system configuration variable.");
10675
10676
#define OS_CONFSTR_METHODDEF    \
10677
    {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
10678
10679
static PyObject *
10680
os_confstr_impl(PyObject *module, int name);
10681
10682
static PyObject *
10683
os_confstr(PyObject *module, PyObject *arg)
10684
0
{
10685
0
    PyObject *return_value = NULL;
10686
0
    int name;
10687
10688
0
    if (!conv_confname(module, arg, &name, "confstr_names")) {
10689
0
        goto exit;
10690
0
    }
10691
0
    return_value = os_confstr_impl(module, name);
10692
10693
0
exit:
10694
0
    return return_value;
10695
0
}
10696
10697
#endif /* defined(HAVE_CONFSTR) */
10698
10699
#if defined(HAVE_SYSCONF)
10700
10701
PyDoc_STRVAR(os_sysconf__doc__,
10702
"sysconf($module, name, /)\n"
10703
"--\n"
10704
"\n"
10705
"Return an integer-valued system configuration variable.");
10706
10707
#define OS_SYSCONF_METHODDEF    \
10708
    {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
10709
10710
static long
10711
os_sysconf_impl(PyObject *module, int name);
10712
10713
static PyObject *
10714
os_sysconf(PyObject *module, PyObject *arg)
10715
0
{
10716
0
    PyObject *return_value = NULL;
10717
0
    int name;
10718
0
    long _return_value;
10719
10720
0
    if (!conv_confname(module, arg, &name, "sysconf_names")) {
10721
0
        goto exit;
10722
0
    }
10723
0
    _return_value = os_sysconf_impl(module, name);
10724
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10725
0
        goto exit;
10726
0
    }
10727
0
    return_value = PyLong_FromLong(_return_value);
10728
10729
0
exit:
10730
0
    return return_value;
10731
0
}
10732
10733
#endif /* defined(HAVE_SYSCONF) */
10734
10735
PyDoc_STRVAR(os_abort__doc__,
10736
"abort($module, /)\n"
10737
"--\n"
10738
"\n"
10739
"Abort the interpreter immediately.\n"
10740
"\n"
10741
"This function \'dumps core\' or otherwise fails in the hardest way\n"
10742
"possible on the hosting operating system.  This function never returns.");
10743
10744
#define OS_ABORT_METHODDEF    \
10745
    {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
10746
10747
static PyObject *
10748
os_abort_impl(PyObject *module);
10749
10750
static PyObject *
10751
os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
10752
0
{
10753
0
    return os_abort_impl(module);
10754
0
}
10755
10756
#if defined(MS_WINDOWS)
10757
10758
PyDoc_STRVAR(os_startfile__doc__,
10759
"startfile($module, /, filepath, operation=<unrepresentable>,\n"
10760
"          arguments=<unrepresentable>, cwd=None, show_cmd=1)\n"
10761
"--\n"
10762
"\n"
10763
"Start a file with its associated application.\n"
10764
"\n"
10765
"When \"operation\" is not specified or \"open\", this acts like\n"
10766
"double-clicking the file in Explorer, or giving the file name as an\n"
10767
"argument to the DOS \"start\" command: the file is opened with whatever\n"
10768
"application (if any) its extension is associated.\n"
10769
"When another \"operation\" is given, it specifies what should be done with\n"
10770
"the file.  A typical operation is \"print\".\n"
10771
"\n"
10772
"\"arguments\" is passed to the application, but should be omitted if the\n"
10773
"file is a document.\n"
10774
"\n"
10775
"\"cwd\" is the working directory for the operation. If \"filepath\" is\n"
10776
"relative, it will be resolved against this directory. This argument\n"
10777
"should usually be an absolute path.\n"
10778
"\n"
10779
"\"show_cmd\" can be used to override the recommended visibility option.\n"
10780
"See the Windows ShellExecute documentation for values.\n"
10781
"\n"
10782
"startfile returns as soon as the associated application is launched.\n"
10783
"There is no option to wait for the application to close, and no way\n"
10784
"to retrieve the application\'s exit status.\n"
10785
"\n"
10786
"The filepath is relative to the current directory.  If you want to use\n"
10787
"an absolute path, make sure the first character is not a slash (\"/\");\n"
10788
"the underlying Win32 ShellExecute function doesn\'t work if it is.");
10789
10790
#define OS_STARTFILE_METHODDEF    \
10791
    {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
10792
10793
static PyObject *
10794
os_startfile_impl(PyObject *module, path_t *filepath,
10795
                  const wchar_t *operation, const wchar_t *arguments,
10796
                  path_t *cwd, int show_cmd);
10797
10798
static PyObject *
10799
os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10800
{
10801
    PyObject *return_value = NULL;
10802
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10803
10804
    #define NUM_KEYWORDS 5
10805
    static struct {
10806
        PyGC_Head _this_is_not_used;
10807
        PyObject_VAR_HEAD
10808
        Py_hash_t ob_hash;
10809
        PyObject *ob_item[NUM_KEYWORDS];
10810
    } _kwtuple = {
10811
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10812
        .ob_hash = -1,
10813
        .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), },
10814
    };
10815
    #undef NUM_KEYWORDS
10816
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10817
10818
    #else  // !Py_BUILD_CORE
10819
    #  define KWTUPLE NULL
10820
    #endif  // !Py_BUILD_CORE
10821
10822
    static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL};
10823
    static _PyArg_Parser _parser = {
10824
        .keywords = _keywords,
10825
        .fname = "startfile",
10826
        .kwtuple = KWTUPLE,
10827
    };
10828
    #undef KWTUPLE
10829
    PyObject *argsbuf[5];
10830
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
10831
    path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0);
10832
    const wchar_t *operation = NULL;
10833
    const wchar_t *arguments = NULL;
10834
    path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0);
10835
    int show_cmd = 1;
10836
10837
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10838
            /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10839
    if (!args) {
10840
        goto exit;
10841
    }
10842
    if (!path_converter(args[0], &filepath)) {
10843
        goto exit;
10844
    }
10845
    if (!noptargs) {
10846
        goto skip_optional_pos;
10847
    }
10848
    if (args[1]) {
10849
        if (!PyUnicode_Check(args[1])) {
10850
            _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]);
10851
            goto exit;
10852
        }
10853
        operation = PyUnicode_AsWideCharString(args[1], NULL);
10854
        if (operation == NULL) {
10855
            goto exit;
10856
        }
10857
        if (!--noptargs) {
10858
            goto skip_optional_pos;
10859
        }
10860
    }
10861
    if (args[2]) {
10862
        if (!PyUnicode_Check(args[2])) {
10863
            _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]);
10864
            goto exit;
10865
        }
10866
        arguments = PyUnicode_AsWideCharString(args[2], NULL);
10867
        if (arguments == NULL) {
10868
            goto exit;
10869
        }
10870
        if (!--noptargs) {
10871
            goto skip_optional_pos;
10872
        }
10873
    }
10874
    if (args[3]) {
10875
        if (!path_converter(args[3], &cwd)) {
10876
            goto exit;
10877
        }
10878
        if (!--noptargs) {
10879
            goto skip_optional_pos;
10880
        }
10881
    }
10882
    show_cmd = PyLong_AsInt(args[4]);
10883
    if (show_cmd == -1 && PyErr_Occurred()) {
10884
        goto exit;
10885
    }
10886
skip_optional_pos:
10887
    return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd);
10888
10889
exit:
10890
    /* Cleanup for filepath */
10891
    path_cleanup(&filepath);
10892
    /* Cleanup for operation */
10893
    PyMem_Free((void *)operation);
10894
    /* Cleanup for arguments */
10895
    PyMem_Free((void *)arguments);
10896
    /* Cleanup for cwd */
10897
    path_cleanup(&cwd);
10898
10899
    return return_value;
10900
}
10901
10902
#endif /* defined(MS_WINDOWS) */
10903
10904
#if defined(HAVE_GETLOADAVG)
10905
10906
PyDoc_STRVAR(os_getloadavg__doc__,
10907
"getloadavg($module, /)\n"
10908
"--\n"
10909
"\n"
10910
"Return average recent system load information.\n"
10911
"\n"
10912
"Return the number of processes in the system run queue averaged over\n"
10913
"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
10914
"Raises OSError if the load average was unobtainable.");
10915
10916
#define OS_GETLOADAVG_METHODDEF    \
10917
    {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
10918
10919
static PyObject *
10920
os_getloadavg_impl(PyObject *module);
10921
10922
static PyObject *
10923
os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
10924
0
{
10925
0
    return os_getloadavg_impl(module);
10926
0
}
10927
10928
#endif /* defined(HAVE_GETLOADAVG) */
10929
10930
PyDoc_STRVAR(os_device_encoding__doc__,
10931
"device_encoding($module, /, fd)\n"
10932
"--\n"
10933
"\n"
10934
"Return a string describing the encoding of a terminal\'s file descriptor.\n"
10935
"\n"
10936
"The file descriptor must be attached to a terminal.\n"
10937
"If the device is not a terminal, return None.");
10938
10939
#define OS_DEVICE_ENCODING_METHODDEF    \
10940
    {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
10941
10942
static PyObject *
10943
os_device_encoding_impl(PyObject *module, int fd);
10944
10945
static PyObject *
10946
os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10947
0
{
10948
0
    PyObject *return_value = NULL;
10949
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10950
10951
0
    #define NUM_KEYWORDS 1
10952
0
    static struct {
10953
0
        PyGC_Head _this_is_not_used;
10954
0
        PyObject_VAR_HEAD
10955
0
        Py_hash_t ob_hash;
10956
0
        PyObject *ob_item[NUM_KEYWORDS];
10957
0
    } _kwtuple = {
10958
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10959
0
        .ob_hash = -1,
10960
0
        .ob_item = { &_Py_ID(fd), },
10961
0
    };
10962
0
    #undef NUM_KEYWORDS
10963
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10964
10965
    #else  // !Py_BUILD_CORE
10966
    #  define KWTUPLE NULL
10967
    #endif  // !Py_BUILD_CORE
10968
10969
0
    static const char * const _keywords[] = {"fd", NULL};
10970
0
    static _PyArg_Parser _parser = {
10971
0
        .keywords = _keywords,
10972
0
        .fname = "device_encoding",
10973
0
        .kwtuple = KWTUPLE,
10974
0
    };
10975
0
    #undef KWTUPLE
10976
0
    PyObject *argsbuf[1];
10977
0
    int fd;
10978
10979
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10980
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10981
0
    if (!args) {
10982
0
        goto exit;
10983
0
    }
10984
0
    fd = PyLong_AsInt(args[0]);
10985
0
    if (fd == -1 && PyErr_Occurred()) {
10986
0
        goto exit;
10987
0
    }
10988
0
    return_value = os_device_encoding_impl(module, fd);
10989
10990
0
exit:
10991
0
    return return_value;
10992
0
}
10993
10994
#if defined(HAVE_SETRESUID)
10995
10996
PyDoc_STRVAR(os_setresuid__doc__,
10997
"setresuid($module, ruid, euid, suid, /)\n"
10998
"--\n"
10999
"\n"
11000
"Set the current process\'s real, effective, and saved user ids.");
11001
11002
#define OS_SETRESUID_METHODDEF    \
11003
    {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__},
11004
11005
static PyObject *
11006
os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
11007
11008
static PyObject *
11009
os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11010
0
{
11011
0
    PyObject *return_value = NULL;
11012
0
    uid_t ruid;
11013
0
    uid_t euid;
11014
0
    uid_t suid;
11015
11016
0
    if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
11017
0
        goto exit;
11018
0
    }
11019
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
11020
0
        goto exit;
11021
0
    }
11022
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
11023
0
        goto exit;
11024
0
    }
11025
0
    if (!_Py_Uid_Converter(args[2], &suid)) {
11026
0
        goto exit;
11027
0
    }
11028
0
    return_value = os_setresuid_impl(module, ruid, euid, suid);
11029
11030
0
exit:
11031
0
    return return_value;
11032
0
}
11033
11034
#endif /* defined(HAVE_SETRESUID) */
11035
11036
#if defined(HAVE_SETRESGID)
11037
11038
PyDoc_STRVAR(os_setresgid__doc__,
11039
"setresgid($module, rgid, egid, sgid, /)\n"
11040
"--\n"
11041
"\n"
11042
"Set the current process\'s real, effective, and saved group ids.");
11043
11044
#define OS_SETRESGID_METHODDEF    \
11045
    {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__},
11046
11047
static PyObject *
11048
os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
11049
11050
static PyObject *
11051
os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11052
0
{
11053
0
    PyObject *return_value = NULL;
11054
0
    gid_t rgid;
11055
0
    gid_t egid;
11056
0
    gid_t sgid;
11057
11058
0
    if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
11059
0
        goto exit;
11060
0
    }
11061
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
11062
0
        goto exit;
11063
0
    }
11064
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
11065
0
        goto exit;
11066
0
    }
11067
0
    if (!_Py_Gid_Converter(args[2], &sgid)) {
11068
0
        goto exit;
11069
0
    }
11070
0
    return_value = os_setresgid_impl(module, rgid, egid, sgid);
11071
11072
0
exit:
11073
0
    return return_value;
11074
0
}
11075
11076
#endif /* defined(HAVE_SETRESGID) */
11077
11078
#if defined(HAVE_GETRESUID)
11079
11080
PyDoc_STRVAR(os_getresuid__doc__,
11081
"getresuid($module, /)\n"
11082
"--\n"
11083
"\n"
11084
"Return a tuple of the current process\'s real, effective, and saved user ids.");
11085
11086
#define OS_GETRESUID_METHODDEF    \
11087
    {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
11088
11089
static PyObject *
11090
os_getresuid_impl(PyObject *module);
11091
11092
static PyObject *
11093
os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
11094
0
{
11095
0
    return os_getresuid_impl(module);
11096
0
}
11097
11098
#endif /* defined(HAVE_GETRESUID) */
11099
11100
#if defined(HAVE_GETRESGID)
11101
11102
PyDoc_STRVAR(os_getresgid__doc__,
11103
"getresgid($module, /)\n"
11104
"--\n"
11105
"\n"
11106
"Return a tuple of the current process\'s real, effective, and saved group ids.");
11107
11108
#define OS_GETRESGID_METHODDEF    \
11109
    {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
11110
11111
static PyObject *
11112
os_getresgid_impl(PyObject *module);
11113
11114
static PyObject *
11115
os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
11116
0
{
11117
0
    return os_getresgid_impl(module);
11118
0
}
11119
11120
#endif /* defined(HAVE_GETRESGID) */
11121
11122
#if defined(USE_XATTRS)
11123
11124
PyDoc_STRVAR(os_getxattr__doc__,
11125
"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
11126
"--\n"
11127
"\n"
11128
"Return the value of extended attribute attribute on path.\n"
11129
"\n"
11130
"path may be either a string, a path-like object, or an open file\n"
11131
"descriptor.\n"
11132
"If follow_symlinks is False, and the last element of the path is\n"
11133
"a symbolic link, getxattr will examine the symbolic link itself\n"
11134
"instead of the file the link points to.");
11135
11136
#define OS_GETXATTR_METHODDEF    \
11137
    {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
11138
11139
static PyObject *
11140
os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
11141
                 int follow_symlinks);
11142
11143
static PyObject *
11144
os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11145
0
{
11146
0
    PyObject *return_value = NULL;
11147
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11148
11149
0
    #define NUM_KEYWORDS 3
11150
0
    static struct {
11151
0
        PyGC_Head _this_is_not_used;
11152
0
        PyObject_VAR_HEAD
11153
0
        Py_hash_t ob_hash;
11154
0
        PyObject *ob_item[NUM_KEYWORDS];
11155
0
    } _kwtuple = {
11156
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11157
0
        .ob_hash = -1,
11158
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
11159
0
    };
11160
0
    #undef NUM_KEYWORDS
11161
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11162
11163
    #else  // !Py_BUILD_CORE
11164
    #  define KWTUPLE NULL
11165
    #endif  // !Py_BUILD_CORE
11166
11167
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
11168
0
    static _PyArg_Parser _parser = {
11169
0
        .keywords = _keywords,
11170
0
        .fname = "getxattr",
11171
0
        .kwtuple = KWTUPLE,
11172
0
    };
11173
0
    #undef KWTUPLE
11174
0
    PyObject *argsbuf[3];
11175
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
11176
0
    path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1);
11177
0
    path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0);
11178
0
    int follow_symlinks = 1;
11179
11180
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11181
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11182
0
    if (!args) {
11183
0
        goto exit;
11184
0
    }
11185
0
    if (!path_converter(args[0], &path)) {
11186
0
        goto exit;
11187
0
    }
11188
0
    if (!path_converter(args[1], &attribute)) {
11189
0
        goto exit;
11190
0
    }
11191
0
    if (!noptargs) {
11192
0
        goto skip_optional_kwonly;
11193
0
    }
11194
0
    follow_symlinks = PyObject_IsTrue(args[2]);
11195
0
    if (follow_symlinks < 0) {
11196
0
        goto exit;
11197
0
    }
11198
0
skip_optional_kwonly:
11199
0
    return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
11200
11201
0
exit:
11202
    /* Cleanup for path */
11203
0
    path_cleanup(&path);
11204
    /* Cleanup for attribute */
11205
0
    path_cleanup(&attribute);
11206
11207
0
    return return_value;
11208
0
}
11209
11210
#endif /* defined(USE_XATTRS) */
11211
11212
#if defined(USE_XATTRS)
11213
11214
PyDoc_STRVAR(os_setxattr__doc__,
11215
"setxattr($module, /, path, attribute, value, flags=0, *,\n"
11216
"         follow_symlinks=True)\n"
11217
"--\n"
11218
"\n"
11219
"Set extended attribute attribute on path to value.\n"
11220
"\n"
11221
"path may be either a string, a path-like object,  or an open file\n"
11222
"descriptor.\n"
11223
"If follow_symlinks is False, and the last element of the path is\n"
11224
"a symbolic link, setxattr will modify the symbolic link itself instead\n"
11225
"of the file the link points to.");
11226
11227
#define OS_SETXATTR_METHODDEF    \
11228
    {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
11229
11230
static PyObject *
11231
os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
11232
                 Py_buffer *value, int flags, int follow_symlinks);
11233
11234
static PyObject *
11235
os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11236
0
{
11237
0
    PyObject *return_value = NULL;
11238
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11239
11240
0
    #define NUM_KEYWORDS 5
11241
0
    static struct {
11242
0
        PyGC_Head _this_is_not_used;
11243
0
        PyObject_VAR_HEAD
11244
0
        Py_hash_t ob_hash;
11245
0
        PyObject *ob_item[NUM_KEYWORDS];
11246
0
    } _kwtuple = {
11247
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11248
0
        .ob_hash = -1,
11249
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
11250
0
    };
11251
0
    #undef NUM_KEYWORDS
11252
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11253
11254
    #else  // !Py_BUILD_CORE
11255
    #  define KWTUPLE NULL
11256
    #endif  // !Py_BUILD_CORE
11257
11258
0
    static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
11259
0
    static _PyArg_Parser _parser = {
11260
0
        .keywords = _keywords,
11261
0
        .fname = "setxattr",
11262
0
        .kwtuple = KWTUPLE,
11263
0
    };
11264
0
    #undef KWTUPLE
11265
0
    PyObject *argsbuf[5];
11266
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
11267
0
    path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1);
11268
0
    path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0);
11269
0
    Py_buffer value = {NULL, NULL};
11270
0
    int flags = 0;
11271
0
    int follow_symlinks = 1;
11272
11273
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11274
0
            /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11275
0
    if (!args) {
11276
0
        goto exit;
11277
0
    }
11278
0
    if (!path_converter(args[0], &path)) {
11279
0
        goto exit;
11280
0
    }
11281
0
    if (!path_converter(args[1], &attribute)) {
11282
0
        goto exit;
11283
0
    }
11284
0
    if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
11285
0
        goto exit;
11286
0
    }
11287
0
    if (!noptargs) {
11288
0
        goto skip_optional_pos;
11289
0
    }
11290
0
    if (args[3]) {
11291
0
        flags = PyLong_AsInt(args[3]);
11292
0
        if (flags == -1 && PyErr_Occurred()) {
11293
0
            goto exit;
11294
0
        }
11295
0
        if (!--noptargs) {
11296
0
            goto skip_optional_pos;
11297
0
        }
11298
0
    }
11299
0
skip_optional_pos:
11300
0
    if (!noptargs) {
11301
0
        goto skip_optional_kwonly;
11302
0
    }
11303
0
    follow_symlinks = PyObject_IsTrue(args[4]);
11304
0
    if (follow_symlinks < 0) {
11305
0
        goto exit;
11306
0
    }
11307
0
skip_optional_kwonly:
11308
0
    return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
11309
11310
0
exit:
11311
    /* Cleanup for path */
11312
0
    path_cleanup(&path);
11313
    /* Cleanup for attribute */
11314
0
    path_cleanup(&attribute);
11315
    /* Cleanup for value */
11316
0
    if (value.obj) {
11317
0
       PyBuffer_Release(&value);
11318
0
    }
11319
11320
0
    return return_value;
11321
0
}
11322
11323
#endif /* defined(USE_XATTRS) */
11324
11325
#if defined(USE_XATTRS)
11326
11327
PyDoc_STRVAR(os_removexattr__doc__,
11328
"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
11329
"--\n"
11330
"\n"
11331
"Remove extended attribute attribute on path.\n"
11332
"\n"
11333
"path may be either a string, a path-like object, or an open file\n"
11334
"descriptor.\n"
11335
"If follow_symlinks is False, and the last element of the path is\n"
11336
"a symbolic link, removexattr will modify the symbolic link itself\n"
11337
"instead of the file the link points to.");
11338
11339
#define OS_REMOVEXATTR_METHODDEF    \
11340
    {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
11341
11342
static PyObject *
11343
os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
11344
                    int follow_symlinks);
11345
11346
static PyObject *
11347
os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11348
0
{
11349
0
    PyObject *return_value = NULL;
11350
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11351
11352
0
    #define NUM_KEYWORDS 3
11353
0
    static struct {
11354
0
        PyGC_Head _this_is_not_used;
11355
0
        PyObject_VAR_HEAD
11356
0
        Py_hash_t ob_hash;
11357
0
        PyObject *ob_item[NUM_KEYWORDS];
11358
0
    } _kwtuple = {
11359
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11360
0
        .ob_hash = -1,
11361
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
11362
0
    };
11363
0
    #undef NUM_KEYWORDS
11364
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11365
11366
    #else  // !Py_BUILD_CORE
11367
    #  define KWTUPLE NULL
11368
    #endif  // !Py_BUILD_CORE
11369
11370
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
11371
0
    static _PyArg_Parser _parser = {
11372
0
        .keywords = _keywords,
11373
0
        .fname = "removexattr",
11374
0
        .kwtuple = KWTUPLE,
11375
0
    };
11376
0
    #undef KWTUPLE
11377
0
    PyObject *argsbuf[3];
11378
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
11379
0
    path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1);
11380
0
    path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0);
11381
0
    int follow_symlinks = 1;
11382
11383
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11384
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11385
0
    if (!args) {
11386
0
        goto exit;
11387
0
    }
11388
0
    if (!path_converter(args[0], &path)) {
11389
0
        goto exit;
11390
0
    }
11391
0
    if (!path_converter(args[1], &attribute)) {
11392
0
        goto exit;
11393
0
    }
11394
0
    if (!noptargs) {
11395
0
        goto skip_optional_kwonly;
11396
0
    }
11397
0
    follow_symlinks = PyObject_IsTrue(args[2]);
11398
0
    if (follow_symlinks < 0) {
11399
0
        goto exit;
11400
0
    }
11401
0
skip_optional_kwonly:
11402
0
    return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
11403
11404
0
exit:
11405
    /* Cleanup for path */
11406
0
    path_cleanup(&path);
11407
    /* Cleanup for attribute */
11408
0
    path_cleanup(&attribute);
11409
11410
0
    return return_value;
11411
0
}
11412
11413
#endif /* defined(USE_XATTRS) */
11414
11415
#if defined(USE_XATTRS)
11416
11417
PyDoc_STRVAR(os_listxattr__doc__,
11418
"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
11419
"--\n"
11420
"\n"
11421
"Return a list of extended attributes on path.\n"
11422
"\n"
11423
"path may be either None, a string, a path-like object, or an open file\n"
11424
"descriptor.  If path is None, listxattr will examine the current\n"
11425
"directory.\n"
11426
"If follow_symlinks is False, and the last element of the path is\n"
11427
"a symbolic link, listxattr will examine the symbolic link itself instead\n"
11428
"of the file the link points to.");
11429
11430
#define OS_LISTXATTR_METHODDEF    \
11431
    {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
11432
11433
static PyObject *
11434
os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
11435
11436
static PyObject *
11437
os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11438
0
{
11439
0
    PyObject *return_value = NULL;
11440
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11441
11442
0
    #define NUM_KEYWORDS 2
11443
0
    static struct {
11444
0
        PyGC_Head _this_is_not_used;
11445
0
        PyObject_VAR_HEAD
11446
0
        Py_hash_t ob_hash;
11447
0
        PyObject *ob_item[NUM_KEYWORDS];
11448
0
    } _kwtuple = {
11449
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11450
0
        .ob_hash = -1,
11451
0
        .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), },
11452
0
    };
11453
0
    #undef NUM_KEYWORDS
11454
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11455
11456
    #else  // !Py_BUILD_CORE
11457
    #  define KWTUPLE NULL
11458
    #endif  // !Py_BUILD_CORE
11459
11460
0
    static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
11461
0
    static _PyArg_Parser _parser = {
11462
0
        .keywords = _keywords,
11463
0
        .fname = "listxattr",
11464
0
        .kwtuple = KWTUPLE,
11465
0
    };
11466
0
    #undef KWTUPLE
11467
0
    PyObject *argsbuf[2];
11468
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
11469
0
    path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1);
11470
0
    int follow_symlinks = 1;
11471
11472
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11473
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11474
0
    if (!args) {
11475
0
        goto exit;
11476
0
    }
11477
0
    if (!noptargs) {
11478
0
        goto skip_optional_pos;
11479
0
    }
11480
0
    if (args[0]) {
11481
0
        if (!path_converter(args[0], &path)) {
11482
0
            goto exit;
11483
0
        }
11484
0
        if (!--noptargs) {
11485
0
            goto skip_optional_pos;
11486
0
        }
11487
0
    }
11488
0
skip_optional_pos:
11489
0
    if (!noptargs) {
11490
0
        goto skip_optional_kwonly;
11491
0
    }
11492
0
    follow_symlinks = PyObject_IsTrue(args[1]);
11493
0
    if (follow_symlinks < 0) {
11494
0
        goto exit;
11495
0
    }
11496
0
skip_optional_kwonly:
11497
0
    return_value = os_listxattr_impl(module, &path, follow_symlinks);
11498
11499
0
exit:
11500
    /* Cleanup for path */
11501
0
    path_cleanup(&path);
11502
11503
0
    return return_value;
11504
0
}
11505
11506
#endif /* defined(USE_XATTRS) */
11507
11508
PyDoc_STRVAR(os_urandom__doc__,
11509
"urandom($module, size, /)\n"
11510
"--\n"
11511
"\n"
11512
"Return a bytes object containing random bytes suitable for cryptographic use.");
11513
11514
#define OS_URANDOM_METHODDEF    \
11515
    {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
11516
11517
static PyObject *
11518
os_urandom_impl(PyObject *module, Py_ssize_t size);
11519
11520
static PyObject *
11521
os_urandom(PyObject *module, PyObject *arg)
11522
0
{
11523
0
    PyObject *return_value = NULL;
11524
0
    Py_ssize_t size;
11525
11526
0
    {
11527
0
        Py_ssize_t ival = -1;
11528
0
        PyObject *iobj = _PyNumber_Index(arg);
11529
0
        if (iobj != NULL) {
11530
0
            ival = PyLong_AsSsize_t(iobj);
11531
0
            Py_DECREF(iobj);
11532
0
        }
11533
0
        if (ival == -1 && PyErr_Occurred()) {
11534
0
            goto exit;
11535
0
        }
11536
0
        size = ival;
11537
0
        if (size < 0) {
11538
0
            PyErr_SetString(PyExc_ValueError,
11539
0
                            "size cannot be negative");
11540
0
            goto exit;
11541
0
        }
11542
0
    }
11543
0
    return_value = os_urandom_impl(module, size);
11544
11545
0
exit:
11546
0
    return return_value;
11547
0
}
11548
11549
#if defined(HAVE_MEMFD_CREATE)
11550
11551
PyDoc_STRVAR(os_memfd_create__doc__,
11552
"memfd_create($module, /, name, flags=MFD_CLOEXEC)\n"
11553
"--\n"
11554
"\n");
11555
11556
#define OS_MEMFD_CREATE_METHODDEF    \
11557
    {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__},
11558
11559
static PyObject *
11560
os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags);
11561
11562
static PyObject *
11563
os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11564
0
{
11565
0
    PyObject *return_value = NULL;
11566
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11567
11568
0
    #define NUM_KEYWORDS 2
11569
0
    static struct {
11570
0
        PyGC_Head _this_is_not_used;
11571
0
        PyObject_VAR_HEAD
11572
0
        Py_hash_t ob_hash;
11573
0
        PyObject *ob_item[NUM_KEYWORDS];
11574
0
    } _kwtuple = {
11575
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11576
0
        .ob_hash = -1,
11577
0
        .ob_item = { &_Py_ID(name), &_Py_ID(flags), },
11578
0
    };
11579
0
    #undef NUM_KEYWORDS
11580
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11581
11582
    #else  // !Py_BUILD_CORE
11583
    #  define KWTUPLE NULL
11584
    #endif  // !Py_BUILD_CORE
11585
11586
0
    static const char * const _keywords[] = {"name", "flags", NULL};
11587
0
    static _PyArg_Parser _parser = {
11588
0
        .keywords = _keywords,
11589
0
        .fname = "memfd_create",
11590
0
        .kwtuple = KWTUPLE,
11591
0
    };
11592
0
    #undef KWTUPLE
11593
0
    PyObject *argsbuf[2];
11594
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11595
0
    PyObject *name = NULL;
11596
0
    unsigned int flags = MFD_CLOEXEC;
11597
11598
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11599
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11600
0
    if (!args) {
11601
0
        goto exit;
11602
0
    }
11603
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
11604
0
        goto exit;
11605
0
    }
11606
0
    if (!noptargs) {
11607
0
        goto skip_optional_pos;
11608
0
    }
11609
0
    {
11610
0
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned int),
11611
0
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
11612
0
                Py_ASNATIVEBYTES_ALLOW_INDEX |
11613
0
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
11614
0
        if (_bytes < 0) {
11615
0
            goto exit;
11616
0
        }
11617
0
        if ((size_t)_bytes > sizeof(unsigned int)) {
11618
0
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
11619
0
                "integer value out of range", 1) < 0)
11620
0
            {
11621
0
                goto exit;
11622
0
            }
11623
0
        }
11624
0
    }
11625
0
skip_optional_pos:
11626
0
    return_value = os_memfd_create_impl(module, name, flags);
11627
11628
0
exit:
11629
    /* Cleanup for name */
11630
0
    Py_XDECREF(name);
11631
11632
0
    return return_value;
11633
0
}
11634
11635
#endif /* defined(HAVE_MEMFD_CREATE) */
11636
11637
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11638
11639
PyDoc_STRVAR(os_eventfd__doc__,
11640
"eventfd($module, /, initval, flags=EFD_CLOEXEC)\n"
11641
"--\n"
11642
"\n"
11643
"Creates and returns an event notification file descriptor.");
11644
11645
#define OS_EVENTFD_METHODDEF    \
11646
    {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__},
11647
11648
static PyObject *
11649
os_eventfd_impl(PyObject *module, unsigned int initval, int flags);
11650
11651
static PyObject *
11652
os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11653
0
{
11654
0
    PyObject *return_value = NULL;
11655
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11656
11657
0
    #define NUM_KEYWORDS 2
11658
0
    static struct {
11659
0
        PyGC_Head _this_is_not_used;
11660
0
        PyObject_VAR_HEAD
11661
0
        Py_hash_t ob_hash;
11662
0
        PyObject *ob_item[NUM_KEYWORDS];
11663
0
    } _kwtuple = {
11664
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11665
0
        .ob_hash = -1,
11666
0
        .ob_item = { &_Py_ID(initval), &_Py_ID(flags), },
11667
0
    };
11668
0
    #undef NUM_KEYWORDS
11669
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11670
11671
    #else  // !Py_BUILD_CORE
11672
    #  define KWTUPLE NULL
11673
    #endif  // !Py_BUILD_CORE
11674
11675
0
    static const char * const _keywords[] = {"initval", "flags", NULL};
11676
0
    static _PyArg_Parser _parser = {
11677
0
        .keywords = _keywords,
11678
0
        .fname = "eventfd",
11679
0
        .kwtuple = KWTUPLE,
11680
0
    };
11681
0
    #undef KWTUPLE
11682
0
    PyObject *argsbuf[2];
11683
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11684
0
    unsigned int initval;
11685
0
    int flags = EFD_CLOEXEC;
11686
11687
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11688
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11689
0
    if (!args) {
11690
0
        goto exit;
11691
0
    }
11692
0
    if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) {
11693
0
        goto exit;
11694
0
    }
11695
0
    if (!noptargs) {
11696
0
        goto skip_optional_pos;
11697
0
    }
11698
0
    flags = PyLong_AsInt(args[1]);
11699
0
    if (flags == -1 && PyErr_Occurred()) {
11700
0
        goto exit;
11701
0
    }
11702
0
skip_optional_pos:
11703
0
    return_value = os_eventfd_impl(module, initval, flags);
11704
11705
0
exit:
11706
0
    return return_value;
11707
0
}
11708
11709
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11710
11711
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11712
11713
PyDoc_STRVAR(os_eventfd_read__doc__,
11714
"eventfd_read($module, /, fd)\n"
11715
"--\n"
11716
"\n"
11717
"Read eventfd value");
11718
11719
#define OS_EVENTFD_READ_METHODDEF    \
11720
    {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__},
11721
11722
static PyObject *
11723
os_eventfd_read_impl(PyObject *module, int fd);
11724
11725
static PyObject *
11726
os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11727
0
{
11728
0
    PyObject *return_value = NULL;
11729
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11730
11731
0
    #define NUM_KEYWORDS 1
11732
0
    static struct {
11733
0
        PyGC_Head _this_is_not_used;
11734
0
        PyObject_VAR_HEAD
11735
0
        Py_hash_t ob_hash;
11736
0
        PyObject *ob_item[NUM_KEYWORDS];
11737
0
    } _kwtuple = {
11738
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11739
0
        .ob_hash = -1,
11740
0
        .ob_item = { &_Py_ID(fd), },
11741
0
    };
11742
0
    #undef NUM_KEYWORDS
11743
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11744
11745
    #else  // !Py_BUILD_CORE
11746
    #  define KWTUPLE NULL
11747
    #endif  // !Py_BUILD_CORE
11748
11749
0
    static const char * const _keywords[] = {"fd", NULL};
11750
0
    static _PyArg_Parser _parser = {
11751
0
        .keywords = _keywords,
11752
0
        .fname = "eventfd_read",
11753
0
        .kwtuple = KWTUPLE,
11754
0
    };
11755
0
    #undef KWTUPLE
11756
0
    PyObject *argsbuf[1];
11757
0
    int fd;
11758
11759
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11760
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11761
0
    if (!args) {
11762
0
        goto exit;
11763
0
    }
11764
0
    fd = PyObject_AsFileDescriptor(args[0]);
11765
0
    if (fd < 0) {
11766
0
        goto exit;
11767
0
    }
11768
0
    return_value = os_eventfd_read_impl(module, fd);
11769
11770
0
exit:
11771
0
    return return_value;
11772
0
}
11773
11774
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11775
11776
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11777
11778
PyDoc_STRVAR(os_eventfd_write__doc__,
11779
"eventfd_write($module, /, fd, value)\n"
11780
"--\n"
11781
"\n"
11782
"Write eventfd value.");
11783
11784
#define OS_EVENTFD_WRITE_METHODDEF    \
11785
    {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__},
11786
11787
static PyObject *
11788
os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value);
11789
11790
static PyObject *
11791
os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11792
0
{
11793
0
    PyObject *return_value = NULL;
11794
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11795
11796
0
    #define NUM_KEYWORDS 2
11797
0
    static struct {
11798
0
        PyGC_Head _this_is_not_used;
11799
0
        PyObject_VAR_HEAD
11800
0
        Py_hash_t ob_hash;
11801
0
        PyObject *ob_item[NUM_KEYWORDS];
11802
0
    } _kwtuple = {
11803
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11804
0
        .ob_hash = -1,
11805
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(value), },
11806
0
    };
11807
0
    #undef NUM_KEYWORDS
11808
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11809
11810
    #else  // !Py_BUILD_CORE
11811
    #  define KWTUPLE NULL
11812
    #endif  // !Py_BUILD_CORE
11813
11814
0
    static const char * const _keywords[] = {"fd", "value", NULL};
11815
0
    static _PyArg_Parser _parser = {
11816
0
        .keywords = _keywords,
11817
0
        .fname = "eventfd_write",
11818
0
        .kwtuple = KWTUPLE,
11819
0
    };
11820
0
    #undef KWTUPLE
11821
0
    PyObject *argsbuf[2];
11822
0
    int fd;
11823
0
    unsigned long long value;
11824
11825
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11826
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11827
0
    if (!args) {
11828
0
        goto exit;
11829
0
    }
11830
0
    fd = PyObject_AsFileDescriptor(args[0]);
11831
0
    if (fd < 0) {
11832
0
        goto exit;
11833
0
    }
11834
0
    if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) {
11835
0
        goto exit;
11836
0
    }
11837
0
    return_value = os_eventfd_write_impl(module, fd, value);
11838
11839
0
exit:
11840
0
    return return_value;
11841
0
}
11842
11843
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11844
11845
#if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL))
11846
11847
PyDoc_STRVAR(os_get_terminal_size__doc__,
11848
"get_terminal_size($module, fd=<unrepresentable>, /)\n"
11849
"--\n"
11850
"\n"
11851
"Return the size of the terminal window as (columns, lines).\n"
11852
"\n"
11853
"The optional argument fd (default standard output) specifies\n"
11854
"which file descriptor should be queried.\n"
11855
"\n"
11856
"If the file descriptor is not connected to a terminal, an OSError\n"
11857
"is thrown.\n"
11858
"\n"
11859
"This function will only be defined if an implementation is\n"
11860
"available for this system.\n"
11861
"\n"
11862
"shutil.get_terminal_size is the high-level function which should\n"
11863
"normally be used, os.get_terminal_size is the low-level implementation.");
11864
11865
#define OS_GET_TERMINAL_SIZE_METHODDEF    \
11866
    {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__},
11867
11868
static PyObject *
11869
os_get_terminal_size_impl(PyObject *module, int fd);
11870
11871
static PyObject *
11872
os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11873
0
{
11874
0
    PyObject *return_value = NULL;
11875
0
    int fd = fileno(stdout);
11876
11877
0
    if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) {
11878
0
        goto exit;
11879
0
    }
11880
0
    if (nargs < 1) {
11881
0
        goto skip_optional;
11882
0
    }
11883
0
    fd = PyLong_AsInt(args[0]);
11884
0
    if (fd == -1 && PyErr_Occurred()) {
11885
0
        goto exit;
11886
0
    }
11887
0
skip_optional:
11888
0
    return_value = os_get_terminal_size_impl(module, fd);
11889
11890
0
exit:
11891
0
    return return_value;
11892
0
}
11893
11894
#endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */
11895
11896
PyDoc_STRVAR(os_cpu_count__doc__,
11897
"cpu_count($module, /)\n"
11898
"--\n"
11899
"\n"
11900
"Return the number of logical CPUs in the system.\n"
11901
"\n"
11902
"Return None if indeterminable.");
11903
11904
#define OS_CPU_COUNT_METHODDEF    \
11905
    {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
11906
11907
static PyObject *
11908
os_cpu_count_impl(PyObject *module);
11909
11910
static PyObject *
11911
os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
11912
0
{
11913
0
    return os_cpu_count_impl(module);
11914
0
}
11915
11916
PyDoc_STRVAR(os_get_inheritable__doc__,
11917
"get_inheritable($module, fd, /)\n"
11918
"--\n"
11919
"\n"
11920
"Get the close-on-exe flag of the specified file descriptor.");
11921
11922
#define OS_GET_INHERITABLE_METHODDEF    \
11923
    {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
11924
11925
static int
11926
os_get_inheritable_impl(PyObject *module, int fd);
11927
11928
static PyObject *
11929
os_get_inheritable(PyObject *module, PyObject *arg)
11930
0
{
11931
0
    PyObject *return_value = NULL;
11932
0
    int fd;
11933
0
    int _return_value;
11934
11935
0
    fd = PyLong_AsInt(arg);
11936
0
    if (fd == -1 && PyErr_Occurred()) {
11937
0
        goto exit;
11938
0
    }
11939
0
    _return_value = os_get_inheritable_impl(module, fd);
11940
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11941
0
        goto exit;
11942
0
    }
11943
0
    return_value = PyBool_FromLong((long)_return_value);
11944
11945
0
exit:
11946
0
    return return_value;
11947
0
}
11948
11949
PyDoc_STRVAR(os_set_inheritable__doc__,
11950
"set_inheritable($module, fd, inheritable, /)\n"
11951
"--\n"
11952
"\n"
11953
"Set the inheritable flag of the specified file descriptor.");
11954
11955
#define OS_SET_INHERITABLE_METHODDEF    \
11956
    {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__},
11957
11958
static PyObject *
11959
os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
11960
11961
static PyObject *
11962
os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11963
0
{
11964
0
    PyObject *return_value = NULL;
11965
0
    int fd;
11966
0
    int inheritable;
11967
11968
0
    if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
11969
0
        goto exit;
11970
0
    }
11971
0
    fd = PyLong_AsInt(args[0]);
11972
0
    if (fd == -1 && PyErr_Occurred()) {
11973
0
        goto exit;
11974
0
    }
11975
0
    inheritable = PyLong_AsInt(args[1]);
11976
0
    if (inheritable == -1 && PyErr_Occurred()) {
11977
0
        goto exit;
11978
0
    }
11979
0
    return_value = os_set_inheritable_impl(module, fd, inheritable);
11980
11981
0
exit:
11982
0
    return return_value;
11983
0
}
11984
11985
#if defined(MS_WINDOWS)
11986
11987
PyDoc_STRVAR(os_get_handle_inheritable__doc__,
11988
"get_handle_inheritable($module, handle, /)\n"
11989
"--\n"
11990
"\n"
11991
"Get the close-on-exe flag of the specified file descriptor.");
11992
11993
#define OS_GET_HANDLE_INHERITABLE_METHODDEF    \
11994
    {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
11995
11996
static int
11997
os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
11998
11999
static PyObject *
12000
os_get_handle_inheritable(PyObject *module, PyObject *arg)
12001
{
12002
    PyObject *return_value = NULL;
12003
    intptr_t handle;
12004
    int _return_value;
12005
12006
    handle = (intptr_t)PyLong_AsVoidPtr(arg);
12007
    if (!handle && PyErr_Occurred()) {
12008
        goto exit;
12009
    }
12010
    _return_value = os_get_handle_inheritable_impl(module, handle);
12011
    if ((_return_value == -1) && PyErr_Occurred()) {
12012
        goto exit;
12013
    }
12014
    return_value = PyBool_FromLong((long)_return_value);
12015
12016
exit:
12017
    return return_value;
12018
}
12019
12020
#endif /* defined(MS_WINDOWS) */
12021
12022
#if defined(MS_WINDOWS)
12023
12024
PyDoc_STRVAR(os_set_handle_inheritable__doc__,
12025
"set_handle_inheritable($module, handle, inheritable, /)\n"
12026
"--\n"
12027
"\n"
12028
"Set the inheritable flag of the specified handle.");
12029
12030
#define OS_SET_HANDLE_INHERITABLE_METHODDEF    \
12031
    {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__},
12032
12033
static PyObject *
12034
os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
12035
                               int inheritable);
12036
12037
static PyObject *
12038
os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
12039
{
12040
    PyObject *return_value = NULL;
12041
    intptr_t handle;
12042
    int inheritable;
12043
12044
    if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) {
12045
        goto exit;
12046
    }
12047
    handle = (intptr_t)PyLong_AsVoidPtr(args[0]);
12048
    if (!handle && PyErr_Occurred()) {
12049
        goto exit;
12050
    }
12051
    inheritable = PyObject_IsTrue(args[1]);
12052
    if (inheritable < 0) {
12053
        goto exit;
12054
    }
12055
    return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
12056
12057
exit:
12058
    return return_value;
12059
}
12060
12061
#endif /* defined(MS_WINDOWS) */
12062
12063
PyDoc_STRVAR(os_get_blocking__doc__,
12064
"get_blocking($module, fd, /)\n"
12065
"--\n"
12066
"\n"
12067
"Get the blocking mode of the file descriptor.\n"
12068
"\n"
12069
"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
12070
12071
#define OS_GET_BLOCKING_METHODDEF    \
12072
    {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
12073
12074
static int
12075
os_get_blocking_impl(PyObject *module, int fd);
12076
12077
static PyObject *
12078
os_get_blocking(PyObject *module, PyObject *arg)
12079
0
{
12080
0
    PyObject *return_value = NULL;
12081
0
    int fd;
12082
0
    int _return_value;
12083
12084
0
    fd = PyLong_AsInt(arg);
12085
0
    if (fd == -1 && PyErr_Occurred()) {
12086
0
        goto exit;
12087
0
    }
12088
0
    _return_value = os_get_blocking_impl(module, fd);
12089
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12090
0
        goto exit;
12091
0
    }
12092
0
    return_value = PyBool_FromLong((long)_return_value);
12093
12094
0
exit:
12095
0
    return return_value;
12096
0
}
12097
12098
PyDoc_STRVAR(os_set_blocking__doc__,
12099
"set_blocking($module, fd, blocking, /)\n"
12100
"--\n"
12101
"\n"
12102
"Set the blocking mode of the specified file descriptor.\n"
12103
"\n"
12104
"Set the O_NONBLOCK flag if blocking is False,\n"
12105
"clear the O_NONBLOCK flag otherwise.");
12106
12107
#define OS_SET_BLOCKING_METHODDEF    \
12108
    {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__},
12109
12110
static PyObject *
12111
os_set_blocking_impl(PyObject *module, int fd, int blocking);
12112
12113
static PyObject *
12114
os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
12115
0
{
12116
0
    PyObject *return_value = NULL;
12117
0
    int fd;
12118
0
    int blocking;
12119
12120
0
    if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
12121
0
        goto exit;
12122
0
    }
12123
0
    fd = PyLong_AsInt(args[0]);
12124
0
    if (fd == -1 && PyErr_Occurred()) {
12125
0
        goto exit;
12126
0
    }
12127
0
    blocking = PyObject_IsTrue(args[1]);
12128
0
    if (blocking < 0) {
12129
0
        goto exit;
12130
0
    }
12131
0
    return_value = os_set_blocking_impl(module, fd, blocking);
12132
12133
0
exit:
12134
0
    return return_value;
12135
0
}
12136
12137
PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
12138
"is_symlink($self, /)\n"
12139
"--\n"
12140
"\n"
12141
"Return True if the entry is a symbolic link; cached per entry.");
12142
12143
#define OS_DIRENTRY_IS_SYMLINK_METHODDEF    \
12144
    {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__},
12145
12146
static int
12147
os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class);
12148
12149
static PyObject *
12150
os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12151
0
{
12152
0
    PyObject *return_value = NULL;
12153
0
    int _return_value;
12154
12155
0
    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
12156
0
        PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
12157
0
        goto exit;
12158
0
    }
12159
0
    _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class);
12160
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12161
0
        goto exit;
12162
0
    }
12163
0
    return_value = PyBool_FromLong((long)_return_value);
12164
12165
0
exit:
12166
0
    return return_value;
12167
0
}
12168
12169
PyDoc_STRVAR(os_DirEntry_is_junction__doc__,
12170
"is_junction($self, /)\n"
12171
"--\n"
12172
"\n"
12173
"Return True if the entry is a junction; cached per entry.");
12174
12175
#define OS_DIRENTRY_IS_JUNCTION_METHODDEF    \
12176
    {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__},
12177
12178
static int
12179
os_DirEntry_is_junction_impl(DirEntry *self);
12180
12181
static PyObject *
12182
os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored))
12183
0
{
12184
0
    PyObject *return_value = NULL;
12185
0
    int _return_value;
12186
12187
0
    _return_value = os_DirEntry_is_junction_impl((DirEntry *)self);
12188
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12189
0
        goto exit;
12190
0
    }
12191
0
    return_value = PyBool_FromLong((long)_return_value);
12192
12193
0
exit:
12194
0
    return return_value;
12195
0
}
12196
12197
PyDoc_STRVAR(os_DirEntry_stat__doc__,
12198
"stat($self, /, *, follow_symlinks=True)\n"
12199
"--\n"
12200
"\n"
12201
"Return stat_result object for the entry; cached per entry.");
12202
12203
#define OS_DIRENTRY_STAT_METHODDEF    \
12204
    {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
12205
12206
static PyObject *
12207
os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class,
12208
                      int follow_symlinks);
12209
12210
static PyObject *
12211
os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12212
0
{
12213
0
    PyObject *return_value = NULL;
12214
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12215
12216
0
    #define NUM_KEYWORDS 1
12217
0
    static struct {
12218
0
        PyGC_Head _this_is_not_used;
12219
0
        PyObject_VAR_HEAD
12220
0
        Py_hash_t ob_hash;
12221
0
        PyObject *ob_item[NUM_KEYWORDS];
12222
0
    } _kwtuple = {
12223
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12224
0
        .ob_hash = -1,
12225
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12226
0
    };
12227
0
    #undef NUM_KEYWORDS
12228
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12229
12230
    #else  // !Py_BUILD_CORE
12231
    #  define KWTUPLE NULL
12232
    #endif  // !Py_BUILD_CORE
12233
12234
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12235
0
    static _PyArg_Parser _parser = {
12236
0
        .keywords = _keywords,
12237
0
        .fname = "stat",
12238
0
        .kwtuple = KWTUPLE,
12239
0
    };
12240
0
    #undef KWTUPLE
12241
0
    PyObject *argsbuf[1];
12242
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12243
0
    int follow_symlinks = 1;
12244
12245
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12246
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12247
0
    if (!args) {
12248
0
        goto exit;
12249
0
    }
12250
0
    if (!noptargs) {
12251
0
        goto skip_optional_kwonly;
12252
0
    }
12253
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12254
0
    if (follow_symlinks < 0) {
12255
0
        goto exit;
12256
0
    }
12257
0
skip_optional_kwonly:
12258
0
    return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks);
12259
12260
0
exit:
12261
0
    return return_value;
12262
0
}
12263
12264
PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
12265
"is_dir($self, /, *, follow_symlinks=True)\n"
12266
"--\n"
12267
"\n"
12268
"Return True if the entry is a directory; cached per entry.");
12269
12270
#define OS_DIRENTRY_IS_DIR_METHODDEF    \
12271
    {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
12272
12273
static int
12274
os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class,
12275
                        int follow_symlinks);
12276
12277
static PyObject *
12278
os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12279
0
{
12280
0
    PyObject *return_value = NULL;
12281
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12282
12283
0
    #define NUM_KEYWORDS 1
12284
0
    static struct {
12285
0
        PyGC_Head _this_is_not_used;
12286
0
        PyObject_VAR_HEAD
12287
0
        Py_hash_t ob_hash;
12288
0
        PyObject *ob_item[NUM_KEYWORDS];
12289
0
    } _kwtuple = {
12290
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12291
0
        .ob_hash = -1,
12292
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12293
0
    };
12294
0
    #undef NUM_KEYWORDS
12295
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12296
12297
    #else  // !Py_BUILD_CORE
12298
    #  define KWTUPLE NULL
12299
    #endif  // !Py_BUILD_CORE
12300
12301
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12302
0
    static _PyArg_Parser _parser = {
12303
0
        .keywords = _keywords,
12304
0
        .fname = "is_dir",
12305
0
        .kwtuple = KWTUPLE,
12306
0
    };
12307
0
    #undef KWTUPLE
12308
0
    PyObject *argsbuf[1];
12309
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12310
0
    int follow_symlinks = 1;
12311
0
    int _return_value;
12312
12313
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12314
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12315
0
    if (!args) {
12316
0
        goto exit;
12317
0
    }
12318
0
    if (!noptargs) {
12319
0
        goto skip_optional_kwonly;
12320
0
    }
12321
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12322
0
    if (follow_symlinks < 0) {
12323
0
        goto exit;
12324
0
    }
12325
0
skip_optional_kwonly:
12326
0
    _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks);
12327
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12328
0
        goto exit;
12329
0
    }
12330
0
    return_value = PyBool_FromLong((long)_return_value);
12331
12332
0
exit:
12333
0
    return return_value;
12334
0
}
12335
12336
PyDoc_STRVAR(os_DirEntry_is_file__doc__,
12337
"is_file($self, /, *, follow_symlinks=True)\n"
12338
"--\n"
12339
"\n"
12340
"Return True if the entry is a file; cached per entry.");
12341
12342
#define OS_DIRENTRY_IS_FILE_METHODDEF    \
12343
    {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
12344
12345
static int
12346
os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class,
12347
                         int follow_symlinks);
12348
12349
static PyObject *
12350
os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12351
0
{
12352
0
    PyObject *return_value = NULL;
12353
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12354
12355
0
    #define NUM_KEYWORDS 1
12356
0
    static struct {
12357
0
        PyGC_Head _this_is_not_used;
12358
0
        PyObject_VAR_HEAD
12359
0
        Py_hash_t ob_hash;
12360
0
        PyObject *ob_item[NUM_KEYWORDS];
12361
0
    } _kwtuple = {
12362
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12363
0
        .ob_hash = -1,
12364
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12365
0
    };
12366
0
    #undef NUM_KEYWORDS
12367
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12368
12369
    #else  // !Py_BUILD_CORE
12370
    #  define KWTUPLE NULL
12371
    #endif  // !Py_BUILD_CORE
12372
12373
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12374
0
    static _PyArg_Parser _parser = {
12375
0
        .keywords = _keywords,
12376
0
        .fname = "is_file",
12377
0
        .kwtuple = KWTUPLE,
12378
0
    };
12379
0
    #undef KWTUPLE
12380
0
    PyObject *argsbuf[1];
12381
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12382
0
    int follow_symlinks = 1;
12383
0
    int _return_value;
12384
12385
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12386
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12387
0
    if (!args) {
12388
0
        goto exit;
12389
0
    }
12390
0
    if (!noptargs) {
12391
0
        goto skip_optional_kwonly;
12392
0
    }
12393
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12394
0
    if (follow_symlinks < 0) {
12395
0
        goto exit;
12396
0
    }
12397
0
skip_optional_kwonly:
12398
0
    _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks);
12399
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12400
0
        goto exit;
12401
0
    }
12402
0
    return_value = PyBool_FromLong((long)_return_value);
12403
12404
0
exit:
12405
0
    return return_value;
12406
0
}
12407
12408
PyDoc_STRVAR(os_DirEntry_inode__doc__,
12409
"inode($self, /)\n"
12410
"--\n"
12411
"\n"
12412
"Return inode of the entry; cached per entry.");
12413
12414
#define OS_DIRENTRY_INODE_METHODDEF    \
12415
    {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
12416
12417
static PyObject *
12418
os_DirEntry_inode_impl(DirEntry *self);
12419
12420
static PyObject *
12421
os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored))
12422
0
{
12423
0
    return os_DirEntry_inode_impl((DirEntry *)self);
12424
0
}
12425
12426
PyDoc_STRVAR(os_DirEntry___fspath____doc__,
12427
"__fspath__($self, /)\n"
12428
"--\n"
12429
"\n"
12430
"Returns the path for the entry.");
12431
12432
#define OS_DIRENTRY___FSPATH___METHODDEF    \
12433
    {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
12434
12435
static PyObject *
12436
os_DirEntry___fspath___impl(DirEntry *self);
12437
12438
static PyObject *
12439
os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored))
12440
0
{
12441
0
    return os_DirEntry___fspath___impl((DirEntry *)self);
12442
0
}
12443
12444
PyDoc_STRVAR(os_scandir__doc__,
12445
"scandir($module, /, path=None)\n"
12446
"--\n"
12447
"\n"
12448
"Return an iterator of DirEntry objects for given path.\n"
12449
"\n"
12450
"path can be specified as either str, bytes, or a path-like object.  If\n"
12451
"path is bytes, the names of yielded DirEntry objects will also be bytes;\n"
12452
"in all other circumstances they will be str.\n"
12453
"\n"
12454
"If path is None, uses the path=\'.\'.");
12455
12456
#define OS_SCANDIR_METHODDEF    \
12457
    {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
12458
12459
static PyObject *
12460
os_scandir_impl(PyObject *module, path_t *path);
12461
12462
static PyObject *
12463
os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12464
0
{
12465
0
    PyObject *return_value = NULL;
12466
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12467
12468
0
    #define NUM_KEYWORDS 1
12469
0
    static struct {
12470
0
        PyGC_Head _this_is_not_used;
12471
0
        PyObject_VAR_HEAD
12472
0
        Py_hash_t ob_hash;
12473
0
        PyObject *ob_item[NUM_KEYWORDS];
12474
0
    } _kwtuple = {
12475
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12476
0
        .ob_hash = -1,
12477
0
        .ob_item = { &_Py_ID(path), },
12478
0
    };
12479
0
    #undef NUM_KEYWORDS
12480
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12481
12482
    #else  // !Py_BUILD_CORE
12483
    #  define KWTUPLE NULL
12484
    #endif  // !Py_BUILD_CORE
12485
12486
0
    static const char * const _keywords[] = {"path", NULL};
12487
0
    static _PyArg_Parser _parser = {
12488
0
        .keywords = _keywords,
12489
0
        .fname = "scandir",
12490
0
        .kwtuple = KWTUPLE,
12491
0
    };
12492
0
    #undef KWTUPLE
12493
0
    PyObject *argsbuf[1];
12494
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12495
0
    path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
12496
12497
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12498
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12499
0
    if (!args) {
12500
0
        goto exit;
12501
0
    }
12502
0
    if (!noptargs) {
12503
0
        goto skip_optional_pos;
12504
0
    }
12505
0
    if (!path_converter(args[0], &path)) {
12506
0
        goto exit;
12507
0
    }
12508
0
skip_optional_pos:
12509
0
    return_value = os_scandir_impl(module, &path);
12510
12511
0
exit:
12512
    /* Cleanup for path */
12513
0
    path_cleanup(&path);
12514
12515
0
    return return_value;
12516
0
}
12517
12518
PyDoc_STRVAR(os_fspath__doc__,
12519
"fspath($module, /, path)\n"
12520
"--\n"
12521
"\n"
12522
"Return the file system path representation of the object.\n"
12523
"\n"
12524
"If the object is str or bytes, then allow it to pass through as-is.  If\n"
12525
"the object defines __fspath__(), then return the result of that method.\n"
12526
"All other types raise a TypeError.");
12527
12528
#define OS_FSPATH_METHODDEF    \
12529
    {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
12530
12531
static PyObject *
12532
os_fspath_impl(PyObject *module, PyObject *path);
12533
12534
static PyObject *
12535
os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12536
1.30k
{
12537
1.30k
    PyObject *return_value = NULL;
12538
1.30k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12539
12540
1.30k
    #define NUM_KEYWORDS 1
12541
1.30k
    static struct {
12542
1.30k
        PyGC_Head _this_is_not_used;
12543
1.30k
        PyObject_VAR_HEAD
12544
1.30k
        Py_hash_t ob_hash;
12545
1.30k
        PyObject *ob_item[NUM_KEYWORDS];
12546
1.30k
    } _kwtuple = {
12547
1.30k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12548
1.30k
        .ob_hash = -1,
12549
1.30k
        .ob_item = { &_Py_ID(path), },
12550
1.30k
    };
12551
1.30k
    #undef NUM_KEYWORDS
12552
1.30k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12553
12554
    #else  // !Py_BUILD_CORE
12555
    #  define KWTUPLE NULL
12556
    #endif  // !Py_BUILD_CORE
12557
12558
1.30k
    static const char * const _keywords[] = {"path", NULL};
12559
1.30k
    static _PyArg_Parser _parser = {
12560
1.30k
        .keywords = _keywords,
12561
1.30k
        .fname = "fspath",
12562
1.30k
        .kwtuple = KWTUPLE,
12563
1.30k
    };
12564
1.30k
    #undef KWTUPLE
12565
1.30k
    PyObject *argsbuf[1];
12566
1.30k
    PyObject *path;
12567
12568
1.30k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12569
1.30k
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12570
1.30k
    if (!args) {
12571
0
        goto exit;
12572
0
    }
12573
1.30k
    path = args[0];
12574
1.30k
    return_value = os_fspath_impl(module, path);
12575
12576
1.30k
exit:
12577
1.30k
    return return_value;
12578
1.30k
}
12579
12580
#if defined(HAVE_GETRANDOM_SYSCALL)
12581
12582
PyDoc_STRVAR(os_getrandom__doc__,
12583
"getrandom($module, /, size, flags=0)\n"
12584
"--\n"
12585
"\n"
12586
"Obtain a series of random bytes.");
12587
12588
#define OS_GETRANDOM_METHODDEF    \
12589
    {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
12590
12591
static PyObject *
12592
os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
12593
12594
static PyObject *
12595
os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12596
0
{
12597
0
    PyObject *return_value = NULL;
12598
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12599
12600
0
    #define NUM_KEYWORDS 2
12601
0
    static struct {
12602
0
        PyGC_Head _this_is_not_used;
12603
0
        PyObject_VAR_HEAD
12604
0
        Py_hash_t ob_hash;
12605
0
        PyObject *ob_item[NUM_KEYWORDS];
12606
0
    } _kwtuple = {
12607
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12608
0
        .ob_hash = -1,
12609
0
        .ob_item = { &_Py_ID(size), &_Py_ID(flags), },
12610
0
    };
12611
0
    #undef NUM_KEYWORDS
12612
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12613
12614
    #else  // !Py_BUILD_CORE
12615
    #  define KWTUPLE NULL
12616
    #endif  // !Py_BUILD_CORE
12617
12618
0
    static const char * const _keywords[] = {"size", "flags", NULL};
12619
0
    static _PyArg_Parser _parser = {
12620
0
        .keywords = _keywords,
12621
0
        .fname = "getrandom",
12622
0
        .kwtuple = KWTUPLE,
12623
0
    };
12624
0
    #undef KWTUPLE
12625
0
    PyObject *argsbuf[2];
12626
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
12627
0
    Py_ssize_t size;
12628
0
    int flags = 0;
12629
12630
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12631
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12632
0
    if (!args) {
12633
0
        goto exit;
12634
0
    }
12635
0
    {
12636
0
        Py_ssize_t ival = -1;
12637
0
        PyObject *iobj = _PyNumber_Index(args[0]);
12638
0
        if (iobj != NULL) {
12639
0
            ival = PyLong_AsSsize_t(iobj);
12640
0
            Py_DECREF(iobj);
12641
0
        }
12642
0
        if (ival == -1 && PyErr_Occurred()) {
12643
0
            goto exit;
12644
0
        }
12645
0
        size = ival;
12646
0
    }
12647
0
    if (!noptargs) {
12648
0
        goto skip_optional_pos;
12649
0
    }
12650
0
    flags = PyLong_AsInt(args[1]);
12651
0
    if (flags == -1 && PyErr_Occurred()) {
12652
0
        goto exit;
12653
0
    }
12654
0
skip_optional_pos:
12655
0
    return_value = os_getrandom_impl(module, size, flags);
12656
12657
0
exit:
12658
0
    return return_value;
12659
0
}
12660
12661
#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
12662
12663
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12664
12665
PyDoc_STRVAR(os__add_dll_directory__doc__,
12666
"_add_dll_directory($module, /, path)\n"
12667
"--\n"
12668
"\n"
12669
"Add a path to the DLL search path.\n"
12670
"\n"
12671
"This search path is used when resolving dependencies for imported\n"
12672
"extension modules (the module itself is resolved through sys.path),\n"
12673
"and also by ctypes.\n"
12674
"\n"
12675
"Returns an opaque value that may be passed to os.remove_dll_directory\n"
12676
"to remove this directory from the search path.");
12677
12678
#define OS__ADD_DLL_DIRECTORY_METHODDEF    \
12679
    {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
12680
12681
static PyObject *
12682
os__add_dll_directory_impl(PyObject *module, path_t *path);
12683
12684
static PyObject *
12685
os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12686
{
12687
    PyObject *return_value = NULL;
12688
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12689
12690
    #define NUM_KEYWORDS 1
12691
    static struct {
12692
        PyGC_Head _this_is_not_used;
12693
        PyObject_VAR_HEAD
12694
        Py_hash_t ob_hash;
12695
        PyObject *ob_item[NUM_KEYWORDS];
12696
    } _kwtuple = {
12697
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12698
        .ob_hash = -1,
12699
        .ob_item = { &_Py_ID(path), },
12700
    };
12701
    #undef NUM_KEYWORDS
12702
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12703
12704
    #else  // !Py_BUILD_CORE
12705
    #  define KWTUPLE NULL
12706
    #endif  // !Py_BUILD_CORE
12707
12708
    static const char * const _keywords[] = {"path", NULL};
12709
    static _PyArg_Parser _parser = {
12710
        .keywords = _keywords,
12711
        .fname = "_add_dll_directory",
12712
        .kwtuple = KWTUPLE,
12713
    };
12714
    #undef KWTUPLE
12715
    PyObject *argsbuf[1];
12716
    path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0);
12717
12718
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12719
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12720
    if (!args) {
12721
        goto exit;
12722
    }
12723
    if (!path_converter(args[0], &path)) {
12724
        goto exit;
12725
    }
12726
    return_value = os__add_dll_directory_impl(module, &path);
12727
12728
exit:
12729
    /* Cleanup for path */
12730
    path_cleanup(&path);
12731
12732
    return return_value;
12733
}
12734
12735
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12736
12737
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12738
12739
PyDoc_STRVAR(os__remove_dll_directory__doc__,
12740
"_remove_dll_directory($module, /, cookie)\n"
12741
"--\n"
12742
"\n"
12743
"Removes a path from the DLL search path.\n"
12744
"\n"
12745
"The parameter is an opaque value that was returned from\n"
12746
"os.add_dll_directory. You can only remove directories that you added\n"
12747
"yourself.");
12748
12749
#define OS__REMOVE_DLL_DIRECTORY_METHODDEF    \
12750
    {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
12751
12752
static PyObject *
12753
os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
12754
12755
static PyObject *
12756
os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12757
{
12758
    PyObject *return_value = NULL;
12759
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12760
12761
    #define NUM_KEYWORDS 1
12762
    static struct {
12763
        PyGC_Head _this_is_not_used;
12764
        PyObject_VAR_HEAD
12765
        Py_hash_t ob_hash;
12766
        PyObject *ob_item[NUM_KEYWORDS];
12767
    } _kwtuple = {
12768
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12769
        .ob_hash = -1,
12770
        .ob_item = { &_Py_ID(cookie), },
12771
    };
12772
    #undef NUM_KEYWORDS
12773
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12774
12775
    #else  // !Py_BUILD_CORE
12776
    #  define KWTUPLE NULL
12777
    #endif  // !Py_BUILD_CORE
12778
12779
    static const char * const _keywords[] = {"cookie", NULL};
12780
    static _PyArg_Parser _parser = {
12781
        .keywords = _keywords,
12782
        .fname = "_remove_dll_directory",
12783
        .kwtuple = KWTUPLE,
12784
    };
12785
    #undef KWTUPLE
12786
    PyObject *argsbuf[1];
12787
    PyObject *cookie;
12788
12789
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12790
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12791
    if (!args) {
12792
        goto exit;
12793
    }
12794
    cookie = args[0];
12795
    return_value = os__remove_dll_directory_impl(module, cookie);
12796
12797
exit:
12798
    return return_value;
12799
}
12800
12801
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12802
12803
#if (defined(WIFEXITED) || defined(MS_WINDOWS))
12804
12805
PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__,
12806
"waitstatus_to_exitcode($module, /, status)\n"
12807
"--\n"
12808
"\n"
12809
"Convert a wait status to an exit code.\n"
12810
"\n"
12811
"On Unix:\n"
12812
"\n"
12813
"* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n"
12814
"* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n"
12815
"* Otherwise, raise a ValueError.\n"
12816
"\n"
12817
"On Windows, return status shifted right by 8 bits.\n"
12818
"\n"
12819
"On Unix, if the process is being traced or if waitpid() was called with\n"
12820
"WUNTRACED option, the caller must first check if WIFSTOPPED(status) is\n"
12821
"true.  This function must not be called if WIFSTOPPED(status) is true.");
12822
12823
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF    \
12824
    {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__},
12825
12826
static PyObject *
12827
os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj);
12828
12829
static PyObject *
12830
os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12831
0
{
12832
0
    PyObject *return_value = NULL;
12833
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12834
12835
0
    #define NUM_KEYWORDS 1
12836
0
    static struct {
12837
0
        PyGC_Head _this_is_not_used;
12838
0
        PyObject_VAR_HEAD
12839
0
        Py_hash_t ob_hash;
12840
0
        PyObject *ob_item[NUM_KEYWORDS];
12841
0
    } _kwtuple = {
12842
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12843
0
        .ob_hash = -1,
12844
0
        .ob_item = { &_Py_ID(status), },
12845
0
    };
12846
0
    #undef NUM_KEYWORDS
12847
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12848
12849
    #else  // !Py_BUILD_CORE
12850
    #  define KWTUPLE NULL
12851
    #endif  // !Py_BUILD_CORE
12852
12853
0
    static const char * const _keywords[] = {"status", NULL};
12854
0
    static _PyArg_Parser _parser = {
12855
0
        .keywords = _keywords,
12856
0
        .fname = "waitstatus_to_exitcode",
12857
0
        .kwtuple = KWTUPLE,
12858
0
    };
12859
0
    #undef KWTUPLE
12860
0
    PyObject *argsbuf[1];
12861
0
    PyObject *status_obj;
12862
12863
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12864
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12865
0
    if (!args) {
12866
0
        goto exit;
12867
0
    }
12868
0
    status_obj = args[0];
12869
0
    return_value = os_waitstatus_to_exitcode_impl(module, status_obj);
12870
12871
0
exit:
12872
0
    return return_value;
12873
0
}
12874
12875
#endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */
12876
12877
#if defined(MS_WINDOWS)
12878
12879
PyDoc_STRVAR(os__supports_virtual_terminal__doc__,
12880
"_supports_virtual_terminal($module, /)\n"
12881
"--\n"
12882
"\n"
12883
"Checks if virtual terminal is supported in windows");
12884
12885
#define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF    \
12886
    {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__},
12887
12888
static PyObject *
12889
os__supports_virtual_terminal_impl(PyObject *module);
12890
12891
static PyObject *
12892
os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored))
12893
{
12894
    return os__supports_virtual_terminal_impl(module);
12895
}
12896
12897
#endif /* defined(MS_WINDOWS) */
12898
12899
PyDoc_STRVAR(os__inputhook__doc__,
12900
"_inputhook($module, /)\n"
12901
"--\n"
12902
"\n"
12903
"Calls PyOS_InputHook dropping the GIL first");
12904
12905
#define OS__INPUTHOOK_METHODDEF    \
12906
    {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__},
12907
12908
static PyObject *
12909
os__inputhook_impl(PyObject *module);
12910
12911
static PyObject *
12912
os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored))
12913
0
{
12914
0
    return os__inputhook_impl(module);
12915
0
}
12916
12917
PyDoc_STRVAR(os__is_inputhook_installed__doc__,
12918
"_is_inputhook_installed($module, /)\n"
12919
"--\n"
12920
"\n"
12921
"Checks if PyOS_InputHook is set");
12922
12923
#define OS__IS_INPUTHOOK_INSTALLED_METHODDEF    \
12924
    {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__},
12925
12926
static PyObject *
12927
os__is_inputhook_installed_impl(PyObject *module);
12928
12929
static PyObject *
12930
os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored))
12931
0
{
12932
0
    return os__is_inputhook_installed_impl(module);
12933
0
}
12934
12935
PyDoc_STRVAR(os__create_environ__doc__,
12936
"_create_environ($module, /)\n"
12937
"--\n"
12938
"\n"
12939
"Create the environment dictionary.");
12940
12941
#define OS__CREATE_ENVIRON_METHODDEF    \
12942
    {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__},
12943
12944
static PyObject *
12945
os__create_environ_impl(PyObject *module);
12946
12947
static PyObject *
12948
os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored))
12949
0
{
12950
0
    return os__create_environ_impl(module);
12951
0
}
12952
12953
#if defined(__EMSCRIPTEN__)
12954
12955
PyDoc_STRVAR(os__emscripten_debugger__doc__,
12956
"_emscripten_debugger($module, /)\n"
12957
"--\n"
12958
"\n"
12959
"Create a breakpoint for the JavaScript debugger. Emscripten only.");
12960
12961
#define OS__EMSCRIPTEN_DEBUGGER_METHODDEF    \
12962
    {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__},
12963
12964
static PyObject *
12965
os__emscripten_debugger_impl(PyObject *module);
12966
12967
static PyObject *
12968
os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored))
12969
{
12970
    return os__emscripten_debugger_impl(module);
12971
}
12972
12973
#endif /* defined(__EMSCRIPTEN__) */
12974
12975
#if defined(__EMSCRIPTEN__)
12976
12977
PyDoc_STRVAR(os__emscripten_log__doc__,
12978
"_emscripten_log($module, /, arg)\n"
12979
"--\n"
12980
"\n"
12981
"Log something to the JS console. Emscripten only.");
12982
12983
#define OS__EMSCRIPTEN_LOG_METHODDEF    \
12984
    {"_emscripten_log", _PyCFunction_CAST(os__emscripten_log), METH_FASTCALL|METH_KEYWORDS, os__emscripten_log__doc__},
12985
12986
static PyObject *
12987
os__emscripten_log_impl(PyObject *module, const char *arg);
12988
12989
static PyObject *
12990
os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12991
{
12992
    PyObject *return_value = NULL;
12993
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12994
12995
    #define NUM_KEYWORDS 1
12996
    static struct {
12997
        PyGC_Head _this_is_not_used;
12998
        PyObject_VAR_HEAD
12999
        Py_hash_t ob_hash;
13000
        PyObject *ob_item[NUM_KEYWORDS];
13001
    } _kwtuple = {
13002
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
13003
        .ob_hash = -1,
13004
        .ob_item = { &_Py_ID(arg), },
13005
    };
13006
    #undef NUM_KEYWORDS
13007
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
13008
13009
    #else  // !Py_BUILD_CORE
13010
    #  define KWTUPLE NULL
13011
    #endif  // !Py_BUILD_CORE
13012
13013
    static const char * const _keywords[] = {"arg", NULL};
13014
    static _PyArg_Parser _parser = {
13015
        .keywords = _keywords,
13016
        .fname = "_emscripten_log",
13017
        .kwtuple = KWTUPLE,
13018
    };
13019
    #undef KWTUPLE
13020
    PyObject *argsbuf[1];
13021
    const char *arg;
13022
13023
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
13024
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
13025
    if (!args) {
13026
        goto exit;
13027
    }
13028
    if (!PyUnicode_Check(args[0])) {
13029
        _PyArg_BadArgument("_emscripten_log", "argument 'arg'", "str", args[0]);
13030
        goto exit;
13031
    }
13032
    Py_ssize_t arg_length;
13033
    arg = PyUnicode_AsUTF8AndSize(args[0], &arg_length);
13034
    if (arg == NULL) {
13035
        goto exit;
13036
    }
13037
    if (strlen(arg) != (size_t)arg_length) {
13038
        PyErr_SetString(PyExc_ValueError, "embedded null character");
13039
        goto exit;
13040
    }
13041
    return_value = os__emscripten_log_impl(module, arg);
13042
13043
exit:
13044
    return return_value;
13045
}
13046
13047
#endif /* defined(__EMSCRIPTEN__) */
13048
13049
#ifndef OS_STATX_METHODDEF
13050
    #define OS_STATX_METHODDEF
13051
#endif /* !defined(OS_STATX_METHODDEF) */
13052
13053
#ifndef OS_TTYNAME_METHODDEF
13054
    #define OS_TTYNAME_METHODDEF
13055
#endif /* !defined(OS_TTYNAME_METHODDEF) */
13056
13057
#ifndef OS_CTERMID_METHODDEF
13058
    #define OS_CTERMID_METHODDEF
13059
#endif /* !defined(OS_CTERMID_METHODDEF) */
13060
13061
#ifndef OS_FCHDIR_METHODDEF
13062
    #define OS_FCHDIR_METHODDEF
13063
#endif /* !defined(OS_FCHDIR_METHODDEF) */
13064
13065
#ifndef OS_FCHMOD_METHODDEF
13066
    #define OS_FCHMOD_METHODDEF
13067
#endif /* !defined(OS_FCHMOD_METHODDEF) */
13068
13069
#ifndef OS_LCHMOD_METHODDEF
13070
    #define OS_LCHMOD_METHODDEF
13071
#endif /* !defined(OS_LCHMOD_METHODDEF) */
13072
13073
#ifndef OS_CHFLAGS_METHODDEF
13074
    #define OS_CHFLAGS_METHODDEF
13075
#endif /* !defined(OS_CHFLAGS_METHODDEF) */
13076
13077
#ifndef OS_LCHFLAGS_METHODDEF
13078
    #define OS_LCHFLAGS_METHODDEF
13079
#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
13080
13081
#ifndef OS_CHROOT_METHODDEF
13082
    #define OS_CHROOT_METHODDEF
13083
#endif /* !defined(OS_CHROOT_METHODDEF) */
13084
13085
#ifndef OS_FSYNC_METHODDEF
13086
    #define OS_FSYNC_METHODDEF
13087
#endif /* !defined(OS_FSYNC_METHODDEF) */
13088
13089
#ifndef OS_SYNC_METHODDEF
13090
    #define OS_SYNC_METHODDEF
13091
#endif /* !defined(OS_SYNC_METHODDEF) */
13092
13093
#ifndef OS_FDATASYNC_METHODDEF
13094
    #define OS_FDATASYNC_METHODDEF
13095
#endif /* !defined(OS_FDATASYNC_METHODDEF) */
13096
13097
#ifndef OS_CHOWN_METHODDEF
13098
    #define OS_CHOWN_METHODDEF
13099
#endif /* !defined(OS_CHOWN_METHODDEF) */
13100
13101
#ifndef OS_FCHOWN_METHODDEF
13102
    #define OS_FCHOWN_METHODDEF
13103
#endif /* !defined(OS_FCHOWN_METHODDEF) */
13104
13105
#ifndef OS_LCHOWN_METHODDEF
13106
    #define OS_LCHOWN_METHODDEF
13107
#endif /* !defined(OS_LCHOWN_METHODDEF) */
13108
13109
#ifndef OS_LINK_METHODDEF
13110
    #define OS_LINK_METHODDEF
13111
#endif /* !defined(OS_LINK_METHODDEF) */
13112
13113
#ifndef OS_LISTDRIVES_METHODDEF
13114
    #define OS_LISTDRIVES_METHODDEF
13115
#endif /* !defined(OS_LISTDRIVES_METHODDEF) */
13116
13117
#ifndef OS_LISTVOLUMES_METHODDEF
13118
    #define OS_LISTVOLUMES_METHODDEF
13119
#endif /* !defined(OS_LISTVOLUMES_METHODDEF) */
13120
13121
#ifndef OS_LISTMOUNTS_METHODDEF
13122
    #define OS_LISTMOUNTS_METHODDEF
13123
#endif /* !defined(OS_LISTMOUNTS_METHODDEF) */
13124
13125
#ifndef OS__PATH_ISDEVDRIVE_METHODDEF
13126
    #define OS__PATH_ISDEVDRIVE_METHODDEF
13127
#endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */
13128
13129
#ifndef OS__GETFULLPATHNAME_METHODDEF
13130
    #define OS__GETFULLPATHNAME_METHODDEF
13131
#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
13132
13133
#ifndef OS__GETFINALPATHNAME_METHODDEF
13134
    #define OS__GETFINALPATHNAME_METHODDEF
13135
#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
13136
13137
#ifndef OS__FINDFIRSTFILE_METHODDEF
13138
    #define OS__FINDFIRSTFILE_METHODDEF
13139
#endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */
13140
13141
#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
13142
    #define OS__GETVOLUMEPATHNAME_METHODDEF
13143
#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
13144
13145
#ifndef OS__PATH_SPLITROOT_METHODDEF
13146
    #define OS__PATH_SPLITROOT_METHODDEF
13147
#endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */
13148
13149
#ifndef OS__PATH_EXISTS_METHODDEF
13150
    #define OS__PATH_EXISTS_METHODDEF
13151
#endif /* !defined(OS__PATH_EXISTS_METHODDEF) */
13152
13153
#ifndef OS__PATH_LEXISTS_METHODDEF
13154
    #define OS__PATH_LEXISTS_METHODDEF
13155
#endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */
13156
13157
#ifndef OS__PATH_ISDIR_METHODDEF
13158
    #define OS__PATH_ISDIR_METHODDEF
13159
#endif /* !defined(OS__PATH_ISDIR_METHODDEF) */
13160
13161
#ifndef OS__PATH_ISFILE_METHODDEF
13162
    #define OS__PATH_ISFILE_METHODDEF
13163
#endif /* !defined(OS__PATH_ISFILE_METHODDEF) */
13164
13165
#ifndef OS__PATH_ISLINK_METHODDEF
13166
    #define OS__PATH_ISLINK_METHODDEF
13167
#endif /* !defined(OS__PATH_ISLINK_METHODDEF) */
13168
13169
#ifndef OS__PATH_ISJUNCTION_METHODDEF
13170
    #define OS__PATH_ISJUNCTION_METHODDEF
13171
#endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */
13172
13173
#ifndef OS_NICE_METHODDEF
13174
    #define OS_NICE_METHODDEF
13175
#endif /* !defined(OS_NICE_METHODDEF) */
13176
13177
#ifndef OS_GETPRIORITY_METHODDEF
13178
    #define OS_GETPRIORITY_METHODDEF
13179
#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
13180
13181
#ifndef OS_SETPRIORITY_METHODDEF
13182
    #define OS_SETPRIORITY_METHODDEF
13183
#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
13184
13185
#ifndef OS_SYSTEM_METHODDEF
13186
    #define OS_SYSTEM_METHODDEF
13187
#endif /* !defined(OS_SYSTEM_METHODDEF) */
13188
13189
#ifndef OS_UMASK_METHODDEF
13190
    #define OS_UMASK_METHODDEF
13191
#endif /* !defined(OS_UMASK_METHODDEF) */
13192
13193
#ifndef OS_UNAME_METHODDEF
13194
    #define OS_UNAME_METHODDEF
13195
#endif /* !defined(OS_UNAME_METHODDEF) */
13196
13197
#ifndef OS_EXECV_METHODDEF
13198
    #define OS_EXECV_METHODDEF
13199
#endif /* !defined(OS_EXECV_METHODDEF) */
13200
13201
#ifndef OS_EXECVE_METHODDEF
13202
    #define OS_EXECVE_METHODDEF
13203
#endif /* !defined(OS_EXECVE_METHODDEF) */
13204
13205
#ifndef OS_POSIX_SPAWN_METHODDEF
13206
    #define OS_POSIX_SPAWN_METHODDEF
13207
#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
13208
13209
#ifndef OS_POSIX_SPAWNP_METHODDEF
13210
    #define OS_POSIX_SPAWNP_METHODDEF
13211
#endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
13212
13213
#ifndef OS_SPAWNV_METHODDEF
13214
    #define OS_SPAWNV_METHODDEF
13215
#endif /* !defined(OS_SPAWNV_METHODDEF) */
13216
13217
#ifndef OS_SPAWNVE_METHODDEF
13218
    #define OS_SPAWNVE_METHODDEF
13219
#endif /* !defined(OS_SPAWNVE_METHODDEF) */
13220
13221
#ifndef OS_REGISTER_AT_FORK_METHODDEF
13222
    #define OS_REGISTER_AT_FORK_METHODDEF
13223
#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
13224
13225
#ifndef OS_FORK1_METHODDEF
13226
    #define OS_FORK1_METHODDEF
13227
#endif /* !defined(OS_FORK1_METHODDEF) */
13228
13229
#ifndef OS_FORK_METHODDEF
13230
    #define OS_FORK_METHODDEF
13231
#endif /* !defined(OS_FORK_METHODDEF) */
13232
13233
#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
13234
    #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
13235
#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
13236
13237
#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
13238
    #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
13239
#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
13240
13241
#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
13242
    #define OS_SCHED_GETSCHEDULER_METHODDEF
13243
#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
13244
13245
#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
13246
    #define OS_SCHED_SETSCHEDULER_METHODDEF
13247
#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
13248
13249
#ifndef OS_SCHED_GETPARAM_METHODDEF
13250
    #define OS_SCHED_GETPARAM_METHODDEF
13251
#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
13252
13253
#ifndef OS_SCHED_SETPARAM_METHODDEF
13254
    #define OS_SCHED_SETPARAM_METHODDEF
13255
#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
13256
13257
#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
13258
    #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
13259
#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
13260
13261
#ifndef OS_SCHED_YIELD_METHODDEF
13262
    #define OS_SCHED_YIELD_METHODDEF
13263
#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
13264
13265
#ifndef OS_SCHED_SETAFFINITY_METHODDEF
13266
    #define OS_SCHED_SETAFFINITY_METHODDEF
13267
#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
13268
13269
#ifndef OS_SCHED_GETAFFINITY_METHODDEF
13270
    #define OS_SCHED_GETAFFINITY_METHODDEF
13271
#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
13272
13273
#ifndef OS_POSIX_OPENPT_METHODDEF
13274
    #define OS_POSIX_OPENPT_METHODDEF
13275
#endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */
13276
13277
#ifndef OS_GRANTPT_METHODDEF
13278
    #define OS_GRANTPT_METHODDEF
13279
#endif /* !defined(OS_GRANTPT_METHODDEF) */
13280
13281
#ifndef OS_UNLOCKPT_METHODDEF
13282
    #define OS_UNLOCKPT_METHODDEF
13283
#endif /* !defined(OS_UNLOCKPT_METHODDEF) */
13284
13285
#ifndef OS_PTSNAME_METHODDEF
13286
    #define OS_PTSNAME_METHODDEF
13287
#endif /* !defined(OS_PTSNAME_METHODDEF) */
13288
13289
#ifndef OS_OPENPTY_METHODDEF
13290
    #define OS_OPENPTY_METHODDEF
13291
#endif /* !defined(OS_OPENPTY_METHODDEF) */
13292
13293
#ifndef OS_LOGIN_TTY_METHODDEF
13294
    #define OS_LOGIN_TTY_METHODDEF
13295
#endif /* !defined(OS_LOGIN_TTY_METHODDEF) */
13296
13297
#ifndef OS_FORKPTY_METHODDEF
13298
    #define OS_FORKPTY_METHODDEF
13299
#endif /* !defined(OS_FORKPTY_METHODDEF) */
13300
13301
#ifndef OS_GETEGID_METHODDEF
13302
    #define OS_GETEGID_METHODDEF
13303
#endif /* !defined(OS_GETEGID_METHODDEF) */
13304
13305
#ifndef OS_GETEUID_METHODDEF
13306
    #define OS_GETEUID_METHODDEF
13307
#endif /* !defined(OS_GETEUID_METHODDEF) */
13308
13309
#ifndef OS_GETGID_METHODDEF
13310
    #define OS_GETGID_METHODDEF
13311
#endif /* !defined(OS_GETGID_METHODDEF) */
13312
13313
#ifndef OS_GETPID_METHODDEF
13314
    #define OS_GETPID_METHODDEF
13315
#endif /* !defined(OS_GETPID_METHODDEF) */
13316
13317
#ifndef OS_GETGROUPLIST_METHODDEF
13318
    #define OS_GETGROUPLIST_METHODDEF
13319
#endif /* !defined(OS_GETGROUPLIST_METHODDEF) */
13320
13321
#ifndef OS_GETGROUPS_METHODDEF
13322
    #define OS_GETGROUPS_METHODDEF
13323
#endif /* !defined(OS_GETGROUPS_METHODDEF) */
13324
13325
#ifndef OS_INITGROUPS_METHODDEF
13326
    #define OS_INITGROUPS_METHODDEF
13327
#endif /* !defined(OS_INITGROUPS_METHODDEF) */
13328
13329
#ifndef OS_GETPGID_METHODDEF
13330
    #define OS_GETPGID_METHODDEF
13331
#endif /* !defined(OS_GETPGID_METHODDEF) */
13332
13333
#ifndef OS_GETPGRP_METHODDEF
13334
    #define OS_GETPGRP_METHODDEF
13335
#endif /* !defined(OS_GETPGRP_METHODDEF) */
13336
13337
#ifndef OS_SETPGRP_METHODDEF
13338
    #define OS_SETPGRP_METHODDEF
13339
#endif /* !defined(OS_SETPGRP_METHODDEF) */
13340
13341
#ifndef OS_GETPPID_METHODDEF
13342
    #define OS_GETPPID_METHODDEF
13343
#endif /* !defined(OS_GETPPID_METHODDEF) */
13344
13345
#ifndef OS_GETLOGIN_METHODDEF
13346
    #define OS_GETLOGIN_METHODDEF
13347
#endif /* !defined(OS_GETLOGIN_METHODDEF) */
13348
13349
#ifndef OS_GETUID_METHODDEF
13350
    #define OS_GETUID_METHODDEF
13351
#endif /* !defined(OS_GETUID_METHODDEF) */
13352
13353
#ifndef OS_KILL_METHODDEF
13354
    #define OS_KILL_METHODDEF
13355
#endif /* !defined(OS_KILL_METHODDEF) */
13356
13357
#ifndef OS_KILLPG_METHODDEF
13358
    #define OS_KILLPG_METHODDEF
13359
#endif /* !defined(OS_KILLPG_METHODDEF) */
13360
13361
#ifndef OS_PLOCK_METHODDEF
13362
    #define OS_PLOCK_METHODDEF
13363
#endif /* !defined(OS_PLOCK_METHODDEF) */
13364
13365
#ifndef OS_SETUID_METHODDEF
13366
    #define OS_SETUID_METHODDEF
13367
#endif /* !defined(OS_SETUID_METHODDEF) */
13368
13369
#ifndef OS_SETEUID_METHODDEF
13370
    #define OS_SETEUID_METHODDEF
13371
#endif /* !defined(OS_SETEUID_METHODDEF) */
13372
13373
#ifndef OS_SETEGID_METHODDEF
13374
    #define OS_SETEGID_METHODDEF
13375
#endif /* !defined(OS_SETEGID_METHODDEF) */
13376
13377
#ifndef OS_SETREUID_METHODDEF
13378
    #define OS_SETREUID_METHODDEF
13379
#endif /* !defined(OS_SETREUID_METHODDEF) */
13380
13381
#ifndef OS_SETREGID_METHODDEF
13382
    #define OS_SETREGID_METHODDEF
13383
#endif /* !defined(OS_SETREGID_METHODDEF) */
13384
13385
#ifndef OS_SETGID_METHODDEF
13386
    #define OS_SETGID_METHODDEF
13387
#endif /* !defined(OS_SETGID_METHODDEF) */
13388
13389
#ifndef OS_SETGROUPS_METHODDEF
13390
    #define OS_SETGROUPS_METHODDEF
13391
#endif /* !defined(OS_SETGROUPS_METHODDEF) */
13392
13393
#ifndef OS_WAIT3_METHODDEF
13394
    #define OS_WAIT3_METHODDEF
13395
#endif /* !defined(OS_WAIT3_METHODDEF) */
13396
13397
#ifndef OS_WAIT4_METHODDEF
13398
    #define OS_WAIT4_METHODDEF
13399
#endif /* !defined(OS_WAIT4_METHODDEF) */
13400
13401
#ifndef OS_WAITID_METHODDEF
13402
    #define OS_WAITID_METHODDEF
13403
#endif /* !defined(OS_WAITID_METHODDEF) */
13404
13405
#ifndef OS_WAITPID_METHODDEF
13406
    #define OS_WAITPID_METHODDEF
13407
#endif /* !defined(OS_WAITPID_METHODDEF) */
13408
13409
#ifndef OS_WAIT_METHODDEF
13410
    #define OS_WAIT_METHODDEF
13411
#endif /* !defined(OS_WAIT_METHODDEF) */
13412
13413
#ifndef OS_PIDFD_OPEN_METHODDEF
13414
    #define OS_PIDFD_OPEN_METHODDEF
13415
#endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */
13416
13417
#ifndef OS_PIDFD_GETFD_METHODDEF
13418
    #define OS_PIDFD_GETFD_METHODDEF
13419
#endif /* !defined(OS_PIDFD_GETFD_METHODDEF) */
13420
13421
#ifndef OS_SETNS_METHODDEF
13422
    #define OS_SETNS_METHODDEF
13423
#endif /* !defined(OS_SETNS_METHODDEF) */
13424
13425
#ifndef OS_UNSHARE_METHODDEF
13426
    #define OS_UNSHARE_METHODDEF
13427
#endif /* !defined(OS_UNSHARE_METHODDEF) */
13428
13429
#ifndef OS_READLINK_METHODDEF
13430
    #define OS_READLINK_METHODDEF
13431
#endif /* !defined(OS_READLINK_METHODDEF) */
13432
13433
#ifndef OS_SYMLINK_METHODDEF
13434
    #define OS_SYMLINK_METHODDEF
13435
#endif /* !defined(OS_SYMLINK_METHODDEF) */
13436
13437
#ifndef OS_TIMERFD_CREATE_METHODDEF
13438
    #define OS_TIMERFD_CREATE_METHODDEF
13439
#endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */
13440
13441
#ifndef OS_TIMERFD_SETTIME_METHODDEF
13442
    #define OS_TIMERFD_SETTIME_METHODDEF
13443
#endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */
13444
13445
#ifndef OS_TIMERFD_SETTIME_NS_METHODDEF
13446
    #define OS_TIMERFD_SETTIME_NS_METHODDEF
13447
#endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */
13448
13449
#ifndef OS_TIMERFD_GETTIME_METHODDEF
13450
    #define OS_TIMERFD_GETTIME_METHODDEF
13451
#endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */
13452
13453
#ifndef OS_TIMERFD_GETTIME_NS_METHODDEF
13454
    #define OS_TIMERFD_GETTIME_NS_METHODDEF
13455
#endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */
13456
13457
#ifndef OS_GETSID_METHODDEF
13458
    #define OS_GETSID_METHODDEF
13459
#endif /* !defined(OS_GETSID_METHODDEF) */
13460
13461
#ifndef OS_SETSID_METHODDEF
13462
    #define OS_SETSID_METHODDEF
13463
#endif /* !defined(OS_SETSID_METHODDEF) */
13464
13465
#ifndef OS_SETPGID_METHODDEF
13466
    #define OS_SETPGID_METHODDEF
13467
#endif /* !defined(OS_SETPGID_METHODDEF) */
13468
13469
#ifndef OS_TCGETPGRP_METHODDEF
13470
    #define OS_TCGETPGRP_METHODDEF
13471
#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
13472
13473
#ifndef OS_TCSETPGRP_METHODDEF
13474
    #define OS_TCSETPGRP_METHODDEF
13475
#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
13476
13477
#ifndef OS_DUP2_METHODDEF
13478
    #define OS_DUP2_METHODDEF
13479
#endif /* !defined(OS_DUP2_METHODDEF) */
13480
13481
#ifndef OS_LOCKF_METHODDEF
13482
    #define OS_LOCKF_METHODDEF
13483
#endif /* !defined(OS_LOCKF_METHODDEF) */
13484
13485
#ifndef OS_READV_METHODDEF
13486
    #define OS_READV_METHODDEF
13487
#endif /* !defined(OS_READV_METHODDEF) */
13488
13489
#ifndef OS_PREAD_METHODDEF
13490
    #define OS_PREAD_METHODDEF
13491
#endif /* !defined(OS_PREAD_METHODDEF) */
13492
13493
#ifndef OS_PREADV_METHODDEF
13494
    #define OS_PREADV_METHODDEF
13495
#endif /* !defined(OS_PREADV_METHODDEF) */
13496
13497
#ifndef OS_SENDFILE_METHODDEF
13498
    #define OS_SENDFILE_METHODDEF
13499
#endif /* !defined(OS_SENDFILE_METHODDEF) */
13500
13501
#ifndef OS__FCOPYFILE_METHODDEF
13502
    #define OS__FCOPYFILE_METHODDEF
13503
#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
13504
13505
#ifndef OS_PIPE_METHODDEF
13506
    #define OS_PIPE_METHODDEF
13507
#endif /* !defined(OS_PIPE_METHODDEF) */
13508
13509
#ifndef OS_PIPE2_METHODDEF
13510
    #define OS_PIPE2_METHODDEF
13511
#endif /* !defined(OS_PIPE2_METHODDEF) */
13512
13513
#ifndef OS_WRITEV_METHODDEF
13514
    #define OS_WRITEV_METHODDEF
13515
#endif /* !defined(OS_WRITEV_METHODDEF) */
13516
13517
#ifndef OS_PWRITE_METHODDEF
13518
    #define OS_PWRITE_METHODDEF
13519
#endif /* !defined(OS_PWRITE_METHODDEF) */
13520
13521
#ifndef OS_PWRITEV_METHODDEF
13522
    #define OS_PWRITEV_METHODDEF
13523
#endif /* !defined(OS_PWRITEV_METHODDEF) */
13524
13525
#ifndef OS_COPY_FILE_RANGE_METHODDEF
13526
    #define OS_COPY_FILE_RANGE_METHODDEF
13527
#endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
13528
13529
#ifndef OS_SPLICE_METHODDEF
13530
    #define OS_SPLICE_METHODDEF
13531
#endif /* !defined(OS_SPLICE_METHODDEF) */
13532
13533
#ifndef OS_MKFIFO_METHODDEF
13534
    #define OS_MKFIFO_METHODDEF
13535
#endif /* !defined(OS_MKFIFO_METHODDEF) */
13536
13537
#ifndef OS_MKNOD_METHODDEF
13538
    #define OS_MKNOD_METHODDEF
13539
#endif /* !defined(OS_MKNOD_METHODDEF) */
13540
13541
#ifndef OS_MAJOR_METHODDEF
13542
    #define OS_MAJOR_METHODDEF
13543
#endif /* !defined(OS_MAJOR_METHODDEF) */
13544
13545
#ifndef OS_MINOR_METHODDEF
13546
    #define OS_MINOR_METHODDEF
13547
#endif /* !defined(OS_MINOR_METHODDEF) */
13548
13549
#ifndef OS_MAKEDEV_METHODDEF
13550
    #define OS_MAKEDEV_METHODDEF
13551
#endif /* !defined(OS_MAKEDEV_METHODDEF) */
13552
13553
#ifndef OS_FTRUNCATE_METHODDEF
13554
    #define OS_FTRUNCATE_METHODDEF
13555
#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
13556
13557
#ifndef OS_TRUNCATE_METHODDEF
13558
    #define OS_TRUNCATE_METHODDEF
13559
#endif /* !defined(OS_TRUNCATE_METHODDEF) */
13560
13561
#ifndef OS_POSIX_FALLOCATE_METHODDEF
13562
    #define OS_POSIX_FALLOCATE_METHODDEF
13563
#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
13564
13565
#ifndef OS_POSIX_FADVISE_METHODDEF
13566
    #define OS_POSIX_FADVISE_METHODDEF
13567
#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
13568
13569
#ifndef OS_PUTENV_METHODDEF
13570
    #define OS_PUTENV_METHODDEF
13571
#endif /* !defined(OS_PUTENV_METHODDEF) */
13572
13573
#ifndef OS_UNSETENV_METHODDEF
13574
    #define OS_UNSETENV_METHODDEF
13575
#endif /* !defined(OS_UNSETENV_METHODDEF) */
13576
13577
#ifndef OS__CLEARENV_METHODDEF
13578
    #define OS__CLEARENV_METHODDEF
13579
#endif /* !defined(OS__CLEARENV_METHODDEF) */
13580
13581
#ifndef OS_WCOREDUMP_METHODDEF
13582
    #define OS_WCOREDUMP_METHODDEF
13583
#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
13584
13585
#ifndef OS_WIFCONTINUED_METHODDEF
13586
    #define OS_WIFCONTINUED_METHODDEF
13587
#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
13588
13589
#ifndef OS_WIFSTOPPED_METHODDEF
13590
    #define OS_WIFSTOPPED_METHODDEF
13591
#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
13592
13593
#ifndef OS_WIFSIGNALED_METHODDEF
13594
    #define OS_WIFSIGNALED_METHODDEF
13595
#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
13596
13597
#ifndef OS_WIFEXITED_METHODDEF
13598
    #define OS_WIFEXITED_METHODDEF
13599
#endif /* !defined(OS_WIFEXITED_METHODDEF) */
13600
13601
#ifndef OS_WEXITSTATUS_METHODDEF
13602
    #define OS_WEXITSTATUS_METHODDEF
13603
#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
13604
13605
#ifndef OS_WTERMSIG_METHODDEF
13606
    #define OS_WTERMSIG_METHODDEF
13607
#endif /* !defined(OS_WTERMSIG_METHODDEF) */
13608
13609
#ifndef OS_WSTOPSIG_METHODDEF
13610
    #define OS_WSTOPSIG_METHODDEF
13611
#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
13612
13613
#ifndef OS_FSTATVFS_METHODDEF
13614
    #define OS_FSTATVFS_METHODDEF
13615
#endif /* !defined(OS_FSTATVFS_METHODDEF) */
13616
13617
#ifndef OS_STATVFS_METHODDEF
13618
    #define OS_STATVFS_METHODDEF
13619
#endif /* !defined(OS_STATVFS_METHODDEF) */
13620
13621
#ifndef OS__GETDISKUSAGE_METHODDEF
13622
    #define OS__GETDISKUSAGE_METHODDEF
13623
#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
13624
13625
#ifndef OS_FPATHCONF_METHODDEF
13626
    #define OS_FPATHCONF_METHODDEF
13627
#endif /* !defined(OS_FPATHCONF_METHODDEF) */
13628
13629
#ifndef OS_PATHCONF_METHODDEF
13630
    #define OS_PATHCONF_METHODDEF
13631
#endif /* !defined(OS_PATHCONF_METHODDEF) */
13632
13633
#ifndef OS_CONFSTR_METHODDEF
13634
    #define OS_CONFSTR_METHODDEF
13635
#endif /* !defined(OS_CONFSTR_METHODDEF) */
13636
13637
#ifndef OS_SYSCONF_METHODDEF
13638
    #define OS_SYSCONF_METHODDEF
13639
#endif /* !defined(OS_SYSCONF_METHODDEF) */
13640
13641
#ifndef OS_STARTFILE_METHODDEF
13642
    #define OS_STARTFILE_METHODDEF
13643
#endif /* !defined(OS_STARTFILE_METHODDEF) */
13644
13645
#ifndef OS_GETLOADAVG_METHODDEF
13646
    #define OS_GETLOADAVG_METHODDEF
13647
#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
13648
13649
#ifndef OS_SETRESUID_METHODDEF
13650
    #define OS_SETRESUID_METHODDEF
13651
#endif /* !defined(OS_SETRESUID_METHODDEF) */
13652
13653
#ifndef OS_SETRESGID_METHODDEF
13654
    #define OS_SETRESGID_METHODDEF
13655
#endif /* !defined(OS_SETRESGID_METHODDEF) */
13656
13657
#ifndef OS_GETRESUID_METHODDEF
13658
    #define OS_GETRESUID_METHODDEF
13659
#endif /* !defined(OS_GETRESUID_METHODDEF) */
13660
13661
#ifndef OS_GETRESGID_METHODDEF
13662
    #define OS_GETRESGID_METHODDEF
13663
#endif /* !defined(OS_GETRESGID_METHODDEF) */
13664
13665
#ifndef OS_GETXATTR_METHODDEF
13666
    #define OS_GETXATTR_METHODDEF
13667
#endif /* !defined(OS_GETXATTR_METHODDEF) */
13668
13669
#ifndef OS_SETXATTR_METHODDEF
13670
    #define OS_SETXATTR_METHODDEF
13671
#endif /* !defined(OS_SETXATTR_METHODDEF) */
13672
13673
#ifndef OS_REMOVEXATTR_METHODDEF
13674
    #define OS_REMOVEXATTR_METHODDEF
13675
#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
13676
13677
#ifndef OS_LISTXATTR_METHODDEF
13678
    #define OS_LISTXATTR_METHODDEF
13679
#endif /* !defined(OS_LISTXATTR_METHODDEF) */
13680
13681
#ifndef OS_MEMFD_CREATE_METHODDEF
13682
    #define OS_MEMFD_CREATE_METHODDEF
13683
#endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */
13684
13685
#ifndef OS_EVENTFD_METHODDEF
13686
    #define OS_EVENTFD_METHODDEF
13687
#endif /* !defined(OS_EVENTFD_METHODDEF) */
13688
13689
#ifndef OS_EVENTFD_READ_METHODDEF
13690
    #define OS_EVENTFD_READ_METHODDEF
13691
#endif /* !defined(OS_EVENTFD_READ_METHODDEF) */
13692
13693
#ifndef OS_EVENTFD_WRITE_METHODDEF
13694
    #define OS_EVENTFD_WRITE_METHODDEF
13695
#endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */
13696
13697
#ifndef OS_GET_TERMINAL_SIZE_METHODDEF
13698
    #define OS_GET_TERMINAL_SIZE_METHODDEF
13699
#endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */
13700
13701
#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
13702
    #define OS_GET_HANDLE_INHERITABLE_METHODDEF
13703
#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
13704
13705
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
13706
    #define OS_SET_HANDLE_INHERITABLE_METHODDEF
13707
#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
13708
13709
#ifndef OS_GETRANDOM_METHODDEF
13710
    #define OS_GETRANDOM_METHODDEF
13711
#endif /* !defined(OS_GETRANDOM_METHODDEF) */
13712
13713
#ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
13714
    #define OS__ADD_DLL_DIRECTORY_METHODDEF
13715
#endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
13716
13717
#ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
13718
    #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
13719
#endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
13720
13721
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13722
    #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13723
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
13724
13725
#ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13726
    #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13727
#endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */
13728
13729
#ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13730
    #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13731
#endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */
13732
13733
#ifndef OS__EMSCRIPTEN_LOG_METHODDEF
13734
    #define OS__EMSCRIPTEN_LOG_METHODDEF
13735
#endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */
13736
/*[clinic end generated code: output=250ea2e34fdd133f input=a9049054013a1b77]*/