Coverage Report

Created: 2025-07-11 06:59

/src/Python-3.8.3/Modules/clinic/posixmodule.c.h
Line
Count
Source (jump to first uncovered line)
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
PyDoc_STRVAR(os_stat__doc__,
6
"stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
7
"--\n"
8
"\n"
9
"Perform a stat system call on the given path.\n"
10
"\n"
11
"  path\n"
12
"    Path to be examined; can be string, bytes, a path-like object or\n"
13
"    open-file-descriptor int.\n"
14
"  dir_fd\n"
15
"    If not None, it should be a file descriptor open to a directory,\n"
16
"    and path should be a relative string; path will then be relative to\n"
17
"    that directory.\n"
18
"  follow_symlinks\n"
19
"    If False, and the last element of the path is a symbolic link,\n"
20
"    stat will examine the symbolic link itself instead of the file\n"
21
"    the link points to.\n"
22
"\n"
23
"dir_fd and follow_symlinks may not be implemented\n"
24
"  on your platform.  If they are unavailable, using them will raise a\n"
25
"  NotImplementedError.\n"
26
"\n"
27
"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
28
"  an open file descriptor.");
29
30
#define OS_STAT_METHODDEF    \
31
    {"stat", (PyCFunction)(void(*)(void))os_stat, METH_FASTCALL|METH_KEYWORDS, os_stat__doc__},
32
33
static PyObject *
34
os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
35
36
static PyObject *
37
os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
38
1.08k
{
39
1.08k
    PyObject *return_value = NULL;
40
1.08k
    static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
41
1.08k
    static _PyArg_Parser _parser = {NULL, _keywords, "stat", 0};
42
1.08k
    PyObject *argsbuf[3];
43
1.08k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
44
1.08k
    path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
45
1.08k
    int dir_fd = DEFAULT_DIR_FD;
46
1.08k
    int follow_symlinks = 1;
47
48
1.08k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
49
1.08k
    if (!args) {
50
0
        goto exit;
51
0
    }
52
1.08k
    if (!path_converter(args[0], &path)) {
53
0
        goto exit;
54
0
    }
55
1.08k
    if (!noptargs) {
56
1.08k
        goto skip_optional_kwonly;
57
1.08k
    }
58
0
    if (args[1]) {
59
0
        if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
60
0
            goto exit;
61
0
        }
62
0
        if (!--noptargs) {
63
0
            goto skip_optional_kwonly;
64
0
        }
65
0
    }
66
0
    follow_symlinks = PyObject_IsTrue(args[2]);
67
0
    if (follow_symlinks < 0) {
68
0
        goto exit;
69
0
    }
70
1.08k
skip_optional_kwonly:
71
1.08k
    return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
72
73
1.08k
exit:
74
    /* Cleanup for path */
75
1.08k
    path_cleanup(&path);
76
77
1.08k
    return return_value;
78
1.08k
}
79
80
PyDoc_STRVAR(os_lstat__doc__,
81
"lstat($module, /, path, *, dir_fd=None)\n"
82
"--\n"
83
"\n"
84
"Perform a stat system call on the given path, without following symbolic links.\n"
85
"\n"
86
"Like stat(), but do not follow symbolic links.\n"
87
"Equivalent to stat(path, follow_symlinks=False).");
88
89
#define OS_LSTAT_METHODDEF    \
90
    {"lstat", (PyCFunction)(void(*)(void))os_lstat, METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
91
92
static PyObject *
93
os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
94
95
static PyObject *
96
os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
97
0
{
98
0
    PyObject *return_value = NULL;
99
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
100
0
    static _PyArg_Parser _parser = {NULL, _keywords, "lstat", 0};
101
0
    PyObject *argsbuf[2];
102
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
103
0
    path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
104
0
    int dir_fd = DEFAULT_DIR_FD;
105
106
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
107
0
    if (!args) {
108
0
        goto exit;
109
0
    }
110
0
    if (!path_converter(args[0], &path)) {
111
0
        goto exit;
112
0
    }
113
0
    if (!noptargs) {
114
0
        goto skip_optional_kwonly;
115
0
    }
116
0
    if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
117
0
        goto exit;
118
0
    }
119
0
skip_optional_kwonly:
120
0
    return_value = os_lstat_impl(module, &path, dir_fd);
121
122
0
exit:
123
    /* Cleanup for path */
124
0
    path_cleanup(&path);
125
126
0
    return return_value;
127
0
}
128
129
PyDoc_STRVAR(os_access__doc__,
130
"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
131
"       follow_symlinks=True)\n"
132
"--\n"
133
"\n"
134
"Use the real uid/gid to test for access to a path.\n"
135
"\n"
136
"  path\n"
137
"    Path to be tested; can be string, bytes, or a path-like object.\n"
138
"  mode\n"
139
"    Operating-system mode bitfield.  Can be F_OK to test existence,\n"
140
"    or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
141
"  dir_fd\n"
142
"    If not None, it should be a file descriptor open to a directory,\n"
143
"    and path should be relative; path will then be relative to that\n"
144
"    directory.\n"
145
"  effective_ids\n"
146
"    If True, access will use the effective uid/gid instead of\n"
147
"    the real uid/gid.\n"
148
"  follow_symlinks\n"
149
"    If False, and the last element of the path is a symbolic link,\n"
150
"    access will examine the symbolic link itself instead of the file\n"
151
"    the link points to.\n"
152
"\n"
153
"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
154
"  on your platform.  If they are unavailable, using them will raise a\n"
155
"  NotImplementedError.\n"
156
"\n"
157
"Note that most operations will use the effective uid/gid, therefore this\n"
158
"  routine can be used in a suid/sgid environment to test if the invoking user\n"
159
"  has the specified access to the path.");
160
161
#define OS_ACCESS_METHODDEF    \
162
    {"access", (PyCFunction)(void(*)(void))os_access, METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
163
164
static int
165
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
166
               int effective_ids, int follow_symlinks);
167
168
static PyObject *
169
os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
170
0
{
171
0
    PyObject *return_value = NULL;
172
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
173
0
    static _PyArg_Parser _parser = {NULL, _keywords, "access", 0};
174
0
    PyObject *argsbuf[5];
175
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
176
0
    path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
177
0
    int mode;
178
0
    int dir_fd = DEFAULT_DIR_FD;
179
0
    int effective_ids = 0;
180
0
    int follow_symlinks = 1;
181
0
    int _return_value;
182
183
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
184
0
    if (!args) {
185
0
        goto exit;
186
0
    }
187
0
    if (!path_converter(args[0], &path)) {
188
0
        goto exit;
189
0
    }
190
0
    if (PyFloat_Check(args[1])) {
191
0
        PyErr_SetString(PyExc_TypeError,
192
0
                        "integer argument expected, got float" );
193
0
        goto exit;
194
0
    }
195
0
    mode = _PyLong_AsInt(args[1]);
196
0
    if (mode == -1 && PyErr_Occurred()) {
197
0
        goto exit;
198
0
    }
199
0
    if (!noptargs) {
200
0
        goto skip_optional_kwonly;
201
0
    }
202
0
    if (args[2]) {
203
0
        if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
204
0
            goto exit;
205
0
        }
206
0
        if (!--noptargs) {
207
0
            goto skip_optional_kwonly;
208
0
        }
209
0
    }
210
0
    if (args[3]) {
211
0
        effective_ids = PyObject_IsTrue(args[3]);
212
0
        if (effective_ids < 0) {
213
0
            goto exit;
214
0
        }
215
0
        if (!--noptargs) {
216
0
            goto skip_optional_kwonly;
217
0
        }
218
0
    }
219
0
    follow_symlinks = PyObject_IsTrue(args[4]);
220
0
    if (follow_symlinks < 0) {
221
0
        goto exit;
222
0
    }
223
0
skip_optional_kwonly:
224
0
    _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
225
0
    if ((_return_value == -1) && PyErr_Occurred()) {
226
0
        goto exit;
227
0
    }
228
0
    return_value = PyBool_FromLong((long)_return_value);
229
230
0
exit:
231
    /* Cleanup for path */
232
0
    path_cleanup(&path);
233
234
0
    return return_value;
