Coverage Report

Created: 2025-10-10 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/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
5.57k
{
47
5.57k
    PyObject *return_value = NULL;
48
5.57k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
49
50
5.57k
    #define NUM_KEYWORDS 3
51
5.57k
    static struct {
52
5.57k
        PyGC_Head _this_is_not_used;
53
5.57k
        PyObject_VAR_HEAD
54
5.57k
        Py_hash_t ob_hash;
55
5.57k
        PyObject *ob_item[NUM_KEYWORDS];
56
5.57k
    } _kwtuple = {
57
5.57k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
58
5.57k
        .ob_hash = -1,
59
5.57k
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
60
5.57k
    };
61
5.57k
    #undef NUM_KEYWORDS
62
5.57k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
63
64
    #else  // !Py_BUILD_CORE
65
    #  define KWTUPLE NULL
66
    #endif  // !Py_BUILD_CORE
67
68
5.57k
    static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
69
5.57k
    static _PyArg_Parser _parser = {
70
5.57k
        .keywords = _keywords,
71
5.57k
        .fname = "stat",
72
5.57k
        .kwtuple = KWTUPLE,
73
5.57k
    };
74
5.57k
    #undef KWTUPLE
75
5.57k
    PyObject *argsbuf[3];
76
5.57k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
77
5.57k
    path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1);
78
5.57k
    int dir_fd = DEFAULT_DIR_FD;
79
5.57k
    int follow_symlinks = 1;
80
81
5.57k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
82
5.57k
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
83
5.57k
    if (!args) {
84
0
        goto exit;
85
0
    }
86
5.57k
    if (!path_converter(args[0], &path)) {
87
0
        goto exit;
88
0
    }
89
5.57k
    if (!noptargs) {
90
5.57k
        goto skip_optional_kwonly;
91
5.57k
    }
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
5.57k
skip_optional_kwonly:
105
5.57k
    return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
106
107
5.57k
exit:
108
    /* Cleanup for path */
109
5.57k
    path_cleanup(&path);
110
111
5.57k
    return return_value;
112
5.57k
}
113
114
PyDoc_STRVAR(os_lstat__doc__,
115
"lstat($module, /, path, *, dir_fd=None)\n"
116
"--\n"
117
"\n"
118
"Perform a stat system call on the given path, without following symbolic links.\n"
119
"\n"
120
"Like stat(), but do not follow symbolic links.\n"
121
"Equivalent to stat(path, follow_symlinks=False).");
122
123
#define OS_LSTAT_METHODDEF    \
124
    {"lstat", _PyCFunction_CAST(os_lstat), METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
125
126
static PyObject *
127
os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
128
129
static PyObject *
130
os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
131
0
{
132
0
    PyObject *return_value = NULL;
133
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
134
135
0
    #define NUM_KEYWORDS 2
136
0
    static struct {
137
0
        PyGC_Head _this_is_not_used;
138
0
        PyObject_VAR_HEAD
139
0
        Py_hash_t ob_hash;
140
0
        PyObject *ob_item[NUM_KEYWORDS];
141
0
    } _kwtuple = {
142
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
143
0
        .ob_hash = -1,
144
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
145
0
    };
146
0
    #undef NUM_KEYWORDS
147
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
148
149
    #else  // !Py_BUILD_CORE
150
    #  define KWTUPLE NULL
151
    #endif  // !Py_BUILD_CORE
152
153
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
154
0
    static _PyArg_Parser _parser = {
155
0
        .keywords = _keywords,
156
0
        .fname = "lstat",
157
0
        .kwtuple = KWTUPLE,
158
0
    };
159
0
    #undef KWTUPLE
160
0
    PyObject *argsbuf[2];
161
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
162
0
    path_t path = PATH_T_INITIALIZE_P("lstat", "path", 0, 0, 0, 0);
163
0
    int dir_fd = DEFAULT_DIR_FD;
164
165
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
166
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
167
0
    if (!args) {
168
0
        goto exit;
169
0
    }
170
0
    if (!path_converter(args[0], &path)) {
171
0
        goto exit;
172
0
    }
173
0
    if (!noptargs) {
174
0
        goto skip_optional_kwonly;
175
0
    }
176
0
    if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
177
0
        goto exit;
178
0
    }
179
0
skip_optional_kwonly:
180
0
    return_value = os_lstat_impl(module, &path, dir_fd);
181
182
0
exit:
183
    /* Cleanup for path */
184
0
    path_cleanup(&path);
185
186
0
    return return_value;
187
0
}
188
189
PyDoc_STRVAR(os_access__doc__,
190
"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
191
"       follow_symlinks=True)\n"
192
"--\n"
193
"\n"
194
"Use the real uid/gid to test for access to a path.\n"
195
"\n"
196
"  path\n"
197
"    Path to be tested; can be string, bytes, or a path-like object.\n"
198
"  mode\n"
199
"    Operating-system mode bitfield.  Can be F_OK to test existence,\n"
200
"    or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
201
"  dir_fd\n"
202
"    If not None, it should be a file descriptor open to a directory,\n"
203
"    and path should be relative; path will then be relative to that\n"
204
"    directory.\n"
205
"  effective_ids\n"
206
"    If True, access will use the effective uid/gid instead of\n"
207
"    the real uid/gid.\n"
208
"  follow_symlinks\n"
209
"    If False, and the last element of the path is a symbolic link,\n"
210
"    access will examine the symbolic link itself instead of the file\n"
211
"    the link points to.\n"
212
"\n"
213
"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
214
"  on your platform.  If they are unavailable, using them will raise a\n"
215
"  NotImplementedError.\n"
216
"\n"
217
"Note that most operations will use the effective uid/gid, therefore this\n"
218
"  routine can be used in a suid/sgid environment to test if the invoking\n"
219
"  user has the specified access to the path.");
220
221
#define OS_ACCESS_METHODDEF    \
222
    {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
223
224
static int
225
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
226
               int effective_ids, int follow_symlinks);
227
228
static PyObject *
229
os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
230
0
{
231
0
    PyObject *return_value = NULL;
232
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
233
234
0
    #define NUM_KEYWORDS 5
235
0
    static struct {
236
0
        PyGC_Head _this_is_not_used;
237
0
        PyObject_VAR_HEAD
238
0
        Py_hash_t ob_hash;
239
0
        PyObject *ob_item[NUM_KEYWORDS];
240
0
    } _kwtuple = {
241
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
242
0
        .ob_hash = -1,
243
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), },
244
0
    };
245
0
    #undef NUM_KEYWORDS
246
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
247
248
    #else  // !Py_BUILD_CORE
249
    #  define KWTUPLE NULL
250
    #endif  // !Py_BUILD_CORE
251
252
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
253
0
    static _PyArg_Parser _parser = {
254
0
        .keywords = _keywords,
255
0
        .fname = "access",
256
0
        .kwtuple = KWTUPLE,
257
0
    };
258
0
    #undef KWTUPLE
259
0
    PyObject *argsbuf[5];
260
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
261
0
    path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0);
262
0
    int mode;
263
0
    int dir_fd = DEFAULT_DIR_FD;
264
0
    int effective_ids = 0;
265
0
    int follow_symlinks = 1;
266
0
    int _return_value;
267
268
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
269
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
270
0
    if (!args) {
271
0
        goto exit;
272
0
    }
273
0
    if (!path_converter(args[0], &path)) {
274
0
        goto exit;
275
0
    }
276
0
    mode = PyLong_AsInt(args[1]);
277
0
    if (mode == -1 && PyErr_Occurred()) {
278
0
        goto exit;
279
0
    }
280
0
    if (!noptargs) {
281
0
        goto skip_optional_kwonly;
282
0
    }
283
0
    if (args[2]) {
284
0
        if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
285
0
            goto exit;
286
0
        }
287
0
        if (!--noptargs) {
288
0
            goto skip_optional_kwonly;
289
0
        }
290
0
    }
291
0
    if (args[3]) {
292
0
        effective_ids = PyObject_IsTrue(args[3]);
293
0
        if (effective_ids < 0) {
294
0
            goto exit;
295
0
        }
296
0
        if (!--noptargs) {
297
0
            goto skip_optional_kwonly;
298
0
        }
299
0
    }
300
0
    follow_symlinks = PyObject_IsTrue(args[4]);
301
0
    if (follow_symlinks < 0) {
302
0
        goto exit;
303
0
    }
304
0
skip_optional_kwonly:
305
0
    _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
306
0
    if ((_return_value == -1) && PyErr_Occurred()) {
307
0
        goto exit;
308
0
    }
309
0
    return_value = PyBool_FromLong((long)_return_value);
310
311
0
exit:
312
    /* Cleanup for path */
313
0
    path_cleanup(&path);
314
315
0
    return return_value;
316
0
}
317
318
#if defined(HAVE_TTYNAME_R)
319
320
PyDoc_STRVAR(os_ttyname__doc__,
321
"ttyname($module, fd, /)\n"
322
"--\n"
323
"\n"
324
"Return the name of the terminal device connected to \'fd\'.\n"
325
"\n"
326
"  fd\n"
327
"    Integer file descriptor handle.");
328
329
#define OS_TTYNAME_METHODDEF    \
330
    {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
331
332
static PyObject *
333
os_ttyname_impl(PyObject *module, int fd);
334
335
static PyObject *
336
os_ttyname(PyObject *module, PyObject *arg)
337
0
{
338
0
    PyObject *return_value = NULL;
339
0
    int fd;
340
341
0
    fd = PyLong_AsInt(arg);
342
0
    if (fd == -1 && PyErr_Occurred()) {
343
0
        goto exit;
344
0
    }
345
0
    return_value = os_ttyname_impl(module, fd);
346
347
0
exit:
348
0
    return return_value;
349
0
}
350
351
#endif /* defined(HAVE_TTYNAME_R) */
352
353
#if defined(HAVE_CTERMID)
354
355
PyDoc_STRVAR(os_ctermid__doc__,
356
"ctermid($module, /)\n"
357
"--\n"
358
"\n"
359
"Return the name of the controlling terminal for this process.");
360
361
#define OS_CTERMID_METHODDEF    \
362
    {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
363
364
static PyObject *
365
os_ctermid_impl(PyObject *module);
366
367
static PyObject *
368
os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
369
0
{
370
0
    return os_ctermid_impl(module);
371
0
}
372
373
#endif /* defined(HAVE_CTERMID) */
374
375
PyDoc_STRVAR(os_chdir__doc__,
376
"chdir($module, /, path)\n"
377
"--\n"
378
"\n"
379
"Change the current working directory to the specified path.\n"
380
"\n"
381
"path may always be specified as a string.\n"
382
"On some platforms, path may also be specified as an open file descriptor.\n"
383
"If this functionality is unavailable, using it raises an exception.");
384
385
#define OS_CHDIR_METHODDEF    \
386
    {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
387
388
static PyObject *
389
os_chdir_impl(PyObject *module, path_t *path);
390
391
static PyObject *
392
os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
393
0
{
394
0
    PyObject *return_value = NULL;
395
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
396
397
0
    #define NUM_KEYWORDS 1
398
0
    static struct {
399
0
        PyGC_Head _this_is_not_used;
400
0
        PyObject_VAR_HEAD
401
0
        Py_hash_t ob_hash;
402
0
        PyObject *ob_item[NUM_KEYWORDS];
403
0
    } _kwtuple = {
404
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
405
0
        .ob_hash = -1,
406
0
        .ob_item = { &_Py_ID(path), },
407
0
    };
408
0
    #undef NUM_KEYWORDS
409
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
410
411
    #else  // !Py_BUILD_CORE
412
    #  define KWTUPLE NULL
413
    #endif  // !Py_BUILD_CORE
414
415
0
    static const char * const _keywords[] = {"path", NULL};
416
0
    static _PyArg_Parser _parser = {
417
0
        .keywords = _keywords,
418
0
        .fname = "chdir",
419
0
        .kwtuple = KWTUPLE,
420
0
    };
421
0
    #undef KWTUPLE
422
0
    PyObject *argsbuf[1];
423
0
    path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR);
424
425
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
426
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
427
0
    if (!args) {
428
0
        goto exit;
429
0
    }
430
0
    if (!path_converter(args[0], &path)) {
431
0
        goto exit;
432
0
    }
433
0
    return_value = os_chdir_impl(module, &path);
434
435
0
exit:
436
    /* Cleanup for path */
437
0
    path_cleanup(&path);
438
439
0
    return return_value;
440
0
}
441
442
#if defined(HAVE_FCHDIR)
443
444
PyDoc_STRVAR(os_fchdir__doc__,
445
"fchdir($module, /, fd)\n"
446
"--\n"
447
"\n"
448
"Change to the directory of the given file descriptor.\n"
449
"\n"
450
"fd must be opened on a directory, not a file.\n"
451
"Equivalent to os.chdir(fd).");
452
453
#define OS_FCHDIR_METHODDEF    \
454
    {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
455
456
static PyObject *
457
os_fchdir_impl(PyObject *module, int fd);
458
459
static PyObject *
460
os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
461
0
{
462
0
    PyObject *return_value = NULL;
463
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
464
465
0
    #define NUM_KEYWORDS 1
466
0
    static struct {
467
0
        PyGC_Head _this_is_not_used;
468
0
        PyObject_VAR_HEAD
469
0
        Py_hash_t ob_hash;
470
0
        PyObject *ob_item[NUM_KEYWORDS];
471
0
    } _kwtuple = {
472
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
473
0
        .ob_hash = -1,
474
0
        .ob_item = { &_Py_ID(fd), },
475
0
    };
476
0
    #undef NUM_KEYWORDS
477
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
478
479
    #else  // !Py_BUILD_CORE
480
    #  define KWTUPLE NULL
481
    #endif  // !Py_BUILD_CORE
482
483
0
    static const char * const _keywords[] = {"fd", NULL};
484
0
    static _PyArg_Parser _parser = {
485
0
        .keywords = _keywords,
486
0
        .fname = "fchdir",
487
0
        .kwtuple = KWTUPLE,
488
0
    };
489
0
    #undef KWTUPLE
490
0
    PyObject *argsbuf[1];
491
0
    int fd;
492
493
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
494
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
495
0
    if (!args) {
496
0
        goto exit;
497
0
    }
498
0
    fd = PyObject_AsFileDescriptor(args[0]);
499
0
    if (fd < 0) {
500
0
        goto exit;
501
0
    }
502
0
    return_value = os_fchdir_impl(module, fd);
503
504
0
exit:
505
0
    return return_value;
506
0
}
507
508
#endif /* defined(HAVE_FCHDIR) */
509
510
PyDoc_STRVAR(os_chmod__doc__,
511
"chmod($module, /, path, mode, *, dir_fd=None,\n"
512
"      follow_symlinks=(os.name != \'nt\'))\n"
513
"--\n"
514
"\n"
515
"Change the access permissions of a file.\n"
516
"\n"
517
"  path\n"
518
"    Path to be modified.  May always be specified as a str, bytes, or a path-like object.\n"
519
"    On some platforms, path may also be specified as an open file descriptor.\n"
520
"    If this functionality is unavailable, using it raises an exception.\n"
521
"  mode\n"
522
"    Operating-system mode bitfield.\n"
523
"    Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
524
"    numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
525
"    Python.\n"
526
"  dir_fd\n"
527
"    If not None, it should be a file descriptor open to a directory,\n"
528
"    and path should be relative; path will then be relative to that\n"
529
"    directory.\n"
530
"  follow_symlinks\n"
531
"    If False, and the last element of the path is a symbolic link,\n"
532
"    chmod will modify the symbolic link itself instead of the file\n"
533
"    the link points to.\n"
534
"\n"
535
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
536
"  an open file descriptor.\n"
537
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
538
"  If they are unavailable, using them will raise a NotImplementedError.");
539
540
#define OS_CHMOD_METHODDEF    \
541
    {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
542
543
static PyObject *
544
os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
545
              int follow_symlinks);
546
547
static PyObject *
548
os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
549
0
{
550
0
    PyObject *return_value = NULL;
551
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
552
553
0
    #define NUM_KEYWORDS 4
554
0
    static struct {
555
0
        PyGC_Head _this_is_not_used;
556
0
        PyObject_VAR_HEAD
557
0
        Py_hash_t ob_hash;
558
0
        PyObject *ob_item[NUM_KEYWORDS];
559
0
    } _kwtuple = {
560
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
561
0
        .ob_hash = -1,
562
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
563
0
    };
564
0
    #undef NUM_KEYWORDS
565
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
566
567
    #else  // !Py_BUILD_CORE
568
    #  define KWTUPLE NULL
569
    #endif  // !Py_BUILD_CORE
570
571
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
572
0
    static _PyArg_Parser _parser = {
573
0
        .keywords = _keywords,
574
0
        .fname = "chmod",
575
0
        .kwtuple = KWTUPLE,
576
0
    };
577
0
    #undef KWTUPLE
578
0
    PyObject *argsbuf[4];
579
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
580
0
    path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD);
581
0
    int mode;
582
0
    int dir_fd = DEFAULT_DIR_FD;
583
0
    int follow_symlinks = CHMOD_DEFAULT_FOLLOW_SYMLINKS;
584
585
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
586
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
587
0
    if (!args) {
588
0
        goto exit;
589
0
    }
590
0
    if (!path_converter(args[0], &path)) {
591
0
        goto exit;
592
0
    }
593
0
    mode = PyLong_AsInt(args[1]);
594
0
    if (mode == -1 && PyErr_Occurred()) {
595
0
        goto exit;
596
0
    }
597
0
    if (!noptargs) {
598
0
        goto skip_optional_kwonly;
599
0
    }
600
0
    if (args[2]) {
601
0
        if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
602
0
            goto exit;
603
0
        }
604
0
        if (!--noptargs) {
605
0
            goto skip_optional_kwonly;
606
0
        }
607
0
    }
608
0
    follow_symlinks = PyObject_IsTrue(args[3]);
609
0
    if (follow_symlinks < 0) {
610
0
        goto exit;
611
0
    }
612
0
skip_optional_kwonly:
613
0
    return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
614
615
0
exit:
616
    /* Cleanup for path */
617
0
    path_cleanup(&path);
618
619
0
    return return_value;
620
0
}
621
622
#if (defined(HAVE_FCHMOD) || defined(MS_WINDOWS))
623
624
PyDoc_STRVAR(os_fchmod__doc__,
625
"fchmod($module, /, fd, mode)\n"
626
"--\n"
627
"\n"
628
"Change the access permissions of the file given by file descriptor fd.\n"
629
"\n"
630
"  fd\n"
631
"    The file descriptor of the file to be modified.\n"
632
"  mode\n"
633
"    Operating-system mode bitfield.\n"
634
"    Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
635
"    numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
636
"    Python.\n"
637
"\n"
638
"Equivalent to os.chmod(fd, mode).");
639
640
#define OS_FCHMOD_METHODDEF    \
641
    {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
642
643
static PyObject *
644
os_fchmod_impl(PyObject *module, int fd, int mode);
645
646
static PyObject *
647
os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
648
0
{
649
0
    PyObject *return_value = NULL;
650
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
651
652
0
    #define NUM_KEYWORDS 2
653
0
    static struct {
654
0
        PyGC_Head _this_is_not_used;
655
0
        PyObject_VAR_HEAD
656
0
        Py_hash_t ob_hash;
657
0
        PyObject *ob_item[NUM_KEYWORDS];
658
0
    } _kwtuple = {
659
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
660
0
        .ob_hash = -1,
661
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(mode), },
662
0
    };
663
0
    #undef NUM_KEYWORDS
664
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
665
666
    #else  // !Py_BUILD_CORE
667
    #  define KWTUPLE NULL
668
    #endif  // !Py_BUILD_CORE
669
670
0
    static const char * const _keywords[] = {"fd", "mode", NULL};
671
0
    static _PyArg_Parser _parser = {
672
0
        .keywords = _keywords,
673
0
        .fname = "fchmod",
674
0
        .kwtuple = KWTUPLE,
675
0
    };
676
0
    #undef KWTUPLE
677
0
    PyObject *argsbuf[2];
678
0
    int fd;
679
0
    int mode;
680
681
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
682
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
683
0
    if (!args) {
684
0
        goto exit;
685
0
    }
686
0
    fd = PyLong_AsInt(args[0]);
687
0
    if (fd == -1 && PyErr_Occurred()) {
688
0
        goto exit;
689
0
    }
690
0
    mode = PyLong_AsInt(args[1]);
691
0
    if (mode == -1 && PyErr_Occurred()) {
692
0
        goto exit;
693
0
    }
694
0
    return_value = os_fchmod_impl(module, fd, mode);
695
696
0
exit:
697
0
    return return_value;
698
0
}
699
700
#endif /* (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) */
701
702
#if (defined(HAVE_LCHMOD) || defined(MS_WINDOWS))
703
704
PyDoc_STRVAR(os_lchmod__doc__,
705
"lchmod($module, /, path, mode)\n"
706
"--\n"
707
"\n"
708
"Change the access permissions of a file, without following symbolic links.\n"
709
"\n"
710
"If path is a symlink, this affects the link itself rather than the target.\n"
711
"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
712
713
#define OS_LCHMOD_METHODDEF    \
714
    {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
715
716
static PyObject *
717
os_lchmod_impl(PyObject *module, path_t *path, int mode);
718
719
static PyObject *
720
os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
721
{
722
    PyObject *return_value = NULL;
723
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
724
725
    #define NUM_KEYWORDS 2
726
    static struct {
727
        PyGC_Head _this_is_not_used;
728
        PyObject_VAR_HEAD
729
        Py_hash_t ob_hash;
730
        PyObject *ob_item[NUM_KEYWORDS];
731
    } _kwtuple = {
732
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
733
        .ob_hash = -1,
734
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), },
735
    };
736
    #undef NUM_KEYWORDS
737
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
738
739
    #else  // !Py_BUILD_CORE
740
    #  define KWTUPLE NULL
741
    #endif  // !Py_BUILD_CORE
742
743
    static const char * const _keywords[] = {"path", "mode", NULL};
744
    static _PyArg_Parser _parser = {
745
        .keywords = _keywords,
746
        .fname = "lchmod",
747
        .kwtuple = KWTUPLE,
748
    };
749
    #undef KWTUPLE
750
    PyObject *argsbuf[2];
751
    path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0);
752
    int mode;
753
754
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
755
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
756
    if (!args) {
757
        goto exit;
758
    }
759
    if (!path_converter(args[0], &path)) {
760
        goto exit;
761
    }
762
    mode = PyLong_AsInt(args[1]);
763
    if (mode == -1 && PyErr_Occurred()) {
764
        goto exit;
765
    }
766
    return_value = os_lchmod_impl(module, &path, mode);
767
768
exit:
769
    /* Cleanup for path */
770
    path_cleanup(&path);
771
772
    return return_value;
773
}
774
775
#endif /* (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) */
776
777
#if defined(HAVE_CHFLAGS)
778
779
PyDoc_STRVAR(os_chflags__doc__,
780
"chflags($module, /, path, flags, follow_symlinks=True)\n"
781
"--\n"
782
"\n"
783
"Set file flags.\n"
784
"\n"
785
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
786
"  link, chflags will change flags on the symbolic link itself instead of the\n"
787
"  file the link points to.\n"
788
"follow_symlinks may not be implemented on your platform.  If it is\n"
789
"unavailable, using it will raise a NotImplementedError.");
790
791
#define OS_CHFLAGS_METHODDEF    \
792
    {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
793
794
static PyObject *
795
os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
796
                int follow_symlinks);
797
798
static PyObject *
799
os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
800
{
801
    PyObject *return_value = NULL;
802
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
803
804
    #define NUM_KEYWORDS 3
805
    static struct {
806
        PyGC_Head _this_is_not_used;
807
        PyObject_VAR_HEAD
808
        Py_hash_t ob_hash;
809
        PyObject *ob_item[NUM_KEYWORDS];
810
    } _kwtuple = {
811
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
812
        .ob_hash = -1,
813
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
814
    };
815
    #undef NUM_KEYWORDS
816
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
817
818
    #else  // !Py_BUILD_CORE
819
    #  define KWTUPLE NULL
820
    #endif  // !Py_BUILD_CORE
821
822
    static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
823
    static _PyArg_Parser _parser = {
824
        .keywords = _keywords,
825
        .fname = "chflags",
826
        .kwtuple = KWTUPLE,
827
    };
828
    #undef KWTUPLE
829
    PyObject *argsbuf[3];
830
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
831
    path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0);
832
    unsigned long flags;
833
    int follow_symlinks = 1;
834
835
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
836
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
837
    if (!args) {
838
        goto exit;
839
    }
840
    if (!path_converter(args[0], &path)) {
841
        goto exit;
842
    }
843
    if (!PyIndex_Check(args[1])) {
844
        _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]);
845
        goto exit;
846
    }
847
    {
848
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long),
849
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
850
                Py_ASNATIVEBYTES_ALLOW_INDEX |
851
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
852
        if (_bytes < 0) {
853
            goto exit;
854
        }
855
        if ((size_t)_bytes > sizeof(unsigned long)) {
856
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
857
                "integer value out of range", 1) < 0)
858
            {
859
                goto exit;
860
            }
861
        }
862
    }
863
    if (!noptargs) {
864
        goto skip_optional_pos;
865
    }
866
    follow_symlinks = PyObject_IsTrue(args[2]);
867
    if (follow_symlinks < 0) {
868
        goto exit;
869
    }
870
skip_optional_pos:
871
    return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
872
873
exit:
874
    /* Cleanup for path */
875
    path_cleanup(&path);
876
877
    return return_value;
878
}
879
880
#endif /* defined(HAVE_CHFLAGS) */
881
882
#if defined(HAVE_LCHFLAGS)
883
884
PyDoc_STRVAR(os_lchflags__doc__,
885
"lchflags($module, /, path, flags)\n"
886
"--\n"
887
"\n"
888
"Set file flags.\n"
889
"\n"
890
"This function will not follow symbolic links.\n"
891
"Equivalent to chflags(path, flags, follow_symlinks=False).");
892
893
#define OS_LCHFLAGS_METHODDEF    \
894
    {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
895
896
static PyObject *
897
os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
898
899
static PyObject *
900
os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
901
{
902
    PyObject *return_value = NULL;
903
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
904
905
    #define NUM_KEYWORDS 2
906
    static struct {
907
        PyGC_Head _this_is_not_used;
908
        PyObject_VAR_HEAD
909
        Py_hash_t ob_hash;
910
        PyObject *ob_item[NUM_KEYWORDS];
911
    } _kwtuple = {
912
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
913
        .ob_hash = -1,
914
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), },
915
    };
916
    #undef NUM_KEYWORDS
917
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
918
919
    #else  // !Py_BUILD_CORE
920
    #  define KWTUPLE NULL
921
    #endif  // !Py_BUILD_CORE
922
923
    static const char * const _keywords[] = {"path", "flags", NULL};
924
    static _PyArg_Parser _parser = {
925
        .keywords = _keywords,
926
        .fname = "lchflags",
927
        .kwtuple = KWTUPLE,
928
    };
929
    #undef KWTUPLE
930
    PyObject *argsbuf[2];
931
    path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0);
932
    unsigned long flags;
933
934
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
935
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
936
    if (!args) {
937
        goto exit;
938
    }
939
    if (!path_converter(args[0], &path)) {
940
        goto exit;
941
    }
942
    if (!PyIndex_Check(args[1])) {
943
        _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]);
944
        goto exit;
945
    }
946
    {
947
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long),
948
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
949
                Py_ASNATIVEBYTES_ALLOW_INDEX |
950
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
951
        if (_bytes < 0) {
952
            goto exit;
953
        }
954
        if ((size_t)_bytes > sizeof(unsigned long)) {
955
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
956
                "integer value out of range", 1) < 0)
957
            {
958
                goto exit;
959
            }
960
        }
961
    }
962
    return_value = os_lchflags_impl(module, &path, flags);
963
964
exit:
965
    /* Cleanup for path */
966
    path_cleanup(&path);
967
968
    return return_value;
969
}
970
971
#endif /* defined(HAVE_LCHFLAGS) */
972
973
#if defined(HAVE_CHROOT)
974
975
PyDoc_STRVAR(os_chroot__doc__,
976
"chroot($module, /, path)\n"
977
"--\n"
978
"\n"
979
"Change root directory to path.");
980
981
#define OS_CHROOT_METHODDEF    \
982
    {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
983
984
static PyObject *
985
os_chroot_impl(PyObject *module, path_t *path);
986
987
static PyObject *
988
os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
989
0
{
990
0
    PyObject *return_value = NULL;
991
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
992
993
0
    #define NUM_KEYWORDS 1
994
0
    static struct {
995
0
        PyGC_Head _this_is_not_used;
996
0
        PyObject_VAR_HEAD
997
0
        Py_hash_t ob_hash;
998
0
        PyObject *ob_item[NUM_KEYWORDS];
999
0
    } _kwtuple = {
1000
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1001
0
        .ob_hash = -1,
1002
0
        .ob_item = { &_Py_ID(path), },
1003
0
    };
1004
0
    #undef NUM_KEYWORDS
1005
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1006
1007
    #else  // !Py_BUILD_CORE
1008
    #  define KWTUPLE NULL
1009
    #endif  // !Py_BUILD_CORE
1010
1011
0
    static const char * const _keywords[] = {"path", NULL};
1012
0
    static _PyArg_Parser _parser = {
1013
0
        .keywords = _keywords,
1014
0
        .fname = "chroot",
1015
0
        .kwtuple = KWTUPLE,
1016
0
    };
1017
0
    #undef KWTUPLE
1018
0
    PyObject *argsbuf[1];
1019
0
    path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0);
1020
1021
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1022
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1023
0
    if (!args) {
1024
0
        goto exit;
1025
0
    }
1026
0
    if (!path_converter(args[0], &path)) {
1027
0
        goto exit;
1028
0
    }
1029
0
    return_value = os_chroot_impl(module, &path);
1030
1031
0
exit:
1032
    /* Cleanup for path */
1033
0
    path_cleanup(&path);
1034
1035
0
    return return_value;
1036
0
}
1037
1038
#endif /* defined(HAVE_CHROOT) */
1039
1040
#if defined(HAVE_FSYNC)
1041
1042
PyDoc_STRVAR(os_fsync__doc__,
1043
"fsync($module, /, fd)\n"
1044
"--\n"
1045
"\n"
1046
"Force write of fd to disk.");
1047
1048
#define OS_FSYNC_METHODDEF    \
1049
    {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
1050
1051
static PyObject *
1052
os_fsync_impl(PyObject *module, int fd);
1053
1054
static PyObject *
1055
os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1056
0
{
1057
0
    PyObject *return_value = NULL;
1058
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1059
1060
0
    #define NUM_KEYWORDS 1
1061
0
    static struct {
1062
0
        PyGC_Head _this_is_not_used;
1063
0
        PyObject_VAR_HEAD
1064
0
        Py_hash_t ob_hash;
1065
0
        PyObject *ob_item[NUM_KEYWORDS];
1066
0
    } _kwtuple = {
1067
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1068
0
        .ob_hash = -1,
1069
0
        .ob_item = { &_Py_ID(fd), },
1070
0
    };
1071
0
    #undef NUM_KEYWORDS
1072
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1073
1074
    #else  // !Py_BUILD_CORE
1075
    #  define KWTUPLE NULL
1076
    #endif  // !Py_BUILD_CORE
1077
1078
0
    static const char * const _keywords[] = {"fd", NULL};
1079
0
    static _PyArg_Parser _parser = {
1080
0
        .keywords = _keywords,
1081
0
        .fname = "fsync",
1082
0
        .kwtuple = KWTUPLE,
1083
0
    };
1084
0
    #undef KWTUPLE
1085
0
    PyObject *argsbuf[1];
1086
0
    int fd;
1087
1088
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1089
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1090
0
    if (!args) {
1091
0
        goto exit;
1092
0
    }
1093
0
    fd = PyObject_AsFileDescriptor(args[0]);
1094
0
    if (fd < 0) {
1095
0
        goto exit;
1096
0
    }
1097
0
    return_value = os_fsync_impl(module, fd);
1098
1099
0
exit:
1100
0
    return return_value;
1101
0
}
1102
1103
#endif /* defined(HAVE_FSYNC) */
1104
1105
#if defined(HAVE_SYNC)
1106
1107
PyDoc_STRVAR(os_sync__doc__,
1108
"sync($module, /)\n"
1109
"--\n"
1110
"\n"
1111
"Force write of everything to disk.");
1112
1113
#define OS_SYNC_METHODDEF    \
1114
    {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
1115
1116
static PyObject *
1117
os_sync_impl(PyObject *module);
1118
1119
static PyObject *
1120
os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
1121
0
{
1122
0
    return os_sync_impl(module);
1123
0
}
1124
1125
#endif /* defined(HAVE_SYNC) */
1126
1127
#if defined(HAVE_FDATASYNC)
1128
1129
PyDoc_STRVAR(os_fdatasync__doc__,
1130
"fdatasync($module, /, fd)\n"
1131
"--\n"
1132
"\n"
1133
"Force write of fd to disk without forcing update of metadata.");
1134
1135
#define OS_FDATASYNC_METHODDEF    \
1136
    {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
1137
1138
static PyObject *
1139
os_fdatasync_impl(PyObject *module, int fd);
1140
1141
static PyObject *
1142
os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1143
0
{
1144
0
    PyObject *return_value = NULL;
1145
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1146
1147
0
    #define NUM_KEYWORDS 1
1148
0
    static struct {
1149
0
        PyGC_Head _this_is_not_used;
1150
0
        PyObject_VAR_HEAD
1151
0
        Py_hash_t ob_hash;
1152
0
        PyObject *ob_item[NUM_KEYWORDS];
1153
0
    } _kwtuple = {
1154
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1155
0
        .ob_hash = -1,
1156
0
        .ob_item = { &_Py_ID(fd), },
1157
0
    };
1158
0
    #undef NUM_KEYWORDS
1159
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1160
1161
    #else  // !Py_BUILD_CORE
1162
    #  define KWTUPLE NULL
1163
    #endif  // !Py_BUILD_CORE
1164
1165
0
    static const char * const _keywords[] = {"fd", NULL};
1166
0
    static _PyArg_Parser _parser = {
1167
0
        .keywords = _keywords,
1168
0
        .fname = "fdatasync",
1169
0
        .kwtuple = KWTUPLE,
1170
0
    };
1171
0
    #undef KWTUPLE
1172
0
    PyObject *argsbuf[1];
1173
0
    int fd;
1174
1175
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1176
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1177
0
    if (!args) {
1178
0
        goto exit;
1179
0
    }
1180
0
    fd = PyObject_AsFileDescriptor(args[0]);
1181
0
    if (fd < 0) {
1182
0
        goto exit;
1183
0
    }
1184
0
    return_value = os_fdatasync_impl(module, fd);
1185
1186
0
exit:
1187
0
    return return_value;
1188
0
}
1189
1190
#endif /* defined(HAVE_FDATASYNC) */
1191
1192
#if defined(HAVE_CHOWN)
1193
1194
PyDoc_STRVAR(os_chown__doc__,
1195
"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
1196
"--\n"
1197
"\n"
1198
"Change the owner and group id of path to the numeric uid and gid.\\\n"
1199
"\n"
1200
"  path\n"
1201
"    Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
1202
"  dir_fd\n"
1203
"    If not None, it should be a file descriptor open to a directory,\n"
1204
"    and path should be relative; path will then be relative to that\n"
1205
"    directory.\n"
1206
"  follow_symlinks\n"
1207
"    If False, and the last element of the path is a symbolic link,\n"
1208
"    stat will examine the symbolic link itself instead of the file\n"
1209
"    the link points to.\n"
1210
"\n"
1211
"path may always be specified as a string.\n"
1212
"On some platforms, path may also be specified as an open file descriptor.\n"
1213
"  If this functionality is unavailable, using it raises an exception.\n"
1214
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1215
"  and path should be relative; path will then be relative to that directory.\n"
1216
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1217
"  link, chown will modify the symbolic link itself instead of the file the\n"
1218
"  link points to.\n"
1219
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
1220
"  an open file descriptor.\n"
1221
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
1222
"  If they are unavailable, using them will raise a NotImplementedError.");
1223
1224
#define OS_CHOWN_METHODDEF    \
1225
    {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
1226
1227
static PyObject *
1228
os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
1229
              int dir_fd, int follow_symlinks);
1230
1231
static PyObject *
1232
os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1233
0
{
1234
0
    PyObject *return_value = NULL;
1235
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1236
1237
0
    #define NUM_KEYWORDS 5
1238
0
    static struct {
1239
0
        PyGC_Head _this_is_not_used;
1240
0
        PyObject_VAR_HEAD
1241
0
        Py_hash_t ob_hash;
1242
0
        PyObject *ob_item[NUM_KEYWORDS];
1243
0
    } _kwtuple = {
1244
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1245
0
        .ob_hash = -1,
1246
0
        .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
1247
0
    };
1248
0
    #undef NUM_KEYWORDS
1249
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1250
1251
    #else  // !Py_BUILD_CORE
1252
    #  define KWTUPLE NULL
1253
    #endif  // !Py_BUILD_CORE
1254
1255
0
    static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
1256
0
    static _PyArg_Parser _parser = {
1257
0
        .keywords = _keywords,
1258
0
        .fname = "chown",
1259
0
        .kwtuple = KWTUPLE,
1260
0
    };
1261
0
    #undef KWTUPLE
1262
0
    PyObject *argsbuf[5];
1263
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
1264
0
    path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN);
1265
0
    uid_t uid;
1266
0
    gid_t gid;
1267
0
    int dir_fd = DEFAULT_DIR_FD;
1268
0
    int follow_symlinks = 1;
1269
1270
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1271
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1272
0
    if (!args) {
1273
0
        goto exit;
1274
0
    }
1275
0
    if (!path_converter(args[0], &path)) {
1276
0
        goto exit;
1277
0
    }
1278
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1279
0
        goto exit;
1280
0
    }
1281
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1282
0
        goto exit;
1283
0
    }
1284
0
    if (!noptargs) {
1285
0
        goto skip_optional_kwonly;
1286
0
    }
1287
0
    if (args[3]) {
1288
0
        if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
1289
0
            goto exit;
1290
0
        }
1291
0
        if (!--noptargs) {
1292
0
            goto skip_optional_kwonly;
1293
0
        }
1294
0
    }
1295
0
    follow_symlinks = PyObject_IsTrue(args[4]);
1296
0
    if (follow_symlinks < 0) {
1297
0
        goto exit;
1298
0
    }
1299
0
skip_optional_kwonly:
1300
0
    return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
1301
1302
0
exit:
1303
    /* Cleanup for path */
1304
0
    path_cleanup(&path);
1305
1306
0
    return return_value;
1307
0
}
1308
1309
#endif /* defined(HAVE_CHOWN) */
1310
1311
#if defined(HAVE_FCHOWN)
1312
1313
PyDoc_STRVAR(os_fchown__doc__,
1314
"fchown($module, /, fd, uid, gid)\n"
1315
"--\n"
1316
"\n"
1317
"Change the owner and group id of the file specified by file descriptor.\n"
1318
"\n"
1319
"Equivalent to os.chown(fd, uid, gid).");
1320
1321
#define OS_FCHOWN_METHODDEF    \
1322
    {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
1323
1324
static PyObject *
1325
os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
1326
1327
static PyObject *
1328
os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1329
0
{
1330
0
    PyObject *return_value = NULL;
1331
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1332
1333
0
    #define NUM_KEYWORDS 3
1334
0
    static struct {
1335
0
        PyGC_Head _this_is_not_used;
1336
0
        PyObject_VAR_HEAD
1337
0
        Py_hash_t ob_hash;
1338
0
        PyObject *ob_item[NUM_KEYWORDS];
1339
0
    } _kwtuple = {
1340
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1341
0
        .ob_hash = -1,
1342
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), },
1343
0
    };
1344
0
    #undef NUM_KEYWORDS
1345
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1346
1347
    #else  // !Py_BUILD_CORE
1348
    #  define KWTUPLE NULL
1349
    #endif  // !Py_BUILD_CORE
1350
1351
0
    static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
1352
0
    static _PyArg_Parser _parser = {
1353
0
        .keywords = _keywords,
1354
0
        .fname = "fchown",
1355
0
        .kwtuple = KWTUPLE,
1356
0
    };
1357
0
    #undef KWTUPLE
1358
0
    PyObject *argsbuf[3];
1359
0
    int fd;
1360
0
    uid_t uid;
1361
0
    gid_t gid;
1362
1363
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1364
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1365
0
    if (!args) {
1366
0
        goto exit;
1367
0
    }
1368
0
    fd = PyLong_AsInt(args[0]);
1369
0
    if (fd == -1 && PyErr_Occurred()) {
1370
0
        goto exit;
1371
0
    }
1372
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1373
0
        goto exit;
1374
0
    }
1375
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1376
0
        goto exit;
1377
0
    }
1378
0
    return_value = os_fchown_impl(module, fd, uid, gid);
1379
1380
0
exit:
1381
0
    return return_value;
1382
0
}
1383
1384
#endif /* defined(HAVE_FCHOWN) */
1385
1386
#if defined(HAVE_LCHOWN)
1387
1388
PyDoc_STRVAR(os_lchown__doc__,
1389
"lchown($module, /, path, uid, gid)\n"
1390
"--\n"
1391
"\n"
1392
"Change the owner and group id of path to the numeric uid and gid.\n"
1393
"\n"
1394
"This function will not follow symbolic links.\n"
1395
"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
1396
1397
#define OS_LCHOWN_METHODDEF    \
1398
    {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
1399
1400
static PyObject *
1401
os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
1402
1403
static PyObject *
1404
os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1405
0
{
1406
0
    PyObject *return_value = NULL;
1407
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1408
1409
0
    #define NUM_KEYWORDS 3
1410
0
    static struct {
1411
0
        PyGC_Head _this_is_not_used;
1412
0
        PyObject_VAR_HEAD
1413
0
        Py_hash_t ob_hash;
1414
0
        PyObject *ob_item[NUM_KEYWORDS];
1415
0
    } _kwtuple = {
1416
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1417
0
        .ob_hash = -1,
1418
0
        .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), },
1419
0
    };
1420
0
    #undef NUM_KEYWORDS
1421
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1422
1423
    #else  // !Py_BUILD_CORE
1424
    #  define KWTUPLE NULL
1425
    #endif  // !Py_BUILD_CORE
1426
1427
0
    static const char * const _keywords[] = {"path", "uid", "gid", NULL};
1428
0
    static _PyArg_Parser _parser = {
1429
0
        .keywords = _keywords,
1430
0
        .fname = "lchown",
1431
0
        .kwtuple = KWTUPLE,
1432
0
    };
1433
0
    #undef KWTUPLE
1434
0
    PyObject *argsbuf[3];
1435
0
    path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0);
1436
0
    uid_t uid;
1437
0
    gid_t gid;
1438
1439
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1440
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1441
0
    if (!args) {
1442
0
        goto exit;
1443
0
    }
1444
0
    if (!path_converter(args[0], &path)) {
1445
0
        goto exit;
1446
0
    }
1447
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1448
0
        goto exit;
1449
0
    }
1450
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1451
0
        goto exit;
1452
0
    }
1453
0
    return_value = os_lchown_impl(module, &path, uid, gid);
1454
1455
0
exit:
1456
    /* Cleanup for path */
1457
0
    path_cleanup(&path);
1458
1459
0
    return return_value;
1460
0
}
1461
1462
#endif /* defined(HAVE_LCHOWN) */
1463
1464
PyDoc_STRVAR(os_getcwd__doc__,
1465
"getcwd($module, /)\n"
1466
"--\n"
1467
"\n"
1468
"Return a unicode string representing the current working directory.");
1469
1470
#define OS_GETCWD_METHODDEF    \
1471
    {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
1472
1473
static PyObject *
1474
os_getcwd_impl(PyObject *module);
1475
1476
static PyObject *
1477
os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
1478
0
{
1479
0
    return os_getcwd_impl(module);
1480
0
}
1481
1482
PyDoc_STRVAR(os_getcwdb__doc__,
1483
"getcwdb($module, /)\n"
1484
"--\n"
1485
"\n"
1486
"Return a bytes string representing the current working directory.");
1487
1488
#define OS_GETCWDB_METHODDEF    \
1489
    {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
1490
1491
static PyObject *
1492
os_getcwdb_impl(PyObject *module);
1493
1494
static PyObject *
1495
os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
1496
0
{
1497
0
    return os_getcwdb_impl(module);
1498
0
}
1499
1500
#if defined(HAVE_LINK)
1501
1502
PyDoc_STRVAR(os_link__doc__,
1503
"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
1504
"     follow_symlinks=(os.name != \'nt\'))\n"
1505
"--\n"
1506
"\n"
1507
"Create a hard link to a file.\n"
1508
"\n"
1509
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1510
"  descriptor open to a directory, and the respective path string (src or dst)\n"
1511
"  should be relative; the path will then be relative to that directory.\n"
1512
"If follow_symlinks is False, and the last element of src is a symbolic\n"
1513
"  link, link will create a link to the symbolic link itself instead of the\n"
1514
"  file the link points to.\n"
1515
"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
1516
"  platform.  If they are unavailable, using them will raise a\n"
1517
"  NotImplementedError.");
1518
1519
#define OS_LINK_METHODDEF    \
1520
    {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
1521
1522
static PyObject *
1523
os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1524
             int dst_dir_fd, int follow_symlinks);
1525
1526
static PyObject *
1527
os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1528
0
{
1529
0
    PyObject *return_value = NULL;
1530
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1531
1532
0
    #define NUM_KEYWORDS 5
1533
0
    static struct {
1534
0
        PyGC_Head _this_is_not_used;
1535
0
        PyObject_VAR_HEAD
1536
0
        Py_hash_t ob_hash;
1537
0
        PyObject *ob_item[NUM_KEYWORDS];
1538
0
    } _kwtuple = {
1539
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1540
0
        .ob_hash = -1,
1541
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), },
1542
0
    };
1543
0
    #undef NUM_KEYWORDS
1544
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1545
1546
    #else  // !Py_BUILD_CORE
1547
    #  define KWTUPLE NULL
1548
    #endif  // !Py_BUILD_CORE
1549
1550
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
1551
0
    static _PyArg_Parser _parser = {
1552
0
        .keywords = _keywords,
1553
0
        .fname = "link",
1554
0
        .kwtuple = KWTUPLE,
1555
0
    };
1556
0
    #undef KWTUPLE
1557
0
    PyObject *argsbuf[5];
1558
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1559
0
    path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0);
1560
0
    path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0);
1561
0
    int src_dir_fd = DEFAULT_DIR_FD;
1562
0
    int dst_dir_fd = DEFAULT_DIR_FD;
1563
0
    int follow_symlinks = -1;
1564
1565
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1566
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1567
0
    if (!args) {
1568
0
        goto exit;
1569
0
    }
1570
0
    if (!path_converter(args[0], &src)) {
1571
0
        goto exit;
1572
0
    }
1573
0
    if (!path_converter(args[1], &dst)) {
1574
0
        goto exit;
1575
0
    }
1576
0
    if (!noptargs) {
1577
0
        goto skip_optional_kwonly;
1578
0
    }
1579
0
    if (args[2]) {
1580
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
1581
0
            goto exit;
1582
0
        }
1583
0
        if (!--noptargs) {
1584
0
            goto skip_optional_kwonly;
1585
0
        }
1586
0
    }
1587
0
    if (args[3]) {
1588
0
        if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1589
0
            goto exit;
1590
0
        }
1591
0
        if (!--noptargs) {
1592
0
            goto skip_optional_kwonly;
1593
0
        }
1594
0
    }
1595
0
    follow_symlinks = PyObject_IsTrue(args[4]);
1596
0
    if (follow_symlinks < 0) {
1597
0
        goto exit;
1598
0
    }
1599
0
skip_optional_kwonly:
1600
0
    return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
1601
1602
0
exit:
1603
    /* Cleanup for src */
1604
0
    path_cleanup(&src);
1605
    /* Cleanup for dst */
1606
0
    path_cleanup(&dst);
1607
1608
0
    return return_value;
1609
0
}
1610
1611
#endif /* defined(HAVE_LINK) */
1612
1613
PyDoc_STRVAR(os_listdir__doc__,
1614
"listdir($module, /, path=None)\n"
1615
"--\n"
1616
"\n"
1617
"Return a list containing the names of the files in the directory.\n"
1618
"\n"
1619
"path can be specified as either str, bytes, or a path-like object.  If path is bytes,\n"
1620
"  the filenames returned will also be bytes; in all other circumstances\n"
1621
"  the filenames returned will be str.\n"
1622
"If path is None, uses the path=\'.\'.\n"
1623
"On some platforms, path may also be specified as an open file descriptor;\\\n"
1624
"  the file descriptor must refer to a directory.\n"
1625
"  If this functionality is unavailable, using it raises NotImplementedError.\n"
1626
"\n"
1627
"The list is in arbitrary order.  It does not include the special\n"
1628
"entries \'.\' and \'..\' even if they are present in the directory.");
1629
1630
#define OS_LISTDIR_METHODDEF    \
1631
    {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
1632
1633
static PyObject *
1634
os_listdir_impl(PyObject *module, path_t *path);
1635
1636
static PyObject *
1637
os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1638
120
{
1639
120
    PyObject *return_value = NULL;
1640
120
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1641
1642
120
    #define NUM_KEYWORDS 1
1643
120
    static struct {
1644
120
        PyGC_Head _this_is_not_used;
1645
120
        PyObject_VAR_HEAD
1646
120
        Py_hash_t ob_hash;
1647
120
        PyObject *ob_item[NUM_KEYWORDS];
1648
120
    } _kwtuple = {
1649
120
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1650
120
        .ob_hash = -1,
1651
120
        .ob_item = { &_Py_ID(path), },
1652
120
    };
1653
120
    #undef NUM_KEYWORDS
1654
120
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1655
1656
    #else  // !Py_BUILD_CORE
1657
    #  define KWTUPLE NULL
1658
    #endif  // !Py_BUILD_CORE
1659
1660
120
    static const char * const _keywords[] = {"path", NULL};
1661
120
    static _PyArg_Parser _parser = {
1662
120
        .keywords = _keywords,
1663
120
        .fname = "listdir",
1664
120
        .kwtuple = KWTUPLE,
1665
120
    };
1666
120
    #undef KWTUPLE
1667
120
    PyObject *argsbuf[1];
1668
120
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1669
120
    path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
1670
1671
120
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1672
120
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1673
120
    if (!args) {
1674
0
        goto exit;
1675
0
    }
1676
120
    if (!noptargs) {
1677
0
        goto skip_optional_pos;
1678
0
    }
1679
120
    if (!path_converter(args[0], &path)) {
1680
0
        goto exit;
1681
0
    }
1682
120
skip_optional_pos:
1683
120
    return_value = os_listdir_impl(module, &path);
1684
1685
120
exit:
1686
    /* Cleanup for path */
1687
120
    path_cleanup(&path);
1688
1689
120
    return return_value;
1690
120
}
1691
1692
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
1693
1694
PyDoc_STRVAR(os_listdrives__doc__,
1695
"listdrives($module, /)\n"
1696
"--\n"
1697
"\n"
1698
"Return a list containing the names of drives in the system.\n"
1699
"\n"
1700
"A drive name typically looks like \'C:\\\\\'.");
1701
1702
#define OS_LISTDRIVES_METHODDEF    \
1703
    {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__},
1704
1705
static PyObject *
1706
os_listdrives_impl(PyObject *module);
1707
1708
static PyObject *
1709
os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored))
1710
{
1711
    return os_listdrives_impl(module);
1712
}
1713
1714
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
1715
1716
#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
1717
1718
PyDoc_STRVAR(os_listvolumes__doc__,
1719
"listvolumes($module, /)\n"
1720
"--\n"
1721
"\n"
1722
"Return a list containing the volumes in the system.\n"
1723
"\n"
1724
"Volumes are typically represented as a GUID path.");
1725
1726
#define OS_LISTVOLUMES_METHODDEF    \
1727
    {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__},
1728
1729
static PyObject *
1730
os_listvolumes_impl(PyObject *module);
1731
1732
static PyObject *
1733
os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored))
1734
{
1735
    return os_listvolumes_impl(module);
1736
}
1737
1738
#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
1739
1740
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
1741
1742
PyDoc_STRVAR(os_listmounts__doc__,
1743
"listmounts($module, /, volume)\n"
1744
"--\n"
1745
"\n"
1746
"Return a list containing mount points for a particular volume.\n"
1747
"\n"
1748
"\'volume\' should be a GUID path as returned from os.listvolumes.");
1749
1750
#define OS_LISTMOUNTS_METHODDEF    \
1751
    {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__},
1752
1753
static PyObject *
1754
os_listmounts_impl(PyObject *module, path_t *volume);
1755
1756
static PyObject *
1757
os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1758
{
1759
    PyObject *return_value = NULL;
1760
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1761
1762
    #define NUM_KEYWORDS 1
1763
    static struct {
1764
        PyGC_Head _this_is_not_used;
1765
        PyObject_VAR_HEAD
1766
        Py_hash_t ob_hash;
1767
        PyObject *ob_item[NUM_KEYWORDS];
1768
    } _kwtuple = {
1769
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1770
        .ob_hash = -1,
1771
        .ob_item = { &_Py_ID(volume), },
1772
    };
1773
    #undef NUM_KEYWORDS
1774
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1775
1776
    #else  // !Py_BUILD_CORE
1777
    #  define KWTUPLE NULL
1778
    #endif  // !Py_BUILD_CORE
1779
1780
    static const char * const _keywords[] = {"volume", NULL};
1781
    static _PyArg_Parser _parser = {
1782
        .keywords = _keywords,
1783
        .fname = "listmounts",
1784
        .kwtuple = KWTUPLE,
1785
    };
1786
    #undef KWTUPLE
1787
    PyObject *argsbuf[1];
1788
    path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0);
1789
1790
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1791
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1792
    if (!args) {
1793
        goto exit;
1794
    }
1795
    if (!path_converter(args[0], &volume)) {
1796
        goto exit;
1797
    }
1798
    return_value = os_listmounts_impl(module, &volume);
1799
1800
exit:
1801
    /* Cleanup for volume */
1802
    path_cleanup(&volume);
1803
1804
    return return_value;
1805
}
1806
1807
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
1808
1809
#if defined(MS_WINDOWS)
1810
1811
PyDoc_STRVAR(os__path_isdevdrive__doc__,
1812
"_path_isdevdrive($module, /, path)\n"
1813
"--\n"
1814
"\n"
1815
"Determines whether the specified path is on a Windows Dev Drive.");
1816
1817
#define OS__PATH_ISDEVDRIVE_METHODDEF    \
1818
    {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__},
1819
1820
static PyObject *
1821
os__path_isdevdrive_impl(PyObject *module, path_t *path);
1822
1823
static PyObject *
1824
os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1825
{
1826
    PyObject *return_value = NULL;
1827
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1828
1829
    #define NUM_KEYWORDS 1
1830
    static struct {
1831
        PyGC_Head _this_is_not_used;
1832
        PyObject_VAR_HEAD
1833
        Py_hash_t ob_hash;
1834
        PyObject *ob_item[NUM_KEYWORDS];
1835
    } _kwtuple = {
1836
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1837
        .ob_hash = -1,
1838
        .ob_item = { &_Py_ID(path), },
1839
    };
1840
    #undef NUM_KEYWORDS
1841
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1842
1843
    #else  // !Py_BUILD_CORE
1844
    #  define KWTUPLE NULL
1845
    #endif  // !Py_BUILD_CORE
1846
1847
    static const char * const _keywords[] = {"path", NULL};
1848
    static _PyArg_Parser _parser = {
1849
        .keywords = _keywords,
1850
        .fname = "_path_isdevdrive",
1851
        .kwtuple = KWTUPLE,
1852
    };
1853
    #undef KWTUPLE
1854
    PyObject *argsbuf[1];
1855
    path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0);
1856
1857
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1858
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1859
    if (!args) {
1860
        goto exit;
1861
    }
1862
    if (!path_converter(args[0], &path)) {
1863
        goto exit;
1864
    }
1865
    return_value = os__path_isdevdrive_impl(module, &path);
1866
1867
exit:
1868
    /* Cleanup for path */
1869
    path_cleanup(&path);
1870
1871
    return return_value;
1872
}
1873
1874
#endif /* defined(MS_WINDOWS) */
1875
1876
#if defined(MS_WINDOWS)
1877
1878
PyDoc_STRVAR(os__getfullpathname__doc__,
1879
"_getfullpathname($module, path, /)\n"
1880
"--\n"
1881
"\n");
1882
1883
#define OS__GETFULLPATHNAME_METHODDEF    \
1884
    {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
1885
1886
static PyObject *
1887
os__getfullpathname_impl(PyObject *module, path_t *path);
1888
1889
static PyObject *
1890
os__getfullpathname(PyObject *module, PyObject *arg)
1891
{
1892
    PyObject *return_value = NULL;
1893
    path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0);
1894
1895
    if (!path_converter(arg, &path)) {
1896
        goto exit;
1897
    }
1898
    return_value = os__getfullpathname_impl(module, &path);
1899
1900
exit:
1901
    /* Cleanup for path */
1902
    path_cleanup(&path);
1903
1904
    return return_value;
1905
}
1906
1907
#endif /* defined(MS_WINDOWS) */
1908
1909
#if defined(MS_WINDOWS)
1910
1911
PyDoc_STRVAR(os__getfinalpathname__doc__,
1912
"_getfinalpathname($module, path, /)\n"
1913
"--\n"
1914
"\n"
1915
"A helper function for samepath on windows.");
1916
1917
#define OS__GETFINALPATHNAME_METHODDEF    \
1918
    {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
1919
1920
static PyObject *
1921
os__getfinalpathname_impl(PyObject *module, path_t *path);
1922
1923
static PyObject *
1924
os__getfinalpathname(PyObject *module, PyObject *arg)
1925
{
1926
    PyObject *return_value = NULL;
1927
    path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0);
1928
1929
    if (!path_converter(arg, &path)) {
1930
        goto exit;
1931
    }
1932
    return_value = os__getfinalpathname_impl(module, &path);
1933
1934
exit:
1935
    /* Cleanup for path */
1936
    path_cleanup(&path);
1937
1938
    return return_value;
1939
}
1940
1941
#endif /* defined(MS_WINDOWS) */
1942
1943
#if defined(MS_WINDOWS)
1944
1945
PyDoc_STRVAR(os__findfirstfile__doc__,
1946
"_findfirstfile($module, path, /)\n"
1947
"--\n"
1948
"\n"
1949
"A function to get the real file name without accessing the file in Windows.");
1950
1951
#define OS__FINDFIRSTFILE_METHODDEF    \
1952
    {"_findfirstfile", (PyCFunction)os__findfirstfile, METH_O, os__findfirstfile__doc__},
1953
1954
static PyObject *
1955
os__findfirstfile_impl(PyObject *module, path_t *path);
1956
1957
static PyObject *
1958
os__findfirstfile(PyObject *module, PyObject *arg)
1959
{
1960
    PyObject *return_value = NULL;
1961
    path_t path = PATH_T_INITIALIZE_P("_findfirstfile", "path", 0, 0, 0, 0);
1962
1963
    if (!path_converter(arg, &path)) {
1964
        goto exit;
1965
    }
1966
    return_value = os__findfirstfile_impl(module, &path);
1967
1968
exit:
1969
    /* Cleanup for path */
1970
    path_cleanup(&path);
1971
1972
    return return_value;
1973
}
1974
1975
#endif /* defined(MS_WINDOWS) */
1976
1977
#if defined(MS_WINDOWS)
1978
1979
PyDoc_STRVAR(os__getvolumepathname__doc__,
1980
"_getvolumepathname($module, /, path)\n"
1981
"--\n"
1982
"\n"
1983
"A helper function for ismount on Win32.");
1984
1985
#define OS__GETVOLUMEPATHNAME_METHODDEF    \
1986
    {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
1987
1988
static PyObject *
1989
os__getvolumepathname_impl(PyObject *module, path_t *path);
1990
1991
static PyObject *
1992
os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1993
{
1994
    PyObject *return_value = NULL;
1995
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1996
1997
    #define NUM_KEYWORDS 1
1998
    static struct {
1999
        PyGC_Head _this_is_not_used;
2000
        PyObject_VAR_HEAD
2001
        Py_hash_t ob_hash;
2002
        PyObject *ob_item[NUM_KEYWORDS];
2003
    } _kwtuple = {
2004
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2005
        .ob_hash = -1,
2006
        .ob_item = { &_Py_ID(path), },
2007
    };
2008
    #undef NUM_KEYWORDS
2009
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2010
2011
    #else  // !Py_BUILD_CORE
2012
    #  define KWTUPLE NULL
2013
    #endif  // !Py_BUILD_CORE
2014
2015
    static const char * const _keywords[] = {"path", NULL};
2016
    static _PyArg_Parser _parser = {
2017
        .keywords = _keywords,
2018
        .fname = "_getvolumepathname",
2019
        .kwtuple = KWTUPLE,
2020
    };
2021
    #undef KWTUPLE
2022
    PyObject *argsbuf[1];
2023
    path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0);
2024
2025
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2026
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2027
    if (!args) {
2028
        goto exit;
2029
    }
2030
    if (!path_converter(args[0], &path)) {
2031
        goto exit;
2032
    }
2033
    return_value = os__getvolumepathname_impl(module, &path);
2034
2035
exit:
2036
    /* Cleanup for path */
2037
    path_cleanup(&path);
2038
2039
    return return_value;
2040
}
2041
2042
#endif /* defined(MS_WINDOWS) */
2043
2044
#if defined(MS_WINDOWS)
2045
2046
PyDoc_STRVAR(os__path_splitroot__doc__,
2047
"_path_splitroot($module, path, /)\n"
2048
"--\n"
2049
"\n"
2050
"Removes everything after the root on Win32.");
2051
2052
#define OS__PATH_SPLITROOT_METHODDEF    \
2053
    {"_path_splitroot", (PyCFunction)os__path_splitroot, METH_O, os__path_splitroot__doc__},
2054
2055
static PyObject *
2056
os__path_splitroot_impl(PyObject *module, path_t *path);
2057
2058
static PyObject *
2059
os__path_splitroot(PyObject *module, PyObject *arg)
2060
{
2061
    PyObject *return_value = NULL;
2062
    path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0);
2063
2064
    if (!path_converter(arg, &path)) {
2065
        goto exit;
2066
    }
2067
    return_value = os__path_splitroot_impl(module, &path);
2068
2069
exit:
2070
    /* Cleanup for path */
2071
    path_cleanup(&path);
2072
2073
    return return_value;
2074
}
2075
2076
#endif /* defined(MS_WINDOWS) */
2077
2078
#if defined(MS_WINDOWS)
2079
2080
PyDoc_STRVAR(os__path_exists__doc__,
2081
"_path_exists($module, /, path)\n"
2082
"--\n"
2083
"\n"
2084
"Test whether a path exists.  Returns False for broken symbolic links.");
2085
2086
#define OS__PATH_EXISTS_METHODDEF    \
2087
    {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__},
2088
2089
static int
2090
os__path_exists_impl(PyObject *module, path_t *path);
2091
2092
static PyObject *
2093
os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2094
{
2095
    PyObject *return_value = NULL;
2096
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2097
2098
    #define NUM_KEYWORDS 1
2099
    static struct {
2100
        PyGC_Head _this_is_not_used;
2101
        PyObject_VAR_HEAD
2102
        Py_hash_t ob_hash;
2103
        PyObject *ob_item[NUM_KEYWORDS];
2104
    } _kwtuple = {
2105
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2106
        .ob_hash = -1,
2107
        .ob_item = { &_Py_ID(path), },
2108
    };
2109
    #undef NUM_KEYWORDS
2110
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2111
2112
    #else  // !Py_BUILD_CORE
2113
    #  define KWTUPLE NULL
2114
    #endif  // !Py_BUILD_CORE
2115
2116
    static const char * const _keywords[] = {"path", NULL};
2117
    static _PyArg_Parser _parser = {
2118
        .keywords = _keywords,
2119
        .fname = "_path_exists",
2120
        .kwtuple = KWTUPLE,
2121
    };
2122
    #undef KWTUPLE
2123
    PyObject *argsbuf[1];
2124
    path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1);
2125
    int _return_value;
2126
2127
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2128
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2129
    if (!args) {
2130
        goto exit;
2131
    }
2132
    if (!path_converter(args[0], &path)) {
2133
        goto exit;
2134
    }
2135
    _return_value = os__path_exists_impl(module, &path);
2136
    if ((_return_value == -1) && PyErr_Occurred()) {
2137
        goto exit;
2138
    }
2139
    return_value = PyBool_FromLong((long)_return_value);
2140
2141
exit:
2142
    /* Cleanup for path */
2143
    path_cleanup(&path);
2144
2145
    return return_value;
2146
}
2147
2148
#endif /* defined(MS_WINDOWS) */
2149
2150
#if defined(MS_WINDOWS)
2151
2152
PyDoc_STRVAR(os__path_lexists__doc__,
2153
"_path_lexists($module, /, path)\n"
2154
"--\n"
2155
"\n"
2156
"Test whether a path exists.  Returns True for broken symbolic links.");
2157
2158
#define OS__PATH_LEXISTS_METHODDEF    \
2159
    {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__},
2160
2161
static int
2162
os__path_lexists_impl(PyObject *module, path_t *path);
2163
2164
static PyObject *
2165
os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2166
{
2167
    PyObject *return_value = NULL;
2168
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2169
2170
    #define NUM_KEYWORDS 1
2171
    static struct {
2172
        PyGC_Head _this_is_not_used;
2173
        PyObject_VAR_HEAD
2174
        Py_hash_t ob_hash;
2175
        PyObject *ob_item[NUM_KEYWORDS];
2176
    } _kwtuple = {
2177
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2178
        .ob_hash = -1,
2179
        .ob_item = { &_Py_ID(path), },
2180
    };
2181
    #undef NUM_KEYWORDS
2182
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2183
2184
    #else  // !Py_BUILD_CORE
2185
    #  define KWTUPLE NULL
2186
    #endif  // !Py_BUILD_CORE
2187
2188
    static const char * const _keywords[] = {"path", NULL};
2189
    static _PyArg_Parser _parser = {
2190
        .keywords = _keywords,
2191
        .fname = "_path_lexists",
2192
        .kwtuple = KWTUPLE,
2193
    };
2194
    #undef KWTUPLE
2195
    PyObject *argsbuf[1];
2196
    path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1);
2197
    int _return_value;
2198
2199
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2200
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2201
    if (!args) {
2202
        goto exit;
2203
    }
2204
    if (!path_converter(args[0], &path)) {
2205
        goto exit;
2206
    }
2207
    _return_value = os__path_lexists_impl(module, &path);
2208
    if ((_return_value == -1) && PyErr_Occurred()) {
2209
        goto exit;
2210
    }
2211
    return_value = PyBool_FromLong((long)_return_value);
2212
2213
exit:
2214
    /* Cleanup for path */
2215
    path_cleanup(&path);
2216
2217
    return return_value;
2218
}
2219
2220
#endif /* defined(MS_WINDOWS) */
2221
2222
#if defined(MS_WINDOWS)
2223
2224
PyDoc_STRVAR(os__path_isdir__doc__,
2225
"_path_isdir($module, path, /)\n"
2226
"--\n"
2227
"\n"
2228
"Return true if the pathname refers to an existing directory.");
2229
2230
#define OS__PATH_ISDIR_METHODDEF    \
2231
    {"_path_isdir", (PyCFunction)os__path_isdir, METH_O, os__path_isdir__doc__},
2232
2233
static int
2234
os__path_isdir_impl(PyObject *module, path_t *path);
2235
2236
static PyObject *
2237
os__path_isdir(PyObject *module, PyObject *arg)
2238
{
2239
    PyObject *return_value = NULL;
2240
    path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1);
2241
    int _return_value;
2242
2243
    if (!path_converter(arg, &path)) {
2244
        goto exit;
2245
    }
2246
    _return_value = os__path_isdir_impl(module, &path);
2247
    if ((_return_value == -1) && PyErr_Occurred()) {
2248
        goto exit;
2249
    }
2250
    return_value = PyBool_FromLong((long)_return_value);
2251
2252
exit:
2253
    /* Cleanup for path */
2254
    path_cleanup(&path);
2255
2256
    return return_value;
2257
}
2258
2259
#endif /* defined(MS_WINDOWS) */
2260
2261
#if defined(MS_WINDOWS)
2262
2263
PyDoc_STRVAR(os__path_isfile__doc__,
2264
"_path_isfile($module, /, path)\n"
2265
"--\n"
2266
"\n"
2267
"Test whether a path is a regular file");
2268
2269
#define OS__PATH_ISFILE_METHODDEF    \
2270
    {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
2271
2272
static int
2273
os__path_isfile_impl(PyObject *module, path_t *path);
2274
2275
static PyObject *
2276
os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2277
{
2278
    PyObject *return_value = NULL;
2279
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2280
2281
    #define NUM_KEYWORDS 1
2282
    static struct {
2283
        PyGC_Head _this_is_not_used;
2284
        PyObject_VAR_HEAD
2285
        Py_hash_t ob_hash;
2286
        PyObject *ob_item[NUM_KEYWORDS];
2287
    } _kwtuple = {
2288
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2289
        .ob_hash = -1,
2290
        .ob_item = { &_Py_ID(path), },
2291
    };
2292
    #undef NUM_KEYWORDS
2293
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2294
2295
    #else  // !Py_BUILD_CORE
2296
    #  define KWTUPLE NULL
2297
    #endif  // !Py_BUILD_CORE
2298
2299
    static const char * const _keywords[] = {"path", NULL};
2300
    static _PyArg_Parser _parser = {
2301
        .keywords = _keywords,
2302
        .fname = "_path_isfile",
2303
        .kwtuple = KWTUPLE,
2304
    };
2305
    #undef KWTUPLE
2306
    PyObject *argsbuf[1];
2307
    path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1);
2308
    int _return_value;
2309
2310
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2311
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2312
    if (!args) {
2313
        goto exit;
2314
    }
2315
    if (!path_converter(args[0], &path)) {
2316
        goto exit;
2317
    }
2318
    _return_value = os__path_isfile_impl(module, &path);
2319
    if ((_return_value == -1) && PyErr_Occurred()) {
2320
        goto exit;
2321
    }
2322
    return_value = PyBool_FromLong((long)_return_value);
2323
2324
exit:
2325
    /* Cleanup for path */
2326
    path_cleanup(&path);
2327
2328
    return return_value;
2329
}
2330
2331
#endif /* defined(MS_WINDOWS) */
2332
2333
#if defined(MS_WINDOWS)
2334
2335
PyDoc_STRVAR(os__path_islink__doc__,
2336
"_path_islink($module, /, path)\n"
2337
"--\n"
2338
"\n"
2339
"Test whether a path is a symbolic link");
2340
2341
#define OS__PATH_ISLINK_METHODDEF    \
2342
    {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
2343
2344
static int
2345
os__path_islink_impl(PyObject *module, path_t *path);
2346
2347
static PyObject *
2348
os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2349
{
2350
    PyObject *return_value = NULL;
2351
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2352
2353
    #define NUM_KEYWORDS 1
2354
    static struct {
2355
        PyGC_Head _this_is_not_used;
2356
        PyObject_VAR_HEAD
2357
        Py_hash_t ob_hash;
2358
        PyObject *ob_item[NUM_KEYWORDS];
2359
    } _kwtuple = {
2360
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2361
        .ob_hash = -1,
2362
        .ob_item = { &_Py_ID(path), },
2363
    };
2364
    #undef NUM_KEYWORDS
2365
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2366
2367
    #else  // !Py_BUILD_CORE
2368
    #  define KWTUPLE NULL
2369
    #endif  // !Py_BUILD_CORE
2370
2371
    static const char * const _keywords[] = {"path", NULL};
2372
    static _PyArg_Parser _parser = {
2373
        .keywords = _keywords,
2374
        .fname = "_path_islink",
2375
        .kwtuple = KWTUPLE,
2376
    };
2377
    #undef KWTUPLE
2378
    PyObject *argsbuf[1];
2379
    path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1);
2380
    int _return_value;
2381
2382
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2383
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2384
    if (!args) {
2385
        goto exit;
2386
    }
2387
    if (!path_converter(args[0], &path)) {
2388
        goto exit;
2389
    }
2390
    _return_value = os__path_islink_impl(module, &path);
2391
    if ((_return_value == -1) && PyErr_Occurred()) {
2392
        goto exit;
2393
    }
2394
    return_value = PyBool_FromLong((long)_return_value);
2395
2396
exit:
2397
    /* Cleanup for path */
2398
    path_cleanup(&path);
2399
2400
    return return_value;
2401
}
2402
2403
#endif /* defined(MS_WINDOWS) */
2404
2405
#if defined(MS_WINDOWS)
2406
2407
PyDoc_STRVAR(os__path_isjunction__doc__,
2408
"_path_isjunction($module, /, path)\n"
2409
"--\n"
2410
"\n"
2411
"Test whether a path is a junction");
2412
2413
#define OS__PATH_ISJUNCTION_METHODDEF    \
2414
    {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__},
2415
2416
static int
2417
os__path_isjunction_impl(PyObject *module, path_t *path);
2418
2419
static PyObject *
2420
os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2421
{
2422
    PyObject *return_value = NULL;
2423
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2424
2425
    #define NUM_KEYWORDS 1
2426
    static struct {
2427
        PyGC_Head _this_is_not_used;
2428
        PyObject_VAR_HEAD
2429
        Py_hash_t ob_hash;
2430
        PyObject *ob_item[NUM_KEYWORDS];
2431
    } _kwtuple = {
2432
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2433
        .ob_hash = -1,
2434
        .ob_item = { &_Py_ID(path), },
2435
    };
2436
    #undef NUM_KEYWORDS
2437
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2438
2439
    #else  // !Py_BUILD_CORE
2440
    #  define KWTUPLE NULL
2441
    #endif  // !Py_BUILD_CORE
2442
2443
    static const char * const _keywords[] = {"path", NULL};
2444
    static _PyArg_Parser _parser = {
2445
        .keywords = _keywords,
2446
        .fname = "_path_isjunction",
2447
        .kwtuple = KWTUPLE,
2448
    };
2449
    #undef KWTUPLE
2450
    PyObject *argsbuf[1];
2451
    path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1);
2452
    int _return_value;
2453
2454
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2455
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2456
    if (!args) {
2457
        goto exit;
2458
    }
2459
    if (!path_converter(args[0], &path)) {
2460
        goto exit;
2461
    }
2462
    _return_value = os__path_isjunction_impl(module, &path);
2463
    if ((_return_value == -1) && PyErr_Occurred()) {
2464
        goto exit;
2465
    }
2466
    return_value = PyBool_FromLong((long)_return_value);
2467
2468
exit:
2469
    /* Cleanup for path */
2470
    path_cleanup(&path);
2471
2472
    return return_value;
2473
}
2474
2475
#endif /* defined(MS_WINDOWS) */
2476
2477
PyDoc_STRVAR(os__path_splitroot_ex__doc__,
2478
"_path_splitroot_ex($module, path, /)\n"
2479
"--\n"
2480
"\n"
2481
"Split a pathname into drive, root and tail.\n"
2482
"\n"
2483
"The tail contains anything after the root.");
2484
2485
#define OS__PATH_SPLITROOT_EX_METHODDEF    \
2486
    {"_path_splitroot_ex", (PyCFunction)os__path_splitroot_ex, METH_O, os__path_splitroot_ex__doc__},
2487
2488
static PyObject *
2489
os__path_splitroot_ex_impl(PyObject *module, path_t *path);
2490
2491
static PyObject *
2492
os__path_splitroot_ex(PyObject *module, PyObject *arg)
2493
0
{
2494
0
    PyObject *return_value = NULL;
2495
0
    path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0);
2496
2497
0
    if (!path_converter(arg, &path)) {
2498
0
        goto exit;
2499
0
    }
2500
0
    return_value = os__path_splitroot_ex_impl(module, &path);
2501
2502
0
exit:
2503
    /* Cleanup for path */
2504
0
    path_cleanup(&path);
2505
2506
0
    return return_value;
2507
0
}
2508
2509
PyDoc_STRVAR(os__path_normpath__doc__,
2510
"_path_normpath($module, /, path)\n"
2511
"--\n"
2512
"\n"
2513
"Normalize path, eliminating double slashes, etc.");
2514
2515
#define OS__PATH_NORMPATH_METHODDEF    \
2516
    {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
2517
2518
static PyObject *
2519
os__path_normpath_impl(PyObject *module, path_t *path);
2520
2521
static PyObject *
2522
os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2523
80
{
2524
80
    PyObject *return_value = NULL;
2525
80
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2526
2527
80
    #define NUM_KEYWORDS 1
2528
80
    static struct {
2529
80
        PyGC_Head _this_is_not_used;
2530
80
        PyObject_VAR_HEAD
2531
80
        Py_hash_t ob_hash;
2532
80
        PyObject *ob_item[NUM_KEYWORDS];
2533
80
    } _kwtuple = {
2534
80
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2535
80
        .ob_hash = -1,
2536
80
        .ob_item = { &_Py_ID(path), },
2537
80
    };
2538
80
    #undef NUM_KEYWORDS
2539
80
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2540
2541
    #else  // !Py_BUILD_CORE
2542
    #  define KWTUPLE NULL
2543
    #endif  // !Py_BUILD_CORE
2544
2545
80
    static const char * const _keywords[] = {"path", NULL};
2546
80
    static _PyArg_Parser _parser = {
2547
80
        .keywords = _keywords,
2548
80
        .fname = "_path_normpath",
2549
80
        .kwtuple = KWTUPLE,
2550
80
    };
2551
80
    #undef KWTUPLE
2552
80
    PyObject *argsbuf[1];
2553
80
    path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0);
2554
2555
80
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2556
80
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2557
80
    if (!args) {
2558
0
        goto exit;
2559
0
    }
2560
80
    if (!path_converter(args[0], &path)) {
2561
0
        goto exit;
2562
0
    }
2563
80
    return_value = os__path_normpath_impl(module, &path);
2564
2565
80
exit:
2566
    /* Cleanup for path */
2567
80
    path_cleanup(&path);
2568
2569
80
    return return_value;
2570
80
}
2571
2572
PyDoc_STRVAR(os_mkdir__doc__,
2573
"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
2574
"--\n"
2575
"\n"
2576
"Create a directory.\n"
2577
"\n"
2578
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2579
"  and path should be relative; path will then be relative to that directory.\n"
2580
"dir_fd may not be implemented on your platform.\n"
2581
"  If it is unavailable, using it will raise a NotImplementedError.\n"
2582
"\n"
2583
"The mode argument is ignored on Windows. Where it is used, the current umask\n"
2584
"value is first masked out.");
2585
2586
#define OS_MKDIR_METHODDEF    \
2587
    {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
2588
2589
static PyObject *
2590
os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
2591
2592
static PyObject *
2593
os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2594
0
{
2595
0
    PyObject *return_value = NULL;
2596
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2597
2598
0
    #define NUM_KEYWORDS 3
2599
0
    static struct {
2600
0
        PyGC_Head _this_is_not_used;
2601
0
        PyObject_VAR_HEAD
2602
0
        Py_hash_t ob_hash;
2603
0
        PyObject *ob_item[NUM_KEYWORDS];
2604
0
    } _kwtuple = {
2605
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2606
0
        .ob_hash = -1,
2607
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
2608
0
    };
2609
0
    #undef NUM_KEYWORDS
2610
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2611
2612
    #else  // !Py_BUILD_CORE
2613
    #  define KWTUPLE NULL
2614
    #endif  // !Py_BUILD_CORE
2615
2616
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
2617
0
    static _PyArg_Parser _parser = {
2618
0
        .keywords = _keywords,
2619
0
        .fname = "mkdir",
2620
0
        .kwtuple = KWTUPLE,
2621
0
    };
2622
0
    #undef KWTUPLE
2623
0
    PyObject *argsbuf[3];
2624
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
2625
0
    path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0);
2626
0
    int mode = 511;
2627
0
    int dir_fd = DEFAULT_DIR_FD;
2628
2629
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2630
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2631
0
    if (!args) {
2632
0
        goto exit;
2633
0
    }
2634
0
    if (!path_converter(args[0], &path)) {
2635
0
        goto exit;
2636
0
    }
2637
0
    if (!noptargs) {
2638
0
        goto skip_optional_pos;
2639
0
    }
2640
0
    if (args[1]) {
2641
0
        mode = PyLong_AsInt(args[1]);
2642
0
        if (mode == -1 && PyErr_Occurred()) {
2643
0
            goto exit;
2644
0
        }
2645
0
        if (!--noptargs) {
2646
0
            goto skip_optional_pos;
2647
0
        }
2648
0
    }
2649
0
skip_optional_pos:
2650
0
    if (!noptargs) {
2651
0
        goto skip_optional_kwonly;
2652
0
    }
2653
0
    if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
2654
0
        goto exit;
2655
0
    }
2656
0
skip_optional_kwonly:
2657
0
    return_value = os_mkdir_impl(module, &path, mode, dir_fd);
2658
2659
0
exit:
2660
    /* Cleanup for path */
2661
0
    path_cleanup(&path);
2662
2663
0
    return return_value;
2664
0
}
2665
2666
#if defined(HAVE_NICE)
2667
2668
PyDoc_STRVAR(os_nice__doc__,
2669
"nice($module, increment, /)\n"
2670
"--\n"
2671
"\n"
2672
"Add increment to the priority of process and return the new priority.");
2673
2674
#define OS_NICE_METHODDEF    \
2675
    {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
2676
2677
static PyObject *
2678
os_nice_impl(PyObject *module, int increment);
2679
2680
static PyObject *
2681
os_nice(PyObject *module, PyObject *arg)
2682
0
{
2683
0
    PyObject *return_value = NULL;
2684
0
    int increment;
2685
2686
0
    increment = PyLong_AsInt(arg);
2687
0
    if (increment == -1 && PyErr_Occurred()) {
2688
0
        goto exit;
2689
0
    }
2690
0
    return_value = os_nice_impl(module, increment);
2691
2692
0
exit:
2693
0
    return return_value;
2694
0
}
2695
2696
#endif /* defined(HAVE_NICE) */
2697
2698
#if defined(HAVE_GETPRIORITY)
2699
2700
PyDoc_STRVAR(os_getpriority__doc__,
2701
"getpriority($module, /, which, who)\n"
2702
"--\n"
2703
"\n"
2704
"Return program scheduling priority.");
2705
2706
#define OS_GETPRIORITY_METHODDEF    \
2707
    {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
2708
2709
static PyObject *
2710
os_getpriority_impl(PyObject *module, int which, int who);
2711
2712
static PyObject *
2713
os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2714
0
{
2715
0
    PyObject *return_value = NULL;
2716
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2717
2718
0
    #define NUM_KEYWORDS 2
2719
0
    static struct {
2720
0
        PyGC_Head _this_is_not_used;
2721
0
        PyObject_VAR_HEAD
2722
0
        Py_hash_t ob_hash;
2723
0
        PyObject *ob_item[NUM_KEYWORDS];
2724
0
    } _kwtuple = {
2725
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2726
0
        .ob_hash = -1,
2727
0
        .ob_item = { &_Py_ID(which), &_Py_ID(who), },
2728
0
    };
2729
0
    #undef NUM_KEYWORDS
2730
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2731
2732
    #else  // !Py_BUILD_CORE
2733
    #  define KWTUPLE NULL
2734
    #endif  // !Py_BUILD_CORE
2735
2736
0
    static const char * const _keywords[] = {"which", "who", NULL};
2737
0
    static _PyArg_Parser _parser = {
2738
0
        .keywords = _keywords,
2739
0
        .fname = "getpriority",
2740
0
        .kwtuple = KWTUPLE,
2741
0
    };
2742
0
    #undef KWTUPLE
2743
0
    PyObject *argsbuf[2];
2744
0
    int which;
2745
0
    int who;
2746
2747
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2748
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2749
0
    if (!args) {
2750
0
        goto exit;
2751
0
    }
2752
0
    which = PyLong_AsInt(args[0]);
2753
0
    if (which == -1 && PyErr_Occurred()) {
2754
0
        goto exit;
2755
0
    }
2756
0
    who = PyLong_AsInt(args[1]);
2757
0
    if (who == -1 && PyErr_Occurred()) {
2758
0
        goto exit;
2759
0
    }
2760
0
    return_value = os_getpriority_impl(module, which, who);
2761
2762
0
exit:
2763
0
    return return_value;
2764
0
}
2765
2766
#endif /* defined(HAVE_GETPRIORITY) */
2767
2768
#if defined(HAVE_SETPRIORITY)
2769
2770
PyDoc_STRVAR(os_setpriority__doc__,
2771
"setpriority($module, /, which, who, priority)\n"
2772
"--\n"
2773
"\n"
2774
"Set program scheduling priority.");
2775
2776
#define OS_SETPRIORITY_METHODDEF    \
2777
    {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
2778
2779
static PyObject *
2780
os_setpriority_impl(PyObject *module, int which, int who, int priority);
2781
2782
static PyObject *
2783
os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2784
0
{
2785
0
    PyObject *return_value = NULL;
2786
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2787
2788
0
    #define NUM_KEYWORDS 3
2789
0
    static struct {
2790
0
        PyGC_Head _this_is_not_used;
2791
0
        PyObject_VAR_HEAD
2792
0
        Py_hash_t ob_hash;
2793
0
        PyObject *ob_item[NUM_KEYWORDS];
2794
0
    } _kwtuple = {
2795
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2796
0
        .ob_hash = -1,
2797
0
        .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), },
2798
0
    };
2799
0
    #undef NUM_KEYWORDS
2800
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2801
2802
    #else  // !Py_BUILD_CORE
2803
    #  define KWTUPLE NULL
2804
    #endif  // !Py_BUILD_CORE
2805
2806
0
    static const char * const _keywords[] = {"which", "who", "priority", NULL};
2807
0
    static _PyArg_Parser _parser = {
2808
0
        .keywords = _keywords,
2809
0
        .fname = "setpriority",
2810
0
        .kwtuple = KWTUPLE,
2811
0
    };
2812
0
    #undef KWTUPLE
2813
0
    PyObject *argsbuf[3];
2814
0
    int which;
2815
0
    int who;
2816
0
    int priority;
2817
2818
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2819
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2820
0
    if (!args) {
2821
0
        goto exit;
2822
0
    }
2823
0
    which = PyLong_AsInt(args[0]);
2824
0
    if (which == -1 && PyErr_Occurred()) {
2825
0
        goto exit;
2826
0
    }
2827
0
    who = PyLong_AsInt(args[1]);
2828
0
    if (who == -1 && PyErr_Occurred()) {
2829
0
        goto exit;
2830
0
    }
2831
0
    priority = PyLong_AsInt(args[2]);
2832
0
    if (priority == -1 && PyErr_Occurred()) {
2833
0
        goto exit;
2834
0
    }
2835
0
    return_value = os_setpriority_impl(module, which, who, priority);
2836
2837
0
exit:
2838
0
    return return_value;
2839
0
}
2840
2841
#endif /* defined(HAVE_SETPRIORITY) */
2842
2843
PyDoc_STRVAR(os_rename__doc__,
2844
"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
2845
"--\n"
2846
"\n"
2847
"Rename a file or directory.\n"
2848
"\n"
2849
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
2850
"  descriptor open to a directory, and the respective path string (src or dst)\n"
2851
"  should be relative; the path will then be relative to that directory.\n"
2852
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
2853
"  If they are unavailable, using them will raise a NotImplementedError.");
2854
2855
#define OS_RENAME_METHODDEF    \
2856
    {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
2857
2858
static PyObject *
2859
os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
2860
               int dst_dir_fd);
2861
2862
static PyObject *
2863
os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2864
0
{
2865
0
    PyObject *return_value = NULL;
2866
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2867
2868
0
    #define NUM_KEYWORDS 4
2869
0
    static struct {
2870
0
        PyGC_Head _this_is_not_used;
2871
0
        PyObject_VAR_HEAD
2872
0
        Py_hash_t ob_hash;
2873
0
        PyObject *ob_item[NUM_KEYWORDS];
2874
0
    } _kwtuple = {
2875
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2876
0
        .ob_hash = -1,
2877
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
2878
0
    };
2879
0
    #undef NUM_KEYWORDS
2880
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2881
2882
    #else  // !Py_BUILD_CORE
2883
    #  define KWTUPLE NULL
2884
    #endif  // !Py_BUILD_CORE
2885
2886
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
2887
0
    static _PyArg_Parser _parser = {
2888
0
        .keywords = _keywords,
2889
0
        .fname = "rename",
2890
0
        .kwtuple = KWTUPLE,
2891
0
    };
2892
0
    #undef KWTUPLE
2893
0
    PyObject *argsbuf[4];
2894
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
2895
0
    path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0);
2896
0
    path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0);
2897
0
    int src_dir_fd = DEFAULT_DIR_FD;
2898
0
    int dst_dir_fd = DEFAULT_DIR_FD;
2899
2900
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2901
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2902
0
    if (!args) {
2903
0
        goto exit;
2904
0
    }
2905
0
    if (!path_converter(args[0], &src)) {
2906
0
        goto exit;
2907
0
    }
2908
0
    if (!path_converter(args[1], &dst)) {
2909
0
        goto exit;
2910
0
    }
2911
0
    if (!noptargs) {
2912
0
        goto skip_optional_kwonly;
2913
0
    }
2914
0
    if (args[2]) {
2915
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
2916
0
            goto exit;
2917
0
        }
2918
0
        if (!--noptargs) {
2919
0
            goto skip_optional_kwonly;
2920
0
        }
2921
0
    }
2922
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
2923
0
        goto exit;
2924
0
    }
2925
0
skip_optional_kwonly:
2926
0
    return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
2927
2928
0
exit:
2929
    /* Cleanup for src */
2930
0
    path_cleanup(&src);
2931
    /* Cleanup for dst */
2932
0
    path_cleanup(&dst);
2933
2934
0
    return return_value;
2935
0
}
2936
2937
PyDoc_STRVAR(os_replace__doc__,
2938
"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
2939
"--\n"
2940
"\n"
2941
"Rename a file or directory, overwriting the destination.\n"
2942
"\n"
2943
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
2944
"  descriptor open to a directory, and the respective path string (src or dst)\n"
2945
"  should be relative; the path will then be relative to that directory.\n"
2946
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
2947
"  If they are unavailable, using them will raise a NotImplementedError.");
2948
2949
#define OS_REPLACE_METHODDEF    \
2950
    {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
2951
2952
static PyObject *
2953
os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
2954
                int dst_dir_fd);
2955
2956
static PyObject *
2957
os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2958
244
{
2959
244
    PyObject *return_value = NULL;
2960
244
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2961
2962
244
    #define NUM_KEYWORDS 4
2963
244
    static struct {
2964
244
        PyGC_Head _this_is_not_used;
2965
244
        PyObject_VAR_HEAD
2966
244
        Py_hash_t ob_hash;
2967
244
        PyObject *ob_item[NUM_KEYWORDS];
2968
244
    } _kwtuple = {
2969
244
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2970
244
        .ob_hash = -1,
2971
244
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
2972
244
    };
2973
244
    #undef NUM_KEYWORDS
2974
244
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2975
2976
    #else  // !Py_BUILD_CORE
2977
    #  define KWTUPLE NULL
2978
    #endif  // !Py_BUILD_CORE
2979
2980
244
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
2981
244
    static _PyArg_Parser _parser = {
2982
244
        .keywords = _keywords,
2983
244
        .fname = "replace",
2984
244
        .kwtuple = KWTUPLE,
2985
244
    };
2986
244
    #undef KWTUPLE
2987
244
    PyObject *argsbuf[4];
2988
244
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
2989
244
    path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0);
2990
244
    path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0);
2991
244
    int src_dir_fd = DEFAULT_DIR_FD;
2992
244
    int dst_dir_fd = DEFAULT_DIR_FD;
2993
2994
244
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2995
244
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2996
244
    if (!args) {
2997
0
        goto exit;
2998
0
    }
2999
244
    if (!path_converter(args[0], &src)) {
3000
0
        goto exit;
3001
0
    }
3002
244
    if (!path_converter(args[1], &dst)) {
3003
0
        goto exit;
3004
0
    }
3005
244
    if (!noptargs) {
3006
244
        goto skip_optional_kwonly;
3007
244
    }
3008
0
    if (args[2]) {
3009
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
3010
0
            goto exit;
3011
0
        }
3012
0
        if (!--noptargs) {
3013
0
            goto skip_optional_kwonly;
3014
0
        }
3015
0
    }
3016
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
3017
0
        goto exit;
3018
0
    }
3019
244
skip_optional_kwonly:
3020
244
    return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
3021
3022
244
exit:
3023
    /* Cleanup for src */
3024
244
    path_cleanup(&src);
3025
    /* Cleanup for dst */
3026
244
    path_cleanup(&dst);
3027
3028
244
    return return_value;
3029
244
}
3030
3031
PyDoc_STRVAR(os_rmdir__doc__,
3032
"rmdir($module, /, path, *, dir_fd=None)\n"
3033
"--\n"
3034
"\n"
3035
"Remove a directory.\n"
3036
"\n"
3037
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3038
"  and path should be relative; path will then be relative to that directory.\n"
3039
"dir_fd may not be implemented on your platform.\n"
3040
"  If it is unavailable, using it will raise a NotImplementedError.");
3041
3042
#define OS_RMDIR_METHODDEF    \
3043
    {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
3044
3045
static PyObject *
3046
os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
3047
3048
static PyObject *
3049
os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3050
0
{
3051
0
    PyObject *return_value = NULL;
3052
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3053
3054
0
    #define NUM_KEYWORDS 2
3055
0
    static struct {
3056
0
        PyGC_Head _this_is_not_used;
3057
0
        PyObject_VAR_HEAD
3058
0
        Py_hash_t ob_hash;
3059
0
        PyObject *ob_item[NUM_KEYWORDS];
3060
0
    } _kwtuple = {
3061
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3062
0
        .ob_hash = -1,
3063
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3064
0
    };
3065
0
    #undef NUM_KEYWORDS
3066
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3067
3068
    #else  // !Py_BUILD_CORE
3069
    #  define KWTUPLE NULL
3070
    #endif  // !Py_BUILD_CORE
3071
3072
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3073
0
    static _PyArg_Parser _parser = {
3074
0
        .keywords = _keywords,
3075
0
        .fname = "rmdir",
3076
0
        .kwtuple = KWTUPLE,
3077
0
    };
3078
0
    #undef KWTUPLE
3079
0
    PyObject *argsbuf[2];
3080
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3081
0
    path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0);
3082
0
    int dir_fd = DEFAULT_DIR_FD;
3083
3084
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3085
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3086
0
    if (!args) {
3087
0
        goto exit;
3088
0
    }
3089
0
    if (!path_converter(args[0], &path)) {
3090
0
        goto exit;
3091
0
    }
3092
0
    if (!noptargs) {
3093
0
        goto skip_optional_kwonly;
3094
0
    }
3095
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3096
0
        goto exit;
3097
0
    }
3098
0
skip_optional_kwonly:
3099
0
    return_value = os_rmdir_impl(module, &path, dir_fd);
3100
3101
0
exit:
3102
    /* Cleanup for path */
3103
0
    path_cleanup(&path);
3104
3105
0
    return return_value;
3106
0
}
3107
3108
#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
3109
3110
PyDoc_STRVAR(os_system__doc__,
3111
"system($module, /, command)\n"
3112
"--\n"
3113
"\n"
3114
"Execute the command in a subshell.");
3115
3116
#define OS_SYSTEM_METHODDEF    \
3117
    {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3118
3119
static long
3120
os_system_impl(PyObject *module, const wchar_t *command);
3121
3122
static PyObject *
3123
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3124
{
3125
    PyObject *return_value = NULL;
3126
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3127
3128
    #define NUM_KEYWORDS 1
3129
    static struct {
3130
        PyGC_Head _this_is_not_used;
3131
        PyObject_VAR_HEAD
3132
        Py_hash_t ob_hash;
3133
        PyObject *ob_item[NUM_KEYWORDS];
3134
    } _kwtuple = {
3135
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3136
        .ob_hash = -1,
3137
        .ob_item = { &_Py_ID(command), },
3138
    };
3139
    #undef NUM_KEYWORDS
3140
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3141
3142
    #else  // !Py_BUILD_CORE
3143
    #  define KWTUPLE NULL
3144
    #endif  // !Py_BUILD_CORE
3145
3146
    static const char * const _keywords[] = {"command", NULL};
3147
    static _PyArg_Parser _parser = {
3148
        .keywords = _keywords,
3149
        .fname = "system",
3150
        .kwtuple = KWTUPLE,
3151
    };
3152
    #undef KWTUPLE
3153
    PyObject *argsbuf[1];
3154
    const wchar_t *command = NULL;
3155
    long _return_value;
3156
3157
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3158
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3159
    if (!args) {
3160
        goto exit;
3161
    }
3162
    if (!PyUnicode_Check(args[0])) {
3163
        _PyArg_BadArgument("system", "argument 'command'", "str", args[0]);
3164
        goto exit;
3165
    }
3166
    command = PyUnicode_AsWideCharString(args[0], NULL);
3167
    if (command == NULL) {
3168
        goto exit;
3169
    }
3170
    _return_value = os_system_impl(module, command);
3171
    if ((_return_value == -1) && PyErr_Occurred()) {
3172
        goto exit;
3173
    }
3174
    return_value = PyLong_FromLong(_return_value);
3175
3176
exit:
3177
    /* Cleanup for command */
3178
    PyMem_Free((void *)command);
3179
3180
    return return_value;
3181
}
3182
3183
#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
3184
3185
#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
3186
3187
PyDoc_STRVAR(os_system__doc__,
3188
"system($module, /, command)\n"
3189
"--\n"
3190
"\n"
3191
"Execute the command in a subshell.");
3192
3193
#define OS_SYSTEM_METHODDEF    \
3194
    {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3195
3196
static long
3197
os_system_impl(PyObject *module, PyObject *command);
3198
3199
static PyObject *
3200
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3201
0
{
3202
0
    PyObject *return_value = NULL;
3203
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3204
3205
0
    #define NUM_KEYWORDS 1
3206
0
    static struct {
3207
0
        PyGC_Head _this_is_not_used;
3208
0
        PyObject_VAR_HEAD
3209
0
        Py_hash_t ob_hash;
3210
0
        PyObject *ob_item[NUM_KEYWORDS];
3211
0
    } _kwtuple = {
3212
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3213
0
        .ob_hash = -1,
3214
0
        .ob_item = { &_Py_ID(command), },
3215
0
    };
3216
0
    #undef NUM_KEYWORDS
3217
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3218
3219
    #else  // !Py_BUILD_CORE
3220
    #  define KWTUPLE NULL
3221
    #endif  // !Py_BUILD_CORE
3222
3223
0
    static const char * const _keywords[] = {"command", NULL};
3224
0
    static _PyArg_Parser _parser = {
3225
0
        .keywords = _keywords,
3226
0
        .fname = "system",
3227
0
        .kwtuple = KWTUPLE,
3228
0
    };
3229
0
    #undef KWTUPLE
3230
0
    PyObject *argsbuf[1];
3231
0
    PyObject *command = NULL;
3232
0
    long _return_value;
3233
3234
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3235
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3236
0
    if (!args) {
3237
0
        goto exit;
3238
0
    }
3239
0
    if (!PyUnicode_FSConverter(args[0], &command)) {
3240
0
        goto exit;
3241
0
    }
3242
0
    _return_value = os_system_impl(module, command);
3243
0
    if ((_return_value == -1) && PyErr_Occurred()) {
3244
0
        goto exit;
3245
0
    }
3246
0
    return_value = PyLong_FromLong(_return_value);
3247
3248
0
exit:
3249
    /* Cleanup for command */
3250
0
    Py_XDECREF(command);
3251
3252
0
    return return_value;
3253
0
}
3254
3255
#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
3256
3257
#if defined(HAVE_UMASK)
3258
3259
PyDoc_STRVAR(os_umask__doc__,
3260
"umask($module, mask, /)\n"
3261
"--\n"
3262
"\n"
3263
"Set the current numeric umask and return the previous umask.");
3264
3265
#define OS_UMASK_METHODDEF    \
3266
    {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
3267
3268
static PyObject *
3269
os_umask_impl(PyObject *module, int mask);
3270
3271
static PyObject *
3272
os_umask(PyObject *module, PyObject *arg)
3273
0
{
3274
0
    PyObject *return_value = NULL;
3275
0
    int mask;
3276
3277
0
    mask = PyLong_AsInt(arg);
3278
0
    if (mask == -1 && PyErr_Occurred()) {
3279
0
        goto exit;
3280
0
    }
3281
0
    return_value = os_umask_impl(module, mask);
3282
3283
0
exit:
3284
0
    return return_value;
3285
0
}
3286
3287
#endif /* defined(HAVE_UMASK) */
3288
3289
PyDoc_STRVAR(os_unlink__doc__,
3290
"unlink($module, /, path, *, dir_fd=None)\n"
3291
"--\n"
3292
"\n"
3293
"Remove a file (same as remove()).\n"
3294
"\n"
3295
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3296
"  and path should be relative; path will then be relative to that directory.\n"
3297
"dir_fd may not be implemented on your platform.\n"
3298
"  If it is unavailable, using it will raise a NotImplementedError.");
3299
3300
#define OS_UNLINK_METHODDEF    \
3301
    {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
3302
3303
static PyObject *
3304
os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
3305
3306
static PyObject *
3307
os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3308
0
{
3309
0
    PyObject *return_value = NULL;
3310
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3311
3312
0
    #define NUM_KEYWORDS 2
3313
0
    static struct {
3314
0
        PyGC_Head _this_is_not_used;
3315
0
        PyObject_VAR_HEAD
3316
0
        Py_hash_t ob_hash;
3317
0
        PyObject *ob_item[NUM_KEYWORDS];
3318
0
    } _kwtuple = {
3319
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3320
0
        .ob_hash = -1,
3321
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3322
0
    };
3323
0
    #undef NUM_KEYWORDS
3324
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3325
3326
    #else  // !Py_BUILD_CORE
3327
    #  define KWTUPLE NULL
3328
    #endif  // !Py_BUILD_CORE
3329
3330
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3331
0
    static _PyArg_Parser _parser = {
3332
0
        .keywords = _keywords,
3333
0
        .fname = "unlink",
3334
0
        .kwtuple = KWTUPLE,
3335
0
    };
3336
0
    #undef KWTUPLE
3337
0
    PyObject *argsbuf[2];
3338
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3339
0
    path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0);
3340
0
    int dir_fd = DEFAULT_DIR_FD;
3341
3342
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3343
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3344
0
    if (!args) {
3345
0
        goto exit;
3346
0
    }
3347
0
    if (!path_converter(args[0], &path)) {
3348
0
        goto exit;
3349
0
    }
3350
0
    if (!noptargs) {
3351
0
        goto skip_optional_kwonly;
3352
0
    }
3353
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3354
0
        goto exit;
3355
0
    }
3356
0
skip_optional_kwonly:
3357
0
    return_value = os_unlink_impl(module, &path, dir_fd);
3358
3359
0
exit:
3360
    /* Cleanup for path */
3361
0
    path_cleanup(&path);
3362
3363
0
    return return_value;
3364
0
}
3365
3366
PyDoc_STRVAR(os_remove__doc__,
3367
"remove($module, /, path, *, dir_fd=None)\n"
3368
"--\n"
3369
"\n"
3370
"Remove a file (same as unlink()).\n"
3371
"\n"
3372
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3373
"  and path should be relative; path will then be relative to that directory.\n"
3374
"dir_fd may not be implemented on your platform.\n"
3375
"  If it is unavailable, using it will raise a NotImplementedError.");
3376
3377
#define OS_REMOVE_METHODDEF    \
3378
    {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
3379
3380
static PyObject *
3381
os_remove_impl(PyObject *module, path_t *path, int dir_fd);
3382
3383
static PyObject *
3384
os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3385
0
{
3386
0
    PyObject *return_value = NULL;
3387
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3388
3389
0
    #define NUM_KEYWORDS 2
3390
0
    static struct {
3391
0
        PyGC_Head _this_is_not_used;
3392
0
        PyObject_VAR_HEAD
3393
0
        Py_hash_t ob_hash;
3394
0
        PyObject *ob_item[NUM_KEYWORDS];
3395
0
    } _kwtuple = {
3396
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3397
0
        .ob_hash = -1,
3398
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3399
0
    };
3400
0
    #undef NUM_KEYWORDS
3401
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3402
3403
    #else  // !Py_BUILD_CORE
3404
    #  define KWTUPLE NULL
3405
    #endif  // !Py_BUILD_CORE
3406
3407
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3408
0
    static _PyArg_Parser _parser = {
3409
0
        .keywords = _keywords,
3410
0
        .fname = "remove",
3411
0
        .kwtuple = KWTUPLE,
3412
0
    };
3413
0
    #undef KWTUPLE
3414
0
    PyObject *argsbuf[2];
3415
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3416
0
    path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0);
3417
0
    int dir_fd = DEFAULT_DIR_FD;
3418
3419
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3420
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3421
0
    if (!args) {
3422
0
        goto exit;
3423
0
    }
3424
0
    if (!path_converter(args[0], &path)) {
3425
0
        goto exit;
3426
0
    }
3427
0
    if (!noptargs) {
3428
0
        goto skip_optional_kwonly;
3429
0
    }
3430
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3431
0
        goto exit;
3432
0
    }
3433
0
skip_optional_kwonly:
3434
0
    return_value = os_remove_impl(module, &path, dir_fd);
3435
3436
0
exit:
3437
    /* Cleanup for path */
3438
0
    path_cleanup(&path);
3439
3440
0
    return return_value;
3441
0
}
3442
3443
#if defined(HAVE_UNAME)
3444
3445
PyDoc_STRVAR(os_uname__doc__,
3446
"uname($module, /)\n"
3447
"--\n"
3448
"\n"
3449
"Return an object identifying the current operating system.\n"
3450
"\n"
3451
"The object behaves like a named tuple with the following fields:\n"
3452
"  (sysname, nodename, release, version, machine)");
3453
3454
#define OS_UNAME_METHODDEF    \
3455
    {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
3456
3457
static PyObject *
3458
os_uname_impl(PyObject *module);
3459
3460
static PyObject *
3461
os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
3462
0
{
3463
0
    return os_uname_impl(module);
3464
0
}
3465
3466
#endif /* defined(HAVE_UNAME) */
3467
3468
PyDoc_STRVAR(os_utime__doc__,
3469
"utime($module, /, path, times=None, *, ns=<unrepresentable>,\n"
3470
"      dir_fd=None, follow_symlinks=True)\n"
3471
"--\n"
3472
"\n"
3473
"Set the access and modified time of path.\n"
3474
"\n"
3475
"path may always be specified as a string.\n"
3476
"On some platforms, path may also be specified as an open file descriptor.\n"
3477
"  If this functionality is unavailable, using it raises an exception.\n"
3478
"\n"
3479
"If times is not None, it must be a tuple (atime, mtime);\n"
3480
"    atime and mtime should be expressed as float seconds since the epoch.\n"
3481
"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
3482
"    atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
3483
"    since the epoch.\n"
3484
"If times is None and ns is unspecified, utime uses the current time.\n"
3485
"Specifying tuples for both times and ns is an error.\n"
3486
"\n"
3487
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3488
"  and path should be relative; path will then be relative to that directory.\n"
3489
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
3490
"  link, utime will modify the symbolic link itself instead of the file the\n"
3491
"  link points to.\n"
3492
"It is an error to use dir_fd or follow_symlinks when specifying path\n"
3493
"  as an open file descriptor.\n"
3494
"dir_fd and follow_symlinks may not be available on your platform.\n"
3495
"  If they are unavailable, using them will raise a NotImplementedError.");
3496
3497
#define OS_UTIME_METHODDEF    \
3498
    {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
3499
3500
static PyObject *
3501
os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
3502
              int dir_fd, int follow_symlinks);
3503
3504
static PyObject *
3505
os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3506
0
{
3507
0
    PyObject *return_value = NULL;
3508
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3509
3510
0
    #define NUM_KEYWORDS 5
3511
0
    static struct {
3512
0
        PyGC_Head _this_is_not_used;
3513
0
        PyObject_VAR_HEAD
3514
0
        Py_hash_t ob_hash;
3515
0
        PyObject *ob_item[NUM_KEYWORDS];
3516
0
    } _kwtuple = {
3517
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3518
0
        .ob_hash = -1,
3519
0
        .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
3520
0
    };
3521
0
    #undef NUM_KEYWORDS
3522
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3523
3524
    #else  // !Py_BUILD_CORE
3525
    #  define KWTUPLE NULL
3526
    #endif  // !Py_BUILD_CORE
3527
3528
0
    static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
3529
0
    static _PyArg_Parser _parser = {
3530
0
        .keywords = _keywords,
3531
0
        .fname = "utime",
3532
0
        .kwtuple = KWTUPLE,
3533
0
    };
3534
0
    #undef KWTUPLE
3535
0
    PyObject *argsbuf[5];
3536
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3537
0
    path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD);
3538
0
    PyObject *times = Py_None;
3539
0
    PyObject *ns = NULL;
3540
0
    int dir_fd = DEFAULT_DIR_FD;
3541
0
    int follow_symlinks = 1;
3542
3543
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3544
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3545
0
    if (!args) {
3546
0
        goto exit;
3547
0
    }
3548
0
    if (!path_converter(args[0], &path)) {
3549
0
        goto exit;
3550
0
    }
3551
0
    if (!noptargs) {
3552
0
        goto skip_optional_pos;
3553
0
    }
3554
0
    if (args[1]) {
3555
0
        times = args[1];
3556
0
        if (!--noptargs) {
3557
0
            goto skip_optional_pos;
3558
0
        }
3559
0
    }
3560
0
skip_optional_pos:
3561
0
    if (!noptargs) {
3562
0
        goto skip_optional_kwonly;
3563
0
    }
3564
0
    if (args[2]) {
3565
0
        ns = args[2];
3566
0
        if (!--noptargs) {
3567
0
            goto skip_optional_kwonly;
3568
0
        }
3569
0
    }
3570
0
    if (args[3]) {
3571
0
        if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
3572
0
            goto exit;
3573
0
        }
3574
0
        if (!--noptargs) {
3575
0
            goto skip_optional_kwonly;
3576
0
        }
3577
0
    }
3578
0
    follow_symlinks = PyObject_IsTrue(args[4]);
3579
0
    if (follow_symlinks < 0) {
3580
0
        goto exit;
3581
0
    }
3582
0
skip_optional_kwonly:
3583
0
    return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
3584
3585
0
exit:
3586
    /* Cleanup for path */
3587
0
    path_cleanup(&path);
3588
3589
0
    return return_value;
3590
0
}
3591
3592
PyDoc_STRVAR(os__exit__doc__,
3593
"_exit($module, /, status)\n"
3594
"--\n"
3595
"\n"
3596
"Exit to the system with specified status, without normal exit processing.");
3597
3598
#define OS__EXIT_METHODDEF    \
3599
    {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
3600
3601
static PyObject *
3602
os__exit_impl(PyObject *module, int status);
3603
3604
static PyObject *
3605
os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3606
0
{
3607
0
    PyObject *return_value = NULL;
3608
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3609
3610
0
    #define NUM_KEYWORDS 1
3611
0
    static struct {
3612
0
        PyGC_Head _this_is_not_used;
3613
0
        PyObject_VAR_HEAD
3614
0
        Py_hash_t ob_hash;
3615
0
        PyObject *ob_item[NUM_KEYWORDS];
3616
0
    } _kwtuple = {
3617
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3618
0
        .ob_hash = -1,
3619
0
        .ob_item = { &_Py_ID(status), },
3620
0
    };
3621
0
    #undef NUM_KEYWORDS
3622
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3623
3624
    #else  // !Py_BUILD_CORE
3625
    #  define KWTUPLE NULL
3626
    #endif  // !Py_BUILD_CORE
3627
3628
0
    static const char * const _keywords[] = {"status", NULL};
3629
0
    static _PyArg_Parser _parser = {
3630
0
        .keywords = _keywords,
3631
0
        .fname = "_exit",
3632
0
        .kwtuple = KWTUPLE,
3633
0
    };
3634
0
    #undef KWTUPLE
3635
0
    PyObject *argsbuf[1];
3636
0
    int status;
3637
3638
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3639
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3640
0
    if (!args) {
3641
0
        goto exit;
3642
0
    }
3643
0
    status = PyLong_AsInt(args[0]);
3644
0
    if (status == -1 && PyErr_Occurred()) {
3645
0
        goto exit;
3646
0
    }
3647
0
    return_value = os__exit_impl(module, status);
3648
3649
0
exit:
3650
0
    return return_value;
3651
0
}
3652
3653
#if defined(HAVE_EXECV)
3654
3655
PyDoc_STRVAR(os_execv__doc__,
3656
"execv($module, path, argv, /)\n"
3657
"--\n"
3658
"\n"
3659
"Execute an executable path with arguments, replacing current process.\n"
3660
"\n"
3661
"  path\n"
3662
"    Path of executable file.\n"
3663
"  argv\n"
3664
"    Tuple or list of strings.");
3665
3666
#define OS_EXECV_METHODDEF    \
3667
    {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__},
3668
3669
static PyObject *
3670
os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
3671
3672
static PyObject *
3673
os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3674
0
{
3675
0
    PyObject *return_value = NULL;
3676
0
    path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0);
3677
0
    PyObject *argv;
3678
3679
0
    if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
3680
0
        goto exit;
3681
0
    }
3682
0
    if (!path_converter(args[0], &path)) {
3683
0
        goto exit;
3684
0
    }
3685
0
    argv = args[1];
3686
0
    return_value = os_execv_impl(module, &path, argv);
3687
3688
0
exit:
3689
    /* Cleanup for path */
3690
0
    path_cleanup(&path);
3691
3692
0
    return return_value;
3693
0
}
3694
3695
#endif /* defined(HAVE_EXECV) */
3696
3697
#if defined(HAVE_EXECV)
3698
3699
PyDoc_STRVAR(os_execve__doc__,
3700
"execve($module, /, path, argv, env)\n"
3701
"--\n"
3702
"\n"
3703
"Execute an executable path with arguments, replacing current process.\n"
3704
"\n"
3705
"  path\n"
3706
"    Path of executable file.\n"
3707
"  argv\n"
3708
"    Tuple or list of strings.\n"
3709
"  env\n"
3710
"    Dictionary of strings mapping to strings.");
3711
3712
#define OS_EXECVE_METHODDEF    \
3713
    {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
3714
3715
static PyObject *
3716
os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
3717
3718
static PyObject *
3719
os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3720
0
{
3721
0
    PyObject *return_value = NULL;
3722
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3723
3724
0
    #define NUM_KEYWORDS 3
3725
0
    static struct {
3726
0
        PyGC_Head _this_is_not_used;
3727
0
        PyObject_VAR_HEAD
3728
0
        Py_hash_t ob_hash;
3729
0
        PyObject *ob_item[NUM_KEYWORDS];
3730
0
    } _kwtuple = {
3731
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3732
0
        .ob_hash = -1,
3733
0
        .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), },
3734
0
    };
3735
0
    #undef NUM_KEYWORDS
3736
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3737
3738
    #else  // !Py_BUILD_CORE
3739
    #  define KWTUPLE NULL
3740
    #endif  // !Py_BUILD_CORE
3741
3742
0
    static const char * const _keywords[] = {"path", "argv", "env", NULL};
3743
0
    static _PyArg_Parser _parser = {
3744
0
        .keywords = _keywords,
3745
0
        .fname = "execve",
3746
0
        .kwtuple = KWTUPLE,
3747
0
    };
3748
0
    #undef KWTUPLE
3749
0
    PyObject *argsbuf[3];
3750
0
    path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE);
3751
0
    PyObject *argv;
3752
0
    PyObject *env;
3753
3754
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3755
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3756
0
    if (!args) {
3757
0
        goto exit;
3758
0
    }
3759
0
    if (!path_converter(args[0], &path)) {
3760
0
        goto exit;
3761
0
    }
3762
0
    argv = args[1];
3763
0
    env = args[2];
3764
0
    return_value = os_execve_impl(module, &path, argv, env);
3765
3766
0
exit:
3767
    /* Cleanup for path */
3768
0
    path_cleanup(&path);
3769
3770
0
    return return_value;
3771
0
}
3772
3773
#endif /* defined(HAVE_EXECV) */
3774
3775
#if defined(HAVE_POSIX_SPAWN)
3776
3777
PyDoc_STRVAR(os_posix_spawn__doc__,
3778
"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
3779
"            setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
3780
"            setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
3781
"--\n"
3782
"\n"
3783
"Execute the program specified by path in a new process.\n"
3784
"\n"
3785
"  path\n"
3786
"    Path of executable file.\n"
3787
"  argv\n"
3788
"    Tuple or list of strings.\n"
3789
"  env\n"
3790
"    Dictionary of strings mapping to strings.\n"
3791
"  file_actions\n"
3792
"    A sequence of file action tuples.\n"
3793
"  setpgroup\n"
3794
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
3795
"  resetids\n"
3796
"    If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
3797
"  setsid\n"
3798
"    If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
3799
"  setsigmask\n"
3800
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
3801
"  setsigdef\n"
3802
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
3803
"  scheduler\n"
3804
"    A tuple with the scheduler policy (optional) and parameters.");
3805
3806
#define OS_POSIX_SPAWN_METHODDEF    \
3807
    {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
3808
3809
static PyObject *
3810
os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
3811
                    PyObject *env, PyObject *file_actions,
3812
                    PyObject *setpgroup, int resetids, int setsid,
3813
                    PyObject *setsigmask, PyObject *setsigdef,
3814
                    PyObject *scheduler);
3815
3816
static PyObject *
3817
os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3818
0
{
3819
0
    PyObject *return_value = NULL;
3820
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3821
3822
0
    #define NUM_KEYWORDS 7
3823
0
    static struct {
3824
0
        PyGC_Head _this_is_not_used;
3825
0
        PyObject_VAR_HEAD
3826
0
        Py_hash_t ob_hash;
3827
0
        PyObject *ob_item[NUM_KEYWORDS];
3828
0
    } _kwtuple = {
3829
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3830
0
        .ob_hash = -1,
3831
0
        .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
3832
0
    };
3833
0
    #undef NUM_KEYWORDS
3834
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3835
3836
    #else  // !Py_BUILD_CORE
3837
    #  define KWTUPLE NULL
3838
    #endif  // !Py_BUILD_CORE
3839
3840
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
3841
0
    static _PyArg_Parser _parser = {
3842
0
        .keywords = _keywords,
3843
0
        .fname = "posix_spawn",
3844
0
        .kwtuple = KWTUPLE,
3845
0
    };
3846
0
    #undef KWTUPLE
3847
0
    PyObject *argsbuf[10];
3848
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
3849
0
    path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0);
3850
0
    PyObject *argv;
3851
0
    PyObject *env;
3852
0
    PyObject *file_actions = NULL;
3853
0
    PyObject *setpgroup = NULL;
3854
0
    int resetids = 0;
3855
0
    int setsid = 0;
3856
0
    PyObject *setsigmask = NULL;
3857
0
    PyObject *setsigdef = NULL;
3858
0
    PyObject *scheduler = NULL;
3859
3860
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3861
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3862
0
    if (!args) {
3863
0
        goto exit;
3864
0
    }
3865
0
    if (!path_converter(args[0], &path)) {
3866
0
        goto exit;
3867
0
    }
3868
0
    argv = args[1];
3869
0
    env = args[2];
3870
0
    if (!noptargs) {
3871
0
        goto skip_optional_kwonly;
3872
0
    }
3873
0
    if (args[3]) {
3874
0
        file_actions = args[3];
3875
0
        if (!--noptargs) {
3876
0
            goto skip_optional_kwonly;
3877
0
        }
3878
0
    }
3879
0
    if (args[4]) {
3880
0
        setpgroup = args[4];
3881
0
        if (!--noptargs) {
3882
0
            goto skip_optional_kwonly;
3883
0
        }
3884
0
    }
3885
0
    if (args[5]) {
3886
0
        resetids = PyObject_IsTrue(args[5]);
3887
0
        if (resetids < 0) {
3888
0
            goto exit;
3889
0
        }
3890
0
        if (!--noptargs) {
3891
0
            goto skip_optional_kwonly;
3892
0
        }
3893
0
    }
3894
0
    if (args[6]) {
3895
0
        setsid = PyObject_IsTrue(args[6]);
3896
0
        if (setsid < 0) {
3897
0
            goto exit;
3898
0
        }
3899
0
        if (!--noptargs) {
3900
0
            goto skip_optional_kwonly;
3901
0
        }
3902
0
    }
3903
0
    if (args[7]) {
3904
0
        setsigmask = args[7];
3905
0
        if (!--noptargs) {
3906
0
            goto skip_optional_kwonly;
3907
0
        }
3908
0
    }
3909
0
    if (args[8]) {
3910
0
        setsigdef = args[8];
3911
0
        if (!--noptargs) {
3912
0
            goto skip_optional_kwonly;
3913
0
        }
3914
0
    }
3915
0
    scheduler = args[9];
3916
0
skip_optional_kwonly:
3917
0
    return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
3918
3919
0
exit:
3920
    /* Cleanup for path */
3921
0
    path_cleanup(&path);
3922
3923
0
    return return_value;
3924
0
}
3925
3926
#endif /* defined(HAVE_POSIX_SPAWN) */
3927
3928
#if defined(HAVE_POSIX_SPAWNP)
3929
3930
PyDoc_STRVAR(os_posix_spawnp__doc__,
3931
"posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
3932
"             setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
3933
"             setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
3934
"--\n"
3935
"\n"
3936
"Execute the program specified by path in a new process.\n"
3937
"\n"
3938
"  path\n"
3939
"    Path of executable file.\n"
3940
"  argv\n"
3941
"    Tuple or list of strings.\n"
3942
"  env\n"
3943
"    Dictionary of strings mapping to strings.\n"
3944
"  file_actions\n"
3945
"    A sequence of file action tuples.\n"
3946
"  setpgroup\n"
3947
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
3948
"  resetids\n"
3949
"    If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
3950
"  setsid\n"
3951
"    If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
3952
"  setsigmask\n"
3953
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
3954
"  setsigdef\n"
3955
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
3956
"  scheduler\n"
3957
"    A tuple with the scheduler policy (optional) and parameters.");
3958
3959
#define OS_POSIX_SPAWNP_METHODDEF    \
3960
    {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
3961
3962
static PyObject *
3963
os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
3964
                     PyObject *env, PyObject *file_actions,
3965
                     PyObject *setpgroup, int resetids, int setsid,
3966
                     PyObject *setsigmask, PyObject *setsigdef,
3967
                     PyObject *scheduler);
3968
3969
static PyObject *
3970
os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3971
0
{
3972
0
    PyObject *return_value = NULL;
3973
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3974
3975
0
    #define NUM_KEYWORDS 7
3976
0
    static struct {
3977
0
        PyGC_Head _this_is_not_used;
3978
0
        PyObject_VAR_HEAD
3979
0
        Py_hash_t ob_hash;
3980
0
        PyObject *ob_item[NUM_KEYWORDS];
3981
0
    } _kwtuple = {
3982
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3983
0
        .ob_hash = -1,
3984
0
        .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
3985
0
    };
3986
0
    #undef NUM_KEYWORDS
3987
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3988
3989
    #else  // !Py_BUILD_CORE
3990
    #  define KWTUPLE NULL
3991
    #endif  // !Py_BUILD_CORE
3992
3993
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
3994
0
    static _PyArg_Parser _parser = {
3995
0
        .keywords = _keywords,
3996
0
        .fname = "posix_spawnp",
3997
0
        .kwtuple = KWTUPLE,
3998
0
    };
3999
0
    #undef KWTUPLE
4000
0
    PyObject *argsbuf[10];
4001
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
4002
0
    path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0);
4003
0
    PyObject *argv;
4004
0
    PyObject *env;
4005
0
    PyObject *file_actions = NULL;
4006
0
    PyObject *setpgroup = NULL;
4007
0
    int resetids = 0;
4008
0
    int setsid = 0;
4009
0
    PyObject *setsigmask = NULL;
4010
0
    PyObject *setsigdef = NULL;
4011
0
    PyObject *scheduler = NULL;
4012
4013
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4014
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4015
0
    if (!args) {
4016
0
        goto exit;
4017
0
    }
4018
0
    if (!path_converter(args[0], &path)) {
4019
0
        goto exit;
4020
0
    }
4021
0
    argv = args[1];
4022
0
    env = args[2];
4023
0
    if (!noptargs) {
4024
0
        goto skip_optional_kwonly;
4025
0
    }
4026
0
    if (args[3]) {
4027
0
        file_actions = args[3];
4028
0
        if (!--noptargs) {
4029
0
            goto skip_optional_kwonly;
4030
0
        }
4031
0
    }
4032
0
    if (args[4]) {
4033
0
        setpgroup = args[4];
4034
0
        if (!--noptargs) {
4035
0
            goto skip_optional_kwonly;
4036
0
        }
4037
0
    }
4038
0
    if (args[5]) {
4039
0
        resetids = PyObject_IsTrue(args[5]);
4040
0
        if (resetids < 0) {
4041
0
            goto exit;
4042
0
        }
4043
0
        if (!--noptargs) {
4044
0
            goto skip_optional_kwonly;
4045
0
        }
4046
0
    }
4047
0
    if (args[6]) {
4048
0
        setsid = PyObject_IsTrue(args[6]);
4049
0
        if (setsid < 0) {
4050
0
            goto exit;
4051
0
        }
4052
0
        if (!--noptargs) {
4053
0
            goto skip_optional_kwonly;
4054
0
        }
4055
0
    }
4056
0
    if (args[7]) {
4057
0
        setsigmask = args[7];
4058
0
        if (!--noptargs) {
4059
0
            goto skip_optional_kwonly;
4060
0
        }
4061
0
    }
4062
0
    if (args[8]) {
4063
0
        setsigdef = args[8];
4064
0
        if (!--noptargs) {
4065
0
            goto skip_optional_kwonly;
4066
0
        }
4067
0
    }
4068
0
    scheduler = args[9];
4069
0
skip_optional_kwonly:
4070
0
    return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
4071
4072
0
exit:
4073
    /* Cleanup for path */
4074
0
    path_cleanup(&path);
4075
4076
0
    return return_value;
4077
0
}
4078
4079
#endif /* defined(HAVE_POSIX_SPAWNP) */
4080
4081
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4082
4083
PyDoc_STRVAR(os_spawnv__doc__,
4084
"spawnv($module, mode, path, argv, /)\n"
4085
"--\n"
4086
"\n"
4087
"Execute the program specified by path in a new process.\n"
4088
"\n"
4089
"  mode\n"
4090
"    Mode of process creation.\n"
4091
"  path\n"
4092
"    Path of executable file.\n"
4093
"  argv\n"
4094
"    Tuple or list of strings.");
4095
4096
#define OS_SPAWNV_METHODDEF    \
4097
    {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__},
4098
4099
static PyObject *
4100
os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
4101
4102
static PyObject *
4103
os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4104
{
4105
    PyObject *return_value = NULL;
4106
    int mode;
4107
    path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0);
4108
    PyObject *argv;
4109
4110
    if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
4111
        goto exit;
4112
    }
4113
    mode = PyLong_AsInt(args[0]);
4114
    if (mode == -1 && PyErr_Occurred()) {
4115
        goto exit;
4116
    }
4117
    if (!path_converter(args[1], &path)) {
4118
        goto exit;
4119
    }
4120
    argv = args[2];
4121
    return_value = os_spawnv_impl(module, mode, &path, argv);
4122
4123
exit:
4124
    /* Cleanup for path */
4125
    path_cleanup(&path);
4126
4127
    return return_value;
4128
}
4129
4130
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4131
4132
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4133
4134
PyDoc_STRVAR(os_spawnve__doc__,
4135
"spawnve($module, mode, path, argv, env, /)\n"
4136
"--\n"
4137
"\n"
4138
"Execute the program specified by path in a new process.\n"
4139
"\n"
4140
"  mode\n"
4141
"    Mode of process creation.\n"
4142
"  path\n"
4143
"    Path of executable file.\n"
4144
"  argv\n"
4145
"    Tuple or list of strings.\n"
4146
"  env\n"
4147
"    Dictionary of strings mapping to strings.");
4148
4149
#define OS_SPAWNVE_METHODDEF    \
4150
    {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__},
4151
4152
static PyObject *
4153
os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
4154
                PyObject *env);
4155
4156
static PyObject *
4157
os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4158
{
4159
    PyObject *return_value = NULL;
4160
    int mode;
4161
    path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0);
4162
    PyObject *argv;
4163
    PyObject *env;
4164
4165
    if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
4166
        goto exit;
4167
    }
4168
    mode = PyLong_AsInt(args[0]);
4169
    if (mode == -1 && PyErr_Occurred()) {
4170
        goto exit;
4171
    }
4172
    if (!path_converter(args[1], &path)) {
4173
        goto exit;
4174
    }
4175
    argv = args[2];
4176
    env = args[3];
4177
    return_value = os_spawnve_impl(module, mode, &path, argv, env);
4178
4179
exit:
4180
    /* Cleanup for path */
4181
    path_cleanup(&path);
4182
4183
    return return_value;
4184
}
4185
4186
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4187
4188
#if defined(HAVE_FORK)
4189
4190
PyDoc_STRVAR(os_register_at_fork__doc__,
4191
"register_at_fork($module, /, *, before=<unrepresentable>,\n"
4192
"                 after_in_child=<unrepresentable>,\n"
4193
"                 after_in_parent=<unrepresentable>)\n"
4194
"--\n"
4195
"\n"
4196
"Register callables to be called when forking a new process.\n"
4197
"\n"
4198
"  before\n"
4199
"    A callable to be called in the parent before the fork() syscall.\n"
4200
"  after_in_child\n"
4201
"    A callable to be called in the child after fork().\n"
4202
"  after_in_parent\n"
4203
"    A callable to be called in the parent after fork().\n"
4204
"\n"
4205
"\'before\' callbacks are called in reverse order.\n"
4206
"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
4207
4208
#define OS_REGISTER_AT_FORK_METHODDEF    \
4209
    {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
4210
4211
static PyObject *
4212
os_register_at_fork_impl(PyObject *module, PyObject *before,
4213
                         PyObject *after_in_child, PyObject *after_in_parent);
4214
4215
static PyObject *
4216
os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4217
2
{
4218
2
    PyObject *return_value = NULL;
4219
2
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4220
4221
2
    #define NUM_KEYWORDS 3
4222
2
    static struct {
4223
2
        PyGC_Head _this_is_not_used;
4224
2
        PyObject_VAR_HEAD
4225
2
        Py_hash_t ob_hash;
4226
2
        PyObject *ob_item[NUM_KEYWORDS];
4227
2
    } _kwtuple = {
4228
2
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4229
2
        .ob_hash = -1,
4230
2
        .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), },
4231
2
    };
4232
2
    #undef NUM_KEYWORDS
4233
2
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4234
4235
    #else  // !Py_BUILD_CORE
4236
    #  define KWTUPLE NULL
4237
    #endif  // !Py_BUILD_CORE
4238
4239
2
    static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
4240
2
    static _PyArg_Parser _parser = {
4241
2
        .keywords = _keywords,
4242
2
        .fname = "register_at_fork",
4243
2
        .kwtuple = KWTUPLE,
4244
2
    };
4245
2
    #undef KWTUPLE
4246
2
    PyObject *argsbuf[3];
4247
2
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
4248
2
    PyObject *before = NULL;
4249
2
    PyObject *after_in_child = NULL;
4250
2
    PyObject *after_in_parent = NULL;
4251
4252
2
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4253
2
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4254
2
    if (!args) {
4255
0
        goto exit;
4256
0
    }
4257
2
    if (!noptargs) {
4258
0
        goto skip_optional_kwonly;
4259
0
    }
4260
2
    if (args[0]) {
4261
0
        before = args[0];
4262
0
        if (!--noptargs) {
4263
0
            goto skip_optional_kwonly;
4264
0
        }
4265
0
    }
4266
2
    if (args[1]) {
4267
2
        after_in_child = args[1];
4268
2
        if (!--noptargs) {
4269
2
            goto skip_optional_kwonly;
4270
2
        }
4271
2
    }
4272
0
    after_in_parent = args[2];
4273
2
skip_optional_kwonly:
4274
2
    return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
4275
4276
2
exit:
4277
2
    return return_value;
4278
2
}
4279
4280
#endif /* defined(HAVE_FORK) */
4281
4282
#if defined(HAVE_FORK1)
4283
4284
PyDoc_STRVAR(os_fork1__doc__,
4285
"fork1($module, /)\n"
4286
"--\n"
4287
"\n"
4288
"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
4289
"\n"
4290
"Return 0 to child process and PID of child to parent process.");
4291
4292
#define OS_FORK1_METHODDEF    \
4293
    {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
4294
4295
static PyObject *
4296
os_fork1_impl(PyObject *module);
4297
4298
static PyObject *
4299
os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
4300
{
4301
    return os_fork1_impl(module);
4302
}
4303
4304
#endif /* defined(HAVE_FORK1) */
4305
4306
#if defined(HAVE_FORK)
4307
4308
PyDoc_STRVAR(os_fork__doc__,
4309
"fork($module, /)\n"
4310
"--\n"
4311
"\n"
4312
"Fork a child process.\n"
4313
"\n"
4314
"Return 0 to child process and PID of child to parent process.");
4315
4316
#define OS_FORK_METHODDEF    \
4317
    {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
4318
4319
static PyObject *
4320
os_fork_impl(PyObject *module);
4321
4322
static PyObject *
4323
os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
4324
0
{
4325
0
    return os_fork_impl(module);
4326
0
}
4327
4328
#endif /* defined(HAVE_FORK) */
4329
4330
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4331
4332
PyDoc_STRVAR(os_sched_get_priority_max__doc__,
4333
"sched_get_priority_max($module, /, policy)\n"
4334
"--\n"
4335
"\n"
4336
"Get the maximum scheduling priority for policy.");
4337
4338
#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF    \
4339
    {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
4340
4341
static PyObject *
4342
os_sched_get_priority_max_impl(PyObject *module, int policy);
4343
4344
static PyObject *
4345
os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4346
0
{
4347
0
    PyObject *return_value = NULL;
4348
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4349
4350
0
    #define NUM_KEYWORDS 1
4351
0
    static struct {
4352
0
        PyGC_Head _this_is_not_used;
4353
0
        PyObject_VAR_HEAD
4354
0
        Py_hash_t ob_hash;
4355
0
        PyObject *ob_item[NUM_KEYWORDS];
4356
0
    } _kwtuple = {
4357
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4358
0
        .ob_hash = -1,
4359
0
        .ob_item = { &_Py_ID(policy), },
4360
0
    };
4361
0
    #undef NUM_KEYWORDS
4362
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4363
4364
    #else  // !Py_BUILD_CORE
4365
    #  define KWTUPLE NULL
4366
    #endif  // !Py_BUILD_CORE
4367
4368
0
    static const char * const _keywords[] = {"policy", NULL};
4369
0
    static _PyArg_Parser _parser = {
4370
0
        .keywords = _keywords,
4371
0
        .fname = "sched_get_priority_max",
4372
0
        .kwtuple = KWTUPLE,
4373
0
    };
4374
0
    #undef KWTUPLE
4375
0
    PyObject *argsbuf[1];
4376
0
    int policy;
4377
4378
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4379
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4380
0
    if (!args) {
4381
0
        goto exit;
4382
0
    }
4383
0
    policy = PyLong_AsInt(args[0]);
4384
0
    if (policy == -1 && PyErr_Occurred()) {
4385
0
        goto exit;
4386
0
    }
4387
0
    return_value = os_sched_get_priority_max_impl(module, policy);
4388
4389
0
exit:
4390
0
    return return_value;
4391
0
}
4392
4393
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4394
4395
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4396
4397
PyDoc_STRVAR(os_sched_get_priority_min__doc__,
4398
"sched_get_priority_min($module, /, policy)\n"
4399
"--\n"
4400
"\n"
4401
"Get the minimum scheduling priority for policy.");
4402
4403
#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF    \
4404
    {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
4405
4406
static PyObject *
4407
os_sched_get_priority_min_impl(PyObject *module, int policy);
4408
4409
static PyObject *
4410
os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4411
0
{
4412
0
    PyObject *return_value = NULL;
4413
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4414
4415
0
    #define NUM_KEYWORDS 1
4416
0
    static struct {
4417
0
        PyGC_Head _this_is_not_used;
4418
0
        PyObject_VAR_HEAD
4419
0
        Py_hash_t ob_hash;
4420
0
        PyObject *ob_item[NUM_KEYWORDS];
4421
0
    } _kwtuple = {
4422
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4423
0
        .ob_hash = -1,
4424
0
        .ob_item = { &_Py_ID(policy), },
4425
0
    };
4426
0
    #undef NUM_KEYWORDS
4427
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4428
4429
    #else  // !Py_BUILD_CORE
4430
    #  define KWTUPLE NULL
4431
    #endif  // !Py_BUILD_CORE
4432
4433
0
    static const char * const _keywords[] = {"policy", NULL};
4434
0
    static _PyArg_Parser _parser = {
4435
0
        .keywords = _keywords,
4436
0
        .fname = "sched_get_priority_min",
4437
0
        .kwtuple = KWTUPLE,
4438
0
    };
4439
0
    #undef KWTUPLE
4440
0
    PyObject *argsbuf[1];
4441
0
    int policy;
4442
4443
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4444
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4445
0
    if (!args) {
4446
0
        goto exit;
4447
0
    }
4448
0
    policy = PyLong_AsInt(args[0]);
4449
0
    if (policy == -1 && PyErr_Occurred()) {
4450
0
        goto exit;
4451
0
    }
4452
0
    return_value = os_sched_get_priority_min_impl(module, policy);
4453
4454
0
exit:
4455
0
    return return_value;
4456
0
}
4457
4458
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4459
4460
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4461
4462
PyDoc_STRVAR(os_sched_getscheduler__doc__,
4463
"sched_getscheduler($module, pid, /)\n"
4464
"--\n"
4465
"\n"
4466
"Get the scheduling policy for the process identified by pid.\n"
4467
"\n"
4468
"Passing 0 for pid returns the scheduling policy for the calling process.");
4469
4470
#define OS_SCHED_GETSCHEDULER_METHODDEF    \
4471
    {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
4472
4473
static PyObject *
4474
os_sched_getscheduler_impl(PyObject *module, pid_t pid);
4475
4476
static PyObject *
4477
os_sched_getscheduler(PyObject *module, PyObject *arg)
4478
0
{
4479
0
    PyObject *return_value = NULL;
4480
0
    pid_t pid;
4481
4482
0
    pid = PyLong_AsPid(arg);
4483
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4484
0
        goto exit;
4485
0
    }
4486
0
    return_value = os_sched_getscheduler_impl(module, pid);
4487
4488
0
exit:
4489
0
    return return_value;
4490
0
}
4491
4492
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4493
4494
#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
4495
4496
PyDoc_STRVAR(os_sched_param__doc__,
4497
"sched_param(sched_priority)\n"
4498
"--\n"
4499
"\n"
4500
"Currently has only one field: sched_priority\n"
4501
"\n"
4502
"  sched_priority\n"
4503
"    A scheduling parameter.");
4504
4505
static PyObject *
4506
os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
4507
4508
static PyObject *
4509
os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
4510
0
{
4511
0
    PyObject *return_value = NULL;
4512
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4513
4514
0
    #define NUM_KEYWORDS 1
4515
0
    static struct {
4516
0
        PyGC_Head _this_is_not_used;
4517
0
        PyObject_VAR_HEAD
4518
0
        Py_hash_t ob_hash;
4519
0
        PyObject *ob_item[NUM_KEYWORDS];
4520
0
    } _kwtuple = {
4521
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4522
0
        .ob_hash = -1,
4523
0
        .ob_item = { &_Py_ID(sched_priority), },
4524
0
    };
4525
0
    #undef NUM_KEYWORDS
4526
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4527
4528
    #else  // !Py_BUILD_CORE
4529
    #  define KWTUPLE NULL
4530
    #endif  // !Py_BUILD_CORE
4531
4532
0
    static const char * const _keywords[] = {"sched_priority", NULL};
4533
0
    static _PyArg_Parser _parser = {
4534
0
        .keywords = _keywords,
4535
0
        .fname = "sched_param",
4536
0
        .kwtuple = KWTUPLE,
4537
0
    };
4538
0
    #undef KWTUPLE
4539
0
    PyObject *argsbuf[1];
4540
0
    PyObject * const *fastargs;
4541
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
4542
0
    PyObject *sched_priority;
4543
4544
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
4545
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4546
0
    if (!fastargs) {
4547
0
        goto exit;
4548
0
    }
4549
0
    sched_priority = fastargs[0];
4550
0
    return_value = os_sched_param_impl(type, sched_priority);
4551
4552
0
exit:
4553
0
    return return_value;
4554
0
}
4555
4556
#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
4557
4558
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4559
4560
PyDoc_STRVAR(os_sched_setscheduler__doc__,
4561
"sched_setscheduler($module, pid, policy, param, /)\n"
4562
"--\n"
4563
"\n"
4564
"Set the scheduling policy for the process identified by pid.\n"
4565
"\n"
4566
"If pid is 0, the calling process is changed.\n"
4567
"param is an instance of sched_param.");
4568
4569
#define OS_SCHED_SETSCHEDULER_METHODDEF    \
4570
    {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__},
4571
4572
static PyObject *
4573
os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
4574
                           PyObject *param_obj);
4575
4576
static PyObject *
4577
os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4578
0
{
4579
0
    PyObject *return_value = NULL;
4580
0
    pid_t pid;
4581
0
    int policy;
4582
0
    PyObject *param_obj;
4583
4584
0
    if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) {
4585
0
        goto exit;
4586
0
    }
4587
0
    pid = PyLong_AsPid(args[0]);
4588
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4589
0
        goto exit;
4590
0
    }
4591
0
    policy = PyLong_AsInt(args[1]);
4592
0
    if (policy == -1 && PyErr_Occurred()) {
4593
0
        goto exit;
4594
0
    }
4595
0
    param_obj = args[2];
4596
0
    return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj);
4597
4598
0
exit:
4599
0
    return return_value;
4600
0
}
4601
4602
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4603
4604
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4605
4606
PyDoc_STRVAR(os_sched_getparam__doc__,
4607
"sched_getparam($module, pid, /)\n"
4608
"--\n"
4609
"\n"
4610
"Returns scheduling parameters for the process identified by pid.\n"
4611
"\n"
4612
"If pid is 0, returns parameters for the calling process.\n"
4613
"Return value is an instance of sched_param.");
4614
4615
#define OS_SCHED_GETPARAM_METHODDEF    \
4616
    {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
4617
4618
static PyObject *
4619
os_sched_getparam_impl(PyObject *module, pid_t pid);
4620
4621
static PyObject *
4622
os_sched_getparam(PyObject *module, PyObject *arg)
4623
0
{
4624
0
    PyObject *return_value = NULL;
4625
0
    pid_t pid;
4626
4627
0
    pid = PyLong_AsPid(arg);
4628
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4629
0
        goto exit;
4630
0
    }
4631
0
    return_value = os_sched_getparam_impl(module, pid);
4632
4633
0
exit:
4634
0
    return return_value;
4635
0
}
4636
4637
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4638
4639
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4640
4641
PyDoc_STRVAR(os_sched_setparam__doc__,
4642
"sched_setparam($module, pid, param, /)\n"
4643
"--\n"
4644
"\n"
4645
"Set scheduling parameters for the process identified by pid.\n"
4646
"\n"
4647
"If pid is 0, sets parameters for the calling process.\n"
4648
"param should be an instance of sched_param.");
4649
4650
#define OS_SCHED_SETPARAM_METHODDEF    \
4651
    {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__},
4652
4653
static PyObject *
4654
os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj);
4655
4656
static PyObject *
4657
os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4658
0
{
4659
0
    PyObject *return_value = NULL;
4660
0
    pid_t pid;
4661
0
    PyObject *param_obj;
4662
4663
0
    if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) {
4664
0
        goto exit;
4665
0
    }
4666
0
    pid = PyLong_AsPid(args[0]);
4667
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4668
0
        goto exit;
4669
0
    }
4670
0
    param_obj = args[1];
4671
0
    return_value = os_sched_setparam_impl(module, pid, param_obj);
4672
4673
0
exit:
4674
0
    return return_value;
4675
0
}
4676
4677
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4678
4679
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
4680
4681
PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
4682
"sched_rr_get_interval($module, pid, /)\n"
4683
"--\n"
4684
"\n"
4685
"Return the round-robin quantum for the process identified by pid, in seconds.\n"
4686
"\n"
4687
"Value returned is a float.");
4688
4689
#define OS_SCHED_RR_GET_INTERVAL_METHODDEF    \
4690
    {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
4691
4692
static double
4693
os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
4694
4695
static PyObject *
4696
os_sched_rr_get_interval(PyObject *module, PyObject *arg)
4697
0
{
4698
0
    PyObject *return_value = NULL;
4699
0
    pid_t pid;
4700
0
    double _return_value;
4701
4702
0
    pid = PyLong_AsPid(arg);
4703
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4704
0
        goto exit;
4705
0
    }
4706
0
    _return_value = os_sched_rr_get_interval_impl(module, pid);
4707
0
    if ((_return_value == -1.0) && PyErr_Occurred()) {
4708
0
        goto exit;
4709
0
    }
4710
0
    return_value = PyFloat_FromDouble(_return_value);
4711
4712
0
exit:
4713
0
    return return_value;
4714
0
}
4715
4716
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
4717
4718
#if defined(HAVE_SCHED_H)
4719
4720
PyDoc_STRVAR(os_sched_yield__doc__,
4721
"sched_yield($module, /)\n"
4722
"--\n"
4723
"\n"
4724
"Voluntarily relinquish the CPU.");
4725
4726
#define OS_SCHED_YIELD_METHODDEF    \
4727
    {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
4728
4729
static PyObject *
4730
os_sched_yield_impl(PyObject *module);
4731
4732
static PyObject *
4733
os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
4734
0
{
4735
0
    return os_sched_yield_impl(module);
4736
0
}
4737
4738
#endif /* defined(HAVE_SCHED_H) */
4739
4740
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4741
4742
PyDoc_STRVAR(os_sched_setaffinity__doc__,
4743
"sched_setaffinity($module, pid, mask, /)\n"
4744
"--\n"
4745
"\n"
4746
"Set the CPU affinity of the process identified by pid to mask.\n"
4747
"\n"
4748
"mask should be an iterable of integers identifying CPUs.");
4749
4750
#define OS_SCHED_SETAFFINITY_METHODDEF    \
4751
    {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__},
4752
4753
static PyObject *
4754
os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
4755
4756
static PyObject *
4757
os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4758
0
{
4759
0
    PyObject *return_value = NULL;
4760
0
    pid_t pid;
4761
0
    PyObject *mask;
4762
4763
0
    if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) {
4764
0
        goto exit;
4765
0
    }
4766
0
    pid = PyLong_AsPid(args[0]);
4767
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4768
0
        goto exit;
4769
0
    }
4770
0
    mask = args[1];
4771
0
    return_value = os_sched_setaffinity_impl(module, pid, mask);
4772
4773
0
exit:
4774
0
    return return_value;
4775
0
}
4776
4777
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4778
4779
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4780
4781
PyDoc_STRVAR(os_sched_getaffinity__doc__,
4782
"sched_getaffinity($module, pid, /)\n"
4783
"--\n"
4784
"\n"
4785
"Return the affinity of the process identified by pid (or the current process if zero).\n"
4786
"\n"
4787
"The affinity is returned as a set of CPU identifiers.");
4788
4789
#define OS_SCHED_GETAFFINITY_METHODDEF    \
4790
    {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
4791
4792
static PyObject *
4793
os_sched_getaffinity_impl(PyObject *module, pid_t pid);
4794
4795
static PyObject *
4796
os_sched_getaffinity(PyObject *module, PyObject *arg)
4797
0
{
4798
0
    PyObject *return_value = NULL;
4799
0
    pid_t pid;
4800
4801
0
    pid = PyLong_AsPid(arg);
4802
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4803
0
        goto exit;
4804
0
    }
4805
0
    return_value = os_sched_getaffinity_impl(module, pid);
4806
4807
0
exit:
4808
0
    return return_value;
4809
0
}
4810
4811
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4812
4813
#if defined(HAVE_POSIX_OPENPT)
4814
4815
PyDoc_STRVAR(os_posix_openpt__doc__,
4816
"posix_openpt($module, oflag, /)\n"
4817
"--\n"
4818
"\n"
4819
"Open and return a file descriptor for a master pseudo-terminal device.\n"
4820
"\n"
4821
"Performs a posix_openpt() C function call. The oflag argument is used to\n"
4822
"set file status flags and file access modes as specified in the manual page\n"
4823
"of posix_openpt() of your system.");
4824
4825
#define OS_POSIX_OPENPT_METHODDEF    \
4826
    {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__},
4827
4828
static int
4829
os_posix_openpt_impl(PyObject *module, int oflag);
4830
4831
static PyObject *
4832
os_posix_openpt(PyObject *module, PyObject *arg)
4833
0
{
4834
0
    PyObject *return_value = NULL;
4835
0
    int oflag;
4836
0
    int _return_value;
4837
4838
0
    oflag = PyLong_AsInt(arg);
4839
0
    if (oflag == -1 && PyErr_Occurred()) {
4840
0
        goto exit;
4841
0
    }
4842
0
    _return_value = os_posix_openpt_impl(module, oflag);
4843
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4844
0
        goto exit;
4845
0
    }
4846
0
    return_value = PyLong_FromLong((long)_return_value);
4847
4848
0
exit:
4849
0
    return return_value;
4850
0
}
4851
4852
#endif /* defined(HAVE_POSIX_OPENPT) */
4853
4854
#if defined(HAVE_GRANTPT)
4855
4856
PyDoc_STRVAR(os_grantpt__doc__,
4857
"grantpt($module, fd, /)\n"
4858
"--\n"
4859
"\n"
4860
"Grant access to the slave pseudo-terminal device.\n"
4861
"\n"
4862
"  fd\n"
4863
"    File descriptor of a master pseudo-terminal device.\n"
4864
"\n"
4865
"Performs a grantpt() C function call.");
4866
4867
#define OS_GRANTPT_METHODDEF    \
4868
    {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__},
4869
4870
static PyObject *
4871
os_grantpt_impl(PyObject *module, int fd);
4872
4873
static PyObject *
4874
os_grantpt(PyObject *module, PyObject *arg)
4875
0
{
4876
0
    PyObject *return_value = NULL;
4877
0
    int fd;
4878
4879
0
    fd = PyObject_AsFileDescriptor(arg);
4880
0
    if (fd < 0) {
4881
0
        goto exit;
4882
0
    }
4883
0
    return_value = os_grantpt_impl(module, fd);
4884
4885
0
exit:
4886
0
    return return_value;
4887
0
}
4888
4889
#endif /* defined(HAVE_GRANTPT) */
4890
4891
#if defined(HAVE_UNLOCKPT)
4892
4893
PyDoc_STRVAR(os_unlockpt__doc__,
4894
"unlockpt($module, fd, /)\n"
4895
"--\n"
4896
"\n"
4897
"Unlock a pseudo-terminal master/slave pair.\n"
4898
"\n"
4899
"  fd\n"
4900
"    File descriptor of a master pseudo-terminal device.\n"
4901
"\n"
4902
"Performs an unlockpt() C function call.");
4903
4904
#define OS_UNLOCKPT_METHODDEF    \
4905
    {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__},
4906
4907
static PyObject *
4908
os_unlockpt_impl(PyObject *module, int fd);
4909
4910
static PyObject *
4911
os_unlockpt(PyObject *module, PyObject *arg)
4912
0
{
4913
0
    PyObject *return_value = NULL;
4914
0
    int fd;
4915
4916
0
    fd = PyObject_AsFileDescriptor(arg);
4917
0
    if (fd < 0) {
4918
0
        goto exit;
4919
0
    }
4920
0
    return_value = os_unlockpt_impl(module, fd);
4921
4922
0
exit:
4923
0
    return return_value;
4924
0
}
4925
4926
#endif /* defined(HAVE_UNLOCKPT) */
4927
4928
#if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R))
4929
4930
PyDoc_STRVAR(os_ptsname__doc__,
4931
"ptsname($module, fd, /)\n"
4932
"--\n"
4933
"\n"
4934
"Return the name of the slave pseudo-terminal device.\n"
4935
"\n"
4936
"  fd\n"
4937
"    File descriptor of a master pseudo-terminal device.\n"
4938
"\n"
4939
"If the ptsname_r() C function is available, it is called;\n"
4940
"otherwise, performs a ptsname() C function call.");
4941
4942
#define OS_PTSNAME_METHODDEF    \
4943
    {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__},
4944
4945
static PyObject *
4946
os_ptsname_impl(PyObject *module, int fd);
4947
4948
static PyObject *
4949
os_ptsname(PyObject *module, PyObject *arg)
4950
0
{
4951
0
    PyObject *return_value = NULL;
4952
0
    int fd;
4953
4954
0
    fd = PyObject_AsFileDescriptor(arg);
4955
0
    if (fd < 0) {
4956
0
        goto exit;
4957
0
    }
4958
0
    return_value = os_ptsname_impl(module, fd);
4959
4960
0
exit:
4961
0
    return return_value;
4962
0
}
4963
4964
#endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */
4965
4966
#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
4967
4968
PyDoc_STRVAR(os_openpty__doc__,
4969
"openpty($module, /)\n"
4970
"--\n"
4971
"\n"
4972
"Open a pseudo-terminal.\n"
4973
"\n"
4974
"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
4975
"for both the master and slave ends.");
4976
4977
#define OS_OPENPTY_METHODDEF    \
4978
    {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
4979
4980
static PyObject *
4981
os_openpty_impl(PyObject *module);
4982
4983
static PyObject *
4984
os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
4985
0
{
4986
0
    return os_openpty_impl(module);
4987
0
}
4988
4989
#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
4990
4991
#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY))
4992
4993
PyDoc_STRVAR(os_login_tty__doc__,
4994
"login_tty($module, fd, /)\n"
4995
"--\n"
4996
"\n"
4997
"Prepare the tty of which fd is a file descriptor for a new login session.\n"
4998
"\n"
4999
"Make the calling process a session leader; make the tty the\n"
5000
"controlling tty, the stdin, the stdout, and the stderr of the\n"
5001
"calling process; close fd.");
5002
5003
#define OS_LOGIN_TTY_METHODDEF    \
5004
    {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__},
5005
5006
static PyObject *
5007
os_login_tty_impl(PyObject *module, int fd);
5008
5009
static PyObject *
5010
os_login_tty(PyObject *module, PyObject *arg)
5011
0
{
5012
0
    PyObject *return_value = NULL;
5013
0
    int fd;
5014
5015
0
    fd = PyObject_AsFileDescriptor(arg);
5016
0
    if (fd < 0) {
5017
0
        goto exit;
5018
0
    }
5019
0
    return_value = os_login_tty_impl(module, fd);
5020
5021
0
exit:
5022
0
    return return_value;
5023
0
}
5024
5025
#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */
5026
5027
#if defined(HAVE_FORKPTY)
5028
5029
PyDoc_STRVAR(os_forkpty__doc__,
5030
"forkpty($module, /)\n"
5031
"--\n"
5032
"\n"
5033
"Fork a new process with a new pseudo-terminal as controlling tty.\n"
5034
"\n"
5035
"Returns a tuple of (pid, master_fd).\n"
5036
"Like fork(), return pid of 0 to the child process,\n"
5037
"and pid of child to the parent process.\n"
5038
"To both, return fd of newly opened pseudo-terminal.");
5039
5040
#define OS_FORKPTY_METHODDEF    \
5041
    {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
5042
5043
static PyObject *
5044
os_forkpty_impl(PyObject *module);
5045
5046
static PyObject *
5047
os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
5048
0
{
5049
0
    return os_forkpty_impl(module);
5050
0
}
5051
5052
#endif /* defined(HAVE_FORKPTY) */
5053
5054
#if defined(HAVE_GETEGID)
5055
5056
PyDoc_STRVAR(os_getegid__doc__,
5057
"getegid($module, /)\n"
5058
"--\n"
5059
"\n"
5060
"Return the current process\'s effective group id.");
5061
5062
#define OS_GETEGID_METHODDEF    \
5063
    {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
5064
5065
static PyObject *
5066
os_getegid_impl(PyObject *module);
5067
5068
static PyObject *
5069
os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
5070
16
{
5071
16
    return os_getegid_impl(module);
5072
16
}
5073
5074
#endif /* defined(HAVE_GETEGID) */
5075
5076
#if defined(HAVE_GETEUID)
5077
5078
PyDoc_STRVAR(os_geteuid__doc__,
5079
"geteuid($module, /)\n"
5080
"--\n"
5081
"\n"
5082
"Return the current process\'s effective user id.");
5083
5084
#define OS_GETEUID_METHODDEF    \
5085
    {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
5086
5087
static PyObject *
5088
os_geteuid_impl(PyObject *module);
5089
5090
static PyObject *
5091
os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5092
16
{
5093
16
    return os_geteuid_impl(module);
5094
16
}
5095
5096
#endif /* defined(HAVE_GETEUID) */
5097
5098
#if defined(HAVE_GETGID)
5099
5100
PyDoc_STRVAR(os_getgid__doc__,
5101
"getgid($module, /)\n"
5102
"--\n"
5103
"\n"
5104
"Return the current process\'s group id.");
5105
5106
#define OS_GETGID_METHODDEF    \
5107
    {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
5108
5109
static PyObject *
5110
os_getgid_impl(PyObject *module);
5111
5112
static PyObject *
5113
os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
5114
16
{
5115
16
    return os_getgid_impl(module);
5116
16
}
5117
5118
#endif /* defined(HAVE_GETGID) */
5119
5120
#if defined(HAVE_GETPID)
5121
5122
PyDoc_STRVAR(os_getpid__doc__,
5123
"getpid($module, /)\n"
5124
"--\n"
5125
"\n"
5126
"Return the current process id.");
5127
5128
#define OS_GETPID_METHODDEF    \
5129
    {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
5130
5131
static PyObject *
5132
os_getpid_impl(PyObject *module);
5133
5134
static PyObject *
5135
os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
5136
0
{
5137
0
    return os_getpid_impl(module);
5138
0
}
5139
5140
#endif /* defined(HAVE_GETPID) */
5141
5142
#if defined(HAVE_GETGROUPLIST) && defined(__APPLE__)
5143
5144
PyDoc_STRVAR(os_getgrouplist__doc__,
5145
"getgrouplist($module, user, group, /)\n"
5146
"--\n"
5147
"\n"
5148
"Returns a list of groups to which a user belongs.\n"
5149
"\n"
5150
"  user\n"
5151
"    username to lookup\n"
5152
"  group\n"
5153
"    base group id of the user");
5154
5155
#define OS_GETGROUPLIST_METHODDEF    \
5156
    {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5157
5158
static PyObject *
5159
os_getgrouplist_impl(PyObject *module, const char *user, int basegid);
5160
5161
static PyObject *
5162
os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5163
{
5164
    PyObject *return_value = NULL;
5165
    const char *user;
5166
    int basegid;
5167
5168
    if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5169
        goto exit;
5170
    }
5171
    if (!PyUnicode_Check(args[0])) {
5172
        _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5173
        goto exit;
5174
    }
5175
    Py_ssize_t user_length;
5176
    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5177
    if (user == NULL) {
5178
        goto exit;
5179
    }
5180
    if (strlen(user) != (size_t)user_length) {
5181
        PyErr_SetString(PyExc_ValueError, "embedded null character");
5182
        goto exit;
5183
    }
5184
    basegid = PyLong_AsInt(args[1]);
5185
    if (basegid == -1 && PyErr_Occurred()) {
5186
        goto exit;
5187
    }
5188
    return_value = os_getgrouplist_impl(module, user, basegid);
5189
5190
exit:
5191
    return return_value;
5192
}
5193
5194
#endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */
5195
5196
#if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__)
5197
5198
PyDoc_STRVAR(os_getgrouplist__doc__,
5199
"getgrouplist($module, user, group, /)\n"
5200
"--\n"
5201
"\n"
5202
"Returns a list of groups to which a user belongs.\n"
5203
"\n"
5204
"  user\n"
5205
"    username to lookup\n"
5206
"  group\n"
5207
"    base group id of the user");
5208
5209
#define OS_GETGROUPLIST_METHODDEF    \
5210
    {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5211
5212
static PyObject *
5213
os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid);
5214
5215
static PyObject *
5216
os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5217
0
{
5218
0
    PyObject *return_value = NULL;
5219
0
    const char *user;
5220
0
    gid_t basegid;
5221
5222
0
    if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5223
0
        goto exit;
5224
0
    }
5225
0
    if (!PyUnicode_Check(args[0])) {
5226
0
        _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5227
0
        goto exit;
5228
0
    }
5229
0
    Py_ssize_t user_length;
5230
0
    user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5231
0
    if (user == NULL) {
5232
0
        goto exit;
5233
0
    }
5234
0
    if (strlen(user) != (size_t)user_length) {
5235
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
5236
0
        goto exit;
5237
0
    }
5238
0
    if (!_Py_Gid_Converter(args[1], &basegid)) {
5239
0
        goto exit;
5240
0
    }
5241
0
    return_value = os_getgrouplist_impl(module, user, basegid);
5242
5243
0
exit:
5244
0
    return return_value;
5245
0
}
5246
5247
#endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */
5248
5249
#if defined(HAVE_GETGROUPS)
5250
5251
PyDoc_STRVAR(os_getgroups__doc__,
5252
"getgroups($module, /)\n"
5253
"--\n"
5254
"\n"
5255
"Return list of supplemental group IDs for the process.");
5256
5257
#define OS_GETGROUPS_METHODDEF    \
5258
    {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
5259
5260
static PyObject *
5261
os_getgroups_impl(PyObject *module);
5262
5263
static PyObject *
5264
os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
5265
0
{
5266
0
    return os_getgroups_impl(module);
5267
0
}
5268
5269
#endif /* defined(HAVE_GETGROUPS) */
5270
5271
#if defined(HAVE_INITGROUPS) && defined(__APPLE__)
5272
5273
PyDoc_STRVAR(os_initgroups__doc__,
5274
"initgroups($module, username, gid, /)\n"
5275
"--\n"
5276
"\n"
5277
"Initialize the group access list.\n"
5278
"\n"
5279
"Call the system initgroups() to initialize the group access list with all of\n"
5280
"the groups of which the specified username is a member, plus the specified\n"
5281
"group id.");
5282
5283
#define OS_INITGROUPS_METHODDEF    \
5284
    {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5285
5286
static PyObject *
5287
os_initgroups_impl(PyObject *module, PyObject *oname, int gid);
5288
5289
static PyObject *
5290
os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5291
{
5292
    PyObject *return_value = NULL;
5293
    PyObject *oname = NULL;
5294
    int gid;
5295
5296
    if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5297
        goto exit;
5298
    }
5299
    if (!PyUnicode_FSConverter(args[0], &oname)) {
5300
        goto exit;
5301
    }
5302
    gid = PyLong_AsInt(args[1]);
5303
    if (gid == -1 && PyErr_Occurred()) {
5304
        goto exit;
5305
    }
5306
    return_value = os_initgroups_impl(module, oname, gid);
5307
5308
exit:
5309
    /* Cleanup for oname */
5310
    Py_XDECREF(oname);
5311
5312
    return return_value;
5313
}
5314
5315
#endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */
5316
5317
#if defined(HAVE_INITGROUPS) && !defined(__APPLE__)
5318
5319
PyDoc_STRVAR(os_initgroups__doc__,
5320
"initgroups($module, username, gid, /)\n"
5321
"--\n"
5322
"\n"
5323
"Initialize the group access list.\n"
5324
"\n"
5325
"Call the system initgroups() to initialize the group access list with all of\n"
5326
"the groups of which the specified username is a member, plus the specified\n"
5327
"group id.");
5328
5329
#define OS_INITGROUPS_METHODDEF    \
5330
    {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5331
5332
static PyObject *
5333
os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid);
5334
5335
static PyObject *
5336
os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5337
0
{
5338
0
    PyObject *return_value = NULL;
5339
0
    PyObject *oname = NULL;
5340
0
    gid_t gid;
5341
5342
0
    if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5343
0
        goto exit;
5344
0
    }
5345
0
    if (!PyUnicode_FSConverter(args[0], &oname)) {
5346
0
        goto exit;
5347
0
    }
5348
0
    if (!_Py_Gid_Converter(args[1], &gid)) {
5349
0
        goto exit;
5350
0
    }
5351
0
    return_value = os_initgroups_impl(module, oname, gid);
5352
5353
0
exit:
5354
    /* Cleanup for oname */
5355
0
    Py_XDECREF(oname);
5356
5357
0
    return return_value;
5358
0
}
5359
5360
#endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */
5361
5362
#if defined(HAVE_GETPGID)
5363
5364
PyDoc_STRVAR(os_getpgid__doc__,
5365
"getpgid($module, /, pid)\n"
5366
"--\n"
5367
"\n"
5368
"Call the system call getpgid(), and return the result.");
5369
5370
#define OS_GETPGID_METHODDEF    \
5371
    {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
5372
5373
static PyObject *
5374
os_getpgid_impl(PyObject *module, pid_t pid);
5375
5376
static PyObject *
5377
os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5378
0
{
5379
0
    PyObject *return_value = NULL;
5380
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5381
5382
0
    #define NUM_KEYWORDS 1
5383
0
    static struct {
5384
0
        PyGC_Head _this_is_not_used;
5385
0
        PyObject_VAR_HEAD
5386
0
        Py_hash_t ob_hash;
5387
0
        PyObject *ob_item[NUM_KEYWORDS];
5388
0
    } _kwtuple = {
5389
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5390
0
        .ob_hash = -1,
5391
0
        .ob_item = { &_Py_ID(pid), },
5392
0
    };
5393
0
    #undef NUM_KEYWORDS
5394
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5395
5396
    #else  // !Py_BUILD_CORE
5397
    #  define KWTUPLE NULL
5398
    #endif  // !Py_BUILD_CORE
5399
5400
0
    static const char * const _keywords[] = {"pid", NULL};
5401
0
    static _PyArg_Parser _parser = {
5402
0
        .keywords = _keywords,
5403
0
        .fname = "getpgid",
5404
0
        .kwtuple = KWTUPLE,
5405
0
    };
5406
0
    #undef KWTUPLE
5407
0
    PyObject *argsbuf[1];
5408
0
    pid_t pid;
5409
5410
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
5411
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
5412
0
    if (!args) {
5413
0
        goto exit;
5414
0
    }
5415
0
    pid = PyLong_AsPid(args[0]);
5416
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5417
0
        goto exit;
5418
0
    }
5419
0
    return_value = os_getpgid_impl(module, pid);
5420
5421
0
exit:
5422
0
    return return_value;
5423
0
}
5424
5425
#endif /* defined(HAVE_GETPGID) */
5426
5427
#if defined(HAVE_GETPGRP)
5428
5429
PyDoc_STRVAR(os_getpgrp__doc__,
5430
"getpgrp($module, /)\n"
5431
"--\n"
5432
"\n"
5433
"Return the current process group id.");
5434
5435
#define OS_GETPGRP_METHODDEF    \
5436
    {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
5437
5438
static PyObject *
5439
os_getpgrp_impl(PyObject *module);
5440
5441
static PyObject *
5442
os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5443
0
{
5444
0
    return os_getpgrp_impl(module);
5445
0
}
5446
5447
#endif /* defined(HAVE_GETPGRP) */
5448
5449
#if defined(HAVE_SETPGRP)
5450
5451
PyDoc_STRVAR(os_setpgrp__doc__,
5452
"setpgrp($module, /)\n"
5453
"--\n"
5454
"\n"
5455
"Make the current process the leader of its process group.");
5456
5457
#define OS_SETPGRP_METHODDEF    \
5458
    {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
5459
5460
static PyObject *
5461
os_setpgrp_impl(PyObject *module);
5462
5463
static PyObject *
5464
os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5465
0
{
5466
0
    return os_setpgrp_impl(module);
5467
0
}
5468
5469
#endif /* defined(HAVE_SETPGRP) */
5470
5471
#if defined(HAVE_GETPPID)
5472
5473
PyDoc_STRVAR(os_getppid__doc__,
5474
"getppid($module, /)\n"
5475
"--\n"
5476
"\n"
5477
"Return the parent\'s process id.\n"
5478
"\n"
5479
"If the parent process has already exited, Windows machines will still\n"
5480
"return its id; others systems will return the id of the \'init\' process (1).");
5481
5482
#define OS_GETPPID_METHODDEF    \
5483
    {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
5484
5485
static PyObject *
5486
os_getppid_impl(PyObject *module);
5487
5488
static PyObject *
5489
os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
5490
0
{
5491
0
    return os_getppid_impl(module);
5492
0
}
5493
5494
#endif /* defined(HAVE_GETPPID) */
5495
5496
#if defined(HAVE_GETLOGIN)
5497
5498
PyDoc_STRVAR(os_getlogin__doc__,
5499
"getlogin($module, /)\n"
5500
"--\n"
5501
"\n"
5502
"Return the actual login name.");
5503
5504
#define OS_GETLOGIN_METHODDEF    \
5505
    {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
5506
5507
static PyObject *
5508
os_getlogin_impl(PyObject *module);
5509
5510
static PyObject *
5511
os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
5512
0
{
5513
0
    return os_getlogin_impl(module);
5514
0
}
5515
5516
#endif /* defined(HAVE_GETLOGIN) */
5517
5518
#if defined(HAVE_GETUID)
5519
5520
PyDoc_STRVAR(os_getuid__doc__,
5521
"getuid($module, /)\n"
5522
"--\n"
5523
"\n"
5524
"Return the current process\'s user id.");
5525
5526
#define OS_GETUID_METHODDEF    \
5527
    {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
5528
5529
static PyObject *
5530
os_getuid_impl(PyObject *module);
5531
5532
static PyObject *
5533
os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5534
16
{
5535
16
    return os_getuid_impl(module);
5536
16
}
5537
5538
#endif /* defined(HAVE_GETUID) */
5539
5540
#if defined(HAVE_KILL)
5541
5542
PyDoc_STRVAR(os_kill__doc__,
5543
"kill($module, pid, signal, /)\n"
5544
"--\n"
5545
"\n"
5546
"Kill a process with a signal.");
5547
5548
#define OS_KILL_METHODDEF    \
5549
    {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__},
5550
5551
static PyObject *
5552
os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
5553
5554
static PyObject *
5555
os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5556
0
{
5557
0
    PyObject *return_value = NULL;
5558
0
    pid_t pid;
5559
0
    Py_ssize_t signal;
5560
5561
0
    if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) {
5562
0
        goto exit;
5563
0
    }
5564
0
    pid = PyLong_AsPid(args[0]);
5565
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5566
0
        goto exit;
5567
0
    }
5568
0
    {
5569
0
        Py_ssize_t ival = -1;
5570
0
        PyObject *iobj = _PyNumber_Index(args[1]);
5571
0
        if (iobj != NULL) {
5572
0
            ival = PyLong_AsSsize_t(iobj);
5573
0
            Py_DECREF(iobj);
5574
0
        }
5575
0
        if (ival == -1 && PyErr_Occurred()) {
5576
0
            goto exit;
5577
0
        }
5578
0
        signal = ival;
5579
0
    }
5580
0
    return_value = os_kill_impl(module, pid, signal);
5581
5582
0
exit:
5583
0
    return return_value;
5584
0
}
5585
5586
#endif /* defined(HAVE_KILL) */
5587
5588
#if defined(HAVE_KILLPG)
5589
5590
PyDoc_STRVAR(os_killpg__doc__,
5591
"killpg($module, pgid, signal, /)\n"
5592
"--\n"
5593
"\n"
5594
"Kill a process group with a signal.");
5595
5596
#define OS_KILLPG_METHODDEF    \
5597
    {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__},
5598
5599
static PyObject *
5600
os_killpg_impl(PyObject *module, pid_t pgid, int signal);
5601
5602
static PyObject *
5603
os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5604
0
{
5605
0
    PyObject *return_value = NULL;
5606
0
    pid_t pgid;
5607
0
    int signal;
5608
5609
0
    if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) {
5610
0
        goto exit;
5611
0
    }
5612
0
    pgid = PyLong_AsPid(args[0]);
5613
0
    if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
5614
0
        goto exit;
5615
0
    }
5616
0
    signal = PyLong_AsInt(args[1]);
5617
0
    if (signal == -1 && PyErr_Occurred()) {
5618
0
        goto exit;
5619
0
    }
5620
0
    return_value = os_killpg_impl(module, pgid, signal);
5621
5622
0
exit:
5623
0
    return return_value;
5624
0
}
5625
5626
#endif /* defined(HAVE_KILLPG) */
5627
5628
#if defined(HAVE_PLOCK)
5629
5630
PyDoc_STRVAR(os_plock__doc__,
5631
"plock($module, op, /)\n"
5632
"--\n"
5633
"\n"
5634
"Lock program segments into memory.\");");
5635
5636
#define OS_PLOCK_METHODDEF    \
5637
    {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
5638
5639
static PyObject *
5640
os_plock_impl(PyObject *module, int op);
5641
5642
static PyObject *
5643
os_plock(PyObject *module, PyObject *arg)
5644
{
5645
    PyObject *return_value = NULL;
5646
    int op;
5647
5648
    op = PyLong_AsInt(arg);
5649
    if (op == -1 && PyErr_Occurred()) {
5650
        goto exit;
5651
    }
5652
    return_value = os_plock_impl(module, op);
5653
5654
exit:
5655
    return return_value;
5656
}
5657
5658
#endif /* defined(HAVE_PLOCK) */
5659
5660
#if defined(HAVE_SETUID)
5661
5662
PyDoc_STRVAR(os_setuid__doc__,
5663
"setuid($module, uid, /)\n"
5664
"--\n"
5665
"\n"
5666
"Set the current process\'s user id.");
5667
5668
#define OS_SETUID_METHODDEF    \
5669
    {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
5670
5671
static PyObject *
5672
os_setuid_impl(PyObject *module, uid_t uid);
5673
5674
static PyObject *
5675
os_setuid(PyObject *module, PyObject *arg)
5676
0
{
5677
0
    PyObject *return_value = NULL;
5678
0
    uid_t uid;
5679
5680
0
    if (!_Py_Uid_Converter(arg, &uid)) {
5681
0
        goto exit;
5682
0
    }
5683
0
    return_value = os_setuid_impl(module, uid);
5684
5685
0
exit:
5686
0
    return return_value;
5687
0
}
5688
5689
#endif /* defined(HAVE_SETUID) */
5690
5691
#if defined(HAVE_SETEUID)
5692
5693
PyDoc_STRVAR(os_seteuid__doc__,
5694
"seteuid($module, euid, /)\n"
5695
"--\n"
5696
"\n"
5697
"Set the current process\'s effective user id.");
5698
5699
#define OS_SETEUID_METHODDEF    \
5700
    {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
5701
5702
static PyObject *
5703
os_seteuid_impl(PyObject *module, uid_t euid);
5704
5705
static PyObject *
5706
os_seteuid(PyObject *module, PyObject *arg)
5707
0
{
5708
0
    PyObject *return_value = NULL;
5709
0
    uid_t euid;
5710
5711
0
    if (!_Py_Uid_Converter(arg, &euid)) {
5712
0
        goto exit;
5713
0
    }
5714
0
    return_value = os_seteuid_impl(module, euid);
5715
5716
0
exit:
5717
0
    return return_value;
5718
0
}
5719
5720
#endif /* defined(HAVE_SETEUID) */
5721
5722
#if defined(HAVE_SETEGID)
5723
5724
PyDoc_STRVAR(os_setegid__doc__,
5725
"setegid($module, egid, /)\n"
5726
"--\n"
5727
"\n"
5728
"Set the current process\'s effective group id.");
5729
5730
#define OS_SETEGID_METHODDEF    \
5731
    {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
5732
5733
static PyObject *
5734
os_setegid_impl(PyObject *module, gid_t egid);
5735
5736
static PyObject *
5737
os_setegid(PyObject *module, PyObject *arg)
5738
0
{
5739
0
    PyObject *return_value = NULL;
5740
0
    gid_t egid;
5741
5742
0
    if (!_Py_Gid_Converter(arg, &egid)) {
5743
0
        goto exit;
5744
0
    }
5745
0
    return_value = os_setegid_impl(module, egid);
5746
5747
0
exit:
5748
0
    return return_value;
5749
0
}
5750
5751
#endif /* defined(HAVE_SETEGID) */
5752
5753
#if defined(HAVE_SETREUID)
5754
5755
PyDoc_STRVAR(os_setreuid__doc__,
5756
"setreuid($module, ruid, euid, /)\n"
5757
"--\n"
5758
"\n"
5759
"Set the current process\'s real and effective user ids.");
5760
5761
#define OS_SETREUID_METHODDEF    \
5762
    {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__},
5763
5764
static PyObject *
5765
os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
5766
5767
static PyObject *
5768
os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5769
0
{
5770
0
    PyObject *return_value = NULL;
5771
0
    uid_t ruid;
5772
0
    uid_t euid;
5773
5774
0
    if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
5775
0
        goto exit;
5776
0
    }
5777
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
5778
0
        goto exit;
5779
0
    }
5780
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
5781
0
        goto exit;
5782
0
    }
5783
0
    return_value = os_setreuid_impl(module, ruid, euid);
5784
5785
0
exit:
5786
0
    return return_value;
5787
0
}
5788
5789
#endif /* defined(HAVE_SETREUID) */
5790
5791
#if defined(HAVE_SETREGID)
5792
5793
PyDoc_STRVAR(os_setregid__doc__,
5794
"setregid($module, rgid, egid, /)\n"
5795
"--\n"
5796
"\n"
5797
"Set the current process\'s real and effective group ids.");
5798
5799
#define OS_SETREGID_METHODDEF    \
5800
    {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__},
5801
5802
static PyObject *
5803
os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
5804
5805
static PyObject *
5806
os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5807
0
{
5808
0
    PyObject *return_value = NULL;
5809
0
    gid_t rgid;
5810
0
    gid_t egid;
5811
5812
0
    if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
5813
0
        goto exit;
5814
0
    }
5815
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
5816
0
        goto exit;
5817
0
    }
5818
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
5819
0
        goto exit;
5820
0
    }
5821
0
    return_value = os_setregid_impl(module, rgid, egid);
5822
5823
0
exit:
5824
0
    return return_value;
5825
0
}
5826
5827
#endif /* defined(HAVE_SETREGID) */
5828
5829
#if defined(HAVE_SETGID)
5830
5831
PyDoc_STRVAR(os_setgid__doc__,
5832
"setgid($module, gid, /)\n"
5833
"--\n"
5834
"\n"
5835
"Set the current process\'s group id.");
5836
5837
#define OS_SETGID_METHODDEF    \
5838
    {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
5839
5840
static PyObject *
5841
os_setgid_impl(PyObject *module, gid_t gid);
5842
5843
static PyObject *
5844
os_setgid(PyObject *module, PyObject *arg)
5845
0
{
5846
0
    PyObject *return_value = NULL;
5847
0
    gid_t gid;
5848
5849
0
    if (!_Py_Gid_Converter(arg, &gid)) {
5850
0
        goto exit;
5851
0
    }
5852
0
    return_value = os_setgid_impl(module, gid);
5853
5854
0
exit:
5855
0
    return return_value;
5856
0
}
5857
5858
#endif /* defined(HAVE_SETGID) */
5859
5860
#if defined(HAVE_SETGROUPS)
5861
5862
PyDoc_STRVAR(os_setgroups__doc__,
5863
"setgroups($module, groups, /)\n"
5864
"--\n"
5865
"\n"
5866
"Set the groups of the current process to list.");
5867
5868
#define OS_SETGROUPS_METHODDEF    \
5869
    {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
5870
5871
#endif /* defined(HAVE_SETGROUPS) */
5872
5873
#if defined(HAVE_WAIT3)
5874
5875
PyDoc_STRVAR(os_wait3__doc__,
5876
"wait3($module, /, options)\n"
5877
"--\n"
5878
"\n"
5879
"Wait for completion of a child process.\n"
5880
"\n"
5881
"Returns a tuple of information about the child process:\n"
5882
"  (pid, status, rusage)");
5883
5884
#define OS_WAIT3_METHODDEF    \
5885
    {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
5886
5887
static PyObject *
5888
os_wait3_impl(PyObject *module, int options);
5889
5890
static PyObject *
5891
os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5892
0
{
5893
0
    PyObject *return_value = NULL;
5894
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5895
5896
0
    #define NUM_KEYWORDS 1
5897
0
    static struct {
5898
0
        PyGC_Head _this_is_not_used;
5899
0
        PyObject_VAR_HEAD
5900
0
        Py_hash_t ob_hash;
5901
0
        PyObject *ob_item[NUM_KEYWORDS];
5902
0
    } _kwtuple = {
5903
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5904
0
        .ob_hash = -1,
5905
0
        .ob_item = { &_Py_ID(options), },
5906
0
    };
5907
0
    #undef NUM_KEYWORDS
5908
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5909
5910
    #else  // !Py_BUILD_CORE
5911
    #  define KWTUPLE NULL
5912
    #endif  // !Py_BUILD_CORE
5913
5914
0
    static const char * const _keywords[] = {"options", NULL};
5915
0
    static _PyArg_Parser _parser = {
5916
0
        .keywords = _keywords,
5917
0
        .fname = "wait3",
5918
0
        .kwtuple = KWTUPLE,
5919
0
    };
5920
0
    #undef KWTUPLE
5921
0
    PyObject *argsbuf[1];
5922
0
    int options;
5923
5924
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
5925
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
5926
0
    if (!args) {
5927
0
        goto exit;
5928
0
    }
5929
0
    options = PyLong_AsInt(args[0]);
5930
0
    if (options == -1 && PyErr_Occurred()) {
5931
0
        goto exit;
5932
0
    }
5933
0
    return_value = os_wait3_impl(module, options);
5934
5935
0
exit:
5936
0
    return return_value;
5937
0
}
5938
5939
#endif /* defined(HAVE_WAIT3) */
5940
5941
#if defined(HAVE_WAIT4)
5942
5943
PyDoc_STRVAR(os_wait4__doc__,
5944
"wait4($module, /, pid, options)\n"
5945
"--\n"
5946
"\n"
5947
"Wait for completion of a specific child process.\n"
5948
"\n"
5949
"Returns a tuple of information about the child process:\n"
5950
"  (pid, status, rusage)");
5951
5952
#define OS_WAIT4_METHODDEF    \
5953
    {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
5954
5955
static PyObject *
5956
os_wait4_impl(PyObject *module, pid_t pid, int options);
5957
5958
static PyObject *
5959
os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5960
0
{
5961
0
    PyObject *return_value = NULL;
5962
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5963
5964
0
    #define NUM_KEYWORDS 2
5965
0
    static struct {
5966
0
        PyGC_Head _this_is_not_used;
5967
0
        PyObject_VAR_HEAD
5968
0
        Py_hash_t ob_hash;
5969
0
        PyObject *ob_item[NUM_KEYWORDS];
5970
0
    } _kwtuple = {
5971
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5972
0
        .ob_hash = -1,
5973
0
        .ob_item = { &_Py_ID(pid), &_Py_ID(options), },
5974
0
    };
5975
0
    #undef NUM_KEYWORDS
5976
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5977
5978
    #else  // !Py_BUILD_CORE
5979
    #  define KWTUPLE NULL
5980
    #endif  // !Py_BUILD_CORE
5981
5982
0
    static const char * const _keywords[] = {"pid", "options", NULL};
5983
0
    static _PyArg_Parser _parser = {
5984
0
        .keywords = _keywords,
5985
0
        .fname = "wait4",
5986
0
        .kwtuple = KWTUPLE,
5987
0
    };
5988
0
    #undef KWTUPLE
5989
0
    PyObject *argsbuf[2];
5990
0
    pid_t pid;
5991
0
    int options;
5992
5993
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
5994
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
5995
0
    if (!args) {
5996
0
        goto exit;
5997
0
    }
5998
0
    pid = PyLong_AsPid(args[0]);
5999
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6000
0
        goto exit;
6001
0
    }
6002
0
    options = PyLong_AsInt(args[1]);
6003
0
    if (options == -1 && PyErr_Occurred()) {
6004
0
        goto exit;
6005
0
    }
6006
0
    return_value = os_wait4_impl(module, pid, options);
6007
6008
0
exit:
6009
0
    return return_value;
6010
0
}
6011
6012
#endif /* defined(HAVE_WAIT4) */
6013
6014
#if defined(HAVE_WAITID)
6015
6016
PyDoc_STRVAR(os_waitid__doc__,
6017
"waitid($module, idtype, id, options, /)\n"
6018
"--\n"
6019
"\n"
6020
"Returns the result of waiting for a process or processes.\n"
6021
"\n"
6022
"  idtype\n"
6023
"    Must be one of be P_PID, P_PGID or P_ALL.\n"
6024
"  id\n"
6025
"    The id to wait on.\n"
6026
"  options\n"
6027
"    Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
6028
"    or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
6029
"\n"
6030
"Returns either waitid_result or None if WNOHANG is specified and there are\n"
6031
"no children in a waitable state.");
6032
6033
#define OS_WAITID_METHODDEF    \
6034
    {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__},
6035
6036
static PyObject *
6037
os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
6038
6039
static PyObject *
6040
os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6041
0
{
6042
0
    PyObject *return_value = NULL;
6043
0
    idtype_t idtype;
6044
0
    id_t id;
6045
0
    int options;
6046
6047
0
    if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) {
6048
0
        goto exit;
6049
0
    }
6050
0
    if (!idtype_t_converter(args[0], &idtype)) {
6051
0
        goto exit;
6052
0
    }
6053
0
    id = (id_t)PyLong_AsPid(args[1]);
6054
0
    if (id == (id_t)(-1) && PyErr_Occurred()) {
6055
0
        goto exit;
6056
0
    }
6057
0
    options = PyLong_AsInt(args[2]);
6058
0
    if (options == -1 && PyErr_Occurred()) {
6059
0
        goto exit;
6060
0
    }
6061
0
    return_value = os_waitid_impl(module, idtype, id, options);
6062
6063
0
exit:
6064
0
    return return_value;
6065
0
}
6066
6067
#endif /* defined(HAVE_WAITID) */
6068
6069
#if defined(HAVE_WAITPID)
6070
6071
PyDoc_STRVAR(os_waitpid__doc__,
6072
"waitpid($module, pid, options, /)\n"
6073
"--\n"
6074
"\n"
6075
"Wait for completion of a given child process.\n"
6076
"\n"
6077
"Returns a tuple of information regarding the child process:\n"
6078
"    (pid, status)\n"
6079
"\n"
6080
"The options argument is ignored on Windows.");
6081
6082
#define OS_WAITPID_METHODDEF    \
6083
    {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6084
6085
static PyObject *
6086
os_waitpid_impl(PyObject *module, pid_t pid, int options);
6087
6088
static PyObject *
6089
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6090
0
{
6091
0
    PyObject *return_value = NULL;
6092
0
    pid_t pid;
6093
0
    int options;
6094
6095
0
    if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6096
0
        goto exit;
6097
0
    }
6098
0
    pid = PyLong_AsPid(args[0]);
6099
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6100
0
        goto exit;
6101
0
    }
6102
0
    options = PyLong_AsInt(args[1]);
6103
0
    if (options == -1 && PyErr_Occurred()) {
6104
0
        goto exit;
6105
0
    }
6106
0
    return_value = os_waitpid_impl(module, pid, options);
6107
6108
0
exit:
6109
0
    return return_value;
6110
0
}
6111
6112
#endif /* defined(HAVE_WAITPID) */
6113
6114
#if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT)
6115
6116
PyDoc_STRVAR(os_waitpid__doc__,
6117
"waitpid($module, pid, options, /)\n"
6118
"--\n"
6119
"\n"
6120
"Wait for completion of a given process.\n"
6121
"\n"
6122
"Returns a tuple of information regarding the process:\n"
6123
"    (pid, status << 8)\n"
6124
"\n"
6125
"The options argument is ignored on Windows.");
6126
6127
#define OS_WAITPID_METHODDEF    \
6128
    {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6129
6130
static PyObject *
6131
os_waitpid_impl(PyObject *module, intptr_t pid, int options);
6132
6133
static PyObject *
6134
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6135
{
6136
    PyObject *return_value = NULL;
6137
    intptr_t pid;
6138
    int options;
6139
6140
    if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6141
        goto exit;
6142
    }
6143
    pid = (intptr_t)PyLong_AsVoidPtr(args[0]);
6144
    if (!pid && PyErr_Occurred()) {
6145
        goto exit;
6146
    }
6147
    options = PyLong_AsInt(args[1]);
6148
    if (options == -1 && PyErr_Occurred()) {
6149
        goto exit;
6150
    }
6151
    return_value = os_waitpid_impl(module, pid, options);
6152
6153
exit:
6154
    return return_value;
6155
}
6156
6157
#endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */
6158
6159
#if defined(HAVE_WAIT)
6160
6161
PyDoc_STRVAR(os_wait__doc__,
6162
"wait($module, /)\n"
6163
"--\n"
6164
"\n"
6165
"Wait for completion of a child process.\n"
6166
"\n"
6167
"Returns a tuple of information about the child process:\n"
6168
"    (pid, status)");
6169
6170
#define OS_WAIT_METHODDEF    \
6171
    {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
6172
6173
static PyObject *
6174
os_wait_impl(PyObject *module);
6175
6176
static PyObject *
6177
os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
6178
0
{
6179
0
    return os_wait_impl(module);
6180
0
}
6181
6182
#endif /* defined(HAVE_WAIT) */
6183
6184
#if (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))
6185
6186
PyDoc_STRVAR(os_pidfd_open__doc__,
6187
"pidfd_open($module, /, pid, flags=0)\n"
6188
"--\n"
6189
"\n"
6190
"Return a file descriptor referring to the process *pid*.\n"
6191
"\n"
6192
"The descriptor can be used to perform process management without races and\n"
6193
"signals.");
6194
6195
#define OS_PIDFD_OPEN_METHODDEF    \
6196
    {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__},
6197
6198
static PyObject *
6199
os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags);
6200
6201
static PyObject *
6202
os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6203
0
{
6204
0
    PyObject *return_value = NULL;
6205
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6206
6207
0
    #define NUM_KEYWORDS 2
6208
0
    static struct {
6209
0
        PyGC_Head _this_is_not_used;
6210
0
        PyObject_VAR_HEAD
6211
0
        Py_hash_t ob_hash;
6212
0
        PyObject *ob_item[NUM_KEYWORDS];
6213
0
    } _kwtuple = {
6214
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6215
0
        .ob_hash = -1,
6216
0
        .ob_item = { &_Py_ID(pid), &_Py_ID(flags), },
6217
0
    };
6218
0
    #undef NUM_KEYWORDS
6219
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6220
6221
    #else  // !Py_BUILD_CORE
6222
    #  define KWTUPLE NULL
6223
    #endif  // !Py_BUILD_CORE
6224
6225
0
    static const char * const _keywords[] = {"pid", "flags", NULL};
6226
0
    static _PyArg_Parser _parser = {
6227
0
        .keywords = _keywords,
6228
0
        .fname = "pidfd_open",
6229
0
        .kwtuple = KWTUPLE,
6230
0
    };
6231
0
    #undef KWTUPLE
6232
0
    PyObject *argsbuf[2];
6233
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6234
0
    pid_t pid;
6235
0
    unsigned int flags = 0;
6236
6237
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6238
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6239
0
    if (!args) {
6240
0
        goto exit;
6241
0
    }
6242
0
    pid = PyLong_AsPid(args[0]);
6243
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6244
0
        goto exit;
6245
0
    }
6246
0
    if (!noptargs) {
6247
0
        goto skip_optional_pos;
6248
0
    }
6249
0
    if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) {
6250
0
        goto exit;
6251
0
    }
6252
0
skip_optional_pos:
6253
0
    return_value = os_pidfd_open_impl(module, pid, flags);
6254
6255
0
exit:
6256
0
    return return_value;
6257
0
}
6258
6259
#endif /* (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */
6260
6261
#if defined(HAVE_SETNS)
6262
6263
PyDoc_STRVAR(os_setns__doc__,
6264
"setns($module, /, fd, nstype=0)\n"
6265
"--\n"
6266
"\n"
6267
"Move the calling thread into different namespaces.\n"
6268
"\n"
6269
"  fd\n"
6270
"    A file descriptor to a namespace.\n"
6271
"  nstype\n"
6272
"    Type of namespace.");
6273
6274
#define OS_SETNS_METHODDEF    \
6275
    {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__},
6276
6277
static PyObject *
6278
os_setns_impl(PyObject *module, int fd, int nstype);
6279
6280
static PyObject *
6281
os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6282
0
{
6283
0
    PyObject *return_value = NULL;
6284
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6285
6286
0
    #define NUM_KEYWORDS 2
6287
0
    static struct {
6288
0
        PyGC_Head _this_is_not_used;
6289
0
        PyObject_VAR_HEAD
6290
0
        Py_hash_t ob_hash;
6291
0
        PyObject *ob_item[NUM_KEYWORDS];
6292
0
    } _kwtuple = {
6293
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6294
0
        .ob_hash = -1,
6295
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), },
6296
0
    };
6297
0
    #undef NUM_KEYWORDS
6298
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6299
6300
    #else  // !Py_BUILD_CORE
6301
    #  define KWTUPLE NULL
6302
    #endif  // !Py_BUILD_CORE
6303
6304
0
    static const char * const _keywords[] = {"fd", "nstype", NULL};
6305
0
    static _PyArg_Parser _parser = {
6306
0
        .keywords = _keywords,
6307
0
        .fname = "setns",
6308
0
        .kwtuple = KWTUPLE,
6309
0
    };
6310
0
    #undef KWTUPLE
6311
0
    PyObject *argsbuf[2];
6312
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6313
0
    int fd;
6314
0
    int nstype = 0;
6315
6316
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6317
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6318
0
    if (!args) {
6319
0
        goto exit;
6320
0
    }
6321
0
    fd = PyObject_AsFileDescriptor(args[0]);
6322
0
    if (fd < 0) {
6323
0
        goto exit;
6324
0
    }
6325
0
    if (!noptargs) {
6326
0
        goto skip_optional_pos;
6327
0
    }
6328
0
    nstype = PyLong_AsInt(args[1]);
6329
0
    if (nstype == -1 && PyErr_Occurred()) {
6330
0
        goto exit;
6331
0
    }
6332
0
skip_optional_pos:
6333
0
    return_value = os_setns_impl(module, fd, nstype);
6334
6335
0
exit:
6336
0
    return return_value;
6337
0
}
6338
6339
#endif /* defined(HAVE_SETNS) */
6340
6341
#if defined(HAVE_UNSHARE)
6342
6343
PyDoc_STRVAR(os_unshare__doc__,
6344
"unshare($module, /, flags)\n"
6345
"--\n"
6346
"\n"
6347
"Disassociate parts of a process (or thread) execution context.\n"
6348
"\n"
6349
"  flags\n"
6350
"    Namespaces to be unshared.");
6351
6352
#define OS_UNSHARE_METHODDEF    \
6353
    {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__},
6354
6355
static PyObject *
6356
os_unshare_impl(PyObject *module, int flags);
6357
6358
static PyObject *
6359
os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6360
0
{
6361
0
    PyObject *return_value = NULL;
6362
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6363
6364
0
    #define NUM_KEYWORDS 1
6365
0
    static struct {
6366
0
        PyGC_Head _this_is_not_used;
6367
0
        PyObject_VAR_HEAD
6368
0
        Py_hash_t ob_hash;
6369
0
        PyObject *ob_item[NUM_KEYWORDS];
6370
0
    } _kwtuple = {
6371
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6372
0
        .ob_hash = -1,
6373
0
        .ob_item = { &_Py_ID(flags), },
6374
0
    };
6375
0
    #undef NUM_KEYWORDS
6376
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6377
6378
    #else  // !Py_BUILD_CORE
6379
    #  define KWTUPLE NULL
6380
    #endif  // !Py_BUILD_CORE
6381
6382
0
    static const char * const _keywords[] = {"flags", NULL};
6383
0
    static _PyArg_Parser _parser = {
6384
0
        .keywords = _keywords,
6385
0
        .fname = "unshare",
6386
0
        .kwtuple = KWTUPLE,
6387
0
    };
6388
0
    #undef KWTUPLE
6389
0
    PyObject *argsbuf[1];
6390
0
    int flags;
6391
6392
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6393
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6394
0
    if (!args) {
6395
0
        goto exit;
6396
0
    }
6397
0
    flags = PyLong_AsInt(args[0]);
6398
0
    if (flags == -1 && PyErr_Occurred()) {
6399
0
        goto exit;
6400
0
    }
6401
0
    return_value = os_unshare_impl(module, flags);
6402
6403
0
exit:
6404
0
    return return_value;
6405
0
}
6406
6407
#endif /* defined(HAVE_UNSHARE) */
6408
6409
#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
6410
6411
PyDoc_STRVAR(os_readlink__doc__,
6412
"readlink($module, /, path, *, dir_fd=None)\n"
6413
"--\n"
6414
"\n"
6415
"Return a string representing the path to which the symbolic link points.\n"
6416
"\n"
6417
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
6418
"and path should be relative; path will then be relative to that directory.\n"
6419
"\n"
6420
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
6421
"using it will raise a NotImplementedError.");
6422
6423
#define OS_READLINK_METHODDEF    \
6424
    {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
6425
6426
static PyObject *
6427
os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
6428
6429
static PyObject *
6430
os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6431
0
{
6432
0
    PyObject *return_value = NULL;
6433
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6434
6435
0
    #define NUM_KEYWORDS 2
6436
0
    static struct {
6437
0
        PyGC_Head _this_is_not_used;
6438
0
        PyObject_VAR_HEAD
6439
0
        Py_hash_t ob_hash;
6440
0
        PyObject *ob_item[NUM_KEYWORDS];
6441
0
    } _kwtuple = {
6442
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6443
0
        .ob_hash = -1,
6444
0
        .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
6445
0
    };
6446
0
    #undef NUM_KEYWORDS
6447
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6448
6449
    #else  // !Py_BUILD_CORE
6450
    #  define KWTUPLE NULL
6451
    #endif  // !Py_BUILD_CORE
6452
6453
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
6454
0
    static _PyArg_Parser _parser = {
6455
0
        .keywords = _keywords,
6456
0
        .fname = "readlink",
6457
0
        .kwtuple = KWTUPLE,
6458
0
    };
6459
0
    #undef KWTUPLE
6460
0
    PyObject *argsbuf[2];
6461
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6462
0
    path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0);
6463
0
    int dir_fd = DEFAULT_DIR_FD;
6464
6465
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6466
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6467
0
    if (!args) {
6468
0
        goto exit;
6469
0
    }
6470
0
    if (!path_converter(args[0], &path)) {
6471
0
        goto exit;
6472
0
    }
6473
0
    if (!noptargs) {
6474
0
        goto skip_optional_kwonly;
6475
0
    }
6476
0
    if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
6477
0
        goto exit;
6478
0
    }
6479
0
skip_optional_kwonly:
6480
0
    return_value = os_readlink_impl(module, &path, dir_fd);
6481
6482
0
exit:
6483
    /* Cleanup for path */
6484
0
    path_cleanup(&path);
6485
6486
0
    return return_value;
6487
0
}
6488
6489
#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
6490
6491
#if defined(HAVE_SYMLINK)
6492
6493
PyDoc_STRVAR(os_symlink__doc__,
6494
"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
6495
"--\n"
6496
"\n"
6497
"Create a symbolic link pointing to src named dst.\n"
6498
"\n"
6499
"target_is_directory is required on Windows if the target is to be\n"
6500
"  interpreted as a directory.  (On Windows, symlink requires\n"
6501
"  Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
6502
"  target_is_directory is ignored on non-Windows platforms.\n"
6503
"\n"
6504
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
6505
"  and path should be relative; path will then be relative to that directory.\n"
6506
"dir_fd may not be implemented on your platform.\n"
6507
"  If it is unavailable, using it will raise a NotImplementedError.");
6508
6509
#define OS_SYMLINK_METHODDEF    \
6510
    {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
6511
6512
static PyObject *
6513
os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
6514
                int target_is_directory, int dir_fd);
6515
6516
static PyObject *
6517
os_symlink(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 4
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(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), },
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[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
6541
0
    static _PyArg_Parser _parser = {
6542
0
        .keywords = _keywords,
6543
0
        .fname = "symlink",
6544
0
        .kwtuple = KWTUPLE,
6545
0
    };
6546
0
    #undef KWTUPLE
6547
0
    PyObject *argsbuf[4];
6548
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
6549
0
    path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0);
6550
0
    path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0);
6551
0
    int target_is_directory = 0;
6552
0
    int dir_fd = DEFAULT_DIR_FD;
6553
6554
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6555
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6556
0
    if (!args) {
6557
0
        goto exit;
6558
0
    }
6559
0
    if (!path_converter(args[0], &src)) {
6560
0
        goto exit;
6561
0
    }
6562
0
    if (!path_converter(args[1], &dst)) {
6563
0
        goto exit;
6564
0
    }
6565
0
    if (!noptargs) {
6566
0
        goto skip_optional_pos;
6567
0
    }
6568
0
    if (args[2]) {
6569
0
        target_is_directory = PyObject_IsTrue(args[2]);
6570
0
        if (target_is_directory < 0) {
6571
0
            goto exit;
6572
0
        }
6573
0
        if (!--noptargs) {
6574
0
            goto skip_optional_pos;
6575
0
        }
6576
0
    }
6577
0
skip_optional_pos:
6578
0
    if (!noptargs) {
6579
0
        goto skip_optional_kwonly;
6580
0
    }
6581
0
    if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
6582
0
        goto exit;
6583
0
    }
6584
0
skip_optional_kwonly:
6585
0
    return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
6586
6587
0
exit:
6588
    /* Cleanup for src */
6589
0
    path_cleanup(&src);
6590
    /* Cleanup for dst */
6591
0
    path_cleanup(&dst);
6592
6593
0
    return return_value;
6594
0
}
6595
6596
#endif /* defined(HAVE_SYMLINK) */
6597
6598
PyDoc_STRVAR(os_times__doc__,
6599
"times($module, /)\n"
6600
"--\n"
6601
"\n"
6602
"Return a collection containing process timing information.\n"
6603
"\n"
6604
"The object returned behaves like a named tuple with these fields:\n"
6605
"  (utime, stime, cutime, cstime, elapsed_time)\n"
6606
"All fields are floating-point numbers.");
6607
6608
#define OS_TIMES_METHODDEF    \
6609
    {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
6610
6611
static PyObject *
6612
os_times_impl(PyObject *module);
6613
6614
static PyObject *
6615
os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
6616
0
{
6617
0
    return os_times_impl(module);
6618
0
}
6619
6620
#if defined(HAVE_TIMERFD_CREATE)
6621
6622
PyDoc_STRVAR(os_timerfd_create__doc__,
6623
"timerfd_create($module, clockid, /, *, flags=0)\n"
6624
"--\n"
6625
"\n"
6626
"Create and return a timer file descriptor.\n"
6627
"\n"
6628
"  clockid\n"
6629
"    A valid clock ID constant as timer file descriptor.\n"
6630
"\n"
6631
"    time.CLOCK_REALTIME\n"
6632
"    time.CLOCK_MONOTONIC\n"
6633
"    time.CLOCK_BOOTTIME\n"
6634
"  flags\n"
6635
"    0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n"
6636
"\n"
6637
"    os.TFD_NONBLOCK\n"
6638
"        If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n"
6639
"        If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n"
6640
"\n"
6641
"    os.TFD_CLOEXEC\n"
6642
"        If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag");
6643
6644
#define OS_TIMERFD_CREATE_METHODDEF    \
6645
    {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__},
6646
6647
static PyObject *
6648
os_timerfd_create_impl(PyObject *module, int clockid, int flags);
6649
6650
static PyObject *
6651
os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6652
0
{
6653
0
    PyObject *return_value = NULL;
6654
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6655
6656
0
    #define NUM_KEYWORDS 1
6657
0
    static struct {
6658
0
        PyGC_Head _this_is_not_used;
6659
0
        PyObject_VAR_HEAD
6660
0
        Py_hash_t ob_hash;
6661
0
        PyObject *ob_item[NUM_KEYWORDS];
6662
0
    } _kwtuple = {
6663
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6664
0
        .ob_hash = -1,
6665
0
        .ob_item = { &_Py_ID(flags), },
6666
0
    };
6667
0
    #undef NUM_KEYWORDS
6668
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6669
6670
    #else  // !Py_BUILD_CORE
6671
    #  define KWTUPLE NULL
6672
    #endif  // !Py_BUILD_CORE
6673
6674
0
    static const char * const _keywords[] = {"", "flags", NULL};
6675
0
    static _PyArg_Parser _parser = {
6676
0
        .keywords = _keywords,
6677
0
        .fname = "timerfd_create",
6678
0
        .kwtuple = KWTUPLE,
6679
0
    };
6680
0
    #undef KWTUPLE
6681
0
    PyObject *argsbuf[2];
6682
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6683
0
    int clockid;
6684
0
    int flags = 0;
6685
6686
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6687
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6688
0
    if (!args) {
6689
0
        goto exit;
6690
0
    }
6691
0
    clockid = PyLong_AsInt(args[0]);
6692
0
    if (clockid == -1 && PyErr_Occurred()) {
6693
0
        goto exit;
6694
0
    }
6695
0
    if (!noptargs) {
6696
0
        goto skip_optional_kwonly;
6697
0
    }
6698
0
    flags = PyLong_AsInt(args[1]);
6699
0
    if (flags == -1 && PyErr_Occurred()) {
6700
0
        goto exit;
6701
0
    }
6702
0
skip_optional_kwonly:
6703
0
    return_value = os_timerfd_create_impl(module, clockid, flags);
6704
6705
0
exit:
6706
0
    return return_value;
6707
0
}
6708
6709
#endif /* defined(HAVE_TIMERFD_CREATE) */
6710
6711
#if defined(HAVE_TIMERFD_CREATE)
6712
6713
PyDoc_STRVAR(os_timerfd_settime__doc__,
6714
"timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n"
6715
"--\n"
6716
"\n"
6717
"Alter a timer file descriptor\'s internal timer in seconds.\n"
6718
"\n"
6719
"  fd\n"
6720
"    A timer file descriptor.\n"
6721
"  flags\n"
6722
"    0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
6723
"  initial\n"
6724
"    The initial expiration time, in seconds.\n"
6725
"  interval\n"
6726
"    The timer\'s interval, in seconds.");
6727
6728
#define OS_TIMERFD_SETTIME_METHODDEF    \
6729
    {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__},
6730
6731
static PyObject *
6732
os_timerfd_settime_impl(PyObject *module, int fd, int flags,
6733
                        double initial_double, double interval_double);
6734
6735
static PyObject *
6736
os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6737
0
{
6738
0
    PyObject *return_value = NULL;
6739
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6740
6741
0
    #define NUM_KEYWORDS 3
6742
0
    static struct {
6743
0
        PyGC_Head _this_is_not_used;
6744
0
        PyObject_VAR_HEAD
6745
0
        Py_hash_t ob_hash;
6746
0
        PyObject *ob_item[NUM_KEYWORDS];
6747
0
    } _kwtuple = {
6748
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6749
0
        .ob_hash = -1,
6750
0
        .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
6751
0
    };
6752
0
    #undef NUM_KEYWORDS
6753
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6754
6755
    #else  // !Py_BUILD_CORE
6756
    #  define KWTUPLE NULL
6757
    #endif  // !Py_BUILD_CORE
6758
6759
0
    static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
6760
0
    static _PyArg_Parser _parser = {
6761
0
        .keywords = _keywords,
6762
0
        .fname = "timerfd_settime",
6763
0
        .kwtuple = KWTUPLE,
6764
0
    };
6765
0
    #undef KWTUPLE
6766
0
    PyObject *argsbuf[4];
6767
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6768
0
    int fd;
6769
0
    int flags = 0;
6770
0
    double initial_double = 0.0;
6771
0
    double interval_double = 0.0;
6772
6773
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6774
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6775
0
    if (!args) {
6776
0
        goto exit;
6777
0
    }
6778
0
    fd = PyObject_AsFileDescriptor(args[0]);
6779
0
    if (fd < 0) {
6780
0
        goto exit;
6781
0
    }
6782
0
    if (!noptargs) {
6783
0
        goto skip_optional_kwonly;
6784
0
    }
6785
0
    if (args[1]) {
6786
0
        flags = PyLong_AsInt(args[1]);
6787
0
        if (flags == -1 && PyErr_Occurred()) {
6788
0
            goto exit;
6789
0
        }
6790
0
        if (!--noptargs) {
6791
0
            goto skip_optional_kwonly;
6792
0
        }
6793
0
    }
6794
0
    if (args[2]) {
6795
0
        if (PyFloat_CheckExact(args[2])) {
6796
0
            initial_double = PyFloat_AS_DOUBLE(args[2]);
6797
0
        }
6798
0
        else
6799
0
        {
6800
0
            initial_double = PyFloat_AsDouble(args[2]);
6801
0
            if (initial_double == -1.0 && PyErr_Occurred()) {
6802
0
                goto exit;
6803
0
            }
6804
0
        }
6805
0
        if (!--noptargs) {
6806
0
            goto skip_optional_kwonly;
6807
0
        }
6808
0
    }
6809
0
    if (PyFloat_CheckExact(args[3])) {
6810
0
        interval_double = PyFloat_AS_DOUBLE(args[3]);
6811
0
    }
6812
0
    else
6813
0
    {
6814
0
        interval_double = PyFloat_AsDouble(args[3]);
6815
0
        if (interval_double == -1.0 && PyErr_Occurred()) {
6816
0
            goto exit;
6817
0
        }
6818
0
    }
6819
0
skip_optional_kwonly:
6820
0
    return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double);
6821
6822
0
exit:
6823
0
    return return_value;
6824
0
}
6825
6826
#endif /* defined(HAVE_TIMERFD_CREATE) */
6827
6828
#if defined(HAVE_TIMERFD_CREATE)
6829
6830
PyDoc_STRVAR(os_timerfd_settime_ns__doc__,
6831
"timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n"
6832
"--\n"
6833
"\n"
6834
"Alter a timer file descriptor\'s internal timer in nanoseconds.\n"
6835
"\n"
6836
"  fd\n"
6837
"    A timer file descriptor.\n"
6838
"  flags\n"
6839
"    0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
6840
"  initial\n"
6841
"    initial expiration timing in seconds.\n"
6842
"  interval\n"
6843
"    interval for the timer in seconds.");
6844
6845
#define OS_TIMERFD_SETTIME_NS_METHODDEF    \
6846
    {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__},
6847
6848
static PyObject *
6849
os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags,
6850
                           long long initial, long long interval);
6851
6852
static PyObject *
6853
os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6854
0
{
6855
0
    PyObject *return_value = NULL;
6856
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6857
6858
0
    #define NUM_KEYWORDS 3
6859
0
    static struct {
6860
0
        PyGC_Head _this_is_not_used;
6861
0
        PyObject_VAR_HEAD
6862
0
        Py_hash_t ob_hash;
6863
0
        PyObject *ob_item[NUM_KEYWORDS];
6864
0
    } _kwtuple = {
6865
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6866
0
        .ob_hash = -1,
6867
0
        .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
6868
0
    };
6869
0
    #undef NUM_KEYWORDS
6870
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6871
6872
    #else  // !Py_BUILD_CORE
6873
    #  define KWTUPLE NULL
6874
    #endif  // !Py_BUILD_CORE
6875
6876
0
    static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
6877
0
    static _PyArg_Parser _parser = {
6878
0
        .keywords = _keywords,
6879
0
        .fname = "timerfd_settime_ns",
6880
0
        .kwtuple = KWTUPLE,
6881
0
    };
6882
0
    #undef KWTUPLE
6883
0
    PyObject *argsbuf[4];
6884
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6885
0
    int fd;
6886
0
    int flags = 0;
6887
0
    long long initial = 0;
6888
0
    long long interval = 0;
6889
6890
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6891
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6892
0
    if (!args) {
6893
0
        goto exit;
6894
0
    }
6895
0
    fd = PyObject_AsFileDescriptor(args[0]);
6896
0
    if (fd < 0) {
6897
0
        goto exit;
6898
0
    }
6899
0
    if (!noptargs) {
6900
0
        goto skip_optional_kwonly;
6901
0
    }
6902
0
    if (args[1]) {
6903
0
        flags = PyLong_AsInt(args[1]);
6904
0
        if (flags == -1 && PyErr_Occurred()) {
6905
0
            goto exit;
6906
0
        }
6907
0
        if (!--noptargs) {
6908
0
            goto skip_optional_kwonly;
6909
0
        }
6910
0
    }
6911
0
    if (args[2]) {
6912
0
        initial = PyLong_AsLongLong(args[2]);
6913
0
        if (initial == -1 && PyErr_Occurred()) {
6914
0
            goto exit;
6915
0
        }
6916
0
        if (!--noptargs) {
6917
0
            goto skip_optional_kwonly;
6918
0
        }
6919
0
    }
6920
0
    interval = PyLong_AsLongLong(args[3]);
6921
0
    if (interval == -1 && PyErr_Occurred()) {
6922
0
        goto exit;
6923
0
    }
6924
0
skip_optional_kwonly:
6925
0
    return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval);
6926
6927
0
exit:
6928
0
    return return_value;
6929
0
}
6930
6931
#endif /* defined(HAVE_TIMERFD_CREATE) */
6932
6933
#if defined(HAVE_TIMERFD_CREATE)
6934
6935
PyDoc_STRVAR(os_timerfd_gettime__doc__,
6936
"timerfd_gettime($module, fd, /)\n"
6937
"--\n"
6938
"\n"
6939
"Return a tuple of a timer file descriptor\'s (interval, next expiration) in float seconds.\n"
6940
"\n"
6941
"  fd\n"
6942
"    A timer file descriptor.");
6943
6944
#define OS_TIMERFD_GETTIME_METHODDEF    \
6945
    {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__},
6946
6947
static PyObject *
6948
os_timerfd_gettime_impl(PyObject *module, int fd);
6949
6950
static PyObject *
6951
os_timerfd_gettime(PyObject *module, PyObject *arg)
6952
0
{
6953
0
    PyObject *return_value = NULL;
6954
0
    int fd;
6955
6956
0
    fd = PyObject_AsFileDescriptor(arg);
6957
0
    if (fd < 0) {
6958
0
        goto exit;
6959
0
    }
6960
0
    return_value = os_timerfd_gettime_impl(module, fd);
6961
6962
0
exit:
6963
0
    return return_value;
6964
0
}
6965
6966
#endif /* defined(HAVE_TIMERFD_CREATE) */
6967
6968
#if defined(HAVE_TIMERFD_CREATE)
6969
6970
PyDoc_STRVAR(os_timerfd_gettime_ns__doc__,
6971
"timerfd_gettime_ns($module, fd, /)\n"
6972
"--\n"
6973
"\n"
6974
"Return a tuple of a timer file descriptor\'s (interval, next expiration) in nanoseconds.\n"
6975
"\n"
6976
"  fd\n"
6977
"    A timer file descriptor.");
6978
6979
#define OS_TIMERFD_GETTIME_NS_METHODDEF    \
6980
    {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__},
6981
6982
static PyObject *
6983
os_timerfd_gettime_ns_impl(PyObject *module, int fd);
6984
6985
static PyObject *
6986
os_timerfd_gettime_ns(PyObject *module, PyObject *arg)
6987
0
{
6988
0
    PyObject *return_value = NULL;
6989
0
    int fd;
6990
6991
0
    fd = PyObject_AsFileDescriptor(arg);
6992
0
    if (fd < 0) {
6993
0
        goto exit;
6994
0
    }
6995
0
    return_value = os_timerfd_gettime_ns_impl(module, fd);
6996
6997
0
exit:
6998
0
    return return_value;
6999
0
}
7000
7001
#endif /* defined(HAVE_TIMERFD_CREATE) */
7002
7003
#if defined(HAVE_GETSID)
7004
7005
PyDoc_STRVAR(os_getsid__doc__,
7006
"getsid($module, pid, /)\n"
7007
"--\n"
7008
"\n"
7009
"Call the system call getsid(pid) and return the result.");
7010
7011
#define OS_GETSID_METHODDEF    \
7012
    {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
7013
7014
static PyObject *
7015
os_getsid_impl(PyObject *module, pid_t pid);
7016
7017
static PyObject *
7018
os_getsid(PyObject *module, PyObject *arg)
7019
0
{
7020
0
    PyObject *return_value = NULL;
7021
0
    pid_t pid;
7022
7023
0
    pid = PyLong_AsPid(arg);
7024
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7025
0
        goto exit;
7026
0
    }
7027
0
    return_value = os_getsid_impl(module, pid);
7028
7029
0
exit:
7030
0
    return return_value;
7031
0
}
7032
7033
#endif /* defined(HAVE_GETSID) */
7034
7035
#if defined(HAVE_SETSID)
7036
7037
PyDoc_STRVAR(os_setsid__doc__,
7038
"setsid($module, /)\n"
7039
"--\n"
7040
"\n"
7041
"Call the system call setsid().");
7042
7043
#define OS_SETSID_METHODDEF    \
7044
    {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
7045
7046
static PyObject *
7047
os_setsid_impl(PyObject *module);
7048
7049
static PyObject *
7050
os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
7051
0
{
7052
0
    return os_setsid_impl(module);
7053
0
}
7054
7055
#endif /* defined(HAVE_SETSID) */
7056
7057
#if defined(HAVE_SETPGID)
7058
7059
PyDoc_STRVAR(os_setpgid__doc__,
7060
"setpgid($module, pid, pgrp, /)\n"
7061
"--\n"
7062
"\n"
7063
"Call the system call setpgid(pid, pgrp).");
7064
7065
#define OS_SETPGID_METHODDEF    \
7066
    {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__},
7067
7068
static PyObject *
7069
os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
7070
7071
static PyObject *
7072
os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7073
0
{
7074
0
    PyObject *return_value = NULL;
7075
0
    pid_t pid;
7076
0
    pid_t pgrp;
7077
7078
0
    if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) {
7079
0
        goto exit;
7080
0
    }
7081
0
    pid = PyLong_AsPid(args[0]);
7082
0
    if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7083
0
        goto exit;
7084
0
    }
7085
0
    pgrp = PyLong_AsPid(args[1]);
7086
0
    if (pgrp == (pid_t)(-1) && PyErr_Occurred()) {
7087
0
        goto exit;
7088
0
    }
7089
0
    return_value = os_setpgid_impl(module, pid, pgrp);
7090
7091
0
exit:
7092
0
    return return_value;
7093
0
}
7094
7095
#endif /* defined(HAVE_SETPGID) */
7096
7097
#if defined(HAVE_TCGETPGRP)
7098
7099
PyDoc_STRVAR(os_tcgetpgrp__doc__,
7100
"tcgetpgrp($module, fd, /)\n"
7101
"--\n"
7102
"\n"
7103
"Return the process group associated with the terminal specified by fd.");
7104
7105
#define OS_TCGETPGRP_METHODDEF    \
7106
    {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
7107
7108
static PyObject *
7109
os_tcgetpgrp_impl(PyObject *module, int fd);
7110
7111
static PyObject *
7112
os_tcgetpgrp(PyObject *module, PyObject *arg)
7113
0
{
7114
0
    PyObject *return_value = NULL;
7115
0
    int fd;
7116
7117
0
    fd = PyLong_AsInt(arg);
7118
0
    if (fd == -1 && PyErr_Occurred()) {
7119
0
        goto exit;
7120
0
    }
7121
0
    return_value = os_tcgetpgrp_impl(module, fd);
7122
7123
0
exit:
7124
0
    return return_value;
7125
0
}
7126
7127
#endif /* defined(HAVE_TCGETPGRP) */
7128
7129
#if defined(HAVE_TCSETPGRP)
7130
7131
PyDoc_STRVAR(os_tcsetpgrp__doc__,
7132
"tcsetpgrp($module, fd, pgid, /)\n"
7133
"--\n"
7134
"\n"
7135
"Set the process group associated with the terminal specified by fd.");
7136
7137
#define OS_TCSETPGRP_METHODDEF    \
7138
    {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__},
7139
7140
static PyObject *
7141
os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
7142
7143
static PyObject *
7144
os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7145
0
{
7146
0
    PyObject *return_value = NULL;
7147
0
    int fd;
7148
0
    pid_t pgid;
7149
7150
0
    if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) {
7151
0
        goto exit;
7152
0
    }
7153
0
    fd = PyLong_AsInt(args[0]);
7154
0
    if (fd == -1 && PyErr_Occurred()) {
7155
0
        goto exit;
7156
0
    }
7157
0
    pgid = PyLong_AsPid(args[1]);
7158
0
    if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
7159
0
        goto exit;
7160
0
    }
7161
0
    return_value = os_tcsetpgrp_impl(module, fd, pgid);
7162
7163
0
exit:
7164
0
    return return_value;
7165
0
}
7166
7167
#endif /* defined(HAVE_TCSETPGRP) */
7168
7169
PyDoc_STRVAR(os_open__doc__,
7170
"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
7171
"--\n"
7172
"\n"
7173
"Open a file for low level IO.  Returns a file descriptor (integer).\n"
7174
"\n"
7175
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
7176
"  and path should be relative; path will then be relative to that directory.\n"
7177
"dir_fd may not be implemented on your platform.\n"
7178
"  If it is unavailable, using it will raise a NotImplementedError.");
7179
7180
#define OS_OPEN_METHODDEF    \
7181
    {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
7182
7183
static int
7184
os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
7185
7186
static PyObject *
7187
os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7188
244
{
7189
244
    PyObject *return_value = NULL;
7190
244
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7191
7192
244
    #define NUM_KEYWORDS 4
7193
244
    static struct {
7194
244
        PyGC_Head _this_is_not_used;
7195
244
        PyObject_VAR_HEAD
7196
244
        Py_hash_t ob_hash;
7197
244
        PyObject *ob_item[NUM_KEYWORDS];
7198
244
    } _kwtuple = {
7199
244
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7200
244
        .ob_hash = -1,
7201
244
        .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), },
7202
244
    };
7203
244
    #undef NUM_KEYWORDS
7204
244
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7205
7206
    #else  // !Py_BUILD_CORE
7207
    #  define KWTUPLE NULL
7208
    #endif  // !Py_BUILD_CORE
7209
7210
244
    static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
7211
244
    static _PyArg_Parser _parser = {
7212
244
        .keywords = _keywords,
7213
244
        .fname = "open",
7214
244
        .kwtuple = KWTUPLE,
7215
244
    };
7216
244
    #undef KWTUPLE
7217
244
    PyObject *argsbuf[4];
7218
244
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7219
244
    path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0);
7220
244
    int flags;
7221
244
    int mode = 511;
7222
244
    int dir_fd = DEFAULT_DIR_FD;
7223
244
    int _return_value;
7224
7225
244
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7226
244
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7227
244
    if (!args) {
7228
0
        goto exit;
7229
0
    }
7230
244
    if (!path_converter(args[0], &path)) {
7231
0
        goto exit;
7232
0
    }
7233
244
    flags = PyLong_AsInt(args[1]);
7234
244
    if (flags == -1 && PyErr_Occurred()) {
7235
0
        goto exit;
7236
0
    }
7237
244
    if (!noptargs) {
7238
0
        goto skip_optional_pos;
7239
0
    }
7240
244
    if (args[2]) {
7241
244
        mode = PyLong_AsInt(args[2]);
7242
244
        if (mode == -1 && PyErr_Occurred()) {
7243
0
            goto exit;
7244
0
        }
7245
244
        if (!--noptargs) {
7246
244
            goto skip_optional_pos;
7247
244
        }
7248
244
    }
7249
244
skip_optional_pos:
7250
244
    if (!noptargs) {
7251
244
        goto skip_optional_kwonly;
7252
244
    }
7253
0
    if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
7254
0
        goto exit;
7255
0
    }
7256
244
skip_optional_kwonly:
7257
244
    _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
7258
244
    if ((_return_value == -1) && PyErr_Occurred()) {
7259
0
        goto exit;
7260
0
    }
7261
244
    return_value = PyLong_FromLong((long)_return_value);
7262
7263
244
exit:
7264
    /* Cleanup for path */
7265
244
    path_cleanup(&path);
7266
7267
244
    return return_value;
7268
244
}
7269
7270
PyDoc_STRVAR(os_close__doc__,
7271
"close($module, /, fd)\n"
7272
"--\n"
7273
"\n"
7274
"Close a file descriptor.");
7275
7276
#define OS_CLOSE_METHODDEF    \
7277
    {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
7278
7279
static PyObject *
7280
os_close_impl(PyObject *module, int fd);
7281
7282
static PyObject *
7283
os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7284
0
{
7285
0
    PyObject *return_value = NULL;
7286
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7287
7288
0
    #define NUM_KEYWORDS 1
7289
0
    static struct {
7290
0
        PyGC_Head _this_is_not_used;
7291
0
        PyObject_VAR_HEAD
7292
0
        Py_hash_t ob_hash;
7293
0
        PyObject *ob_item[NUM_KEYWORDS];
7294
0
    } _kwtuple = {
7295
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7296
0
        .ob_hash = -1,
7297
0
        .ob_item = { &_Py_ID(fd), },
7298
0
    };
7299
0
    #undef NUM_KEYWORDS
7300
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7301
7302
    #else  // !Py_BUILD_CORE
7303
    #  define KWTUPLE NULL
7304
    #endif  // !Py_BUILD_CORE
7305
7306
0
    static const char * const _keywords[] = {"fd", NULL};
7307
0
    static _PyArg_Parser _parser = {
7308
0
        .keywords = _keywords,
7309
0
        .fname = "close",
7310
0
        .kwtuple = KWTUPLE,
7311
0
    };
7312
0
    #undef KWTUPLE
7313
0
    PyObject *argsbuf[1];
7314
0
    int fd;
7315
7316
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7317
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7318
0
    if (!args) {
7319
0
        goto exit;
7320
0
    }
7321
0
    fd = PyLong_AsInt(args[0]);
7322
0
    if (fd == -1 && PyErr_Occurred()) {
7323
0
        goto exit;
7324
0
    }
7325
0
    return_value = os_close_impl(module, fd);
7326
7327
0
exit:
7328
0
    return return_value;
7329
0
}
7330
7331
PyDoc_STRVAR(os_closerange__doc__,
7332
"closerange($module, fd_low, fd_high, /)\n"
7333
"--\n"
7334
"\n"
7335
"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
7336
7337
#define OS_CLOSERANGE_METHODDEF    \
7338
    {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__},
7339
7340
static PyObject *
7341
os_closerange_impl(PyObject *module, int fd_low, int fd_high);
7342
7343
static PyObject *
7344
os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7345
0
{
7346
0
    PyObject *return_value = NULL;
7347
0
    int fd_low;
7348
0
    int fd_high;
7349
7350
0
    if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
7351
0
        goto exit;
7352
0
    }
7353
0
    fd_low = PyLong_AsInt(args[0]);
7354
0
    if (fd_low == -1 && PyErr_Occurred()) {
7355
0
        goto exit;
7356
0
    }
7357
0
    fd_high = PyLong_AsInt(args[1]);
7358
0
    if (fd_high == -1 && PyErr_Occurred()) {
7359
0
        goto exit;
7360
0
    }
7361
0
    return_value = os_closerange_impl(module, fd_low, fd_high);
7362
7363
0
exit:
7364
0
    return return_value;
7365
0
}
7366
7367
PyDoc_STRVAR(os_dup__doc__,
7368
"dup($module, fd, /)\n"
7369
"--\n"
7370
"\n"
7371
"Return a duplicate of a file descriptor.");
7372
7373
#define OS_DUP_METHODDEF    \
7374
    {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
7375
7376
static int
7377
os_dup_impl(PyObject *module, int fd);
7378
7379
static PyObject *
7380
os_dup(PyObject *module, PyObject *arg)
7381
0
{
7382
0
    PyObject *return_value = NULL;
7383
0
    int fd;
7384
0
    int _return_value;
7385
7386
0
    fd = PyLong_AsInt(arg);
7387
0
    if (fd == -1 && PyErr_Occurred()) {
7388
0
        goto exit;
7389
0
    }
7390
0
    _return_value = os_dup_impl(module, fd);
7391
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7392
0
        goto exit;
7393
0
    }
7394
0
    return_value = PyLong_FromLong((long)_return_value);
7395
7396
0
exit:
7397
0
    return return_value;
7398
0
}
7399
7400
#if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
7401
7402
PyDoc_STRVAR(os_dup2__doc__,
7403
"dup2($module, /, fd, fd2, inheritable=True)\n"
7404
"--\n"
7405
"\n"
7406
"Duplicate file descriptor.");
7407
7408
#define OS_DUP2_METHODDEF    \
7409
    {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
7410
7411
static int
7412
os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
7413
7414
static PyObject *
7415
os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7416
0
{
7417
0
    PyObject *return_value = NULL;
7418
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7419
7420
0
    #define NUM_KEYWORDS 3
7421
0
    static struct {
7422
0
        PyGC_Head _this_is_not_used;
7423
0
        PyObject_VAR_HEAD
7424
0
        Py_hash_t ob_hash;
7425
0
        PyObject *ob_item[NUM_KEYWORDS];
7426
0
    } _kwtuple = {
7427
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7428
0
        .ob_hash = -1,
7429
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), },
7430
0
    };
7431
0
    #undef NUM_KEYWORDS
7432
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7433
7434
    #else  // !Py_BUILD_CORE
7435
    #  define KWTUPLE NULL
7436
    #endif  // !Py_BUILD_CORE
7437
7438
0
    static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
7439
0
    static _PyArg_Parser _parser = {
7440
0
        .keywords = _keywords,
7441
0
        .fname = "dup2",
7442
0
        .kwtuple = KWTUPLE,
7443
0
    };
7444
0
    #undef KWTUPLE
7445
0
    PyObject *argsbuf[3];
7446
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7447
0
    int fd;
7448
0
    int fd2;
7449
0
    int inheritable = 1;
7450
0
    int _return_value;
7451
7452
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7453
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7454
0
    if (!args) {
7455
0
        goto exit;
7456
0
    }
7457
0
    fd = PyLong_AsInt(args[0]);
7458
0
    if (fd == -1 && PyErr_Occurred()) {
7459
0
        goto exit;
7460
0
    }
7461
0
    fd2 = PyLong_AsInt(args[1]);
7462
0
    if (fd2 == -1 && PyErr_Occurred()) {
7463
0
        goto exit;
7464
0
    }
7465
0
    if (!noptargs) {
7466
0
        goto skip_optional_pos;
7467
0
    }
7468
0
    inheritable = PyObject_IsTrue(args[2]);
7469
0
    if (inheritable < 0) {
7470
0
        goto exit;
7471
0
    }
7472
0
skip_optional_pos:
7473
0
    _return_value = os_dup2_impl(module, fd, fd2, inheritable);
7474
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7475
0
        goto exit;
7476
0
    }
7477
0
    return_value = PyLong_FromLong((long)_return_value);
7478
7479
0
exit:
7480
0
    return return_value;
7481
0
}
7482
7483
#endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
7484
7485
#if defined(HAVE_LOCKF)
7486
7487
PyDoc_STRVAR(os_lockf__doc__,
7488
"lockf($module, fd, command, length, /)\n"
7489
"--\n"
7490
"\n"
7491
"Apply, test or remove a POSIX lock on an open file descriptor.\n"
7492
"\n"
7493
"  fd\n"
7494
"    An open file descriptor.\n"
7495
"  command\n"
7496
"    One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
7497
"  length\n"
7498
"    The number of bytes to lock, starting at the current position.");
7499
7500
#define OS_LOCKF_METHODDEF    \
7501
    {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__},
7502
7503
static PyObject *
7504
os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
7505
7506
static PyObject *
7507
os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7508
0
{
7509
0
    PyObject *return_value = NULL;
7510
0
    int fd;
7511
0
    int command;
7512
0
    Py_off_t length;
7513
7514
0
    if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
7515
0
        goto exit;
7516
0
    }
7517
0
    fd = PyLong_AsInt(args[0]);
7518
0
    if (fd == -1 && PyErr_Occurred()) {
7519
0
        goto exit;
7520
0
    }
7521
0
    command = PyLong_AsInt(args[1]);
7522
0
    if (command == -1 && PyErr_Occurred()) {
7523
0
        goto exit;
7524
0
    }
7525
0
    if (!Py_off_t_converter(args[2], &length)) {
7526
0
        goto exit;
7527
0
    }
7528
0
    return_value = os_lockf_impl(module, fd, command, length);
7529
7530
0
exit:
7531
0
    return return_value;
7532
0
}
7533
7534
#endif /* defined(HAVE_LOCKF) */
7535
7536
PyDoc_STRVAR(os_lseek__doc__,
7537
"lseek($module, fd, position, whence, /)\n"
7538
"--\n"
7539
"\n"
7540
"Set the position of a file descriptor.  Return the new position.\n"
7541
"\n"
7542
"  fd\n"
7543
"    An open file descriptor, as returned by os.open().\n"
7544
"  position\n"
7545
"    Position, interpreted relative to \'whence\'.\n"
7546
"  whence\n"
7547
"    The relative position to seek from. Valid values are:\n"
7548
"    - SEEK_SET: seek from the start of the file.\n"
7549
"    - SEEK_CUR: seek from the current file position.\n"
7550
"    - SEEK_END: seek from the end of the file.\n"
7551
"\n"
7552
"The return value is the number of bytes relative to the beginning of the file.");
7553
7554
#define OS_LSEEK_METHODDEF    \
7555
    {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__},
7556
7557
static Py_off_t
7558
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
7559
7560
static PyObject *
7561
os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7562
0
{
7563
0
    PyObject *return_value = NULL;
7564
0
    int fd;
7565
0
    Py_off_t position;
7566
0
    int how;
7567
0
    Py_off_t _return_value;
7568
7569
0
    if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
7570
0
        goto exit;
7571
0
    }
7572
0
    fd = PyLong_AsInt(args[0]);
7573
0
    if (fd == -1 && PyErr_Occurred()) {
7574
0
        goto exit;
7575
0
    }
7576
0
    if (!Py_off_t_converter(args[1], &position)) {
7577
0
        goto exit;
7578
0
    }
7579
0
    how = PyLong_AsInt(args[2]);
7580
0
    if (how == -1 && PyErr_Occurred()) {
7581
0
        goto exit;
7582
0
    }
7583
0
    _return_value = os_lseek_impl(module, fd, position, how);
7584
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7585
0
        goto exit;
7586
0
    }
7587
0
    return_value = PyLong_FromPy_off_t(_return_value);
7588
7589
0
exit:
7590
0
    return return_value;
7591
0
}
7592
7593
PyDoc_STRVAR(os_read__doc__,
7594
"read($module, fd, length, /)\n"
7595
"--\n"
7596
"\n"
7597
"Read from a file descriptor.  Returns a bytes object.");
7598
7599
#define OS_READ_METHODDEF    \
7600
    {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__},
7601
7602
static PyObject *
7603
os_read_impl(PyObject *module, int fd, Py_ssize_t length);
7604
7605
static PyObject *
7606
os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7607
0
{
7608
0
    PyObject *return_value = NULL;
7609
0
    int fd;
7610
0
    Py_ssize_t length;
7611
7612
0
    if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
7613
0
        goto exit;
7614
0
    }
7615
0
    fd = PyLong_AsInt(args[0]);
7616
0
    if (fd == -1 && PyErr_Occurred()) {
7617
0
        goto exit;
7618
0
    }
7619
0
    {
7620
0
        Py_ssize_t ival = -1;
7621
0
        PyObject *iobj = _PyNumber_Index(args[1]);
7622
0
        if (iobj != NULL) {
7623
0
            ival = PyLong_AsSsize_t(iobj);
7624
0
            Py_DECREF(iobj);
7625
0
        }
7626
0
        if (ival == -1 && PyErr_Occurred()) {
7627
0
            goto exit;
7628
0
        }
7629
0
        length = ival;
7630
0
    }
7631
0
    return_value = os_read_impl(module, fd, length);
7632
7633
0
exit:
7634
0
    return return_value;
7635
0
}
7636
7637
PyDoc_STRVAR(os_readinto__doc__,
7638
"readinto($module, fd, buffer, /)\n"
7639
"--\n"
7640
"\n"
7641
"Read into a buffer object from a file descriptor.\n"
7642
"\n"
7643
"The buffer should be mutable and bytes-like. On success, returns the number of\n"
7644
"bytes read. Less bytes may be read than the size of the buffer. The underlying\n"
7645
"system call will be retried when interrupted by a signal, unless the signal\n"
7646
"handler raises an exception. Other errors will not be retried and an error will\n"
7647
"be raised.\n"
7648
"\n"
7649
"Returns 0 if *fd* is at end of file or if the provided *buffer* has length 0\n"
7650
"(which can be used to check for errors without reading data). Never returns\n"
7651
"negative.");
7652
7653
#define OS_READINTO_METHODDEF    \
7654
    {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__},
7655
7656
static Py_ssize_t
7657
os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer);
7658
7659
static PyObject *
7660
os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7661
0
{
7662
0
    PyObject *return_value = NULL;
7663
0
    int fd;
7664
0
    Py_buffer buffer = {NULL, NULL};
7665
0
    Py_ssize_t _return_value;
7666
7667
0
    if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) {
7668
0
        goto exit;
7669
0
    }
7670
0
    fd = PyLong_AsInt(args[0]);
7671
0
    if (fd == -1 && PyErr_Occurred()) {
7672
0
        goto exit;
7673
0
    }
7674
0
    if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) {
7675
0
        _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]);
7676
0
        goto exit;
7677
0
    }
7678
0
    _return_value = os_readinto_impl(module, fd, &buffer);
7679
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7680
0
        goto exit;
7681
0
    }
7682
0
    return_value = PyLong_FromSsize_t(_return_value);
7683
7684
0
exit:
7685
    /* Cleanup for buffer */
7686
0
    if (buffer.obj) {
7687
0
       PyBuffer_Release(&buffer);
7688
0
    }
7689
7690
0
    return return_value;
7691
0
}
7692
7693
#if defined(HAVE_READV)
7694
7695
PyDoc_STRVAR(os_readv__doc__,
7696
"readv($module, fd, buffers, /)\n"
7697
"--\n"
7698
"\n"
7699
"Read from a file descriptor fd into an iterable of buffers.\n"
7700
"\n"
7701
"The buffers should be mutable buffers accepting bytes.\n"
7702
"readv will transfer data into each buffer until it is full\n"
7703
"and then move on to the next buffer in the sequence to hold\n"
7704
"the rest of the data.\n"
7705
"\n"
7706
"readv returns the total number of bytes read,\n"
7707
"which may be less than the total capacity of all the buffers.");
7708
7709
#define OS_READV_METHODDEF    \
7710
    {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__},
7711
7712
static Py_ssize_t
7713
os_readv_impl(PyObject *module, int fd, PyObject *buffers);
7714
7715
static PyObject *
7716
os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7717
0
{
7718
0
    PyObject *return_value = NULL;
7719
0
    int fd;
7720
0
    PyObject *buffers;
7721
0
    Py_ssize_t _return_value;
7722
7723
0
    if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
7724
0
        goto exit;
7725
0
    }
7726
0
    fd = PyLong_AsInt(args[0]);
7727
0
    if (fd == -1 && PyErr_Occurred()) {
7728
0
        goto exit;
7729
0
    }
7730
0
    buffers = args[1];
7731
0
    _return_value = os_readv_impl(module, fd, buffers);
7732
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7733
0
        goto exit;
7734
0
    }
7735
0
    return_value = PyLong_FromSsize_t(_return_value);
7736
7737
0
exit:
7738
0
    return return_value;
7739
0
}
7740
7741
#endif /* defined(HAVE_READV) */
7742
7743
#if defined(HAVE_PREAD)
7744
7745
PyDoc_STRVAR(os_pread__doc__,
7746
"pread($module, fd, length, offset, /)\n"
7747
"--\n"
7748
"\n"
7749
"Read a number of bytes from a file descriptor starting at a particular offset.\n"
7750
"\n"
7751
"Read length bytes from file descriptor fd, starting at offset bytes from\n"
7752
"the beginning of the file.  The file offset remains unchanged.");
7753
7754
#define OS_PREAD_METHODDEF    \
7755
    {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__},
7756
7757
static PyObject *
7758
os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset);
7759
7760
static PyObject *
7761
os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7762
0
{
7763
0
    PyObject *return_value = NULL;
7764
0
    int fd;
7765
0
    Py_ssize_t length;
7766
0
    Py_off_t offset;
7767
7768
0
    if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
7769
0
        goto exit;
7770
0
    }
7771
0
    fd = PyLong_AsInt(args[0]);
7772
0
    if (fd == -1 && PyErr_Occurred()) {
7773
0
        goto exit;
7774
0
    }
7775
0
    {
7776
0
        Py_ssize_t ival = -1;
7777
0
        PyObject *iobj = _PyNumber_Index(args[1]);
7778
0
        if (iobj != NULL) {
7779
0
            ival = PyLong_AsSsize_t(iobj);
7780
0
            Py_DECREF(iobj);
7781
0
        }
7782
0
        if (ival == -1 && PyErr_Occurred()) {
7783
0
            goto exit;
7784
0
        }
7785
0
        length = ival;
7786
0
    }
7787
0
    if (!Py_off_t_converter(args[2], &offset)) {
7788
0
        goto exit;
7789
0
    }
7790
0
    return_value = os_pread_impl(module, fd, length, offset);
7791
7792
0
exit:
7793
0
    return return_value;
7794
0
}
7795
7796
#endif /* defined(HAVE_PREAD) */
7797
7798
#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
7799
7800
PyDoc_STRVAR(os_preadv__doc__,
7801
"preadv($module, fd, buffers, offset, flags=0, /)\n"
7802
"--\n"
7803
"\n"
7804
"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
7805
"\n"
7806
"Combines the functionality of readv() and pread(). As readv(), it will\n"
7807
"transfer data into each buffer until it is full and then move on to the next\n"
7808
"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
7809
"specifies the file offset at which the input operation is to be performed. It\n"
7810
"will return the total number of bytes read (which can be less than the total\n"
7811
"capacity of all the objects).\n"
7812
"\n"
7813
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
7814
"\n"
7815
"- RWF_HIPRI\n"
7816
"- RWF_NOWAIT\n"
7817
"- RWF_DONTCACHE\n"
7818
"\n"
7819
"Using non-zero flags requires Linux 4.6 or newer.");
7820
7821
#define OS_PREADV_METHODDEF    \
7822
    {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__},
7823
7824
static Py_ssize_t
7825
os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
7826
               int flags);
7827
7828
static PyObject *
7829
os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7830
0
{
7831
0
    PyObject *return_value = NULL;
7832
0
    int fd;
7833
0
    PyObject *buffers;
7834
0
    Py_off_t offset;
7835
0
    int flags = 0;
7836
0
    Py_ssize_t _return_value;
7837
7838
0
    if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
7839
0
        goto exit;
7840
0
    }
7841
0
    fd = PyLong_AsInt(args[0]);
7842
0
    if (fd == -1 && PyErr_Occurred()) {
7843
0
        goto exit;
7844
0
    }
7845
0
    buffers = args[1];
7846
0
    if (!Py_off_t_converter(args[2], &offset)) {
7847
0
        goto exit;
7848
0
    }
7849
0
    if (nargs < 4) {
7850
0
        goto skip_optional;
7851
0
    }
7852
0
    flags = PyLong_AsInt(args[3]);
7853
0
    if (flags == -1 && PyErr_Occurred()) {
7854
0
        goto exit;
7855
0
    }
7856
0
skip_optional:
7857
0
    _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
7858
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7859
0
        goto exit;
7860
0
    }
7861
0
    return_value = PyLong_FromSsize_t(_return_value);
7862
7863
0
exit:
7864
0
    return return_value;
7865
0
}
7866
7867
#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
7868
7869
PyDoc_STRVAR(os_write__doc__,
7870
"write($module, fd, data, /)\n"
7871
"--\n"
7872
"\n"
7873
"Write a bytes object to a file descriptor.");
7874
7875
#define OS_WRITE_METHODDEF    \
7876
    {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__},
7877
7878
static Py_ssize_t
7879
os_write_impl(PyObject *module, int fd, Py_buffer *data);
7880
7881
static PyObject *
7882
os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7883
0
{
7884
0
    PyObject *return_value = NULL;
7885
0
    int fd;
7886
0
    Py_buffer data = {NULL, NULL};
7887
0
    Py_ssize_t _return_value;
7888
7889
0
    if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
7890
0
        goto exit;
7891
0
    }
7892
0
    fd = PyLong_AsInt(args[0]);
7893
0
    if (fd == -1 && PyErr_Occurred()) {
7894
0
        goto exit;
7895
0
    }
7896
0
    if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
7897
0
        goto exit;
7898
0
    }
7899
0
    _return_value = os_write_impl(module, fd, &data);
7900
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7901
0
        goto exit;
7902
0
    }
7903
0
    return_value = PyLong_FromSsize_t(_return_value);
7904
7905
0
exit:
7906
    /* Cleanup for data */
7907
0
    if (data.obj) {
7908
0
       PyBuffer_Release(&data);
7909
0
    }
7910
7911
0
    return return_value;
7912
0
}
7913
7914
#if defined(HAVE_SENDFILE) && defined(__APPLE__)
7915
7916
PyDoc_STRVAR(os_sendfile__doc__,
7917
"sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
7918
"         trailers=(), flags=0)\n"
7919
"--\n"
7920
"\n"
7921
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
7922
7923
#define OS_SENDFILE_METHODDEF    \
7924
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
7925
7926
static PyObject *
7927
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
7928
                 Py_off_t sbytes, PyObject *headers, PyObject *trailers,
7929
                 int flags);
7930
7931
static PyObject *
7932
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7933
{
7934
    PyObject *return_value = NULL;
7935
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7936
7937
    #define NUM_KEYWORDS 7
7938
    static struct {
7939
        PyGC_Head _this_is_not_used;
7940
        PyObject_VAR_HEAD
7941
        Py_hash_t ob_hash;
7942
        PyObject *ob_item[NUM_KEYWORDS];
7943
    } _kwtuple = {
7944
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7945
        .ob_hash = -1,
7946
        .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), },
7947
    };
7948
    #undef NUM_KEYWORDS
7949
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7950
7951
    #else  // !Py_BUILD_CORE
7952
    #  define KWTUPLE NULL
7953
    #endif  // !Py_BUILD_CORE
7954
7955
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
7956
    static _PyArg_Parser _parser = {
7957
        .keywords = _keywords,
7958
        .fname = "sendfile",
7959
        .kwtuple = KWTUPLE,
7960
    };
7961
    #undef KWTUPLE
7962
    PyObject *argsbuf[7];
7963
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
7964
    int out_fd;
7965
    int in_fd;
7966
    Py_off_t offset;
7967
    Py_off_t sbytes;
7968
    PyObject *headers = NULL;
7969
    PyObject *trailers = NULL;
7970
    int flags = 0;
7971
7972
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7973
            /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7974
    if (!args) {
7975
        goto exit;
7976
    }
7977
    out_fd = PyLong_AsInt(args[0]);
7978
    if (out_fd == -1 && PyErr_Occurred()) {
7979
        goto exit;
7980
    }
7981
    in_fd = PyLong_AsInt(args[1]);
7982
    if (in_fd == -1 && PyErr_Occurred()) {
7983
        goto exit;
7984
    }
7985
    if (!Py_off_t_converter(args[2], &offset)) {
7986
        goto exit;
7987
    }
7988
    if (!Py_off_t_converter(args[3], &sbytes)) {
7989
        goto exit;
7990
    }
7991
    if (!noptargs) {
7992
        goto skip_optional_pos;
7993
    }
7994
    if (args[4]) {
7995
        headers = args[4];
7996
        if (!--noptargs) {
7997
            goto skip_optional_pos;
7998
        }
7999
    }
8000
    if (args[5]) {
8001
        trailers = args[5];
8002
        if (!--noptargs) {
8003
            goto skip_optional_pos;
8004
        }
8005
    }
8006
    flags = PyLong_AsInt(args[6]);
8007
    if (flags == -1 && PyErr_Occurred()) {
8008
        goto exit;
8009
    }
8010
skip_optional_pos:
8011
    return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags);
8012
8013
exit:
8014
    return return_value;
8015
}
8016
8017
#endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */
8018
8019
#if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__))
8020
8021
PyDoc_STRVAR(os_sendfile__doc__,
8022
"sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
8023
"         trailers=(), flags=0)\n"
8024
"--\n"
8025
"\n"
8026
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8027
8028
#define OS_SENDFILE_METHODDEF    \
8029
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8030
8031
static PyObject *
8032
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
8033
                 Py_ssize_t count, PyObject *headers, PyObject *trailers,
8034
                 int flags);
8035
8036
static PyObject *
8037
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8038
{
8039
    PyObject *return_value = NULL;
8040
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8041
8042
    #define NUM_KEYWORDS 7
8043
    static struct {
8044
        PyGC_Head _this_is_not_used;
8045
        PyObject_VAR_HEAD
8046
        Py_hash_t ob_hash;
8047
        PyObject *ob_item[NUM_KEYWORDS];
8048
    } _kwtuple = {
8049
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8050
        .ob_hash = -1,
8051
        .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), },
8052
    };
8053
    #undef NUM_KEYWORDS
8054
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8055
8056
    #else  // !Py_BUILD_CORE
8057
    #  define KWTUPLE NULL
8058
    #endif  // !Py_BUILD_CORE
8059
8060
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
8061
    static _PyArg_Parser _parser = {
8062
        .keywords = _keywords,
8063
        .fname = "sendfile",
8064
        .kwtuple = KWTUPLE,
8065
    };
8066
    #undef KWTUPLE
8067
    PyObject *argsbuf[7];
8068
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
8069
    int out_fd;
8070
    int in_fd;
8071
    Py_off_t offset;
8072
    Py_ssize_t count;
8073
    PyObject *headers = NULL;
8074
    PyObject *trailers = NULL;
8075
    int flags = 0;
8076
8077
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8078
            /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8079
    if (!args) {
8080
        goto exit;
8081
    }
8082
    out_fd = PyLong_AsInt(args[0]);
8083
    if (out_fd == -1 && PyErr_Occurred()) {
8084
        goto exit;
8085
    }
8086
    in_fd = PyLong_AsInt(args[1]);
8087
    if (in_fd == -1 && PyErr_Occurred()) {
8088
        goto exit;
8089
    }
8090
    if (!Py_off_t_converter(args[2], &offset)) {
8091
        goto exit;
8092
    }
8093
    {
8094
        Py_ssize_t ival = -1;
8095
        PyObject *iobj = _PyNumber_Index(args[3]);
8096
        if (iobj != NULL) {
8097
            ival = PyLong_AsSsize_t(iobj);
8098
            Py_DECREF(iobj);
8099
        }
8100
        if (ival == -1 && PyErr_Occurred()) {
8101
            goto exit;
8102
        }
8103
        count = ival;
8104
        if (count < 0) {
8105
            PyErr_SetString(PyExc_ValueError,
8106
                            "count cannot be negative");
8107
            goto exit;
8108
        }
8109
    }
8110
    if (!noptargs) {
8111
        goto skip_optional_pos;
8112
    }
8113
    if (args[4]) {
8114
        headers = args[4];
8115
        if (!--noptargs) {
8116
            goto skip_optional_pos;
8117
        }
8118
    }
8119
    if (args[5]) {
8120
        trailers = args[5];
8121
        if (!--noptargs) {
8122
            goto skip_optional_pos;
8123
        }
8124
    }
8125
    flags = PyLong_AsInt(args[6]);
8126
    if (flags == -1 && PyErr_Occurred()) {
8127
        goto exit;
8128
    }
8129
skip_optional_pos:
8130
    return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags);
8131
8132
exit:
8133
    return return_value;
8134
}
8135
8136
#endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */
8137
8138
#if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__))
8139
8140
PyDoc_STRVAR(os_sendfile__doc__,
8141
"sendfile($module, /, out_fd, in_fd, offset, count)\n"
8142
"--\n"
8143
"\n"
8144
"Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8145
8146
#define OS_SENDFILE_METHODDEF    \
8147
    {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8148
8149
static PyObject *
8150
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
8151
                 Py_ssize_t count);
8152
8153
static PyObject *
8154
os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8155
0
{
8156
0
    PyObject *return_value = NULL;
8157
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8158
8159
0
    #define NUM_KEYWORDS 4
8160
0
    static struct {
8161
0
        PyGC_Head _this_is_not_used;
8162
0
        PyObject_VAR_HEAD
8163
0
        Py_hash_t ob_hash;
8164
0
        PyObject *ob_item[NUM_KEYWORDS];
8165
0
    } _kwtuple = {
8166
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8167
0
        .ob_hash = -1,
8168
0
        .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), },
8169
0
    };
8170
0
    #undef NUM_KEYWORDS
8171
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8172
8173
    #else  // !Py_BUILD_CORE
8174
    #  define KWTUPLE NULL
8175
    #endif  // !Py_BUILD_CORE
8176
8177
0
    static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL};
8178
0
    static _PyArg_Parser _parser = {
8179
0
        .keywords = _keywords,
8180
0
        .fname = "sendfile",
8181
0
        .kwtuple = KWTUPLE,
8182
0
    };
8183
0
    #undef KWTUPLE
8184
0
    PyObject *argsbuf[4];
8185
0
    int out_fd;
8186
0
    int in_fd;
8187
0
    PyObject *offobj;
8188
0
    Py_ssize_t count;
8189
8190
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8191
0
            /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8192
0
    if (!args) {
8193
0
        goto exit;
8194
0
    }
8195
0
    out_fd = PyLong_AsInt(args[0]);
8196
0
    if (out_fd == -1 && PyErr_Occurred()) {
8197
0
        goto exit;
8198
0
    }
8199
0
    in_fd = PyLong_AsInt(args[1]);
8200
0
    if (in_fd == -1 && PyErr_Occurred()) {
8201
0
        goto exit;
8202
0
    }
8203
0
    offobj = args[2];
8204
0
    {
8205
0
        Py_ssize_t ival = -1;
8206
0
        PyObject *iobj = _PyNumber_Index(args[3]);
8207
0
        if (iobj != NULL) {
8208
0
            ival = PyLong_AsSsize_t(iobj);
8209
0
            Py_DECREF(iobj);
8210
0
        }
8211
0
        if (ival == -1 && PyErr_Occurred()) {
8212
0
            goto exit;
8213
0
        }
8214
0
        count = ival;
8215
0
        if (count < 0) {
8216
0
            PyErr_SetString(PyExc_ValueError,
8217
0
                            "count cannot be negative");
8218
0
            goto exit;
8219
0
        }
8220
0
    }
8221
0
    return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count);
8222
8223
0
exit:
8224
0
    return return_value;
8225
0
}
8226
8227
#endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */
8228
8229
#if defined(__APPLE__)
8230
8231
PyDoc_STRVAR(os__fcopyfile__doc__,
8232
"_fcopyfile($module, in_fd, out_fd, flags, /)\n"
8233
"--\n"
8234
"\n"
8235
"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
8236
8237
#define OS__FCOPYFILE_METHODDEF    \
8238
    {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__},
8239
8240
static PyObject *
8241
os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags);
8242
8243
static PyObject *
8244
os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8245
{
8246
    PyObject *return_value = NULL;
8247
    int in_fd;
8248
    int out_fd;
8249
    int flags;
8250
8251
    if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
8252
        goto exit;
8253
    }
8254
    in_fd = PyLong_AsInt(args[0]);
8255
    if (in_fd == -1 && PyErr_Occurred()) {
8256
        goto exit;
8257
    }
8258
    out_fd = PyLong_AsInt(args[1]);
8259
    if (out_fd == -1 && PyErr_Occurred()) {
8260
        goto exit;
8261
    }
8262
    flags = PyLong_AsInt(args[2]);
8263
    if (flags == -1 && PyErr_Occurred()) {
8264
        goto exit;
8265
    }
8266
    return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags);
8267
8268
exit:
8269
    return return_value;
8270
}
8271
8272
#endif /* defined(__APPLE__) */
8273
8274
PyDoc_STRVAR(os_fstat__doc__,
8275
"fstat($module, /, fd)\n"
8276
"--\n"
8277
"\n"
8278
"Perform a stat system call on the given file descriptor.\n"
8279
"\n"
8280
"Like stat(), but for an open file descriptor.\n"
8281
"Equivalent to os.stat(fd).");
8282
8283
#define OS_FSTAT_METHODDEF    \
8284
    {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
8285
8286
static PyObject *
8287
os_fstat_impl(PyObject *module, int fd);
8288
8289
static PyObject *
8290
os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8291
0
{
8292
0
    PyObject *return_value = NULL;
8293
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8294
8295
0
    #define NUM_KEYWORDS 1
8296
0
    static struct {
8297
0
        PyGC_Head _this_is_not_used;
8298
0
        PyObject_VAR_HEAD
8299
0
        Py_hash_t ob_hash;
8300
0
        PyObject *ob_item[NUM_KEYWORDS];
8301
0
    } _kwtuple = {
8302
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8303
0
        .ob_hash = -1,
8304
0
        .ob_item = { &_Py_ID(fd), },
8305
0
    };
8306
0
    #undef NUM_KEYWORDS
8307
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8308
8309
    #else  // !Py_BUILD_CORE
8310
    #  define KWTUPLE NULL
8311
    #endif  // !Py_BUILD_CORE
8312
8313
0
    static const char * const _keywords[] = {"fd", NULL};
8314
0
    static _PyArg_Parser _parser = {
8315
0
        .keywords = _keywords,
8316
0
        .fname = "fstat",
8317
0
        .kwtuple = KWTUPLE,
8318
0
    };
8319
0
    #undef KWTUPLE
8320
0
    PyObject *argsbuf[1];
8321
0
    int fd;
8322
8323
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8324
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8325
0
    if (!args) {
8326
0
        goto exit;
8327
0
    }
8328
0
    fd = PyLong_AsInt(args[0]);
8329
0
    if (fd == -1 && PyErr_Occurred()) {
8330
0
        goto exit;
8331
0
    }
8332
0
    return_value = os_fstat_impl(module, fd);
8333
8334
0
exit:
8335
0
    return return_value;
8336
0
}
8337
8338
PyDoc_STRVAR(os_isatty__doc__,
8339
"isatty($module, fd, /)\n"
8340
"--\n"
8341
"\n"
8342
"Return True if the fd is connected to a terminal.\n"
8343
"\n"
8344
"Return True if the file descriptor is an open file descriptor\n"
8345
"connected to the slave end of a terminal.");
8346
8347
#define OS_ISATTY_METHODDEF    \
8348
    {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
8349
8350
static int
8351
os_isatty_impl(PyObject *module, int fd);
8352
8353
static PyObject *
8354
os_isatty(PyObject *module, PyObject *arg)
8355
0
{
8356
0
    PyObject *return_value = NULL;
8357
0
    int fd;
8358
0
    int _return_value;
8359
8360
0
    fd = PyLong_AsInt(arg);
8361
0
    if (fd == -1 && PyErr_Occurred()) {
8362
0
        goto exit;
8363
0
    }
8364
0
    _return_value = os_isatty_impl(module, fd);
8365
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8366
0
        goto exit;
8367
0
    }
8368
0
    return_value = PyBool_FromLong((long)_return_value);
8369
8370
0
exit:
8371
0
    return return_value;
8372
0
}
8373
8374
#if defined(HAVE_PIPE)
8375
8376
PyDoc_STRVAR(os_pipe__doc__,
8377
"pipe($module, /)\n"
8378
"--\n"
8379
"\n"
8380
"Create a pipe.\n"
8381
"\n"
8382
"Returns a tuple of two file descriptors:\n"
8383
"  (read_fd, write_fd)");
8384
8385
#define OS_PIPE_METHODDEF    \
8386
    {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
8387
8388
static PyObject *
8389
os_pipe_impl(PyObject *module);
8390
8391
static PyObject *
8392
os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
8393
0
{
8394
0
    return os_pipe_impl(module);
8395
0
}
8396
8397
#endif /* defined(HAVE_PIPE) */
8398
8399
#if defined(HAVE_PIPE2)
8400
8401
PyDoc_STRVAR(os_pipe2__doc__,
8402
"pipe2($module, flags, /)\n"
8403
"--\n"
8404
"\n"
8405
"Create a pipe with flags set atomically.\n"
8406
"\n"
8407
"Returns a tuple of two file descriptors:\n"
8408
"  (read_fd, write_fd)\n"
8409
"\n"
8410
"flags can be constructed by ORing together one or more of these values:\n"
8411
"O_NONBLOCK, O_CLOEXEC.");
8412
8413
#define OS_PIPE2_METHODDEF    \
8414
    {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
8415
8416
static PyObject *
8417
os_pipe2_impl(PyObject *module, int flags);
8418
8419
static PyObject *
8420
os_pipe2(PyObject *module, PyObject *arg)
8421
0
{
8422
0
    PyObject *return_value = NULL;
8423
0
    int flags;
8424
8425
0
    flags = PyLong_AsInt(arg);
8426
0
    if (flags == -1 && PyErr_Occurred()) {
8427
0
        goto exit;
8428
0
    }
8429
0
    return_value = os_pipe2_impl(module, flags);
8430
8431
0
exit:
8432
0
    return return_value;
8433
0
}
8434
8435
#endif /* defined(HAVE_PIPE2) */
8436
8437
#if defined(HAVE_WRITEV)
8438
8439
PyDoc_STRVAR(os_writev__doc__,
8440
"writev($module, fd, buffers, /)\n"
8441
"--\n"
8442
"\n"
8443
"Iterate over buffers, and write the contents of each to a file descriptor.\n"
8444
"\n"
8445
"Returns the total number of bytes written.\n"
8446
"buffers must be a sequence of bytes-like objects.");
8447
8448
#define OS_WRITEV_METHODDEF    \
8449
    {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__},
8450
8451
static Py_ssize_t
8452
os_writev_impl(PyObject *module, int fd, PyObject *buffers);
8453
8454
static PyObject *
8455
os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8456
0
{
8457
0
    PyObject *return_value = NULL;
8458
0
    int fd;
8459
0
    PyObject *buffers;
8460
0
    Py_ssize_t _return_value;
8461
8462
0
    if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
8463
0
        goto exit;
8464
0
    }
8465
0
    fd = PyLong_AsInt(args[0]);
8466
0
    if (fd == -1 && PyErr_Occurred()) {
8467
0
        goto exit;
8468
0
    }
8469
0
    buffers = args[1];
8470
0
    _return_value = os_writev_impl(module, fd, buffers);
8471
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8472
0
        goto exit;
8473
0
    }
8474
0
    return_value = PyLong_FromSsize_t(_return_value);
8475
8476
0
exit:
8477
0
    return return_value;
8478
0
}
8479
8480
#endif /* defined(HAVE_WRITEV) */
8481
8482
#if defined(HAVE_PWRITE)
8483
8484
PyDoc_STRVAR(os_pwrite__doc__,
8485
"pwrite($module, fd, buffer, offset, /)\n"
8486
"--\n"
8487
"\n"
8488
"Write bytes to a file descriptor starting at a particular offset.\n"
8489
"\n"
8490
"Write buffer to fd, starting at offset bytes from the beginning of\n"
8491
"the file.  Returns the number of bytes written.  Does not change the\n"
8492
"current file offset.");
8493
8494
#define OS_PWRITE_METHODDEF    \
8495
    {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__},
8496
8497
static Py_ssize_t
8498
os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
8499
8500
static PyObject *
8501
os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8502
0
{
8503
0
    PyObject *return_value = NULL;
8504
0
    int fd;
8505
0
    Py_buffer buffer = {NULL, NULL};
8506
0
    Py_off_t offset;
8507
0
    Py_ssize_t _return_value;
8508
8509
0
    if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
8510
0
        goto exit;
8511
0
    }
8512
0
    fd = PyLong_AsInt(args[0]);
8513
0
    if (fd == -1 && PyErr_Occurred()) {
8514
0
        goto exit;
8515
0
    }
8516
0
    if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
8517
0
        goto exit;
8518
0
    }
8519
0
    if (!Py_off_t_converter(args[2], &offset)) {
8520
0
        goto exit;
8521
0
    }
8522
0
    _return_value = os_pwrite_impl(module, fd, &buffer, offset);
8523
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8524
0
        goto exit;
8525
0
    }
8526
0
    return_value = PyLong_FromSsize_t(_return_value);
8527
8528
0
exit:
8529
    /* Cleanup for buffer */
8530
0
    if (buffer.obj) {
8531
0
       PyBuffer_Release(&buffer);
8532
0
    }
8533
8534
0
    return return_value;
8535
0
}
8536
8537
#endif /* defined(HAVE_PWRITE) */
8538
8539
#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
8540
8541
PyDoc_STRVAR(os_pwritev__doc__,
8542
"pwritev($module, fd, buffers, offset, flags=0, /)\n"
8543
"--\n"
8544
"\n"
8545
"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
8546
"\n"
8547
"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
8548
"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
8549
"buffer is written before proceeding to second, and so on. The operating system may\n"
8550
"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
8551
"This function writes the contents of each object to the file descriptor and returns\n"
8552
"the total number of bytes written.\n"
8553
"\n"
8554
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
8555
"\n"
8556
"- RWF_DSYNC\n"
8557
"- RWF_SYNC\n"
8558
"- RWF_APPEND\n"
8559
"- RWF_DONTCACHE\n"
8560
"\n"
8561
"Using non-zero flags requires Linux 4.7 or newer.");
8562
8563
#define OS_PWRITEV_METHODDEF    \
8564
    {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__},
8565
8566
static Py_ssize_t
8567
os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
8568
                int flags);
8569
8570
static PyObject *
8571
os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8572
0
{
8573
0
    PyObject *return_value = NULL;
8574
0
    int fd;
8575
0
    PyObject *buffers;
8576
0
    Py_off_t offset;
8577
0
    int flags = 0;
8578
0
    Py_ssize_t _return_value;
8579
8580
0
    if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
8581
0
        goto exit;
8582
0
    }
8583
0
    fd = PyLong_AsInt(args[0]);
8584
0
    if (fd == -1 && PyErr_Occurred()) {
8585
0
        goto exit;
8586
0
    }
8587
0
    buffers = args[1];
8588
0
    if (!Py_off_t_converter(args[2], &offset)) {
8589
0
        goto exit;
8590
0
    }
8591
0
    if (nargs < 4) {
8592
0
        goto skip_optional;
8593
0
    }
8594
0
    flags = PyLong_AsInt(args[3]);
8595
0
    if (flags == -1 && PyErr_Occurred()) {
8596
0
        goto exit;
8597
0
    }
8598
0
skip_optional:
8599
0
    _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
8600
0
    if ((_return_value == -1) && PyErr_Occurred()) {
8601
0
        goto exit;
8602
0
    }
8603
0
    return_value = PyLong_FromSsize_t(_return_value);
8604
8605
0
exit:
8606
0
    return return_value;
8607
0
}
8608
8609
#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
8610
8611
#if defined(HAVE_COPY_FILE_RANGE)
8612
8613
PyDoc_STRVAR(os_copy_file_range__doc__,
8614
"copy_file_range($module, /, src, dst, count, offset_src=None,\n"
8615
"                offset_dst=None)\n"
8616
"--\n"
8617
"\n"
8618
"Copy count bytes from one file descriptor to another.\n"
8619
"\n"
8620
"  src\n"
8621
"    Source file descriptor.\n"
8622
"  dst\n"
8623
"    Destination file descriptor.\n"
8624
"  count\n"
8625
"    Number of bytes to copy.\n"
8626
"  offset_src\n"
8627
"    Starting offset in src.\n"
8628
"  offset_dst\n"
8629
"    Starting offset in dst.\n"
8630
"\n"
8631
"If offset_src is None, then src is read from the current position;\n"
8632
"respectively for offset_dst.");
8633
8634
#define OS_COPY_FILE_RANGE_METHODDEF    \
8635
    {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__},
8636
8637
static PyObject *
8638
os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count,
8639
                        PyObject *offset_src, PyObject *offset_dst);
8640
8641
static PyObject *
8642
os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8643
0
{
8644
0
    PyObject *return_value = NULL;
8645
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8646
8647
0
    #define NUM_KEYWORDS 5
8648
0
    static struct {
8649
0
        PyGC_Head _this_is_not_used;
8650
0
        PyObject_VAR_HEAD
8651
0
        Py_hash_t ob_hash;
8652
0
        PyObject *ob_item[NUM_KEYWORDS];
8653
0
    } _kwtuple = {
8654
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8655
0
        .ob_hash = -1,
8656
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), },
8657
0
    };
8658
0
    #undef NUM_KEYWORDS
8659
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8660
8661
    #else  // !Py_BUILD_CORE
8662
    #  define KWTUPLE NULL
8663
    #endif  // !Py_BUILD_CORE
8664
8665
0
    static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL};
8666
0
    static _PyArg_Parser _parser = {
8667
0
        .keywords = _keywords,
8668
0
        .fname = "copy_file_range",
8669
0
        .kwtuple = KWTUPLE,
8670
0
    };
8671
0
    #undef KWTUPLE
8672
0
    PyObject *argsbuf[5];
8673
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
8674
0
    int src;
8675
0
    int dst;
8676
0
    Py_ssize_t count;
8677
0
    PyObject *offset_src = Py_None;
8678
0
    PyObject *offset_dst = Py_None;
8679
8680
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8681
0
            /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8682
0
    if (!args) {
8683
0
        goto exit;
8684
0
    }
8685
0
    src = PyLong_AsInt(args[0]);
8686
0
    if (src == -1 && PyErr_Occurred()) {
8687
0
        goto exit;
8688
0
    }
8689
0
    dst = PyLong_AsInt(args[1]);
8690
0
    if (dst == -1 && PyErr_Occurred()) {
8691
0
        goto exit;
8692
0
    }
8693
0
    {
8694
0
        Py_ssize_t ival = -1;
8695
0
        PyObject *iobj = _PyNumber_Index(args[2]);
8696
0
        if (iobj != NULL) {
8697
0
            ival = PyLong_AsSsize_t(iobj);
8698
0
            Py_DECREF(iobj);
8699
0
        }
8700
0
        if (ival == -1 && PyErr_Occurred()) {
8701
0
            goto exit;
8702
0
        }
8703
0
        count = ival;
8704
0
        if (count < 0) {
8705
0
            PyErr_SetString(PyExc_ValueError,
8706
0
                            "count cannot be negative");
8707
0
            goto exit;
8708
0
        }
8709
0
    }
8710
0
    if (!noptargs) {
8711
0
        goto skip_optional_pos;
8712
0
    }
8713
0
    if (args[3]) {
8714
0
        offset_src = args[3];
8715
0
        if (!--noptargs) {
8716
0
            goto skip_optional_pos;
8717
0
        }
8718
0
    }
8719
0
    offset_dst = args[4];
8720
0
skip_optional_pos:
8721
0
    return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst);
8722
8723
0
exit:
8724
0
    return return_value;
8725
0
}
8726
8727
#endif /* defined(HAVE_COPY_FILE_RANGE) */
8728
8729
#if ((defined(HAVE_SPLICE) && !defined(_AIX)))
8730
8731
PyDoc_STRVAR(os_splice__doc__,
8732
"splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n"
8733
"       flags=0)\n"
8734
"--\n"
8735
"\n"
8736
"Transfer count bytes from one pipe to a descriptor or vice versa.\n"
8737
"\n"
8738
"  src\n"
8739
"    Source file descriptor.\n"
8740
"  dst\n"
8741
"    Destination file descriptor.\n"
8742
"  count\n"
8743
"    Number of bytes to copy.\n"
8744
"  offset_src\n"
8745
"    Starting offset in src.\n"
8746
"  offset_dst\n"
8747
"    Starting offset in dst.\n"
8748
"  flags\n"
8749
"    Flags to modify the semantics of the call.\n"
8750
"\n"
8751
"If offset_src is None, then src is read from the current position;\n"
8752
"respectively for offset_dst. The offset associated to the file\n"
8753
"descriptor that refers to a pipe must be None.");
8754
8755
#define OS_SPLICE_METHODDEF    \
8756
    {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__},
8757
8758
static PyObject *
8759
os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
8760
               PyObject *offset_src, PyObject *offset_dst,
8761
               unsigned int flags);
8762
8763
static PyObject *
8764
os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8765
0
{
8766
0
    PyObject *return_value = NULL;
8767
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8768
8769
0
    #define NUM_KEYWORDS 6
8770
0
    static struct {
8771
0
        PyGC_Head _this_is_not_used;
8772
0
        PyObject_VAR_HEAD
8773
0
        Py_hash_t ob_hash;
8774
0
        PyObject *ob_item[NUM_KEYWORDS];
8775
0
    } _kwtuple = {
8776
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8777
0
        .ob_hash = -1,
8778
0
        .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), },
8779
0
    };
8780
0
    #undef NUM_KEYWORDS
8781
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8782
8783
    #else  // !Py_BUILD_CORE
8784
    #  define KWTUPLE NULL
8785
    #endif  // !Py_BUILD_CORE
8786
8787
0
    static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL};
8788
0
    static _PyArg_Parser _parser = {
8789
0
        .keywords = _keywords,
8790
0
        .fname = "splice",
8791
0
        .kwtuple = KWTUPLE,
8792
0
    };
8793
0
    #undef KWTUPLE
8794
0
    PyObject *argsbuf[6];
8795
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
8796
0
    int src;
8797
0
    int dst;
8798
0
    Py_ssize_t count;
8799
0
    PyObject *offset_src = Py_None;
8800
0
    PyObject *offset_dst = Py_None;
8801
0
    unsigned int flags = 0;
8802
8803
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8804
0
            /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8805
0
    if (!args) {
8806
0
        goto exit;
8807
0
    }
8808
0
    src = PyLong_AsInt(args[0]);
8809
0
    if (src == -1 && PyErr_Occurred()) {
8810
0
        goto exit;
8811
0
    }
8812
0
    dst = PyLong_AsInt(args[1]);
8813
0
    if (dst == -1 && PyErr_Occurred()) {
8814
0
        goto exit;
8815
0
    }
8816
0
    {
8817
0
        Py_ssize_t ival = -1;
8818
0
        PyObject *iobj = _PyNumber_Index(args[2]);
8819
0
        if (iobj != NULL) {
8820
0
            ival = PyLong_AsSsize_t(iobj);
8821
0
            Py_DECREF(iobj);
8822
0
        }
8823
0
        if (ival == -1 && PyErr_Occurred()) {
8824
0
            goto exit;
8825
0
        }
8826
0
        count = ival;
8827
0
        if (count < 0) {
8828
0
            PyErr_SetString(PyExc_ValueError,
8829
0
                            "count cannot be negative");
8830
0
            goto exit;
8831
0
        }
8832
0
    }
8833
0
    if (!noptargs) {
8834
0
        goto skip_optional_pos;
8835
0
    }
8836
0
    if (args[3]) {
8837
0
        offset_src = args[3];
8838
0
        if (!--noptargs) {
8839
0
            goto skip_optional_pos;
8840
0
        }
8841
0
    }
8842
0
    if (args[4]) {
8843
0
        offset_dst = args[4];
8844
0
        if (!--noptargs) {
8845
0
            goto skip_optional_pos;
8846
0
        }
8847
0
    }
8848
0
    if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) {
8849
0
        goto exit;
8850
0
    }
8851
0
skip_optional_pos:
8852
0
    return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags);
8853
8854
0
exit:
8855
0
    return return_value;
8856
0
}
8857
8858
#endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */
8859
8860
#if defined(HAVE_MKFIFO)
8861
8862
PyDoc_STRVAR(os_mkfifo__doc__,
8863
"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
8864
"--\n"
8865
"\n"
8866
"Create a \"fifo\" (a POSIX named pipe).\n"
8867
"\n"
8868
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
8869
"  and path should be relative; path will then be relative to that directory.\n"
8870
"dir_fd may not be implemented on your platform.\n"
8871
"  If it is unavailable, using it will raise a NotImplementedError.");
8872
8873
#define OS_MKFIFO_METHODDEF    \
8874
    {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
8875
8876
static PyObject *
8877
os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
8878
8879
static PyObject *
8880
os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8881
0
{
8882
0
    PyObject *return_value = NULL;
8883
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8884
8885
0
    #define NUM_KEYWORDS 3
8886
0
    static struct {
8887
0
        PyGC_Head _this_is_not_used;
8888
0
        PyObject_VAR_HEAD
8889
0
        Py_hash_t ob_hash;
8890
0
        PyObject *ob_item[NUM_KEYWORDS];
8891
0
    } _kwtuple = {
8892
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8893
0
        .ob_hash = -1,
8894
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
8895
0
    };
8896
0
    #undef NUM_KEYWORDS
8897
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8898
8899
    #else  // !Py_BUILD_CORE
8900
    #  define KWTUPLE NULL
8901
    #endif  // !Py_BUILD_CORE
8902
8903
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
8904
0
    static _PyArg_Parser _parser = {
8905
0
        .keywords = _keywords,
8906
0
        .fname = "mkfifo",
8907
0
        .kwtuple = KWTUPLE,
8908
0
    };
8909
0
    #undef KWTUPLE
8910
0
    PyObject *argsbuf[3];
8911
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
8912
0
    path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0);
8913
0
    int mode = 438;
8914
0
    int dir_fd = DEFAULT_DIR_FD;
8915
8916
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8917
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8918
0
    if (!args) {
8919
0
        goto exit;
8920
0
    }
8921
0
    if (!path_converter(args[0], &path)) {
8922
0
        goto exit;
8923
0
    }
8924
0
    if (!noptargs) {
8925
0
        goto skip_optional_pos;
8926
0
    }
8927
0
    if (args[1]) {
8928
0
        mode = PyLong_AsInt(args[1]);
8929
0
        if (mode == -1 && PyErr_Occurred()) {
8930
0
            goto exit;
8931
0
        }
8932
0
        if (!--noptargs) {
8933
0
            goto skip_optional_pos;
8934
0
        }
8935
0
    }
8936
0
skip_optional_pos:
8937
0
    if (!noptargs) {
8938
0
        goto skip_optional_kwonly;
8939
0
    }
8940
0
    if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
8941
0
        goto exit;
8942
0
    }
8943
0
skip_optional_kwonly:
8944
0
    return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
8945
8946
0
exit:
8947
    /* Cleanup for path */
8948
0
    path_cleanup(&path);
8949
8950
0
    return return_value;
8951
0
}
8952
8953
#endif /* defined(HAVE_MKFIFO) */
8954
8955
#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
8956
8957
PyDoc_STRVAR(os_mknod__doc__,
8958
"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
8959
"--\n"
8960
"\n"
8961
"Create a node in the file system.\n"
8962
"\n"
8963
"Create a node in the file system (file, device special file or named pipe)\n"
8964
"at path.  mode specifies both the permissions to use and the\n"
8965
"type of node to be created, being combined (bitwise OR) with one of\n"
8966
"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO.  If S_IFCHR or S_IFBLK is set on mode,\n"
8967
"device defines the newly created device special file (probably using\n"
8968
"os.makedev()).  Otherwise device is ignored.\n"
8969
"\n"
8970
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
8971
"  and path should be relative; path will then be relative to that directory.\n"
8972
"dir_fd may not be implemented on your platform.\n"
8973
"  If it is unavailable, using it will raise a NotImplementedError.");
8974
8975
#define OS_MKNOD_METHODDEF    \
8976
    {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
8977
8978
static PyObject *
8979
os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
8980
              int dir_fd);
8981
8982
static PyObject *
8983
os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8984
0
{
8985
0
    PyObject *return_value = NULL;
8986
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8987
8988
0
    #define NUM_KEYWORDS 4
8989
0
    static struct {
8990
0
        PyGC_Head _this_is_not_used;
8991
0
        PyObject_VAR_HEAD
8992
0
        Py_hash_t ob_hash;
8993
0
        PyObject *ob_item[NUM_KEYWORDS];
8994
0
    } _kwtuple = {
8995
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8996
0
        .ob_hash = -1,
8997
0
        .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), },
8998
0
    };
8999
0
    #undef NUM_KEYWORDS
9000
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9001
9002
    #else  // !Py_BUILD_CORE
9003
    #  define KWTUPLE NULL
9004
    #endif  // !Py_BUILD_CORE
9005
9006
0
    static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
9007
0
    static _PyArg_Parser _parser = {
9008
0
        .keywords = _keywords,
9009
0
        .fname = "mknod",
9010
0
        .kwtuple = KWTUPLE,
9011
0
    };
9012
0
    #undef KWTUPLE
9013
0
    PyObject *argsbuf[4];
9014
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
9015
0
    path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0);
9016
0
    int mode = 384;
9017
0
    dev_t device = 0;
9018
0
    int dir_fd = DEFAULT_DIR_FD;
9019
9020
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9021
0
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9022
0
    if (!args) {
9023
0
        goto exit;
9024
0
    }
9025
0
    if (!path_converter(args[0], &path)) {
9026
0
        goto exit;
9027
0
    }
9028
0
    if (!noptargs) {
9029
0
        goto skip_optional_pos;
9030
0
    }
9031
0
    if (args[1]) {
9032
0
        mode = PyLong_AsInt(args[1]);
9033
0
        if (mode == -1 && PyErr_Occurred()) {
9034
0
            goto exit;
9035
0
        }
9036
0
        if (!--noptargs) {
9037
0
            goto skip_optional_pos;
9038
0
        }
9039
0
    }
9040
0
    if (args[2]) {
9041
0
        if (!_Py_Dev_Converter(args[2], &device)) {
9042
0
            goto exit;
9043
0
        }
9044
0
        if (!--noptargs) {
9045
0
            goto skip_optional_pos;
9046
0
        }
9047
0
    }
9048
0
skip_optional_pos:
9049
0
    if (!noptargs) {
9050
0
        goto skip_optional_kwonly;
9051
0
    }
9052
0
    if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
9053
0
        goto exit;
9054
0
    }
9055
0
skip_optional_kwonly:
9056
0
    return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
9057
9058
0
exit:
9059
    /* Cleanup for path */
9060
0
    path_cleanup(&path);
9061
9062
0
    return return_value;
9063
0
}
9064
9065
#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
9066
9067
#if defined(HAVE_DEVICE_MACROS)
9068
9069
PyDoc_STRVAR(os_major__doc__,
9070
"major($module, device, /)\n"
9071
"--\n"
9072
"\n"
9073
"Extracts a device major number from a raw device number.");
9074
9075
#define OS_MAJOR_METHODDEF    \
9076
    {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
9077
9078
static PyObject *
9079
os_major_impl(PyObject *module, dev_t device);
9080
9081
static PyObject *
9082
os_major(PyObject *module, PyObject *arg)
9083
0
{
9084
0
    PyObject *return_value = NULL;
9085
0
    dev_t device;
9086
9087
0
    if (!_Py_Dev_Converter(arg, &device)) {
9088
0
        goto exit;
9089
0
    }
9090
0
    return_value = os_major_impl(module, device);
9091
9092
0
exit:
9093
0
    return return_value;
9094
0
}
9095
9096
#endif /* defined(HAVE_DEVICE_MACROS) */
9097
9098
#if defined(HAVE_DEVICE_MACROS)
9099
9100
PyDoc_STRVAR(os_minor__doc__,
9101
"minor($module, device, /)\n"
9102
"--\n"
9103
"\n"
9104
"Extracts a device minor number from a raw device number.");
9105
9106
#define OS_MINOR_METHODDEF    \
9107
    {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
9108
9109
static PyObject *
9110
os_minor_impl(PyObject *module, dev_t device);
9111
9112
static PyObject *
9113
os_minor(PyObject *module, PyObject *arg)
9114
0
{
9115
0
    PyObject *return_value = NULL;
9116
0
    dev_t device;
9117
9118
0
    if (!_Py_Dev_Converter(arg, &device)) {
9119
0
        goto exit;
9120
0
    }
9121
0
    return_value = os_minor_impl(module, device);
9122
9123
0
exit:
9124
0
    return return_value;
9125
0
}
9126
9127
#endif /* defined(HAVE_DEVICE_MACROS) */
9128
9129
#if defined(HAVE_DEVICE_MACROS)
9130
9131
PyDoc_STRVAR(os_makedev__doc__,
9132
"makedev($module, major, minor, /)\n"
9133
"--\n"
9134
"\n"
9135
"Composes a raw device number from the major and minor device numbers.");
9136
9137
#define OS_MAKEDEV_METHODDEF    \
9138
    {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__},
9139
9140
static dev_t
9141
os_makedev_impl(PyObject *module, dev_t major, dev_t minor);
9142
9143
static PyObject *
9144
os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9145
0
{
9146
0
    PyObject *return_value = NULL;
9147
0
    dev_t major;
9148
0
    dev_t minor;
9149
0
    dev_t _return_value;
9150
9151
0
    if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
9152
0
        goto exit;
9153
0
    }
9154
0
    if (!_Py_Dev_Converter(args[0], &major)) {
9155
0
        goto exit;
9156
0
    }
9157
0
    if (!_Py_Dev_Converter(args[1], &minor)) {
9158
0
        goto exit;
9159
0
    }
9160
0
    _return_value = os_makedev_impl(module, major, minor);
9161
0
    if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
9162
0
        goto exit;
9163
0
    }
9164
0
    return_value = _PyLong_FromDev(_return_value);
9165
9166
0
exit:
9167
0
    return return_value;
9168
0
}
9169
9170
#endif /* defined(HAVE_DEVICE_MACROS) */
9171
9172
#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
9173
9174
PyDoc_STRVAR(os_ftruncate__doc__,
9175
"ftruncate($module, fd, length, /)\n"
9176
"--\n"
9177
"\n"
9178
"Truncate a file, specified by file descriptor, to a specific length.");
9179
9180
#define OS_FTRUNCATE_METHODDEF    \
9181
    {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__},
9182
9183
static PyObject *
9184
os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
9185
9186
static PyObject *
9187
os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9188
0
{
9189
0
    PyObject *return_value = NULL;
9190
0
    int fd;
9191
0
    Py_off_t length;
9192
9193
0
    if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
9194
0
        goto exit;
9195
0
    }
9196
0
    fd = PyLong_AsInt(args[0]);
9197
0
    if (fd == -1 && PyErr_Occurred()) {
9198
0
        goto exit;
9199
0
    }
9200
0
    if (!Py_off_t_converter(args[1], &length)) {
9201
0
        goto exit;
9202
0
    }
9203
0
    return_value = os_ftruncate_impl(module, fd, length);
9204
9205
0
exit:
9206
0
    return return_value;
9207
0
}
9208
9209
#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
9210
9211
#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
9212
9213
PyDoc_STRVAR(os_truncate__doc__,
9214
"truncate($module, /, path, length)\n"
9215
"--\n"
9216
"\n"
9217
"Truncate a file, specified by path, to a specific length.\n"
9218
"\n"
9219
"On some platforms, path may also be specified as an open file descriptor.\n"
9220
"  If this functionality is unavailable, using it raises an exception.");
9221
9222
#define OS_TRUNCATE_METHODDEF    \
9223
    {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
9224
9225
static PyObject *
9226
os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
9227
9228
static PyObject *
9229
os_truncate(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 2
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(length), },
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", "length", NULL};
9253
0
    static _PyArg_Parser _parser = {
9254
0
        .keywords = _keywords,
9255
0
        .fname = "truncate",
9256
0
        .kwtuple = KWTUPLE,
9257
0
    };
9258
0
    #undef KWTUPLE
9259
0
    PyObject *argsbuf[2];
9260
0
    path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE);
9261
0
    Py_off_t length;
9262
9263
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9264
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9265
0
    if (!args) {
9266
0
        goto exit;
9267
0
    }
9268
0
    if (!path_converter(args[0], &path)) {
9269
0
        goto exit;
9270
0
    }
9271
0
    if (!Py_off_t_converter(args[1], &length)) {
9272
0
        goto exit;
9273
0
    }
9274
0
    return_value = os_truncate_impl(module, &path, length);
9275
9276
0
exit:
9277
    /* Cleanup for path */
9278
0
    path_cleanup(&path);
9279
9280
0
    return return_value;
9281
0
}
9282
9283
#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
9284
9285
#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__))
9286
9287
PyDoc_STRVAR(os_posix_fallocate__doc__,
9288
"posix_fallocate($module, fd, offset, length, /)\n"
9289
"--\n"
9290
"\n"
9291
"Ensure a file has allocated at least a particular number of bytes on disk.\n"
9292
"\n"
9293
"Ensure that the file specified by fd encompasses a range of bytes\n"
9294
"starting at offset bytes from the beginning and continuing for length bytes.");
9295
9296
#define OS_POSIX_FALLOCATE_METHODDEF    \
9297
    {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__},
9298
9299
static PyObject *
9300
os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
9301
                        Py_off_t length);
9302
9303
static PyObject *
9304
os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9305
0
{
9306
0
    PyObject *return_value = NULL;
9307
0
    int fd;
9308
0
    Py_off_t offset;
9309
0
    Py_off_t length;
9310
9311
0
    if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
9312
0
        goto exit;
9313
0
    }
9314
0
    fd = PyLong_AsInt(args[0]);
9315
0
    if (fd == -1 && PyErr_Occurred()) {
9316
0
        goto exit;
9317
0
    }
9318
0
    if (!Py_off_t_converter(args[1], &offset)) {
9319
0
        goto exit;
9320
0
    }
9321
0
    if (!Py_off_t_converter(args[2], &length)) {
9322
0
        goto exit;
9323
0
    }
9324
0
    return_value = os_posix_fallocate_impl(module, fd, offset, length);
9325
9326
0
exit:
9327
0
    return return_value;
9328
0
}
9329
9330
#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */
9331
9332
#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
9333
9334
PyDoc_STRVAR(os_posix_fadvise__doc__,
9335
"posix_fadvise($module, fd, offset, length, advice, /)\n"
9336
"--\n"
9337
"\n"
9338
"Announce an intention to access data in a specific pattern.\n"
9339
"\n"
9340
"Announce an intention to access data in a specific pattern, thus allowing\n"
9341
"the kernel to make optimizations.\n"
9342
"The advice applies to the region of the file specified by fd starting at\n"
9343
"offset and continuing for length bytes.\n"
9344
"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
9345
"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
9346
"POSIX_FADV_DONTNEED.");
9347
9348
#define OS_POSIX_FADVISE_METHODDEF    \
9349
    {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__},
9350
9351
static PyObject *
9352
os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
9353
                      Py_off_t length, int advice);
9354
9355
static PyObject *
9356
os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9357
0
{
9358
0
    PyObject *return_value = NULL;
9359
0
    int fd;
9360
0
    Py_off_t offset;
9361
0
    Py_off_t length;
9362
0
    int advice;
9363
9364
0
    if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
9365
0
        goto exit;
9366
0
    }
9367
0
    fd = PyLong_AsInt(args[0]);
9368
0
    if (fd == -1 && PyErr_Occurred()) {
9369
0
        goto exit;
9370
0
    }
9371
0
    if (!Py_off_t_converter(args[1], &offset)) {
9372
0
        goto exit;
9373
0
    }
9374
0
    if (!Py_off_t_converter(args[2], &length)) {
9375
0
        goto exit;
9376
0
    }
9377
0
    advice = PyLong_AsInt(args[3]);
9378
0
    if (advice == -1 && PyErr_Occurred()) {
9379
0
        goto exit;
9380
0
    }
9381
0
    return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
9382
9383
0
exit:
9384
0
    return return_value;
9385
0
}
9386
9387
#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
9388
9389
#if defined(MS_WINDOWS)
9390
9391
PyDoc_STRVAR(os_putenv__doc__,
9392
"putenv($module, name, value, /)\n"
9393
"--\n"
9394
"\n"
9395
"Change or add an environment variable.");
9396
9397
#define OS_PUTENV_METHODDEF    \
9398
    {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9399
9400
static PyObject *
9401
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9402
9403
static PyObject *
9404
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9405
{
9406
    PyObject *return_value = NULL;
9407
    PyObject *name;
9408
    PyObject *value;
9409
9410
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9411
        goto exit;
9412
    }
9413
    if (!PyUnicode_Check(args[0])) {
9414
        _PyArg_BadArgument("putenv", "argument 1", "str", args[0]);
9415
        goto exit;
9416
    }
9417
    name = args[0];
9418
    if (!PyUnicode_Check(args[1])) {
9419
        _PyArg_BadArgument("putenv", "argument 2", "str", args[1]);
9420
        goto exit;
9421
    }
9422
    value = args[1];
9423
    return_value = os_putenv_impl(module, name, value);
9424
9425
exit:
9426
    return return_value;
9427
}
9428
9429
#endif /* defined(MS_WINDOWS) */
9430
9431
#if !defined(MS_WINDOWS)
9432
9433
PyDoc_STRVAR(os_putenv__doc__,
9434
"putenv($module, name, value, /)\n"
9435
"--\n"
9436
"\n"
9437
"Change or add an environment variable.");
9438
9439
#define OS_PUTENV_METHODDEF    \
9440
    {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9441
9442
static PyObject *
9443
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9444
9445
static PyObject *
9446
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9447
0
{
9448
0
    PyObject *return_value = NULL;
9449
0
    PyObject *name = NULL;
9450
0
    PyObject *value = NULL;
9451
9452
0
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9453
0
        goto exit;
9454
0
    }
9455
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
9456
0
        goto exit;
9457
0
    }
9458
0
    if (!PyUnicode_FSConverter(args[1], &value)) {
9459
0
        goto exit;
9460
0
    }
9461
0
    return_value = os_putenv_impl(module, name, value);
9462
9463
0
exit:
9464
    /* Cleanup for name */
9465
0
    Py_XDECREF(name);
9466
    /* Cleanup for value */
9467
0
    Py_XDECREF(value);
9468
9469
0
    return return_value;
9470
0
}
9471
9472
#endif /* !defined(MS_WINDOWS) */
9473
9474
#if defined(MS_WINDOWS)
9475
9476
PyDoc_STRVAR(os_unsetenv__doc__,
9477
"unsetenv($module, name, /)\n"
9478
"--\n"
9479
"\n"
9480
"Delete an environment variable.");
9481
9482
#define OS_UNSETENV_METHODDEF    \
9483
    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9484
9485
static PyObject *
9486
os_unsetenv_impl(PyObject *module, PyObject *name);
9487
9488
static PyObject *
9489
os_unsetenv(PyObject *module, PyObject *arg)
9490
{
9491
    PyObject *return_value = NULL;
9492
    PyObject *name;
9493
9494
    if (!PyUnicode_Check(arg)) {
9495
        _PyArg_BadArgument("unsetenv", "argument", "str", arg);
9496
        goto exit;
9497
    }
9498
    name = arg;
9499
    return_value = os_unsetenv_impl(module, name);
9500
9501
exit:
9502
    return return_value;
9503
}
9504
9505
#endif /* defined(MS_WINDOWS) */
9506
9507
#if !defined(MS_WINDOWS)
9508
9509
PyDoc_STRVAR(os_unsetenv__doc__,
9510
"unsetenv($module, name, /)\n"
9511
"--\n"
9512
"\n"
9513
"Delete an environment variable.");
9514
9515
#define OS_UNSETENV_METHODDEF    \
9516
    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9517
9518
static PyObject *
9519
os_unsetenv_impl(PyObject *module, PyObject *name);
9520
9521
static PyObject *
9522
os_unsetenv(PyObject *module, PyObject *arg)
9523
0
{
9524
0
    PyObject *return_value = NULL;
9525
0
    PyObject *name = NULL;
9526
9527
0
    if (!PyUnicode_FSConverter(arg, &name)) {
9528
0
        goto exit;
9529
0
    }
9530
0
    return_value = os_unsetenv_impl(module, name);
9531
9532
0
exit:
9533
    /* Cleanup for name */
9534
0
    Py_XDECREF(name);
9535
9536
0
    return return_value;
9537
0
}
9538
9539
#endif /* !defined(MS_WINDOWS) */
9540
9541
PyDoc_STRVAR(os_strerror__doc__,
9542
"strerror($module, code, /)\n"
9543
"--\n"
9544
"\n"
9545
"Translate an error code to a message string.");
9546
9547
#define OS_STRERROR_METHODDEF    \
9548
    {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
9549
9550
static PyObject *
9551
os_strerror_impl(PyObject *module, int code);
9552
9553
static PyObject *
9554
os_strerror(PyObject *module, PyObject *arg)
9555
0
{
9556
0
    PyObject *return_value = NULL;
9557
0
    int code;
9558
9559
0
    code = PyLong_AsInt(arg);
9560
0
    if (code == -1 && PyErr_Occurred()) {
9561
0
        goto exit;
9562
0
    }
9563
0
    return_value = os_strerror_impl(module, code);
9564
9565
0
exit:
9566
0
    return return_value;
9567
0
}
9568
9569
#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
9570
9571
PyDoc_STRVAR(os_WCOREDUMP__doc__,
9572
"WCOREDUMP($module, status, /)\n"
9573
"--\n"
9574
"\n"
9575
"Return True if the process returning status was dumped to a core file.");
9576
9577
#define OS_WCOREDUMP_METHODDEF    \
9578
    {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
9579
9580
static int
9581
os_WCOREDUMP_impl(PyObject *module, int status);
9582
9583
static PyObject *
9584
os_WCOREDUMP(PyObject *module, PyObject *arg)
9585
0
{
9586
0
    PyObject *return_value = NULL;
9587
0
    int status;
9588
0
    int _return_value;
9589
9590
0
    status = PyLong_AsInt(arg);
9591
0
    if (status == -1 && PyErr_Occurred()) {
9592
0
        goto exit;
9593
0
    }
9594
0
    _return_value = os_WCOREDUMP_impl(module, status);
9595
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9596
0
        goto exit;
9597
0
    }
9598
0
    return_value = PyBool_FromLong((long)_return_value);
9599
9600
0
exit:
9601
0
    return return_value;
9602
0
}
9603
9604
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
9605
9606
#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
9607
9608
PyDoc_STRVAR(os_WIFCONTINUED__doc__,
9609
"WIFCONTINUED($module, /, status)\n"
9610
"--\n"
9611
"\n"
9612
"Return True if a particular process was continued from a job control stop.\n"
9613
"\n"
9614
"Return True if the process returning status was continued from a\n"
9615
"job control stop.");
9616
9617
#define OS_WIFCONTINUED_METHODDEF    \
9618
    {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
9619
9620
static int
9621
os_WIFCONTINUED_impl(PyObject *module, int status);
9622
9623
static PyObject *
9624
os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9625
0
{
9626
0
    PyObject *return_value = NULL;
9627
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9628
9629
0
    #define NUM_KEYWORDS 1
9630
0
    static struct {
9631
0
        PyGC_Head _this_is_not_used;
9632
0
        PyObject_VAR_HEAD
9633
0
        Py_hash_t ob_hash;
9634
0
        PyObject *ob_item[NUM_KEYWORDS];
9635
0
    } _kwtuple = {
9636
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9637
0
        .ob_hash = -1,
9638
0
        .ob_item = { &_Py_ID(status), },
9639
0
    };
9640
0
    #undef NUM_KEYWORDS
9641
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9642
9643
    #else  // !Py_BUILD_CORE
9644
    #  define KWTUPLE NULL
9645
    #endif  // !Py_BUILD_CORE
9646
9647
0
    static const char * const _keywords[] = {"status", NULL};
9648
0
    static _PyArg_Parser _parser = {
9649
0
        .keywords = _keywords,
9650
0
        .fname = "WIFCONTINUED",
9651
0
        .kwtuple = KWTUPLE,
9652
0
    };
9653
0
    #undef KWTUPLE
9654
0
    PyObject *argsbuf[1];
9655
0
    int status;
9656
0
    int _return_value;
9657
9658
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9659
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9660
0
    if (!args) {
9661
0
        goto exit;
9662
0
    }
9663
0
    status = PyLong_AsInt(args[0]);
9664
0
    if (status == -1 && PyErr_Occurred()) {
9665
0
        goto exit;
9666
0
    }
9667
0
    _return_value = os_WIFCONTINUED_impl(module, status);
9668
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9669
0
        goto exit;
9670
0
    }
9671
0
    return_value = PyBool_FromLong((long)_return_value);
9672
9673
0
exit:
9674
0
    return return_value;
9675
0
}
9676
9677
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
9678
9679
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
9680
9681
PyDoc_STRVAR(os_WIFSTOPPED__doc__,
9682
"WIFSTOPPED($module, /, status)\n"
9683
"--\n"
9684
"\n"
9685
"Return True if the process returning status was stopped.");
9686
9687
#define OS_WIFSTOPPED_METHODDEF    \
9688
    {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
9689
9690
static int
9691
os_WIFSTOPPED_impl(PyObject *module, int status);
9692
9693
static PyObject *
9694
os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9695
0
{
9696
0
    PyObject *return_value = NULL;
9697
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9698
9699
0
    #define NUM_KEYWORDS 1
9700
0
    static struct {
9701
0
        PyGC_Head _this_is_not_used;
9702
0
        PyObject_VAR_HEAD
9703
0
        Py_hash_t ob_hash;
9704
0
        PyObject *ob_item[NUM_KEYWORDS];
9705
0
    } _kwtuple = {
9706
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9707
0
        .ob_hash = -1,
9708
0
        .ob_item = { &_Py_ID(status), },
9709
0
    };
9710
0
    #undef NUM_KEYWORDS
9711
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9712
9713
    #else  // !Py_BUILD_CORE
9714
    #  define KWTUPLE NULL
9715
    #endif  // !Py_BUILD_CORE
9716
9717
0
    static const char * const _keywords[] = {"status", NULL};
9718
0
    static _PyArg_Parser _parser = {
9719
0
        .keywords = _keywords,
9720
0
        .fname = "WIFSTOPPED",
9721
0
        .kwtuple = KWTUPLE,
9722
0
    };
9723
0
    #undef KWTUPLE
9724
0
    PyObject *argsbuf[1];
9725
0
    int status;
9726
0
    int _return_value;
9727
9728
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9729
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9730
0
    if (!args) {
9731
0
        goto exit;
9732
0
    }
9733
0
    status = PyLong_AsInt(args[0]);
9734
0
    if (status == -1 && PyErr_Occurred()) {
9735
0
        goto exit;
9736
0
    }
9737
0
    _return_value = os_WIFSTOPPED_impl(module, status);
9738
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9739
0
        goto exit;
9740
0
    }
9741
0
    return_value = PyBool_FromLong((long)_return_value);
9742
9743
0
exit:
9744
0
    return return_value;
9745
0
}
9746
9747
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
9748
9749
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
9750
9751
PyDoc_STRVAR(os_WIFSIGNALED__doc__,
9752
"WIFSIGNALED($module, /, status)\n"
9753
"--\n"
9754
"\n"
9755
"Return True if the process returning status was terminated by a signal.");
9756
9757
#define OS_WIFSIGNALED_METHODDEF    \
9758
    {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
9759
9760
static int
9761
os_WIFSIGNALED_impl(PyObject *module, int status);
9762
9763
static PyObject *
9764
os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9765
0
{
9766
0
    PyObject *return_value = NULL;
9767
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9768
9769
0
    #define NUM_KEYWORDS 1
9770
0
    static struct {
9771
0
        PyGC_Head _this_is_not_used;
9772
0
        PyObject_VAR_HEAD
9773
0
        Py_hash_t ob_hash;
9774
0
        PyObject *ob_item[NUM_KEYWORDS];
9775
0
    } _kwtuple = {
9776
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9777
0
        .ob_hash = -1,
9778
0
        .ob_item = { &_Py_ID(status), },
9779
0
    };
9780
0
    #undef NUM_KEYWORDS
9781
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9782
9783
    #else  // !Py_BUILD_CORE
9784
    #  define KWTUPLE NULL
9785
    #endif  // !Py_BUILD_CORE
9786
9787
0
    static const char * const _keywords[] = {"status", NULL};
9788
0
    static _PyArg_Parser _parser = {
9789
0
        .keywords = _keywords,
9790
0
        .fname = "WIFSIGNALED",
9791
0
        .kwtuple = KWTUPLE,
9792
0
    };
9793
0
    #undef KWTUPLE
9794
0
    PyObject *argsbuf[1];
9795
0
    int status;
9796
0
    int _return_value;
9797
9798
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9799
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9800
0
    if (!args) {
9801
0
        goto exit;
9802
0
    }
9803
0
    status = PyLong_AsInt(args[0]);
9804
0
    if (status == -1 && PyErr_Occurred()) {
9805
0
        goto exit;
9806
0
    }
9807
0
    _return_value = os_WIFSIGNALED_impl(module, status);
9808
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9809
0
        goto exit;
9810
0
    }
9811
0
    return_value = PyBool_FromLong((long)_return_value);
9812
9813
0
exit:
9814
0
    return return_value;
9815
0
}
9816
9817
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
9818
9819
#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
9820
9821
PyDoc_STRVAR(os_WIFEXITED__doc__,
9822
"WIFEXITED($module, /, status)\n"
9823
"--\n"
9824
"\n"
9825
"Return True if the process returning status exited via the exit() system call.");
9826
9827
#define OS_WIFEXITED_METHODDEF    \
9828
    {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
9829
9830
static int
9831
os_WIFEXITED_impl(PyObject *module, int status);
9832
9833
static PyObject *
9834
os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9835
0
{
9836
0
    PyObject *return_value = NULL;
9837
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9838
9839
0
    #define NUM_KEYWORDS 1
9840
0
    static struct {
9841
0
        PyGC_Head _this_is_not_used;
9842
0
        PyObject_VAR_HEAD
9843
0
        Py_hash_t ob_hash;
9844
0
        PyObject *ob_item[NUM_KEYWORDS];
9845
0
    } _kwtuple = {
9846
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9847
0
        .ob_hash = -1,
9848
0
        .ob_item = { &_Py_ID(status), },
9849
0
    };
9850
0
    #undef NUM_KEYWORDS
9851
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9852
9853
    #else  // !Py_BUILD_CORE
9854
    #  define KWTUPLE NULL
9855
    #endif  // !Py_BUILD_CORE
9856
9857
0
    static const char * const _keywords[] = {"status", NULL};
9858
0
    static _PyArg_Parser _parser = {
9859
0
        .keywords = _keywords,
9860
0
        .fname = "WIFEXITED",
9861
0
        .kwtuple = KWTUPLE,
9862
0
    };
9863
0
    #undef KWTUPLE
9864
0
    PyObject *argsbuf[1];
9865
0
    int status;
9866
0
    int _return_value;
9867
9868
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9869
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9870
0
    if (!args) {
9871
0
        goto exit;
9872
0
    }
9873
0
    status = PyLong_AsInt(args[0]);
9874
0
    if (status == -1 && PyErr_Occurred()) {
9875
0
        goto exit;
9876
0
    }
9877
0
    _return_value = os_WIFEXITED_impl(module, status);
9878
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9879
0
        goto exit;
9880
0
    }
9881
0
    return_value = PyBool_FromLong((long)_return_value);
9882
9883
0
exit:
9884
0
    return return_value;
9885
0
}
9886
9887
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
9888
9889
#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
9890
9891
PyDoc_STRVAR(os_WEXITSTATUS__doc__,
9892
"WEXITSTATUS($module, /, status)\n"
9893
"--\n"
9894
"\n"
9895
"Return the process return code from status.");
9896
9897
#define OS_WEXITSTATUS_METHODDEF    \
9898
    {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
9899
9900
static int
9901
os_WEXITSTATUS_impl(PyObject *module, int status);
9902
9903
static PyObject *
9904
os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9905
0
{
9906
0
    PyObject *return_value = NULL;
9907
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9908
9909
0
    #define NUM_KEYWORDS 1
9910
0
    static struct {
9911
0
        PyGC_Head _this_is_not_used;
9912
0
        PyObject_VAR_HEAD
9913
0
        Py_hash_t ob_hash;
9914
0
        PyObject *ob_item[NUM_KEYWORDS];
9915
0
    } _kwtuple = {
9916
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9917
0
        .ob_hash = -1,
9918
0
        .ob_item = { &_Py_ID(status), },
9919
0
    };
9920
0
    #undef NUM_KEYWORDS
9921
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9922
9923
    #else  // !Py_BUILD_CORE
9924
    #  define KWTUPLE NULL
9925
    #endif  // !Py_BUILD_CORE
9926
9927
0
    static const char * const _keywords[] = {"status", NULL};
9928
0
    static _PyArg_Parser _parser = {
9929
0
        .keywords = _keywords,
9930
0
        .fname = "WEXITSTATUS",
9931
0
        .kwtuple = KWTUPLE,
9932
0
    };
9933
0
    #undef KWTUPLE
9934
0
    PyObject *argsbuf[1];
9935
0
    int status;
9936
0
    int _return_value;
9937
9938
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9939
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9940
0
    if (!args) {
9941
0
        goto exit;
9942
0
    }
9943
0
    status = PyLong_AsInt(args[0]);
9944
0
    if (status == -1 && PyErr_Occurred()) {
9945
0
        goto exit;
9946
0
    }
9947
0
    _return_value = os_WEXITSTATUS_impl(module, status);
9948
0
    if ((_return_value == -1) && PyErr_Occurred()) {
9949
0
        goto exit;
9950
0
    }
9951
0
    return_value = PyLong_FromLong((long)_return_value);
9952
9953
0
exit:
9954
0
    return return_value;
9955
0
}
9956
9957
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
9958
9959
#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
9960
9961
PyDoc_STRVAR(os_WTERMSIG__doc__,
9962
"WTERMSIG($module, /, status)\n"
9963
"--\n"
9964
"\n"
9965
"Return the signal that terminated the process that provided the status value.");
9966
9967
#define OS_WTERMSIG_METHODDEF    \
9968
    {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
9969
9970
static int
9971
os_WTERMSIG_impl(PyObject *module, int status);
9972
9973
static PyObject *
9974
os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9975
0
{
9976
0
    PyObject *return_value = NULL;
9977
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9978
9979
0
    #define NUM_KEYWORDS 1
9980
0
    static struct {
9981
0
        PyGC_Head _this_is_not_used;
9982
0
        PyObject_VAR_HEAD
9983
0
        Py_hash_t ob_hash;
9984
0
        PyObject *ob_item[NUM_KEYWORDS];
9985
0
    } _kwtuple = {
9986
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9987
0
        .ob_hash = -1,
9988
0
        .ob_item = { &_Py_ID(status), },
9989
0
    };
9990
0
    #undef NUM_KEYWORDS
9991
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9992
9993
    #else  // !Py_BUILD_CORE
9994
    #  define KWTUPLE NULL
9995
    #endif  // !Py_BUILD_CORE
9996
9997
0
    static const char * const _keywords[] = {"status", NULL};
9998
0
    static _PyArg_Parser _parser = {
9999
0
        .keywords = _keywords,
10000
0
        .fname = "WTERMSIG",
10001
0
        .kwtuple = KWTUPLE,
10002
0
    };
10003
0
    #undef KWTUPLE
10004
0
    PyObject *argsbuf[1];
10005
0
    int status;
10006
0
    int _return_value;
10007
10008
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10009
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10010
0
    if (!args) {
10011
0
        goto exit;
10012
0
    }
10013
0
    status = PyLong_AsInt(args[0]);
10014
0
    if (status == -1 && PyErr_Occurred()) {
10015
0
        goto exit;
10016
0
    }
10017
0
    _return_value = os_WTERMSIG_impl(module, status);
10018
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10019
0
        goto exit;
10020
0
    }
10021
0
    return_value = PyLong_FromLong((long)_return_value);
10022
10023
0
exit:
10024
0
    return return_value;
10025
0
}
10026
10027
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
10028
10029
#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
10030
10031
PyDoc_STRVAR(os_WSTOPSIG__doc__,
10032
"WSTOPSIG($module, /, status)\n"
10033
"--\n"
10034
"\n"
10035
"Return the signal that stopped the process that provided the status value.");
10036
10037
#define OS_WSTOPSIG_METHODDEF    \
10038
    {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
10039
10040
static int
10041
os_WSTOPSIG_impl(PyObject *module, int status);
10042
10043
static PyObject *
10044
os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10045
0
{
10046
0
    PyObject *return_value = NULL;
10047
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10048
10049
0
    #define NUM_KEYWORDS 1
10050
0
    static struct {
10051
0
        PyGC_Head _this_is_not_used;
10052
0
        PyObject_VAR_HEAD
10053
0
        Py_hash_t ob_hash;
10054
0
        PyObject *ob_item[NUM_KEYWORDS];
10055
0
    } _kwtuple = {
10056
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10057
0
        .ob_hash = -1,
10058
0
        .ob_item = { &_Py_ID(status), },
10059
0
    };
10060
0
    #undef NUM_KEYWORDS
10061
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10062
10063
    #else  // !Py_BUILD_CORE
10064
    #  define KWTUPLE NULL
10065
    #endif  // !Py_BUILD_CORE
10066
10067
0
    static const char * const _keywords[] = {"status", NULL};
10068
0
    static _PyArg_Parser _parser = {
10069
0
        .keywords = _keywords,
10070
0
        .fname = "WSTOPSIG",
10071
0
        .kwtuple = KWTUPLE,
10072
0
    };
10073
0
    #undef KWTUPLE
10074
0
    PyObject *argsbuf[1];
10075
0
    int status;
10076
0
    int _return_value;
10077
10078
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10079
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10080
0
    if (!args) {
10081
0
        goto exit;
10082
0
    }
10083
0
    status = PyLong_AsInt(args[0]);
10084
0
    if (status == -1 && PyErr_Occurred()) {
10085
0
        goto exit;
10086
0
    }
10087
0
    _return_value = os_WSTOPSIG_impl(module, status);
10088
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10089
0
        goto exit;
10090
0
    }
10091
0
    return_value = PyLong_FromLong((long)_return_value);
10092
10093
0
exit:
10094
0
    return return_value;
10095
0
}
10096
10097
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
10098
10099
#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
10100
10101
PyDoc_STRVAR(os_fstatvfs__doc__,
10102
"fstatvfs($module, fd, /)\n"
10103
"--\n"
10104
"\n"
10105
"Perform an fstatvfs system call on the given fd.\n"
10106
"\n"
10107
"Equivalent to statvfs(fd).");
10108
10109
#define OS_FSTATVFS_METHODDEF    \
10110
    {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
10111
10112
static PyObject *
10113
os_fstatvfs_impl(PyObject *module, int fd);
10114
10115
static PyObject *
10116
os_fstatvfs(PyObject *module, PyObject *arg)
10117
0
{
10118
0
    PyObject *return_value = NULL;
10119
0
    int fd;
10120
10121
0
    fd = PyLong_AsInt(arg);
10122
0
    if (fd == -1 && PyErr_Occurred()) {
10123
0
        goto exit;
10124
0
    }
10125
0
    return_value = os_fstatvfs_impl(module, fd);
10126
10127
0
exit:
10128
0
    return return_value;
10129
0
}
10130
10131
#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10132
10133
#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
10134
10135
PyDoc_STRVAR(os_statvfs__doc__,
10136
"statvfs($module, /, path)\n"
10137
"--\n"
10138
"\n"
10139
"Perform a statvfs system call on the given path.\n"
10140
"\n"
10141
"path may always be specified as a string.\n"
10142
"On some platforms, path may also be specified as an open file descriptor.\n"
10143
"  If this functionality is unavailable, using it raises an exception.");
10144
10145
#define OS_STATVFS_METHODDEF    \
10146
    {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
10147
10148
static PyObject *
10149
os_statvfs_impl(PyObject *module, path_t *path);
10150
10151
static PyObject *
10152
os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10153
0
{
10154
0
    PyObject *return_value = NULL;
10155
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10156
10157
0
    #define NUM_KEYWORDS 1
10158
0
    static struct {
10159
0
        PyGC_Head _this_is_not_used;
10160
0
        PyObject_VAR_HEAD
10161
0
        Py_hash_t ob_hash;
10162
0
        PyObject *ob_item[NUM_KEYWORDS];
10163
0
    } _kwtuple = {
10164
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10165
0
        .ob_hash = -1,
10166
0
        .ob_item = { &_Py_ID(path), },
10167
0
    };
10168
0
    #undef NUM_KEYWORDS
10169
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10170
10171
    #else  // !Py_BUILD_CORE
10172
    #  define KWTUPLE NULL
10173
    #endif  // !Py_BUILD_CORE
10174
10175
0
    static const char * const _keywords[] = {"path", NULL};
10176
0
    static _PyArg_Parser _parser = {
10177
0
        .keywords = _keywords,
10178
0
        .fname = "statvfs",
10179
0
        .kwtuple = KWTUPLE,
10180
0
    };
10181
0
    #undef KWTUPLE
10182
0
    PyObject *argsbuf[1];
10183
0
    path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS);
10184
10185
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10186
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10187
0
    if (!args) {
10188
0
        goto exit;
10189
0
    }
10190
0
    if (!path_converter(args[0], &path)) {
10191
0
        goto exit;
10192
0
    }
10193
0
    return_value = os_statvfs_impl(module, &path);
10194
10195
0
exit:
10196
    /* Cleanup for path */
10197
0
    path_cleanup(&path);
10198
10199
0
    return return_value;
10200
0
}
10201
10202
#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10203
10204
#if defined(MS_WINDOWS)
10205
10206
PyDoc_STRVAR(os__getdiskusage__doc__,
10207
"_getdiskusage($module, /, path)\n"
10208
"--\n"
10209
"\n"
10210
"Return disk usage statistics about the given path as a (total, free) tuple.");
10211
10212
#define OS__GETDISKUSAGE_METHODDEF    \
10213
    {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
10214
10215
static PyObject *
10216
os__getdiskusage_impl(PyObject *module, path_t *path);
10217
10218
static PyObject *
10219
os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10220
{
10221
    PyObject *return_value = NULL;
10222
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10223
10224
    #define NUM_KEYWORDS 1
10225
    static struct {
10226
        PyGC_Head _this_is_not_used;
10227
        PyObject_VAR_HEAD
10228
        Py_hash_t ob_hash;
10229
        PyObject *ob_item[NUM_KEYWORDS];
10230
    } _kwtuple = {
10231
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10232
        .ob_hash = -1,
10233
        .ob_item = { &_Py_ID(path), },
10234
    };
10235
    #undef NUM_KEYWORDS
10236
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10237
10238
    #else  // !Py_BUILD_CORE
10239
    #  define KWTUPLE NULL
10240
    #endif  // !Py_BUILD_CORE
10241
10242
    static const char * const _keywords[] = {"path", NULL};
10243
    static _PyArg_Parser _parser = {
10244
        .keywords = _keywords,
10245
        .fname = "_getdiskusage",
10246
        .kwtuple = KWTUPLE,
10247
    };
10248
    #undef KWTUPLE
10249
    PyObject *argsbuf[1];
10250
    path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0);
10251
10252
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10253
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10254
    if (!args) {
10255
        goto exit;
10256
    }
10257
    if (!path_converter(args[0], &path)) {
10258
        goto exit;
10259
    }
10260
    return_value = os__getdiskusage_impl(module, &path);
10261
10262
exit:
10263
    /* Cleanup for path */
10264
    path_cleanup(&path);
10265
10266
    return return_value;
10267
}
10268
10269
#endif /* defined(MS_WINDOWS) */
10270
10271
#if defined(HAVE_FPATHCONF)
10272
10273
PyDoc_STRVAR(os_fpathconf__doc__,
10274
"fpathconf($module, fd, name, /)\n"
10275
"--\n"
10276
"\n"
10277
"Return the configuration limit name for the file descriptor fd.\n"
10278
"\n"
10279
"If there is no limit, return -1.");
10280
10281
#define OS_FPATHCONF_METHODDEF    \
10282
    {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__},
10283
10284
static long
10285
os_fpathconf_impl(PyObject *module, int fd, int name);
10286
10287
static PyObject *
10288
os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10289
0
{
10290
0
    PyObject *return_value = NULL;
10291
0
    int fd;
10292
0
    int name;
10293
0
    long _return_value;
10294
10295
0
    if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
10296
0
        goto exit;
10297
0
    }
10298
0
    fd = PyObject_AsFileDescriptor(args[0]);
10299
0
    if (fd < 0) {
10300
0
        goto exit;
10301
0
    }
10302
0
    if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10303
0
        goto exit;
10304
0
    }
10305
0
    _return_value = os_fpathconf_impl(module, fd, name);
10306
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10307
0
        goto exit;
10308
0
    }
10309
0
    return_value = PyLong_FromLong(_return_value);
10310
10311
0
exit:
10312
0
    return return_value;
10313
0
}
10314
10315
#endif /* defined(HAVE_FPATHCONF) */
10316
10317
#if defined(HAVE_PATHCONF)
10318
10319
PyDoc_STRVAR(os_pathconf__doc__,
10320
"pathconf($module, /, path, name)\n"
10321
"--\n"
10322
"\n"
10323
"Return the configuration limit name for the file or directory path.\n"
10324
"\n"
10325
"If there is no limit, return -1.\n"
10326
"On some platforms, path may also be specified as an open file descriptor.\n"
10327
"  If this functionality is unavailable, using it raises an exception.");
10328
10329
#define OS_PATHCONF_METHODDEF    \
10330
    {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
10331
10332
static long
10333
os_pathconf_impl(PyObject *module, path_t *path, int name);
10334
10335
static PyObject *
10336
os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10337
0
{
10338
0
    PyObject *return_value = NULL;
10339
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10340
10341
0
    #define NUM_KEYWORDS 2
10342
0
    static struct {
10343
0
        PyGC_Head _this_is_not_used;
10344
0
        PyObject_VAR_HEAD
10345
0
        Py_hash_t ob_hash;
10346
0
        PyObject *ob_item[NUM_KEYWORDS];
10347
0
    } _kwtuple = {
10348
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10349
0
        .ob_hash = -1,
10350
0
        .ob_item = { &_Py_ID(path), &_Py_ID(name), },
10351
0
    };
10352
0
    #undef NUM_KEYWORDS
10353
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10354
10355
    #else  // !Py_BUILD_CORE
10356
    #  define KWTUPLE NULL
10357
    #endif  // !Py_BUILD_CORE
10358
10359
0
    static const char * const _keywords[] = {"path", "name", NULL};
10360
0
    static _PyArg_Parser _parser = {
10361
0
        .keywords = _keywords,
10362
0
        .fname = "pathconf",
10363
0
        .kwtuple = KWTUPLE,
10364
0
    };
10365
0
    #undef KWTUPLE
10366
0
    PyObject *argsbuf[2];
10367
0
    path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF);
10368
0
    int name;
10369
0
    long _return_value;
10370
10371
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10372
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10373
0
    if (!args) {
10374
0
        goto exit;
10375
0
    }
10376
0
    if (!path_converter(args[0], &path)) {
10377
0
        goto exit;
10378
0
    }
10379
0
    if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10380
0
        goto exit;
10381
0
    }
10382
0
    _return_value = os_pathconf_impl(module, &path, name);
10383
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10384
0
        goto exit;
10385
0
    }
10386
0
    return_value = PyLong_FromLong(_return_value);
10387
10388
0
exit:
10389
    /* Cleanup for path */
10390
0
    path_cleanup(&path);
10391
10392
0
    return return_value;
10393
0
}
10394
10395
#endif /* defined(HAVE_PATHCONF) */
10396
10397
#if defined(HAVE_CONFSTR)
10398
10399
PyDoc_STRVAR(os_confstr__doc__,
10400
"confstr($module, name, /)\n"
10401
"--\n"
10402
"\n"
10403
"Return a string-valued system configuration variable.");
10404
10405
#define OS_CONFSTR_METHODDEF    \
10406
    {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
10407
10408
static PyObject *
10409
os_confstr_impl(PyObject *module, int name);
10410
10411
static PyObject *
10412
os_confstr(PyObject *module, PyObject *arg)
10413
0
{
10414
0
    PyObject *return_value = NULL;
10415
0
    int name;
10416
10417
0
    if (!conv_confname(module, arg, &name, "confstr_names")) {
10418
0
        goto exit;
10419
0
    }
10420
0
    return_value = os_confstr_impl(module, name);
10421
10422
0
exit:
10423
0
    return return_value;
10424
0
}
10425
10426
#endif /* defined(HAVE_CONFSTR) */
10427
10428
#if defined(HAVE_SYSCONF)
10429
10430
PyDoc_STRVAR(os_sysconf__doc__,
10431
"sysconf($module, name, /)\n"
10432
"--\n"
10433
"\n"
10434
"Return an integer-valued system configuration variable.");
10435
10436
#define OS_SYSCONF_METHODDEF    \
10437
    {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
10438
10439
static long
10440
os_sysconf_impl(PyObject *module, int name);
10441
10442
static PyObject *
10443
os_sysconf(PyObject *module, PyObject *arg)
10444
0
{
10445
0
    PyObject *return_value = NULL;
10446
0
    int name;
10447
0
    long _return_value;
10448
10449
0
    if (!conv_confname(module, arg, &name, "sysconf_names")) {
10450
0
        goto exit;
10451
0
    }
10452
0
    _return_value = os_sysconf_impl(module, name);
10453
0
    if ((_return_value == -1) && PyErr_Occurred()) {
10454
0
        goto exit;
10455
0
    }
10456
0
    return_value = PyLong_FromLong(_return_value);
10457
10458
0
exit:
10459
0
    return return_value;
10460
0
}
10461
10462
#endif /* defined(HAVE_SYSCONF) */
10463
10464
PyDoc_STRVAR(os_abort__doc__,
10465
"abort($module, /)\n"
10466
"--\n"
10467
"\n"
10468
"Abort the interpreter immediately.\n"
10469
"\n"
10470
"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
10471
"on the hosting operating system.  This function never returns.");
10472
10473
#define OS_ABORT_METHODDEF    \
10474
    {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
10475
10476
static PyObject *
10477
os_abort_impl(PyObject *module);
10478
10479
static PyObject *
10480
os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
10481
0
{
10482
0
    return os_abort_impl(module);
10483
0
}
10484
10485
#if defined(MS_WINDOWS)
10486
10487
PyDoc_STRVAR(os_startfile__doc__,
10488
"startfile($module, /, filepath, operation=<unrepresentable>,\n"
10489
"          arguments=<unrepresentable>, cwd=None, show_cmd=1)\n"
10490
"--\n"
10491
"\n"
10492
"Start a file with its associated application.\n"
10493
"\n"
10494
"When \"operation\" is not specified or \"open\", this acts like\n"
10495
"double-clicking the file in Explorer, or giving the file name as an\n"
10496
"argument to the DOS \"start\" command: the file is opened with whatever\n"
10497
"application (if any) its extension is associated.\n"
10498
"When another \"operation\" is given, it specifies what should be done with\n"
10499
"the file.  A typical operation is \"print\".\n"
10500
"\n"
10501
"\"arguments\" is passed to the application, but should be omitted if the\n"
10502
"file is a document.\n"
10503
"\n"
10504
"\"cwd\" is the working directory for the operation. If \"filepath\" is\n"
10505
"relative, it will be resolved against this directory. This argument\n"
10506
"should usually be an absolute path.\n"
10507
"\n"
10508
"\"show_cmd\" can be used to override the recommended visibility option.\n"
10509
"See the Windows ShellExecute documentation for values.\n"
10510
"\n"
10511
"startfile returns as soon as the associated application is launched.\n"
10512
"There is no option to wait for the application to close, and no way\n"
10513
"to retrieve the application\'s exit status.\n"
10514
"\n"
10515
"The filepath is relative to the current directory.  If you want to use\n"
10516
"an absolute path, make sure the first character is not a slash (\"/\");\n"
10517
"the underlying Win32 ShellExecute function doesn\'t work if it is.");
10518
10519
#define OS_STARTFILE_METHODDEF    \
10520
    {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
10521
10522
static PyObject *
10523
os_startfile_impl(PyObject *module, path_t *filepath,
10524
                  const wchar_t *operation, const wchar_t *arguments,
10525
                  path_t *cwd, int show_cmd);
10526
10527
static PyObject *
10528
os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10529
{
10530
    PyObject *return_value = NULL;
10531
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10532
10533
    #define NUM_KEYWORDS 5
10534
    static struct {
10535
        PyGC_Head _this_is_not_used;
10536
        PyObject_VAR_HEAD
10537
        Py_hash_t ob_hash;
10538
        PyObject *ob_item[NUM_KEYWORDS];
10539
    } _kwtuple = {
10540
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10541
        .ob_hash = -1,
10542
        .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), },
10543
    };
10544
    #undef NUM_KEYWORDS
10545
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10546
10547
    #else  // !Py_BUILD_CORE
10548
    #  define KWTUPLE NULL
10549
    #endif  // !Py_BUILD_CORE
10550
10551
    static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL};
10552
    static _PyArg_Parser _parser = {
10553
        .keywords = _keywords,
10554
        .fname = "startfile",
10555
        .kwtuple = KWTUPLE,
10556
    };
10557
    #undef KWTUPLE
10558
    PyObject *argsbuf[5];
10559
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
10560
    path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0);
10561
    const wchar_t *operation = NULL;
10562
    const wchar_t *arguments = NULL;
10563
    path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0);
10564
    int show_cmd = 1;
10565
10566
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10567
            /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10568
    if (!args) {
10569
        goto exit;
10570
    }
10571
    if (!path_converter(args[0], &filepath)) {
10572
        goto exit;
10573
    }
10574
    if (!noptargs) {
10575
        goto skip_optional_pos;
10576
    }
10577
    if (args[1]) {
10578
        if (!PyUnicode_Check(args[1])) {
10579
            _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]);
10580
            goto exit;
10581
        }
10582
        operation = PyUnicode_AsWideCharString(args[1], NULL);
10583
        if (operation == NULL) {
10584
            goto exit;
10585
        }
10586
        if (!--noptargs) {
10587
            goto skip_optional_pos;
10588
        }
10589
    }
10590
    if (args[2]) {
10591
        if (!PyUnicode_Check(args[2])) {
10592
            _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]);
10593
            goto exit;
10594
        }
10595
        arguments = PyUnicode_AsWideCharString(args[2], NULL);
10596
        if (arguments == NULL) {
10597
            goto exit;
10598
        }
10599
        if (!--noptargs) {
10600
            goto skip_optional_pos;
10601
        }
10602
    }
10603
    if (args[3]) {
10604
        if (!path_converter(args[3], &cwd)) {
10605
            goto exit;
10606
        }
10607
        if (!--noptargs) {
10608
            goto skip_optional_pos;
10609
        }
10610
    }
10611
    show_cmd = PyLong_AsInt(args[4]);
10612
    if (show_cmd == -1 && PyErr_Occurred()) {
10613
        goto exit;
10614
    }
10615
skip_optional_pos:
10616
    return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd);
10617
10618
exit:
10619
    /* Cleanup for filepath */
10620
    path_cleanup(&filepath);
10621
    /* Cleanup for operation */
10622
    PyMem_Free((void *)operation);
10623
    /* Cleanup for arguments */
10624
    PyMem_Free((void *)arguments);
10625
    /* Cleanup for cwd */
10626
    path_cleanup(&cwd);
10627
10628
    return return_value;
10629
}
10630
10631
#endif /* defined(MS_WINDOWS) */
10632
10633
#if defined(HAVE_GETLOADAVG)
10634
10635
PyDoc_STRVAR(os_getloadavg__doc__,
10636
"getloadavg($module, /)\n"
10637
"--\n"
10638
"\n"
10639
"Return average recent system load information.\n"
10640
"\n"
10641
"Return the number of processes in the system run queue averaged over\n"
10642
"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
10643
"Raises OSError if the load average was unobtainable.");
10644
10645
#define OS_GETLOADAVG_METHODDEF    \
10646
    {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
10647
10648
static PyObject *
10649
os_getloadavg_impl(PyObject *module);
10650
10651
static PyObject *
10652
os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
10653
0
{
10654
0
    return os_getloadavg_impl(module);
10655
0
}
10656
10657
#endif /* defined(HAVE_GETLOADAVG) */
10658
10659
PyDoc_STRVAR(os_device_encoding__doc__,
10660
"device_encoding($module, /, fd)\n"
10661
"--\n"
10662
"\n"
10663
"Return a string describing the encoding of a terminal\'s file descriptor.\n"
10664
"\n"
10665
"The file descriptor must be attached to a terminal.\n"
10666
"If the device is not a terminal, return None.");
10667
10668
#define OS_DEVICE_ENCODING_METHODDEF    \
10669
    {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
10670
10671
static PyObject *
10672
os_device_encoding_impl(PyObject *module, int fd);
10673
10674
static PyObject *
10675
os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10676
0
{
10677
0
    PyObject *return_value = NULL;
10678
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10679
10680
0
    #define NUM_KEYWORDS 1
10681
0
    static struct {
10682
0
        PyGC_Head _this_is_not_used;
10683
0
        PyObject_VAR_HEAD
10684
0
        Py_hash_t ob_hash;
10685
0
        PyObject *ob_item[NUM_KEYWORDS];
10686
0
    } _kwtuple = {
10687
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10688
0
        .ob_hash = -1,
10689
0
        .ob_item = { &_Py_ID(fd), },
10690
0
    };
10691
0
    #undef NUM_KEYWORDS
10692
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10693
10694
    #else  // !Py_BUILD_CORE
10695
    #  define KWTUPLE NULL
10696
    #endif  // !Py_BUILD_CORE
10697
10698
0
    static const char * const _keywords[] = {"fd", NULL};
10699
0
    static _PyArg_Parser _parser = {
10700
0
        .keywords = _keywords,
10701
0
        .fname = "device_encoding",
10702
0
        .kwtuple = KWTUPLE,
10703
0
    };
10704
0
    #undef KWTUPLE
10705
0
    PyObject *argsbuf[1];
10706
0
    int fd;
10707
10708
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10709
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10710
0
    if (!args) {
10711
0
        goto exit;
10712
0
    }
10713
0
    fd = PyLong_AsInt(args[0]);
10714
0
    if (fd == -1 && PyErr_Occurred()) {
10715
0
        goto exit;
10716
0
    }
10717
0
    return_value = os_device_encoding_impl(module, fd);
10718
10719
0
exit:
10720
0
    return return_value;
10721
0
}
10722
10723
#if defined(HAVE_SETRESUID)
10724
10725
PyDoc_STRVAR(os_setresuid__doc__,
10726
"setresuid($module, ruid, euid, suid, /)\n"
10727
"--\n"
10728
"\n"
10729
"Set the current process\'s real, effective, and saved user ids.");
10730
10731
#define OS_SETRESUID_METHODDEF    \
10732
    {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__},
10733
10734
static PyObject *
10735
os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
10736
10737
static PyObject *
10738
os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10739
0
{
10740
0
    PyObject *return_value = NULL;
10741
0
    uid_t ruid;
10742
0
    uid_t euid;
10743
0
    uid_t suid;
10744
10745
0
    if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
10746
0
        goto exit;
10747
0
    }
10748
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
10749
0
        goto exit;
10750
0
    }
10751
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
10752
0
        goto exit;
10753
0
    }
10754
0
    if (!_Py_Uid_Converter(args[2], &suid)) {
10755
0
        goto exit;
10756
0
    }
10757
0
    return_value = os_setresuid_impl(module, ruid, euid, suid);
10758
10759
0
exit:
10760
0
    return return_value;
10761
0
}
10762
10763
#endif /* defined(HAVE_SETRESUID) */
10764
10765
#if defined(HAVE_SETRESGID)
10766
10767
PyDoc_STRVAR(os_setresgid__doc__,
10768
"setresgid($module, rgid, egid, sgid, /)\n"
10769
"--\n"
10770
"\n"
10771
"Set the current process\'s real, effective, and saved group ids.");
10772
10773
#define OS_SETRESGID_METHODDEF    \
10774
    {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__},
10775
10776
static PyObject *
10777
os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
10778
10779
static PyObject *
10780
os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10781
0
{
10782
0
    PyObject *return_value = NULL;
10783
0
    gid_t rgid;
10784
0
    gid_t egid;
10785
0
    gid_t sgid;
10786
10787
0
    if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
10788
0
        goto exit;
10789
0
    }
10790
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
10791
0
        goto exit;
10792
0
    }
10793
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
10794
0
        goto exit;
10795
0
    }
10796
0
    if (!_Py_Gid_Converter(args[2], &sgid)) {
10797
0
        goto exit;
10798
0
    }
10799
0
    return_value = os_setresgid_impl(module, rgid, egid, sgid);
10800
10801
0
exit:
10802
0
    return return_value;
10803
0
}
10804
10805
#endif /* defined(HAVE_SETRESGID) */
10806
10807
#if defined(HAVE_GETRESUID)
10808
10809
PyDoc_STRVAR(os_getresuid__doc__,
10810
"getresuid($module, /)\n"
10811
"--\n"
10812
"\n"
10813
"Return a tuple of the current process\'s real, effective, and saved user ids.");
10814
10815
#define OS_GETRESUID_METHODDEF    \
10816
    {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
10817
10818
static PyObject *
10819
os_getresuid_impl(PyObject *module);
10820
10821
static PyObject *
10822
os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
10823
0
{
10824
0
    return os_getresuid_impl(module);
10825
0
}
10826
10827
#endif /* defined(HAVE_GETRESUID) */
10828
10829
#if defined(HAVE_GETRESGID)
10830
10831
PyDoc_STRVAR(os_getresgid__doc__,
10832
"getresgid($module, /)\n"
10833
"--\n"
10834
"\n"
10835
"Return a tuple of the current process\'s real, effective, and saved group ids.");
10836
10837
#define OS_GETRESGID_METHODDEF    \
10838
    {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
10839
10840
static PyObject *
10841
os_getresgid_impl(PyObject *module);
10842
10843
static PyObject *
10844
os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
10845
0
{
10846
0
    return os_getresgid_impl(module);
10847
0
}
10848
10849
#endif /* defined(HAVE_GETRESGID) */
10850
10851
#if defined(USE_XATTRS)
10852
10853
PyDoc_STRVAR(os_getxattr__doc__,
10854
"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
10855
"--\n"
10856
"\n"
10857
"Return the value of extended attribute attribute on path.\n"
10858
"\n"
10859
"path may be either a string, a path-like object, or an open file descriptor.\n"
10860
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
10861
"  link, getxattr will examine the symbolic link itself instead of the file\n"
10862
"  the link points to.");
10863
10864
#define OS_GETXATTR_METHODDEF    \
10865
    {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
10866
10867
static PyObject *
10868
os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
10869
                 int follow_symlinks);
10870
10871
static PyObject *
10872
os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10873
0
{
10874
0
    PyObject *return_value = NULL;
10875
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10876
10877
0
    #define NUM_KEYWORDS 3
10878
0
    static struct {
10879
0
        PyGC_Head _this_is_not_used;
10880
0
        PyObject_VAR_HEAD
10881
0
        Py_hash_t ob_hash;
10882
0
        PyObject *ob_item[NUM_KEYWORDS];
10883
0
    } _kwtuple = {
10884
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10885
0
        .ob_hash = -1,
10886
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
10887
0
    };
10888
0
    #undef NUM_KEYWORDS
10889
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10890
10891
    #else  // !Py_BUILD_CORE
10892
    #  define KWTUPLE NULL
10893
    #endif  // !Py_BUILD_CORE
10894
10895
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
10896
0
    static _PyArg_Parser _parser = {
10897
0
        .keywords = _keywords,
10898
0
        .fname = "getxattr",
10899
0
        .kwtuple = KWTUPLE,
10900
0
    };
10901
0
    #undef KWTUPLE
10902
0
    PyObject *argsbuf[3];
10903
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
10904
0
    path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1);
10905
0
    path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0);
10906
0
    int follow_symlinks = 1;
10907
10908
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10909
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10910
0
    if (!args) {
10911
0
        goto exit;
10912
0
    }
10913
0
    if (!path_converter(args[0], &path)) {
10914
0
        goto exit;
10915
0
    }
10916
0
    if (!path_converter(args[1], &attribute)) {
10917
0
        goto exit;
10918
0
    }
10919
0
    if (!noptargs) {
10920
0
        goto skip_optional_kwonly;
10921
0
    }
10922
0
    follow_symlinks = PyObject_IsTrue(args[2]);
10923
0
    if (follow_symlinks < 0) {
10924
0
        goto exit;
10925
0
    }
10926
0
skip_optional_kwonly:
10927
0
    return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
10928
10929
0
exit:
10930
    /* Cleanup for path */
10931
0
    path_cleanup(&path);
10932
    /* Cleanup for attribute */
10933
0
    path_cleanup(&attribute);
10934
10935
0
    return return_value;
10936
0
}
10937
10938
#endif /* defined(USE_XATTRS) */
10939
10940
#if defined(USE_XATTRS)
10941
10942
PyDoc_STRVAR(os_setxattr__doc__,
10943
"setxattr($module, /, path, attribute, value, flags=0, *,\n"
10944
"         follow_symlinks=True)\n"
10945
"--\n"
10946
"\n"
10947
"Set extended attribute attribute on path to value.\n"
10948
"\n"
10949
"path may be either a string, a path-like object,  or an open file descriptor.\n"
10950
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
10951
"  link, setxattr will modify the symbolic link itself instead of the file\n"
10952
"  the link points to.");
10953
10954
#define OS_SETXATTR_METHODDEF    \
10955
    {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
10956
10957
static PyObject *
10958
os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
10959
                 Py_buffer *value, int flags, int follow_symlinks);
10960
10961
static PyObject *
10962
os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10963
0
{
10964
0
    PyObject *return_value = NULL;
10965
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10966
10967
0
    #define NUM_KEYWORDS 5
10968
0
    static struct {
10969
0
        PyGC_Head _this_is_not_used;
10970
0
        PyObject_VAR_HEAD
10971
0
        Py_hash_t ob_hash;
10972
0
        PyObject *ob_item[NUM_KEYWORDS];
10973
0
    } _kwtuple = {
10974
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10975
0
        .ob_hash = -1,
10976
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
10977
0
    };
10978
0
    #undef NUM_KEYWORDS
10979
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10980
10981
    #else  // !Py_BUILD_CORE
10982
    #  define KWTUPLE NULL
10983
    #endif  // !Py_BUILD_CORE
10984
10985
0
    static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
10986
0
    static _PyArg_Parser _parser = {
10987
0
        .keywords = _keywords,
10988
0
        .fname = "setxattr",
10989
0
        .kwtuple = KWTUPLE,
10990
0
    };
10991
0
    #undef KWTUPLE
10992
0
    PyObject *argsbuf[5];
10993
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
10994
0
    path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1);
10995
0
    path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0);
10996
0
    Py_buffer value = {NULL, NULL};
10997
0
    int flags = 0;
10998
0
    int follow_symlinks = 1;
10999
11000
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11001
0
            /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11002
0
    if (!args) {
11003
0
        goto exit;
11004
0
    }
11005
0
    if (!path_converter(args[0], &path)) {
11006
0
        goto exit;
11007
0
    }
11008
0
    if (!path_converter(args[1], &attribute)) {
11009
0
        goto exit;
11010
0
    }
11011
0
    if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
11012
0
        goto exit;
11013
0
    }
11014
0
    if (!noptargs) {
11015
0
        goto skip_optional_pos;
11016
0
    }
11017
0
    if (args[3]) {
11018
0
        flags = PyLong_AsInt(args[3]);
11019
0
        if (flags == -1 && PyErr_Occurred()) {
11020
0
            goto exit;
11021
0
        }
11022
0
        if (!--noptargs) {
11023
0
            goto skip_optional_pos;
11024
0
        }
11025
0
    }
11026
0
skip_optional_pos:
11027
0
    if (!noptargs) {
11028
0
        goto skip_optional_kwonly;
11029
0
    }
11030
0
    follow_symlinks = PyObject_IsTrue(args[4]);
11031
0
    if (follow_symlinks < 0) {
11032
0
        goto exit;
11033
0
    }
11034
0
skip_optional_kwonly:
11035
0
    return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
11036
11037
0
exit:
11038
    /* Cleanup for path */
11039
0
    path_cleanup(&path);
11040
    /* Cleanup for attribute */
11041
0
    path_cleanup(&attribute);
11042
    /* Cleanup for value */
11043
0
    if (value.obj) {
11044
0
       PyBuffer_Release(&value);
11045
0
    }
11046
11047
0
    return return_value;
11048
0
}
11049
11050
#endif /* defined(USE_XATTRS) */
11051
11052
#if defined(USE_XATTRS)
11053
11054
PyDoc_STRVAR(os_removexattr__doc__,
11055
"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
11056
"--\n"
11057
"\n"
11058
"Remove extended attribute attribute on path.\n"
11059
"\n"
11060
"path may be either a string, a path-like object, or an open file descriptor.\n"
11061
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
11062
"  link, removexattr will modify the symbolic link itself instead of the file\n"
11063
"  the link points to.");
11064
11065
#define OS_REMOVEXATTR_METHODDEF    \
11066
    {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
11067
11068
static PyObject *
11069
os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
11070
                    int follow_symlinks);
11071
11072
static PyObject *
11073
os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11074
0
{
11075
0
    PyObject *return_value = NULL;
11076
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11077
11078
0
    #define NUM_KEYWORDS 3
11079
0
    static struct {
11080
0
        PyGC_Head _this_is_not_used;
11081
0
        PyObject_VAR_HEAD
11082
0
        Py_hash_t ob_hash;
11083
0
        PyObject *ob_item[NUM_KEYWORDS];
11084
0
    } _kwtuple = {
11085
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11086
0
        .ob_hash = -1,
11087
0
        .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
11088
0
    };
11089
0
    #undef NUM_KEYWORDS
11090
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11091
11092
    #else  // !Py_BUILD_CORE
11093
    #  define KWTUPLE NULL
11094
    #endif  // !Py_BUILD_CORE
11095
11096
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
11097
0
    static _PyArg_Parser _parser = {
11098
0
        .keywords = _keywords,
11099
0
        .fname = "removexattr",
11100
0
        .kwtuple = KWTUPLE,
11101
0
    };
11102
0
    #undef KWTUPLE
11103
0
    PyObject *argsbuf[3];
11104
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
11105
0
    path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1);
11106
0
    path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0);
11107
0
    int follow_symlinks = 1;
11108
11109
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11110
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11111
0
    if (!args) {
11112
0
        goto exit;
11113
0
    }
11114
0
    if (!path_converter(args[0], &path)) {
11115
0
        goto exit;
11116
0
    }
11117
0
    if (!path_converter(args[1], &attribute)) {
11118
0
        goto exit;
11119
0
    }
11120
0
    if (!noptargs) {
11121
0
        goto skip_optional_kwonly;
11122
0
    }
11123
0
    follow_symlinks = PyObject_IsTrue(args[2]);
11124
0
    if (follow_symlinks < 0) {
11125
0
        goto exit;
11126
0
    }
11127
0
skip_optional_kwonly:
11128
0
    return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
11129
11130
0
exit:
11131
    /* Cleanup for path */
11132
0
    path_cleanup(&path);
11133
    /* Cleanup for attribute */
11134
0
    path_cleanup(&attribute);
11135
11136
0
    return return_value;
11137
0
}
11138
11139
#endif /* defined(USE_XATTRS) */
11140
11141
#if defined(USE_XATTRS)
11142
11143
PyDoc_STRVAR(os_listxattr__doc__,
11144
"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
11145
"--\n"
11146
"\n"
11147
"Return a list of extended attributes on path.\n"
11148
"\n"
11149
"path may be either None, a string, a path-like object, or an open file descriptor.\n"
11150
"if path is None, listxattr will examine the current directory.\n"
11151
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
11152
"  link, listxattr will examine the symbolic link itself instead of the file\n"
11153
"  the link points to.");
11154
11155
#define OS_LISTXATTR_METHODDEF    \
11156
    {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
11157
11158
static PyObject *
11159
os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
11160
11161
static PyObject *
11162
os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11163
0
{
11164
0
    PyObject *return_value = NULL;
11165
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11166
11167
0
    #define NUM_KEYWORDS 2
11168
0
    static struct {
11169
0
        PyGC_Head _this_is_not_used;
11170
0
        PyObject_VAR_HEAD
11171
0
        Py_hash_t ob_hash;
11172
0
        PyObject *ob_item[NUM_KEYWORDS];
11173
0
    } _kwtuple = {
11174
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11175
0
        .ob_hash = -1,
11176
0
        .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), },
11177
0
    };
11178
0
    #undef NUM_KEYWORDS
11179
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11180
11181
    #else  // !Py_BUILD_CORE
11182
    #  define KWTUPLE NULL
11183
    #endif  // !Py_BUILD_CORE
11184
11185
0
    static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
11186
0
    static _PyArg_Parser _parser = {
11187
0
        .keywords = _keywords,
11188
0
        .fname = "listxattr",
11189
0
        .kwtuple = KWTUPLE,
11190
0
    };
11191
0
    #undef KWTUPLE
11192
0
    PyObject *argsbuf[2];
11193
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
11194
0
    path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1);
11195
0
    int follow_symlinks = 1;
11196
11197
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11198
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11199
0
    if (!args) {
11200
0
        goto exit;
11201
0
    }
11202
0
    if (!noptargs) {
11203
0
        goto skip_optional_pos;
11204
0
    }
11205
0
    if (args[0]) {
11206
0
        if (!path_converter(args[0], &path)) {
11207
0
            goto exit;
11208
0
        }
11209
0
        if (!--noptargs) {
11210
0
            goto skip_optional_pos;
11211
0
        }
11212
0
    }
11213
0
skip_optional_pos:
11214
0
    if (!noptargs) {
11215
0
        goto skip_optional_kwonly;
11216
0
    }
11217
0
    follow_symlinks = PyObject_IsTrue(args[1]);
11218
0
    if (follow_symlinks < 0) {
11219
0
        goto exit;
11220
0
    }
11221
0
skip_optional_kwonly:
11222
0
    return_value = os_listxattr_impl(module, &path, follow_symlinks);
11223
11224
0
exit:
11225
    /* Cleanup for path */
11226
0
    path_cleanup(&path);
11227
11228
0
    return return_value;
11229
0
}
11230
11231
#endif /* defined(USE_XATTRS) */
11232
11233
PyDoc_STRVAR(os_urandom__doc__,
11234
"urandom($module, size, /)\n"
11235
"--\n"
11236
"\n"
11237
"Return a bytes object containing random bytes suitable for cryptographic use.");
11238
11239
#define OS_URANDOM_METHODDEF    \
11240
    {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
11241
11242
static PyObject *
11243
os_urandom_impl(PyObject *module, Py_ssize_t size);
11244
11245
static PyObject *
11246
os_urandom(PyObject *module, PyObject *arg)
11247
0
{
11248
0
    PyObject *return_value = NULL;
11249
0
    Py_ssize_t size;
11250
11251
0
    {
11252
0
        Py_ssize_t ival = -1;
11253
0
        PyObject *iobj = _PyNumber_Index(arg);
11254
0
        if (iobj != NULL) {
11255
0
            ival = PyLong_AsSsize_t(iobj);
11256
0
            Py_DECREF(iobj);
11257
0
        }
11258
0
        if (ival == -1 && PyErr_Occurred()) {
11259
0
            goto exit;
11260
0
        }
11261
0
        size = ival;
11262
0
        if (size < 0) {
11263
0
            PyErr_SetString(PyExc_ValueError,
11264
0
                            "size cannot be negative");
11265
0
            goto exit;
11266
0
        }
11267
0
    }
11268
0
    return_value = os_urandom_impl(module, size);
11269
11270
0
exit:
11271
0
    return return_value;
11272
0
}
11273
11274
#if defined(HAVE_MEMFD_CREATE)
11275
11276
PyDoc_STRVAR(os_memfd_create__doc__,
11277
"memfd_create($module, /, name, flags=MFD_CLOEXEC)\n"
11278
"--\n"
11279
"\n");
11280
11281
#define OS_MEMFD_CREATE_METHODDEF    \
11282
    {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__},
11283
11284
static PyObject *
11285
os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags);
11286
11287
static PyObject *
11288
os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11289
0
{
11290
0
    PyObject *return_value = NULL;
11291
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11292
11293
0
    #define NUM_KEYWORDS 2
11294
0
    static struct {
11295
0
        PyGC_Head _this_is_not_used;
11296
0
        PyObject_VAR_HEAD
11297
0
        Py_hash_t ob_hash;
11298
0
        PyObject *ob_item[NUM_KEYWORDS];
11299
0
    } _kwtuple = {
11300
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11301
0
        .ob_hash = -1,
11302
0
        .ob_item = { &_Py_ID(name), &_Py_ID(flags), },
11303
0
    };
11304
0
    #undef NUM_KEYWORDS
11305
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11306
11307
    #else  // !Py_BUILD_CORE
11308
    #  define KWTUPLE NULL
11309
    #endif  // !Py_BUILD_CORE
11310
11311
0
    static const char * const _keywords[] = {"name", "flags", NULL};
11312
0
    static _PyArg_Parser _parser = {
11313
0
        .keywords = _keywords,
11314
0
        .fname = "memfd_create",
11315
0
        .kwtuple = KWTUPLE,
11316
0
    };
11317
0
    #undef KWTUPLE
11318
0
    PyObject *argsbuf[2];
11319
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11320
0
    PyObject *name = NULL;
11321
0
    unsigned int flags = MFD_CLOEXEC;
11322
11323
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11324
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11325
0
    if (!args) {
11326
0
        goto exit;
11327
0
    }
11328
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
11329
0
        goto exit;
11330
0
    }
11331
0
    if (!noptargs) {
11332
0
        goto skip_optional_pos;
11333
0
    }
11334
0
    {
11335
0
        Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned int),
11336
0
                Py_ASNATIVEBYTES_NATIVE_ENDIAN |
11337
0
                Py_ASNATIVEBYTES_ALLOW_INDEX |
11338
0
                Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
11339
0
        if (_bytes < 0) {
11340
0
            goto exit;
11341
0
        }
11342
0
        if ((size_t)_bytes > sizeof(unsigned int)) {
11343
0
            if (PyErr_WarnEx(PyExc_DeprecationWarning,
11344
0
                "integer value out of range", 1) < 0)
11345
0
            {
11346
0
                goto exit;
11347
0
            }
11348
0
        }
11349
0
    }
11350
0
skip_optional_pos:
11351
0
    return_value = os_memfd_create_impl(module, name, flags);
11352
11353
0
exit:
11354
    /* Cleanup for name */
11355
0
    Py_XDECREF(name);
11356
11357
0
    return return_value;
11358
0
}
11359
11360
#endif /* defined(HAVE_MEMFD_CREATE) */
11361
11362
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11363
11364
PyDoc_STRVAR(os_eventfd__doc__,
11365
"eventfd($module, /, initval, flags=EFD_CLOEXEC)\n"
11366
"--\n"
11367
"\n"
11368
"Creates and returns an event notification file descriptor.");
11369
11370
#define OS_EVENTFD_METHODDEF    \
11371
    {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__},
11372
11373
static PyObject *
11374
os_eventfd_impl(PyObject *module, unsigned int initval, int flags);
11375
11376
static PyObject *
11377
os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11378
0
{
11379
0
    PyObject *return_value = NULL;
11380
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11381
11382
0
    #define NUM_KEYWORDS 2
11383
0
    static struct {
11384
0
        PyGC_Head _this_is_not_used;
11385
0
        PyObject_VAR_HEAD
11386
0
        Py_hash_t ob_hash;
11387
0
        PyObject *ob_item[NUM_KEYWORDS];
11388
0
    } _kwtuple = {
11389
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11390
0
        .ob_hash = -1,
11391
0
        .ob_item = { &_Py_ID(initval), &_Py_ID(flags), },
11392
0
    };
11393
0
    #undef NUM_KEYWORDS
11394
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11395
11396
    #else  // !Py_BUILD_CORE
11397
    #  define KWTUPLE NULL
11398
    #endif  // !Py_BUILD_CORE
11399
11400
0
    static const char * const _keywords[] = {"initval", "flags", NULL};
11401
0
    static _PyArg_Parser _parser = {
11402
0
        .keywords = _keywords,
11403
0
        .fname = "eventfd",
11404
0
        .kwtuple = KWTUPLE,
11405
0
    };
11406
0
    #undef KWTUPLE
11407
0
    PyObject *argsbuf[2];
11408
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11409
0
    unsigned int initval;
11410
0
    int flags = EFD_CLOEXEC;
11411
11412
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11413
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11414
0
    if (!args) {
11415
0
        goto exit;
11416
0
    }
11417
0
    if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) {
11418
0
        goto exit;
11419
0
    }
11420
0
    if (!noptargs) {
11421
0
        goto skip_optional_pos;
11422
0
    }
11423
0
    flags = PyLong_AsInt(args[1]);
11424
0
    if (flags == -1 && PyErr_Occurred()) {
11425
0
        goto exit;
11426
0
    }
11427
0
skip_optional_pos:
11428
0
    return_value = os_eventfd_impl(module, initval, flags);
11429
11430
0
exit:
11431
0
    return return_value;
11432
0
}
11433
11434
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11435
11436
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11437
11438
PyDoc_STRVAR(os_eventfd_read__doc__,
11439
"eventfd_read($module, /, fd)\n"
11440
"--\n"
11441
"\n"
11442
"Read eventfd value");
11443
11444
#define OS_EVENTFD_READ_METHODDEF    \
11445
    {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__},
11446
11447
static PyObject *
11448
os_eventfd_read_impl(PyObject *module, int fd);
11449
11450
static PyObject *
11451
os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11452
0
{
11453
0
    PyObject *return_value = NULL;
11454
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11455
11456
0
    #define NUM_KEYWORDS 1
11457
0
    static struct {
11458
0
        PyGC_Head _this_is_not_used;
11459
0
        PyObject_VAR_HEAD
11460
0
        Py_hash_t ob_hash;
11461
0
        PyObject *ob_item[NUM_KEYWORDS];
11462
0
    } _kwtuple = {
11463
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11464
0
        .ob_hash = -1,
11465
0
        .ob_item = { &_Py_ID(fd), },
11466
0
    };
11467
0
    #undef NUM_KEYWORDS
11468
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11469
11470
    #else  // !Py_BUILD_CORE
11471
    #  define KWTUPLE NULL
11472
    #endif  // !Py_BUILD_CORE
11473
11474
0
    static const char * const _keywords[] = {"fd", NULL};
11475
0
    static _PyArg_Parser _parser = {
11476
0
        .keywords = _keywords,
11477
0
        .fname = "eventfd_read",
11478
0
        .kwtuple = KWTUPLE,
11479
0
    };
11480
0
    #undef KWTUPLE
11481
0
    PyObject *argsbuf[1];
11482
0
    int fd;
11483
11484
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11485
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11486
0
    if (!args) {
11487
0
        goto exit;
11488
0
    }
11489
0
    fd = PyObject_AsFileDescriptor(args[0]);
11490
0
    if (fd < 0) {
11491
0
        goto exit;
11492
0
    }
11493
0
    return_value = os_eventfd_read_impl(module, fd);
11494
11495
0
exit:
11496
0
    return return_value;
11497
0
}
11498
11499
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11500
11501
#if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11502
11503
PyDoc_STRVAR(os_eventfd_write__doc__,
11504
"eventfd_write($module, /, fd, value)\n"
11505
"--\n"
11506
"\n"
11507
"Write eventfd value.");
11508
11509
#define OS_EVENTFD_WRITE_METHODDEF    \
11510
    {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__},
11511
11512
static PyObject *
11513
os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value);
11514
11515
static PyObject *
11516
os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11517
0
{
11518
0
    PyObject *return_value = NULL;
11519
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11520
11521
0
    #define NUM_KEYWORDS 2
11522
0
    static struct {
11523
0
        PyGC_Head _this_is_not_used;
11524
0
        PyObject_VAR_HEAD
11525
0
        Py_hash_t ob_hash;
11526
0
        PyObject *ob_item[NUM_KEYWORDS];
11527
0
    } _kwtuple = {
11528
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11529
0
        .ob_hash = -1,
11530
0
        .ob_item = { &_Py_ID(fd), &_Py_ID(value), },
11531
0
    };
11532
0
    #undef NUM_KEYWORDS
11533
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11534
11535
    #else  // !Py_BUILD_CORE
11536
    #  define KWTUPLE NULL
11537
    #endif  // !Py_BUILD_CORE
11538
11539
0
    static const char * const _keywords[] = {"fd", "value", NULL};
11540
0
    static _PyArg_Parser _parser = {
11541
0
        .keywords = _keywords,
11542
0
        .fname = "eventfd_write",
11543
0
        .kwtuple = KWTUPLE,
11544
0
    };
11545
0
    #undef KWTUPLE
11546
0
    PyObject *argsbuf[2];
11547
0
    int fd;
11548
0
    unsigned long long value;
11549
11550
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11551
0
            /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11552
0
    if (!args) {
11553
0
        goto exit;
11554
0
    }
11555
0
    fd = PyObject_AsFileDescriptor(args[0]);
11556
0
    if (fd < 0) {
11557
0
        goto exit;
11558
0
    }
11559
0
    if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) {
11560
0
        goto exit;
11561
0
    }
11562
0
    return_value = os_eventfd_write_impl(module, fd, value);
11563
11564
0
exit:
11565
0
    return return_value;
11566
0
}
11567
11568
#endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11569
11570
#if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL))
11571
11572
PyDoc_STRVAR(os_get_terminal_size__doc__,
11573
"get_terminal_size($module, fd=<unrepresentable>, /)\n"
11574
"--\n"
11575
"\n"
11576
"Return the size of the terminal window as (columns, lines).\n"
11577
"\n"
11578
"The optional argument fd (default standard output) specifies\n"
11579
"which file descriptor should be queried.\n"
11580
"\n"
11581
"If the file descriptor is not connected to a terminal, an OSError\n"
11582
"is thrown.\n"
11583
"\n"
11584
"This function will only be defined if an implementation is\n"
11585
"available for this system.\n"
11586
"\n"
11587
"shutil.get_terminal_size is the high-level function which should\n"
11588
"normally be used, os.get_terminal_size is the low-level implementation.");
11589
11590
#define OS_GET_TERMINAL_SIZE_METHODDEF    \
11591
    {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__},
11592
11593
static PyObject *
11594
os_get_terminal_size_impl(PyObject *module, int fd);
11595
11596
static PyObject *
11597
os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11598
0
{
11599
0
    PyObject *return_value = NULL;
11600
0
    int fd = fileno(stdout);
11601
11602
0
    if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) {
11603
0
        goto exit;
11604
0
    }
11605
0
    if (nargs < 1) {
11606
0
        goto skip_optional;
11607
0
    }
11608
0
    fd = PyLong_AsInt(args[0]);
11609
0
    if (fd == -1 && PyErr_Occurred()) {
11610
0
        goto exit;
11611
0
    }
11612
0
skip_optional:
11613
0
    return_value = os_get_terminal_size_impl(module, fd);
11614
11615
0
exit:
11616
0
    return return_value;
11617
0
}
11618
11619
#endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */
11620
11621
PyDoc_STRVAR(os_cpu_count__doc__,
11622
"cpu_count($module, /)\n"
11623
"--\n"
11624
"\n"
11625
"Return the number of logical CPUs in the system.\n"
11626
"\n"
11627
"Return None if indeterminable.");
11628
11629
#define OS_CPU_COUNT_METHODDEF    \
11630
    {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
11631
11632
static PyObject *
11633
os_cpu_count_impl(PyObject *module);
11634
11635
static PyObject *
11636
os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
11637
0
{
11638
0
    return os_cpu_count_impl(module);
11639
0
}
11640
11641
PyDoc_STRVAR(os_get_inheritable__doc__,
11642
"get_inheritable($module, fd, /)\n"
11643
"--\n"
11644
"\n"
11645
"Get the close-on-exe flag of the specified file descriptor.");
11646
11647
#define OS_GET_INHERITABLE_METHODDEF    \
11648
    {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
11649
11650
static int
11651
os_get_inheritable_impl(PyObject *module, int fd);
11652
11653
static PyObject *
11654
os_get_inheritable(PyObject *module, PyObject *arg)
11655
0
{
11656
0
    PyObject *return_value = NULL;
11657
0
    int fd;
11658
0
    int _return_value;
11659
11660
0
    fd = PyLong_AsInt(arg);
11661
0
    if (fd == -1 && PyErr_Occurred()) {
11662
0
        goto exit;
11663
0
    }
11664
0
    _return_value = os_get_inheritable_impl(module, fd);
11665
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11666
0
        goto exit;
11667
0
    }
11668
0
    return_value = PyBool_FromLong((long)_return_value);
11669
11670
0
exit:
11671
0
    return return_value;
11672
0
}
11673
11674
PyDoc_STRVAR(os_set_inheritable__doc__,
11675
"set_inheritable($module, fd, inheritable, /)\n"
11676
"--\n"
11677
"\n"
11678
"Set the inheritable flag of the specified file descriptor.");
11679
11680
#define OS_SET_INHERITABLE_METHODDEF    \
11681
    {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__},
11682
11683
static PyObject *
11684
os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
11685
11686
static PyObject *
11687
os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11688
0
{
11689
0
    PyObject *return_value = NULL;
11690
0
    int fd;
11691
0
    int inheritable;
11692
11693
0
    if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
11694
0
        goto exit;
11695
0
    }
11696
0
    fd = PyLong_AsInt(args[0]);
11697
0
    if (fd == -1 && PyErr_Occurred()) {
11698
0
        goto exit;
11699
0
    }
11700
0
    inheritable = PyLong_AsInt(args[1]);
11701
0
    if (inheritable == -1 && PyErr_Occurred()) {
11702
0
        goto exit;
11703
0
    }
11704
0
    return_value = os_set_inheritable_impl(module, fd, inheritable);
11705
11706
0
exit:
11707
0
    return return_value;
11708
0
}
11709
11710
#if defined(MS_WINDOWS)
11711
11712
PyDoc_STRVAR(os_get_handle_inheritable__doc__,
11713
"get_handle_inheritable($module, handle, /)\n"
11714
"--\n"
11715
"\n"
11716
"Get the close-on-exe flag of the specified file descriptor.");
11717
11718
#define OS_GET_HANDLE_INHERITABLE_METHODDEF    \
11719
    {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
11720
11721
static int
11722
os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
11723
11724
static PyObject *
11725
os_get_handle_inheritable(PyObject *module, PyObject *arg)
11726
{
11727
    PyObject *return_value = NULL;
11728
    intptr_t handle;
11729
    int _return_value;
11730
11731
    handle = (intptr_t)PyLong_AsVoidPtr(arg);
11732
    if (!handle && PyErr_Occurred()) {
11733
        goto exit;
11734
    }
11735
    _return_value = os_get_handle_inheritable_impl(module, handle);
11736
    if ((_return_value == -1) && PyErr_Occurred()) {
11737
        goto exit;
11738
    }
11739
    return_value = PyBool_FromLong((long)_return_value);
11740
11741
exit:
11742
    return return_value;
11743
}
11744
11745
#endif /* defined(MS_WINDOWS) */
11746
11747
#if defined(MS_WINDOWS)
11748
11749
PyDoc_STRVAR(os_set_handle_inheritable__doc__,
11750
"set_handle_inheritable($module, handle, inheritable, /)\n"
11751
"--\n"
11752
"\n"
11753
"Set the inheritable flag of the specified handle.");
11754
11755
#define OS_SET_HANDLE_INHERITABLE_METHODDEF    \
11756
    {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__},
11757
11758
static PyObject *
11759
os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
11760
                               int inheritable);
11761
11762
static PyObject *
11763
os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11764
{
11765
    PyObject *return_value = NULL;
11766
    intptr_t handle;
11767
    int inheritable;
11768
11769
    if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) {
11770
        goto exit;
11771
    }
11772
    handle = (intptr_t)PyLong_AsVoidPtr(args[0]);
11773
    if (!handle && PyErr_Occurred()) {
11774
        goto exit;
11775
    }
11776
    inheritable = PyObject_IsTrue(args[1]);
11777
    if (inheritable < 0) {
11778
        goto exit;
11779
    }
11780
    return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
11781
11782
exit:
11783
    return return_value;
11784
}
11785
11786
#endif /* defined(MS_WINDOWS) */
11787
11788
PyDoc_STRVAR(os_get_blocking__doc__,
11789
"get_blocking($module, fd, /)\n"
11790
"--\n"
11791
"\n"
11792
"Get the blocking mode of the file descriptor.\n"
11793
"\n"
11794
"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
11795
11796
#define OS_GET_BLOCKING_METHODDEF    \
11797
    {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
11798
11799
static int
11800
os_get_blocking_impl(PyObject *module, int fd);
11801
11802
static PyObject *
11803
os_get_blocking(PyObject *module, PyObject *arg)
11804
0
{
11805
0
    PyObject *return_value = NULL;
11806
0
    int fd;
11807
0
    int _return_value;
11808
11809
0
    fd = PyLong_AsInt(arg);
11810
0
    if (fd == -1 && PyErr_Occurred()) {
11811
0
        goto exit;
11812
0
    }
11813
0
    _return_value = os_get_blocking_impl(module, fd);
11814
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11815
0
        goto exit;
11816
0
    }
11817
0
    return_value = PyBool_FromLong((long)_return_value);
11818
11819
0
exit:
11820
0
    return return_value;
11821
0
}
11822
11823
PyDoc_STRVAR(os_set_blocking__doc__,
11824
"set_blocking($module, fd, blocking, /)\n"
11825
"--\n"
11826
"\n"
11827
"Set the blocking mode of the specified file descriptor.\n"
11828
"\n"
11829
"Set the O_NONBLOCK flag if blocking is False,\n"
11830
"clear the O_NONBLOCK flag otherwise.");
11831
11832
#define OS_SET_BLOCKING_METHODDEF    \
11833
    {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__},
11834
11835
static PyObject *
11836
os_set_blocking_impl(PyObject *module, int fd, int blocking);
11837
11838
static PyObject *
11839
os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11840
0
{
11841
0
    PyObject *return_value = NULL;
11842
0
    int fd;
11843
0
    int blocking;
11844
11845
0
    if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
11846
0
        goto exit;
11847
0
    }
11848
0
    fd = PyLong_AsInt(args[0]);
11849
0
    if (fd == -1 && PyErr_Occurred()) {
11850
0
        goto exit;
11851
0
    }
11852
0
    blocking = PyObject_IsTrue(args[1]);
11853
0
    if (blocking < 0) {
11854
0
        goto exit;
11855
0
    }
11856
0
    return_value = os_set_blocking_impl(module, fd, blocking);
11857
11858
0
exit:
11859
0
    return return_value;
11860
0
}
11861
11862
PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
11863
"is_symlink($self, /)\n"
11864
"--\n"
11865
"\n"
11866
"Return True if the entry is a symbolic link; cached per entry.");
11867
11868
#define OS_DIRENTRY_IS_SYMLINK_METHODDEF    \
11869
    {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__},
11870
11871
static int
11872
os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class);
11873
11874
static PyObject *
11875
os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11876
0
{
11877
0
    PyObject *return_value = NULL;
11878
0
    int _return_value;
11879
11880
0
    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
11881
0
        PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
11882
0
        goto exit;
11883
0
    }
11884
0
    _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class);
11885
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11886
0
        goto exit;
11887
0
    }
11888
0
    return_value = PyBool_FromLong((long)_return_value);
11889
11890
0
exit:
11891
0
    return return_value;
11892
0
}
11893
11894
PyDoc_STRVAR(os_DirEntry_is_junction__doc__,
11895
"is_junction($self, /)\n"
11896
"--\n"
11897
"\n"
11898
"Return True if the entry is a junction; cached per entry.");
11899
11900
#define OS_DIRENTRY_IS_JUNCTION_METHODDEF    \
11901
    {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__},
11902
11903
static int
11904
os_DirEntry_is_junction_impl(DirEntry *self);
11905
11906
static PyObject *
11907
os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored))
11908
0
{
11909
0
    PyObject *return_value = NULL;
11910
0
    int _return_value;
11911
11912
0
    _return_value = os_DirEntry_is_junction_impl((DirEntry *)self);
11913
0
    if ((_return_value == -1) && PyErr_Occurred()) {
11914
0
        goto exit;
11915
0
    }
11916
0
    return_value = PyBool_FromLong((long)_return_value);
11917
11918
0
exit:
11919
0
    return return_value;
11920
0
}
11921
11922
PyDoc_STRVAR(os_DirEntry_stat__doc__,
11923
"stat($self, /, *, follow_symlinks=True)\n"
11924
"--\n"
11925
"\n"
11926
"Return stat_result object for the entry; cached per entry.");
11927
11928
#define OS_DIRENTRY_STAT_METHODDEF    \
11929
    {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
11930
11931
static PyObject *
11932
os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class,
11933
                      int follow_symlinks);
11934
11935
static PyObject *
11936
os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11937
0
{
11938
0
    PyObject *return_value = NULL;
11939
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11940
11941
0
    #define NUM_KEYWORDS 1
11942
0
    static struct {
11943
0
        PyGC_Head _this_is_not_used;
11944
0
        PyObject_VAR_HEAD
11945
0
        Py_hash_t ob_hash;
11946
0
        PyObject *ob_item[NUM_KEYWORDS];
11947
0
    } _kwtuple = {
11948
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11949
0
        .ob_hash = -1,
11950
0
        .ob_item = { &_Py_ID(follow_symlinks), },
11951
0
    };
11952
0
    #undef NUM_KEYWORDS
11953
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11954
11955
    #else  // !Py_BUILD_CORE
11956
    #  define KWTUPLE NULL
11957
    #endif  // !Py_BUILD_CORE
11958
11959
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
11960
0
    static _PyArg_Parser _parser = {
11961
0
        .keywords = _keywords,
11962
0
        .fname = "stat",
11963
0
        .kwtuple = KWTUPLE,
11964
0
    };
11965
0
    #undef KWTUPLE
11966
0
    PyObject *argsbuf[1];
11967
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
11968
0
    int follow_symlinks = 1;
11969
11970
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11971
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11972
0
    if (!args) {
11973
0
        goto exit;
11974
0
    }
11975
0
    if (!noptargs) {
11976
0
        goto skip_optional_kwonly;
11977
0
    }
11978
0
    follow_symlinks = PyObject_IsTrue(args[0]);
11979
0
    if (follow_symlinks < 0) {
11980
0
        goto exit;
11981
0
    }
11982
0
skip_optional_kwonly:
11983
0
    return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks);
11984
11985
0
exit:
11986
0
    return return_value;
11987
0
}
11988
11989
PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
11990
"is_dir($self, /, *, follow_symlinks=True)\n"
11991
"--\n"
11992
"\n"
11993
"Return True if the entry is a directory; cached per entry.");
11994
11995
#define OS_DIRENTRY_IS_DIR_METHODDEF    \
11996
    {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
11997
11998
static int
11999
os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class,
12000
                        int follow_symlinks);
12001
12002
static PyObject *
12003
os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12004
0
{
12005
0
    PyObject *return_value = NULL;
12006
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12007
12008
0
    #define NUM_KEYWORDS 1
12009
0
    static struct {
12010
0
        PyGC_Head _this_is_not_used;
12011
0
        PyObject_VAR_HEAD
12012
0
        Py_hash_t ob_hash;
12013
0
        PyObject *ob_item[NUM_KEYWORDS];
12014
0
    } _kwtuple = {
12015
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12016
0
        .ob_hash = -1,
12017
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12018
0
    };
12019
0
    #undef NUM_KEYWORDS
12020
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12021
12022
    #else  // !Py_BUILD_CORE
12023
    #  define KWTUPLE NULL
12024
    #endif  // !Py_BUILD_CORE
12025
12026
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12027
0
    static _PyArg_Parser _parser = {
12028
0
        .keywords = _keywords,
12029
0
        .fname = "is_dir",
12030
0
        .kwtuple = KWTUPLE,
12031
0
    };
12032
0
    #undef KWTUPLE
12033
0
    PyObject *argsbuf[1];
12034
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12035
0
    int follow_symlinks = 1;
12036
0
    int _return_value;
12037
12038
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12039
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12040
0
    if (!args) {
12041
0
        goto exit;
12042
0
    }
12043
0
    if (!noptargs) {
12044
0
        goto skip_optional_kwonly;
12045
0
    }
12046
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12047
0
    if (follow_symlinks < 0) {
12048
0
        goto exit;
12049
0
    }
12050
0
skip_optional_kwonly:
12051
0
    _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks);
12052
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12053
0
        goto exit;
12054
0
    }
12055
0
    return_value = PyBool_FromLong((long)_return_value);
12056
12057
0
exit:
12058
0
    return return_value;
12059
0
}
12060
12061
PyDoc_STRVAR(os_DirEntry_is_file__doc__,
12062
"is_file($self, /, *, follow_symlinks=True)\n"
12063
"--\n"
12064
"\n"
12065
"Return True if the entry is a file; cached per entry.");
12066
12067
#define OS_DIRENTRY_IS_FILE_METHODDEF    \
12068
    {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
12069
12070
static int
12071
os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class,
12072
                         int follow_symlinks);
12073
12074
static PyObject *
12075
os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12076
0
{
12077
0
    PyObject *return_value = NULL;
12078
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12079
12080
0
    #define NUM_KEYWORDS 1
12081
0
    static struct {
12082
0
        PyGC_Head _this_is_not_used;
12083
0
        PyObject_VAR_HEAD
12084
0
        Py_hash_t ob_hash;
12085
0
        PyObject *ob_item[NUM_KEYWORDS];
12086
0
    } _kwtuple = {
12087
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12088
0
        .ob_hash = -1,
12089
0
        .ob_item = { &_Py_ID(follow_symlinks), },
12090
0
    };
12091
0
    #undef NUM_KEYWORDS
12092
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12093
12094
    #else  // !Py_BUILD_CORE
12095
    #  define KWTUPLE NULL
12096
    #endif  // !Py_BUILD_CORE
12097
12098
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
12099
0
    static _PyArg_Parser _parser = {
12100
0
        .keywords = _keywords,
12101
0
        .fname = "is_file",
12102
0
        .kwtuple = KWTUPLE,
12103
0
    };
12104
0
    #undef KWTUPLE
12105
0
    PyObject *argsbuf[1];
12106
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12107
0
    int follow_symlinks = 1;
12108
0
    int _return_value;
12109
12110
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12111
0
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12112
0
    if (!args) {
12113
0
        goto exit;
12114
0
    }
12115
0
    if (!noptargs) {
12116
0
        goto skip_optional_kwonly;
12117
0
    }
12118
0
    follow_symlinks = PyObject_IsTrue(args[0]);
12119
0
    if (follow_symlinks < 0) {
12120
0
        goto exit;
12121
0
    }
12122
0
skip_optional_kwonly:
12123
0
    _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks);
12124
0
    if ((_return_value == -1) && PyErr_Occurred()) {
12125
0
        goto exit;
12126
0
    }
12127
0
    return_value = PyBool_FromLong((long)_return_value);
12128
12129
0
exit:
12130
0
    return return_value;
12131
0
}
12132
12133
PyDoc_STRVAR(os_DirEntry_inode__doc__,
12134
"inode($self, /)\n"
12135
"--\n"
12136
"\n"
12137
"Return inode of the entry; cached per entry.");
12138
12139
#define OS_DIRENTRY_INODE_METHODDEF    \
12140
    {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
12141
12142
static PyObject *
12143
os_DirEntry_inode_impl(DirEntry *self);
12144
12145
static PyObject *
12146
os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored))
12147
0
{
12148
0
    return os_DirEntry_inode_impl((DirEntry *)self);
12149
0
}
12150
12151
PyDoc_STRVAR(os_DirEntry___fspath____doc__,
12152
"__fspath__($self, /)\n"
12153
"--\n"
12154
"\n"
12155
"Returns the path for the entry.");
12156
12157
#define OS_DIRENTRY___FSPATH___METHODDEF    \
12158
    {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
12159
12160
static PyObject *
12161
os_DirEntry___fspath___impl(DirEntry *self);
12162
12163
static PyObject *
12164
os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored))
12165
0
{
12166
0
    return os_DirEntry___fspath___impl((DirEntry *)self);
12167
0
}
12168
12169
PyDoc_STRVAR(os_scandir__doc__,
12170
"scandir($module, /, path=None)\n"
12171
"--\n"
12172
"\n"
12173
"Return an iterator of DirEntry objects for given path.\n"
12174
"\n"
12175
"path can be specified as either str, bytes, or a path-like object.  If path\n"
12176
"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
12177
"all other circumstances they will be str.\n"
12178
"\n"
12179
"If path is None, uses the path=\'.\'.");
12180
12181
#define OS_SCANDIR_METHODDEF    \
12182
    {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
12183
12184
static PyObject *
12185
os_scandir_impl(PyObject *module, path_t *path);
12186
12187
static PyObject *
12188
os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12189
0
{
12190
0
    PyObject *return_value = NULL;
12191
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12192
12193
0
    #define NUM_KEYWORDS 1
12194
0
    static struct {
12195
0
        PyGC_Head _this_is_not_used;
12196
0
        PyObject_VAR_HEAD
12197
0
        Py_hash_t ob_hash;
12198
0
        PyObject *ob_item[NUM_KEYWORDS];
12199
0
    } _kwtuple = {
12200
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12201
0
        .ob_hash = -1,
12202
0
        .ob_item = { &_Py_ID(path), },
12203
0
    };
12204
0
    #undef NUM_KEYWORDS
12205
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12206
12207
    #else  // !Py_BUILD_CORE
12208
    #  define KWTUPLE NULL
12209
    #endif  // !Py_BUILD_CORE
12210
12211
0
    static const char * const _keywords[] = {"path", NULL};
12212
0
    static _PyArg_Parser _parser = {
12213
0
        .keywords = _keywords,
12214
0
        .fname = "scandir",
12215
0
        .kwtuple = KWTUPLE,
12216
0
    };
12217
0
    #undef KWTUPLE
12218
0
    PyObject *argsbuf[1];
12219
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12220
0
    path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
12221
12222
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12223
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12224
0
    if (!args) {
12225
0
        goto exit;
12226
0
    }
12227
0
    if (!noptargs) {
12228
0
        goto skip_optional_pos;
12229
0
    }
12230
0
    if (!path_converter(args[0], &path)) {
12231
0
        goto exit;
12232
0
    }
12233
0
skip_optional_pos:
12234
0
    return_value = os_scandir_impl(module, &path);
12235
12236
0
exit:
12237
    /* Cleanup for path */
12238
0
    path_cleanup(&path);
12239
12240
0
    return return_value;
12241
0
}
12242
12243
PyDoc_STRVAR(os_fspath__doc__,
12244
"fspath($module, /, path)\n"
12245
"--\n"
12246
"\n"
12247
"Return the file system path representation of the object.\n"
12248
"\n"
12249
"If the object is str or bytes, then allow it to pass through as-is. If the\n"
12250
"object defines __fspath__(), then return the result of that method. All other\n"
12251
"types raise a TypeError.");
12252
12253
#define OS_FSPATH_METHODDEF    \
12254
    {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
12255
12256
static PyObject *
12257
os_fspath_impl(PyObject *module, PyObject *path);
12258
12259
static PyObject *
12260
os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12261
3.12k
{
12262
3.12k
    PyObject *return_value = NULL;
12263
3.12k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12264
12265
3.12k
    #define NUM_KEYWORDS 1
12266
3.12k
    static struct {
12267
3.12k
        PyGC_Head _this_is_not_used;
12268
3.12k
        PyObject_VAR_HEAD
12269
3.12k
        Py_hash_t ob_hash;
12270
3.12k
        PyObject *ob_item[NUM_KEYWORDS];
12271
3.12k
    } _kwtuple = {
12272
3.12k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12273
3.12k
        .ob_hash = -1,
12274
3.12k
        .ob_item = { &_Py_ID(path), },
12275
3.12k
    };
12276
3.12k
    #undef NUM_KEYWORDS
12277
3.12k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12278
12279
    #else  // !Py_BUILD_CORE
12280
    #  define KWTUPLE NULL
12281
    #endif  // !Py_BUILD_CORE
12282
12283
3.12k
    static const char * const _keywords[] = {"path", NULL};
12284
3.12k
    static _PyArg_Parser _parser = {
12285
3.12k
        .keywords = _keywords,
12286
3.12k
        .fname = "fspath",
12287
3.12k
        .kwtuple = KWTUPLE,
12288
3.12k
    };
12289
3.12k
    #undef KWTUPLE
12290
3.12k
    PyObject *argsbuf[1];
12291
3.12k
    PyObject *path;
12292
12293
3.12k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12294
3.12k
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12295
3.12k
    if (!args) {
12296
0
        goto exit;
12297
0
    }
12298
3.12k
    path = args[0];
12299
3.12k
    return_value = os_fspath_impl(module, path);
12300
12301
3.12k
exit:
12302
3.12k
    return return_value;
12303
3.12k
}
12304
12305
#if defined(HAVE_GETRANDOM_SYSCALL)
12306
12307
PyDoc_STRVAR(os_getrandom__doc__,
12308
"getrandom($module, /, size, flags=0)\n"
12309
"--\n"
12310
"\n"
12311
"Obtain a series of random bytes.");
12312
12313
#define OS_GETRANDOM_METHODDEF    \
12314
    {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
12315
12316
static PyObject *
12317
os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
12318
12319
static PyObject *
12320
os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12321
0
{
12322
0
    PyObject *return_value = NULL;
12323
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12324
12325
0
    #define NUM_KEYWORDS 2
12326
0
    static struct {
12327
0
        PyGC_Head _this_is_not_used;
12328
0
        PyObject_VAR_HEAD
12329
0
        Py_hash_t ob_hash;
12330
0
        PyObject *ob_item[NUM_KEYWORDS];
12331
0
    } _kwtuple = {
12332
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12333
0
        .ob_hash = -1,
12334
0
        .ob_item = { &_Py_ID(size), &_Py_ID(flags), },
12335
0
    };
12336
0
    #undef NUM_KEYWORDS
12337
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12338
12339
    #else  // !Py_BUILD_CORE
12340
    #  define KWTUPLE NULL
12341
    #endif  // !Py_BUILD_CORE
12342
12343
0
    static const char * const _keywords[] = {"size", "flags", NULL};
12344
0
    static _PyArg_Parser _parser = {
12345
0
        .keywords = _keywords,
12346
0
        .fname = "getrandom",
12347
0
        .kwtuple = KWTUPLE,
12348
0
    };
12349
0
    #undef KWTUPLE
12350
0
    PyObject *argsbuf[2];
12351
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
12352
0
    Py_ssize_t size;
12353
0
    int flags = 0;
12354
12355
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12356
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12357
0
    if (!args) {
12358
0
        goto exit;
12359
0
    }
12360
0
    {
12361
0
        Py_ssize_t ival = -1;
12362
0
        PyObject *iobj = _PyNumber_Index(args[0]);
12363
0
        if (iobj != NULL) {
12364
0
            ival = PyLong_AsSsize_t(iobj);
12365
0
            Py_DECREF(iobj);
12366
0
        }
12367
0
        if (ival == -1 && PyErr_Occurred()) {
12368
0
            goto exit;
12369
0
        }
12370
0
        size = ival;
12371
0
    }
12372
0
    if (!noptargs) {
12373
0
        goto skip_optional_pos;
12374
0
    }
12375
0
    flags = PyLong_AsInt(args[1]);
12376
0
    if (flags == -1 && PyErr_Occurred()) {
12377
0
        goto exit;
12378
0
    }
12379
0
skip_optional_pos:
12380
0
    return_value = os_getrandom_impl(module, size, flags);
12381
12382
0
exit:
12383
0
    return return_value;
12384
0
}
12385
12386
#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
12387
12388
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12389
12390
PyDoc_STRVAR(os__add_dll_directory__doc__,
12391
"_add_dll_directory($module, /, path)\n"
12392
"--\n"
12393
"\n"
12394
"Add a path to the DLL search path.\n"
12395
"\n"
12396
"This search path is used when resolving dependencies for imported\n"
12397
"extension modules (the module itself is resolved through sys.path),\n"
12398
"and also by ctypes.\n"
12399
"\n"
12400
"Returns an opaque value that may be passed to os.remove_dll_directory\n"
12401
"to remove this directory from the search path.");
12402
12403
#define OS__ADD_DLL_DIRECTORY_METHODDEF    \
12404
    {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
12405
12406
static PyObject *
12407
os__add_dll_directory_impl(PyObject *module, path_t *path);
12408
12409
static PyObject *
12410
os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12411
{
12412
    PyObject *return_value = NULL;
12413
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12414
12415
    #define NUM_KEYWORDS 1
12416
    static struct {
12417
        PyGC_Head _this_is_not_used;
12418
        PyObject_VAR_HEAD
12419
        Py_hash_t ob_hash;
12420
        PyObject *ob_item[NUM_KEYWORDS];
12421
    } _kwtuple = {
12422
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12423
        .ob_hash = -1,
12424
        .ob_item = { &_Py_ID(path), },
12425
    };
12426
    #undef NUM_KEYWORDS
12427
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12428
12429
    #else  // !Py_BUILD_CORE
12430
    #  define KWTUPLE NULL
12431
    #endif  // !Py_BUILD_CORE
12432
12433
    static const char * const _keywords[] = {"path", NULL};
12434
    static _PyArg_Parser _parser = {
12435
        .keywords = _keywords,
12436
        .fname = "_add_dll_directory",
12437
        .kwtuple = KWTUPLE,
12438
    };
12439
    #undef KWTUPLE
12440
    PyObject *argsbuf[1];
12441
    path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0);
12442
12443
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12444
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12445
    if (!args) {
12446
        goto exit;
12447
    }
12448
    if (!path_converter(args[0], &path)) {
12449
        goto exit;
12450
    }
12451
    return_value = os__add_dll_directory_impl(module, &path);
12452
12453
exit:
12454
    /* Cleanup for path */
12455
    path_cleanup(&path);
12456
12457
    return return_value;
12458
}
12459
12460
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12461
12462
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12463
12464
PyDoc_STRVAR(os__remove_dll_directory__doc__,
12465
"_remove_dll_directory($module, /, cookie)\n"
12466
"--\n"
12467
"\n"
12468
"Removes a path from the DLL search path.\n"
12469
"\n"
12470
"The parameter is an opaque value that was returned from\n"
12471
"os.add_dll_directory. You can only remove directories that you added\n"
12472
"yourself.");
12473
12474
#define OS__REMOVE_DLL_DIRECTORY_METHODDEF    \
12475
    {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
12476
12477
static PyObject *
12478
os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
12479
12480
static PyObject *
12481
os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12482
{
12483
    PyObject *return_value = NULL;
12484
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12485
12486
    #define NUM_KEYWORDS 1
12487
    static struct {
12488
        PyGC_Head _this_is_not_used;
12489
        PyObject_VAR_HEAD
12490
        Py_hash_t ob_hash;
12491
        PyObject *ob_item[NUM_KEYWORDS];
12492
    } _kwtuple = {
12493
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12494
        .ob_hash = -1,
12495
        .ob_item = { &_Py_ID(cookie), },
12496
    };
12497
    #undef NUM_KEYWORDS
12498
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12499
12500
    #else  // !Py_BUILD_CORE
12501
    #  define KWTUPLE NULL
12502
    #endif  // !Py_BUILD_CORE
12503
12504
    static const char * const _keywords[] = {"cookie", NULL};
12505
    static _PyArg_Parser _parser = {
12506
        .keywords = _keywords,
12507
        .fname = "_remove_dll_directory",
12508
        .kwtuple = KWTUPLE,
12509
    };
12510
    #undef KWTUPLE
12511
    PyObject *argsbuf[1];
12512
    PyObject *cookie;
12513
12514
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12515
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12516
    if (!args) {
12517
        goto exit;
12518
    }
12519
    cookie = args[0];
12520
    return_value = os__remove_dll_directory_impl(module, cookie);
12521
12522
exit:
12523
    return return_value;
12524
}
12525
12526
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12527
12528
#if (defined(WIFEXITED) || defined(MS_WINDOWS))
12529
12530
PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__,
12531
"waitstatus_to_exitcode($module, /, status)\n"
12532
"--\n"
12533
"\n"
12534
"Convert a wait status to an exit code.\n"
12535
"\n"
12536
"On Unix:\n"
12537
"\n"
12538
"* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n"
12539
"* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n"
12540
"* Otherwise, raise a ValueError.\n"
12541
"\n"
12542
"On Windows, return status shifted right by 8 bits.\n"
12543
"\n"
12544
"On Unix, if the process is being traced or if waitpid() was called with\n"
12545
"WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n"
12546
"This function must not be called if WIFSTOPPED(status) is true.");
12547
12548
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF    \
12549
    {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__},
12550
12551
static PyObject *
12552
os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj);
12553
12554
static PyObject *
12555
os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12556
0
{
12557
0
    PyObject *return_value = NULL;
12558
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12559
12560
0
    #define NUM_KEYWORDS 1
12561
0
    static struct {
12562
0
        PyGC_Head _this_is_not_used;
12563
0
        PyObject_VAR_HEAD
12564
0
        Py_hash_t ob_hash;
12565
0
        PyObject *ob_item[NUM_KEYWORDS];
12566
0
    } _kwtuple = {
12567
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12568
0
        .ob_hash = -1,
12569
0
        .ob_item = { &_Py_ID(status), },
12570
0
    };
12571
0
    #undef NUM_KEYWORDS
12572
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12573
12574
    #else  // !Py_BUILD_CORE
12575
    #  define KWTUPLE NULL
12576
    #endif  // !Py_BUILD_CORE
12577
12578
0
    static const char * const _keywords[] = {"status", NULL};
12579
0
    static _PyArg_Parser _parser = {
12580
0
        .keywords = _keywords,
12581
0
        .fname = "waitstatus_to_exitcode",
12582
0
        .kwtuple = KWTUPLE,
12583
0
    };
12584
0
    #undef KWTUPLE
12585
0
    PyObject *argsbuf[1];
12586
0
    PyObject *status_obj;
12587
12588
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12589
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12590
0
    if (!args) {
12591
0
        goto exit;
12592
0
    }
12593
0
    status_obj = args[0];
12594
0
    return_value = os_waitstatus_to_exitcode_impl(module, status_obj);
12595
12596
0
exit:
12597
0
    return return_value;
12598
0
}
12599
12600
#endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */
12601
12602
#if defined(MS_WINDOWS)
12603
12604
PyDoc_STRVAR(os__supports_virtual_terminal__doc__,
12605
"_supports_virtual_terminal($module, /)\n"
12606
"--\n"
12607
"\n"
12608
"Checks if virtual terminal is supported in windows");
12609
12610
#define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF    \
12611
    {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__},
12612
12613
static PyObject *
12614
os__supports_virtual_terminal_impl(PyObject *module);
12615
12616
static PyObject *
12617
os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored))
12618
{
12619
    return os__supports_virtual_terminal_impl(module);
12620
}
12621
12622
#endif /* defined(MS_WINDOWS) */
12623
12624
PyDoc_STRVAR(os__inputhook__doc__,
12625
"_inputhook($module, /)\n"
12626
"--\n"
12627
"\n"
12628
"Calls PyOS_CallInputHook droppong the GIL first");
12629
12630
#define OS__INPUTHOOK_METHODDEF    \
12631
    {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__},
12632
12633
static PyObject *
12634
os__inputhook_impl(PyObject *module);
12635
12636
static PyObject *
12637
os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored))
12638
0
{
12639
0
    return os__inputhook_impl(module);
12640
0
}
12641
12642
PyDoc_STRVAR(os__is_inputhook_installed__doc__,
12643
"_is_inputhook_installed($module, /)\n"
12644
"--\n"
12645
"\n"
12646
"Checks if PyOS_CallInputHook is set");
12647
12648
#define OS__IS_INPUTHOOK_INSTALLED_METHODDEF    \
12649
    {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__},
12650
12651
static PyObject *
12652
os__is_inputhook_installed_impl(PyObject *module);
12653
12654
static PyObject *
12655
os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored))
12656
0
{
12657
0
    return os__is_inputhook_installed_impl(module);
12658
0
}
12659
12660
PyDoc_STRVAR(os__create_environ__doc__,
12661
"_create_environ($module, /)\n"
12662
"--\n"
12663
"\n"
12664
"Create the environment dictionary.");
12665
12666
#define OS__CREATE_ENVIRON_METHODDEF    \
12667
    {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__},
12668
12669
static PyObject *
12670
os__create_environ_impl(PyObject *module);
12671
12672
static PyObject *
12673
os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored))
12674
0
{
12675
0
    return os__create_environ_impl(module);
12676
0
}
12677
12678
#if defined(__EMSCRIPTEN__)
12679
12680
PyDoc_STRVAR(os__emscripten_debugger__doc__,
12681
"_emscripten_debugger($module, /)\n"
12682
"--\n"
12683
"\n"
12684
"Create a breakpoint for the JavaScript debugger. Emscripten only.");
12685
12686
#define OS__EMSCRIPTEN_DEBUGGER_METHODDEF    \
12687
    {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__},
12688
12689
static PyObject *
12690
os__emscripten_debugger_impl(PyObject *module);
12691
12692
static PyObject *
12693
os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored))
12694
{
12695
    return os__emscripten_debugger_impl(module);
12696
}
12697
12698
#endif /* defined(__EMSCRIPTEN__) */
12699
12700
#if defined(__EMSCRIPTEN__)
12701
12702
PyDoc_STRVAR(os__emscripten_log__doc__,
12703
"_emscripten_log($module, /, arg)\n"
12704
"--\n"
12705
"\n"
12706
"Log something to the JS console. Emscripten only.");
12707
12708
#define OS__EMSCRIPTEN_LOG_METHODDEF    \
12709
    {"_emscripten_log", _PyCFunction_CAST(os__emscripten_log), METH_FASTCALL|METH_KEYWORDS, os__emscripten_log__doc__},
12710
12711
static PyObject *
12712
os__emscripten_log_impl(PyObject *module, const char *arg);
12713
12714
static PyObject *
12715
os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12716
{
12717
    PyObject *return_value = NULL;
12718
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12719
12720
    #define NUM_KEYWORDS 1
12721
    static struct {
12722
        PyGC_Head _this_is_not_used;
12723
        PyObject_VAR_HEAD
12724
        Py_hash_t ob_hash;
12725
        PyObject *ob_item[NUM_KEYWORDS];
12726
    } _kwtuple = {
12727
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12728
        .ob_hash = -1,
12729
        .ob_item = { &_Py_ID(arg), },
12730
    };
12731
    #undef NUM_KEYWORDS
12732
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12733
12734
    #else  // !Py_BUILD_CORE
12735
    #  define KWTUPLE NULL
12736
    #endif  // !Py_BUILD_CORE
12737
12738
    static const char * const _keywords[] = {"arg", NULL};
12739
    static _PyArg_Parser _parser = {
12740
        .keywords = _keywords,
12741
        .fname = "_emscripten_log",
12742
        .kwtuple = KWTUPLE,
12743
    };
12744
    #undef KWTUPLE
12745
    PyObject *argsbuf[1];
12746
    const char *arg;
12747
12748
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12749
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12750
    if (!args) {
12751
        goto exit;
12752
    }
12753
    if (!PyUnicode_Check(args[0])) {
12754
        _PyArg_BadArgument("_emscripten_log", "argument 'arg'", "str", args[0]);
12755
        goto exit;
12756
    }
12757
    Py_ssize_t arg_length;
12758
    arg = PyUnicode_AsUTF8AndSize(args[0], &arg_length);
12759
    if (arg == NULL) {
12760
        goto exit;
12761
    }
12762
    if (strlen(arg) != (size_t)arg_length) {
12763
        PyErr_SetString(PyExc_ValueError, "embedded null character");
12764
        goto exit;
12765
    }
12766
    return_value = os__emscripten_log_impl(module, arg);
12767
12768
exit:
12769
    return return_value;
12770
}
12771
12772
#endif /* defined(__EMSCRIPTEN__) */
12773
12774
#ifndef OS_TTYNAME_METHODDEF
12775
    #define OS_TTYNAME_METHODDEF
12776
#endif /* !defined(OS_TTYNAME_METHODDEF) */
12777
12778
#ifndef OS_CTERMID_METHODDEF
12779
    #define OS_CTERMID_METHODDEF
12780
#endif /* !defined(OS_CTERMID_METHODDEF) */
12781
12782
#ifndef OS_FCHDIR_METHODDEF
12783
    #define OS_FCHDIR_METHODDEF
12784
#endif /* !defined(OS_FCHDIR_METHODDEF) */
12785
12786
#ifndef OS_FCHMOD_METHODDEF
12787
    #define OS_FCHMOD_METHODDEF
12788
#endif /* !defined(OS_FCHMOD_METHODDEF) */
12789
12790
#ifndef OS_LCHMOD_METHODDEF
12791
    #define OS_LCHMOD_METHODDEF
12792
#endif /* !defined(OS_LCHMOD_METHODDEF) */
12793
12794
#ifndef OS_CHFLAGS_METHODDEF
12795
    #define OS_CHFLAGS_METHODDEF
12796
#endif /* !defined(OS_CHFLAGS_METHODDEF) */
12797
12798
#ifndef OS_LCHFLAGS_METHODDEF
12799
    #define OS_LCHFLAGS_METHODDEF
12800
#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
12801
12802
#ifndef OS_CHROOT_METHODDEF
12803
    #define OS_CHROOT_METHODDEF
12804
#endif /* !defined(OS_CHROOT_METHODDEF) */
12805
12806
#ifndef OS_FSYNC_METHODDEF
12807
    #define OS_FSYNC_METHODDEF
12808
#endif /* !defined(OS_FSYNC_METHODDEF) */
12809
12810
#ifndef OS_SYNC_METHODDEF
12811
    #define OS_SYNC_METHODDEF
12812
#endif /* !defined(OS_SYNC_METHODDEF) */
12813
12814
#ifndef OS_FDATASYNC_METHODDEF
12815
    #define OS_FDATASYNC_METHODDEF
12816
#endif /* !defined(OS_FDATASYNC_METHODDEF) */
12817
12818
#ifndef OS_CHOWN_METHODDEF
12819
    #define OS_CHOWN_METHODDEF
12820
#endif /* !defined(OS_CHOWN_METHODDEF) */
12821
12822
#ifndef OS_FCHOWN_METHODDEF
12823
    #define OS_FCHOWN_METHODDEF
12824
#endif /* !defined(OS_FCHOWN_METHODDEF) */
12825
12826
#ifndef OS_LCHOWN_METHODDEF
12827
    #define OS_LCHOWN_METHODDEF
12828
#endif /* !defined(OS_LCHOWN_METHODDEF) */
12829
12830
#ifndef OS_LINK_METHODDEF
12831
    #define OS_LINK_METHODDEF
12832
#endif /* !defined(OS_LINK_METHODDEF) */
12833
12834
#ifndef OS_LISTDRIVES_METHODDEF
12835
    #define OS_LISTDRIVES_METHODDEF
12836
#endif /* !defined(OS_LISTDRIVES_METHODDEF) */
12837
12838
#ifndef OS_LISTVOLUMES_METHODDEF
12839
    #define OS_LISTVOLUMES_METHODDEF
12840
#endif /* !defined(OS_LISTVOLUMES_METHODDEF) */
12841
12842
#ifndef OS_LISTMOUNTS_METHODDEF
12843
    #define OS_LISTMOUNTS_METHODDEF
12844
#endif /* !defined(OS_LISTMOUNTS_METHODDEF) */
12845
12846
#ifndef OS__PATH_ISDEVDRIVE_METHODDEF
12847
    #define OS__PATH_ISDEVDRIVE_METHODDEF
12848
#endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */
12849
12850
#ifndef OS__GETFULLPATHNAME_METHODDEF
12851
    #define OS__GETFULLPATHNAME_METHODDEF
12852
#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
12853
12854
#ifndef OS__GETFINALPATHNAME_METHODDEF
12855
    #define OS__GETFINALPATHNAME_METHODDEF
12856
#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
12857
12858
#ifndef OS__FINDFIRSTFILE_METHODDEF
12859
    #define OS__FINDFIRSTFILE_METHODDEF
12860
#endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */
12861
12862
#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
12863
    #define OS__GETVOLUMEPATHNAME_METHODDEF
12864
#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
12865
12866
#ifndef OS__PATH_SPLITROOT_METHODDEF
12867
    #define OS__PATH_SPLITROOT_METHODDEF
12868
#endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */
12869
12870
#ifndef OS__PATH_EXISTS_METHODDEF
12871
    #define OS__PATH_EXISTS_METHODDEF
12872
#endif /* !defined(OS__PATH_EXISTS_METHODDEF) */
12873
12874
#ifndef OS__PATH_LEXISTS_METHODDEF
12875
    #define OS__PATH_LEXISTS_METHODDEF
12876
#endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */
12877
12878
#ifndef OS__PATH_ISDIR_METHODDEF
12879
    #define OS__PATH_ISDIR_METHODDEF
12880
#endif /* !defined(OS__PATH_ISDIR_METHODDEF) */
12881
12882
#ifndef OS__PATH_ISFILE_METHODDEF
12883
    #define OS__PATH_ISFILE_METHODDEF
12884
#endif /* !defined(OS__PATH_ISFILE_METHODDEF) */
12885
12886
#ifndef OS__PATH_ISLINK_METHODDEF
12887
    #define OS__PATH_ISLINK_METHODDEF
12888
#endif /* !defined(OS__PATH_ISLINK_METHODDEF) */
12889
12890
#ifndef OS__PATH_ISJUNCTION_METHODDEF
12891
    #define OS__PATH_ISJUNCTION_METHODDEF
12892
#endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */
12893
12894
#ifndef OS_NICE_METHODDEF
12895
    #define OS_NICE_METHODDEF
12896
#endif /* !defined(OS_NICE_METHODDEF) */
12897
12898
#ifndef OS_GETPRIORITY_METHODDEF
12899
    #define OS_GETPRIORITY_METHODDEF
12900
#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
12901
12902
#ifndef OS_SETPRIORITY_METHODDEF
12903
    #define OS_SETPRIORITY_METHODDEF
12904
#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
12905
12906
#ifndef OS_SYSTEM_METHODDEF
12907
    #define OS_SYSTEM_METHODDEF
12908
#endif /* !defined(OS_SYSTEM_METHODDEF) */
12909
12910
#ifndef OS_UMASK_METHODDEF
12911
    #define OS_UMASK_METHODDEF
12912
#endif /* !defined(OS_UMASK_METHODDEF) */
12913
12914
#ifndef OS_UNAME_METHODDEF
12915
    #define OS_UNAME_METHODDEF
12916
#endif /* !defined(OS_UNAME_METHODDEF) */
12917
12918
#ifndef OS_EXECV_METHODDEF
12919
    #define OS_EXECV_METHODDEF
12920
#endif /* !defined(OS_EXECV_METHODDEF) */
12921
12922
#ifndef OS_EXECVE_METHODDEF
12923
    #define OS_EXECVE_METHODDEF
12924
#endif /* !defined(OS_EXECVE_METHODDEF) */
12925
12926
#ifndef OS_POSIX_SPAWN_METHODDEF
12927
    #define OS_POSIX_SPAWN_METHODDEF
12928
#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
12929
12930
#ifndef OS_POSIX_SPAWNP_METHODDEF
12931
    #define OS_POSIX_SPAWNP_METHODDEF
12932
#endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
12933
12934
#ifndef OS_SPAWNV_METHODDEF
12935
    #define OS_SPAWNV_METHODDEF
12936
#endif /* !defined(OS_SPAWNV_METHODDEF) */
12937
12938
#ifndef OS_SPAWNVE_METHODDEF
12939
    #define OS_SPAWNVE_METHODDEF
12940
#endif /* !defined(OS_SPAWNVE_METHODDEF) */
12941
12942
#ifndef OS_REGISTER_AT_FORK_METHODDEF
12943
    #define OS_REGISTER_AT_FORK_METHODDEF
12944
#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
12945
12946
#ifndef OS_FORK1_METHODDEF
12947
    #define OS_FORK1_METHODDEF
12948
#endif /* !defined(OS_FORK1_METHODDEF) */
12949
12950
#ifndef OS_FORK_METHODDEF
12951
    #define OS_FORK_METHODDEF
12952
#endif /* !defined(OS_FORK_METHODDEF) */
12953
12954
#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
12955
    #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
12956
#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
12957
12958
#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
12959
    #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
12960
#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
12961
12962
#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
12963
    #define OS_SCHED_GETSCHEDULER_METHODDEF
12964
#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
12965
12966
#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
12967
    #define OS_SCHED_SETSCHEDULER_METHODDEF
12968
#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
12969
12970
#ifndef OS_SCHED_GETPARAM_METHODDEF
12971
    #define OS_SCHED_GETPARAM_METHODDEF
12972
#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
12973
12974
#ifndef OS_SCHED_SETPARAM_METHODDEF
12975
    #define OS_SCHED_SETPARAM_METHODDEF
12976
#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
12977
12978
#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
12979
    #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
12980
#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
12981
12982
#ifndef OS_SCHED_YIELD_METHODDEF
12983
    #define OS_SCHED_YIELD_METHODDEF
12984
#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
12985
12986
#ifndef OS_SCHED_SETAFFINITY_METHODDEF
12987
    #define OS_SCHED_SETAFFINITY_METHODDEF
12988
#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
12989
12990
#ifndef OS_SCHED_GETAFFINITY_METHODDEF
12991
    #define OS_SCHED_GETAFFINITY_METHODDEF
12992
#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
12993
12994
#ifndef OS_POSIX_OPENPT_METHODDEF
12995
    #define OS_POSIX_OPENPT_METHODDEF
12996
#endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */
12997
12998
#ifndef OS_GRANTPT_METHODDEF
12999
    #define OS_GRANTPT_METHODDEF
13000
#endif /* !defined(OS_GRANTPT_METHODDEF) */
13001
13002
#ifndef OS_UNLOCKPT_METHODDEF
13003
    #define OS_UNLOCKPT_METHODDEF
13004
#endif /* !defined(OS_UNLOCKPT_METHODDEF) */
13005
13006
#ifndef OS_PTSNAME_METHODDEF
13007
    #define OS_PTSNAME_METHODDEF
13008
#endif /* !defined(OS_PTSNAME_METHODDEF) */
13009
13010
#ifndef OS_OPENPTY_METHODDEF
13011
    #define OS_OPENPTY_METHODDEF
13012
#endif /* !defined(OS_OPENPTY_METHODDEF) */
13013
13014
#ifndef OS_LOGIN_TTY_METHODDEF
13015
    #define OS_LOGIN_TTY_METHODDEF
13016
#endif /* !defined(OS_LOGIN_TTY_METHODDEF) */
13017
13018
#ifndef OS_FORKPTY_METHODDEF
13019
    #define OS_FORKPTY_METHODDEF
13020
#endif /* !defined(OS_FORKPTY_METHODDEF) */
13021
13022
#ifndef OS_GETEGID_METHODDEF
13023
    #define OS_GETEGID_METHODDEF
13024
#endif /* !defined(OS_GETEGID_METHODDEF) */
13025
13026
#ifndef OS_GETEUID_METHODDEF
13027
    #define OS_GETEUID_METHODDEF
13028
#endif /* !defined(OS_GETEUID_METHODDEF) */
13029
13030
#ifndef OS_GETGID_METHODDEF
13031
    #define OS_GETGID_METHODDEF
13032
#endif /* !defined(OS_GETGID_METHODDEF) */
13033
13034
#ifndef OS_GETPID_METHODDEF
13035
    #define OS_GETPID_METHODDEF
13036
#endif /* !defined(OS_GETPID_METHODDEF) */
13037
13038
#ifndef OS_GETGROUPLIST_METHODDEF
13039
    #define OS_GETGROUPLIST_METHODDEF
13040
#endif /* !defined(OS_GETGROUPLIST_METHODDEF) */
13041
13042
#ifndef OS_GETGROUPS_METHODDEF
13043
    #define OS_GETGROUPS_METHODDEF
13044
#endif /* !defined(OS_GETGROUPS_METHODDEF) */
13045
13046
#ifndef OS_INITGROUPS_METHODDEF
13047
    #define OS_INITGROUPS_METHODDEF
13048
#endif /* !defined(OS_INITGROUPS_METHODDEF) */
13049
13050
#ifndef OS_GETPGID_METHODDEF
13051
    #define OS_GETPGID_METHODDEF
13052
#endif /* !defined(OS_GETPGID_METHODDEF) */
13053
13054
#ifndef OS_GETPGRP_METHODDEF
13055
    #define OS_GETPGRP_METHODDEF
13056
#endif /* !defined(OS_GETPGRP_METHODDEF) */
13057
13058
#ifndef OS_SETPGRP_METHODDEF
13059
    #define OS_SETPGRP_METHODDEF
13060
#endif /* !defined(OS_SETPGRP_METHODDEF) */
13061
13062
#ifndef OS_GETPPID_METHODDEF
13063
    #define OS_GETPPID_METHODDEF
13064
#endif /* !defined(OS_GETPPID_METHODDEF) */
13065
13066
#ifndef OS_GETLOGIN_METHODDEF
13067
    #define OS_GETLOGIN_METHODDEF
13068
#endif /* !defined(OS_GETLOGIN_METHODDEF) */
13069
13070
#ifndef OS_GETUID_METHODDEF
13071
    #define OS_GETUID_METHODDEF
13072
#endif /* !defined(OS_GETUID_METHODDEF) */
13073
13074
#ifndef OS_KILL_METHODDEF
13075
    #define OS_KILL_METHODDEF
13076
#endif /* !defined(OS_KILL_METHODDEF) */
13077
13078
#ifndef OS_KILLPG_METHODDEF
13079
    #define OS_KILLPG_METHODDEF
13080
#endif /* !defined(OS_KILLPG_METHODDEF) */
13081
13082
#ifndef OS_PLOCK_METHODDEF
13083
    #define OS_PLOCK_METHODDEF
13084
#endif /* !defined(OS_PLOCK_METHODDEF) */
13085
13086
#ifndef OS_SETUID_METHODDEF
13087
    #define OS_SETUID_METHODDEF
13088
#endif /* !defined(OS_SETUID_METHODDEF) */
13089
13090
#ifndef OS_SETEUID_METHODDEF
13091
    #define OS_SETEUID_METHODDEF
13092
#endif /* !defined(OS_SETEUID_METHODDEF) */
13093
13094
#ifndef OS_SETEGID_METHODDEF
13095
    #define OS_SETEGID_METHODDEF
13096
#endif /* !defined(OS_SETEGID_METHODDEF) */
13097
13098
#ifndef OS_SETREUID_METHODDEF
13099
    #define OS_SETREUID_METHODDEF
13100
#endif /* !defined(OS_SETREUID_METHODDEF) */
13101
13102
#ifndef OS_SETREGID_METHODDEF
13103
    #define OS_SETREGID_METHODDEF
13104
#endif /* !defined(OS_SETREGID_METHODDEF) */
13105
13106
#ifndef OS_SETGID_METHODDEF
13107
    #define OS_SETGID_METHODDEF
13108
#endif /* !defined(OS_SETGID_METHODDEF) */
13109
13110
#ifndef OS_SETGROUPS_METHODDEF
13111
    #define OS_SETGROUPS_METHODDEF
13112
#endif /* !defined(OS_SETGROUPS_METHODDEF) */
13113
13114
#ifndef OS_WAIT3_METHODDEF
13115
    #define OS_WAIT3_METHODDEF
13116
#endif /* !defined(OS_WAIT3_METHODDEF) */
13117
13118
#ifndef OS_WAIT4_METHODDEF
13119
    #define OS_WAIT4_METHODDEF
13120
#endif /* !defined(OS_WAIT4_METHODDEF) */
13121
13122
#ifndef OS_WAITID_METHODDEF
13123
    #define OS_WAITID_METHODDEF
13124
#endif /* !defined(OS_WAITID_METHODDEF) */
13125
13126
#ifndef OS_WAITPID_METHODDEF
13127
    #define OS_WAITPID_METHODDEF
13128
#endif /* !defined(OS_WAITPID_METHODDEF) */
13129
13130
#ifndef OS_WAIT_METHODDEF
13131
    #define OS_WAIT_METHODDEF
13132
#endif /* !defined(OS_WAIT_METHODDEF) */
13133
13134
#ifndef OS_PIDFD_OPEN_METHODDEF
13135
    #define OS_PIDFD_OPEN_METHODDEF
13136
#endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */
13137
13138
#ifndef OS_SETNS_METHODDEF
13139
    #define OS_SETNS_METHODDEF
13140
#endif /* !defined(OS_SETNS_METHODDEF) */
13141
13142
#ifndef OS_UNSHARE_METHODDEF
13143
    #define OS_UNSHARE_METHODDEF
13144
#endif /* !defined(OS_UNSHARE_METHODDEF) */
13145
13146
#ifndef OS_READLINK_METHODDEF
13147
    #define OS_READLINK_METHODDEF
13148
#endif /* !defined(OS_READLINK_METHODDEF) */
13149
13150
#ifndef OS_SYMLINK_METHODDEF
13151
    #define OS_SYMLINK_METHODDEF
13152
#endif /* !defined(OS_SYMLINK_METHODDEF) */
13153
13154
#ifndef OS_TIMERFD_CREATE_METHODDEF
13155
    #define OS_TIMERFD_CREATE_METHODDEF
13156
#endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */
13157
13158
#ifndef OS_TIMERFD_SETTIME_METHODDEF
13159
    #define OS_TIMERFD_SETTIME_METHODDEF
13160
#endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */
13161
13162
#ifndef OS_TIMERFD_SETTIME_NS_METHODDEF
13163
    #define OS_TIMERFD_SETTIME_NS_METHODDEF
13164
#endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */
13165
13166
#ifndef OS_TIMERFD_GETTIME_METHODDEF
13167
    #define OS_TIMERFD_GETTIME_METHODDEF
13168
#endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */
13169
13170
#ifndef OS_TIMERFD_GETTIME_NS_METHODDEF
13171
    #define OS_TIMERFD_GETTIME_NS_METHODDEF
13172
#endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */
13173
13174
#ifndef OS_GETSID_METHODDEF
13175
    #define OS_GETSID_METHODDEF
13176
#endif /* !defined(OS_GETSID_METHODDEF) */
13177
13178
#ifndef OS_SETSID_METHODDEF
13179
    #define OS_SETSID_METHODDEF
13180
#endif /* !defined(OS_SETSID_METHODDEF) */
13181
13182
#ifndef OS_SETPGID_METHODDEF
13183
    #define OS_SETPGID_METHODDEF
13184
#endif /* !defined(OS_SETPGID_METHODDEF) */
13185
13186
#ifndef OS_TCGETPGRP_METHODDEF
13187
    #define OS_TCGETPGRP_METHODDEF
13188
#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
13189
13190
#ifndef OS_TCSETPGRP_METHODDEF
13191
    #define OS_TCSETPGRP_METHODDEF
13192
#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
13193
13194
#ifndef OS_DUP2_METHODDEF
13195
    #define OS_DUP2_METHODDEF
13196
#endif /* !defined(OS_DUP2_METHODDEF) */
13197
13198
#ifndef OS_LOCKF_METHODDEF
13199
    #define OS_LOCKF_METHODDEF
13200
#endif /* !defined(OS_LOCKF_METHODDEF) */
13201
13202
#ifndef OS_READV_METHODDEF
13203
    #define OS_READV_METHODDEF
13204
#endif /* !defined(OS_READV_METHODDEF) */
13205
13206
#ifndef OS_PREAD_METHODDEF
13207
    #define OS_PREAD_METHODDEF
13208
#endif /* !defined(OS_PREAD_METHODDEF) */
13209
13210
#ifndef OS_PREADV_METHODDEF
13211
    #define OS_PREADV_METHODDEF
13212
#endif /* !defined(OS_PREADV_METHODDEF) */
13213
13214
#ifndef OS_SENDFILE_METHODDEF
13215
    #define OS_SENDFILE_METHODDEF
13216
#endif /* !defined(OS_SENDFILE_METHODDEF) */
13217
13218
#ifndef OS__FCOPYFILE_METHODDEF
13219
    #define OS__FCOPYFILE_METHODDEF
13220
#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
13221
13222
#ifndef OS_PIPE_METHODDEF
13223
    #define OS_PIPE_METHODDEF
13224
#endif /* !defined(OS_PIPE_METHODDEF) */
13225
13226
#ifndef OS_PIPE2_METHODDEF
13227
    #define OS_PIPE2_METHODDEF
13228
#endif /* !defined(OS_PIPE2_METHODDEF) */
13229
13230
#ifndef OS_WRITEV_METHODDEF
13231
    #define OS_WRITEV_METHODDEF
13232
#endif /* !defined(OS_WRITEV_METHODDEF) */
13233
13234
#ifndef OS_PWRITE_METHODDEF
13235
    #define OS_PWRITE_METHODDEF
13236
#endif /* !defined(OS_PWRITE_METHODDEF) */
13237
13238
#ifndef OS_PWRITEV_METHODDEF
13239
    #define OS_PWRITEV_METHODDEF
13240
#endif /* !defined(OS_PWRITEV_METHODDEF) */
13241
13242
#ifndef OS_COPY_FILE_RANGE_METHODDEF
13243
    #define OS_COPY_FILE_RANGE_METHODDEF
13244
#endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
13245
13246
#ifndef OS_SPLICE_METHODDEF
13247
    #define OS_SPLICE_METHODDEF
13248
#endif /* !defined(OS_SPLICE_METHODDEF) */
13249
13250
#ifndef OS_MKFIFO_METHODDEF
13251
    #define OS_MKFIFO_METHODDEF
13252
#endif /* !defined(OS_MKFIFO_METHODDEF) */
13253
13254
#ifndef OS_MKNOD_METHODDEF
13255
    #define OS_MKNOD_METHODDEF
13256
#endif /* !defined(OS_MKNOD_METHODDEF) */
13257
13258
#ifndef OS_MAJOR_METHODDEF
13259
    #define OS_MAJOR_METHODDEF
13260
#endif /* !defined(OS_MAJOR_METHODDEF) */
13261
13262
#ifndef OS_MINOR_METHODDEF
13263
    #define OS_MINOR_METHODDEF
13264
#endif /* !defined(OS_MINOR_METHODDEF) */
13265
13266
#ifndef OS_MAKEDEV_METHODDEF
13267
    #define OS_MAKEDEV_METHODDEF
13268
#endif /* !defined(OS_MAKEDEV_METHODDEF) */
13269
13270
#ifndef OS_FTRUNCATE_METHODDEF
13271
    #define OS_FTRUNCATE_METHODDEF
13272
#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
13273
13274
#ifndef OS_TRUNCATE_METHODDEF
13275
    #define OS_TRUNCATE_METHODDEF
13276
#endif /* !defined(OS_TRUNCATE_METHODDEF) */
13277
13278
#ifndef OS_POSIX_FALLOCATE_METHODDEF
13279
    #define OS_POSIX_FALLOCATE_METHODDEF
13280
#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
13281
13282
#ifndef OS_POSIX_FADVISE_METHODDEF
13283
    #define OS_POSIX_FADVISE_METHODDEF
13284
#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
13285
13286
#ifndef OS_PUTENV_METHODDEF
13287
    #define OS_PUTENV_METHODDEF
13288
#endif /* !defined(OS_PUTENV_METHODDEF) */
13289
13290
#ifndef OS_UNSETENV_METHODDEF
13291
    #define OS_UNSETENV_METHODDEF
13292
#endif /* !defined(OS_UNSETENV_METHODDEF) */
13293
13294
#ifndef OS_WCOREDUMP_METHODDEF
13295
    #define OS_WCOREDUMP_METHODDEF
13296
#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
13297
13298
#ifndef OS_WIFCONTINUED_METHODDEF
13299
    #define OS_WIFCONTINUED_METHODDEF
13300
#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
13301
13302
#ifndef OS_WIFSTOPPED_METHODDEF
13303
    #define OS_WIFSTOPPED_METHODDEF
13304
#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
13305
13306
#ifndef OS_WIFSIGNALED_METHODDEF
13307
    #define OS_WIFSIGNALED_METHODDEF
13308
#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
13309
13310
#ifndef OS_WIFEXITED_METHODDEF
13311
    #define OS_WIFEXITED_METHODDEF
13312
#endif /* !defined(OS_WIFEXITED_METHODDEF) */
13313
13314
#ifndef OS_WEXITSTATUS_METHODDEF
13315
    #define OS_WEXITSTATUS_METHODDEF
13316
#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
13317
13318
#ifndef OS_WTERMSIG_METHODDEF
13319
    #define OS_WTERMSIG_METHODDEF
13320
#endif /* !defined(OS_WTERMSIG_METHODDEF) */
13321
13322
#ifndef OS_WSTOPSIG_METHODDEF
13323
    #define OS_WSTOPSIG_METHODDEF
13324
#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
13325
13326
#ifndef OS_FSTATVFS_METHODDEF
13327
    #define OS_FSTATVFS_METHODDEF
13328
#endif /* !defined(OS_FSTATVFS_METHODDEF) */
13329
13330
#ifndef OS_STATVFS_METHODDEF
13331
    #define OS_STATVFS_METHODDEF
13332
#endif /* !defined(OS_STATVFS_METHODDEF) */
13333
13334
#ifndef OS__GETDISKUSAGE_METHODDEF
13335
    #define OS__GETDISKUSAGE_METHODDEF
13336
#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
13337
13338
#ifndef OS_FPATHCONF_METHODDEF
13339
    #define OS_FPATHCONF_METHODDEF
13340
#endif /* !defined(OS_FPATHCONF_METHODDEF) */
13341
13342
#ifndef OS_PATHCONF_METHODDEF
13343
    #define OS_PATHCONF_METHODDEF
13344
#endif /* !defined(OS_PATHCONF_METHODDEF) */
13345
13346
#ifndef OS_CONFSTR_METHODDEF
13347
    #define OS_CONFSTR_METHODDEF
13348
#endif /* !defined(OS_CONFSTR_METHODDEF) */
13349
13350
#ifndef OS_SYSCONF_METHODDEF
13351
    #define OS_SYSCONF_METHODDEF
13352
#endif /* !defined(OS_SYSCONF_METHODDEF) */
13353
13354
#ifndef OS_STARTFILE_METHODDEF
13355
    #define OS_STARTFILE_METHODDEF
13356
#endif /* !defined(OS_STARTFILE_METHODDEF) */
13357
13358
#ifndef OS_GETLOADAVG_METHODDEF
13359
    #define OS_GETLOADAVG_METHODDEF
13360
#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
13361
13362
#ifndef OS_SETRESUID_METHODDEF
13363
    #define OS_SETRESUID_METHODDEF
13364
#endif /* !defined(OS_SETRESUID_METHODDEF) */
13365
13366
#ifndef OS_SETRESGID_METHODDEF
13367
    #define OS_SETRESGID_METHODDEF
13368
#endif /* !defined(OS_SETRESGID_METHODDEF) */
13369
13370
#ifndef OS_GETRESUID_METHODDEF
13371
    #define OS_GETRESUID_METHODDEF
13372
#endif /* !defined(OS_GETRESUID_METHODDEF) */
13373
13374
#ifndef OS_GETRESGID_METHODDEF
13375
    #define OS_GETRESGID_METHODDEF
13376
#endif /* !defined(OS_GETRESGID_METHODDEF) */
13377
13378
#ifndef OS_GETXATTR_METHODDEF
13379
    #define OS_GETXATTR_METHODDEF
13380
#endif /* !defined(OS_GETXATTR_METHODDEF) */
13381
13382
#ifndef OS_SETXATTR_METHODDEF
13383
    #define OS_SETXATTR_METHODDEF
13384
#endif /* !defined(OS_SETXATTR_METHODDEF) */
13385
13386
#ifndef OS_REMOVEXATTR_METHODDEF
13387
    #define OS_REMOVEXATTR_METHODDEF
13388
#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
13389
13390
#ifndef OS_LISTXATTR_METHODDEF
13391
    #define OS_LISTXATTR_METHODDEF
13392
#endif /* !defined(OS_LISTXATTR_METHODDEF) */
13393
13394
#ifndef OS_MEMFD_CREATE_METHODDEF
13395
    #define OS_MEMFD_CREATE_METHODDEF
13396
#endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */
13397
13398
#ifndef OS_EVENTFD_METHODDEF
13399
    #define OS_EVENTFD_METHODDEF
13400
#endif /* !defined(OS_EVENTFD_METHODDEF) */
13401
13402
#ifndef OS_EVENTFD_READ_METHODDEF
13403
    #define OS_EVENTFD_READ_METHODDEF
13404
#endif /* !defined(OS_EVENTFD_READ_METHODDEF) */
13405
13406
#ifndef OS_EVENTFD_WRITE_METHODDEF
13407
    #define OS_EVENTFD_WRITE_METHODDEF
13408
#endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */
13409
13410
#ifndef OS_GET_TERMINAL_SIZE_METHODDEF
13411
    #define OS_GET_TERMINAL_SIZE_METHODDEF
13412
#endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */
13413
13414
#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
13415
    #define OS_GET_HANDLE_INHERITABLE_METHODDEF
13416
#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
13417
13418
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
13419
    #define OS_SET_HANDLE_INHERITABLE_METHODDEF
13420
#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
13421
13422
#ifndef OS_GETRANDOM_METHODDEF
13423
    #define OS_GETRANDOM_METHODDEF
13424
#endif /* !defined(OS_GETRANDOM_METHODDEF) */
13425
13426
#ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
13427
    #define OS__ADD_DLL_DIRECTORY_METHODDEF
13428
#endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
13429
13430
#ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
13431
    #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
13432
#endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
13433
13434
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13435
    #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13436
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
13437
13438
#ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13439
    #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13440
#endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */
13441
13442
#ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13443
    #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13444
#endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */
13445
13446
#ifndef OS__EMSCRIPTEN_LOG_METHODDEF
13447
    #define OS__EMSCRIPTEN_LOG_METHODDEF
13448
#endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */
13449
/*[clinic end generated code: output=b5b370c499174f85 input=a9049054013a1b77]*/