LCOV - code coverage report
Current view: top level - Modules/clinic - posixmodule.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 1816 2285 79.5 %
Date: 2022-07-07 18:19:46 Functions: 156 170 91.8 %

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

Generated by: LCOV version 1.14