235
0
}
236
237
#if defined(HAVE_TTYNAME)
238
239
PyDoc_STRVAR(os_ttyname__doc__,
240
"ttyname($module, fd, /)\n"
241
"--\n"
242
"\n"
243
"Return the name of the terminal device connected to \'fd\'.\n"
244
"\n"
245
"  fd\n"
246
"    Integer file descriptor handle.");
247
248
#define OS_TTYNAME_METHODDEF    \
249
    {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
250
251
static PyObject *
252
os_ttyname_impl(PyObject *module, int fd);
253
254
static PyObject *
255
os_ttyname(PyObject *module, PyObject *arg)
256
0
{
257
0
    PyObject *return_value = NULL;
258
0
    int fd;
259
260
0
    if (PyFloat_Check(arg)) {
261
0
        PyErr_SetString(PyExc_TypeError,
262
0
                        "integer argument expected, got float" );
263
0
        goto exit;
264
0
    }
265
0
    fd = _PyLong_AsInt(arg);
266
0
    if (fd == -1 && PyErr_Occurred()) {
267
0
        goto exit;
268
0
    }
269
0
    return_value = os_ttyname_impl(module, fd);
270
271
0
exit:
272
0
    return return_value;
273
0
}
274
275
#endif /* defined(HAVE_TTYNAME) */
276
277
#if defined(HAVE_CTERMID)
278
279
PyDoc_STRVAR(os_ctermid__doc__,
280
"ctermid($module, /)\n"
281
"--\n"
282
"\n"
283
"Return the name of the controlling terminal for this process.");
284
285
#define OS_CTERMID_METHODDEF    \
286
    {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
287
288
static PyObject *
289
os_ctermid_impl(PyObject *module);
290
291
static PyObject *
292
os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
293
0
{
294
0
    return os_ctermid_impl(module);
295
0
}
296
297
#endif /* defined(HAVE_CTERMID) */
298
299
PyDoc_STRVAR(os_chdir__doc__,
300
"chdir($module, /, path)\n"
301
"--\n"
302
"\n"
303
"Change the current working directory to the specified path.\n"
304
"\n"
305
"path may always be specified as a string.\n"
306
"On some platforms, path may also be specified as an open file descriptor.\n"
307
"  If this functionality is unavailable, using it raises an exception.");
308
309
#define OS_CHDIR_METHODDEF    \
310
    {"chdir", (PyCFunction)(void(*)(void))os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
311
312
static PyObject *
313
os_chdir_impl(PyObject *module, path_t *path);
314
315
static PyObject *
316
os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
317
0
{
318
0
    PyObject *return_value = NULL;
319
0
    static const char * const _keywords[] = {"path", NULL};
320
0
    static _PyArg_Parser _parser = {NULL, _keywords, "chdir", 0};
321
0
    PyObject *argsbuf[1];
322
0
    path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
323
324
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
325
0
    if (!args) {
326
0
        goto exit;
327
0
    }
328
0
    if (!path_converter(args[0], &path)) {
329
0
        goto exit;
330
0
    }
331
0
    return_value = os_chdir_impl(module, &path);
332
333
0
exit:
334
    /* Cleanup for path */
335
0
    path_cleanup(&path);
336
337
0
    return return_value;
338
0
}
339
340
#if defined(HAVE_FCHDIR)
341
342
PyDoc_STRVAR(os_fchdir__doc__,
343
"fchdir($module, /, fd)\n"
344
"--\n"
345
"\n"
346
"Change to the directory of the given file descriptor.\n"
347
"\n"
348
"fd must be opened on a directory, not a file.\n"
349
"Equivalent to os.chdir(fd).");
350
351
#define OS_FCHDIR_METHODDEF    \
352
    {"fchdir", (PyCFunction)(void(*)(void))os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
353
354
static PyObject *
355
os_fchdir_impl(PyObject *module, int fd);
356
357
static PyObject *
358
os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
359
0
{
360
0
    PyObject *return_value = NULL;
361
0
    static const char * const _keywords[] = {"fd", NULL};
362
0
    static _PyArg_Parser _parser = {NULL, _keywords, "fchdir", 0};
363
0
    PyObject *argsbuf[1];
364
0
    int fd;
365
366
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
367
0
    if (!args) {
368
0
        goto exit;
369
0
    }
370
0
    if (!fildes_converter(args[0], &fd)) {
371
0
        goto exit;
372
0
    }
373
0
    return_value = os_fchdir_impl(module, fd);
374
375
0
exit:
376
0
    return return_value;
377
0
}
378
379
#endif /* defined(HAVE_FCHDIR) */
380
381
PyDoc_STRVAR(os_chmod__doc__,
382
"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
383
"--\n"
384
"\n"
385
"Change the access permissions of a file.\n"
386
"\n"
387
"  path\n"
388
"    Path to be modified.  May always be specified as a str, bytes, or a path-like object.\n"
389
"    On some platforms, path may also be specified as an open file descriptor.\n"
390
"    If this functionality is unavailable, using it raises an exception.\n"
391
"  mode\n"
392
"    Operating-system mode bitfield.\n"
393
"  dir_fd\n"
394
"    If not None, it should be a file descriptor open to a directory,\n"
395
"    and path should be relative; path will then be relative to that\n"
396
"    directory.\n"
397
"  follow_symlinks\n"
398
"    If False, and the last element of the path is a symbolic link,\n"
399
"    chmod will modify the symbolic link itself instead of the file\n"
400
"    the link points to.\n"
401
"\n"
402
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
403
"  an open file descriptor.\n"
404
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
405
"  If they are unavailable, using them will raise a NotImplementedError.");
406
407
#define OS_CHMOD_METHODDEF    \
408
    {"chmod", (PyCFunction)(void(*)(void))os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
409
410
static PyObject *
411
os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
412
              int follow_symlinks);
413
414
static PyObject *
415
os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
416
0
{
417
0
    PyObject *return_value = NULL;
418
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
419
0
    static _PyArg_Parser _parser = {NULL, _keywords, "chmod", 0};
420
0
    PyObject *argsbuf[4];
421
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
422
0
    path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
423
0
    int mode;
424
0
    int dir_fd = DEFAULT_DIR_FD;
425
0
    int follow_symlinks = 1;
426
427
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
428
0
    if (!args) {
429
0
        goto exit;
430
0
    }
431
0
    if (!path_converter(args[0], &path)) {
432
0
        goto exit;
433
0
    }
434
0
    if (PyFloat_Check(args[1])) {
435
0
        PyErr_SetString(PyExc_TypeError,
436
0
                        "integer argument expected, got float" );
437
0
        goto exit;
438
0
    }
439
0
    mode = _PyLong_AsInt(args[1]);
440
0
    if (mode == -1 && PyErr_Occurred()) {
441
0
        goto exit;
442
0
    }
443
0
    if (!noptargs) {
444
0
        goto skip_optional_kwonly;
445
0
    }
446
0
    if (args[2]) {
447
0
        if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
448
0
            goto exit;
449
0
        }
450
0
        if (!--noptargs) {
451
0
            goto skip_optional_kwonly;
452
0
        }
453
0
    }
454
0
    follow_symlinks = PyObject_IsTrue(args[3]);
455
0
    if (follow_symlinks < 0) {
456
0
        goto exit;
457
0
    }
458
0
skip_optional_kwonly:
459
0
    return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
460
461
0
exit:
462
    /* Cleanup for path */
463
0
    path_cleanup(&path);
464
465
0
    return return_value;
466
0
}
467
468
#if defined(HAVE_FCHMOD)
469
470
PyDoc_STRVAR(os_fchmod__doc__,
471
"fchmod($module, /, fd, mode)\n"
472
"--\n"
473
"\n"
474
"Change the access permissions of the file given by file descriptor fd.\n"
475
"\n"
476
"Equivalent to os.chmod(fd, mode).");
477
478
#define OS_FCHMOD_METHODDEF    \
479
    {"fchmod", (PyCFunction)(void(*)(void))os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
480
481
static PyObject *
482
os_fchmod_impl(PyObject *module, int fd, int mode);
483
484
static PyObject *
485
os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
486
0
{
487
0
    PyObject *return_value = NULL;
488
0
    static const char * const _keywords[] = {"fd", "mode", NULL};
489
0
    static _PyArg_Parser _parser = {NULL, _keywords, "fchmod", 0};
490
0
    PyObject *argsbuf[2];
491
0
    int fd;
492
0
    int mode;
493
494
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
495
0
    if (!args) {
496
0
        goto exit;
497
0
    }
498
0
    if (PyFloat_Check(args[0])) {
499
0
        PyErr_SetString(PyExc_TypeError,
500
0
                        "integer argument expected, got float" );
501
0
        goto exit;
502
0
    }
503
0
    fd = _PyLong_AsInt(args[0]);
504
0
    if (fd == -1 && PyErr_Occurred()) {
505
0
        goto exit;
506
0
    }
507
0
    if (PyFloat_Check(args[1])) {
508
0
        PyErr_SetString(PyExc_TypeError,
509
0
                        "integer argument expected, got float" );
510
0
        goto exit;
511
0
    }
512
0
    mode = _PyLong_AsInt(args[1]);
513
0
    if (mode == -1 && PyErr_Occurred()) {
514
0
        goto exit;
515
0
    }
516
0
    return_value = os_fchmod_impl(module, fd, mode);
517
518
0
exit:
519
0
    return return_value;
520
0
}
521
522
#endif /* defined(HAVE_FCHMOD) */
523
524
#if defined(HAVE_LCHMOD)
525
526
PyDoc_STRVAR(os_lchmod__doc__,
527
"lchmod($module, /, path, mode)\n"
528
"--\n"
529
"\n"
530
"Change the access permissions of a file, without following symbolic links.\n"
531
"\n"
532
"If path is a symlink, this affects the link itself rather than the target.\n"
533
"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
534
535
#define OS_LCHMOD_METHODDEF    \
536
    {"lchmod", (PyCFunction)(void(*)(void))os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
537
538
static PyObject *
539
os_lchmod_impl(PyObject *module, path_t *path, int mode);
540
541
static PyObject *
542
os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
543
{
544
    PyObject *return_value = NULL;
545
    static const char * const _keywords[] = {"path", "mode", NULL};
546
    static _PyArg_Parser _parser = {NULL, _keywords, "lchmod", 0};
547
    PyObject *argsbuf[2];
548
    path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
549
    int mode;
550
551
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
552
    if (!args) {
553
        goto exit;
554
    }
555
    if (!path_converter(args[0], &path)) {
556
        goto exit;
557
    }
558
    if (PyFloat_Check(args[1])) {
559
        PyErr_SetString(PyExc_TypeError,
560
                        "integer argument expected, got float" );
561
        goto exit;
562
    }
563
    mode = _PyLong_AsInt(args[1]);
564
    if (mode == -1 && PyErr_Occurred()) {
565
        goto exit;
566
    }
567
    return_value = os_lchmod_impl(module, &path, mode);
568
569
exit:
570
    /* Cleanup for path */
571
    path_cleanup(&path);
572
573
    return return_value;
574
}
575
576
#endif /* defined(HAVE_LCHMOD) */
577
578
#if defined(HAVE_CHFLAGS)
579
580
PyDoc_STRVAR(os_chflags__doc__,
581
"chflags($module, /, path, flags, follow_symlinks=True)\n"
582
"--\n"
583
"\n"
584
"Set file flags.\n"
585
"\n"
586
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
587
"  link, chflags will change flags on the symbolic link itself instead of the\n"
588
"  file the link points to.\n"
589
"follow_symlinks may not be implemented on your platform.  If it is\n"
590
"unavailable, using it will raise a NotImplementedError.");
591
592
#define OS_CHFLAGS_METHODDEF    \
593
    {"chflags", (PyCFunction)(void(*)(void))os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
594
595
static PyObject *
596
os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
597
                int follow_symlinks);
598
599
static PyObject *
600
os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
601
{
602
    PyObject *return_value = NULL;
603
    static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
604
    static _PyArg_Parser _parser = {NULL, _keywords, "chflags", 0};
605
    PyObject *argsbuf[3];
606
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
607
    path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
608
    unsigned long flags;
609
    int follow_symlinks = 1;
610
611
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
612
    if (!args) {
613
        goto exit;
614
    }
615
    if (!path_converter(args[0], &path)) {
616
        goto exit;
617
    }
618
    if (!PyLong_Check(args[1])) {
619
        _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]);
620
        goto exit;
621
    }
622
    flags = PyLong_AsUnsignedLongMask(args[1]);
623
    if (!noptargs) {
624
        goto skip_optional_pos;
625
    }
626
    follow_symlinks = PyObject_IsTrue(args[2]);
627
    if (follow_symlinks < 0) {
628
        goto exit;
629
    }
630
skip_optional_pos:
631
    return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
632
633
exit:
634
    /* Cleanup for path */
635
    path_cleanup(&path);
636
637
    return return_value;
638
}
639
640
#endif /* defined(HAVE_CHFLAGS) */
641
642
#if defined(HAVE_LCHFLAGS)
643
644
PyDoc_STRVAR(os_lchflags__doc__,
645
"lchflags($module, /, path, flags)\n"
646
"--\n"
647
"\n"
648
"Set file flags.\n"
649
"\n"
650
"This function will not follow symbolic links.\n"
651
"Equivalent to chflags(path, flags, follow_symlinks=False).");
652
653
#define OS_LCHFLAGS_METHODDEF    \
654
    {"lchflags", (PyCFunction)(void(*)(void))os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
655
656
static PyObject *
657
os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
658
659
static PyObject *
660
os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
661
{
662
    PyObject *return_value = NULL;
663
    static const char * const _keywords[] = {"path", "flags", NULL};
664
    static _PyArg_Parser _parser = {NULL, _keywords, "lchflags", 0};
665
    PyObject *argsbuf[2];
666
    path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
667
    unsigned long flags;
668
669
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
670
    if (!args) {
671
        goto exit;
672
    }
673
    if (!path_converter(args[0], &path)) {
674
        goto exit;
675
    }
676
    if (!PyLong_Check(args[1])) {
677
        _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]);
678
        goto exit;
679
    }
680
    flags = PyLong_AsUnsignedLongMask(args[1]);
681
    return_value = os_lchflags_impl(module, &path, flags);
682
683
exit:
684
    /* Cleanup for path */
685
    path_cleanup(&path);
686
687
    return return_value;
688
}
689
690
#endif /* defined(HAVE_LCHFLAGS) */
691
692
#if defined(HAVE_CHROOT)
693
694
PyDoc_STRVAR(os_chroot__doc__,
695
"chroot($module, /, path)\n"
696
"--\n"
697
"\n"
698
"Change root directory to path.");
699
700
#define OS_CHROOT_METHODDEF    \
701
    {"chroot", (PyCFunction)(void(*)(void))os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
702
703
static PyObject *
704
os_chroot_impl(PyObject *module, path_t *path);
705
706
static PyObject *
707
os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
708
0
{
709
0
    PyObject *return_value = NULL;
710
0
    static const char * const _keywords[] = {"path", NULL};
711
0
    static _PyArg_Parser _parser = {NULL, _keywords, "chroot", 0};
712
0
    PyObject *argsbuf[1];
713
0
    path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
714
715
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
716
0
    if (!args) {
717
0
        goto exit;
718
0
    }
719
0
    if (!path_converter(args[0], &path)) {
720
0
        goto exit;
721
0
    }
722
0
    return_value = os_chroot_impl(module, &path);
723
724
0
exit:
725
    /* Cleanup for path */
726
0
    path_cleanup(&path);
727
728
0
    return return_value;
729
0
}
730
731
#endif /* defined(HAVE_CHROOT) */
732
733
#if defined(HAVE_FSYNC)
734
735
PyDoc_STRVAR(os_fsync__doc__,
736
"fsync($module, /, fd)\n"
737
"--\n"
738
"\n"
739
"Force write of fd to disk.");
740
741
#define OS_FSYNC_METHODDEF    \
742
    {"fsync", (PyCFunction)(void(*)(void))os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
743
744
static PyObject *
745
os_fsync_impl(PyObject *module, int fd);
746
747
static PyObject *
748
os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
749
0
{
750
0
    PyObject *return_value = NULL;
751
0
    static const char * const _keywords[] = {"fd", NULL};
752
0
    static _PyArg_Parser _parser = {NULL, _keywords, "fsync", 0};
753
0
    PyObject *argsbuf[1];
754
0
    int fd;
755
756
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
757
0
    if (!args) {
758
0
        goto exit;
759
0
    }
760
0
    if (!fildes_converter(args[0], &fd)) {
761
0
        goto exit;
762
0
    }
763
0
    return_value = os_fsync_impl(module, fd);
764
765
0
exit:
766
0
    return return_value;
767
0
}
768
769
#endif /* defined(HAVE_FSYNC) */
770
771
#if defined(HAVE_SYNC)
772
773
PyDoc_STRVAR(os_sync__doc__,
774
"sync($module, /)\n"
775
"--\n"
776
"\n"
777
"Force write of everything to disk.");
778
779
#define OS_SYNC_METHODDEF    \
780
    {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
781
782
static PyObject *
783
os_sync_impl(PyObject *module);
784
785
static PyObject *
786
os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
787
0
{
788
0
    return os_sync_impl(module);
789
0
}
790
791
#endif /* defined(HAVE_SYNC) */
792
793
#if defined(HAVE_FDATASYNC)
794
795
PyDoc_STRVAR(os_fdatasync__doc__,
796
"fdatasync($module, /, fd)\n"
797
"--\n"
798
"\n"
799
"Force write of fd to disk without forcing update of metadata.");
800
801
#define OS_FDATASYNC_METHODDEF    \
802
    {"fdatasync", (PyCFunction)(void(*)(void))os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
803
804
static PyObject *
805
os_fdatasync_impl(PyObject *module, int fd);
806
807
static PyObject *
808
os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
809
0
{
810
0
    PyObject *return_value = NULL;
811
0
    static const char * const _keywords[] = {"fd", NULL};
812
0
    static _PyArg_Parser _parser = {NULL, _keywords, "fdatasync", 0};
813
0
    PyObject *argsbuf[1];
814
0
    int fd;
815
816
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
817
0
    if (!args) {
818
0
        goto exit;
819
0
    }
820
0
    if (!fildes_converter(args[0], &fd)) {
821
0
        goto exit;
822
0
    }
823
0
    return_value = os_fdatasync_impl(module, fd);
824
825
0
exit:
826
0
    return return_value;
827
0
}
828
829
#endif /* defined(HAVE_FDATASYNC) */
830
831
#if defined(HAVE_CHOWN)
832
833
PyDoc_STRVAR(os_chown__doc__,
834
"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
835
"--\n"
836
"\n"
837
"Change the owner and group id of path to the numeric uid and gid.\\\n"
838
"\n"
839
"  path\n"
840
"    Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
841
"  dir_fd\n"
842
"    If not None, it should be a file descriptor open to a directory,\n"
843
"    and path should be relative; path will then be relative to that\n"
844
"    directory.\n"
845
"  follow_symlinks\n"
846
"    If False, and the last element of the path is a symbolic link,\n"
847
"    stat will examine the symbolic link itself instead of the file\n"
848
"    the link points to.\n"
849
"\n"
850
"path may always be specified as a string.\n"
851
"On some platforms, path may also be specified as an open file descriptor.\n"
852
"  If this functionality is unavailable, using it raises an exception.\n"
853
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
854
"  and path should be relative; path will then be relative to that directory.\n"
855
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
856
"  link, chown will modify the symbolic link itself instead of the file the\n"
857
"  link points to.\n"
858
"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
859
"  an open file descriptor.\n"
860
"dir_fd and follow_symlinks may not be implemented on your platform.\n"
861
"  If they are unavailable, using them will raise a NotImplementedError.");
862
863
#define OS_CHOWN_METHODDEF    \
864
    {"chown", (PyCFunction)(void(*)(void))os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
865
866
static PyObject *
867
os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
868
              int dir_fd, int follow_symlinks);
869
870
static PyObject *
871
os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
872
0
{
873
0
    PyObject *return_value = NULL;
874
0
    static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
875
0
    static _PyArg_Parser _parser = {NULL, _keywords, "chown", 0};
876
0
    PyObject *argsbuf[5];
877
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
878
0
    path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
879
0
    uid_t uid;
880
0
    gid_t gid;
881
0
    int dir_fd = DEFAULT_DIR_FD;
882
0
    int follow_symlinks = 1;
883
884
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
885
0
    if (!args) {
886
0
        goto exit;
887
0
    }
888
0
    if (!path_converter(args[0], &path)) {
889
0
        goto exit;
890
0
    }
891
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
892
0
        goto exit;
893
0
    }
894
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
895
0
        goto exit;
896
0
    }
897
0
    if (!noptargs) {
898
0
        goto skip_optional_kwonly;
899
0
    }
900
0
    if (args[3]) {
901
0
        if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
902
0
            goto exit;
903
0
        }
904
0
        if (!--noptargs) {
905
0
            goto skip_optional_kwonly;
906
0
        }
907
0
    }
908
0
    follow_symlinks = PyObject_IsTrue(args[4]);
909
0
    if (follow_symlinks < 0) {
910
0
        goto exit;
911
0
    }
912
0
skip_optional_kwonly:
913
0
    return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
914
915
0
exit:
916
    /* Cleanup for path */
917
0
    path_cleanup(&path);
918
919
0
    return return_value;
920
0
}
921
922
#endif /* defined(HAVE_CHOWN) */
923
924
#if defined(HAVE_FCHOWN)
925
926
PyDoc_STRVAR(os_fchown__doc__,
927
"fchown($module, /, fd, uid, gid)\n"
928
"--\n"
929
"\n"
930
"Change the owner and group id of the file specified by file descriptor.\n"
931
"\n"
932
"Equivalent to os.chown(fd, uid, gid).");
933
934
#define OS_FCHOWN_METHODDEF    \
935
    {"fchown", (PyCFunction)(void(*)(void))os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
936
937
static PyObject *
938
os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
939
940
static PyObject *
941
os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
942
0
{
943
0
    PyObject *return_value = NULL;
944
0
    static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
945
0
    static _PyArg_Parser _parser = {NULL, _keywords, "fchown", 0};
946
0
    PyObject *argsbuf[3];
947
0
    int fd;
948
0
    uid_t uid;
949
0
    gid_t gid;
950
951
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
952
0
    if (!args) {
953
0
        goto exit;
954
0
    }
955
0
    if (PyFloat_Check(args[0])) {
956
0
        PyErr_SetString(PyExc_TypeError,
957
0
                        "integer argument expected, got float" );
958
0
        goto exit;
959
0
    }
960
0
    fd = _PyLong_AsInt(args[0]);
961
0
    if (fd == -1 && PyErr_Occurred()) {
962
0
        goto exit;
963
0
    }
964
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
965
0
        goto exit;
966
0
    }
967
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
968
0
        goto exit;
969
0
    }
970
0
    return_value = os_fchown_impl(module, fd, uid, gid);
971
972
0
exit:
973
0
    return return_value;
974
0
}
975
976
#endif /* defined(HAVE_FCHOWN) */
977
978
#if defined(HAVE_LCHOWN)
979
980
PyDoc_STRVAR(os_lchown__doc__,
981
"lchown($module, /, path, uid, gid)\n"
982
"--\n"
983
"\n"
984
"Change the owner and group id of path to the numeric uid and gid.\n"
985
"\n"
986
"This function will not follow symbolic links.\n"
987
"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
988
989
#define OS_LCHOWN_METHODDEF    \
990
    {"lchown", (PyCFunction)(void(*)(void))os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
991
992
static PyObject *
993
os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
994
995
static PyObject *
996
os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
997
0
{
998
0
    PyObject *return_value = NULL;
999
0
    static const char * const _keywords[] = {"path", "uid", "gid", NULL};
1000
0
    static _PyArg_Parser _parser = {NULL, _keywords, "lchown", 0};
1001
0
    PyObject *argsbuf[3];
1002
0
    path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
1003
0
    uid_t uid;
1004
0
    gid_t gid;
1005
1006
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
1007
0
    if (!args) {
1008
0
        goto exit;
1009
0
    }
1010
0
    if (!path_converter(args[0], &path)) {
1011
0
        goto exit;
1012
0
    }
1013
0
    if (!_Py_Uid_Converter(args[1], &uid)) {
1014
0
        goto exit;
1015
0
    }
1016
0
    if (!_Py_Gid_Converter(args[2], &gid)) {
1017
0
        goto exit;
1018
0
    }
1019
0
    return_value = os_lchown_impl(module, &path, uid, gid);
1020
1021
0
exit:
1022
    /* Cleanup for path */
1023
0
    path_cleanup(&path);
1024
1025
0
    return return_value;
1026
0
}
1027
1028
#endif /* defined(HAVE_LCHOWN) */
1029
1030
PyDoc_STRVAR(os_getcwd__doc__,
1031
"getcwd($module, /)\n"
1032
"--\n"
1033
"\n"
1034
"Return a unicode string representing the current working directory.");
1035
1036
#define OS_GETCWD_METHODDEF    \
1037
    {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
1038
1039
static PyObject *
1040
os_getcwd_impl(PyObject *module);
1041
1042
static PyObject *
1043
os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
1044
0
{
1045
0
    return os_getcwd_impl(module);
1046
0
}
1047
1048
PyDoc_STRVAR(os_getcwdb__doc__,
1049
"getcwdb($module, /)\n"
1050
"--\n"
1051
"\n"
1052
"Return a bytes string representing the current working directory.");
1053
1054
#define OS_GETCWDB_METHODDEF    \
1055
    {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
1056
1057
static PyObject *
1058
os_getcwdb_impl(PyObject *module);
1059
1060
static PyObject *
1061
os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
1062
0
{
1063
0
    return os_getcwdb_impl(module);
1064
0
}
1065
1066
#if defined(HAVE_LINK)
1067
1068
PyDoc_STRVAR(os_link__doc__,
1069
"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
1070
"     follow_symlinks=True)\n"
1071
"--\n"
1072
"\n"
1073
"Create a hard link to a file.\n"
1074
"\n"
1075
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1076
"  descriptor open to a directory, and the respective path string (src or dst)\n"
1077
"  should be relative; the path will then be relative to that directory.\n"
1078
"If follow_symlinks is False, and the last element of src is a symbolic\n"
1079
"  link, link will create a link to the symbolic link itself instead of the\n"
1080
"  file the link points to.\n"
1081
"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
1082
"  platform.  If they are unavailable, using them will raise a\n"
1083
"  NotImplementedError.");
1084
1085
#define OS_LINK_METHODDEF    \
1086
    {"link", (PyCFunction)(void(*)(void))os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
1087
1088
static PyObject *
1089
os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1090
             int dst_dir_fd, int follow_symlinks);
1091
1092
static PyObject *
1093
os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1094
0
{
1095
0
    PyObject *return_value = NULL;
1096
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
1097
0
    static _PyArg_Parser _parser = {NULL, _keywords, "link", 0};
1098
0
    PyObject *argsbuf[5];
1099
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1100
0
    path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
1101
0
    path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
1102
0
    int src_dir_fd = DEFAULT_DIR_FD;
1103
0
    int dst_dir_fd = DEFAULT_DIR_FD;
1104
0
    int follow_symlinks = 1;
1105
1106
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
1107
0
    if (!args) {
1108
0
        goto exit;
1109
0
    }
1110
0
    if (!path_converter(args[0], &src)) {
1111
0
        goto exit;
1112
0
    }
1113
0
    if (!path_converter(args[1], &dst)) {
1114
0
        goto exit;
1115
0
    }
1116
0
    if (!noptargs) {
1117
0
        goto skip_optional_kwonly;
1118
0
    }
1119
0
    if (args[2]) {
1120
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
1121
0
            goto exit;
1122
0
        }
1123
0
        if (!--noptargs) {
1124
0
            goto skip_optional_kwonly;
1125
0
        }
1126
0
    }
1127
0
    if (args[3]) {
1128
0
        if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1129
0
            goto exit;
1130
0
        }
1131
0
        if (!--noptargs) {
1132
0
            goto skip_optional_kwonly;
1133
0
        }
1134
0
    }
1135
0
    follow_symlinks = PyObject_IsTrue(args[4]);
1136
0
    if (follow_symlinks < 0) {
1137
0
        goto exit;
1138
0
    }
1139
0
skip_optional_kwonly:
1140
0
    return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
1141
1142
0
exit:
1143
    /* Cleanup for src */
1144
0
    path_cleanup(&src);
1145
    /* Cleanup for dst */
1146
0
    path_cleanup(&dst);
1147
1148
0
    return return_value;
1149
0
}
1150
1151
#endif /* defined(HAVE_LINK) */
1152
1153
PyDoc_STRVAR(os_listdir__doc__,
1154
"listdir($module, /, path=None)\n"
1155
"--\n"
1156
"\n"
1157
"Return a list containing the names of the files in the directory.\n"
1158
"\n"
1159
"path can be specified as either str, bytes, or a path-like object.  If path is bytes,\n"
1160
"  the filenames returned will also be bytes; in all other circumstances\n"
1161
"  the filenames returned will be str.\n"
1162
"If path is None, uses the path=\'.\'.\n"
1163
"On some platforms, path may also be specified as an open file descriptor;\\\n"
1164
"  the file descriptor must refer to a directory.\n"
1165
"  If this functionality is unavailable, using it raises NotImplementedError.\n"
1166
"\n"
1167
"The list is in arbitrary order.  It does not include the special\n"
1168
"entries \'.\' and \'..\' even if they are present in the directory.");
1169
1170
#define OS_LISTDIR_METHODDEF    \
1171
    {"listdir", (PyCFunction)(void(*)(void))os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
1172
1173
static PyObject *
1174
os_listdir_impl(PyObject *module, path_t *path);
1175
1176
static PyObject *
1177
os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1178
29
{
1179
29
    PyObject *return_value = NULL;
1180
29
    static const char * const _keywords[] = {"path", NULL};
1181
29
    static _PyArg_Parser _parser = {NULL, _keywords, "listdir", 0};
1182
29
    PyObject *argsbuf[1];
1183
29
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1184
29
    path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
1185
1186
29
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
1187
29
    if (!args) {
1188
0
        goto exit;
1189
0
    }
1190
29
    if (!noptargs) {
1191
0
        goto skip_optional_pos;
1192
0
    }
1193
29
    if (!path_converter(args[0], &path)) {
1194
0
        goto exit;
1195
0
    }
1196
29
skip_optional_pos:
1197
29
    return_value = os_listdir_impl(module, &path);
1198
1199
29
exit:
1200
    /* Cleanup for path */
1201
29
    path_cleanup(&path);
1202
1203
29
    return return_value;
1204
29
}
1205
1206
#if defined(MS_WINDOWS)
1207
1208
PyDoc_STRVAR(os__getfullpathname__doc__,
1209
"_getfullpathname($module, path, /)\n"
1210
"--\n"
1211
"\n");
1212
1213
#define OS__GETFULLPATHNAME_METHODDEF    \
1214
    {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
1215
1216
static PyObject *
1217
os__getfullpathname_impl(PyObject *module, path_t *path);
1218
1219
static PyObject *
1220
os__getfullpathname(PyObject *module, PyObject *arg)
1221
{
1222
    PyObject *return_value = NULL;
1223
    path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
1224
1225
    if (!path_converter(arg, &path)) {
1226
        goto exit;
1227
    }
1228
    return_value = os__getfullpathname_impl(module, &path);
1229
1230
exit:
1231
    /* Cleanup for path */
1232
    path_cleanup(&path);
1233
1234
    return return_value;
1235
}
1236
1237
#endif /* defined(MS_WINDOWS) */
1238
1239
#if defined(MS_WINDOWS)
1240
1241
PyDoc_STRVAR(os__getfinalpathname__doc__,
1242
"_getfinalpathname($module, path, /)\n"
1243
"--\n"
1244
"\n"
1245
"A helper function for samepath on windows.");
1246
1247
#define OS__GETFINALPATHNAME_METHODDEF    \
1248
    {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
1249
1250
static PyObject *
1251
os__getfinalpathname_impl(PyObject *module, path_t *path);
1252
1253
static PyObject *
1254
os__getfinalpathname(PyObject *module, PyObject *arg)
1255
{
1256
    PyObject *return_value = NULL;
1257
    path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
1258
1259
    if (!path_converter(arg, &path)) {
1260
        goto exit;
1261
    }
1262
    return_value = os__getfinalpathname_impl(module, &path);
1263
1264
exit:
1265
    /* Cleanup for path */
1266
    path_cleanup(&path);
1267
1268
    return return_value;
1269
}
1270
1271
#endif /* defined(MS_WINDOWS) */
1272
1273
#if defined(MS_WINDOWS)
1274
1275
PyDoc_STRVAR(os__getvolumepathname__doc__,
1276
"_getvolumepathname($module, /, path)\n"
1277
"--\n"
1278
"\n"
1279
"A helper function for ismount on Win32.");
1280
1281
#define OS__GETVOLUMEPATHNAME_METHODDEF    \
1282
    {"_getvolumepathname", (PyCFunction)(void(*)(void))os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
1283
1284
static PyObject *
1285
os__getvolumepathname_impl(PyObject *module, path_t *path);
1286
1287
static PyObject *
1288
os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1289
{
1290
    PyObject *return_value = NULL;
1291
    static const char * const _keywords[] = {"path", NULL};
1292
    static _PyArg_Parser _parser = {NULL, _keywords, "_getvolumepathname", 0};
1293
    PyObject *argsbuf[1];
1294
    path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
1295
1296
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1297
    if (!args) {
1298
        goto exit;
1299
    }
1300
    if (!path_converter(args[0], &path)) {
1301
        goto exit;
1302
    }
1303
    return_value = os__getvolumepathname_impl(module, &path);
1304
1305
exit:
1306
    /* Cleanup for path */
1307
    path_cleanup(&path);
1308
1309
    return return_value;
1310
}
1311
1312
#endif /* defined(MS_WINDOWS) */
1313
1314
PyDoc_STRVAR(os_mkdir__doc__,
1315
"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1316
"--\n"
1317
"\n"
1318
"Create a directory.\n"
1319
"\n"
1320
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1321
"  and path should be relative; path will then be relative to that directory.\n"
1322
"dir_fd may not be implemented on your platform.\n"
1323
"  If it is unavailable, using it will raise a NotImplementedError.\n"
1324
"\n"
1325
"The mode argument is ignored on Windows.");
1326
1327
#define OS_MKDIR_METHODDEF    \
1328
    {"mkdir", (PyCFunction)(void(*)(void))os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
1329
1330
static PyObject *
1331
os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
1332
1333
static PyObject *
1334
os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1335
0
{
1336
0
    PyObject *return_value = NULL;
1337
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1338
0
    static _PyArg_Parser _parser = {NULL, _keywords, "mkdir", 0};
1339
0
    PyObject *argsbuf[3];
1340
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1341
0
    path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1342
0
    int mode = 511;
1343
0
    int dir_fd = DEFAULT_DIR_FD;
1344
1345
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
1346
0
    if (!args) {
1347
0
        goto exit;
1348
0
    }
1349
0
    if (!path_converter(args[0], &path)) {
1350
0
        goto exit;
1351
0
    }
1352
0
    if (!noptargs) {
1353
0
        goto skip_optional_pos;
1354
0
    }
1355
0
    if (args[1]) {
1356
0
        if (PyFloat_Check(args[1])) {
1357
0
            PyErr_SetString(PyExc_TypeError,
1358
0
                            "integer argument expected, got float" );
1359
0
            goto exit;
1360
0
        }
1361
0
        mode = _PyLong_AsInt(args[1]);
1362
0
        if (mode == -1 && PyErr_Occurred()) {
1363
0
            goto exit;
1364
0
        }
1365
0
        if (!--noptargs) {
1366
0
            goto skip_optional_pos;
1367
0
        }
1368
0
    }
1369
0
skip_optional_pos:
1370
0
    if (!noptargs) {
1371
0
        goto skip_optional_kwonly;
1372
0
    }
1373
0
    if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
1374
0
        goto exit;
1375
0
    }
1376
0
skip_optional_kwonly:
1377
0
    return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1378
1379
0
exit:
1380
    /* Cleanup for path */
1381
0
    path_cleanup(&path);
1382
1383
0
    return return_value;
1384
0
}
1385
1386
#if defined(HAVE_NICE)
1387
1388
PyDoc_STRVAR(os_nice__doc__,
1389
"nice($module, increment, /)\n"
1390
"--\n"
1391
"\n"
1392
"Add increment to the priority of process and return the new priority.");
1393
1394
#define OS_NICE_METHODDEF    \
1395
    {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
1396
1397
static PyObject *
1398
os_nice_impl(PyObject *module, int increment);
1399
1400
static PyObject *
1401
os_nice(PyObject *module, PyObject *arg)
1402
0
{
1403
0
    PyObject *return_value = NULL;
1404
0
    int increment;
1405
1406
0
    if (PyFloat_Check(arg)) {
1407
0
        PyErr_SetString(PyExc_TypeError,
1408
0
                        "integer argument expected, got float" );
1409
0
        goto exit;
1410
0
    }
1411
0
    increment = _PyLong_AsInt(arg);
1412
0
    if (increment == -1 && PyErr_Occurred()) {
1413
0
        goto exit;
1414
0
    }
1415
0
    return_value = os_nice_impl(module, increment);
1416
1417
0
exit:
1418
0
    return return_value;
1419
0
}
1420
1421
#endif /* defined(HAVE_NICE) */
1422
1423
#if defined(HAVE_GETPRIORITY)
1424
1425
PyDoc_STRVAR(os_getpriority__doc__,
1426
"getpriority($module, /, which, who)\n"
1427
"--\n"
1428
"\n"
1429
"Return program scheduling priority.");
1430
1431
#define OS_GETPRIORITY_METHODDEF    \
1432
    {"getpriority", (PyCFunction)(void(*)(void))os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
1433
1434
static PyObject *
1435
os_getpriority_impl(PyObject *module, int which, int who);
1436
1437
static PyObject *
1438
os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1439
0
{
1440
0
    PyObject *return_value = NULL;
1441
0
    static const char * const _keywords[] = {"which", "who", NULL};
1442
0
    static _PyArg_Parser _parser = {NULL, _keywords, "getpriority", 0};
1443
0
    PyObject *argsbuf[2];
1444
0
    int which;
1445
0
    int who;
1446
1447
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
1448
0
    if (!args) {
1449
0
        goto exit;
1450
0
    }
1451
0
    if (PyFloat_Check(args[0])) {
1452
0
        PyErr_SetString(PyExc_TypeError,
1453
0
                        "integer argument expected, got float" );
1454
0
        goto exit;
1455
0
    }
1456
0
    which = _PyLong_AsInt(args[0]);
1457
0
    if (which == -1 && PyErr_Occurred()) {
1458
0
        goto exit;
1459
0
    }
1460
0
    if (PyFloat_Check(args[1])) {
1461
0
        PyErr_SetString(PyExc_TypeError,
1462
0
                        "integer argument expected, got float" );
1463
0
        goto exit;
1464
0
    }
1465
0
    who = _PyLong_AsInt(args[1]);
1466
0
    if (who == -1 && PyErr_Occurred()) {
1467
0
        goto exit;
1468
0
    }
1469
0
    return_value = os_getpriority_impl(module, which, who);
1470
1471
0
exit:
1472
0
    return return_value;
1473
0
}
1474
1475
#endif /* defined(HAVE_GETPRIORITY) */
1476
1477
#if defined(HAVE_SETPRIORITY)
1478
1479
PyDoc_STRVAR(os_setpriority__doc__,
1480
"setpriority($module, /, which, who, priority)\n"
1481
"--\n"
1482
"\n"
1483
"Set program scheduling priority.");
1484
1485
#define OS_SETPRIORITY_METHODDEF    \
1486
    {"setpriority", (PyCFunction)(void(*)(void))os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
1487
1488
static PyObject *
1489
os_setpriority_impl(PyObject *module, int which, int who, int priority);
1490
1491
static PyObject *
1492
os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1493
0
{
1494
0
    PyObject *return_value = NULL;
1495
0
    static const char * const _keywords[] = {"which", "who", "priority", NULL};
1496
0
    static _PyArg_Parser _parser = {NULL, _keywords, "setpriority", 0};
1497
0
    PyObject *argsbuf[3];
1498
0
    int which;
1499
0
    int who;
1500
0
    int priority;
1501
1502
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
1503
0
    if (!args) {
1504
0
        goto exit;
1505
0
    }
1506
0
    if (PyFloat_Check(args[0])) {
1507
0
        PyErr_SetString(PyExc_TypeError,
1508
0
                        "integer argument expected, got float" );
1509
0
        goto exit;
1510
0
    }
1511
0
    which = _PyLong_AsInt(args[0]);
1512
0
    if (which == -1 && PyErr_Occurred()) {
1513
0
        goto exit;
1514
0
    }
1515
0
    if (PyFloat_Check(args[1])) {
1516
0
        PyErr_SetString(PyExc_TypeError,
1517
0
                        "integer argument expected, got float" );
1518
0
        goto exit;
1519
0
    }
1520
0
    who = _PyLong_AsInt(args[1]);
1521
0
    if (who == -1 && PyErr_Occurred()) {
1522
0
        goto exit;
1523
0
    }
1524
0
    if (PyFloat_Check(args[2])) {
1525
0
        PyErr_SetString(PyExc_TypeError,
1526
0
                        "integer argument expected, got float" );
1527
0
        goto exit;
1528
0
    }
1529
0
    priority = _PyLong_AsInt(args[2]);
1530
0
    if (priority == -1 && PyErr_Occurred()) {
1531
0
        goto exit;
1532
0
    }
1533
0
    return_value = os_setpriority_impl(module, which, who, priority);
1534
1535
0
exit:
1536
0
    return return_value;
1537
0
}
1538
1539
#endif /* defined(HAVE_SETPRIORITY) */
1540
1541
PyDoc_STRVAR(os_rename__doc__,
1542
"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1543
"--\n"
1544
"\n"
1545
"Rename a file or directory.\n"
1546
"\n"
1547
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1548
"  descriptor open to a directory, and the respective path string (src or dst)\n"
1549
"  should be relative; the path will then be relative to that directory.\n"
1550
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1551
"  If they are unavailable, using them will raise a NotImplementedError.");
1552
1553
#define OS_RENAME_METHODDEF    \
1554
    {"rename", (PyCFunction)(void(*)(void))os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
1555
1556
static PyObject *
1557
os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1558
               int dst_dir_fd);
1559
1560
static PyObject *
1561
os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1562
0
{
1563
0
    PyObject *return_value = NULL;
1564
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1565
0
    static _PyArg_Parser _parser = {NULL, _keywords, "rename", 0};
1566
0
    PyObject *argsbuf[4];
1567
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1568
0
    path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1569
0
    path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1570
0
    int src_dir_fd = DEFAULT_DIR_FD;
1571
0
    int dst_dir_fd = DEFAULT_DIR_FD;
1572
1573
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
1574
0
    if (!args) {
1575
0
        goto exit;
1576
0
    }
1577
0
    if (!path_converter(args[0], &src)) {
1578
0
        goto exit;
1579
0
    }
1580
0
    if (!path_converter(args[1], &dst)) {
1581
0
        goto exit;
1582
0
    }
1583
0
    if (!noptargs) {
1584
0
        goto skip_optional_kwonly;
1585
0
    }
1586
0
    if (args[2]) {
1587
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
1588
0
            goto exit;
1589
0
        }
1590
0
        if (!--noptargs) {
1591
0
            goto skip_optional_kwonly;
1592
0
        }
1593
0
    }
1594
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1595
0
        goto exit;
1596
0
    }
1597
0
skip_optional_kwonly:
1598
0
    return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1599
1600
0
exit:
1601
    /* Cleanup for src */
1602
0
    path_cleanup(&src);
1603
    /* Cleanup for dst */
1604
0
    path_cleanup(&dst);
1605
1606
0
    return return_value;
1607
0
}
1608
1609
PyDoc_STRVAR(os_replace__doc__,
1610
"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1611
"--\n"
1612
"\n"
1613
"Rename a file or directory, overwriting the destination.\n"
1614
"\n"
1615
"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1616
"  descriptor open to a directory, and the respective path string (src or dst)\n"
1617
"  should be relative; the path will then be relative to that directory.\n"
1618
"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1619
"  If they are unavailable, using them will raise a NotImplementedError.");
1620
1621
#define OS_REPLACE_METHODDEF    \
1622
    {"replace", (PyCFunction)(void(*)(void))os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
1623
1624
static PyObject *
1625
os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1626
                int dst_dir_fd);
1627
1628
static PyObject *
1629
os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1630
0
{
1631
0
    PyObject *return_value = NULL;
1632
0
    static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1633
0
    static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0};
1634
0
    PyObject *argsbuf[4];
1635
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1636
0
    path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1637
0
    path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1638
0
    int src_dir_fd = DEFAULT_DIR_FD;
1639
0
    int dst_dir_fd = DEFAULT_DIR_FD;
1640
1641
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
1642
0
    if (!args) {
1643
0
        goto exit;
1644
0
    }
1645
0
    if (!path_converter(args[0], &src)) {
1646
0
        goto exit;
1647
0
    }
1648
0
    if (!path_converter(args[1], &dst)) {
1649
0
        goto exit;
1650
0
    }
1651
0
    if (!noptargs) {
1652
0
        goto skip_optional_kwonly;
1653
0
    }
1654
0
    if (args[2]) {
1655
0
        if (!dir_fd_converter(args[2], &src_dir_fd)) {
1656
0
            goto exit;
1657
0
        }
1658
0
        if (!--noptargs) {
1659
0
            goto skip_optional_kwonly;
1660
0
        }
1661
0
    }
1662
0
    if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1663
0
        goto exit;
1664
0
    }
1665
0
skip_optional_kwonly:
1666
0
    return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1667
1668
0
exit:
1669
    /* Cleanup for src */
1670
0
    path_cleanup(&src);
1671
    /* Cleanup for dst */
1672
0
    path_cleanup(&dst);
1673
1674
0
    return return_value;
1675
0
}
1676
1677
PyDoc_STRVAR(os_rmdir__doc__,
1678
"rmdir($module, /, path, *, dir_fd=None)\n"
1679
"--\n"
1680
"\n"
1681
"Remove a directory.\n"
1682
"\n"
1683
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1684
"  and path should be relative; path will then be relative to that directory.\n"
1685
"dir_fd may not be implemented on your platform.\n"
1686
"  If it is unavailable, using it will raise a NotImplementedError.");
1687
1688
#define OS_RMDIR_METHODDEF    \
1689
    {"rmdir", (PyCFunction)(void(*)(void))os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
1690
1691
static PyObject *
1692
os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
1693
1694
static PyObject *
1695
os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1696
0
{
1697
0
    PyObject *return_value = NULL;
1698
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
1699
0
    static _PyArg_Parser _parser = {NULL, _keywords, "rmdir", 0};
1700
0
    PyObject *argsbuf[2];
1701
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1702
0
    path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1703
0
    int dir_fd = DEFAULT_DIR_FD;
1704
1705
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1706
0
    if (!args) {
1707
0
        goto exit;
1708
0
    }
1709
0
    if (!path_converter(args[0], &path)) {
1710
0
        goto exit;
1711
0
    }
1712
0
    if (!noptargs) {
1713
0
        goto skip_optional_kwonly;
1714
0
    }
1715
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
1716
0
        goto exit;
1717
0
    }
1718
0
skip_optional_kwonly:
1719
0
    return_value = os_rmdir_impl(module, &path, dir_fd);
1720
1721
0
exit:
1722
    /* Cleanup for path */
1723
0
    path_cleanup(&path);
1724
1725
0
    return return_value;
1726
0
}
1727
1728
#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1729
1730
PyDoc_STRVAR(os_system__doc__,
1731
"system($module, /, command)\n"
1732
"--\n"
1733
"\n"
1734
"Execute the command in a subshell.");
1735
1736
#define OS_SYSTEM_METHODDEF    \
1737
    {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
1738
1739
static long
1740
os_system_impl(PyObject *module, const Py_UNICODE *command);
1741
1742
static PyObject *
1743
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1744
{
1745
    PyObject *return_value = NULL;
1746
    static const char * const _keywords[] = {"command", NULL};
1747
    static _PyArg_Parser _parser = {"u:system", _keywords, 0};
1748
    const Py_UNICODE *command;
1749
    long _return_value;
1750
1751
    if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1752
        &command)) {
1753
        goto exit;
1754
    }
1755
    _return_value = os_system_impl(module, command);
1756
    if ((_return_value == -1) && PyErr_Occurred()) {
1757
        goto exit;
1758
    }
1759
    return_value = PyLong_FromLong(_return_value);
1760
1761
exit:
1762
    return return_value;
1763
}
1764
1765
#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1766
1767
#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1768
1769
PyDoc_STRVAR(os_system__doc__,
1770
"system($module, /, command)\n"
1771
"--\n"
1772
"\n"
1773
"Execute the command in a subshell.");
1774
1775
#define OS_SYSTEM_METHODDEF    \
1776
    {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
1777
1778
static long
1779
os_system_impl(PyObject *module, PyObject *command);
1780
1781
static PyObject *
1782
os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1783
0
{
1784
0
    PyObject *return_value = NULL;
1785
0
    static const char * const _keywords[] = {"command", NULL};
1786
0
    static _PyArg_Parser _parser = {NULL, _keywords, "system", 0};
1787
0
    PyObject *argsbuf[1];
1788
0
    PyObject *command = NULL;
1789
0
    long _return_value;
1790
1791
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1792
0
    if (!args) {
1793
0
        goto exit;
1794
0
    }
1795
0
    if (!PyUnicode_FSConverter(args[0], &command)) {
1796
0
        goto exit;
1797
0
    }
1798
0
    _return_value = os_system_impl(module, command);
1799
0
    if ((_return_value == -1) && PyErr_Occurred()) {
1800
0
        goto exit;
1801
0
    }
1802
0
    return_value = PyLong_FromLong(_return_value);
1803
1804
0
exit:
1805
    /* Cleanup for command */
1806
0
    Py_XDECREF(command);
1807
1808
0
    return return_value;
1809
0
}
1810
1811
#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1812
1813
PyDoc_STRVAR(os_umask__doc__,
1814
"umask($module, mask, /)\n"
1815
"--\n"
1816
"\n"
1817
"Set the current numeric umask and return the previous umask.");
1818
1819
#define OS_UMASK_METHODDEF    \
1820
    {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
1821
1822
static PyObject *
1823
os_umask_impl(PyObject *module, int mask);
1824
1825
static PyObject *
1826
os_umask(PyObject *module, PyObject *arg)
1827
0
{
1828
0
    PyObject *return_value = NULL;
1829
0
    int mask;
1830
1831
0
    if (PyFloat_Check(arg)) {
1832
0
        PyErr_SetString(PyExc_TypeError,
1833
0
                        "integer argument expected, got float" );
1834
0
        goto exit;
1835
0
    }
1836
0
    mask = _PyLong_AsInt(arg);
1837
0
    if (mask == -1 && PyErr_Occurred()) {
1838
0
        goto exit;
1839
0
    }
1840
0
    return_value = os_umask_impl(module, mask);
1841
1842
0
exit:
1843
0
    return return_value;
1844
0
}
1845
1846
PyDoc_STRVAR(os_unlink__doc__,
1847
"unlink($module, /, path, *, dir_fd=None)\n"
1848
"--\n"
1849
"\n"
1850
"Remove a file (same as remove()).\n"
1851
"\n"
1852
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1853
"  and path should be relative; path will then be relative to that directory.\n"
1854
"dir_fd may not be implemented on your platform.\n"
1855
"  If it is unavailable, using it will raise a NotImplementedError.");
1856
1857
#define OS_UNLINK_METHODDEF    \
1858
    {"unlink", (PyCFunction)(void(*)(void))os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
1859
1860
static PyObject *
1861
os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
1862
1863
static PyObject *
1864
os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1865
0
{
1866
0
    PyObject *return_value = NULL;
1867
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
1868
0
    static _PyArg_Parser _parser = {NULL, _keywords, "unlink", 0};
1869
0
    PyObject *argsbuf[2];
1870
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1871
0
    path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1872
0
    int dir_fd = DEFAULT_DIR_FD;
1873
1874
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1875
0
    if (!args) {
1876
0
        goto exit;
1877
0
    }
1878
0
    if (!path_converter(args[0], &path)) {
1879
0
        goto exit;
1880
0
    }
1881
0
    if (!noptargs) {
1882
0
        goto skip_optional_kwonly;
1883
0
    }
1884
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
1885
0
        goto exit;
1886
0
    }
1887
0
skip_optional_kwonly:
1888
0
    return_value = os_unlink_impl(module, &path, dir_fd);
1889
1890
0
exit:
1891
    /* Cleanup for path */
1892
0
    path_cleanup(&path);
1893
1894
0
    return return_value;
1895
0
}
1896
1897
PyDoc_STRVAR(os_remove__doc__,
1898
"remove($module, /, path, *, dir_fd=None)\n"
1899
"--\n"
1900
"\n"
1901
"Remove a file (same as unlink()).\n"
1902
"\n"
1903
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1904
"  and path should be relative; path will then be relative to that directory.\n"
1905
"dir_fd may not be implemented on your platform.\n"
1906
"  If it is unavailable, using it will raise a NotImplementedError.");
1907
1908
#define OS_REMOVE_METHODDEF    \
1909
    {"remove", (PyCFunction)(void(*)(void))os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
1910
1911
static PyObject *
1912
os_remove_impl(PyObject *module, path_t *path, int dir_fd);
1913
1914
static PyObject *
1915
os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1916
0
{
1917
0
    PyObject *return_value = NULL;
1918
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
1919
0
    static _PyArg_Parser _parser = {NULL, _keywords, "remove", 0};
1920
0
    PyObject *argsbuf[2];
1921
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1922
0
    path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1923
0
    int dir_fd = DEFAULT_DIR_FD;
1924
1925
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1926
0
    if (!args) {
1927
0
        goto exit;
1928
0
    }
1929
0
    if (!path_converter(args[0], &path)) {
1930
0
        goto exit;
1931
0
    }
1932
0
    if (!noptargs) {
1933
0
        goto skip_optional_kwonly;
1934
0
    }
1935
0
    if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
1936
0
        goto exit;
1937
0
    }
1938
0
skip_optional_kwonly:
1939
0
    return_value = os_remove_impl(module, &path, dir_fd);
1940
1941
0
exit:
1942
    /* Cleanup for path */
1943
0
    path_cleanup(&path);
1944
1945
0
    return return_value;
1946
0
}
1947
1948
#if defined(HAVE_UNAME)
1949
1950
PyDoc_STRVAR(os_uname__doc__,
1951
"uname($module, /)\n"
1952
"--\n"
1953
"\n"
1954
"Return an object identifying the current operating system.\n"
1955
"\n"
1956
"The object behaves like a named tuple with the following fields:\n"
1957
"  (sysname, nodename, release, version, machine)");
1958
1959
#define OS_UNAME_METHODDEF    \
1960
    {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1961
1962
static PyObject *
1963
os_uname_impl(PyObject *module);
1964
1965
static PyObject *
1966
os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
1967
0
{
1968
0
    return os_uname_impl(module);
1969
0
}
1970
1971
#endif /* defined(HAVE_UNAME) */
1972
1973
PyDoc_STRVAR(os_utime__doc__,
1974
"utime($module, /, path, times=None, *, ns=<unrepresentable>,\n"
1975
"      dir_fd=None, follow_symlinks=True)\n"
1976
"--\n"
1977
"\n"
1978
"Set the access and modified time of path.\n"
1979
"\n"
1980
"path may always be specified as a string.\n"
1981
"On some platforms, path may also be specified as an open file descriptor.\n"
1982
"  If this functionality is unavailable, using it raises an exception.\n"
1983
"\n"
1984
"If times is not None, it must be a tuple (atime, mtime);\n"
1985
"    atime and mtime should be expressed as float seconds since the epoch.\n"
1986
"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
1987
"    atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1988
"    since the epoch.\n"
1989
"If times is None and ns is unspecified, utime uses the current time.\n"
1990
"Specifying tuples for both times and ns is an error.\n"
1991
"\n"
1992
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1993
"  and path should be relative; path will then be relative to that directory.\n"
1994
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1995
"  link, utime will modify the symbolic link itself instead of the file the\n"
1996
"  link points to.\n"
1997
"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1998
"  as an open file descriptor.\n"
1999
"dir_fd and follow_symlinks may not be available on your platform.\n"
2000
"  If they are unavailable, using them will raise a NotImplementedError.");
2001
2002
#define OS_UTIME_METHODDEF    \
2003
    {"utime", (PyCFunction)(void(*)(void))os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
2004
2005
static PyObject *
2006
os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
2007
              int dir_fd, int follow_symlinks);
2008
2009
static PyObject *
2010
os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2011
0
{
2012
0
    PyObject *return_value = NULL;
2013
0
    static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
2014
0
    static _PyArg_Parser _parser = {NULL, _keywords, "utime", 0};
2015
0
    PyObject *argsbuf[5];
2016
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
2017
0
    path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
2018
0
    PyObject *times = Py_None;
2019
0
    PyObject *ns = NULL;
2020
0
    int dir_fd = DEFAULT_DIR_FD;
2021
0
    int follow_symlinks = 1;
2022
2023
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
2024
0
    if (!args) {
2025
0
        goto exit;
2026
0
    }
2027
0
    if (!path_converter(args[0], &path)) {
2028
0
        goto exit;
2029
0
    }
2030
0
    if (!noptargs) {
2031
0
        goto skip_optional_pos;
2032
0
    }
2033
0
    if (args[1]) {
2034
0
        times = args[1];
2035
0
        if (!--noptargs) {
2036
0
            goto skip_optional_pos;
2037
0
        }
2038
0
    }
2039
0
skip_optional_pos:
2040
0
    if (!noptargs) {
2041
0
        goto skip_optional_kwonly;
2042
0
    }
2043
0
    if (args[2]) {
2044
0
        ns = args[2];
2045
0
        if (!--noptargs) {
2046
0
            goto skip_optional_kwonly;
2047
0
        }
2048
0
    }
2049
0
    if (args[3]) {
2050
0
        if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
2051
0
            goto exit;
2052
0
        }
2053
0
        if (!--noptargs) {
2054
0
            goto skip_optional_kwonly;
2055
0
        }
2056
0
    }
2057
0
    follow_symlinks = PyObject_IsTrue(args[4]);
2058
0
    if (follow_symlinks < 0) {
2059
0
        goto exit;
2060
0
    }
2061
0
skip_optional_kwonly:
2062
0
    return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
2063
2064
0
exit:
2065
    /* Cleanup for path */
2066
0
    path_cleanup(&path);
2067
2068
0
    return return_value;
2069
0
}
2070
2071
PyDoc_STRVAR(os__exit__doc__,
2072
"_exit($module, /, status)\n"
2073
"--\n"
2074
"\n"
2075
"Exit to the system with specified status, without normal exit processing.");
2076
2077
#define OS__EXIT_METHODDEF    \
2078
    {"_exit", (PyCFunction)(void(*)(void))os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
2079
2080
static PyObject *
2081
os__exit_impl(PyObject *module, int status);
2082
2083
static PyObject *
2084
os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2085
0
{
2086
0
    PyObject *return_value = NULL;
2087
0
    static const char * const _keywords[] = {"status", NULL};
2088
0
    static _PyArg_Parser _parser = {NULL, _keywords, "_exit", 0};
2089
0
    PyObject *argsbuf[1];
2090
0
    int status;
2091
2092
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2093
0
    if (!args) {
2094
0
        goto exit;
2095
0
    }
2096
0
    if (PyFloat_Check(args[0])) {
2097
0
        PyErr_SetString(PyExc_TypeError,
2098
0
                        "integer argument expected, got float" );
2099
0
        goto exit;
2100
0
    }
2101
0
    status = _PyLong_AsInt(args[0]);
2102
0
    if (status == -1 && PyErr_Occurred()) {
2103
0
        goto exit;
2104
0
    }
2105
0
    return_value = os__exit_impl(module, status);
2106
2107
0
exit:
2108
0
    return return_value;
2109
0
}
2110
2111
#if defined(HAVE_EXECV)
2112
2113
PyDoc_STRVAR(os_execv__doc__,
2114
"execv($module, path, argv, /)\n"
2115
"--\n"
2116
"\n"
2117
"Execute an executable path with arguments, replacing current process.\n"
2118
"\n"
2119
"  path\n"
2120
"    Path of executable file.\n"
2121
"  argv\n"
2122
"    Tuple or list of strings.");
2123
2124
#define OS_EXECV_METHODDEF    \
2125
    {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__},
2126
2127
static PyObject *
2128
os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
2129
2130
static PyObject *
2131
os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2132
0
{
2133
0
    PyObject *return_value = NULL;
2134
0
    path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
2135
0
    PyObject *argv;
2136
2137
0
    if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
2138
0
        goto exit;
2139
0
    }
2140
0
    if (!path_converter(args[0], &path)) {
2141
0
        goto exit;
2142
0
    }
2143
0
    argv = args[1];
2144
0
    return_value = os_execv_impl(module, &path, argv);
2145
2146
0
exit:
2147
    /* Cleanup for path */
2148
0
    path_cleanup(&path);
2149
2150
0
    return return_value;
2151
0
}
2152
2153
#endif /* defined(HAVE_EXECV) */
2154
2155
#if defined(HAVE_EXECV)
2156
2157
PyDoc_STRVAR(os_execve__doc__,
2158
"execve($module, /, path, argv, env)\n"
2159
"--\n"
2160
"\n"
2161
"Execute an executable path with arguments, replacing current process.\n"
2162
"\n"
2163
"  path\n"
2164
"    Path of executable file.\n"
2165
"  argv\n"
2166
"    Tuple or list of strings.\n"
2167
"  env\n"
2168
"    Dictionary of strings mapping to strings.");
2169
2170
#define OS_EXECVE_METHODDEF    \
2171
    {"execve", (PyCFunction)(void(*)(void))os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
2172
2173
static PyObject *
2174
os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
2175
2176
static PyObject *
2177
os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2178
0
{
2179
0
    PyObject *return_value = NULL;
2180
0
    static const char * const _keywords[] = {"path", "argv", "env", NULL};
2181
0
    static _PyArg_Parser _parser = {NULL, _keywords, "execve", 0};
2182
0
    PyObject *argsbuf[3];
2183
0
    path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
2184
0
    PyObject *argv;
2185
0
    PyObject *env;
2186
2187
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
2188
0
    if (!args) {
2189
0
        goto exit;
2190
0
    }
2191
0
    if (!path_converter(args[0], &path)) {
2192
0
        goto exit;
2193
0
    }
2194
0
    argv = args[1];
2195
0
    env = args[2];
2196
0
    return_value = os_execve_impl(module, &path, argv, env);
2197
2198
0
exit:
2199
    /* Cleanup for path */
2200
0
    path_cleanup(&path);
2201
2202
0
    return return_value;
2203
0
}
2204
2205
#endif /* defined(HAVE_EXECV) */
2206
2207
#if defined(HAVE_POSIX_SPAWN)
2208
2209
PyDoc_STRVAR(os_posix_spawn__doc__,
2210
"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
2211
"            setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
2212
"            setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
2213
"--\n"
2214
"\n"
2215
"Execute the program specified by path in a new process.\n"
2216
"\n"
2217
"  path\n"
2218
"    Path of executable file.\n"
2219
"  argv\n"
2220
"    Tuple or list of strings.\n"
2221
"  env\n"
2222
"    Dictionary of strings mapping to strings.\n"
2223
"  file_actions\n"
2224
"    A sequence of file action tuples.\n"
2225
"  setpgroup\n"
2226
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
2227
"  resetids\n"
2228
"    If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
2229
"  setsid\n"
2230
"    If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
2231
"  setsigmask\n"
2232
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
2233
"  setsigdef\n"
2234
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
2235
"  scheduler\n"
2236
"    A tuple with the scheduler policy (optional) and parameters.");
2237
2238
#define OS_POSIX_SPAWN_METHODDEF    \
2239
    {"posix_spawn", (PyCFunction)(void(*)(void))os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
2240
2241
static PyObject *
2242
os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
2243
                    PyObject *env, PyObject *file_actions,
2244
                    PyObject *setpgroup, int resetids, int setsid,
2245
                    PyObject *setsigmask, PyObject *setsigdef,
2246
                    PyObject *scheduler);
2247
2248
static PyObject *
2249
os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2250
0
{
2251
0
    PyObject *return_value = NULL;
2252
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
2253
0
    static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawn", 0};
2254
0
    PyObject *argsbuf[10];
2255
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
2256
0
    path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
2257
0
    PyObject *argv;
2258
0
    PyObject *env;
2259
0
    PyObject *file_actions = NULL;
2260
0
    PyObject *setpgroup = NULL;
2261
0
    int resetids = 0;
2262
0
    int setsid = 0;
2263
0
    PyObject *setsigmask = NULL;
2264
0
    PyObject *setsigdef = NULL;
2265
0
    PyObject *scheduler = NULL;
2266
2267
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
2268
0
    if (!args) {
2269
0
        goto exit;
2270
0
    }
2271
0
    if (!path_converter(args[0], &path)) {
2272
0
        goto exit;
2273
0
    }
2274
0
    argv = args[1];
2275
0
    env = args[2];
2276
0
    if (!noptargs) {
2277
0
        goto skip_optional_kwonly;
2278
0
    }
2279
0
    if (args[3]) {
2280
0
        file_actions = args[3];
2281
0
        if (!--noptargs) {
2282
0
            goto skip_optional_kwonly;
2283
0
        }
2284
0
    }
2285
0
    if (args[4]) {
2286
0
        setpgroup = args[4];
2287
0
        if (!--noptargs) {
2288
0
            goto skip_optional_kwonly;
2289
0
        }
2290
0
    }
2291
0
    if (args[5]) {
2292
0
        if (PyFloat_Check(args[5])) {
2293
0
            PyErr_SetString(PyExc_TypeError,
2294
0
                            "integer argument expected, got float" );
2295
0
            goto exit;
2296
0
        }
2297
0
        resetids = _PyLong_AsInt(args[5]);
2298
0
        if (resetids == -1 && PyErr_Occurred()) {
2299
0
            goto exit;
2300
0
        }
2301
0
        if (!--noptargs) {
2302
0
            goto skip_optional_kwonly;
2303
0
        }
2304
0
    }
2305
0
    if (args[6]) {
2306
0
        if (PyFloat_Check(args[6])) {
2307
0
            PyErr_SetString(PyExc_TypeError,
2308
0
                            "integer argument expected, got float" );
2309
0
            goto exit;
2310
0
        }
2311
0
        setsid = _PyLong_AsInt(args[6]);
2312
0
        if (setsid == -1 && PyErr_Occurred()) {
2313
0
            goto exit;
2314
0
        }
2315
0
        if (!--noptargs) {
2316
0
            goto skip_optional_kwonly;
2317
0
        }
2318
0
    }
2319
0
    if (args[7]) {
2320
0
        setsigmask = args[7];
2321
0
        if (!--noptargs) {
2322
0
            goto skip_optional_kwonly;
2323
0
        }
2324
0
    }
2325
0
    if (args[8]) {
2326
0
        setsigdef = args[8];
2327
0
        if (!--noptargs) {
2328
0
            goto skip_optional_kwonly;
2329
0
        }
2330
0
    }
2331
0
    scheduler = args[9];
2332
0
skip_optional_kwonly:
2333
0
    return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
2334
2335
0
exit:
2336
    /* Cleanup for path */
2337
0
    path_cleanup(&path);
2338
2339
0
    return return_value;
2340
0
}
2341
2342
#endif /* defined(HAVE_POSIX_SPAWN) */
2343
2344
#if defined(HAVE_POSIX_SPAWNP)
2345
2346
PyDoc_STRVAR(os_posix_spawnp__doc__,
2347
"posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
2348
"             setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
2349
"             setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
2350
"--\n"
2351
"\n"
2352
"Execute the program specified by path in a new process.\n"
2353
"\n"
2354
"  path\n"
2355
"    Path of executable file.\n"
2356
"  argv\n"
2357
"    Tuple or list of strings.\n"
2358
"  env\n"
2359
"    Dictionary of strings mapping to strings.\n"
2360
"  file_actions\n"
2361
"    A sequence of file action tuples.\n"
2362
"  setpgroup\n"
2363
"    The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
2364
"  resetids\n"
2365
"    If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
2366
"  setsid\n"
2367
"    If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
2368
"  setsigmask\n"
2369
"    The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
2370
"  setsigdef\n"
2371
"    The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
2372
"  scheduler\n"
2373
"    A tuple with the scheduler policy (optional) and parameters.");
2374
2375
#define OS_POSIX_SPAWNP_METHODDEF    \
2376
    {"posix_spawnp", (PyCFunction)(void(*)(void))os_posix_spawnp, METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
2377
2378
static PyObject *
2379
os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
2380
                     PyObject *env, PyObject *file_actions,
2381
                     PyObject *setpgroup, int resetids, int setsid,
2382
                     PyObject *setsigmask, PyObject *setsigdef,
2383
                     PyObject *scheduler);
2384
2385
static PyObject *
2386
os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2387
0
{
2388
0
    PyObject *return_value = NULL;
2389
0
    static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
2390
0
    static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawnp", 0};
2391
0
    PyObject *argsbuf[10];
2392
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
2393
0
    path_t path = PATH_T_INITIALIZE("posix_spawnp", "path", 0, 0);
2394
0
    PyObject *argv;
2395
0
    PyObject *env;
2396
0
    PyObject *file_actions = NULL;
2397
0
    PyObject *setpgroup = NULL;
2398
0
    int resetids = 0;
2399
0
    int setsid = 0;
2400
0
    PyObject *setsigmask = NULL;
2401
0
    PyObject *setsigdef = NULL;
2402
0
    PyObject *scheduler = NULL;
2403
2404
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
2405
0
    if (!args) {
2406
0
        goto exit;
2407
0
    }
2408
0
    if (!path_converter(args[0], &path)) {
2409
0
        goto exit;
2410
0
    }
2411
0
    argv = args[1];
2412
0
    env = args[2];
2413
0
    if (!noptargs) {
2414
0
        goto skip_optional_kwonly;
2415
0
    }
2416
0
    if (args[3]) {
2417
0
        file_actions = args[3];
2418
0
        if (!--noptargs) {
2419
0
            goto skip_optional_kwonly;
2420
0
        }
2421
0
    }
2422
0
    if (args[4]) {
2423
0
        setpgroup = args[4];
2424
0
        if (!--noptargs) {
2425
0
            goto skip_optional_kwonly;
2426
0
        }
2427
0
    }
2428
0
    if (args[5]) {
2429
0
        if (PyFloat_Check(args[5])) {
2430
0
            PyErr_SetString(PyExc_TypeError,
2431
0
                            "integer argument expected, got float" );
2432
0
            goto exit;
2433
0
        }
2434
0
        resetids = _PyLong_AsInt(args[5]);
2435
0
        if (resetids == -1 && PyErr_Occurred()) {
2436
0
            goto exit;
2437
0
        }
2438
0
        if (!--noptargs) {
2439
0
            goto skip_optional_kwonly;
2440
0
        }
2441
0
    }
2442
0
    if (args[6]) {
2443
0
        if (PyFloat_Check(args[6])) {
2444
0
            PyErr_SetString(PyExc_TypeError,
2445
0
                            "integer argument expected, got float" );
2446
0
            goto exit;
2447
0
        }
2448
0
        setsid = _PyLong_AsInt(args[6]);
2449
0
        if (setsid == -1 && PyErr_Occurred()) {
2450
0
            goto exit;
2451
0
        }
2452
0
        if (!--noptargs) {
2453
0
            goto skip_optional_kwonly;
2454
0
        }
2455
0
    }
2456
0
    if (args[7]) {
2457
0
        setsigmask = args[7];
2458
0
        if (!--noptargs) {
2459
0
            goto skip_optional_kwonly;
2460
0
        }
2461
0
    }
2462
0
    if (args[8]) {
2463
0
        setsigdef = args[8];
2464
0
        if (!--noptargs) {
2465
0
            goto skip_optional_kwonly;
2466
0
        }
2467
0
    }
2468
0
    scheduler = args[9];
2469
0
skip_optional_kwonly:
2470
0
    return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
2471
2472
0
exit:
2473
    /* Cleanup for path */
2474
0
    path_cleanup(&path);
2475
2476
0
    return return_value;
2477
0
}
2478
2479
#endif /* defined(HAVE_POSIX_SPAWNP) */
2480
2481
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
2482
2483
PyDoc_STRVAR(os_spawnv__doc__,
2484
"spawnv($module, mode, path, argv, /)\n"
2485
"--\n"
2486
"\n"
2487
"Execute the program specified by path in a new process.\n"
2488
"\n"
2489
"  mode\n"
2490
"    Mode of process creation.\n"
2491
"  path\n"
2492
"    Path of executable file.\n"
2493
"  argv\n"
2494
"    Tuple or list of strings.");
2495
2496
#define OS_SPAWNV_METHODDEF    \
2497
    {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__},
2498
2499
static PyObject *
2500
os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
2501
2502
static PyObject *
2503
os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2504
{
2505
    PyObject *return_value = NULL;
2506
    int mode;
2507
    path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
2508
    PyObject *argv;
2509
2510
    if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
2511
        goto exit;
2512
    }
2513
    if (PyFloat_Check(args[0])) {
2514
        PyErr_SetString(PyExc_TypeError,
2515
                        "integer argument expected, got float" );
2516
        goto exit;
2517
    }
2518
    mode = _PyLong_AsInt(args[0]);
2519
    if (mode == -1 && PyErr_Occurred()) {
2520
        goto exit;
2521
    }
2522
    if (!path_converter(args[1], &path)) {
2523
        goto exit;
2524
    }
2525
    argv = args[2];
2526
    return_value = os_spawnv_impl(module, mode, &path, argv);
2527
2528
exit:
2529
    /* Cleanup for path */
2530
    path_cleanup(&path);
2531
2532
    return return_value;
2533
}
2534
2535
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
2536
2537
#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
2538
2539
PyDoc_STRVAR(os_spawnve__doc__,
2540
"spawnve($module, mode, path, argv, env, /)\n"
2541
"--\n"
2542
"\n"
2543
"Execute the program specified by path in a new process.\n"
2544
"\n"
2545
"  mode\n"
2546
"    Mode of process creation.\n"
2547
"  path\n"
2548
"    Path of executable file.\n"
2549
"  argv\n"
2550
"    Tuple or list of strings.\n"
2551
"  env\n"
2552
"    Dictionary of strings mapping to strings.");
2553
2554
#define OS_SPAWNVE_METHODDEF    \
2555
    {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__},
2556
2557
static PyObject *
2558
os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
2559
                PyObject *env);
2560
2561
static PyObject *
2562
os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2563
{
2564
    PyObject *return_value = NULL;
2565
    int mode;
2566
    path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
2567
    PyObject *argv;
2568
    PyObject *env;
2569
2570
    if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
2571
        goto exit;
2572
    }
2573
    if (PyFloat_Check(args[0])) {
2574
        PyErr_SetString(PyExc_TypeError,
2575
                        "integer argument expected, got float" );
2576
        goto exit;
2577
    }
2578
    mode = _PyLong_AsInt(args[0]);
2579
    if (mode == -1 && PyErr_Occurred()) {
2580
        goto exit;
2581
    }
2582
    if (!path_converter(args[1], &path)) {
2583
        goto exit;
2584
    }
2585
    argv = args[2];
2586
    env = args[3];
2587
    return_value = os_spawnve_impl(module, mode, &path, argv, env);
2588
2589
exit:
2590
    /* Cleanup for path */
2591
    path_cleanup(&path);
2592
2593
    return return_value;
2594
}
2595
2596
#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
2597
2598
#if defined(HAVE_FORK)
2599
2600
PyDoc_STRVAR(os_register_at_fork__doc__,
2601
"register_at_fork($module, /, *, before=<unrepresentable>,\n"
2602
"                 after_in_child=<unrepresentable>,\n"
2603
"                 after_in_parent=<unrepresentable>)\n"
2604
"--\n"
2605
"\n"
2606
"Register callables to be called when forking a new process.\n"
2607
"\n"
2608
"  before\n"
2609
"    A callable to be called in the parent before the fork() syscall.\n"
2610
"  after_in_child\n"
2611
"    A callable to be called in the child after fork().\n"
2612
"  after_in_parent\n"
2613
"    A callable to be called in the parent after fork().\n"
2614
"\n"
2615
"\'before\' callbacks are called in reverse order.\n"
2616
"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
2617
2618
#define OS_REGISTER_AT_FORK_METHODDEF    \
2619
    {"register_at_fork", (PyCFunction)(void(*)(void))os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
2620
2621
static PyObject *
2622
os_register_at_fork_impl(PyObject *module, PyObject *before,
2623
                         PyObject *after_in_child, PyObject *after_in_parent);
2624
2625
static PyObject *
2626
os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2627
2
{
2628
2
    PyObject *return_value = NULL;
2629
2
    static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
2630
2
    static _PyArg_Parser _parser = {NULL, _keywords, "register_at_fork", 0};
2631
2
    PyObject *argsbuf[3];
2632
2
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
2633
2
    PyObject *before = NULL;
2634
2
    PyObject *after_in_child = NULL;
2635
2
    PyObject *after_in_parent = NULL;
2636
2637
2
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
2638
2
    if (!args) {
2639
0
        goto exit;
2640
0
    }
2641
2
    if (!noptargs) {
2642
0
        goto skip_optional_kwonly;
2643
0
    }
2644
2
    if (args[0]) {
2645
1
        before = args[0];
2646
1
        if (!--noptargs) {
2647
0
            goto skip_optional_kwonly;
2648
0
        }
2649
1
    }
2650
2
    if (args[1]) {
2651
2
        after_in_child = args[1];
2652
2
        if (!--noptargs) {
2653
1
            goto skip_optional_kwonly;
2654
1
        }
2655
2
    }
2656
1
    after_in_parent = args[2];
2657
2
skip_optional_kwonly:
2658
2
    return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
2659
2660
2
exit:
2661
2
    return return_value;
2662
2
}
2663
2664
#endif /* defined(HAVE_FORK) */
2665
2666
#if defined(HAVE_FORK1)
2667
2668
PyDoc_STRVAR(os_fork1__doc__,
2669
"fork1($module, /)\n"
2670
"--\n"
2671
"\n"
2672
"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
2673
"\n"
2674
"Return 0 to child process and PID of child to parent process.");
2675
2676
#define OS_FORK1_METHODDEF    \
2677
    {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
2678
2679
static PyObject *
2680
os_fork1_impl(PyObject *module);
2681
2682
static PyObject *
2683
os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
2684
{
2685
    return os_fork1_impl(module);
2686
}
2687
2688
#endif /* defined(HAVE_FORK1) */
2689
2690
#if defined(HAVE_FORK)
2691
2692
PyDoc_STRVAR(os_fork__doc__,
2693
"fork($module, /)\n"
2694
"--\n"
2695
"\n"
2696
"Fork a child process.\n"
2697
"\n"
2698
"Return 0 to child process and PID of child to parent process.");
2699
2700
#define OS_FORK_METHODDEF    \
2701
    {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
2702
2703
static PyObject *
2704
os_fork_impl(PyObject *module);
2705
2706
static PyObject *
2707
os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
2708
0
{
2709
0
    return os_fork_impl(module);
2710
0
}
2711
2712
#endif /* defined(HAVE_FORK) */
2713
2714
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2715
2716
PyDoc_STRVAR(os_sched_get_priority_max__doc__,
2717
"sched_get_priority_max($module, /, policy)\n"
2718
"--\n"
2719
"\n"
2720
"Get the maximum scheduling priority for policy.");
2721
2722
#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF    \
2723
    {"sched_get_priority_max", (PyCFunction)(void(*)(void))os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
2724
2725
static PyObject *
2726
os_sched_get_priority_max_impl(PyObject *module, int policy);
2727
2728
static PyObject *
2729
os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2730
0
{
2731
0
    PyObject *return_value = NULL;
2732
0
    static const char * const _keywords[] = {"policy", NULL};
2733
0
    static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_max", 0};
2734
0
    PyObject *argsbuf[1];
2735
0
    int policy;
2736
2737
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2738
0
    if (!args) {
2739
0
        goto exit;
2740
0
    }
2741
0
    if (PyFloat_Check(args[0])) {
2742
0
        PyErr_SetString(PyExc_TypeError,
2743
0
                        "integer argument expected, got float" );
2744
0
        goto exit;
2745
0
    }
2746
0
    policy = _PyLong_AsInt(args[0]);
2747
0
    if (policy == -1 && PyErr_Occurred()) {
2748
0
        goto exit;
2749
0
    }
2750
0
    return_value = os_sched_get_priority_max_impl(module, policy);
2751
2752
0
exit:
2753
0
    return return_value;
2754
0
}
2755
2756
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2757
2758
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2759
2760
PyDoc_STRVAR(os_sched_get_priority_min__doc__,
2761
"sched_get_priority_min($module, /, policy)\n"
2762
"--\n"
2763
"\n"
2764
"Get the minimum scheduling priority for policy.");
2765
2766
#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF    \
2767
    {"sched_get_priority_min", (PyCFunction)(void(*)(void))os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
2768
2769
static PyObject *
2770
os_sched_get_priority_min_impl(PyObject *module, int policy);
2771
2772
static PyObject *
2773
os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2774
0
{
2775
0
    PyObject *return_value = NULL;
2776
0
    static const char * const _keywords[] = {"policy", NULL};
2777
0
    static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_min", 0};
2778
0
    PyObject *argsbuf[1];
2779
0
    int policy;
2780
2781
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2782
0
    if (!args) {
2783
0
        goto exit;
2784
0
    }
2785
0
    if (PyFloat_Check(args[0])) {
2786
0
        PyErr_SetString(PyExc_TypeError,
2787
0
                        "integer argument expected, got float" );
2788
0
        goto exit;
2789
0
    }
2790
0
    policy = _PyLong_AsInt(args[0]);
2791
0
    if (policy == -1 && PyErr_Occurred()) {
2792
0
        goto exit;
2793
0
    }
2794
0
    return_value = os_sched_get_priority_min_impl(module, policy);
2795
2796
0
exit:
2797
0
    return return_value;
2798
0
}
2799
2800
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2801
2802
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2803
2804
PyDoc_STRVAR(os_sched_getscheduler__doc__,
2805
"sched_getscheduler($module, pid, /)\n"
2806
"--\n"
2807
"\n"
2808
"Get the scheduling policy for the process identifiedy by pid.\n"
2809
"\n"
2810
"Passing 0 for pid returns the scheduling policy for the calling process.");
2811
2812
#define OS_SCHED_GETSCHEDULER_METHODDEF    \
2813
    {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
2814
2815
static PyObject *
2816
os_sched_getscheduler_impl(PyObject *module, pid_t pid);
2817
2818
static PyObject *
2819
os_sched_getscheduler(PyObject *module, PyObject *arg)
2820
0
{
2821
0
    PyObject *return_value = NULL;
2822
0
    pid_t pid;
2823
2824
0
    if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
2825
0
        goto exit;
2826
0
    }
2827
0
    return_value = os_sched_getscheduler_impl(module, pid);
2828
2829
0
exit:
2830
0
    return return_value;
2831
0
}
2832
2833
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2834
2835
#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
2836
2837
PyDoc_STRVAR(os_sched_param__doc__,
2838
"sched_param(sched_priority)\n"
2839
"--\n"
2840
"\n"
2841
"Current has only one field: sched_priority\");\n"
2842
"\n"
2843
"  sched_priority\n"
2844
"    A scheduling parameter.");
2845
2846
static PyObject *
2847
os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2848
2849
static PyObject *
2850
os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2851
0
{
2852
0
    PyObject *return_value = NULL;
2853
0
    static const char * const _keywords[] = {"sched_priority", NULL};
2854
0
    static _PyArg_Parser _parser = {NULL, _keywords, "sched_param", 0};
2855
0
    PyObject *argsbuf[1];
2856
0
    PyObject * const *fastargs;
2857
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
2858
0
    PyObject *sched_priority;
2859
2860
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
2861
0
    if (!fastargs) {
2862
0
        goto exit;
2863
0
    }
2864
0
    sched_priority = fastargs[0];
2865
0
    return_value = os_sched_param_impl(type, sched_priority);
2866
2867
0
exit:
2868
0
    return return_value;
2869
0
}
2870
2871
#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
2872
2873
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2874
2875
PyDoc_STRVAR(os_sched_setscheduler__doc__,
2876
"sched_setscheduler($module, pid, policy, param, /)\n"
2877
"--\n"
2878
"\n"
2879
"Set the scheduling policy for the process identified by pid.\n"
2880
"\n"
2881
"If pid is 0, the calling process is changed.\n"
2882
"param is an instance of sched_param.");
2883
2884
#define OS_SCHED_SETSCHEDULER_METHODDEF    \
2885
    {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
2886
2887
static PyObject *
2888
os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
2889
                           struct sched_param *param);
2890
2891
static PyObject *
2892
os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2893
0
{
2894
0
    PyObject *return_value = NULL;
2895
0
    pid_t pid;
2896
0
    int policy;
2897
0
    struct sched_param param;
2898
2899
0
    if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2900
0
        &pid, &policy, convert_sched_param, &param)) {
2901
0
        goto exit;
2902
0
    }
2903
0
    return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2904
2905
0
exit:
2906
0
    return return_value;
2907
0
}
2908
2909
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2910
2911
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2912
2913
PyDoc_STRVAR(os_sched_getparam__doc__,
2914
"sched_getparam($module, pid, /)\n"
2915
"--\n"
2916
"\n"
2917
"Returns scheduling parameters for the process identified by pid.\n"
2918
"\n"
2919
"If pid is 0, returns parameters for the calling process.\n"
2920
"Return value is an instance of sched_param.");
2921
2922
#define OS_SCHED_GETPARAM_METHODDEF    \
2923
    {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
2924
2925
static PyObject *
2926
os_sched_getparam_impl(PyObject *module, pid_t pid);
2927
2928
static PyObject *
2929
os_sched_getparam(PyObject *module, PyObject *arg)
2930
0
{
2931
0
    PyObject *return_value = NULL;
2932
0
    pid_t pid;
2933
2934
0
    if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
2935
0
        goto exit;
2936
0
    }
2937
0
    return_value = os_sched_getparam_impl(module, pid);
2938
2939
0
exit:
2940
0
    return return_value;
2941
0
}
2942
2943
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2944
2945
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2946
2947
PyDoc_STRVAR(os_sched_setparam__doc__,
2948
"sched_setparam($module, pid, param, /)\n"
2949
"--\n"
2950
"\n"
2951
"Set scheduling parameters for the process identified by pid.\n"
2952
"\n"
2953
"If pid is 0, sets parameters for the calling process.\n"
2954
"param should be an instance of sched_param.");
2955
2956
#define OS_SCHED_SETPARAM_METHODDEF    \
2957
    {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
2958
2959
static PyObject *
2960
os_sched_setparam_impl(PyObject *module, pid_t pid,
2961
                       struct sched_param *param);
2962
2963
static PyObject *
2964
os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2965
0
{
2966
0
    PyObject *return_value = NULL;
2967
0
    pid_t pid;
2968
0
    struct sched_param param;
2969
2970
0
    if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2971
0
        &pid, convert_sched_param, &param)) {
2972
0
        goto exit;
2973
0
    }
2974
0
    return_value = os_sched_setparam_impl(module, pid, &param);
2975
2976
0
exit:
2977
0
    return return_value;
2978
0
}
2979
2980
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2981
2982
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2983
2984
PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2985
"sched_rr_get_interval($module, pid, /)\n"
2986
"--\n"
2987
"\n"
2988
"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2989
"\n"
2990
"Value returned is a float.");
2991
2992
#define OS_SCHED_RR_GET_INTERVAL_METHODDEF    \
2993
    {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
2994
2995
static double
2996
os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
2997
2998
static PyObject *
2999
os_sched_rr_get_interval(PyObject *module, PyObject *arg)
3000
0
{
3001
0
    PyObject *return_value = NULL;
3002
0
    pid_t pid;
3003
0
    double _return_value;
3004
3005
0
    if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
3006
0
        goto exit;
3007
0
    }
3008
0
    _return_value = os_sched_rr_get_interval_impl(module, pid);
3009
0
    if ((_return_value == -1.0) && PyErr_Occurred()) {
3010
0
        goto exit;
3011
0
    }
3012
0
    return_value = PyFloat_FromDouble(_return_value);
3013
3014
0
exit:
3015
0
    return return_value;
3016
0
}
3017
3018
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
3019
3020
#if defined(HAVE_SCHED_H)
3021
3022
PyDoc_STRVAR(os_sched_yield__doc__,
3023
"sched_yield($module, /)\n"
3024
"--\n"
3025
"\n"
3026
"Voluntarily relinquish the CPU.");
3027
3028
#define OS_SCHED_YIELD_METHODDEF    \
3029
    {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
3030
3031
static PyObject *
3032
os_sched_yield_impl(PyObject *module);
3033
3034
static PyObject *
3035
os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
3036
0
{
3037
0
    return os_sched_yield_impl(module);
3038
0
}
3039
3040
#endif /* defined(HAVE_SCHED_H) */
3041
3042
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
3043
3044
PyDoc_STRVAR(os_sched_setaffinity__doc__,
3045
"sched_setaffinity($module, pid, mask, /)\n"
3046
"--\n"
3047
"\n"
3048
"Set the CPU affinity of the process identified by pid to mask.\n"
3049
"\n"
3050
"mask should be an iterable of integers identifying CPUs.");
3051
3052
#define OS_SCHED_SETAFFINITY_METHODDEF    \
3053
    {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
3054
3055
static PyObject *
3056
os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
3057
3058
static PyObject *
3059
os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3060
0
{
3061
0
    PyObject *return_value = NULL;
3062
0
    pid_t pid;
3063
0
    PyObject *mask;
3064
3065
0
    if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
3066
0
        &pid, &mask)) {
3067
0
        goto exit;
3068
0
    }
3069
0
    return_value = os_sched_setaffinity_impl(module, pid, mask);
3070
3071
0
exit:
3072
0
    return return_value;
3073
0
}
3074
3075
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
3076
3077
#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
3078
3079
PyDoc_STRVAR(os_sched_getaffinity__doc__,
3080
"sched_getaffinity($module, pid, /)\n"
3081
"--\n"
3082
"\n"
3083
"Return the affinity of the process identified by pid (or the current process if zero).\n"
3084
"\n"
3085
"The affinity is returned as a set of CPU identifiers.");
3086
3087
#define OS_SCHED_GETAFFINITY_METHODDEF    \
3088
    {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
3089
3090
static PyObject *
3091
os_sched_getaffinity_impl(PyObject *module, pid_t pid);
3092
3093
static PyObject *
3094
os_sched_getaffinity(PyObject *module, PyObject *arg)
3095
0
{
3096
0
    PyObject *return_value = NULL;
3097
0
    pid_t pid;
3098
3099
0
    if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
3100
0
        goto exit;
3101
0
    }
3102
0
    return_value = os_sched_getaffinity_impl(module, pid);
3103
3104
0
exit:
3105
0
    return return_value;
3106
0
}
3107
3108
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
3109
3110
#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
3111
3112
PyDoc_STRVAR(os_openpty__doc__,
3113
"openpty($module, /)\n"
3114
"--\n"
3115
"\n"
3116
"Open a pseudo-terminal.\n"
3117
"\n"
3118
"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
3119
"for both the master and slave ends.");
3120
3121
#define OS_OPENPTY_METHODDEF    \
3122
    {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
3123
3124
static PyObject *
3125
os_openpty_impl(PyObject *module);
3126
3127
static PyObject *
3128
os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
3129
0
{
3130
0
    return os_openpty_impl(module);
3131
0
}
3132
3133
#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
3134
3135
#if defined(HAVE_FORKPTY)
3136
3137
PyDoc_STRVAR(os_forkpty__doc__,
3138
"forkpty($module, /)\n"
3139
"--\n"
3140
"\n"
3141
"Fork a new process with a new pseudo-terminal as controlling tty.\n"
3142
"\n"
3143
"Returns a tuple of (pid, master_fd).\n"
3144
"Like fork(), return pid of 0 to the child process,\n"
3145
"and pid of child to the parent process.\n"
3146
"To both, return fd of newly opened pseudo-terminal.");
3147
3148
#define OS_FORKPTY_METHODDEF    \
3149
    {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
3150
3151
static PyObject *
3152
os_forkpty_impl(PyObject *module);
3153
3154
static PyObject *
3155
os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
3156
0
{
3157
0
    return os_forkpty_impl(module);
3158
0
}
3159
3160
#endif /* defined(HAVE_FORKPTY) */
3161
3162
#if defined(HAVE_GETEGID)
3163
3164
PyDoc_STRVAR(os_getegid__doc__,
3165
"getegid($module, /)\n"
3166
"--\n"
3167
"\n"
3168
"Return the current process\'s effective group id.");
3169
3170
#define OS_GETEGID_METHODDEF    \
3171
    {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
3172
3173
static PyObject *
3174
os_getegid_impl(PyObject *module);
3175
3176
static PyObject *
3177
os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
3178
0
{
3179
0
    return os_getegid_impl(module);
3180
0
}
3181
3182
#endif /* defined(HAVE_GETEGID) */
3183
3184
#if defined(HAVE_GETEUID)
3185
3186
PyDoc_STRVAR(os_geteuid__doc__,
3187
"geteuid($module, /)\n"
3188
"--\n"
3189
"\n"
3190
"Return the current process\'s effective user id.");
3191
3192
#define OS_GETEUID_METHODDEF    \
3193
    {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
3194
3195
static PyObject *
3196
os_geteuid_impl(PyObject *module);
3197
3198
static PyObject *
3199
os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
3200
0
{
3201
0
    return os_geteuid_impl(module);
3202
0
}
3203
3204
#endif /* defined(HAVE_GETEUID) */
3205
3206
#if defined(HAVE_GETGID)
3207
3208
PyDoc_STRVAR(os_getgid__doc__,
3209
"getgid($module, /)\n"
3210
"--\n"
3211
"\n"
3212
"Return the current process\'s group id.");
3213
3214
#define OS_GETGID_METHODDEF    \
3215
    {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
3216
3217
static PyObject *
3218
os_getgid_impl(PyObject *module);
3219
3220
static PyObject *
3221
os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
3222
0
{
3223
0
    return os_getgid_impl(module);
3224
0
}
3225
3226
#endif /* defined(HAVE_GETGID) */
3227
3228
#if defined(HAVE_GETPID)
3229
3230
PyDoc_STRVAR(os_getpid__doc__,
3231
"getpid($module, /)\n"
3232
"--\n"
3233
"\n"
3234
"Return the current process id.");
3235
3236
#define OS_GETPID_METHODDEF    \
3237
    {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
3238
3239
static PyObject *
3240
os_getpid_impl(PyObject *module);
3241
3242
static PyObject *
3243
os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
3244
14
{
3245
14
    return os_getpid_impl(module);
3246
14
}
3247
3248
#endif /* defined(HAVE_GETPID) */
3249
3250
#if defined(HAVE_GETGROUPS)
3251
3252
PyDoc_STRVAR(os_getgroups__doc__,
3253
"getgroups($module, /)\n"
3254
"--\n"
3255
"\n"
3256
"Return list of supplemental group IDs for the process.");
3257
3258
#define OS_GETGROUPS_METHODDEF    \
3259
    {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
3260
3261
static PyObject *
3262
os_getgroups_impl(PyObject *module);
3263
3264
static PyObject *
3265
os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
3266
0
{
3267
0
    return os_getgroups_impl(module);
3268
0
}
3269
3270
#endif /* defined(HAVE_GETGROUPS) */
3271
3272
#if defined(HAVE_GETPGID)
3273
3274
PyDoc_STRVAR(os_getpgid__doc__,
3275
"getpgid($module, /, pid)\n"
3276
"--\n"
3277
"\n"
3278
"Call the system call getpgid(), and return the result.");
3279
3280
#define OS_GETPGID_METHODDEF    \
3281
    {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
3282
3283
static PyObject *
3284
os_getpgid_impl(PyObject *module, pid_t pid);
3285
3286
static PyObject *
3287
os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3288
0
{
3289
0
    PyObject *return_value = NULL;
3290
0
    static const char * const _keywords[] = {"pid", NULL};
3291
0
    static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
3292
0
    pid_t pid;
3293
3294
0
    if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3295
0
        &pid)) {
3296
0
        goto exit;
3297
0
    }
3298
0
    return_value = os_getpgid_impl(module, pid);
3299
3300
0
exit:
3301
0
    return return_value;
3302
0
}
3303
3304
#endif /* defined(HAVE_GETPGID) */
3305
3306
#if defined(HAVE_GETPGRP)
3307
3308
PyDoc_STRVAR(os_getpgrp__doc__,
3309
"getpgrp($module, /)\n"
3310
"--\n"
3311
"\n"
3312
"Return the current process group id.");
3313
3314
#define OS_GETPGRP_METHODDEF    \
3315
    {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
3316
3317
static PyObject *
3318
os_getpgrp_impl(PyObject *module);
3319
3320
static PyObject *
3321
os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
3322
0
{
3323
0
    return os_getpgrp_impl(module);
3324
0
}
3325
3326
#endif /* defined(HAVE_GETPGRP) */
3327
3328
#if defined(HAVE_SETPGRP)
3329
3330
PyDoc_STRVAR(os_setpgrp__doc__,
3331
"setpgrp($module, /)\n"
3332
"--\n"
3333
"\n"
3334
"Make the current process the leader of its process group.");
3335
3336
#define OS_SETPGRP_METHODDEF    \
3337
    {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
3338
3339
static PyObject *
3340
os_setpgrp_impl(PyObject *module);
3341
3342
static PyObject *
3343
os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
3344
0
{
3345
0
    return os_setpgrp_impl(module);
3346
0
}
3347
3348
#endif /* defined(HAVE_SETPGRP) */
3349
3350
#if defined(HAVE_GETPPID)
3351
3352
PyDoc_STRVAR(os_getppid__doc__,
3353
"getppid($module, /)\n"
3354
"--\n"
3355
"\n"
3356
"Return the parent\'s process id.\n"
3357
"\n"
3358
"If the parent process has already exited, Windows machines will still\n"
3359
"return its id; others systems will return the id of the \'init\' process (1).");
3360
3361
#define OS_GETPPID_METHODDEF    \
3362
    {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
3363
3364
static PyObject *
3365
os_getppid_impl(PyObject *module);
3366
3367
static PyObject *
3368
os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
3369
0
{
3370
0
    return os_getppid_impl(module);
3371
0
}
3372
3373
#endif /* defined(HAVE_GETPPID) */
3374
3375
#if defined(HAVE_GETLOGIN)
3376
3377
PyDoc_STRVAR(os_getlogin__doc__,
3378
"getlogin($module, /)\n"
3379
"--\n"
3380
"\n"
3381
"Return the actual login name.");
3382
3383
#define OS_GETLOGIN_METHODDEF    \
3384
    {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
3385
3386
static PyObject *
3387
os_getlogin_impl(PyObject *module);
3388
3389
static PyObject *
3390
os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
3391
0
{
3392
0
    return os_getlogin_impl(module);
3393
0
}
3394
3395
#endif /* defined(HAVE_GETLOGIN) */
3396
3397
#if defined(HAVE_GETUID)
3398
3399
PyDoc_STRVAR(os_getuid__doc__,
3400
"getuid($module, /)\n"
3401
"--\n"
3402
"\n"
3403
"Return the current process\'s user id.");
3404
3405
#define OS_GETUID_METHODDEF    \
3406
    {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
3407
3408
static PyObject *
3409
os_getuid_impl(PyObject *module);
3410
3411
static PyObject *
3412
os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
3413
0
{
3414
0
    return os_getuid_impl(module);
3415
0
}
3416
3417
#endif /* defined(HAVE_GETUID) */
3418
3419
#if defined(HAVE_KILL)
3420
3421
PyDoc_STRVAR(os_kill__doc__,
3422
"kill($module, pid, signal, /)\n"
3423
"--\n"
3424
"\n"
3425
"Kill a process with a signal.");
3426
3427
#define OS_KILL_METHODDEF    \
3428
    {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__},
3429
3430
static PyObject *
3431
os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
3432
3433
static PyObject *
3434
os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3435
0
{
3436
0
    PyObject *return_value = NULL;
3437
0
    pid_t pid;
3438
0
    Py_ssize_t signal;
3439
3440
0
    if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
3441
0
        &pid, &signal)) {
3442
0
        goto exit;
3443
0
    }
3444
0
    return_value = os_kill_impl(module, pid, signal);
3445
3446
0
exit:
3447
0
    return return_value;
3448
0
}
3449
3450
#endif /* defined(HAVE_KILL) */
3451
3452
#if defined(HAVE_KILLPG)
3453
3454
PyDoc_STRVAR(os_killpg__doc__,
3455
"killpg($module, pgid, signal, /)\n"
3456
"--\n"
3457
"\n"
3458
"Kill a process group with a signal.");
3459
3460
#define OS_KILLPG_METHODDEF    \
3461
    {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__},
3462
3463
static PyObject *
3464
os_killpg_impl(PyObject *module, pid_t pgid, int signal);
3465
3466
static PyObject *
3467
os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3468
0
{
3469
0
    PyObject *return_value = NULL;
3470
0
    pid_t pgid;
3471
0
    int signal;
3472
3473
0
    if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
3474
0
        &pgid, &signal)) {
3475
0
        goto exit;
3476
0
    }
3477
0
    return_value = os_killpg_impl(module, pgid, signal);
3478
3479
0
exit:
3480
0
    return return_value;
3481
0
}
3482
3483
#endif /* defined(HAVE_KILLPG) */
3484
3485
#if defined(HAVE_PLOCK)
3486
3487
PyDoc_STRVAR(os_plock__doc__,
3488
"plock($module, op, /)\n"
3489
"--\n"
3490
"\n"
3491
"Lock program segments into memory.\");");
3492
3493
#define OS_PLOCK_METHODDEF    \
3494
    {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
3495
3496
static PyObject *
3497
os_plock_impl(PyObject *module, int op);
3498
3499
static PyObject *
3500
os_plock(PyObject *module, PyObject *arg)
3501
{
3502
    PyObject *return_value = NULL;
3503
    int op;
3504
3505
    if (PyFloat_Check(arg)) {
3506
        PyErr_SetString(PyExc_TypeError,
3507
                        "integer argument expected, got float" );
3508
        goto exit;
3509
    }
3510
    op = _PyLong_AsInt(arg);
3511
    if (op == -1 && PyErr_Occurred()) {
3512
        goto exit;
3513
    }
3514
    return_value = os_plock_impl(module, op);
3515
3516
exit:
3517
    return return_value;
3518
}
3519
3520
#endif /* defined(HAVE_PLOCK) */
3521
3522
#if defined(HAVE_SETUID)
3523
3524
PyDoc_STRVAR(os_setuid__doc__,
3525
"setuid($module, uid, /)\n"
3526
"--\n"
3527
"\n"
3528
"Set the current process\'s user id.");
3529
3530
#define OS_SETUID_METHODDEF    \
3531
    {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
3532
3533
static PyObject *
3534
os_setuid_impl(PyObject *module, uid_t uid);
3535
3536
static PyObject *
3537
os_setuid(PyObject *module, PyObject *arg)
3538
0
{
3539
0
    PyObject *return_value = NULL;
3540
0
    uid_t uid;
3541
3542
0
    if (!_Py_Uid_Converter(arg, &uid)) {
3543
0
        goto exit;
3544
0
    }
3545
0
    return_value = os_setuid_impl(module, uid);
3546
3547
0
exit:
3548
0
    return return_value;
3549
0
}
3550
3551
#endif /* defined(HAVE_SETUID) */
3552
3553
#if defined(HAVE_SETEUID)
3554
3555
PyDoc_STRVAR(os_seteuid__doc__,
3556
"seteuid($module, euid, /)\n"
3557
"--\n"
3558
"\n"
3559
"Set the current process\'s effective user id.");
3560
3561
#define OS_SETEUID_METHODDEF    \
3562
    {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
3563
3564
static PyObject *
3565
os_seteuid_impl(PyObject *module, uid_t euid);
3566
3567
static PyObject *
3568
os_seteuid(PyObject *module, PyObject *arg)
3569
0
{
3570
0
    PyObject *return_value = NULL;
3571
0
    uid_t euid;
3572
3573
0
    if (!_Py_Uid_Converter(arg, &euid)) {
3574
0
        goto exit;
3575
0
    }
3576
0
    return_value = os_seteuid_impl(module, euid);
3577
3578
0
exit:
3579
0
    return return_value;
3580
0
}
3581
3582
#endif /* defined(HAVE_SETEUID) */
3583
3584
#if defined(HAVE_SETEGID)
3585
3586
PyDoc_STRVAR(os_setegid__doc__,
3587
"setegid($module, egid, /)\n"
3588
"--\n"
3589
"\n"
3590
"Set the current process\'s effective group id.");
3591
3592
#define OS_SETEGID_METHODDEF    \
3593
    {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
3594
3595
static PyObject *
3596
os_setegid_impl(PyObject *module, gid_t egid);
3597
3598
static PyObject *
3599
os_setegid(PyObject *module, PyObject *arg)
3600
0
{
3601
0
    PyObject *return_value = NULL;
3602
0
    gid_t egid;
3603
3604
0
    if (!_Py_Gid_Converter(arg, &egid)) {
3605
0
        goto exit;
3606
0
    }
3607
0
    return_value = os_setegid_impl(module, egid);
3608
3609
0
exit:
3610
0
    return return_value;
3611
0
}
3612
3613
#endif /* defined(HAVE_SETEGID) */
3614
3615
#if defined(HAVE_SETREUID)
3616
3617
PyDoc_STRVAR(os_setreuid__doc__,
3618
"setreuid($module, ruid, euid, /)\n"
3619
"--\n"
3620
"\n"
3621
"Set the current process\'s real and effective user ids.");
3622
3623
#define OS_SETREUID_METHODDEF    \
3624
    {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__},
3625
3626
static PyObject *
3627
os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
3628
3629
static PyObject *
3630
os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3631
0
{
3632
0
    PyObject *return_value = NULL;
3633
0
    uid_t ruid;
3634
0
    uid_t euid;
3635
3636
0
    if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
3637
0
        goto exit;
3638
0
    }
3639
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
3640
0
        goto exit;
3641
0
    }
3642
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
3643
0
        goto exit;
3644
0
    }
3645
0
    return_value = os_setreuid_impl(module, ruid, euid);
3646
3647
0
exit:
3648
0
    return return_value;
3649
0
}
3650
3651
#endif /* defined(HAVE_SETREUID) */
3652
3653
#if defined(HAVE_SETREGID)
3654
3655
PyDoc_STRVAR(os_setregid__doc__,
3656
"setregid($module, rgid, egid, /)\n"
3657
"--\n"
3658
"\n"
3659
"Set the current process\'s real and effective group ids.");
3660
3661
#define OS_SETREGID_METHODDEF    \
3662
    {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__},
3663
3664
static PyObject *
3665
os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
3666
3667
static PyObject *
3668
os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3669
0
{
3670
0
    PyObject *return_value = NULL;
3671
0
    gid_t rgid;
3672
0
    gid_t egid;
3673
3674
0
    if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
3675
0
        goto exit;
3676
0
    }
3677
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
3678
0
        goto exit;
3679
0
    }
3680
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
3681
0
        goto exit;
3682
0
    }
3683
0
    return_value = os_setregid_impl(module, rgid, egid);
3684
3685
0
exit:
3686
0
    return return_value;
3687
0
}
3688
3689
#endif /* defined(HAVE_SETREGID) */
3690
3691
#if defined(HAVE_SETGID)
3692
3693
PyDoc_STRVAR(os_setgid__doc__,
3694
"setgid($module, gid, /)\n"
3695
"--\n"
3696
"\n"
3697
"Set the current process\'s group id.");
3698
3699
#define OS_SETGID_METHODDEF    \
3700
    {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
3701
3702
static PyObject *
3703
os_setgid_impl(PyObject *module, gid_t gid);
3704
3705
static PyObject *
3706
os_setgid(PyObject *module, PyObject *arg)
3707
0
{
3708
0
    PyObject *return_value = NULL;
3709
0
    gid_t gid;
3710
3711
0
    if (!_Py_Gid_Converter(arg, &gid)) {
3712
0
        goto exit;
3713
0
    }
3714
0
    return_value = os_setgid_impl(module, gid);
3715
3716
0
exit:
3717
0
    return return_value;
3718
0
}
3719
3720
#endif /* defined(HAVE_SETGID) */
3721
3722
#if defined(HAVE_SETGROUPS)
3723
3724
PyDoc_STRVAR(os_setgroups__doc__,
3725
"setgroups($module, groups, /)\n"
3726
"--\n"
3727
"\n"
3728
"Set the groups of the current process to list.");
3729
3730
#define OS_SETGROUPS_METHODDEF    \
3731
    {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
3732
3733
#endif /* defined(HAVE_SETGROUPS) */
3734
3735
#if defined(HAVE_WAIT3)
3736
3737
PyDoc_STRVAR(os_wait3__doc__,
3738
"wait3($module, /, options)\n"
3739
"--\n"
3740
"\n"
3741
"Wait for completion of a child process.\n"
3742
"\n"
3743
"Returns a tuple of information about the child process:\n"
3744
"  (pid, status, rusage)");
3745
3746
#define OS_WAIT3_METHODDEF    \
3747
    {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
3748
3749
static PyObject *
3750
os_wait3_impl(PyObject *module, int options);
3751
3752
static PyObject *
3753
os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3754
0
{
3755
0
    PyObject *return_value = NULL;
3756
0
    static const char * const _keywords[] = {"options", NULL};
3757
0
    static _PyArg_Parser _parser = {NULL, _keywords, "wait3", 0};
3758
0
    PyObject *argsbuf[1];
3759
0
    int options;
3760
3761
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
3762
0
    if (!args) {
3763
0
        goto exit;
3764
0
    }
3765
0
    if (PyFloat_Check(args[0])) {
3766
0
        PyErr_SetString(PyExc_TypeError,
3767
0
                        "integer argument expected, got float" );
3768
0
        goto exit;
3769
0
    }
3770
0
    options = _PyLong_AsInt(args[0]);
3771
0
    if (options == -1 && PyErr_Occurred()) {
3772
0
        goto exit;
3773
0
    }
3774
0
    return_value = os_wait3_impl(module, options);
3775
3776
0
exit:
3777
0
    return return_value;
3778
0
}
3779
3780
#endif /* defined(HAVE_WAIT3) */
3781
3782
#if defined(HAVE_WAIT4)
3783
3784
PyDoc_STRVAR(os_wait4__doc__,
3785
"wait4($module, /, pid, options)\n"
3786
"--\n"
3787
"\n"
3788
"Wait for completion of a specific child process.\n"
3789
"\n"
3790
"Returns a tuple of information about the child process:\n"
3791
"  (pid, status, rusage)");
3792
3793
#define OS_WAIT4_METHODDEF    \
3794
    {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
3795
3796
static PyObject *
3797
os_wait4_impl(PyObject *module, pid_t pid, int options);
3798
3799
static PyObject *
3800
os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3801
0
{
3802
0
    PyObject *return_value = NULL;
3803
0
    static const char * const _keywords[] = {"pid", "options", NULL};
3804
0
    static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
3805
0
    pid_t pid;
3806
0
    int options;
3807
3808
0
    if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3809
0
        &pid, &options)) {
3810
0
        goto exit;
3811
0
    }
3812
0
    return_value = os_wait4_impl(module, pid, options);
3813
3814
0
exit:
3815
0
    return return_value;
3816
0
}
3817
3818
#endif /* defined(HAVE_WAIT4) */
3819
3820
#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3821
3822
PyDoc_STRVAR(os_waitid__doc__,
3823
"waitid($module, idtype, id, options, /)\n"
3824
"--\n"
3825
"\n"
3826
"Returns the result of waiting for a process or processes.\n"
3827
"\n"
3828
"  idtype\n"
3829
"    Must be one of be P_PID, P_PGID or P_ALL.\n"
3830
"  id\n"
3831
"    The id to wait on.\n"
3832
"  options\n"
3833
"    Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3834
"    or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3835
"\n"
3836
"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3837
"no children in a waitable state.");
3838
3839
#define OS_WAITID_METHODDEF    \
3840
    {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__},
3841
3842
static PyObject *
3843
os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
3844
3845
static PyObject *
3846
os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3847
0
{
3848
0
    PyObject *return_value = NULL;
3849
0
    idtype_t idtype;
3850
0
    id_t id;
3851
0
    int options;
3852
3853
0
    if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3854
0
        &idtype, &id, &options)) {
3855
0
        goto exit;
3856
0
    }
3857
0
    return_value = os_waitid_impl(module, idtype, id, options);
3858
3859
0
exit:
3860
0
    return return_value;
3861
0
}
3862
3863
#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3864
3865
#if defined(HAVE_WAITPID)
3866
3867
PyDoc_STRVAR(os_waitpid__doc__,
3868
"waitpid($module, pid, options, /)\n"
3869
"--\n"
3870
"\n"
3871
"Wait for completion of a given child process.\n"
3872
"\n"
3873
"Returns a tuple of information regarding the child process:\n"
3874
"    (pid, status)\n"
3875
"\n"
3876
"The options argument is ignored on Windows.");
3877
3878
#define OS_WAITPID_METHODDEF    \
3879
    {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
3880
3881
static PyObject *
3882
os_waitpid_impl(PyObject *module, pid_t pid, int options);
3883
3884
static PyObject *
3885
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3886
0
{
3887
0
    PyObject *return_value = NULL;
3888
0
    pid_t pid;
3889
0
    int options;
3890
3891
0
    if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3892
0
        &pid, &options)) {
3893
0
        goto exit;
3894
0
    }
3895
0
    return_value = os_waitpid_impl(module, pid, options);
3896
3897
0
exit:
3898
0
    return return_value;
3899
0
}
3900
3901
#endif /* defined(HAVE_WAITPID) */
3902
3903
#if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT)
3904
3905
PyDoc_STRVAR(os_waitpid__doc__,
3906
"waitpid($module, pid, options, /)\n"
3907
"--\n"
3908
"\n"
3909
"Wait for completion of a given process.\n"
3910
"\n"
3911
"Returns a tuple of information regarding the process:\n"
3912
"    (pid, status << 8)\n"
3913
"\n"
3914
"The options argument is ignored on Windows.");
3915
3916
#define OS_WAITPID_METHODDEF    \
3917
    {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
3918
3919
static PyObject *
3920
os_waitpid_impl(PyObject *module, intptr_t pid, int options);
3921
3922
static PyObject *
3923
os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3924
{
3925
    PyObject *return_value = NULL;
3926
    intptr_t pid;
3927
    int options;
3928
3929
    if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3930
        &pid, &options)) {
3931
        goto exit;
3932
    }
3933
    return_value = os_waitpid_impl(module, pid, options);
3934
3935
exit:
3936
    return return_value;
3937
}
3938
3939
#endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */
3940
3941
#if defined(HAVE_WAIT)
3942
3943
PyDoc_STRVAR(os_wait__doc__,
3944
"wait($module, /)\n"
3945
"--\n"
3946
"\n"
3947
"Wait for completion of a child process.\n"
3948
"\n"
3949
"Returns a tuple of information about the child process:\n"
3950
"    (pid, status)");
3951
3952
#define OS_WAIT_METHODDEF    \
3953
    {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3954
3955
static PyObject *
3956
os_wait_impl(PyObject *module);
3957
3958
static PyObject *
3959
os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
3960
0
{
3961
0
    return os_wait_impl(module);
3962
0
}
3963
3964
#endif /* defined(HAVE_WAIT) */
3965
3966
#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
3967
3968
PyDoc_STRVAR(os_readlink__doc__,
3969
"readlink($module, /, path, *, dir_fd=None)\n"
3970
"--\n"
3971
"\n"
3972
"Return a string representing the path to which the symbolic link points.\n"
3973
"\n"
3974
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3975
"and path should be relative; path will then be relative to that directory.\n"
3976
"\n"
3977
"dir_fd may not be implemented on your platform.  If it is unavailable,\n"
3978
"using it will raise a NotImplementedError.");
3979
3980
#define OS_READLINK_METHODDEF    \
3981
    {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
3982
3983
static PyObject *
3984
os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
3985
3986
static PyObject *
3987
os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3988
0
{
3989
0
    PyObject *return_value = NULL;
3990
0
    static const char * const _keywords[] = {"path", "dir_fd", NULL};
3991
0
    static _PyArg_Parser _parser = {NULL, _keywords, "readlink", 0};
3992
0
    PyObject *argsbuf[2];
3993
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3994
0
    path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
3995
0
    int dir_fd = DEFAULT_DIR_FD;
3996
3997
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
3998
0
    if (!args) {
3999
0
        goto exit;
4000
0
    }
4001
0
    if (!path_converter(args[0], &path)) {
4002
0
        goto exit;
4003
0
    }
4004
0
    if (!noptargs) {
4005
0
        goto skip_optional_kwonly;
4006
0
    }
4007
0
    if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
4008
0
        goto exit;
4009
0
    }
4010
0
skip_optional_kwonly:
4011
0
    return_value = os_readlink_impl(module, &path, dir_fd);
4012
4013
0
exit:
4014
    /* Cleanup for path */
4015
0
    path_cleanup(&path);
4016
4017
0
    return return_value;
4018
0
}
4019
4020
#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
4021
4022
#if defined(HAVE_SYMLINK)
4023
4024
PyDoc_STRVAR(os_symlink__doc__,
4025
"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
4026
"--\n"
4027
"\n"
4028
"Create a symbolic link pointing to src named dst.\n"
4029
"\n"
4030
"target_is_directory is required on Windows if the target is to be\n"
4031
"  interpreted as a directory.  (On Windows, symlink requires\n"
4032
"  Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
4033
"  target_is_directory is ignored on non-Windows platforms.\n"
4034
"\n"
4035
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4036
"  and path should be relative; path will then be relative to that directory.\n"
4037
"dir_fd may not be implemented on your platform.\n"
4038
"  If it is unavailable, using it will raise a NotImplementedError.");
4039
4040
#define OS_SYMLINK_METHODDEF    \
4041
    {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
4042
4043
static PyObject *
4044
os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
4045
                int target_is_directory, int dir_fd);
4046
4047
static PyObject *
4048
os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4049
0
{
4050
0
    PyObject *return_value = NULL;
4051
0
    static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
4052
0
    static _PyArg_Parser _parser = {NULL, _keywords, "symlink", 0};
4053
0
    PyObject *argsbuf[4];
4054
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
4055
0
    path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
4056
0
    path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
4057
0
    int target_is_directory = 0;
4058
0
    int dir_fd = DEFAULT_DIR_FD;
4059
4060
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
4061
0
    if (!args) {
4062
0
        goto exit;
4063
0
    }
4064
0
    if (!path_converter(args[0], &src)) {
4065
0
        goto exit;
4066
0
    }
4067
0
    if (!path_converter(args[1], &dst)) {
4068
0
        goto exit;
4069
0
    }
4070
0
    if (!noptargs) {
4071
0
        goto skip_optional_pos;
4072
0
    }
4073
0
    if (args[2]) {
4074
0
        target_is_directory = PyObject_IsTrue(args[2]);
4075
0
        if (target_is_directory < 0) {
4076
0
            goto exit;
4077
0
        }
4078
0
        if (!--noptargs) {
4079
0
            goto skip_optional_pos;
4080
0
        }
4081
0
    }
4082
0
skip_optional_pos:
4083
0
    if (!noptargs) {
4084
0
        goto skip_optional_kwonly;
4085
0
    }
4086
0
    if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
4087
0
        goto exit;
4088
0
    }
4089
0
skip_optional_kwonly:
4090
0
    return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
4091
4092
0
exit:
4093
    /* Cleanup for src */
4094
0
    path_cleanup(&src);
4095
    /* Cleanup for dst */
4096
0
    path_cleanup(&dst);
4097
4098
0
    return return_value;
4099
0
}
4100
4101
#endif /* defined(HAVE_SYMLINK) */
4102
4103
#if defined(HAVE_TIMES)
4104
4105
PyDoc_STRVAR(os_times__doc__,
4106
"times($module, /)\n"
4107
"--\n"
4108
"\n"
4109
"Return a collection containing process timing information.\n"
4110
"\n"
4111
"The object returned behaves like a named tuple with these fields:\n"
4112
"  (utime, stime, cutime, cstime, elapsed_time)\n"
4113
"All fields are floating point numbers.");
4114
4115
#define OS_TIMES_METHODDEF    \
4116
    {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
4117
4118
static PyObject *
4119
os_times_impl(PyObject *module);
4120
4121
static PyObject *
4122
os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
4123
0
{
4124
0
    return os_times_impl(module);
4125
0
}
4126
4127
#endif /* defined(HAVE_TIMES) */
4128
4129
#if defined(HAVE_GETSID)
4130
4131
PyDoc_STRVAR(os_getsid__doc__,
4132
"getsid($module, pid, /)\n"
4133
"--\n"
4134
"\n"
4135
"Call the system call getsid(pid) and return the result.");
4136
4137
#define OS_GETSID_METHODDEF    \
4138
    {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
4139
4140
static PyObject *
4141
os_getsid_impl(PyObject *module, pid_t pid);
4142
4143
static PyObject *
4144
os_getsid(PyObject *module, PyObject *arg)
4145
0
{
4146
0
    PyObject *return_value = NULL;
4147
0
    pid_t pid;
4148
4149
0
    if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
4150
0
        goto exit;
4151
0
    }
4152
0
    return_value = os_getsid_impl(module, pid);
4153
4154
0
exit:
4155
0
    return return_value;
4156
0
}
4157
4158
#endif /* defined(HAVE_GETSID) */
4159
4160
#if defined(HAVE_SETSID)
4161
4162
PyDoc_STRVAR(os_setsid__doc__,
4163
"setsid($module, /)\n"
4164
"--\n"
4165
"\n"
4166
"Call the system call setsid().");
4167
4168
#define OS_SETSID_METHODDEF    \
4169
    {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
4170
4171
static PyObject *
4172
os_setsid_impl(PyObject *module);
4173
4174
static PyObject *
4175
os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
4176
0
{
4177
0
    return os_setsid_impl(module);
4178
0
}
4179
4180
#endif /* defined(HAVE_SETSID) */
4181
4182
#if defined(HAVE_SETPGID)
4183
4184
PyDoc_STRVAR(os_setpgid__doc__,
4185
"setpgid($module, pid, pgrp, /)\n"
4186
"--\n"
4187
"\n"
4188
"Call the system call setpgid(pid, pgrp).");
4189
4190
#define OS_SETPGID_METHODDEF    \
4191
    {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__},
4192
4193
static PyObject *
4194
os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
4195
4196
static PyObject *
4197
os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4198
0
{
4199
0
    PyObject *return_value = NULL;
4200
0
    pid_t pid;
4201
0
    pid_t pgrp;
4202
4203
0
    if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
4204
0
        &pid, &pgrp)) {
4205
0
        goto exit;
4206
0
    }
4207
0
    return_value = os_setpgid_impl(module, pid, pgrp);
4208
4209
0
exit:
4210
0
    return return_value;
4211
0
}
4212
4213
#endif /* defined(HAVE_SETPGID) */
4214
4215
#if defined(HAVE_TCGETPGRP)
4216
4217
PyDoc_STRVAR(os_tcgetpgrp__doc__,
4218
"tcgetpgrp($module, fd, /)\n"
4219
"--\n"
4220
"\n"
4221
"Return the process group associated with the terminal specified by fd.");
4222
4223
#define OS_TCGETPGRP_METHODDEF    \
4224
    {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
4225
4226
static PyObject *
4227
os_tcgetpgrp_impl(PyObject *module, int fd);
4228
4229
static PyObject *
4230
os_tcgetpgrp(PyObject *module, PyObject *arg)
4231
0
{
4232
0
    PyObject *return_value = NULL;
4233
0
    int fd;
4234
4235
0
    if (PyFloat_Check(arg)) {
4236
0
        PyErr_SetString(PyExc_TypeError,
4237
0
                        "integer argument expected, got float" );
4238
0
        goto exit;
4239
0
    }
4240
0
    fd = _PyLong_AsInt(arg);
4241
0
    if (fd == -1 && PyErr_Occurred()) {
4242
0
        goto exit;
4243
0
    }
4244
0
    return_value = os_tcgetpgrp_impl(module, fd);
4245
4246
0
exit:
4247
0
    return return_value;
4248
0
}
4249
4250
#endif /* defined(HAVE_TCGETPGRP) */
4251
4252
#if defined(HAVE_TCSETPGRP)
4253
4254
PyDoc_STRVAR(os_tcsetpgrp__doc__,
4255
"tcsetpgrp($module, fd, pgid, /)\n"
4256
"--\n"
4257
"\n"
4258
"Set the process group associated with the terminal specified by fd.");
4259
4260
#define OS_TCSETPGRP_METHODDEF    \
4261
    {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
4262
4263
static PyObject *
4264
os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
4265
4266
static PyObject *
4267
os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4268
0
{
4269
0
    PyObject *return_value = NULL;
4270
0
    int fd;
4271
0
    pid_t pgid;
4272
4273
0
    if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
4274
0
        &fd, &pgid)) {
4275
0
        goto exit;
4276
0
    }
4277
0
    return_value = os_tcsetpgrp_impl(module, fd, pgid);
4278
4279
0
exit:
4280
0
    return return_value;
4281
0
}
4282
4283
#endif /* defined(HAVE_TCSETPGRP) */
4284
4285
PyDoc_STRVAR(os_open__doc__,
4286
"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
4287
"--\n"
4288
"\n"
4289
"Open a file for low level IO.  Returns a file descriptor (integer).\n"
4290
"\n"
4291
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4292
"  and path should be relative; path will then be relative to that directory.\n"
4293
"dir_fd may not be implemented on your platform.\n"
4294
"  If it is unavailable, using it will raise a NotImplementedError.");
4295
4296
#define OS_OPEN_METHODDEF    \
4297
    {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
4298
4299
static int
4300
os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
4301
4302
static PyObject *
4303
os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4304
0
{
4305
0
    PyObject *return_value = NULL;
4306
0
    static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
4307
0
    static _PyArg_Parser _parser = {NULL, _keywords, "open", 0};
4308
0
    PyObject *argsbuf[4];
4309
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
4310
0
    path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
4311
0
    int flags;
4312
0
    int mode = 511;
4313
0
    int dir_fd = DEFAULT_DIR_FD;
4314
0
    int _return_value;
4315
4316
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
4317
0
    if (!args) {
4318
0
        goto exit;
4319
0
    }
4320
0
    if (!path_converter(args[0], &path)) {
4321
0
        goto exit;
4322
0
    }
4323
0
    if (PyFloat_Check(args[1])) {
4324
0
        PyErr_SetString(PyExc_TypeError,
4325
0
                        "integer argument expected, got float" );
4326
0
        goto exit;
4327
0
    }
4328
0
    flags = _PyLong_AsInt(args[1]);
4329
0
    if (flags == -1 && PyErr_Occurred()) {
4330
0
        goto exit;
4331
0
    }
4332
0
    if (!noptargs) {
4333
0
        goto skip_optional_pos;
4334
0
    }
4335
0
    if (args[2]) {
4336
0
        if (PyFloat_Check(args[2])) {
4337
0
            PyErr_SetString(PyExc_TypeError,
4338
0
                            "integer argument expected, got float" );
4339
0
            goto exit;
4340
0
        }
4341
0
        mode = _PyLong_AsInt(args[2]);
4342
0
        if (mode == -1 && PyErr_Occurred()) {
4343
0
            goto exit;
4344
0
        }
4345
0
        if (!--noptargs) {
4346
0
            goto skip_optional_pos;
4347
0
        }
4348
0
    }
4349
0
skip_optional_pos:
4350
0
    if (!noptargs) {
4351
0
        goto skip_optional_kwonly;
4352
0
    }
4353
0
    if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
4354
0
        goto exit;
4355
0
    }
4356
0
skip_optional_kwonly:
4357
0
    _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
4358
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4359
0
        goto exit;
4360
0
    }
4361
0
    return_value = PyLong_FromLong((long)_return_value);
4362
4363
0
exit:
4364
    /* Cleanup for path */
4365
0
    path_cleanup(&path);
4366
4367
0
    return return_value;
4368
0
}
4369
4370
PyDoc_STRVAR(os_close__doc__,
4371
"close($module, /, fd)\n"
4372
"--\n"
4373
"\n"
4374
"Close a file descriptor.");
4375
4376
#define OS_CLOSE_METHODDEF    \
4377
    {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
4378
4379
static PyObject *
4380
os_close_impl(PyObject *module, int fd);
4381
4382
static PyObject *
4383
os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4384
0
{
4385
0
    PyObject *return_value = NULL;
4386
0
    static const char * const _keywords[] = {"fd", NULL};
4387
0
    static _PyArg_Parser _parser = {NULL, _keywords, "close", 0};
4388
0
    PyObject *argsbuf[1];
4389
0
    int fd;
4390
4391
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
4392
0
    if (!args) {
4393
0
        goto exit;
4394
0
    }
4395
0
    if (PyFloat_Check(args[0])) {
4396
0
        PyErr_SetString(PyExc_TypeError,
4397
0
                        "integer argument expected, got float" );
4398
0
        goto exit;
4399
0
    }
4400
0
    fd = _PyLong_AsInt(args[0]);
4401
0
    if (fd == -1 && PyErr_Occurred()) {
4402
0
        goto exit;
4403
0
    }
4404
0
    return_value = os_close_impl(module, fd);
4405
4406
0
exit:
4407
0
    return return_value;
4408
0
}
4409
4410
PyDoc_STRVAR(os_closerange__doc__,
4411
"closerange($module, fd_low, fd_high, /)\n"
4412
"--\n"
4413
"\n"
4414
"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
4415
4416
#define OS_CLOSERANGE_METHODDEF    \
4417
    {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__},
4418
4419
static PyObject *
4420
os_closerange_impl(PyObject *module, int fd_low, int fd_high);
4421
4422
static PyObject *
4423
os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4424
0
{
4425
0
    PyObject *return_value = NULL;
4426
0
    int fd_low;
4427
0
    int fd_high;
4428
4429
0
    if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
4430
0
        goto exit;
4431
0
    }
4432
0
    if (PyFloat_Check(args[0])) {
4433
0
        PyErr_SetString(PyExc_TypeError,
4434
0
                        "integer argument expected, got float" );
4435
0
        goto exit;
4436
0
    }
4437
0
    fd_low = _PyLong_AsInt(args[0]);
4438
0
    if (fd_low == -1 && PyErr_Occurred()) {
4439
0
        goto exit;
4440
0
    }
4441
0
    if (PyFloat_Check(args[1])) {
4442
0
        PyErr_SetString(PyExc_TypeError,
4443
0
                        "integer argument expected, got float" );
4444
0
        goto exit;
4445
0
    }
4446
0
    fd_high = _PyLong_AsInt(args[1]);
4447
0
    if (fd_high == -1 && PyErr_Occurred()) {
4448
0
        goto exit;
4449
0
    }
4450
0
    return_value = os_closerange_impl(module, fd_low, fd_high);
4451
4452
0
exit:
4453
0
    return return_value;
4454
0
}
4455
4456
PyDoc_STRVAR(os_dup__doc__,
4457
"dup($module, fd, /)\n"
4458
"--\n"
4459
"\n"
4460
"Return a duplicate of a file descriptor.");
4461
4462
#define OS_DUP_METHODDEF    \
4463
    {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
4464
4465
static int
4466
os_dup_impl(PyObject *module, int fd);
4467
4468
static PyObject *
4469
os_dup(PyObject *module, PyObject *arg)
4470
0
{
4471
0
    PyObject *return_value = NULL;
4472
0
    int fd;
4473
0
    int _return_value;
4474
4475
0
    if (PyFloat_Check(arg)) {
4476
0
        PyErr_SetString(PyExc_TypeError,
4477
0
                        "integer argument expected, got float" );
4478
0
        goto exit;
4479
0
    }
4480
0
    fd = _PyLong_AsInt(arg);
4481
0
    if (fd == -1 && PyErr_Occurred()) {
4482
0
        goto exit;
4483
0
    }
4484
0
    _return_value = os_dup_impl(module, fd);
4485
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4486
0
        goto exit;
4487
0
    }
4488
0
    return_value = PyLong_FromLong((long)_return_value);
4489
4490
0
exit:
4491
0
    return return_value;
4492
0
}
4493
4494
PyDoc_STRVAR(os_dup2__doc__,
4495
"dup2($module, /, fd, fd2, inheritable=True)\n"
4496
"--\n"
4497
"\n"
4498
"Duplicate file descriptor.");
4499
4500
#define OS_DUP2_METHODDEF    \
4501
    {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
4502
4503
static int
4504
os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
4505
4506
static PyObject *
4507
os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4508
0
{
4509
0
    PyObject *return_value = NULL;
4510
0
    static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
4511
0
    static _PyArg_Parser _parser = {NULL, _keywords, "dup2", 0};
4512
0
    PyObject *argsbuf[3];
4513
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
4514
0
    int fd;
4515
0
    int fd2;
4516
0
    int inheritable = 1;
4517
0
    int _return_value;
4518
4519
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
4520
0
    if (!args) {
4521
0
        goto exit;
4522
0
    }
4523
0
    if (PyFloat_Check(args[0])) {
4524
0
        PyErr_SetString(PyExc_TypeError,
4525
0
                        "integer argument expected, got float" );
4526
0
        goto exit;
4527
0
    }
4528
0
    fd = _PyLong_AsInt(args[0]);
4529
0
    if (fd == -1 && PyErr_Occurred()) {
4530
0
        goto exit;
4531
0
    }
4532
0
    if (PyFloat_Check(args[1])) {
4533
0
        PyErr_SetString(PyExc_TypeError,
4534
0
                        "integer argument expected, got float" );
4535
0
        goto exit;
4536
0
    }
4537
0
    fd2 = _PyLong_AsInt(args[1]);
4538
0
    if (fd2 == -1 && PyErr_Occurred()) {
4539
0
        goto exit;
4540
0
    }
4541
0
    if (!noptargs) {
4542
0
        goto skip_optional_pos;
4543
0
    }
4544
0
    inheritable = PyObject_IsTrue(args[2]);
4545
0
    if (inheritable < 0) {
4546
0
        goto exit;
4547
0
    }
4548
0
skip_optional_pos:
4549
0
    _return_value = os_dup2_impl(module, fd, fd2, inheritable);
4550
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4551
0
        goto exit;
4552
0
    }
4553
0
    return_value = PyLong_FromLong((long)_return_value);
4554
4555
0
exit:
4556
0
    return return_value;
4557
0
}
4558
4559
#if defined(HAVE_LOCKF)
4560
4561
PyDoc_STRVAR(os_lockf__doc__,
4562
"lockf($module, fd, command, length, /)\n"
4563
"--\n"
4564
"\n"
4565
"Apply, test or remove a POSIX lock on an open file descriptor.\n"
4566
"\n"
4567
"  fd\n"
4568
"    An open file descriptor.\n"
4569
"  command\n"
4570
"    One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
4571
"  length\n"
4572
"    The number of bytes to lock, starting at the current position.");
4573
4574
#define OS_LOCKF_METHODDEF    \
4575
    {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__},
4576
4577
static PyObject *
4578
os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
4579
4580
static PyObject *
4581
os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4582
0
{
4583
0
    PyObject *return_value = NULL;
4584
0
    int fd;
4585
0
    int command;
4586
0
    Py_off_t length;
4587
4588
0
    if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
4589
0
        goto exit;
4590
0
    }
4591
0
    if (PyFloat_Check(args[0])) {
4592
0
        PyErr_SetString(PyExc_TypeError,
4593
0
                        "integer argument expected, got float" );
4594
0
        goto exit;
4595
0
    }
4596
0
    fd = _PyLong_AsInt(args[0]);
4597
0
    if (fd == -1 && PyErr_Occurred()) {
4598
0
        goto exit;
4599
0
    }
4600
0
    if (PyFloat_Check(args[1])) {
4601
0
        PyErr_SetString(PyExc_TypeError,
4602
0
                        "integer argument expected, got float" );
4603
0
        goto exit;
4604
0
    }
4605
0
    command = _PyLong_AsInt(args[1]);
4606
0
    if (command == -1 && PyErr_Occurred()) {
4607
0
        goto exit;
4608
0
    }
4609
0
    if (!Py_off_t_converter(args[2], &length)) {
4610
0
        goto exit;
4611
0
    }
4612
0
    return_value = os_lockf_impl(module, fd, command, length);
4613
4614
0
exit:
4615
0
    return return_value;
4616
0
}
4617
4618
#endif /* defined(HAVE_LOCKF) */
4619
4620
PyDoc_STRVAR(os_lseek__doc__,
4621
"lseek($module, fd, position, how, /)\n"
4622
"--\n"
4623
"\n"
4624
"Set the position of a file descriptor.  Return the new position.\n"
4625
"\n"
4626
"Return the new cursor position in number of bytes\n"
4627
"relative to the beginning of the file.");
4628
4629
#define OS_LSEEK_METHODDEF    \
4630
    {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__},
4631
4632
static Py_off_t
4633
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
4634
4635
static PyObject *
4636
os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4637
0
{
4638
0
    PyObject *return_value = NULL;
4639
0
    int fd;
4640
0
    Py_off_t position;
4641
0
    int how;
4642
0
    Py_off_t _return_value;
4643
4644
0
    if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
4645
0
        goto exit;
4646
0
    }
4647
0
    if (PyFloat_Check(args[0])) {
4648
0
        PyErr_SetString(PyExc_TypeError,
4649
0
                        "integer argument expected, got float" );
4650
0
        goto exit;
4651
0
    }
4652
0
    fd = _PyLong_AsInt(args[0]);
4653
0
    if (fd == -1 && PyErr_Occurred()) {
4654
0
        goto exit;
4655
0
    }
4656
0
    if (!Py_off_t_converter(args[1], &position)) {
4657
0
        goto exit;
4658
0
    }
4659
0
    if (PyFloat_Check(args[2])) {
4660
0
        PyErr_SetString(PyExc_TypeError,
4661
0
                        "integer argument expected, got float" );
4662
0
        goto exit;
4663
0
    }
4664
0
    how = _PyLong_AsInt(args[2]);
4665
0
    if (how == -1 && PyErr_Occurred()) {
4666
0
        goto exit;
4667
0
    }
4668
0
    _return_value = os_lseek_impl(module, fd, position, how);
4669
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4670
0
        goto exit;
4671
0
    }
4672
0
    return_value = PyLong_FromPy_off_t(_return_value);
4673
4674
0
exit:
4675
0
    return return_value;
4676
0
}
4677
4678
PyDoc_STRVAR(os_read__doc__,
4679
"read($module, fd, length, /)\n"
4680
"--\n"
4681
"\n"
4682
"Read from a file descriptor.  Returns a bytes object.");
4683
4684
#define OS_READ_METHODDEF    \
4685
    {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__},
4686
4687
static PyObject *
4688
os_read_impl(PyObject *module, int fd, Py_ssize_t length);
4689
4690
static PyObject *
4691
os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4692
0
{
4693
0
    PyObject *return_value = NULL;
4694
0
    int fd;
4695
0
    Py_ssize_t length;
4696
4697
0
    if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
4698
0
        goto exit;
4699
0
    }
4700
0
    if (PyFloat_Check(args[0])) {
4701
0
        PyErr_SetString(PyExc_TypeError,
4702
0
                        "integer argument expected, got float" );
4703
0
        goto exit;
4704
0
    }
4705
0
    fd = _PyLong_AsInt(args[0]);
4706
0
    if (fd == -1 && PyErr_Occurred()) {
4707
0
        goto exit;
4708
0
    }
4709
0
    if (PyFloat_Check(args[1])) {
4710
0
        PyErr_SetString(PyExc_TypeError,
4711
0
                        "integer argument expected, got float" );
4712
0
        goto exit;
4713
0
    }
4714
0
    {
4715
0
        Py_ssize_t ival = -1;
4716
0
        PyObject *iobj = PyNumber_Index(args[1]);
4717
0
        if (iobj != NULL) {
4718
0
            ival = PyLong_AsSsize_t(iobj);
4719
0
            Py_DECREF(iobj);
4720
0
        }
4721
0
        if (ival == -1 && PyErr_Occurred()) {
4722
0
            goto exit;
4723
0
        }
4724
0
        length = ival;
4725
0
    }
4726
0
    return_value = os_read_impl(module, fd, length);
4727
4728
0
exit:
4729
0
    return return_value;
4730
0
}
4731
4732
#if defined(HAVE_READV)
4733
4734
PyDoc_STRVAR(os_readv__doc__,
4735
"readv($module, fd, buffers, /)\n"
4736
"--\n"
4737
"\n"
4738
"Read from a file descriptor fd into an iterable of buffers.\n"
4739
"\n"
4740
"The buffers should be mutable buffers accepting bytes.\n"
4741
"readv will transfer data into each buffer until it is full\n"
4742
"and then move on to the next buffer in the sequence to hold\n"
4743
"the rest of the data.\n"
4744
"\n"
4745
"readv returns the total number of bytes read,\n"
4746
"which may be less than the total capacity of all the buffers.");
4747
4748
#define OS_READV_METHODDEF    \
4749
    {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__},
4750
4751
static Py_ssize_t
4752
os_readv_impl(PyObject *module, int fd, PyObject *buffers);
4753
4754
static PyObject *
4755
os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4756
0
{
4757
0
    PyObject *return_value = NULL;
4758
0
    int fd;
4759
0
    PyObject *buffers;
4760
0
    Py_ssize_t _return_value;
4761
4762
0
    if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
4763
0
        goto exit;
4764
0
    }
4765
0
    if (PyFloat_Check(args[0])) {
4766
0
        PyErr_SetString(PyExc_TypeError,
4767
0
                        "integer argument expected, got float" );
4768
0
        goto exit;
4769
0
    }
4770
0
    fd = _PyLong_AsInt(args[0]);
4771
0
    if (fd == -1 && PyErr_Occurred()) {
4772
0
        goto exit;
4773
0
    }
4774
0
    buffers = args[1];
4775
0
    _return_value = os_readv_impl(module, fd, buffers);
4776
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4777
0
        goto exit;
4778
0
    }
4779
0
    return_value = PyLong_FromSsize_t(_return_value);
4780
4781
0
exit:
4782
0
    return return_value;
4783
0
}
4784
4785
#endif /* defined(HAVE_READV) */
4786
4787
#if defined(HAVE_PREAD)
4788
4789
PyDoc_STRVAR(os_pread__doc__,
4790
"pread($module, fd, length, offset, /)\n"
4791
"--\n"
4792
"\n"
4793
"Read a number of bytes from a file descriptor starting at a particular offset.\n"
4794
"\n"
4795
"Read length bytes from file descriptor fd, starting at offset bytes from\n"
4796
"the beginning of the file.  The file offset remains unchanged.");
4797
4798
#define OS_PREAD_METHODDEF    \
4799
    {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__},
4800
4801
static PyObject *
4802
os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
4803
4804
static PyObject *
4805
os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4806
0
{
4807
0
    PyObject *return_value = NULL;
4808
0
    int fd;
4809
0
    int length;
4810
0
    Py_off_t offset;
4811
4812
0
    if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
4813
0
        goto exit;
4814
0
    }
4815
0
    if (PyFloat_Check(args[0])) {
4816
0
        PyErr_SetString(PyExc_TypeError,
4817
0
                        "integer argument expected, got float" );
4818
0
        goto exit;
4819
0
    }
4820
0
    fd = _PyLong_AsInt(args[0]);
4821
0
    if (fd == -1 && PyErr_Occurred()) {
4822
0
        goto exit;
4823
0
    }
4824
0
    if (PyFloat_Check(args[1])) {
4825
0
        PyErr_SetString(PyExc_TypeError,
4826
0
                        "integer argument expected, got float" );
4827
0
        goto exit;
4828
0
    }
4829
0
    length = _PyLong_AsInt(args[1]);
4830
0
    if (length == -1 && PyErr_Occurred()) {
4831
0
        goto exit;
4832
0
    }
4833
0
    if (!Py_off_t_converter(args[2], &offset)) {
4834
0
        goto exit;
4835
0
    }
4836
0
    return_value = os_pread_impl(module, fd, length, offset);
4837
4838
0
exit:
4839
0
    return return_value;
4840
0
}
4841
4842
#endif /* defined(HAVE_PREAD) */
4843
4844
#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
4845
4846
PyDoc_STRVAR(os_preadv__doc__,
4847
"preadv($module, fd, buffers, offset, flags=0, /)\n"
4848
"--\n"
4849
"\n"
4850
"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
4851
"\n"
4852
"Combines the functionality of readv() and pread(). As readv(), it will\n"
4853
"transfer data into each buffer until it is full and then move on to the next\n"
4854
"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
4855
"specifies the file offset at which the input operation is to be performed. It\n"
4856
"will return the total number of bytes read (which can be less than the total\n"
4857
"capacity of all the objects).\n"
4858
"\n"
4859
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4860
"\n"
4861
"- RWF_HIPRI\n"
4862
"- RWF_NOWAIT\n"
4863
"\n"
4864
"Using non-zero flags requires Linux 4.6 or newer.");
4865
4866
#define OS_PREADV_METHODDEF    \
4867
    {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__},
4868
4869
static Py_ssize_t
4870
os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4871
               int flags);
4872
4873
static PyObject *
4874
os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4875
0
{
4876
0
    PyObject *return_value = NULL;
4877
0
    int fd;
4878
0
    PyObject *buffers;
4879
0
    Py_off_t offset;
4880
0
    int flags = 0;
4881
0
    Py_ssize_t _return_value;
4882
4883
0
    if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
4884
0
        goto exit;
4885
0
    }
4886
0
    if (PyFloat_Check(args[0])) {
4887
0
        PyErr_SetString(PyExc_TypeError,
4888
0
                        "integer argument expected, got float" );
4889
0
        goto exit;
4890
0
    }
4891
0
    fd = _PyLong_AsInt(args[0]);
4892
0
    if (fd == -1 && PyErr_Occurred()) {
4893
0
        goto exit;
4894
0
    }
4895
0
    buffers = args[1];
4896
0
    if (!Py_off_t_converter(args[2], &offset)) {
4897
0
        goto exit;
4898
0
    }
4899
0
    if (nargs < 4) {
4900
0
        goto skip_optional;
4901
0
    }
4902
0
    if (PyFloat_Check(args[3])) {
4903
0
        PyErr_SetString(PyExc_TypeError,
4904
0
                        "integer argument expected, got float" );
4905
0
        goto exit;
4906
0
    }
4907
0
    flags = _PyLong_AsInt(args[3]);
4908
0
    if (flags == -1 && PyErr_Occurred()) {
4909
0
        goto exit;
4910
0
    }
4911
0
skip_optional:
4912
0
    _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
4913
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4914
0
        goto exit;
4915
0
    }
4916
0
    return_value = PyLong_FromSsize_t(_return_value);
4917
4918
0
exit:
4919
0
    return return_value;
4920
0
}
4921
4922
#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
4923
4924
PyDoc_STRVAR(os_write__doc__,
4925
"write($module, fd, data, /)\n"
4926
"--\n"
4927
"\n"
4928
"Write a bytes object to a file descriptor.");
4929
4930
#define OS_WRITE_METHODDEF    \
4931
    {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__},
4932
4933
static Py_ssize_t
4934
os_write_impl(PyObject *module, int fd, Py_buffer *data);
4935
4936
static PyObject *
4937
os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4938
0
{
4939
0
    PyObject *return_value = NULL;
4940
0
    int fd;
4941
0
    Py_buffer data = {NULL, NULL};
4942
0
    Py_ssize_t _return_value;
4943
4944
0
    if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
4945
0
        goto exit;
4946
0
    }
4947
0
    if (PyFloat_Check(args[0])) {
4948
0
        PyErr_SetString(PyExc_TypeError,
4949
0
                        "integer argument expected, got float" );
4950
0
        goto exit;
4951
0
    }
4952
0
    fd = _PyLong_AsInt(args[0]);
4953
0
    if (fd == -1 && PyErr_Occurred()) {
4954
0
        goto exit;
4955
0
    }
4956
0
    if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
4957
0
        goto exit;
4958
0
    }
4959
0
    if (!PyBuffer_IsContiguous(&data, 'C')) {
4960
0
        _PyArg_BadArgument("write", "argument 2", "contiguous buffer", args[1]);
4961
0
        goto exit;
4962
0
    }
4963
0
    _return_value = os_write_impl(module, fd, &data);
4964
0
    if ((_return_value == -1) && PyErr_Occurred()) {
4965
0
        goto exit;
4966
0
    }
4967
0
    return_value = PyLong_FromSsize_t(_return_value);
4968
4969
0
exit:
4970
    /* Cleanup for data */
4971
0
    if (data.obj) {
4972
0
       PyBuffer_Release(&data);
4973
0
    }
4974
4975
0
    return return_value;
4976
0
}
4977
4978
#if defined(__APPLE__)
4979
4980
PyDoc_STRVAR(os__fcopyfile__doc__,
4981
"_fcopyfile($module, infd, outfd, flags, /)\n"
4982
"--\n"
4983
"\n"
4984
"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
4985
4986
#define OS__FCOPYFILE_METHODDEF    \
4987
    {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
4988
4989
static PyObject *
4990
os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
4991
4992
static PyObject *
4993
os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4994
{
4995
    PyObject *return_value = NULL;
4996
    int infd;
4997
    int outfd;
4998
    int flags;
4999
5000
    if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
5001
        goto exit;
5002
    }
5003
    if (PyFloat_Check(args[0])) {
5004
        PyErr_SetString(PyExc_TypeError,
5005
                        "integer argument expected, got float" );
5006
        goto exit;
5007
    }
5008
    infd = _PyLong_AsInt(args[0]);
5009
    if (infd == -1 && PyErr_Occurred()) {
5010
        goto exit;
5011
    }
5012
    if (PyFloat_Check(args[1])) {
5013
        PyErr_SetString(PyExc_TypeError,
5014
                        "integer argument expected, got float" );
5015
        goto exit;
5016
    }
5017
    outfd = _PyLong_AsInt(args[1]);
5018
    if (outfd == -1 && PyErr_Occurred()) {
5019
        goto exit;
5020
    }
5021
    if (PyFloat_Check(args[2])) {
5022
        PyErr_SetString(PyExc_TypeError,
5023
                        "integer argument expected, got float" );
5024
        goto exit;
5025
    }
5026
    flags = _PyLong_AsInt(args[2]);
5027
    if (flags == -1 && PyErr_Occurred()) {
5028
        goto exit;
5029
    }
5030
    return_value = os__fcopyfile_impl(module, infd, outfd, flags);
5031
5032
exit:
5033
    return return_value;
5034
}
5035
5036
#endif /* defined(__APPLE__) */
5037
5038
PyDoc_STRVAR(os_fstat__doc__,
5039
"fstat($module, /, fd)\n"
5040
"--\n"
5041
"\n"
5042
"Perform a stat system call on the given file descriptor.\n"
5043
"\n"
5044
"Like stat(), but for an open file descriptor.\n"
5045
"Equivalent to os.stat(fd).");
5046
5047
#define OS_FSTAT_METHODDEF    \
5048
    {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
5049
5050
static PyObject *
5051
os_fstat_impl(PyObject *module, int fd);
5052
5053
static PyObject *
5054
os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5055
0
{
5056
0
    PyObject *return_value = NULL;
5057
0
    static const char * const _keywords[] = {"fd", NULL};
5058
0
    static _PyArg_Parser _parser = {NULL, _keywords, "fstat", 0};
5059
0
    PyObject *argsbuf[1];
5060
0
    int fd;
5061
5062
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
5063
0
    if (!args) {
5064
0
        goto exit;
5065
0
    }
5066
0
    if (PyFloat_Check(args[0])) {
5067
0
        PyErr_SetString(PyExc_TypeError,
5068
0
                        "integer argument expected, got float" );
5069
0
        goto exit;
5070
0
    }
5071
0
    fd = _PyLong_AsInt(args[0]);
5072
0
    if (fd == -1 && PyErr_Occurred()) {
5073
0
        goto exit;
5074
0
    }
5075
0
    return_value = os_fstat_impl(module, fd);
5076
5077
0
exit:
5078
0
    return return_value;
5079
0
}
5080
5081
PyDoc_STRVAR(os_isatty__doc__,
5082
"isatty($module, fd, /)\n"
5083
"--\n"
5084
"\n"
5085
"Return True if the fd is connected to a terminal.\n"
5086
"\n"
5087
"Return True if the file descriptor is an open file descriptor\n"
5088
"connected to the slave end of a terminal.");
5089
5090
#define OS_ISATTY_METHODDEF    \
5091
    {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
5092
5093
static int
5094
os_isatty_impl(PyObject *module, int fd);
5095
5096
static PyObject *
5097
os_isatty(PyObject *module, PyObject *arg)
5098
0
{
5099
0
    PyObject *return_value = NULL;
5100
0
    int fd;
5101
0
    int _return_value;
5102
5103
0
    if (PyFloat_Check(arg)) {
5104
0
        PyErr_SetString(PyExc_TypeError,
5105
0
                        "integer argument expected, got float" );
5106
0
        goto exit;
5107
0
    }
5108
0
    fd = _PyLong_AsInt(arg);
5109
0
    if (fd == -1 && PyErr_Occurred()) {
5110
0
        goto exit;
5111
0
    }
5112
0
    _return_value = os_isatty_impl(module, fd);
5113
0
    if ((_return_value == -1) && PyErr_Occurred()) {
5114
0
        goto exit;
5115
0
    }
5116
0
    return_value = PyBool_FromLong((long)_return_value);
5117
5118
0
exit:
5119
0
    return return_value;
5120
0
}
5121
5122
#if defined(HAVE_PIPE)
5123
5124
PyDoc_STRVAR(os_pipe__doc__,
5125
"pipe($module, /)\n"
5126
"--\n"
5127
"\n"
5128
"Create a pipe.\n"
5129
"\n"
5130
"Returns a tuple of two file descriptors:\n"
5131
"  (read_fd, write_fd)");
5132
5133
#define OS_PIPE_METHODDEF    \
5134
    {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
5135
5136
static PyObject *
5137
os_pipe_impl(PyObject *module);
5138
5139
static PyObject *
5140
os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
5141
0
{
5142
0
    return os_pipe_impl(module);
5143
0
}
5144
5145
#endif /* defined(HAVE_PIPE) */
5146
5147
#if defined(HAVE_PIPE2)
5148
5149
PyDoc_STRVAR(os_pipe2__doc__,
5150
"pipe2($module, flags, /)\n"
5151
"--\n"
5152
"\n"
5153
"Create a pipe with flags set atomically.\n"
5154
"\n"
5155
"Returns a tuple of two file descriptors:\n"
5156
"  (read_fd, write_fd)\n"
5157
"\n"
5158
"flags can be constructed by ORing together one or more of these values:\n"
5159
"O_NONBLOCK, O_CLOEXEC.");
5160
5161
#define OS_PIPE2_METHODDEF    \
5162
    {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
5163
5164
static PyObject *
5165
os_pipe2_impl(PyObject *module, int flags);
5166
5167
static PyObject *
5168
os_pipe2(PyObject *module, PyObject *arg)
5169
0
{
5170
0
    PyObject *return_value = NULL;
5171
0
    int flags;
5172
5173
0
    if (PyFloat_Check(arg)) {
5174
0
        PyErr_SetString(PyExc_TypeError,
5175
0
                        "integer argument expected, got float" );
5176
0
        goto exit;
5177
0
    }
5178
0
    flags = _PyLong_AsInt(arg);
5179
0
    if (flags == -1 && PyErr_Occurred()) {
5180
0
        goto exit;
5181
0
    }
5182
0
    return_value = os_pipe2_impl(module, flags);
5183
5184
0
exit:
5185
0
    return return_value;
5186
0
}
5187
5188
#endif /* defined(HAVE_PIPE2) */
5189
5190
#if defined(HAVE_WRITEV)
5191
5192
PyDoc_STRVAR(os_writev__doc__,
5193
"writev($module, fd, buffers, /)\n"
5194
"--\n"
5195
"\n"
5196
"Iterate over buffers, and write the contents of each to a file descriptor.\n"
5197
"\n"
5198
"Returns the total number of bytes written.\n"
5199
"buffers must be a sequence of bytes-like objects.");
5200
5201
#define OS_WRITEV_METHODDEF    \
5202
    {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__},
5203
5204
static Py_ssize_t
5205
os_writev_impl(PyObject *module, int fd, PyObject *buffers);
5206
5207
static PyObject *
5208
os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5209
0
{
5210
0
    PyObject *return_value = NULL;
5211
0
    int fd;
5212
0
    PyObject *buffers;
5213
0
    Py_ssize_t _return_value;
5214
5215
0
    if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
5216
0
        goto exit;
5217
0
    }
5218
0
    if (PyFloat_Check(args[0])) {
5219
0
        PyErr_SetString(PyExc_TypeError,
5220
0
                        "integer argument expected, got float" );
5221
0
        goto exit;
5222
0
    }
5223
0
    fd = _PyLong_AsInt(args[0]);
5224
0
    if (fd == -1 && PyErr_Occurred()) {
5225
0
        goto exit;
5226
0
    }
5227
0
    buffers = args[1];
5228
0
    _return_value = os_writev_impl(module, fd, buffers);
5229
0
    if ((_return_value == -1) && PyErr_Occurred()) {
5230
0
        goto exit;
5231
0
    }
5232
0
    return_value = PyLong_FromSsize_t(_return_value);
5233
5234
0
exit:
5235
0
    return return_value;
5236
0
}
5237
5238
#endif /* defined(HAVE_WRITEV) */
5239
5240
#if defined(HAVE_PWRITE)
5241
5242
PyDoc_STRVAR(os_pwrite__doc__,
5243
"pwrite($module, fd, buffer, offset, /)\n"
5244
"--\n"
5245
"\n"
5246
"Write bytes to a file descriptor starting at a particular offset.\n"
5247
"\n"
5248
"Write buffer to fd, starting at offset bytes from the beginning of\n"
5249
"the file.  Returns the number of bytes writte.  Does not change the\n"
5250
"current file offset.");
5251
5252
#define OS_PWRITE_METHODDEF    \
5253
    {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__},
5254
5255
static Py_ssize_t
5256
os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
5257
5258
static PyObject *
5259
os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5260
0
{
5261
0
    PyObject *return_value = NULL;
5262
0
    int fd;
5263
0
    Py_buffer buffer = {NULL, NULL};
5264
0
    Py_off_t offset;
5265
0
    Py_ssize_t _return_value;
5266
5267
0
    if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
5268
0
        goto exit;
5269
0
    }
5270
0
    if (PyFloat_Check(args[0])) {
5271
0
        PyErr_SetString(PyExc_TypeError,
5272
0
                        "integer argument expected, got float" );
5273
0
        goto exit;
5274
0
    }
5275
0
    fd = _PyLong_AsInt(args[0]);
5276
0
    if (fd == -1 && PyErr_Occurred()) {
5277
0
        goto exit;
5278
0
    }
5279
0
    if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
5280
0
        goto exit;
5281
0
    }
5282
0
    if (!PyBuffer_IsContiguous(&buffer, 'C')) {
5283
0
        _PyArg_BadArgument("pwrite", "argument 2", "contiguous buffer", args[1]);
5284
0
        goto exit;
5285
0
    }
5286
0
    if (!Py_off_t_converter(args[2], &offset)) {
5287
0
        goto exit;
5288
0
    }
5289
0
    _return_value = os_pwrite_impl(module, fd, &buffer, offset);
5290
0
    if ((_return_value == -1) && PyErr_Occurred()) {
5291
0
        goto exit;
5292
0
    }
5293
0
    return_value = PyLong_FromSsize_t(_return_value);
5294
5295
0
exit:
5296
    /* Cleanup for buffer */
5297
0
    if (buffer.obj) {
5298
0
       PyBuffer_Release(&buffer);
5299
0
    }
5300
5301
0
    return return_value;
5302
0
}
5303
5304
#endif /* defined(HAVE_PWRITE) */
5305
5306
#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
5307
5308
PyDoc_STRVAR(os_pwritev__doc__,
5309
"pwritev($module, fd, buffers, offset, flags=0, /)\n"
5310
"--\n"
5311
"\n"
5312
"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
5313
"\n"
5314
"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
5315
"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
5316
"buffer is written before proceeding to second, and so on. The operating system may\n"
5317
"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
5318
"This function writes the contents of each object to the file descriptor and returns\n"
5319
"the total number of bytes written.\n"
5320
"\n"
5321
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
5322
"\n"
5323
"- RWF_DSYNC\n"
5324
"- RWF_SYNC\n"
5325
"\n"
5326
"Using non-zero flags requires Linux 4.7 or newer.");
5327
5328
#define OS_PWRITEV_METHODDEF    \
5329
    {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__},
5330
5331
static Py_ssize_t
5332
os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
5333
                int flags);
5334
5335
static PyObject *
5336
os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5337
0
{
5338
0
    PyObject *return_value = NULL;
5339
0
    int fd;
5340
0
    PyObject *buffers;
5341
0
    Py_off_t offset;
5342
0
    int flags = 0;
5343
0
    Py_ssize_t _return_value;
5344
5345
0
    if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
5346
0
        goto exit;
5347
0
    }
5348
0
    if (PyFloat_Check(args[0])) {
5349
0
        PyErr_SetString(PyExc_TypeError,
5350
0
                        "integer argument expected, got float" );
5351
0
        goto exit;
5352
0
    }
5353
0
    fd = _PyLong_AsInt(args[0]);
5354
0
    if (fd == -1 && PyErr_Occurred()) {
5355
0
        goto exit;
5356
0
    }
5357
0
    buffers = args[1];
5358
0
    if (!Py_off_t_converter(args[2], &offset)) {
5359
0
        goto exit;
5360
0
    }
5361
0
    if (nargs < 4) {
5362
0
        goto skip_optional;
5363
0
    }
5364
0
    if (PyFloat_Check(args[3])) {
5365
0
        PyErr_SetString(PyExc_TypeError,
5366
0
                        "integer argument expected, got float" );
5367
0
        goto exit;
5368
0
    }
5369
0
    flags = _PyLong_AsInt(args[3]);
5370
0
    if (flags == -1 && PyErr_Occurred()) {
5371
0
        goto exit;
5372
0
    }
5373
0
skip_optional:
5374
0
    _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
5375
0
    if ((_return_value == -1) && PyErr_Occurred()) {
5376
0
        goto exit;
5377
0
    }
5378
0
    return_value = PyLong_FromSsize_t(_return_value);
5379
5380
0
exit:
5381
0
    return return_value;
5382
0
}
5383
5384
#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
5385
5386
#if defined(HAVE_COPY_FILE_RANGE)
5387
5388
PyDoc_STRVAR(os_copy_file_range__doc__,
5389
"copy_file_range($module, /, src, dst, count, offset_src=None,\n"
5390
"                offset_dst=None)\n"
5391
"--\n"
5392
"\n"
5393
"Copy count bytes from one file descriptor to another.\n"
5394
"\n"
5395
"  src\n"
5396
"    Source file descriptor.\n"
5397
"  dst\n"
5398
"    Destination file descriptor.\n"
5399
"  count\n"
5400
"    Number of bytes to copy.\n"
5401
"  offset_src\n"
5402
"    Starting offset in src.\n"
5403
"  offset_dst\n"
5404
"    Starting offset in dst.\n"
5405
"\n"
5406
"If offset_src is None, then src is read from the current position;\n"
5407
"respectively for offset_dst.");
5408
5409
#define OS_COPY_FILE_RANGE_METHODDEF    \
5410
    {"copy_file_range", (PyCFunction)(void(*)(void))os_copy_file_range, METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__},
5411
5412
static PyObject *
5413
os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count,
5414
                        PyObject *offset_src, PyObject *offset_dst);
5415
5416
static PyObject *
5417
os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5418
0
{
5419
0
    PyObject *return_value = NULL;
5420
0
    static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL};
5421
0
    static _PyArg_Parser _parser = {NULL, _keywords, "copy_file_range", 0};
5422
0
    PyObject *argsbuf[5];
5423
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
5424
0
    int src;
5425
0
    int dst;
5426
0
    Py_ssize_t count;
5427
0
    PyObject *offset_src = Py_None;
5428
0
    PyObject *offset_dst = Py_None;
5429
5430
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 5, 0, argsbuf);
5431
0
    if (!args) {
5432
0
        goto exit;
5433
0
    }
5434
0
    if (PyFloat_Check(args[0])) {
5435
0
        PyErr_SetString(PyExc_TypeError,
5436
0
                        "integer argument expected, got float" );
5437
0
        goto exit;
5438
0
    }
5439
0
    src = _PyLong_AsInt(args[0]);
5440
0
    if (src == -1 && PyErr_Occurred()) {
5441
0
        goto exit;
5442
0
    }
5443
0
    if (PyFloat_Check(args[1])) {
5444
0
        PyErr_SetString(PyExc_TypeError,
5445
0
                        "integer argument expected, got float" );
5446
0
        goto exit;
5447
0
    }
5448
0
    dst = _PyLong_AsInt(args[1]);
5449
0
    if (dst == -1 && PyErr_Occurred()) {
5450
0
        goto exit;
5451
0
    }
5452
0
    if (PyFloat_Check(args[2])) {
5453
0
        PyErr_SetString(PyExc_TypeError,
5454
0
                        "integer argument expected, got float" );
5455
0
        goto exit;
5456
0
    }
5457
0
    {
5458
0
        Py_ssize_t ival = -1;
5459
0
        PyObject *iobj = PyNumber_Index(args[2]);
5460
0
        if (iobj != NULL) {
5461
0
            ival = PyLong_AsSsize_t(iobj);
5462
0
            Py_DECREF(iobj);
5463
0
        }
5464
0
        if (ival == -1 && PyErr_Occurred()) {
5465
0
            goto exit;
5466
0
        }
5467
0
        count = ival;
5468
0
    }
5469
0
    if (!noptargs) {
5470
0
        goto skip_optional_pos;
5471
0
    }
5472
0
    if (args[3]) {
5473
0
        offset_src = args[3];
5474
0
        if (!--noptargs) {
5475
0
            goto skip_optional_pos;
5476
0
        }
5477
0
    }
5478
0
    offset_dst = args[4];
5479
0
skip_optional_pos:
5480
0
    return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst);
5481
5482
0
exit:
5483
0
    return return_value;
5484
0
}
5485
5486
#endif /* defined(HAVE_COPY_FILE_RANGE) */
5487
5488
#if defined(HAVE_MKFIFO)
5489
5490
PyDoc_STRVAR(os_mkfifo__doc__,
5491
"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
5492
"--\n"
5493
"\n"
5494
"Create a \"fifo\" (a POSIX named pipe).\n"
5495
"\n"
5496
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
5497
"  and path should be relative; path will then be relative to that directory.\n"
5498
"dir_fd may not be implemented on your platform.\n"
5499
"  If it is unavailable, using it will raise a NotImplementedError.");
5500
5501
#define OS_MKFIFO_METHODDEF    \
5502
    {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
5503
5504
static PyObject *
5505
os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
5506
5507
static PyObject *
5508
os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5509
0
{
5510
0
    PyObject *return_value = NULL;
5511
0
    static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
5512
0
    static _PyArg_Parser _parser = {NULL, _keywords, "mkfifo", 0};
5513
0
    PyObject *argsbuf[3];
5514
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
5515
0
    path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
5516
0
    int mode = 438;
5517
0
    int dir_fd = DEFAULT_DIR_FD;
5518
5519
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
5520
0
    if (!args) {
5521
0
        goto exit;
5522
0
    }
5523
0
    if (!path_converter(args[0], &path)) {
5524
0
        goto exit;
5525
0
    }
5526
0
    if (!noptargs) {
5527
0
        goto skip_optional_pos;
5528
0
    }
5529
0
    if (args[1]) {
5530
0
        if (PyFloat_Check(args[1])) {
5531
0
            PyErr_SetString(PyExc_TypeError,
5532
0
                            "integer argument expected, got float" );
5533
0
            goto exit;
5534
0
        }
5535
0
        mode = _PyLong_AsInt(args[1]);
5536
0
        if (mode == -1 && PyErr_Occurred()) {
5537
0
            goto exit;
5538
0
        }
5539
0
        if (!--noptargs) {
5540
0
            goto skip_optional_pos;
5541
0
        }
5542
0
    }
5543
0
skip_optional_pos:
5544
0
    if (!noptargs) {
5545
0
        goto skip_optional_kwonly;
5546
0
    }
5547
0
    if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
5548
0
        goto exit;
5549
0
    }
5550
0
skip_optional_kwonly:
5551
0
    return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
5552
5553
0
exit:
5554
    /* Cleanup for path */
5555
0
    path_cleanup(&path);
5556
5557
0
    return return_value;
5558
0
}
5559
5560
#endif /* defined(HAVE_MKFIFO) */
5561
5562
#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
5563
5564
PyDoc_STRVAR(os_mknod__doc__,
5565
"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
5566
"--\n"
5567
"\n"
5568
"Create a node in the file system.\n"
5569
"\n"
5570
"Create a node in the file system (file, device special file or named pipe)\n"
5571
"at path.  mode specifies both the permissions to use and the\n"
5572
"type of node to be created, being combined (bitwise OR) with one of\n"
5573
"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO.  If S_IFCHR or S_IFBLK is set on mode,\n"
5574
"device defines the newly created device special file (probably using\n"
5575
"os.makedev()).  Otherwise device is ignored.\n"
5576
"\n"
5577
"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
5578
"  and path should be relative; path will then be relative to that directory.\n"
5579
"dir_fd may not be implemented on your platform.\n"
5580
"  If it is unavailable, using it will raise a NotImplementedError.");
5581
5582
#define OS_MKNOD_METHODDEF    \
5583
    {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
5584
5585
static PyObject *
5586
os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
5587
              int dir_fd);
5588
5589
static PyObject *
5590
os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5591
0
{
5592
0
    PyObject *return_value = NULL;
5593
0
    static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
5594
0
    static _PyArg_Parser _parser = {NULL, _keywords, "mknod", 0};
5595
0
    PyObject *argsbuf[4];
5596
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
5597
0
    path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
5598
0
    int mode = 384;
5599
0
    dev_t device = 0;
5600
0
    int dir_fd = DEFAULT_DIR_FD;
5601
5602
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
5603
0
    if (!args) {
5604
0
        goto exit;
5605
0
    }
5606
0
    if (!path_converter(args[0], &path)) {
5607
0
        goto exit;
5608
0
    }
5609
0
    if (!noptargs) {
5610
0
        goto skip_optional_pos;
5611
0
    }
5612
0
    if (args[1]) {
5613
0
        if (PyFloat_Check(args[1])) {
5614
0
            PyErr_SetString(PyExc_TypeError,
5615
0
                            "integer argument expected, got float" );
5616
0
            goto exit;
5617
0
        }
5618
0
        mode = _PyLong_AsInt(args[1]);
5619
0
        if (mode == -1 && PyErr_Occurred()) {
5620
0
            goto exit;
5621
0
        }
5622
0
        if (!--noptargs) {
5623
0
            goto skip_optional_pos;
5624
0
        }
5625
0
    }
5626
0
    if (args[2]) {
5627
0
        if (!_Py_Dev_Converter(args[2], &device)) {
5628
0
            goto exit;
5629
0
        }
5630
0
        if (!--noptargs) {
5631
0
            goto skip_optional_pos;
5632
0
        }
5633
0
    }
5634
0
skip_optional_pos:
5635
0
    if (!noptargs) {
5636
0
        goto skip_optional_kwonly;
5637
0
    }
5638
0
    if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
5639
0
        goto exit;
5640
0
    }
5641
0
skip_optional_kwonly:
5642
0
    return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
5643
5644
0
exit:
5645
    /* Cleanup for path */
5646
0
    path_cleanup(&path);
5647
5648
0
    return return_value;
5649
0
}
5650
5651
#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
5652
5653
#if defined(HAVE_DEVICE_MACROS)
5654
5655
PyDoc_STRVAR(os_major__doc__,
5656
"major($module, device, /)\n"
5657
"--\n"
5658
"\n"
5659
"Extracts a device major number from a raw device number.");
5660
5661
#define OS_MAJOR_METHODDEF    \
5662
    {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
5663
5664
static unsigned int
5665
os_major_impl(PyObject *module, dev_t device);
5666
5667
static PyObject *
5668
os_major(PyObject *module, PyObject *arg)
5669
0
{
5670
0
    PyObject *return_value = NULL;
5671
0
    dev_t device;
5672
0
    unsigned int _return_value;
5673
5674
0
    if (!_Py_Dev_Converter(arg, &device)) {
5675
0
        goto exit;
5676
0
    }
5677
0
    _return_value = os_major_impl(module, device);
5678
0
    if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
5679
0
        goto exit;
5680
0
    }
5681
0
    return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
5682
5683
0
exit:
5684
0
    return return_value;
5685
0
}
5686
5687
#endif /* defined(HAVE_DEVICE_MACROS) */
5688
5689
#if defined(HAVE_DEVICE_MACROS)
5690
5691
PyDoc_STRVAR(os_minor__doc__,
5692
"minor($module, device, /)\n"
5693
"--\n"
5694
"\n"
5695
"Extracts a device minor number from a raw device number.");
5696
5697
#define OS_MINOR_METHODDEF    \
5698
    {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
5699
5700
static unsigned int
5701
os_minor_impl(PyObject *module, dev_t device);
5702
5703
static PyObject *
5704
os_minor(PyObject *module, PyObject *arg)
5705
0
{
5706
0
    PyObject *return_value = NULL;
5707
0
    dev_t device;
5708
0
    unsigned int _return_value;
5709
5710
0
    if (!_Py_Dev_Converter(arg, &device)) {
5711
0
        goto exit;
5712
0
    }
5713
0
    _return_value = os_minor_impl(module, device);
5714
0
    if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
5715
0
        goto exit;
5716
0
    }
5717
0
    return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
5718
5719
0
exit:
5720
0
    return return_value;
5721
0
}
5722
5723
#endif /* defined(HAVE_DEVICE_MACROS) */
5724
5725
#if defined(HAVE_DEVICE_MACROS)
5726
5727
PyDoc_STRVAR(os_makedev__doc__,
5728
"makedev($module, major, minor, /)\n"
5729
"--\n"
5730
"\n"
5731
"Composes a raw device number from the major and minor device numbers.");
5732
5733
#define OS_MAKEDEV_METHODDEF    \
5734
    {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__},
5735
5736
static dev_t
5737
os_makedev_impl(PyObject *module, int major, int minor);
5738
5739
static PyObject *
5740
os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5741
0
{
5742
0
    PyObject *return_value = NULL;
5743
0
    int major;
5744
0
    int minor;
5745
0
    dev_t _return_value;
5746
5747
0
    if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
5748
0
        goto exit;
5749
0
    }
5750
0
    if (PyFloat_Check(args[0])) {
5751
0
        PyErr_SetString(PyExc_TypeError,
5752
0
                        "integer argument expected, got float" );
5753
0
        goto exit;
5754
0
    }
5755
0
    major = _PyLong_AsInt(args[0]);
5756
0
    if (major == -1 && PyErr_Occurred()) {
5757
0
        goto exit;
5758
0
    }
5759
0
    if (PyFloat_Check(args[1])) {
5760
0
        PyErr_SetString(PyExc_TypeError,
5761
0
                        "integer argument expected, got float" );
5762
0
        goto exit;
5763
0
    }
5764
0
    minor = _PyLong_AsInt(args[1]);
5765
0
    if (minor == -1 && PyErr_Occurred()) {
5766
0
        goto exit;
5767
0
    }
5768
0
    _return_value = os_makedev_impl(module, major, minor);
5769
0
    if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
5770
0
        goto exit;
5771
0
    }
5772
0
    return_value = _PyLong_FromDev(_return_value);
5773
5774
0
exit:
5775
0
    return return_value;
5776
0
}
5777
5778
#endif /* defined(HAVE_DEVICE_MACROS) */
5779
5780
#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
5781
5782
PyDoc_STRVAR(os_ftruncate__doc__,
5783
"ftruncate($module, fd, length, /)\n"
5784
"--\n"
5785
"\n"
5786
"Truncate a file, specified by file descriptor, to a specific length.");
5787
5788
#define OS_FTRUNCATE_METHODDEF    \
5789
    {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
5790
5791
static PyObject *
5792
os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
5793
5794
static PyObject *
5795
os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5796
0
{
5797
0
    PyObject *return_value = NULL;
5798
0
    int fd;
5799
0
    Py_off_t length;
5800
5801
0
    if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
5802
0
        goto exit;
5803
0
    }
5804
0
    if (PyFloat_Check(args[0])) {
5805
0
        PyErr_SetString(PyExc_TypeError,
5806
0
                        "integer argument expected, got float" );
5807
0
        goto exit;
5808
0
    }
5809
0
    fd = _PyLong_AsInt(args[0]);
5810
0
    if (fd == -1 && PyErr_Occurred()) {
5811
0
        goto exit;
5812
0
    }
5813
0
    if (!Py_off_t_converter(args[1], &length)) {
5814
0
        goto exit;
5815
0
    }
5816
0
    return_value = os_ftruncate_impl(module, fd, length);
5817
5818
0
exit:
5819
0
    return return_value;
5820
0
}
5821
5822
#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
5823
5824
#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
5825
5826
PyDoc_STRVAR(os_truncate__doc__,
5827
"truncate($module, /, path, length)\n"
5828
"--\n"
5829
"\n"
5830
"Truncate a file, specified by path, to a specific length.\n"
5831
"\n"
5832
"On some platforms, path may also be specified as an open file descriptor.\n"
5833
"  If this functionality is unavailable, using it raises an exception.");
5834
5835
#define OS_TRUNCATE_METHODDEF    \
5836
    {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
5837
5838
static PyObject *
5839
os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
5840
5841
static PyObject *
5842
os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5843
0
{
5844
0
    PyObject *return_value = NULL;
5845
0
    static const char * const _keywords[] = {"path", "length", NULL};
5846
0
    static _PyArg_Parser _parser = {NULL, _keywords, "truncate", 0};
5847
0
    PyObject *argsbuf[2];
5848
0
    path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
5849
0
    Py_off_t length;
5850
5851
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
5852
0
    if (!args) {
5853
0
        goto exit;
5854
0
    }
5855
0
    if (!path_converter(args[0], &path)) {
5856
0
        goto exit;
5857
0
    }
5858
0
    if (!Py_off_t_converter(args[1], &length)) {
5859
0
        goto exit;
5860
0
    }
5861
0
    return_value = os_truncate_impl(module, &path, length);
5862
5863
0
exit:
5864
    /* Cleanup for path */
5865
0
    path_cleanup(&path);
5866
5867
0
    return return_value;
5868
0
}
5869
5870
#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
5871
5872
#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
5873
5874
PyDoc_STRVAR(os_posix_fallocate__doc__,
5875
"posix_fallocate($module, fd, offset, length, /)\n"
5876
"--\n"
5877
"\n"
5878
"Ensure a file has allocated at least a particular number of bytes on disk.\n"
5879
"\n"
5880
"Ensure that the file specified by fd encompasses a range of bytes\n"
5881
"starting at offset bytes from the beginning and continuing for length bytes.");
5882
5883
#define OS_POSIX_FALLOCATE_METHODDEF    \
5884
    {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
5885
5886
static PyObject *
5887
os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
5888
                        Py_off_t length);
5889
5890
static PyObject *
5891
os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5892
0
{
5893
0
    PyObject *return_value = NULL;
5894
0
    int fd;
5895
0
    Py_off_t offset;
5896
0
    Py_off_t length;
5897
5898
0
    if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
5899
0
        goto exit;
5900
0
    }
5901
0
    if (PyFloat_Check(args[0])) {
5902
0
        PyErr_SetString(PyExc_TypeError,
5903
0
                        "integer argument expected, got float" );
5904
0
        goto exit;
5905
0
    }
5906
0
    fd = _PyLong_AsInt(args[0]);
5907
0
    if (fd == -1 && PyErr_Occurred()) {
5908
0
        goto exit;
5909
0
    }
5910
0
    if (!Py_off_t_converter(args[1], &offset)) {
5911
0
        goto exit;
5912
0
    }
5913
0
    if (!Py_off_t_converter(args[2], &length)) {
5914
0
        goto exit;
5915
0
    }
5916
0
    return_value = os_posix_fallocate_impl(module, fd, offset, length);
5917
5918
0
exit:
5919
0
    return return_value;
5920
0
}
5921
5922
#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
5923
5924
#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
5925
5926
PyDoc_STRVAR(os_posix_fadvise__doc__,
5927
"posix_fadvise($module, fd, offset, length, advice, /)\n"
5928
"--\n"
5929
"\n"
5930
"Announce an intention to access data in a specific pattern.\n"
5931
"\n"
5932
"Announce an intention to access data in a specific pattern, thus allowing\n"
5933
"the kernel to make optimizations.\n"
5934
"The advice applies to the region of the file specified by fd starting at\n"
5935
"offset and continuing for length bytes.\n"
5936
"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
5937
"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
5938
"POSIX_FADV_DONTNEED.");
5939
5940
#define OS_POSIX_FADVISE_METHODDEF    \
5941
    {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
5942
5943
static PyObject *
5944
os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
5945
                      Py_off_t length, int advice);
5946
5947
static PyObject *
5948
os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5949
0
{
5950
0
    PyObject *return_value = NULL;
5951
0
    int fd;
5952
0
    Py_off_t offset;
5953
0
    Py_off_t length;
5954
0
    int advice;
5955
5956
0
    if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
5957
0
        goto exit;
5958
0
    }
5959
0
    if (PyFloat_Check(args[0])) {
5960
0
        PyErr_SetString(PyExc_TypeError,
5961
0
                        "integer argument expected, got float" );
5962
0
        goto exit;
5963
0
    }
5964
0
    fd = _PyLong_AsInt(args[0]);
5965
0
    if (fd == -1 && PyErr_Occurred()) {
5966
0
        goto exit;
5967
0
    }
5968
0
    if (!Py_off_t_converter(args[1], &offset)) {
5969
0
        goto exit;
5970
0
    }
5971
0
    if (!Py_off_t_converter(args[2], &length)) {
5972
0
        goto exit;
5973
0
    }
5974
0
    if (PyFloat_Check(args[3])) {
5975
0
        PyErr_SetString(PyExc_TypeError,
5976
0
                        "integer argument expected, got float" );
5977
0
        goto exit;
5978
0
    }
5979
0
    advice = _PyLong_AsInt(args[3]);
5980
0
    if (advice == -1 && PyErr_Occurred()) {
5981
0
        goto exit;
5982
0
    }
5983
0
    return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
5984
5985
0
exit:
5986
0
    return return_value;
5987
0
}
5988
5989
#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
5990
5991
#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
5992
5993
PyDoc_STRVAR(os_putenv__doc__,
5994
"putenv($module, name, value, /)\n"
5995
"--\n"
5996
"\n"
5997
"Change or add an environment variable.");
5998
5999
#define OS_PUTENV_METHODDEF    \
6000
    {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
6001
6002
static PyObject *
6003
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
6004
6005
static PyObject *
6006
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6007
{
6008
    PyObject *return_value = NULL;
6009
    PyObject *name;
6010
    PyObject *value;
6011
6012
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
6013
        goto exit;
6014
    }
6015
    if (!PyUnicode_Check(args[0])) {
6016
        _PyArg_BadArgument("putenv", "argument 1", "str", args[0]);
6017
        goto exit;
6018
    }
6019
    if (PyUnicode_READY(args[0]) == -1) {
6020
        goto exit;
6021
    }
6022
    name = args[0];
6023
    if (!PyUnicode_Check(args[1])) {
6024
        _PyArg_BadArgument("putenv", "argument 2", "str", args[1]);
6025
        goto exit;
6026
    }
6027
    if (PyUnicode_READY(args[1]) == -1) {
6028
        goto exit;
6029
    }
6030
    value = args[1];
6031
    return_value = os_putenv_impl(module, name, value);
6032
6033
exit:
6034
    return return_value;
6035
}
6036
6037
#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
6038
6039
#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
6040
6041
PyDoc_STRVAR(os_putenv__doc__,
6042
"putenv($module, name, value, /)\n"
6043
"--\n"
6044
"\n"
6045
"Change or add an environment variable.");
6046
6047
#define OS_PUTENV_METHODDEF    \
6048
    {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
6049
6050
static PyObject *
6051
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
6052
6053
static PyObject *
6054
os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6055
0
{
6056
0
    PyObject *return_value = NULL;
6057
0
    PyObject *name = NULL;
6058
0
    PyObject *value = NULL;
6059
6060
0
    if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
6061
0
        goto exit;
6062
0
    }
6063
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
6064
0
        goto exit;
6065
0
    }
6066
0
    if (!PyUnicode_FSConverter(args[1], &value)) {
6067
0
        goto exit;
6068
0
    }
6069
0
    return_value = os_putenv_impl(module, name, value);
6070
6071
0
exit:
6072
    /* Cleanup for name */
6073
0
    Py_XDECREF(name);
6074
    /* Cleanup for value */
6075
0
    Py_XDECREF(value);
6076
6077
0
    return return_value;
6078
0
}
6079
6080
#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
6081
6082
#if defined(HAVE_UNSETENV)
6083
6084
PyDoc_STRVAR(os_unsetenv__doc__,
6085
"unsetenv($module, name, /)\n"
6086
"--\n"
6087
"\n"
6088
"Delete an environment variable.");
6089
6090
#define OS_UNSETENV_METHODDEF    \
6091
    {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
6092
6093
static PyObject *
6094
os_unsetenv_impl(PyObject *module, PyObject *name);
6095
6096
static PyObject *
6097
os_unsetenv(PyObject *module, PyObject *arg)
6098
0
{
6099
0
    PyObject *return_value = NULL;
6100
0
    PyObject *name = NULL;
6101
6102
0
    if (!PyUnicode_FSConverter(arg, &name)) {
6103
0
        goto exit;
6104
0
    }
6105
0
    return_value = os_unsetenv_impl(module, name);
6106
6107
0
exit:
6108
    /* Cleanup for name */
6109
0
    Py_XDECREF(name);
6110
6111
0
    return return_value;
6112
0
}
6113
6114
#endif /* defined(HAVE_UNSETENV) */
6115
6116
PyDoc_STRVAR(os_strerror__doc__,
6117
"strerror($module, code, /)\n"
6118
"--\n"
6119
"\n"
6120
"Translate an error code to a message string.");
6121
6122
#define OS_STRERROR_METHODDEF    \
6123
    {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
6124
6125
static PyObject *
6126
os_strerror_impl(PyObject *module, int code);
6127
6128
static PyObject *
6129
os_strerror(PyObject *module, PyObject *arg)
6130
0
{
6131
0
    PyObject *return_value = NULL;
6132
0
    int code;
6133
6134
0
    if (PyFloat_Check(arg)) {
6135
0
        PyErr_SetString(PyExc_TypeError,
6136
0
                        "integer argument expected, got float" );
6137
0
        goto exit;
6138
0
    }
6139
0
    code = _PyLong_AsInt(arg);
6140
0
    if (code == -1 && PyErr_Occurred()) {
6141
0
        goto exit;
6142
0
    }
6143
0
    return_value = os_strerror_impl(module, code);
6144
6145
0
exit:
6146
0
    return return_value;
6147
0
}
6148
6149
#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
6150
6151
PyDoc_STRVAR(os_WCOREDUMP__doc__,
6152
"WCOREDUMP($module, status, /)\n"
6153
"--\n"
6154
"\n"
6155
"Return True if the process returning status was dumped to a core file.");
6156
6157
#define OS_WCOREDUMP_METHODDEF    \
6158
    {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
6159
6160
static int
6161
os_WCOREDUMP_impl(PyObject *module, int status);
6162
6163
static PyObject *
6164
os_WCOREDUMP(PyObject *module, PyObject *arg)
6165
0
{
6166
0
    PyObject *return_value = NULL;
6167
0
    int status;
6168
0
    int _return_value;
6169
6170
0
    if (PyFloat_Check(arg)) {
6171
0
        PyErr_SetString(PyExc_TypeError,
6172
0
                        "integer argument expected, got float" );
6173
0
        goto exit;
6174
0
    }
6175
0
    status = _PyLong_AsInt(arg);
6176
0
    if (status == -1 && PyErr_Occurred()) {
6177
0
        goto exit;
6178
0
    }
6179
0
    _return_value = os_WCOREDUMP_impl(module, status);
6180
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6181
0
        goto exit;
6182
0
    }
6183
0
    return_value = PyBool_FromLong((long)_return_value);
6184
6185
0
exit:
6186
0
    return return_value;
6187
0
}
6188
6189
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
6190
6191
#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
6192
6193
PyDoc_STRVAR(os_WIFCONTINUED__doc__,
6194
"WIFCONTINUED($module, /, status)\n"
6195
"--\n"
6196
"\n"
6197
"Return True if a particular process was continued from a job control stop.\n"
6198
"\n"
6199
"Return True if the process returning status was continued from a\n"
6200
"job control stop.");
6201
6202
#define OS_WIFCONTINUED_METHODDEF    \
6203
    {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
6204
6205
static int
6206
os_WIFCONTINUED_impl(PyObject *module, int status);
6207
6208
static PyObject *
6209
os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6210
0
{
6211
0
    PyObject *return_value = NULL;
6212
0
    static const char * const _keywords[] = {"status", NULL};
6213
0
    static _PyArg_Parser _parser = {NULL, _keywords, "WIFCONTINUED", 0};
6214
0
    PyObject *argsbuf[1];
6215
0
    int status;
6216
0
    int _return_value;
6217
6218
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6219
0
    if (!args) {
6220
0
        goto exit;
6221
0
    }
6222
0
    if (PyFloat_Check(args[0])) {
6223
0
        PyErr_SetString(PyExc_TypeError,
6224
0
                        "integer argument expected, got float" );
6225
0
        goto exit;
6226
0
    }
6227
0
    status = _PyLong_AsInt(args[0]);
6228
0
    if (status == -1 && PyErr_Occurred()) {
6229
0
        goto exit;
6230
0
    }
6231
0
    _return_value = os_WIFCONTINUED_impl(module, status);
6232
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6233
0
        goto exit;
6234
0
    }
6235
0
    return_value = PyBool_FromLong((long)_return_value);
6236
6237
0
exit:
6238
0
    return return_value;
6239
0
}
6240
6241
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
6242
6243
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
6244
6245
PyDoc_STRVAR(os_WIFSTOPPED__doc__,
6246
"WIFSTOPPED($module, /, status)\n"
6247
"--\n"
6248
"\n"
6249
"Return True if the process returning status was stopped.");
6250
6251
#define OS_WIFSTOPPED_METHODDEF    \
6252
    {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
6253
6254
static int
6255
os_WIFSTOPPED_impl(PyObject *module, int status);
6256
6257
static PyObject *
6258
os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6259
0
{
6260
0
    PyObject *return_value = NULL;
6261
0
    static const char * const _keywords[] = {"status", NULL};
6262
0
    static _PyArg_Parser _parser = {NULL, _keywords, "WIFSTOPPED", 0};
6263
0
    PyObject *argsbuf[1];
6264
0
    int status;
6265
0
    int _return_value;
6266
6267
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6268
0
    if (!args) {
6269
0
        goto exit;
6270
0
    }
6271
0
    if (PyFloat_Check(args[0])) {
6272
0
        PyErr_SetString(PyExc_TypeError,
6273
0
                        "integer argument expected, got float" );
6274
0
        goto exit;
6275
0
    }
6276
0
    status = _PyLong_AsInt(args[0]);
6277
0
    if (status == -1 && PyErr_Occurred()) {
6278
0
        goto exit;
6279
0
    }
6280
0
    _return_value = os_WIFSTOPPED_impl(module, status);
6281
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6282
0
        goto exit;
6283
0
    }
6284
0
    return_value = PyBool_FromLong((long)_return_value);
6285
6286
0
exit:
6287
0
    return return_value;
6288
0
}
6289
6290
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
6291
6292
#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
6293
6294
PyDoc_STRVAR(os_WIFSIGNALED__doc__,
6295
"WIFSIGNALED($module, /, status)\n"
6296
"--\n"
6297
"\n"
6298
"Return True if the process returning status was terminated by a signal.");
6299
6300
#define OS_WIFSIGNALED_METHODDEF    \
6301
    {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
6302
6303
static int
6304
os_WIFSIGNALED_impl(PyObject *module, int status);
6305
6306
static PyObject *
6307
os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6308
0
{
6309
0
    PyObject *return_value = NULL;
6310
0
    static const char * const _keywords[] = {"status", NULL};
6311
0
    static _PyArg_Parser _parser = {NULL, _keywords, "WIFSIGNALED", 0};
6312
0
    PyObject *argsbuf[1];
6313
0
    int status;
6314
0
    int _return_value;
6315
6316
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6317
0
    if (!args) {
6318
0
        goto exit;
6319
0
    }
6320
0
    if (PyFloat_Check(args[0])) {
6321
0
        PyErr_SetString(PyExc_TypeError,
6322
0
                        "integer argument expected, got float" );
6323
0
        goto exit;
6324
0
    }
6325
0
    status = _PyLong_AsInt(args[0]);
6326
0
    if (status == -1 && PyErr_Occurred()) {
6327
0
        goto exit;
6328
0
    }
6329
0
    _return_value = os_WIFSIGNALED_impl(module, status);
6330
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6331
0
        goto exit;
6332
0
    }
6333
0
    return_value = PyBool_FromLong((long)_return_value);
6334
6335
0
exit:
6336
0
    return return_value;
6337
0
}
6338
6339
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
6340
6341
#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
6342
6343
PyDoc_STRVAR(os_WIFEXITED__doc__,
6344
"WIFEXITED($module, /, status)\n"
6345
"--\n"
6346
"\n"
6347
"Return True if the process returning status exited via the exit() system call.");
6348
6349
#define OS_WIFEXITED_METHODDEF    \
6350
    {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
6351
6352
static int
6353
os_WIFEXITED_impl(PyObject *module, int status);
6354
6355
static PyObject *
6356
os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6357
0
{
6358
0
    PyObject *return_value = NULL;
6359
0
    static const char * const _keywords[] = {"status", NULL};
6360
0
    static _PyArg_Parser _parser = {NULL, _keywords, "WIFEXITED", 0};
6361
0
    PyObject *argsbuf[1];
6362
0
    int status;
6363
0
    int _return_value;
6364
6365
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6366
0
    if (!args) {
6367
0
        goto exit;
6368
0
    }
6369
0
    if (PyFloat_Check(args[0])) {
6370
0
        PyErr_SetString(PyExc_TypeError,
6371
0
                        "integer argument expected, got float" );
6372
0
        goto exit;
6373
0
    }
6374
0
    status = _PyLong_AsInt(args[0]);
6375
0
    if (status == -1 && PyErr_Occurred()) {
6376
0
        goto exit;
6377
0
    }
6378
0
    _return_value = os_WIFEXITED_impl(module, status);
6379
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6380
0
        goto exit;
6381
0
    }
6382
0
    return_value = PyBool_FromLong((long)_return_value);
6383
6384
0
exit:
6385
0
    return return_value;
6386
0
}
6387
6388
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
6389
6390
#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
6391
6392
PyDoc_STRVAR(os_WEXITSTATUS__doc__,
6393
"WEXITSTATUS($module, /, status)\n"
6394
"--\n"
6395
"\n"
6396
"Return the process return code from status.");
6397
6398
#define OS_WEXITSTATUS_METHODDEF    \
6399
    {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
6400
6401
static int
6402
os_WEXITSTATUS_impl(PyObject *module, int status);
6403
6404
static PyObject *
6405
os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6406
0
{
6407
0
    PyObject *return_value = NULL;
6408
0
    static const char * const _keywords[] = {"status", NULL};
6409
0
    static _PyArg_Parser _parser = {NULL, _keywords, "WEXITSTATUS", 0};
6410
0
    PyObject *argsbuf[1];
6411
0
    int status;
6412
0
    int _return_value;
6413
6414
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6415
0
    if (!args) {
6416
0
        goto exit;
6417
0
    }
6418
0
    if (PyFloat_Check(args[0])) {
6419
0
        PyErr_SetString(PyExc_TypeError,
6420
0
                        "integer argument expected, got float" );
6421
0
        goto exit;
6422
0
    }
6423
0
    status = _PyLong_AsInt(args[0]);
6424
0
    if (status == -1 && PyErr_Occurred()) {
6425
0
        goto exit;
6426
0
    }
6427
0
    _return_value = os_WEXITSTATUS_impl(module, status);
6428
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6429
0
        goto exit;
6430
0
    }
6431
0
    return_value = PyLong_FromLong((long)_return_value);
6432
6433
0
exit:
6434
0
    return return_value;
6435
0
}
6436
6437
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
6438
6439
#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
6440
6441
PyDoc_STRVAR(os_WTERMSIG__doc__,
6442
"WTERMSIG($module, /, status)\n"
6443
"--\n"
6444
"\n"
6445
"Return the signal that terminated the process that provided the status value.");
6446
6447
#define OS_WTERMSIG_METHODDEF    \
6448
    {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
6449
6450
static int
6451
os_WTERMSIG_impl(PyObject *module, int status);
6452
6453
static PyObject *
6454
os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6455
0
{
6456
0
    PyObject *return_value = NULL;
6457
0
    static const char * const _keywords[] = {"status", NULL};
6458
0
    static _PyArg_Parser _parser = {NULL, _keywords, "WTERMSIG", 0};
6459
0
    PyObject *argsbuf[1];
6460
0
    int status;
6461
0
    int _return_value;
6462
6463
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6464
0
    if (!args) {
6465
0
        goto exit;
6466
0
    }
6467
0
    if (PyFloat_Check(args[0])) {
6468
0
        PyErr_SetString(PyExc_TypeError,
6469
0
                        "integer argument expected, got float" );
6470
0
        goto exit;
6471
0
    }
6472
0
    status = _PyLong_AsInt(args[0]);
6473
0
    if (status == -1 && PyErr_Occurred()) {
6474
0
        goto exit;
6475
0
    }
6476
0
    _return_value = os_WTERMSIG_impl(module, status);
6477
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6478
0
        goto exit;
6479
0
    }
6480
0
    return_value = PyLong_FromLong((long)_return_value);
6481
6482
0
exit:
6483
0
    return return_value;
6484
0
}
6485
6486
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
6487
6488
#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
6489
6490
PyDoc_STRVAR(os_WSTOPSIG__doc__,
6491
"WSTOPSIG($module, /, status)\n"
6492
"--\n"
6493
"\n"
6494
"Return the signal that stopped the process that provided the status value.");
6495
6496
#define OS_WSTOPSIG_METHODDEF    \
6497
    {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
6498
6499
static int
6500
os_WSTOPSIG_impl(PyObject *module, int status);
6501
6502
static PyObject *
6503
os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6504
0
{
6505
0
    PyObject *return_value = NULL;
6506
0
    static const char * const _keywords[] = {"status", NULL};
6507
0
    static _PyArg_Parser _parser = {NULL, _keywords, "WSTOPSIG", 0};
6508
0
    PyObject *argsbuf[1];
6509
0
    int status;
6510
0
    int _return_value;
6511
6512
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6513
0
    if (!args) {
6514
0
        goto exit;
6515
0
    }
6516
0
    if (PyFloat_Check(args[0])) {
6517
0
        PyErr_SetString(PyExc_TypeError,
6518
0
                        "integer argument expected, got float" );
6519
0
        goto exit;
6520
0
    }
6521
0
    status = _PyLong_AsInt(args[0]);
6522
0
    if (status == -1 && PyErr_Occurred()) {
6523
0
        goto exit;
6524
0
    }
6525
0
    _return_value = os_WSTOPSIG_impl(module, status);
6526
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6527
0
        goto exit;
6528
0
    }
6529
0
    return_value = PyLong_FromLong((long)_return_value);
6530
6531
0
exit:
6532
0
    return return_value;
6533
0
}
6534
6535
#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
6536
6537
#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
6538
6539
PyDoc_STRVAR(os_fstatvfs__doc__,
6540
"fstatvfs($module, fd, /)\n"
6541
"--\n"
6542
"\n"
6543
"Perform an fstatvfs system call on the given fd.\n"
6544
"\n"
6545
"Equivalent to statvfs(fd).");
6546
6547
#define OS_FSTATVFS_METHODDEF    \
6548
    {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
6549
6550
static PyObject *
6551
os_fstatvfs_impl(PyObject *module, int fd);
6552
6553
static PyObject *
6554
os_fstatvfs(PyObject *module, PyObject *arg)
6555
0
{
6556
0
    PyObject *return_value = NULL;
6557
0
    int fd;
6558
6559
0
    if (PyFloat_Check(arg)) {
6560
0
        PyErr_SetString(PyExc_TypeError,
6561
0
                        "integer argument expected, got float" );
6562
0
        goto exit;
6563
0
    }
6564
0
    fd = _PyLong_AsInt(arg);
6565
0
    if (fd == -1 && PyErr_Occurred()) {
6566
0
        goto exit;
6567
0
    }
6568
0
    return_value = os_fstatvfs_impl(module, fd);
6569
6570
0
exit:
6571
0
    return return_value;
6572
0
}
6573
6574
#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
6575
6576
#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
6577
6578
PyDoc_STRVAR(os_statvfs__doc__,
6579
"statvfs($module, /, path)\n"
6580
"--\n"
6581
"\n"
6582
"Perform a statvfs system call on the given path.\n"
6583
"\n"
6584
"path may always be specified as a string.\n"
6585
"On some platforms, path may also be specified as an open file descriptor.\n"
6586
"  If this functionality is unavailable, using it raises an exception.");
6587
6588
#define OS_STATVFS_METHODDEF    \
6589
    {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
6590
6591
static PyObject *
6592
os_statvfs_impl(PyObject *module, path_t *path);
6593
6594
static PyObject *
6595
os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6596
0
{
6597
0
    PyObject *return_value = NULL;
6598
0
    static const char * const _keywords[] = {"path", NULL};
6599
0
    static _PyArg_Parser _parser = {NULL, _keywords, "statvfs", 0};
6600
0
    PyObject *argsbuf[1];
6601
0
    path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
6602
6603
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6604
0
    if (!args) {
6605
0
        goto exit;
6606
0
    }
6607
0
    if (!path_converter(args[0], &path)) {
6608
0
        goto exit;
6609
0
    }
6610
0
    return_value = os_statvfs_impl(module, &path);
6611
6612
0
exit:
6613
    /* Cleanup for path */
6614
0
    path_cleanup(&path);
6615
6616
0
    return return_value;
6617
0
}
6618
6619
#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
6620
6621
#if defined(MS_WINDOWS)
6622
6623
PyDoc_STRVAR(os__getdiskusage__doc__,
6624
"_getdiskusage($module, /, path)\n"
6625
"--\n"
6626
"\n"
6627
"Return disk usage statistics about the given path as a (total, free) tuple.");
6628
6629
#define OS__GETDISKUSAGE_METHODDEF    \
6630
    {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
6631
6632
static PyObject *
6633
os__getdiskusage_impl(PyObject *module, path_t *path);
6634
6635
static PyObject *
6636
os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6637
{
6638
    PyObject *return_value = NULL;
6639
    static const char * const _keywords[] = {"path", NULL};
6640
    static _PyArg_Parser _parser = {NULL, _keywords, "_getdiskusage", 0};
6641
    PyObject *argsbuf[1];
6642
    path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
6643
6644
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6645
    if (!args) {
6646
        goto exit;
6647
    }
6648
    if (!path_converter(args[0], &path)) {
6649
        goto exit;
6650
    }
6651
    return_value = os__getdiskusage_impl(module, &path);
6652
6653
exit:
6654
    /* Cleanup for path */
6655
    path_cleanup(&path);
6656
6657
    return return_value;
6658
}
6659
6660
#endif /* defined(MS_WINDOWS) */
6661
6662
#if defined(HAVE_FPATHCONF)
6663
6664
PyDoc_STRVAR(os_fpathconf__doc__,
6665
"fpathconf($module, fd, name, /)\n"
6666
"--\n"
6667
"\n"
6668
"Return the configuration limit name for the file descriptor fd.\n"
6669
"\n"
6670
"If there is no limit, return -1.");
6671
6672
#define OS_FPATHCONF_METHODDEF    \
6673
    {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
6674
6675
static long
6676
os_fpathconf_impl(PyObject *module, int fd, int name);
6677
6678
static PyObject *
6679
os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6680
0
{
6681
0
    PyObject *return_value = NULL;
6682
0
    int fd;
6683
0
    int name;
6684
0
    long _return_value;
6685
6686
0
    if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
6687
0
        goto exit;
6688
0
    }
6689
0
    if (PyFloat_Check(args[0])) {
6690
0
        PyErr_SetString(PyExc_TypeError,
6691
0
                        "integer argument expected, got float" );
6692
0
        goto exit;
6693
0
    }
6694
0
    fd = _PyLong_AsInt(args[0]);
6695
0
    if (fd == -1 && PyErr_Occurred()) {
6696
0
        goto exit;
6697
0
    }
6698
0
    if (!conv_path_confname(args[1], &name)) {
6699
0
        goto exit;
6700
0
    }
6701
0
    _return_value = os_fpathconf_impl(module, fd, name);
6702
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6703
0
        goto exit;
6704
0
    }
6705
0
    return_value = PyLong_FromLong(_return_value);
6706
6707
0
exit:
6708
0
    return return_value;
6709
0
}
6710
6711
#endif /* defined(HAVE_FPATHCONF) */
6712
6713
#if defined(HAVE_PATHCONF)
6714
6715
PyDoc_STRVAR(os_pathconf__doc__,
6716
"pathconf($module, /, path, name)\n"
6717
"--\n"
6718
"\n"
6719
"Return the configuration limit name for the file or directory path.\n"
6720
"\n"
6721
"If there is no limit, return -1.\n"
6722
"On some platforms, path may also be specified as an open file descriptor.\n"
6723
"  If this functionality is unavailable, using it raises an exception.");
6724
6725
#define OS_PATHCONF_METHODDEF    \
6726
    {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
6727
6728
static long
6729
os_pathconf_impl(PyObject *module, path_t *path, int name);
6730
6731
static PyObject *
6732
os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6733
0
{
6734
0
    PyObject *return_value = NULL;
6735
0
    static const char * const _keywords[] = {"path", "name", NULL};
6736
0
    static _PyArg_Parser _parser = {NULL, _keywords, "pathconf", 0};
6737
0
    PyObject *argsbuf[2];
6738
0
    path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
6739
0
    int name;
6740
0
    long _return_value;
6741
6742
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
6743
0
    if (!args) {
6744
0
        goto exit;
6745
0
    }
6746
0
    if (!path_converter(args[0], &path)) {
6747
0
        goto exit;
6748
0
    }
6749
0
    if (!conv_path_confname(args[1], &name)) {
6750
0
        goto exit;
6751
0
    }
6752
0
    _return_value = os_pathconf_impl(module, &path, name);
6753
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6754
0
        goto exit;
6755
0
    }
6756
0
    return_value = PyLong_FromLong(_return_value);
6757
6758
0
exit:
6759
    /* Cleanup for path */
6760
0
    path_cleanup(&path);
6761
6762
0
    return return_value;
6763
0
}
6764
6765
#endif /* defined(HAVE_PATHCONF) */
6766
6767
#if defined(HAVE_CONFSTR)
6768
6769
PyDoc_STRVAR(os_confstr__doc__,
6770
"confstr($module, name, /)\n"
6771
"--\n"
6772
"\n"
6773
"Return a string-valued system configuration variable.");
6774
6775
#define OS_CONFSTR_METHODDEF    \
6776
    {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
6777
6778
static PyObject *
6779
os_confstr_impl(PyObject *module, int name);
6780
6781
static PyObject *
6782
os_confstr(PyObject *module, PyObject *arg)
6783
0
{
6784
0
    PyObject *return_value = NULL;
6785
0
    int name;
6786
6787
0
    if (!conv_confstr_confname(arg, &name)) {
6788
0
        goto exit;
6789
0
    }
6790
0
    return_value = os_confstr_impl(module, name);
6791
6792
0
exit:
6793
0
    return return_value;
6794
0
}
6795
6796
#endif /* defined(HAVE_CONFSTR) */
6797
6798
#if defined(HAVE_SYSCONF)
6799
6800
PyDoc_STRVAR(os_sysconf__doc__,
6801
"sysconf($module, name, /)\n"
6802
"--\n"
6803
"\n"
6804
"Return an integer-valued system configuration variable.");
6805
6806
#define OS_SYSCONF_METHODDEF    \
6807
    {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
6808
6809
static long
6810
os_sysconf_impl(PyObject *module, int name);
6811
6812
static PyObject *
6813
os_sysconf(PyObject *module, PyObject *arg)
6814
0
{
6815
0
    PyObject *return_value = NULL;
6816
0
    int name;
6817
0
    long _return_value;
6818
6819
0
    if (!conv_sysconf_confname(arg, &name)) {
6820
0
        goto exit;
6821
0
    }
6822
0
    _return_value = os_sysconf_impl(module, name);
6823
0
    if ((_return_value == -1) && PyErr_Occurred()) {
6824
0
        goto exit;
6825
0
    }
6826
0
    return_value = PyLong_FromLong(_return_value);
6827
6828
0
exit:
6829
0
    return return_value;
6830
0
}
6831
6832
#endif /* defined(HAVE_SYSCONF) */
6833
6834
PyDoc_STRVAR(os_abort__doc__,
6835
"abort($module, /)\n"
6836
"--\n"
6837
"\n"
6838
"Abort the interpreter immediately.\n"
6839
"\n"
6840
"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
6841
"on the hosting operating system.  This function never returns.");
6842
6843
#define OS_ABORT_METHODDEF    \
6844
    {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
6845
6846
static PyObject *
6847
os_abort_impl(PyObject *module);
6848
6849
static PyObject *
6850
os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
6851
0
{
6852
0
    return os_abort_impl(module);
6853
0
}
6854
6855
#if defined(MS_WINDOWS)
6856
6857
PyDoc_STRVAR(os_startfile__doc__,
6858
"startfile($module, /, filepath, operation=<unrepresentable>)\n"
6859
"--\n"
6860
"\n"
6861
"Start a file with its associated application.\n"
6862
"\n"
6863
"When \"operation\" is not specified or \"open\", this acts like\n"
6864
"double-clicking the file in Explorer, or giving the file name as an\n"
6865
"argument to the DOS \"start\" command: the file is opened with whatever\n"
6866
"application (if any) its extension is associated.\n"
6867
"When another \"operation\" is given, it specifies what should be done with\n"
6868
"the file.  A typical operation is \"print\".\n"
6869
"\n"
6870
"startfile returns as soon as the associated application is launched.\n"
6871
"There is no option to wait for the application to close, and no way\n"
6872
"to retrieve the application\'s exit status.\n"
6873
"\n"
6874
"The filepath is relative to the current directory.  If you want to use\n"
6875
"an absolute path, make sure the first character is not a slash (\"/\");\n"
6876
"the underlying Win32 ShellExecute function doesn\'t work if it is.");
6877
6878
#define OS_STARTFILE_METHODDEF    \
6879
    {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
6880
6881
static PyObject *
6882
os_startfile_impl(PyObject *module, path_t *filepath,
6883
                  const Py_UNICODE *operation);
6884
6885
static PyObject *
6886
os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6887
{
6888
    PyObject *return_value = NULL;
6889
    static const char * const _keywords[] = {"filepath", "operation", NULL};
6890
    static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
6891
    path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
6892
    const Py_UNICODE *operation = NULL;
6893
6894
    if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
6895
        path_converter, &filepath, &operation)) {
6896
        goto exit;
6897
    }
6898
    return_value = os_startfile_impl(module, &filepath, operation);
6899
6900
exit:
6901
    /* Cleanup for filepath */
6902
    path_cleanup(&filepath);
6903
6904
    return return_value;
6905
}
6906
6907
#endif /* defined(MS_WINDOWS) */
6908
6909
#if defined(HAVE_GETLOADAVG)
6910
6911
PyDoc_STRVAR(os_getloadavg__doc__,
6912
"getloadavg($module, /)\n"
6913
"--\n"
6914
"\n"
6915
"Return average recent system load information.\n"
6916
"\n"
6917
"Return the number of processes in the system run queue averaged over\n"
6918
"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
6919
"Raises OSError if the load average was unobtainable.");
6920
6921
#define OS_GETLOADAVG_METHODDEF    \
6922
    {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
6923
6924
static PyObject *
6925
os_getloadavg_impl(PyObject *module);
6926
6927
static PyObject *
6928
os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
6929
0
{
6930
0
    return os_getloadavg_impl(module);
6931
0
}
6932
6933
#endif /* defined(HAVE_GETLOADAVG) */
6934
6935
PyDoc_STRVAR(os_device_encoding__doc__,
6936
"device_encoding($module, /, fd)\n"
6937
"--\n"
6938
"\n"
6939
"Return a string describing the encoding of a terminal\'s file descriptor.\n"
6940
"\n"
6941
"The file descriptor must be attached to a terminal.\n"
6942
"If the device is not a terminal, return None.");
6943
6944
#define OS_DEVICE_ENCODING_METHODDEF    \
6945
    {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
6946
6947
static PyObject *
6948
os_device_encoding_impl(PyObject *module, int fd);
6949
6950
static PyObject *
6951
os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6952
0
{
6953
0
    PyObject *return_value = NULL;
6954
0
    static const char * const _keywords[] = {"fd", NULL};
6955
0
    static _PyArg_Parser _parser = {NULL, _keywords, "device_encoding", 0};
6956
0
    PyObject *argsbuf[1];
6957
0
    int fd;
6958
6959
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6960
0
    if (!args) {
6961
0
        goto exit;
6962
0
    }
6963
0
    if (PyFloat_Check(args[0])) {
6964
0
        PyErr_SetString(PyExc_TypeError,
6965
0
                        "integer argument expected, got float" );
6966
0
        goto exit;
6967
0
    }
6968
0
    fd = _PyLong_AsInt(args[0]);
6969
0
    if (fd == -1 && PyErr_Occurred()) {
6970
0
        goto exit;
6971
0
    }
6972
0
    return_value = os_device_encoding_impl(module, fd);
6973
6974
0
exit:
6975
0
    return return_value;
6976
0
}
6977
6978
#if defined(HAVE_SETRESUID)
6979
6980
PyDoc_STRVAR(os_setresuid__doc__,
6981
"setresuid($module, ruid, euid, suid, /)\n"
6982
"--\n"
6983
"\n"
6984
"Set the current process\'s real, effective, and saved user ids.");
6985
6986
#define OS_SETRESUID_METHODDEF    \
6987
    {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__},
6988
6989
static PyObject *
6990
os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
6991
6992
static PyObject *
6993
os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6994
0
{
6995
0
    PyObject *return_value = NULL;
6996
0
    uid_t ruid;
6997
0
    uid_t euid;
6998
0
    uid_t suid;
6999
7000
0
    if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
7001
0
        goto exit;
7002
0
    }
7003
0
    if (!_Py_Uid_Converter(args[0], &ruid)) {
7004
0
        goto exit;
7005
0
    }
7006
0
    if (!_Py_Uid_Converter(args[1], &euid)) {
7007
0
        goto exit;
7008
0
    }
7009
0
    if (!_Py_Uid_Converter(args[2], &suid)) {
7010
0
        goto exit;
7011
0
    }
7012
0
    return_value = os_setresuid_impl(module, ruid, euid, suid);
7013
7014
0
exit:
7015
0
    return return_value;
7016
0
}
7017
7018
#endif /* defined(HAVE_SETRESUID) */
7019
7020
#if defined(HAVE_SETRESGID)
7021
7022
PyDoc_STRVAR(os_setresgid__doc__,
7023
"setresgid($module, rgid, egid, sgid, /)\n"
7024
"--\n"
7025
"\n"
7026
"Set the current process\'s real, effective, and saved group ids.");
7027
7028
#define OS_SETRESGID_METHODDEF    \
7029
    {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__},
7030
7031
static PyObject *
7032
os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
7033
7034
static PyObject *
7035
os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7036
0
{
7037
0
    PyObject *return_value = NULL;
7038
0
    gid_t rgid;
7039
0
    gid_t egid;
7040
0
    gid_t sgid;
7041
7042
0
    if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
7043
0
        goto exit;
7044
0
    }
7045
0
    if (!_Py_Gid_Converter(args[0], &rgid)) {
7046
0
        goto exit;
7047
0
    }
7048
0
    if (!_Py_Gid_Converter(args[1], &egid)) {
7049
0
        goto exit;
7050
0
    }
7051
0
    if (!_Py_Gid_Converter(args[2], &sgid)) {
7052
0
        goto exit;
7053
0
    }
7054
0
    return_value = os_setresgid_impl(module, rgid, egid, sgid);
7055
7056
0
exit:
7057
0
    return return_value;
7058
0
}
7059
7060
#endif /* defined(HAVE_SETRESGID) */
7061
7062
#if defined(HAVE_GETRESUID)
7063
7064
PyDoc_STRVAR(os_getresuid__doc__,
7065
"getresuid($module, /)\n"
7066
"--\n"
7067
"\n"
7068
"Return a tuple of the current process\'s real, effective, and saved user ids.");
7069
7070
#define OS_GETRESUID_METHODDEF    \
7071
    {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
7072
7073
static PyObject *
7074
os_getresuid_impl(PyObject *module);
7075
7076
static PyObject *
7077
os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
7078
0
{
7079
0
    return os_getresuid_impl(module);
7080
0
}
7081
7082
#endif /* defined(HAVE_GETRESUID) */
7083
7084
#if defined(HAVE_GETRESGID)
7085
7086
PyDoc_STRVAR(os_getresgid__doc__,
7087
"getresgid($module, /)\n"
7088
"--\n"
7089
"\n"
7090
"Return a tuple of the current process\'s real, effective, and saved group ids.");
7091
7092
#define OS_GETRESGID_METHODDEF    \
7093
    {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
7094
7095
static PyObject *
7096
os_getresgid_impl(PyObject *module);
7097
7098
static PyObject *
7099
os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
7100
0
{
7101
0
    return os_getresgid_impl(module);
7102
0
}
7103
7104
#endif /* defined(HAVE_GETRESGID) */
7105
7106
#if defined(USE_XATTRS)
7107
7108
PyDoc_STRVAR(os_getxattr__doc__,
7109
"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
7110
"--\n"
7111
"\n"
7112
"Return the value of extended attribute attribute on path.\n"
7113
"\n"
7114
"path may be either a string, a path-like object, or an open file descriptor.\n"
7115
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
7116
"  link, getxattr will examine the symbolic link itself instead of the file\n"
7117
"  the link points to.");
7118
7119
#define OS_GETXATTR_METHODDEF    \
7120
    {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
7121
7122
static PyObject *
7123
os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
7124
                 int follow_symlinks);
7125
7126
static PyObject *
7127
os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7128
0
{
7129
0
    PyObject *return_value = NULL;
7130
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
7131
0
    static _PyArg_Parser _parser = {NULL, _keywords, "getxattr", 0};
7132
0
    PyObject *argsbuf[3];
7133
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7134
0
    path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
7135
0
    path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
7136
0
    int follow_symlinks = 1;
7137
7138
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
7139
0
    if (!args) {
7140
0
        goto exit;
7141
0
    }
7142
0
    if (!path_converter(args[0], &path)) {
7143
0
        goto exit;
7144
0
    }
7145
0
    if (!path_converter(args[1], &attribute)) {
7146
0
        goto exit;
7147
0
    }
7148
0
    if (!noptargs) {
7149
0
        goto skip_optional_kwonly;
7150
0
    }
7151
0
    follow_symlinks = PyObject_IsTrue(args[2]);
7152
0
    if (follow_symlinks < 0) {
7153
0
        goto exit;
7154
0
    }
7155
0
skip_optional_kwonly:
7156
0
    return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
7157
7158
0
exit:
7159
    /* Cleanup for path */
7160
0
    path_cleanup(&path);
7161
    /* Cleanup for attribute */
7162
0
    path_cleanup(&attribute);
7163
7164
0
    return return_value;
7165
0
}
7166
7167
#endif /* defined(USE_XATTRS) */
7168
7169
#if defined(USE_XATTRS)
7170
7171
PyDoc_STRVAR(os_setxattr__doc__,
7172
"setxattr($module, /, path, attribute, value, flags=0, *,\n"
7173
"         follow_symlinks=True)\n"
7174
"--\n"
7175
"\n"
7176
"Set extended attribute attribute on path to value.\n"
7177
"\n"
7178
"path may be either a string, a path-like object,  or an open file descriptor.\n"
7179
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
7180
"  link, setxattr will modify the symbolic link itself instead of the file\n"
7181
"  the link points to.");
7182
7183
#define OS_SETXATTR_METHODDEF    \
7184
    {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
7185
7186
static PyObject *
7187
os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
7188
                 Py_buffer *value, int flags, int follow_symlinks);
7189
7190
static PyObject *
7191
os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7192
0
{
7193
0
    PyObject *return_value = NULL;
7194
0
    static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
7195
0
    static _PyArg_Parser _parser = {NULL, _keywords, "setxattr", 0};
7196
0
    PyObject *argsbuf[5];
7197
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
7198
0
    path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
7199
0
    path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
7200
0
    Py_buffer value = {NULL, NULL};
7201
0
    int flags = 0;
7202
0
    int follow_symlinks = 1;
7203
7204
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf);
7205
0
    if (!args) {
7206
0
        goto exit;
7207
0
    }
7208
0
    if (!path_converter(args[0], &path)) {
7209
0
        goto exit;
7210
0
    }
7211
0
    if (!path_converter(args[1], &attribute)) {
7212
0
        goto exit;
7213
0
    }
7214
0
    if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
7215
0
        goto exit;
7216
0
    }
7217
0
    if (!PyBuffer_IsContiguous(&value, 'C')) {
7218
0
        _PyArg_BadArgument("setxattr", "argument 'value'", "contiguous buffer", args[2]);
7219
0
        goto exit;
7220
0
    }
7221
0
    if (!noptargs) {
7222
0
        goto skip_optional_pos;
7223
0
    }
7224
0
    if (args[3]) {
7225
0
        if (PyFloat_Check(args[3])) {
7226
0
            PyErr_SetString(PyExc_TypeError,
7227
0
                            "integer argument expected, got float" );
7228
0
            goto exit;
7229
0
        }
7230
0
        flags = _PyLong_AsInt(args[3]);
7231
0
        if (flags == -1 && PyErr_Occurred()) {
7232
0
            goto exit;
7233
0
        }
7234
0
        if (!--noptargs) {
7235
0
            goto skip_optional_pos;
7236
0
        }
7237
0
    }
7238
0
skip_optional_pos:
7239
0
    if (!noptargs) {
7240
0
        goto skip_optional_kwonly;
7241
0
    }
7242
0
    follow_symlinks = PyObject_IsTrue(args[4]);
7243
0
    if (follow_symlinks < 0) {
7244
0
        goto exit;
7245
0
    }
7246
0
skip_optional_kwonly:
7247
0
    return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
7248
7249
0
exit:
7250
    /* Cleanup for path */
7251
0
    path_cleanup(&path);
7252
    /* Cleanup for attribute */
7253
0
    path_cleanup(&attribute);
7254
    /* Cleanup for value */
7255
0
    if (value.obj) {
7256
0
       PyBuffer_Release(&value);
7257
0
    }
7258
7259
0
    return return_value;
7260
0
}
7261
7262
#endif /* defined(USE_XATTRS) */
7263
7264
#if defined(USE_XATTRS)
7265
7266
PyDoc_STRVAR(os_removexattr__doc__,
7267
"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
7268
"--\n"
7269
"\n"
7270
"Remove extended attribute attribute on path.\n"
7271
"\n"
7272
"path may be either a string, a path-like object, or an open file descriptor.\n"
7273
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
7274
"  link, removexattr will modify the symbolic link itself instead of the file\n"
7275
"  the link points to.");
7276
7277
#define OS_REMOVEXATTR_METHODDEF    \
7278
    {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
7279
7280
static PyObject *
7281
os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
7282
                    int follow_symlinks);
7283
7284
static PyObject *
7285
os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7286
0
{
7287
0
    PyObject *return_value = NULL;
7288
0
    static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
7289
0
    static _PyArg_Parser _parser = {NULL, _keywords, "removexattr", 0};
7290
0
    PyObject *argsbuf[3];
7291
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7292
0
    path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
7293
0
    path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
7294
0
    int follow_symlinks = 1;
7295
7296
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
7297
0
    if (!args) {
7298
0
        goto exit;
7299
0
    }
7300
0
    if (!path_converter(args[0], &path)) {
7301
0
        goto exit;
7302
0
    }
7303
0
    if (!path_converter(args[1], &attribute)) {
7304
0
        goto exit;
7305
0
    }
7306
0
    if (!noptargs) {
7307
0
        goto skip_optional_kwonly;
7308
0
    }
7309
0
    follow_symlinks = PyObject_IsTrue(args[2]);
7310
0
    if (follow_symlinks < 0) {
7311
0
        goto exit;
7312
0
    }
7313
0
skip_optional_kwonly:
7314
0
    return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
7315
7316
0
exit:
7317
    /* Cleanup for path */
7318
0
    path_cleanup(&path);
7319
    /* Cleanup for attribute */
7320
0
    path_cleanup(&attribute);
7321
7322
0
    return return_value;
7323
0
}
7324
7325
#endif /* defined(USE_XATTRS) */
7326
7327
#if defined(USE_XATTRS)
7328
7329
PyDoc_STRVAR(os_listxattr__doc__,
7330
"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
7331
"--\n"
7332
"\n"
7333
"Return a list of extended attributes on path.\n"
7334
"\n"
7335
"path may be either None, a string, a path-like object, or an open file descriptor.\n"
7336
"if path is None, listxattr will examine the current directory.\n"
7337
"If follow_symlinks is False, and the last element of the path is a symbolic\n"
7338
"  link, listxattr will examine the symbolic link itself instead of the file\n"
7339
"  the link points to.");
7340
7341
#define OS_LISTXATTR_METHODDEF    \
7342
    {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
7343
7344
static PyObject *
7345
os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
7346
7347
static PyObject *
7348
os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7349
0
{
7350
0
    PyObject *return_value = NULL;
7351
0
    static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
7352
0
    static _PyArg_Parser _parser = {NULL, _keywords, "listxattr", 0};
7353
0
    PyObject *argsbuf[2];
7354
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
7355
0
    path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
7356
0
    int follow_symlinks = 1;
7357
7358
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
7359
0
    if (!args) {
7360
0
        goto exit;
7361
0
    }
7362
0
    if (!noptargs) {
7363
0
        goto skip_optional_pos;
7364
0
    }
7365
0
    if (args[0]) {
7366
0
        if (!path_converter(args[0], &path)) {
7367
0
            goto exit;
7368
0
        }
7369
0
        if (!--noptargs) {
7370
0
            goto skip_optional_pos;
7371
0
        }
7372
0
    }
7373
0
skip_optional_pos:
7374
0
    if (!noptargs) {
7375
0
        goto skip_optional_kwonly;
7376
0
    }
7377
0
    follow_symlinks = PyObject_IsTrue(args[1]);
7378
0
    if (follow_symlinks < 0) {
7379
0
        goto exit;
7380
0
    }
7381
0
skip_optional_kwonly:
7382
0
    return_value = os_listxattr_impl(module, &path, follow_symlinks);
7383
7384
0
exit:
7385
    /* Cleanup for path */
7386
0
    path_cleanup(&path);
7387
7388
0
    return return_value;
7389
0
}
7390
7391
#endif /* defined(USE_XATTRS) */
7392
7393
PyDoc_STRVAR(os_urandom__doc__,
7394
"urandom($module, size, /)\n"
7395
"--\n"
7396
"\n"
7397
"Return a bytes object containing random bytes suitable for cryptographic use.");
7398
7399
#define OS_URANDOM_METHODDEF    \
7400
    {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
7401
7402
static PyObject *
7403
os_urandom_impl(PyObject *module, Py_ssize_t size);
7404
7405
static PyObject *
7406
os_urandom(PyObject *module, PyObject *arg)
7407
0
{
7408
0
    PyObject *return_value = NULL;
7409
0
    Py_ssize_t size;
7410
7411
0
    if (PyFloat_Check(arg)) {
7412
0
        PyErr_SetString(PyExc_TypeError,
7413
0
                        "integer argument expected, got float" );
7414
0
        goto exit;
7415
0
    }
7416
0
    {
7417
0
        Py_ssize_t ival = -1;
7418
0
        PyObject *iobj = PyNumber_Index(arg);
7419
0
        if (iobj != NULL) {
7420
0
            ival = PyLong_AsSsize_t(iobj);
7421
0
            Py_DECREF(iobj);
7422
0
        }
7423
0
        if (ival == -1 && PyErr_Occurred()) {
7424
0
            goto exit;
7425
0
        }
7426
0
        size = ival;
7427
0
    }
7428
0
    return_value = os_urandom_impl(module, size);
7429
7430
0
exit:
7431
0
    return return_value;
7432
0
}
7433
7434
#if defined(HAVE_MEMFD_CREATE)
7435
7436
PyDoc_STRVAR(os_memfd_create__doc__,
7437
"memfd_create($module, /, name, flags=MFD_CLOEXEC)\n"
7438
"--\n"
7439
"\n");
7440
7441
#define OS_MEMFD_CREATE_METHODDEF    \
7442
    {"memfd_create", (PyCFunction)(void(*)(void))os_memfd_create, METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__},
7443
7444
static PyObject *
7445
os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags);
7446
7447
static PyObject *
7448
os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7449
0
{
7450
0
    PyObject *return_value = NULL;
7451
0
    static const char * const _keywords[] = {"name", "flags", NULL};
7452
0
    static _PyArg_Parser _parser = {NULL, _keywords, "memfd_create", 0};
7453
0
    PyObject *argsbuf[2];
7454
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
7455
0
    PyObject *name = NULL;
7456
0
    unsigned int flags = MFD_CLOEXEC;
7457
7458
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
7459
0
    if (!args) {
7460
0
        goto exit;
7461
0
    }
7462
0
    if (!PyUnicode_FSConverter(args[0], &name)) {
7463
0
        goto exit;
7464
0
    }
7465
0
    if (!noptargs) {
7466
0
        goto skip_optional_pos;
7467
0
    }
7468
0
    if (PyFloat_Check(args[1])) {
7469
0
        PyErr_SetString(PyExc_TypeError,
7470
0
                        "integer argument expected, got float" );
7471
0
        goto exit;
7472
0
    }
7473
0
    flags = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
7474
0
    if (flags == (unsigned int)-1 && PyErr_Occurred()) {
7475
0
        goto exit;
7476
0
    }
7477
0
skip_optional_pos:
7478
0
    return_value = os_memfd_create_impl(module, name, flags);
7479
7480
0
exit:
7481
    /* Cleanup for name */
7482
0
    Py_XDECREF(name);
7483
7484
0
    return return_value;
7485
0
}
7486
7487
#endif /* defined(HAVE_MEMFD_CREATE) */
7488
7489
PyDoc_STRVAR(os_cpu_count__doc__,
7490
"cpu_count($module, /)\n"
7491
"--\n"
7492
"\n"
7493
"Return the number of CPUs in the system; return None if indeterminable.\n"
7494
"\n"
7495
"This number is not equivalent to the number of CPUs the current process can\n"
7496
"use.  The number of usable CPUs can be obtained with\n"
7497
"``len(os.sched_getaffinity(0))``");
7498
7499
#define OS_CPU_COUNT_METHODDEF    \
7500
    {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
7501
7502
static PyObject *
7503
os_cpu_count_impl(PyObject *module);
7504
7505
static PyObject *
7506
os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
7507
0
{
7508
0
    return os_cpu_count_impl(module);
7509
0
}
7510
7511
PyDoc_STRVAR(os_get_inheritable__doc__,
7512
"get_inheritable($module, fd, /)\n"
7513
"--\n"
7514
"\n"
7515
"Get the close-on-exe flag of the specified file descriptor.");
7516
7517
#define OS_GET_INHERITABLE_METHODDEF    \
7518
    {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
7519
7520
static int
7521
os_get_inheritable_impl(PyObject *module, int fd);
7522
7523
static PyObject *
7524
os_get_inheritable(PyObject *module, PyObject *arg)
7525
0
{
7526
0
    PyObject *return_value = NULL;
7527
0
    int fd;
7528
0
    int _return_value;
7529
7530
0
    if (PyFloat_Check(arg)) {
7531
0
        PyErr_SetString(PyExc_TypeError,
7532
0
                        "integer argument expected, got float" );
7533
0
        goto exit;
7534
0
    }
7535
0
    fd = _PyLong_AsInt(arg);
7536
0
    if (fd == -1 && PyErr_Occurred()) {
7537
0
        goto exit;
7538
0
    }
7539
0
    _return_value = os_get_inheritable_impl(module, fd);
7540
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7541
0
        goto exit;
7542
0
    }
7543
0
    return_value = PyBool_FromLong((long)_return_value);
7544
7545
0
exit:
7546
0
    return return_value;
7547
0
}
7548
7549
PyDoc_STRVAR(os_set_inheritable__doc__,
7550
"set_inheritable($module, fd, inheritable, /)\n"
7551
"--\n"
7552
"\n"
7553
"Set the inheritable flag of the specified file descriptor.");
7554
7555
#define OS_SET_INHERITABLE_METHODDEF    \
7556
    {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
7557
7558
static PyObject *
7559
os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
7560
7561
static PyObject *
7562
os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7563
0
{
7564
0
    PyObject *return_value = NULL;
7565
0
    int fd;
7566
0
    int inheritable;
7567
7568
0
    if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
7569
0
        goto exit;
7570
0
    }
7571
0
    if (PyFloat_Check(args[0])) {
7572
0
        PyErr_SetString(PyExc_TypeError,
7573
0
                        "integer argument expected, got float" );
7574
0
        goto exit;
7575
0
    }
7576
0
    fd = _PyLong_AsInt(args[0]);
7577
0
    if (fd == -1 && PyErr_Occurred()) {
7578
0
        goto exit;
7579
0
    }
7580
0
    if (PyFloat_Check(args[1])) {
7581
0
        PyErr_SetString(PyExc_TypeError,
7582
0
                        "integer argument expected, got float" );
7583
0
        goto exit;
7584
0
    }
7585
0
    inheritable = _PyLong_AsInt(args[1]);
7586
0
    if (inheritable == -1 && PyErr_Occurred()) {
7587
0
        goto exit;
7588
0
    }
7589
0
    return_value = os_set_inheritable_impl(module, fd, inheritable);
7590
7591
0
exit:
7592
0
    return return_value;
7593
0
}
7594
7595
#if defined(MS_WINDOWS)
7596
7597
PyDoc_STRVAR(os_get_handle_inheritable__doc__,
7598
"get_handle_inheritable($module, handle, /)\n"
7599
"--\n"
7600
"\n"
7601
"Get the close-on-exe flag of the specified file descriptor.");
7602
7603
#define OS_GET_HANDLE_INHERITABLE_METHODDEF    \
7604
    {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
7605
7606
static int
7607
os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
7608
7609
static PyObject *
7610
os_get_handle_inheritable(PyObject *module, PyObject *arg)
7611
{
7612
    PyObject *return_value = NULL;
7613
    intptr_t handle;
7614
    int _return_value;
7615
7616
    if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
7617
        goto exit;
7618
    }
7619
    _return_value = os_get_handle_inheritable_impl(module, handle);
7620
    if ((_return_value == -1) && PyErr_Occurred()) {
7621
        goto exit;
7622
    }
7623
    return_value = PyBool_FromLong((long)_return_value);
7624
7625
exit:
7626
    return return_value;
7627
}
7628
7629
#endif /* defined(MS_WINDOWS) */
7630
7631
#if defined(MS_WINDOWS)
7632
7633
PyDoc_STRVAR(os_set_handle_inheritable__doc__,
7634
"set_handle_inheritable($module, handle, inheritable, /)\n"
7635
"--\n"
7636
"\n"
7637
"Set the inheritable flag of the specified handle.");
7638
7639
#define OS_SET_HANDLE_INHERITABLE_METHODDEF    \
7640
    {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
7641
7642
static PyObject *
7643
os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
7644
                               int inheritable);
7645
7646
static PyObject *
7647
os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7648
{
7649
    PyObject *return_value = NULL;
7650
    intptr_t handle;
7651
    int inheritable;
7652
7653
    if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
7654
        &handle, &inheritable)) {
7655
        goto exit;
7656
    }
7657
    return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
7658
7659
exit:
7660
    return return_value;
7661
}
7662
7663
#endif /* defined(MS_WINDOWS) */
7664
7665
#if !defined(MS_WINDOWS)
7666
7667
PyDoc_STRVAR(os_get_blocking__doc__,
7668
"get_blocking($module, fd, /)\n"
7669
"--\n"
7670
"\n"
7671
"Get the blocking mode of the file descriptor.\n"
7672
"\n"
7673
"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
7674
7675
#define OS_GET_BLOCKING_METHODDEF    \
7676
    {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
7677
7678
static int
7679
os_get_blocking_impl(PyObject *module, int fd);
7680
7681
static PyObject *
7682
os_get_blocking(PyObject *module, PyObject *arg)
7683
0
{
7684
0
    PyObject *return_value = NULL;
7685
0
    int fd;
7686
0
    int _return_value;
7687
7688
0
    if (PyFloat_Check(arg)) {
7689
0
        PyErr_SetString(PyExc_TypeError,
7690
0
                        "integer argument expected, got float" );
7691
0
        goto exit;
7692
0
    }
7693
0
    fd = _PyLong_AsInt(arg);
7694
0
    if (fd == -1 && PyErr_Occurred()) {
7695
0
        goto exit;
7696
0
    }
7697
0
    _return_value = os_get_blocking_impl(module, fd);
7698
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7699
0
        goto exit;
7700
0
    }
7701
0
    return_value = PyBool_FromLong((long)_return_value);
7702
7703
0
exit:
7704
0
    return return_value;
7705
0
}
7706
7707
#endif /* !defined(MS_WINDOWS) */
7708
7709
#if !defined(MS_WINDOWS)
7710
7711
PyDoc_STRVAR(os_set_blocking__doc__,
7712
"set_blocking($module, fd, blocking, /)\n"
7713
"--\n"
7714
"\n"
7715
"Set the blocking mode of the specified file descriptor.\n"
7716
"\n"
7717
"Set the O_NONBLOCK flag if blocking is False,\n"
7718
"clear the O_NONBLOCK flag otherwise.");
7719
7720
#define OS_SET_BLOCKING_METHODDEF    \
7721
    {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__},
7722
7723
static PyObject *
7724
os_set_blocking_impl(PyObject *module, int fd, int blocking);
7725
7726
static PyObject *
7727
os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7728
0
{
7729
0
    PyObject *return_value = NULL;
7730
0
    int fd;
7731
0
    int blocking;
7732
7733
0
    if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
7734
0
        goto exit;
7735
0
    }
7736
0
    if (PyFloat_Check(args[0])) {
7737
0
        PyErr_SetString(PyExc_TypeError,
7738
0
                        "integer argument expected, got float" );
7739
0
        goto exit;
7740
0
    }
7741
0
    fd = _PyLong_AsInt(args[0]);
7742
0
    if (fd == -1 && PyErr_Occurred()) {
7743
0
        goto exit;
7744
0
    }
7745
0
    if (PyFloat_Check(args[1])) {
7746
0
        PyErr_SetString(PyExc_TypeError,
7747
0
                        "integer argument expected, got float" );
7748
0
        goto exit;
7749
0
    }
7750
0
    blocking = _PyLong_AsInt(args[1]);
7751
0
    if (blocking == -1 && PyErr_Occurred()) {
7752
0
        goto exit;
7753
0
    }
7754
0
    return_value = os_set_blocking_impl(module, fd, blocking);
7755
7756
0
exit:
7757
0
    return return_value;
7758
0
}
7759
7760
#endif /* !defined(MS_WINDOWS) */
7761
7762
PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
7763
"is_symlink($self, /)\n"
7764
"--\n"
7765
"\n"
7766
"Return True if the entry is a symbolic link; cached per entry.");
7767
7768
#define OS_DIRENTRY_IS_SYMLINK_METHODDEF    \
7769
    {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
7770
7771
static int
7772
os_DirEntry_is_symlink_impl(DirEntry *self);
7773
7774
static PyObject *
7775
os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
7776
0
{
7777
0
    PyObject *return_value = NULL;
7778
0
    int _return_value;
7779
7780
0
    _return_value = os_DirEntry_is_symlink_impl(self);
7781
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7782
0
        goto exit;
7783
0
    }
7784
0
    return_value = PyBool_FromLong((long)_return_value);
7785
7786
0
exit:
7787
0
    return return_value;
7788
0
}
7789
7790
PyDoc_STRVAR(os_DirEntry_stat__doc__,
7791
"stat($self, /, *, follow_symlinks=True)\n"
7792
"--\n"
7793
"\n"
7794
"Return stat_result object for the entry; cached per entry.");
7795
7796
#define OS_DIRENTRY_STAT_METHODDEF    \
7797
    {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
7798
7799
static PyObject *
7800
os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
7801
7802
static PyObject *
7803
os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7804
0
{
7805
0
    PyObject *return_value = NULL;
7806
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
7807
0
    static _PyArg_Parser _parser = {NULL, _keywords, "stat", 0};
7808
0
    PyObject *argsbuf[1];
7809
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
7810
0
    int follow_symlinks = 1;
7811
7812
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
7813
0
    if (!args) {
7814
0
        goto exit;
7815
0
    }
7816
0
    if (!noptargs) {
7817
0
        goto skip_optional_kwonly;
7818
0
    }
7819
0
    follow_symlinks = PyObject_IsTrue(args[0]);
7820
0
    if (follow_symlinks < 0) {
7821
0
        goto exit;
7822
0
    }
7823
0
skip_optional_kwonly:
7824
0
    return_value = os_DirEntry_stat_impl(self, follow_symlinks);
7825
7826
0
exit:
7827
0
    return return_value;
7828
0
}
7829
7830
PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
7831
"is_dir($self, /, *, follow_symlinks=True)\n"
7832
"--\n"
7833
"\n"
7834
"Return True if the entry is a directory; cached per entry.");
7835
7836
#define OS_DIRENTRY_IS_DIR_METHODDEF    \
7837
    {"is_dir", (PyCFunction)(void(*)(void))os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
7838
7839
static int
7840
os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
7841
7842
static PyObject *
7843
os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7844
0
{
7845
0
    PyObject *return_value = NULL;
7846
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
7847
0
    static _PyArg_Parser _parser = {NULL, _keywords, "is_dir", 0};
7848
0
    PyObject *argsbuf[1];
7849
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
7850
0
    int follow_symlinks = 1;
7851
0
    int _return_value;
7852
7853
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
7854
0
    if (!args) {
7855
0
        goto exit;
7856
0
    }
7857
0
    if (!noptargs) {
7858
0
        goto skip_optional_kwonly;
7859
0
    }
7860
0
    follow_symlinks = PyObject_IsTrue(args[0]);
7861
0
    if (follow_symlinks < 0) {
7862
0
        goto exit;
7863
0
    }
7864
0
skip_optional_kwonly:
7865
0
    _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
7866
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7867
0
        goto exit;
7868
0
    }
7869
0
    return_value = PyBool_FromLong((long)_return_value);
7870
7871
0
exit:
7872
0
    return return_value;
7873
0
}
7874
7875
PyDoc_STRVAR(os_DirEntry_is_file__doc__,
7876
"is_file($self, /, *, follow_symlinks=True)\n"
7877
"--\n"
7878
"\n"
7879
"Return True if the entry is a file; cached per entry.");
7880
7881
#define OS_DIRENTRY_IS_FILE_METHODDEF    \
7882
    {"is_file", (PyCFunction)(void(*)(void))os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
7883
7884
static int
7885
os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
7886
7887
static PyObject *
7888
os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7889
0
{
7890
0
    PyObject *return_value = NULL;
7891
0
    static const char * const _keywords[] = {"follow_symlinks", NULL};
7892
0
    static _PyArg_Parser _parser = {NULL, _keywords, "is_file", 0};
7893
0
    PyObject *argsbuf[1];
7894
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
7895
0
    int follow_symlinks = 1;
7896
0
    int _return_value;
7897
7898
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
7899
0
    if (!args) {
7900
0
        goto exit;
7901
0
    }
7902
0
    if (!noptargs) {
7903
0
        goto skip_optional_kwonly;
7904
0
    }
7905
0
    follow_symlinks = PyObject_IsTrue(args[0]);
7906
0
    if (follow_symlinks < 0) {
7907
0
        goto exit;
7908
0
    }
7909
0
skip_optional_kwonly:
7910
0
    _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
7911
0
    if ((_return_value == -1) && PyErr_Occurred()) {
7912
0
        goto exit;
7913
0
    }
7914
0
    return_value = PyBool_FromLong((long)_return_value);
7915
7916
0
exit:
7917
0
    return return_value;
7918
0
}
7919
7920
PyDoc_STRVAR(os_DirEntry_inode__doc__,
7921
"inode($self, /)\n"
7922
"--\n"
7923
"\n"
7924
"Return inode of the entry; cached per entry.");
7925
7926
#define OS_DIRENTRY_INODE_METHODDEF    \
7927
    {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
7928
7929
static PyObject *
7930
os_DirEntry_inode_impl(DirEntry *self);
7931
7932
static PyObject *
7933
os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
7934
0
{
7935
0
    return os_DirEntry_inode_impl(self);
7936
0
}
7937
7938
PyDoc_STRVAR(os_DirEntry___fspath____doc__,
7939
"__fspath__($self, /)\n"
7940
"--\n"
7941
"\n"
7942
"Returns the path for the entry.");
7943
7944
#define OS_DIRENTRY___FSPATH___METHODDEF    \
7945
    {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
7946
7947
static PyObject *
7948
os_DirEntry___fspath___impl(DirEntry *self);
7949
7950
static PyObject *
7951
os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
7952
0
{
7953
0
    return os_DirEntry___fspath___impl(self);
7954
0
}
7955
7956
PyDoc_STRVAR(os_scandir__doc__,
7957
"scandir($module, /, path=None)\n"
7958
"--\n"
7959
"\n"
7960
"Return an iterator of DirEntry objects for given path.\n"
7961
"\n"
7962
"path can be specified as either str, bytes, or a path-like object.  If path\n"
7963
"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
7964
"all other circumstances they will be str.\n"
7965
"\n"
7966
"If path is None, uses the path=\'.\'.");
7967
7968
#define OS_SCANDIR_METHODDEF    \
7969
    {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
7970
7971
static PyObject *
7972
os_scandir_impl(PyObject *module, path_t *path);
7973
7974
static PyObject *
7975
os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7976
0
{
7977
0
    PyObject *return_value = NULL;
7978
0
    static const char * const _keywords[] = {"path", NULL};
7979
0
    static _PyArg_Parser _parser = {NULL, _keywords, "scandir", 0};
7980
0
    PyObject *argsbuf[1];
7981
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
7982
0
    path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
7983
7984
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
7985
0
    if (!args) {
7986
0
        goto exit;
7987
0
    }
7988
0
    if (!noptargs) {
7989
0
        goto skip_optional_pos;
7990
0
    }
7991
0
    if (!path_converter(args[0], &path)) {
7992
0
        goto exit;
7993
0
    }
7994
0
skip_optional_pos:
7995
0
    return_value = os_scandir_impl(module, &path);
7996
7997
0
exit:
7998
    /* Cleanup for path */
7999
0
    path_cleanup(&path);
8000
8001
0
    return return_value;
8002
0
}
8003
8004
PyDoc_STRVAR(os_fspath__doc__,
8005
"fspath($module, /, path)\n"
8006
"--\n"
8007
"\n"
8008
"Return the file system path representation of the object.\n"
8009
"\n"
8010
"If the object is str or bytes, then allow it to pass through as-is. If the\n"
8011
"object defines __fspath__(), then return the result of that method. All other\n"
8012
"types raise a TypeError.");
8013
8014
#define OS_FSPATH_METHODDEF    \
8015
    {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
8016
8017
static PyObject *
8018
os_fspath_impl(PyObject *module, PyObject *path);
8019
8020
static PyObject *
8021
os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8022
1.44k
{
8023
1.44k
    PyObject *return_value = NULL;
8024
1.44k
    static const char * const _keywords[] = {"path", NULL};
8025
1.44k
    static _PyArg_Parser _parser = {NULL, _keywords, "fspath", 0};
8026
1.44k
    PyObject *argsbuf[1];
8027
1.44k
    PyObject *path;
8028
8029
1.44k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
8030
1.44k
    if (!args) {
8031
0
        goto exit;
8032
0
    }
8033
1.44k
    path = args[0];
8034
1.44k
    return_value = os_fspath_impl(module, path);
8035
8036
1.44k
exit:
8037
1.44k
    return return_value;
8038
1.44k
}
8039
8040
#if defined(HAVE_GETRANDOM_SYSCALL)
8041
8042
PyDoc_STRVAR(os_getrandom__doc__,
8043
"getrandom($module, /, size, flags=0)\n"
8044
"--\n"
8045
"\n"
8046
"Obtain a series of random bytes.");
8047
8048
#define OS_GETRANDOM_METHODDEF    \
8049
    {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
8050
8051
static PyObject *
8052
os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
8053
8054
static PyObject *
8055
os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8056
0
{
8057
0
    PyObject *return_value = NULL;
8058
0
    static const char * const _keywords[] = {"size", "flags", NULL};
8059
0
    static _PyArg_Parser _parser = {NULL, _keywords, "getrandom", 0};
8060
0
    PyObject *argsbuf[2];
8061
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
8062
0
    Py_ssize_t size;
8063
0
    int flags = 0;
8064
8065
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
8066
0
    if (!args) {
8067
0
        goto exit;
8068
0
    }
8069
0
    if (PyFloat_Check(args[0])) {
8070
0
        PyErr_SetString(PyExc_TypeError,
8071
0
                        "integer argument expected, got float" );
8072
0
        goto exit;
8073
0
    }
8074
0
    {
8075
0
        Py_ssize_t ival = -1;
8076
0
        PyObject *iobj = PyNumber_Index(args[0]);
8077
0
        if (iobj != NULL) {
8078
0
            ival = PyLong_AsSsize_t(iobj);
8079
0
            Py_DECREF(iobj);
8080
0
        }
8081
0
        if (ival == -1 && PyErr_Occurred()) {
8082
0
            goto exit;
8083
0
        }
8084
0
        size = ival;
8085
0
    }
8086
0
    if (!noptargs) {
8087
0
        goto skip_optional_pos;
8088
0
    }
8089
0
    if (PyFloat_Check(args[1])) {
8090
0
        PyErr_SetString(PyExc_TypeError,
8091
0
                        "integer argument expected, got float" );
8092
0
        goto exit;
8093
0
    }
8094
0
    flags = _PyLong_AsInt(args[1]);
8095
0
    if (flags == -1 && PyErr_Occurred()) {
8096
0
        goto exit;
8097
0
    }
8098
0
skip_optional_pos:
8099
0
    return_value = os_getrandom_impl(module, size, flags);
8100
8101
0
exit:
8102
0
    return return_value;
8103
0
}
8104
8105
#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
8106
8107
#if defined(MS_WINDOWS)
8108
8109
PyDoc_STRVAR(os__add_dll_directory__doc__,
8110
"_add_dll_directory($module, /, path)\n"
8111
"--\n"
8112
"\n"
8113
"Add a path to the DLL search path.\n"
8114
"\n"
8115
"This search path is used when resolving dependencies for imported\n"
8116
"extension modules (the module itself is resolved through sys.path),\n"
8117
"and also by ctypes.\n"
8118
"\n"
8119
"Returns an opaque value that may be passed to os.remove_dll_directory\n"
8120
"to remove this directory from the search path.");
8121
8122
#define OS__ADD_DLL_DIRECTORY_METHODDEF    \
8123
    {"_add_dll_directory", (PyCFunction)(void(*)(void))os__add_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
8124
8125
static PyObject *
8126
os__add_dll_directory_impl(PyObject *module, path_t *path);
8127
8128
static PyObject *
8129
os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8130
{
8131
    PyObject *return_value = NULL;
8132
    static const char * const _keywords[] = {"path", NULL};
8133
    static _PyArg_Parser _parser = {NULL, _keywords, "_add_dll_directory", 0};
8134
    PyObject *argsbuf[1];
8135
    path_t path = PATH_T_INITIALIZE("_add_dll_directory", "path", 0, 0);
8136
8137
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
8138
    if (!args) {
8139
        goto exit;
8140
    }
8141
    if (!path_converter(args[0], &path)) {
8142
        goto exit;
8143
    }
8144
    return_value = os__add_dll_directory_impl(module, &path);
8145
8146
exit:
8147
    /* Cleanup for path */
8148
    path_cleanup(&path);
8149
8150
    return return_value;
8151
}
8152
8153
#endif /* defined(MS_WINDOWS) */
8154
8155
#if defined(MS_WINDOWS)
8156
8157
PyDoc_STRVAR(os__remove_dll_directory__doc__,
8158
"_remove_dll_directory($module, /, cookie)\n"
8159
"--\n"
8160
"\n"
8161
"Removes a path from the DLL search path.\n"
8162
"\n"
8163
"The parameter is an opaque value that was returned from\n"
8164
"os.add_dll_directory. You can only remove directories that you added\n"
8165
"yourself.");
8166
8167
#define OS__REMOVE_DLL_DIRECTORY_METHODDEF    \
8168
    {"_remove_dll_directory", (PyCFunction)(void(*)(void))os__remove_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
8169
8170
static PyObject *
8171
os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
8172
8173
static PyObject *
8174
os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8175
{
8176
    PyObject *return_value = NULL;
8177
    static const char * const _keywords[] = {"cookie", NULL};
8178
    static _PyArg_Parser _parser = {NULL, _keywords, "_remove_dll_directory", 0};
8179
    PyObject *argsbuf[1];
8180
    PyObject *cookie;
8181
8182
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
8183
    if (!args) {
8184
        goto exit;
8185
    }
8186
    cookie = args[0];
8187
    return_value = os__remove_dll_directory_impl(module, cookie);
8188
8189
exit:
8190
    return return_value;
8191
}
8192
8193
#endif /* defined(MS_WINDOWS) */
8194
8195
#ifndef OS_TTYNAME_METHODDEF
8196
    #define OS_TTYNAME_METHODDEF
8197
#endif /* !defined(OS_TTYNAME_METHODDEF) */
8198
8199
#ifndef OS_CTERMID_METHODDEF
8200
    #define OS_CTERMID_METHODDEF
8201
#endif /* !defined(OS_CTERMID_METHODDEF) */
8202
8203
#ifndef OS_FCHDIR_METHODDEF
8204
    #define OS_FCHDIR_METHODDEF
8205
#endif /* !defined(OS_FCHDIR_METHODDEF) */
8206
8207
#ifndef OS_FCHMOD_METHODDEF
8208
    #define OS_FCHMOD_METHODDEF
8209
#endif /* !defined(OS_FCHMOD_METHODDEF) */
8210
8211
#ifndef OS_LCHMOD_METHODDEF
8212
    #define OS_LCHMOD_METHODDEF
8213
#endif /* !defined(OS_LCHMOD_METHODDEF) */
8214
8215
#ifndef OS_CHFLAGS_METHODDEF
8216
    #define OS_CHFLAGS_METHODDEF
8217
#endif /* !defined(OS_CHFLAGS_METHODDEF) */
8218
8219
#ifndef OS_LCHFLAGS_METHODDEF
8220
    #define OS_LCHFLAGS_METHODDEF
8221
#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
8222
8223
#ifndef OS_CHROOT_METHODDEF
8224
    #define OS_CHROOT_METHODDEF
8225
#endif /* !defined(OS_CHROOT_METHODDEF) */
8226
8227
#ifndef OS_FSYNC_METHODDEF
8228
    #define OS_FSYNC_METHODDEF
8229
#endif /* !defined(OS_FSYNC_METHODDEF) */
8230
8231
#ifndef OS_SYNC_METHODDEF
8232
    #define OS_SYNC_METHODDEF
8233
#endif /* !defined(OS_SYNC_METHODDEF) */
8234
8235
#ifndef OS_FDATASYNC_METHODDEF
8236
    #define OS_FDATASYNC_METHODDEF
8237
#endif /* !defined(OS_FDATASYNC_METHODDEF) */
8238
8239
#ifndef OS_CHOWN_METHODDEF
8240
    #define OS_CHOWN_METHODDEF
8241
#endif /* !defined(OS_CHOWN_METHODDEF) */
8242
8243
#ifndef OS_FCHOWN_METHODDEF
8244
    #define OS_FCHOWN_METHODDEF
8245
#endif /* !defined(OS_FCHOWN_METHODDEF) */
8246
8247
#ifndef OS_LCHOWN_METHODDEF
8248
    #define OS_LCHOWN_METHODDEF
8249
#endif /* !defined(OS_LCHOWN_METHODDEF) */
8250
8251
#ifndef OS_LINK_METHODDEF
8252
    #define OS_LINK_METHODDEF
8253
#endif /* !defined(OS_LINK_METHODDEF) */
8254
8255
#ifndef OS__GETFULLPATHNAME_METHODDEF
8256
    #define OS__GETFULLPATHNAME_METHODDEF
8257
#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
8258
8259
#ifndef OS__GETFINALPATHNAME_METHODDEF
8260
    #define OS__GETFINALPATHNAME_METHODDEF
8261
#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
8262
8263
#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
8264
    #define OS__GETVOLUMEPATHNAME_METHODDEF
8265
#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
8266
8267
#ifndef OS_NICE_METHODDEF
8268
    #define OS_NICE_METHODDEF
8269
#endif /* !defined(OS_NICE_METHODDEF) */
8270
8271
#ifndef OS_GETPRIORITY_METHODDEF
8272
    #define OS_GETPRIORITY_METHODDEF
8273
#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
8274
8275
#ifndef OS_SETPRIORITY_METHODDEF
8276
    #define OS_SETPRIORITY_METHODDEF
8277
#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
8278
8279
#ifndef OS_SYSTEM_METHODDEF
8280
    #define OS_SYSTEM_METHODDEF
8281
#endif /* !defined(OS_SYSTEM_METHODDEF) */
8282
8283
#ifndef OS_UNAME_METHODDEF
8284
    #define OS_UNAME_METHODDEF
8285
#endif /* !defined(OS_UNAME_METHODDEF) */
8286
8287
#ifndef OS_EXECV_METHODDEF
8288
    #define OS_EXECV_METHODDEF
8289
#endif /* !defined(OS_EXECV_METHODDEF) */
8290
8291
#ifndef OS_EXECVE_METHODDEF
8292
    #define OS_EXECVE_METHODDEF
8293
#endif /* !defined(OS_EXECVE_METHODDEF) */
8294
8295
#ifndef OS_POSIX_SPAWN_METHODDEF
8296
    #define OS_POSIX_SPAWN_METHODDEF
8297
#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
8298
8299
#ifndef OS_POSIX_SPAWNP_METHODDEF
8300
    #define OS_POSIX_SPAWNP_METHODDEF
8301
#endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
8302
8303
#ifndef OS_SPAWNV_METHODDEF
8304
    #define OS_SPAWNV_METHODDEF
8305
#endif /* !defined(OS_SPAWNV_METHODDEF) */
8306
8307
#ifndef OS_SPAWNVE_METHODDEF
8308
    #define OS_SPAWNVE_METHODDEF
8309
#endif /* !defined(OS_SPAWNVE_METHODDEF) */
8310
8311
#ifndef OS_REGISTER_AT_FORK_METHODDEF
8312
    #define OS_REGISTER_AT_FORK_METHODDEF
8313
#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
8314
8315
#ifndef OS_FORK1_METHODDEF
8316
    #define OS_FORK1_METHODDEF
8317
#endif /* !defined(OS_FORK1_METHODDEF) */
8318
8319
#ifndef OS_FORK_METHODDEF
8320
    #define OS_FORK_METHODDEF
8321
#endif /* !defined(OS_FORK_METHODDEF) */
8322
8323
#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
8324
    #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
8325
#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
8326
8327
#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
8328
    #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
8329
#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
8330
8331
#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
8332
    #define OS_SCHED_GETSCHEDULER_METHODDEF
8333
#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
8334
8335
#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
8336
    #define OS_SCHED_SETSCHEDULER_METHODDEF
8337
#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
8338
8339
#ifndef OS_SCHED_GETPARAM_METHODDEF
8340
    #define OS_SCHED_GETPARAM_METHODDEF
8341
#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
8342
8343
#ifndef OS_SCHED_SETPARAM_METHODDEF
8344
    #define OS_SCHED_SETPARAM_METHODDEF
8345
#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
8346
8347
#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
8348
    #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
8349
#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
8350
8351
#ifndef OS_SCHED_YIELD_METHODDEF
8352
    #define OS_SCHED_YIELD_METHODDEF
8353
#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
8354
8355
#ifndef OS_SCHED_SETAFFINITY_METHODDEF
8356
    #define OS_SCHED_SETAFFINITY_METHODDEF
8357
#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
8358
8359
#ifndef OS_SCHED_GETAFFINITY_METHODDEF
8360
    #define OS_SCHED_GETAFFINITY_METHODDEF
8361
#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
8362
8363
#ifndef OS_OPENPTY_METHODDEF
8364
    #define OS_OPENPTY_METHODDEF
8365
#endif /* !defined(OS_OPENPTY_METHODDEF) */
8366
8367
#ifndef OS_FORKPTY_METHODDEF
8368
    #define OS_FORKPTY_METHODDEF
8369
#endif /* !defined(OS_FORKPTY_METHODDEF) */
8370
8371
#ifndef OS_GETEGID_METHODDEF
8372
    #define OS_GETEGID_METHODDEF
8373
#endif /* !defined(OS_GETEGID_METHODDEF) */
8374
8375
#ifndef OS_GETEUID_METHODDEF
8376
    #define OS_GETEUID_METHODDEF
8377
#endif /* !defined(OS_GETEUID_METHODDEF) */
8378
8379
#ifndef OS_GETGID_METHODDEF
8380
    #define OS_GETGID_METHODDEF
8381
#endif /* !defined(OS_GETGID_METHODDEF) */
8382
8383
#ifndef OS_GETPID_METHODDEF
8384
    #define OS_GETPID_METHODDEF
8385
#endif /* !defined(OS_GETPID_METHODDEF) */
8386
8387
#ifndef OS_GETGROUPS_METHODDEF
8388
    #define OS_GETGROUPS_METHODDEF
8389
#endif /* !defined(OS_GETGROUPS_METHODDEF) */
8390
8391
#ifndef OS_GETPGID_METHODDEF
8392
    #define OS_GETPGID_METHODDEF
8393
#endif /* !defined(OS_GETPGID_METHODDEF) */
8394
8395
#ifndef OS_GETPGRP_METHODDEF
8396
    #define OS_GETPGRP_METHODDEF
8397
#endif /* !defined(OS_GETPGRP_METHODDEF) */
8398
8399
#ifndef OS_SETPGRP_METHODDEF
8400
    #define OS_SETPGRP_METHODDEF
8401
#endif /* !defined(OS_SETPGRP_METHODDEF) */
8402
8403
#ifndef OS_GETPPID_METHODDEF
8404
    #define OS_GETPPID_METHODDEF
8405
#endif /* !defined(OS_GETPPID_METHODDEF) */
8406
8407
#ifndef OS_GETLOGIN_METHODDEF
8408
    #define OS_GETLOGIN_METHODDEF
8409
#endif /* !defined(OS_GETLOGIN_METHODDEF) */
8410
8411
#ifndef OS_GETUID_METHODDEF
8412
    #define OS_GETUID_METHODDEF
8413
#endif /* !defined(OS_GETUID_METHODDEF) */
8414
8415
#ifndef OS_KILL_METHODDEF
8416
    #define OS_KILL_METHODDEF
8417
#endif /* !defined(OS_KILL_METHODDEF) */
8418
8419
#ifndef OS_KILLPG_METHODDEF
8420
    #define OS_KILLPG_METHODDEF
8421
#endif /* !defined(OS_KILLPG_METHODDEF) */
8422
8423
#ifndef OS_PLOCK_METHODDEF
8424
    #define OS_PLOCK_METHODDEF
8425
#endif /* !defined(OS_PLOCK_METHODDEF) */
8426
8427
#ifndef OS_SETUID_METHODDEF
8428
    #define OS_SETUID_METHODDEF
8429
#endif /* !defined(OS_SETUID_METHODDEF) */
8430
8431
#ifndef OS_SETEUID_METHODDEF
8432
    #define OS_SETEUID_METHODDEF
8433
#endif /* !defined(OS_SETEUID_METHODDEF) */
8434
8435
#ifndef OS_SETEGID_METHODDEF
8436
    #define OS_SETEGID_METHODDEF
8437
#endif /* !defined(OS_SETEGID_METHODDEF) */
8438
8439
#ifndef OS_SETREUID_METHODDEF
8440
    #define OS_SETREUID_METHODDEF
8441
#endif /* !defined(OS_SETREUID_METHODDEF) */
8442
8443
#ifndef OS_SETREGID_METHODDEF
8444
    #define OS_SETREGID_METHODDEF
8445
#endif /* !defined(OS_SETREGID_METHODDEF) */
8446
8447
#ifndef OS_SETGID_METHODDEF
8448
    #define OS_SETGID_METHODDEF
8449
#endif /* !defined(OS_SETGID_METHODDEF) */
8450
8451
#ifndef OS_SETGROUPS_METHODDEF
8452
    #define OS_SETGROUPS_METHODDEF
8453
#endif /* !defined(OS_SETGROUPS_METHODDEF) */
8454
8455
#ifndef OS_WAIT3_METHODDEF
8456
    #define OS_WAIT3_METHODDEF
8457
#endif /* !defined(OS_WAIT3_METHODDEF) */
8458
8459
#ifndef OS_WAIT4_METHODDEF
8460
    #define OS_WAIT4_METHODDEF
8461
#endif /* !defined(OS_WAIT4_METHODDEF) */
8462
8463
#ifndef OS_WAITID_METHODDEF
8464
    #define OS_WAITID_METHODDEF
8465
#endif /* !defined(OS_WAITID_METHODDEF) */
8466
8467
#ifndef OS_WAITPID_METHODDEF
8468
    #define OS_WAITPID_METHODDEF
8469
#endif /* !defined(OS_WAITPID_METHODDEF) */
8470
8471
#ifndef OS_WAIT_METHODDEF
8472
    #define OS_WAIT_METHODDEF
8473
#endif /* !defined(OS_WAIT_METHODDEF) */
8474
8475
#ifndef OS_READLINK_METHODDEF
8476
    #define OS_READLINK_METHODDEF
8477
#endif /* !defined(OS_READLINK_METHODDEF) */
8478
8479
#ifndef OS_SYMLINK_METHODDEF
8480
    #define OS_SYMLINK_METHODDEF
8481
#endif /* !defined(OS_SYMLINK_METHODDEF) */
8482
8483
#ifndef OS_TIMES_METHODDEF
8484
    #define OS_TIMES_METHODDEF
8485
#endif /* !defined(OS_TIMES_METHODDEF) */
8486
8487
#ifndef OS_GETSID_METHODDEF
8488
    #define OS_GETSID_METHODDEF
8489
#endif /* !defined(OS_GETSID_METHODDEF) */
8490
8491
#ifndef OS_SETSID_METHODDEF
8492
    #define OS_SETSID_METHODDEF
8493
#endif /* !defined(OS_SETSID_METHODDEF) */
8494
8495
#ifndef OS_SETPGID_METHODDEF
8496
    #define OS_SETPGID_METHODDEF
8497
#endif /* !defined(OS_SETPGID_METHODDEF) */
8498
8499
#ifndef OS_TCGETPGRP_METHODDEF
8500
    #define OS_TCGETPGRP_METHODDEF
8501
#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
8502
8503
#ifndef OS_TCSETPGRP_METHODDEF
8504
    #define OS_TCSETPGRP_METHODDEF
8505
#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
8506
8507
#ifndef OS_LOCKF_METHODDEF
8508
    #define OS_LOCKF_METHODDEF
8509
#endif /* !defined(OS_LOCKF_METHODDEF) */
8510
8511
#ifndef OS_READV_METHODDEF
8512
    #define OS_READV_METHODDEF
8513
#endif /* !defined(OS_READV_METHODDEF) */
8514
8515
#ifndef OS_PREAD_METHODDEF
8516
    #define OS_PREAD_METHODDEF
8517
#endif /* !defined(OS_PREAD_METHODDEF) */
8518
8519
#ifndef OS_PREADV_METHODDEF
8520
    #define OS_PREADV_METHODDEF
8521
#endif /* !defined(OS_PREADV_METHODDEF) */
8522
8523
#ifndef OS__FCOPYFILE_METHODDEF
8524
    #define OS__FCOPYFILE_METHODDEF
8525
#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
8526
8527
#ifndef OS_PIPE_METHODDEF
8528
    #define OS_PIPE_METHODDEF
8529
#endif /* !defined(OS_PIPE_METHODDEF) */
8530
8531
#ifndef OS_PIPE2_METHODDEF
8532
    #define OS_PIPE2_METHODDEF
8533
#endif /* !defined(OS_PIPE2_METHODDEF) */
8534
8535
#ifndef OS_WRITEV_METHODDEF
8536
    #define OS_WRITEV_METHODDEF
8537
#endif /* !defined(OS_WRITEV_METHODDEF) */
8538
8539
#ifndef OS_PWRITE_METHODDEF
8540
    #define OS_PWRITE_METHODDEF
8541
#endif /* !defined(OS_PWRITE_METHODDEF) */
8542
8543
#ifndef OS_PWRITEV_METHODDEF
8544
    #define OS_PWRITEV_METHODDEF
8545
#endif /* !defined(OS_PWRITEV_METHODDEF) */
8546
8547
#ifndef OS_COPY_FILE_RANGE_METHODDEF
8548
    #define OS_COPY_FILE_RANGE_METHODDEF
8549
#endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
8550
8551
#ifndef OS_MKFIFO_METHODDEF
8552
    #define OS_MKFIFO_METHODDEF
8553
#endif /* !defined(OS_MKFIFO_METHODDEF) */
8554
8555
#ifndef OS_MKNOD_METHODDEF
8556
    #define OS_MKNOD_METHODDEF
8557
#endif /* !defined(OS_MKNOD_METHODDEF) */
8558
8559
#ifndef OS_MAJOR_METHODDEF
8560
    #define OS_MAJOR_METHODDEF
8561
#endif /* !defined(OS_MAJOR_METHODDEF) */
8562
8563
#ifndef OS_MINOR_METHODDEF
8564
    #define OS_MINOR_METHODDEF
8565
#endif /* !defined(OS_MINOR_METHODDEF) */
8566
8567
#ifndef OS_MAKEDEV_METHODDEF
8568
    #define OS_MAKEDEV_METHODDEF
8569
#endif /* !defined(OS_MAKEDEV_METHODDEF) */
8570
8571
#ifndef OS_FTRUNCATE_METHODDEF
8572
    #define OS_FTRUNCATE_METHODDEF
8573
#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
8574
8575
#ifndef OS_TRUNCATE_METHODDEF
8576
    #define OS_TRUNCATE_METHODDEF
8577
#endif /* !defined(OS_TRUNCATE_METHODDEF) */
8578
8579
#ifndef OS_POSIX_FALLOCATE_METHODDEF
8580
    #define OS_POSIX_FALLOCATE_METHODDEF
8581
#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
8582
8583
#ifndef OS_POSIX_FADVISE_METHODDEF
8584
    #define OS_POSIX_FADVISE_METHODDEF
8585
#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
8586
8587
#ifndef OS_PUTENV_METHODDEF
8588
    #define OS_PUTENV_METHODDEF
8589
#endif /* !defined(OS_PUTENV_METHODDEF) */
8590
8591
#ifndef OS_UNSETENV_METHODDEF
8592
    #define OS_UNSETENV_METHODDEF
8593
#endif /* !defined(OS_UNSETENV_METHODDEF) */
8594
8595
#ifndef OS_WCOREDUMP_METHODDEF
8596
    #define OS_WCOREDUMP_METHODDEF
8597
#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
8598
8599
#ifndef OS_WIFCONTINUED_METHODDEF
8600
    #define OS_WIFCONTINUED_METHODDEF
8601
#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
8602
8603
#ifndef OS_WIFSTOPPED_METHODDEF
8604
    #define OS_WIFSTOPPED_METHODDEF
8605
#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
8606
8607
#ifndef OS_WIFSIGNALED_METHODDEF
8608
    #define OS_WIFSIGNALED_METHODDEF
8609
#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
8610
8611
#ifndef OS_WIFEXITED_METHODDEF
8612
    #define OS_WIFEXITED_METHODDEF
8613
#endif /* !defined(OS_WIFEXITED_METHODDEF) */
8614
8615
#ifndef OS_WEXITSTATUS_METHODDEF
8616
    #define OS_WEXITSTATUS_METHODDEF
8617
#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
8618
8619
#ifndef OS_WTERMSIG_METHODDEF
8620
    #define OS_WTERMSIG_METHODDEF
8621
#endif /* !defined(OS_WTERMSIG_METHODDEF) */
8622
8623
#ifndef OS_WSTOPSIG_METHODDEF
8624
    #define OS_WSTOPSIG_METHODDEF
8625
#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
8626
8627
#ifndef OS_FSTATVFS_METHODDEF
8628
    #define OS_FSTATVFS_METHODDEF
8629
#endif /* !defined(OS_FSTATVFS_METHODDEF) */
8630
8631
#ifndef OS_STATVFS_METHODDEF
8632
    #define OS_STATVFS_METHODDEF
8633
#endif /* !defined(OS_STATVFS_METHODDEF) */
8634
8635
#ifndef OS__GETDISKUSAGE_METHODDEF
8636
    #define OS__GETDISKUSAGE_METHODDEF
8637
#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
8638
8639
#ifndef OS_FPATHCONF_METHODDEF
8640
    #define OS_FPATHCONF_METHODDEF
8641
#endif /* !defined(OS_FPATHCONF_METHODDEF) */
8642
8643
#ifndef OS_PATHCONF_METHODDEF
8644
    #define OS_PATHCONF_METHODDEF
8645
#endif /* !defined(OS_PATHCONF_METHODDEF) */
8646
8647
#ifndef OS_CONFSTR_METHODDEF
8648
    #define OS_CONFSTR_METHODDEF
8649
#endif /* !defined(OS_CONFSTR_METHODDEF) */
8650
8651
#ifndef OS_SYSCONF_METHODDEF
8652
    #define OS_SYSCONF_METHODDEF
8653
#endif /* !defined(OS_SYSCONF_METHODDEF) */
8654
8655
#ifndef OS_STARTFILE_METHODDEF
8656
    #define OS_STARTFILE_METHODDEF
8657
#endif /* !defined(OS_STARTFILE_METHODDEF) */
8658
8659
#ifndef OS_GETLOADAVG_METHODDEF
8660
    #define OS_GETLOADAVG_METHODDEF
8661
#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
8662
8663
#ifndef OS_SETRESUID_METHODDEF
8664
    #define OS_SETRESUID_METHODDEF
8665
#endif /* !defined(OS_SETRESUID_METHODDEF) */
8666
8667
#ifndef OS_SETRESGID_METHODDEF
8668
    #define OS_SETRESGID_METHODDEF
8669
#endif /* !defined(OS_SETRESGID_METHODDEF) */
8670
8671
#ifndef OS_GETRESUID_METHODDEF
8672
    #define OS_GETRESUID_METHODDEF
8673
#endif /* !defined(OS_GETRESUID_METHODDEF) */
8674
8675
#ifndef OS_GETRESGID_METHODDEF
8676
    #define OS_GETRESGID_METHODDEF
8677
#endif /* !defined(OS_GETRESGID_METHODDEF) */
8678
8679
#ifndef OS_GETXATTR_METHODDEF
8680
    #define OS_GETXATTR_METHODDEF
8681
#endif /* !defined(OS_GETXATTR_METHODDEF) */
8682
8683
#ifndef OS_SETXATTR_METHODDEF
8684
    #define OS_SETXATTR_METHODDEF
8685
#endif /* !defined(OS_SETXATTR_METHODDEF) */
8686
8687
#ifndef OS_REMOVEXATTR_METHODDEF
8688
    #define OS_REMOVEXATTR_METHODDEF
8689
#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
8690
8691
#ifndef OS_LISTXATTR_METHODDEF
8692
    #define OS_LISTXATTR_METHODDEF
8693
#endif /* !defined(OS_LISTXATTR_METHODDEF) */
8694
8695
#ifndef OS_MEMFD_CREATE_METHODDEF
8696
    #define OS_MEMFD_CREATE_METHODDEF
8697
#endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */
8698
8699
#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
8700
    #define OS_GET_HANDLE_INHERITABLE_METHODDEF
8701
#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
8702
8703
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
8704
    #define OS_SET_HANDLE_INHERITABLE_METHODDEF
8705
#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
8706
8707
#ifndef OS_GET_BLOCKING_METHODDEF
8708
    #define OS_GET_BLOCKING_METHODDEF
8709
#endif /* !defined(OS_GET_BLOCKING_METHODDEF) */
8710
8711
#ifndef OS_SET_BLOCKING_METHODDEF
8712
    #define OS_SET_BLOCKING_METHODDEF
8713
#endif /* !defined(OS_SET_BLOCKING_METHODDEF) */
8714
8715
#ifndef OS_GETRANDOM_METHODDEF
8716
    #define OS_GETRANDOM_METHODDEF
8717
#endif /* !defined(OS_GETRANDOM_METHODDEF) */
8718
8719
#ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
8720
    #define OS__ADD_DLL_DIRECTORY_METHODDEF
8721
#endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
8722
8723
#ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
8724
    #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
8725
#endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
8726
/*[clinic end generated code: output=edb5a840b51fcaa8 input=a9049054013a1b77]*/