Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 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" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 12 | " Path to be examined; can be string, bytes, a path-like object or\n" |
Xiang Zhang | 4459e00 | 2017-01-22 13:04:17 +0800 | [diff] [blame] | 13 | " open-file-descriptor int.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 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 \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 31 | {"stat", (PyCFunction)(void(*)(void))os_stat, METH_FASTCALL|METH_KEYWORDS, os_stat__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 32 | |
| 33 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 34 | os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 35 | |
| 36 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 37 | os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 38 | { |
| 39 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 40 | static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; |
| 41 | static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 42 | path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1); |
| 43 | int dir_fd = DEFAULT_DIR_FD; |
| 44 | int follow_symlinks = 1; |
| 45 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 46 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 47 | path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 48 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 49 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 50 | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
| 51 | |
| 52 | exit: |
| 53 | /* Cleanup for path */ |
| 54 | path_cleanup(&path); |
| 55 | |
| 56 | return return_value; |
| 57 | } |
| 58 | |
| 59 | PyDoc_STRVAR(os_lstat__doc__, |
| 60 | "lstat($module, /, path, *, dir_fd=None)\n" |
| 61 | "--\n" |
| 62 | "\n" |
| 63 | "Perform a stat system call on the given path, without following symbolic links.\n" |
| 64 | "\n" |
| 65 | "Like stat(), but do not follow symbolic links.\n" |
| 66 | "Equivalent to stat(path, follow_symlinks=False)."); |
| 67 | |
| 68 | #define OS_LSTAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 69 | {"lstat", (PyCFunction)(void(*)(void))os_lstat, METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 70 | |
| 71 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 72 | os_lstat_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 73 | |
| 74 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 75 | os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 76 | { |
| 77 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 78 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 79 | static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 80 | path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0); |
| 81 | int dir_fd = DEFAULT_DIR_FD; |
| 82 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 83 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 84 | path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 85 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 86 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 87 | return_value = os_lstat_impl(module, &path, dir_fd); |
| 88 | |
| 89 | exit: |
| 90 | /* Cleanup for path */ |
| 91 | path_cleanup(&path); |
| 92 | |
| 93 | return return_value; |
| 94 | } |
| 95 | |
| 96 | PyDoc_STRVAR(os_access__doc__, |
| 97 | "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n" |
| 98 | " follow_symlinks=True)\n" |
| 99 | "--\n" |
| 100 | "\n" |
| 101 | "Use the real uid/gid to test for access to a path.\n" |
| 102 | "\n" |
| 103 | " path\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 104 | " Path to be tested; can be string, bytes, or a path-like object.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 105 | " mode\n" |
| 106 | " Operating-system mode bitfield. Can be F_OK to test existence,\n" |
| 107 | " or the inclusive-OR of R_OK, W_OK, and X_OK.\n" |
| 108 | " dir_fd\n" |
| 109 | " If not None, it should be a file descriptor open to a directory,\n" |
| 110 | " and path should be relative; path will then be relative to that\n" |
| 111 | " directory.\n" |
| 112 | " effective_ids\n" |
| 113 | " If True, access will use the effective uid/gid instead of\n" |
| 114 | " the real uid/gid.\n" |
| 115 | " follow_symlinks\n" |
| 116 | " If False, and the last element of the path is a symbolic link,\n" |
| 117 | " access will examine the symbolic link itself instead of the file\n" |
| 118 | " the link points to.\n" |
| 119 | "\n" |
| 120 | "dir_fd, effective_ids, and follow_symlinks may not be implemented\n" |
| 121 | " on your platform. If they are unavailable, using them will raise a\n" |
| 122 | " NotImplementedError.\n" |
| 123 | "\n" |
| 124 | "Note that most operations will use the effective uid/gid, therefore this\n" |
| 125 | " routine can be used in a suid/sgid environment to test if the invoking user\n" |
| 126 | " has the specified access to the path."); |
| 127 | |
| 128 | #define OS_ACCESS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 129 | {"access", (PyCFunction)(void(*)(void))os_access, METH_FASTCALL|METH_KEYWORDS, os_access__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 130 | |
| 131 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 132 | os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 133 | int effective_ids, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 134 | |
| 135 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 136 | os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 137 | { |
| 138 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 139 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL}; |
| 140 | static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0}; |
Benjamin Peterson | 768f3b4 | 2016-09-05 15:29:33 -0700 | [diff] [blame] | 141 | path_t path = PATH_T_INITIALIZE("access", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 142 | int mode; |
| 143 | int dir_fd = DEFAULT_DIR_FD; |
| 144 | int effective_ids = 0; |
| 145 | int follow_symlinks = 1; |
| 146 | int _return_value; |
| 147 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 148 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 149 | path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 150 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 151 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 152 | _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 153 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 154 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 155 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 156 | return_value = PyBool_FromLong((long)_return_value); |
| 157 | |
| 158 | exit: |
| 159 | /* Cleanup for path */ |
| 160 | path_cleanup(&path); |
| 161 | |
| 162 | return return_value; |
| 163 | } |
| 164 | |
| 165 | #if defined(HAVE_TTYNAME) |
| 166 | |
| 167 | PyDoc_STRVAR(os_ttyname__doc__, |
| 168 | "ttyname($module, fd, /)\n" |
| 169 | "--\n" |
| 170 | "\n" |
| 171 | "Return the name of the terminal device connected to \'fd\'.\n" |
| 172 | "\n" |
| 173 | " fd\n" |
| 174 | " Integer file descriptor handle."); |
| 175 | |
| 176 | #define OS_TTYNAME_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 177 | {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 178 | |
Serhiy Storchaka | 4db62e1 | 2018-12-17 16:47:45 +0200 | [diff] [blame] | 179 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 180 | os_ttyname_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 181 | |
| 182 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 183 | os_ttyname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 184 | { |
| 185 | PyObject *return_value = NULL; |
| 186 | int fd; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 187 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 188 | if (PyFloat_Check(arg)) { |
| 189 | PyErr_SetString(PyExc_TypeError, |
| 190 | "integer argument expected, got float" ); |
| 191 | goto exit; |
| 192 | } |
| 193 | fd = _PyLong_AsInt(arg); |
| 194 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 195 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 196 | } |
Serhiy Storchaka | 4db62e1 | 2018-12-17 16:47:45 +0200 | [diff] [blame] | 197 | return_value = os_ttyname_impl(module, fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 198 | |
| 199 | exit: |
| 200 | return return_value; |
| 201 | } |
| 202 | |
| 203 | #endif /* defined(HAVE_TTYNAME) */ |
| 204 | |
| 205 | #if defined(HAVE_CTERMID) |
| 206 | |
| 207 | PyDoc_STRVAR(os_ctermid__doc__, |
| 208 | "ctermid($module, /)\n" |
| 209 | "--\n" |
| 210 | "\n" |
| 211 | "Return the name of the controlling terminal for this process."); |
| 212 | |
| 213 | #define OS_CTERMID_METHODDEF \ |
| 214 | {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, |
| 215 | |
| 216 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 217 | os_ctermid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 218 | |
| 219 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 220 | os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 221 | { |
| 222 | return os_ctermid_impl(module); |
| 223 | } |
| 224 | |
| 225 | #endif /* defined(HAVE_CTERMID) */ |
| 226 | |
| 227 | PyDoc_STRVAR(os_chdir__doc__, |
| 228 | "chdir($module, /, path)\n" |
| 229 | "--\n" |
| 230 | "\n" |
| 231 | "Change the current working directory to the specified path.\n" |
| 232 | "\n" |
| 233 | "path may always be specified as a string.\n" |
| 234 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 235 | " If this functionality is unavailable, using it raises an exception."); |
| 236 | |
| 237 | #define OS_CHDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 238 | {"chdir", (PyCFunction)(void(*)(void))os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 239 | |
| 240 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 241 | os_chdir_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 242 | |
| 243 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 244 | os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 245 | { |
| 246 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 247 | static const char * const _keywords[] = {"path", NULL}; |
| 248 | static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 249 | path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR); |
| 250 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 251 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 252 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 253 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 254 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 255 | return_value = os_chdir_impl(module, &path); |
| 256 | |
| 257 | exit: |
| 258 | /* Cleanup for path */ |
| 259 | path_cleanup(&path); |
| 260 | |
| 261 | return return_value; |
| 262 | } |
| 263 | |
| 264 | #if defined(HAVE_FCHDIR) |
| 265 | |
| 266 | PyDoc_STRVAR(os_fchdir__doc__, |
| 267 | "fchdir($module, /, fd)\n" |
| 268 | "--\n" |
| 269 | "\n" |
| 270 | "Change to the directory of the given file descriptor.\n" |
| 271 | "\n" |
| 272 | "fd must be opened on a directory, not a file.\n" |
| 273 | "Equivalent to os.chdir(fd)."); |
| 274 | |
| 275 | #define OS_FCHDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 276 | {"fchdir", (PyCFunction)(void(*)(void))os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 277 | |
| 278 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 279 | os_fchdir_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 280 | |
| 281 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 282 | os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 283 | { |
| 284 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 285 | static const char * const _keywords[] = {"fd", NULL}; |
| 286 | static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 287 | int fd; |
| 288 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 289 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 290 | fildes_converter, &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 291 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 292 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 293 | return_value = os_fchdir_impl(module, fd); |
| 294 | |
| 295 | exit: |
| 296 | return return_value; |
| 297 | } |
| 298 | |
| 299 | #endif /* defined(HAVE_FCHDIR) */ |
| 300 | |
| 301 | PyDoc_STRVAR(os_chmod__doc__, |
| 302 | "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n" |
| 303 | "--\n" |
| 304 | "\n" |
| 305 | "Change the access permissions of a file.\n" |
| 306 | "\n" |
| 307 | " path\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 308 | " Path to be modified. May always be specified as a str, bytes, or a path-like object.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 309 | " On some platforms, path may also be specified as an open file descriptor.\n" |
| 310 | " If this functionality is unavailable, using it raises an exception.\n" |
| 311 | " mode\n" |
| 312 | " Operating-system mode bitfield.\n" |
| 313 | " dir_fd\n" |
| 314 | " If not None, it should be a file descriptor open to a directory,\n" |
| 315 | " and path should be relative; path will then be relative to that\n" |
| 316 | " directory.\n" |
| 317 | " follow_symlinks\n" |
| 318 | " If False, and the last element of the path is a symbolic link,\n" |
| 319 | " chmod will modify the symbolic link itself instead of the file\n" |
| 320 | " the link points to.\n" |
| 321 | "\n" |
| 322 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 323 | " an open file descriptor.\n" |
| 324 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 325 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 326 | |
| 327 | #define OS_CHMOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 328 | {"chmod", (PyCFunction)(void(*)(void))os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 329 | |
| 330 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 331 | os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 332 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 333 | |
| 334 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 335 | os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 336 | { |
| 337 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 338 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL}; |
| 339 | static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 340 | path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD); |
| 341 | int mode; |
| 342 | int dir_fd = DEFAULT_DIR_FD; |
| 343 | int follow_symlinks = 1; |
| 344 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 345 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 346 | path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 347 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 348 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 349 | return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); |
| 350 | |
| 351 | exit: |
| 352 | /* Cleanup for path */ |
| 353 | path_cleanup(&path); |
| 354 | |
| 355 | return return_value; |
| 356 | } |
| 357 | |
| 358 | #if defined(HAVE_FCHMOD) |
| 359 | |
| 360 | PyDoc_STRVAR(os_fchmod__doc__, |
| 361 | "fchmod($module, /, fd, mode)\n" |
| 362 | "--\n" |
| 363 | "\n" |
| 364 | "Change the access permissions of the file given by file descriptor fd.\n" |
| 365 | "\n" |
| 366 | "Equivalent to os.chmod(fd, mode)."); |
| 367 | |
| 368 | #define OS_FCHMOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 369 | {"fchmod", (PyCFunction)(void(*)(void))os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 370 | |
| 371 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 372 | os_fchmod_impl(PyObject *module, int fd, int mode); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 373 | |
| 374 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 375 | os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 376 | { |
| 377 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 378 | static const char * const _keywords[] = {"fd", "mode", NULL}; |
| 379 | static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 380 | int fd; |
| 381 | int mode; |
| 382 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 383 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 384 | &fd, &mode)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 385 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 386 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 387 | return_value = os_fchmod_impl(module, fd, mode); |
| 388 | |
| 389 | exit: |
| 390 | return return_value; |
| 391 | } |
| 392 | |
| 393 | #endif /* defined(HAVE_FCHMOD) */ |
| 394 | |
| 395 | #if defined(HAVE_LCHMOD) |
| 396 | |
| 397 | PyDoc_STRVAR(os_lchmod__doc__, |
| 398 | "lchmod($module, /, path, mode)\n" |
| 399 | "--\n" |
| 400 | "\n" |
| 401 | "Change the access permissions of a file, without following symbolic links.\n" |
| 402 | "\n" |
| 403 | "If path is a symlink, this affects the link itself rather than the target.\n" |
| 404 | "Equivalent to chmod(path, mode, follow_symlinks=False).\""); |
| 405 | |
| 406 | #define OS_LCHMOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 407 | {"lchmod", (PyCFunction)(void(*)(void))os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 408 | |
| 409 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 410 | os_lchmod_impl(PyObject *module, path_t *path, int mode); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 411 | |
| 412 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 413 | os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 414 | { |
| 415 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 416 | static const char * const _keywords[] = {"path", "mode", NULL}; |
| 417 | static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 418 | path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0); |
| 419 | int mode; |
| 420 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 421 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 422 | path_converter, &path, &mode)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 423 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 424 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 425 | return_value = os_lchmod_impl(module, &path, mode); |
| 426 | |
| 427 | exit: |
| 428 | /* Cleanup for path */ |
| 429 | path_cleanup(&path); |
| 430 | |
| 431 | return return_value; |
| 432 | } |
| 433 | |
| 434 | #endif /* defined(HAVE_LCHMOD) */ |
| 435 | |
| 436 | #if defined(HAVE_CHFLAGS) |
| 437 | |
| 438 | PyDoc_STRVAR(os_chflags__doc__, |
| 439 | "chflags($module, /, path, flags, follow_symlinks=True)\n" |
| 440 | "--\n" |
| 441 | "\n" |
| 442 | "Set file flags.\n" |
| 443 | "\n" |
| 444 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 445 | " link, chflags will change flags on the symbolic link itself instead of the\n" |
| 446 | " file the link points to.\n" |
| 447 | "follow_symlinks may not be implemented on your platform. If it is\n" |
| 448 | "unavailable, using it will raise a NotImplementedError."); |
| 449 | |
| 450 | #define OS_CHFLAGS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 451 | {"chflags", (PyCFunction)(void(*)(void))os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 452 | |
| 453 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 454 | os_chflags_impl(PyObject *module, path_t *path, unsigned long flags, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 455 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 456 | |
| 457 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 458 | os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 459 | { |
| 460 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 461 | static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL}; |
| 462 | static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 463 | path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0); |
| 464 | unsigned long flags; |
| 465 | int follow_symlinks = 1; |
| 466 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 467 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 468 | path_converter, &path, &flags, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 469 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 470 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 471 | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
| 472 | |
| 473 | exit: |
| 474 | /* Cleanup for path */ |
| 475 | path_cleanup(&path); |
| 476 | |
| 477 | return return_value; |
| 478 | } |
| 479 | |
| 480 | #endif /* defined(HAVE_CHFLAGS) */ |
| 481 | |
| 482 | #if defined(HAVE_LCHFLAGS) |
| 483 | |
| 484 | PyDoc_STRVAR(os_lchflags__doc__, |
| 485 | "lchflags($module, /, path, flags)\n" |
| 486 | "--\n" |
| 487 | "\n" |
| 488 | "Set file flags.\n" |
| 489 | "\n" |
| 490 | "This function will not follow symbolic links.\n" |
| 491 | "Equivalent to chflags(path, flags, follow_symlinks=False)."); |
| 492 | |
| 493 | #define OS_LCHFLAGS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 494 | {"lchflags", (PyCFunction)(void(*)(void))os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 495 | |
| 496 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 497 | os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 498 | |
| 499 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 500 | os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 501 | { |
| 502 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 503 | static const char * const _keywords[] = {"path", "flags", NULL}; |
| 504 | static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 505 | path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0); |
| 506 | unsigned long flags; |
| 507 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 508 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 509 | path_converter, &path, &flags)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 510 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 511 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 512 | return_value = os_lchflags_impl(module, &path, flags); |
| 513 | |
| 514 | exit: |
| 515 | /* Cleanup for path */ |
| 516 | path_cleanup(&path); |
| 517 | |
| 518 | return return_value; |
| 519 | } |
| 520 | |
| 521 | #endif /* defined(HAVE_LCHFLAGS) */ |
| 522 | |
| 523 | #if defined(HAVE_CHROOT) |
| 524 | |
| 525 | PyDoc_STRVAR(os_chroot__doc__, |
| 526 | "chroot($module, /, path)\n" |
| 527 | "--\n" |
| 528 | "\n" |
| 529 | "Change root directory to path."); |
| 530 | |
| 531 | #define OS_CHROOT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 532 | {"chroot", (PyCFunction)(void(*)(void))os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 533 | |
| 534 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 535 | os_chroot_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 536 | |
| 537 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 538 | os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 539 | { |
| 540 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 541 | static const char * const _keywords[] = {"path", NULL}; |
| 542 | static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 543 | path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0); |
| 544 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 545 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 546 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 547 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 548 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 549 | return_value = os_chroot_impl(module, &path); |
| 550 | |
| 551 | exit: |
| 552 | /* Cleanup for path */ |
| 553 | path_cleanup(&path); |
| 554 | |
| 555 | return return_value; |
| 556 | } |
| 557 | |
| 558 | #endif /* defined(HAVE_CHROOT) */ |
| 559 | |
| 560 | #if defined(HAVE_FSYNC) |
| 561 | |
| 562 | PyDoc_STRVAR(os_fsync__doc__, |
| 563 | "fsync($module, /, fd)\n" |
| 564 | "--\n" |
| 565 | "\n" |
| 566 | "Force write of fd to disk."); |
| 567 | |
| 568 | #define OS_FSYNC_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 569 | {"fsync", (PyCFunction)(void(*)(void))os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 570 | |
| 571 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 572 | os_fsync_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 573 | |
| 574 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 575 | os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 576 | { |
| 577 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 578 | static const char * const _keywords[] = {"fd", NULL}; |
| 579 | static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 580 | int fd; |
| 581 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 582 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 583 | fildes_converter, &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 584 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 585 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 586 | return_value = os_fsync_impl(module, fd); |
| 587 | |
| 588 | exit: |
| 589 | return return_value; |
| 590 | } |
| 591 | |
| 592 | #endif /* defined(HAVE_FSYNC) */ |
| 593 | |
| 594 | #if defined(HAVE_SYNC) |
| 595 | |
| 596 | PyDoc_STRVAR(os_sync__doc__, |
| 597 | "sync($module, /)\n" |
| 598 | "--\n" |
| 599 | "\n" |
| 600 | "Force write of everything to disk."); |
| 601 | |
| 602 | #define OS_SYNC_METHODDEF \ |
| 603 | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
| 604 | |
| 605 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 606 | os_sync_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 607 | |
| 608 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 609 | os_sync(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 610 | { |
| 611 | return os_sync_impl(module); |
| 612 | } |
| 613 | |
| 614 | #endif /* defined(HAVE_SYNC) */ |
| 615 | |
| 616 | #if defined(HAVE_FDATASYNC) |
| 617 | |
| 618 | PyDoc_STRVAR(os_fdatasync__doc__, |
| 619 | "fdatasync($module, /, fd)\n" |
| 620 | "--\n" |
| 621 | "\n" |
| 622 | "Force write of fd to disk without forcing update of metadata."); |
| 623 | |
| 624 | #define OS_FDATASYNC_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 625 | {"fdatasync", (PyCFunction)(void(*)(void))os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 626 | |
| 627 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 628 | os_fdatasync_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 629 | |
| 630 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 631 | os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 632 | { |
| 633 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 634 | static const char * const _keywords[] = {"fd", NULL}; |
| 635 | static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 636 | int fd; |
| 637 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 638 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 639 | fildes_converter, &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 640 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 641 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 642 | return_value = os_fdatasync_impl(module, fd); |
| 643 | |
| 644 | exit: |
| 645 | return return_value; |
| 646 | } |
| 647 | |
| 648 | #endif /* defined(HAVE_FDATASYNC) */ |
| 649 | |
| 650 | #if defined(HAVE_CHOWN) |
| 651 | |
| 652 | PyDoc_STRVAR(os_chown__doc__, |
| 653 | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
| 654 | "--\n" |
| 655 | "\n" |
| 656 | "Change the owner and group id of path to the numeric uid and gid.\\\n" |
| 657 | "\n" |
| 658 | " path\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 659 | " Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 660 | " dir_fd\n" |
| 661 | " If not None, it should be a file descriptor open to a directory,\n" |
| 662 | " and path should be relative; path will then be relative to that\n" |
| 663 | " directory.\n" |
| 664 | " follow_symlinks\n" |
| 665 | " If False, and the last element of the path is a symbolic link,\n" |
| 666 | " stat will examine the symbolic link itself instead of the file\n" |
| 667 | " the link points to.\n" |
| 668 | "\n" |
| 669 | "path may always be specified as a string.\n" |
| 670 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 671 | " If this functionality is unavailable, using it raises an exception.\n" |
| 672 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 673 | " and path should be relative; path will then be relative to that directory.\n" |
| 674 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 675 | " link, chown will modify the symbolic link itself instead of the file the\n" |
| 676 | " link points to.\n" |
| 677 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 678 | " an open file descriptor.\n" |
| 679 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 680 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 681 | |
| 682 | #define OS_CHOWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 683 | {"chown", (PyCFunction)(void(*)(void))os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 684 | |
| 685 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 686 | os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 687 | int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 688 | |
| 689 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 690 | os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 691 | { |
| 692 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 693 | static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; |
| 694 | static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 695 | path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN); |
| 696 | uid_t uid; |
| 697 | gid_t gid; |
| 698 | int dir_fd = DEFAULT_DIR_FD; |
| 699 | int follow_symlinks = 1; |
| 700 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 701 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 702 | path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 703 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 704 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 705 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
| 706 | |
| 707 | exit: |
| 708 | /* Cleanup for path */ |
| 709 | path_cleanup(&path); |
| 710 | |
| 711 | return return_value; |
| 712 | } |
| 713 | |
| 714 | #endif /* defined(HAVE_CHOWN) */ |
| 715 | |
| 716 | #if defined(HAVE_FCHOWN) |
| 717 | |
| 718 | PyDoc_STRVAR(os_fchown__doc__, |
| 719 | "fchown($module, /, fd, uid, gid)\n" |
| 720 | "--\n" |
| 721 | "\n" |
| 722 | "Change the owner and group id of the file specified by file descriptor.\n" |
| 723 | "\n" |
| 724 | "Equivalent to os.chown(fd, uid, gid)."); |
| 725 | |
| 726 | #define OS_FCHOWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 727 | {"fchown", (PyCFunction)(void(*)(void))os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 728 | |
| 729 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 730 | os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 731 | |
| 732 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 733 | os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 734 | { |
| 735 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 736 | static const char * const _keywords[] = {"fd", "uid", "gid", NULL}; |
| 737 | static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 738 | int fd; |
| 739 | uid_t uid; |
| 740 | gid_t gid; |
| 741 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 742 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 743 | &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 744 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 745 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 746 | return_value = os_fchown_impl(module, fd, uid, gid); |
| 747 | |
| 748 | exit: |
| 749 | return return_value; |
| 750 | } |
| 751 | |
| 752 | #endif /* defined(HAVE_FCHOWN) */ |
| 753 | |
| 754 | #if defined(HAVE_LCHOWN) |
| 755 | |
| 756 | PyDoc_STRVAR(os_lchown__doc__, |
| 757 | "lchown($module, /, path, uid, gid)\n" |
| 758 | "--\n" |
| 759 | "\n" |
| 760 | "Change the owner and group id of path to the numeric uid and gid.\n" |
| 761 | "\n" |
| 762 | "This function will not follow symbolic links.\n" |
| 763 | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); |
| 764 | |
| 765 | #define OS_LCHOWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 766 | {"lchown", (PyCFunction)(void(*)(void))os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 767 | |
| 768 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 769 | os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 770 | |
| 771 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 772 | os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 773 | { |
| 774 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 775 | static const char * const _keywords[] = {"path", "uid", "gid", NULL}; |
| 776 | static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 777 | path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0); |
| 778 | uid_t uid; |
| 779 | gid_t gid; |
| 780 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 781 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 782 | path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 783 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 784 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 785 | return_value = os_lchown_impl(module, &path, uid, gid); |
| 786 | |
| 787 | exit: |
| 788 | /* Cleanup for path */ |
| 789 | path_cleanup(&path); |
| 790 | |
| 791 | return return_value; |
| 792 | } |
| 793 | |
| 794 | #endif /* defined(HAVE_LCHOWN) */ |
| 795 | |
| 796 | PyDoc_STRVAR(os_getcwd__doc__, |
| 797 | "getcwd($module, /)\n" |
| 798 | "--\n" |
| 799 | "\n" |
| 800 | "Return a unicode string representing the current working directory."); |
| 801 | |
| 802 | #define OS_GETCWD_METHODDEF \ |
| 803 | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
| 804 | |
| 805 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 806 | os_getcwd_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 807 | |
| 808 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 809 | os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 810 | { |
| 811 | return os_getcwd_impl(module); |
| 812 | } |
| 813 | |
| 814 | PyDoc_STRVAR(os_getcwdb__doc__, |
| 815 | "getcwdb($module, /)\n" |
| 816 | "--\n" |
| 817 | "\n" |
| 818 | "Return a bytes string representing the current working directory."); |
| 819 | |
| 820 | #define OS_GETCWDB_METHODDEF \ |
| 821 | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
| 822 | |
| 823 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 824 | os_getcwdb_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 825 | |
| 826 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 827 | os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 828 | { |
| 829 | return os_getcwdb_impl(module); |
| 830 | } |
| 831 | |
| 832 | #if defined(HAVE_LINK) |
| 833 | |
| 834 | PyDoc_STRVAR(os_link__doc__, |
| 835 | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
| 836 | " follow_symlinks=True)\n" |
| 837 | "--\n" |
| 838 | "\n" |
| 839 | "Create a hard link to a file.\n" |
| 840 | "\n" |
| 841 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 842 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 843 | " should be relative; the path will then be relative to that directory.\n" |
| 844 | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
| 845 | " link, link will create a link to the symbolic link itself instead of the\n" |
| 846 | " file the link points to.\n" |
| 847 | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" |
| 848 | " platform. If they are unavailable, using them will raise a\n" |
| 849 | " NotImplementedError."); |
| 850 | |
| 851 | #define OS_LINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 852 | {"link", (PyCFunction)(void(*)(void))os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 853 | |
| 854 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 855 | os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 856 | int dst_dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 857 | |
| 858 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 859 | os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 860 | { |
| 861 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 862 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; |
| 863 | static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 864 | path_t src = PATH_T_INITIALIZE("link", "src", 0, 0); |
| 865 | path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0); |
| 866 | int src_dir_fd = DEFAULT_DIR_FD; |
| 867 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 868 | int follow_symlinks = 1; |
| 869 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 870 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 871 | path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 872 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 873 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 874 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
| 875 | |
| 876 | exit: |
| 877 | /* Cleanup for src */ |
| 878 | path_cleanup(&src); |
| 879 | /* Cleanup for dst */ |
| 880 | path_cleanup(&dst); |
| 881 | |
| 882 | return return_value; |
| 883 | } |
| 884 | |
| 885 | #endif /* defined(HAVE_LINK) */ |
| 886 | |
| 887 | PyDoc_STRVAR(os_listdir__doc__, |
| 888 | "listdir($module, /, path=None)\n" |
| 889 | "--\n" |
| 890 | "\n" |
| 891 | "Return a list containing the names of the files in the directory.\n" |
| 892 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 893 | "path can be specified as either str, bytes, or a path-like object. If path is bytes,\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 894 | " the filenames returned will also be bytes; in all other circumstances\n" |
| 895 | " the filenames returned will be str.\n" |
| 896 | "If path is None, uses the path=\'.\'.\n" |
| 897 | "On some platforms, path may also be specified as an open file descriptor;\\\n" |
| 898 | " the file descriptor must refer to a directory.\n" |
| 899 | " If this functionality is unavailable, using it raises NotImplementedError.\n" |
| 900 | "\n" |
| 901 | "The list is in arbitrary order. It does not include the special\n" |
| 902 | "entries \'.\' and \'..\' even if they are present in the directory."); |
| 903 | |
| 904 | #define OS_LISTDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 905 | {"listdir", (PyCFunction)(void(*)(void))os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 906 | |
| 907 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 908 | os_listdir_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 909 | |
| 910 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 911 | os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 912 | { |
| 913 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 914 | static const char * const _keywords[] = {"path", NULL}; |
| 915 | static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 916 | path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR); |
| 917 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 918 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 919 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 920 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 921 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 922 | return_value = os_listdir_impl(module, &path); |
| 923 | |
| 924 | exit: |
| 925 | /* Cleanup for path */ |
| 926 | path_cleanup(&path); |
| 927 | |
| 928 | return return_value; |
| 929 | } |
| 930 | |
| 931 | #if defined(MS_WINDOWS) |
| 932 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 933 | PyDoc_STRVAR(os__getfullpathname__doc__, |
| 934 | "_getfullpathname($module, path, /)\n" |
| 935 | "--\n" |
| 936 | "\n"); |
| 937 | |
| 938 | #define OS__GETFULLPATHNAME_METHODDEF \ |
| 939 | {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__}, |
| 940 | |
| 941 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 942 | os__getfullpathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 943 | |
| 944 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 945 | os__getfullpathname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 946 | { |
| 947 | PyObject *return_value = NULL; |
| 948 | path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0); |
| 949 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 950 | if (!path_converter(arg, &path)) { |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 951 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 952 | } |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 953 | return_value = os__getfullpathname_impl(module, &path); |
| 954 | |
| 955 | exit: |
| 956 | /* Cleanup for path */ |
| 957 | path_cleanup(&path); |
| 958 | |
| 959 | return return_value; |
| 960 | } |
| 961 | |
| 962 | #endif /* defined(MS_WINDOWS) */ |
| 963 | |
| 964 | #if defined(MS_WINDOWS) |
| 965 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 966 | PyDoc_STRVAR(os__getfinalpathname__doc__, |
| 967 | "_getfinalpathname($module, path, /)\n" |
| 968 | "--\n" |
| 969 | "\n" |
| 970 | "A helper function for samepath on windows."); |
| 971 | |
| 972 | #define OS__GETFINALPATHNAME_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 973 | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 974 | |
| 975 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 976 | os__getfinalpathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 977 | |
| 978 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 979 | os__getfinalpathname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 980 | { |
| 981 | PyObject *return_value = NULL; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 982 | path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 983 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 984 | if (!path_converter(arg, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 985 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 986 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 987 | return_value = os__getfinalpathname_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 988 | |
| 989 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 990 | /* Cleanup for path */ |
| 991 | path_cleanup(&path); |
| 992 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 993 | return return_value; |
| 994 | } |
| 995 | |
| 996 | #endif /* defined(MS_WINDOWS) */ |
| 997 | |
| 998 | #if defined(MS_WINDOWS) |
| 999 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1000 | PyDoc_STRVAR(os__isdir__doc__, |
| 1001 | "_isdir($module, path, /)\n" |
| 1002 | "--\n" |
Serhiy Storchaka | 579f038 | 2016-11-08 20:21:22 +0200 | [diff] [blame] | 1003 | "\n" |
| 1004 | "Return true if the pathname refers to an existing directory."); |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1005 | |
| 1006 | #define OS__ISDIR_METHODDEF \ |
| 1007 | {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__}, |
| 1008 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1009 | #endif /* defined(MS_WINDOWS) */ |
| 1010 | |
| 1011 | #if defined(MS_WINDOWS) |
| 1012 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1013 | PyDoc_STRVAR(os__getvolumepathname__doc__, |
| 1014 | "_getvolumepathname($module, /, path)\n" |
| 1015 | "--\n" |
| 1016 | "\n" |
| 1017 | "A helper function for ismount on Win32."); |
| 1018 | |
| 1019 | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1020 | {"_getvolumepathname", (PyCFunction)(void(*)(void))os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1021 | |
| 1022 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1023 | os__getvolumepathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1024 | |
| 1025 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1026 | os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1027 | { |
| 1028 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1029 | static const char * const _keywords[] = {"path", NULL}; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1030 | static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0}; |
| 1031 | path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1032 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1033 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1034 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1035 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1036 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1037 | return_value = os__getvolumepathname_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1038 | |
| 1039 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1040 | /* Cleanup for path */ |
| 1041 | path_cleanup(&path); |
| 1042 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1043 | return return_value; |
| 1044 | } |
| 1045 | |
| 1046 | #endif /* defined(MS_WINDOWS) */ |
| 1047 | |
| 1048 | PyDoc_STRVAR(os_mkdir__doc__, |
| 1049 | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
| 1050 | "--\n" |
| 1051 | "\n" |
| 1052 | "Create a directory.\n" |
| 1053 | "\n" |
| 1054 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1055 | " and path should be relative; path will then be relative to that directory.\n" |
| 1056 | "dir_fd may not be implemented on your platform.\n" |
| 1057 | " If it is unavailable, using it will raise a NotImplementedError.\n" |
| 1058 | "\n" |
| 1059 | "The mode argument is ignored on Windows."); |
| 1060 | |
| 1061 | #define OS_MKDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1062 | {"mkdir", (PyCFunction)(void(*)(void))os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1063 | |
| 1064 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1065 | os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1066 | |
| 1067 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1068 | os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1069 | { |
| 1070 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1071 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
| 1072 | static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1073 | path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0); |
| 1074 | int mode = 511; |
| 1075 | int dir_fd = DEFAULT_DIR_FD; |
| 1076 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1077 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1078 | path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1079 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1080 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1081 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
| 1082 | |
| 1083 | exit: |
| 1084 | /* Cleanup for path */ |
| 1085 | path_cleanup(&path); |
| 1086 | |
| 1087 | return return_value; |
| 1088 | } |
| 1089 | |
| 1090 | #if defined(HAVE_NICE) |
| 1091 | |
| 1092 | PyDoc_STRVAR(os_nice__doc__, |
| 1093 | "nice($module, increment, /)\n" |
| 1094 | "--\n" |
| 1095 | "\n" |
| 1096 | "Add increment to the priority of process and return the new priority."); |
| 1097 | |
| 1098 | #define OS_NICE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1099 | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1100 | |
| 1101 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1102 | os_nice_impl(PyObject *module, int increment); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1103 | |
| 1104 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1105 | os_nice(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1106 | { |
| 1107 | PyObject *return_value = NULL; |
| 1108 | int increment; |
| 1109 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1110 | if (PyFloat_Check(arg)) { |
| 1111 | PyErr_SetString(PyExc_TypeError, |
| 1112 | "integer argument expected, got float" ); |
| 1113 | goto exit; |
| 1114 | } |
| 1115 | increment = _PyLong_AsInt(arg); |
| 1116 | if (increment == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1117 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1118 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1119 | return_value = os_nice_impl(module, increment); |
| 1120 | |
| 1121 | exit: |
| 1122 | return return_value; |
| 1123 | } |
| 1124 | |
| 1125 | #endif /* defined(HAVE_NICE) */ |
| 1126 | |
| 1127 | #if defined(HAVE_GETPRIORITY) |
| 1128 | |
| 1129 | PyDoc_STRVAR(os_getpriority__doc__, |
| 1130 | "getpriority($module, /, which, who)\n" |
| 1131 | "--\n" |
| 1132 | "\n" |
| 1133 | "Return program scheduling priority."); |
| 1134 | |
| 1135 | #define OS_GETPRIORITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1136 | {"getpriority", (PyCFunction)(void(*)(void))os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1137 | |
| 1138 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1139 | os_getpriority_impl(PyObject *module, int which, int who); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1140 | |
| 1141 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1142 | os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1143 | { |
| 1144 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1145 | static const char * const _keywords[] = {"which", "who", NULL}; |
| 1146 | static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1147 | int which; |
| 1148 | int who; |
| 1149 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1150 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1151 | &which, &who)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1152 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1153 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1154 | return_value = os_getpriority_impl(module, which, who); |
| 1155 | |
| 1156 | exit: |
| 1157 | return return_value; |
| 1158 | } |
| 1159 | |
| 1160 | #endif /* defined(HAVE_GETPRIORITY) */ |
| 1161 | |
| 1162 | #if defined(HAVE_SETPRIORITY) |
| 1163 | |
| 1164 | PyDoc_STRVAR(os_setpriority__doc__, |
| 1165 | "setpriority($module, /, which, who, priority)\n" |
| 1166 | "--\n" |
| 1167 | "\n" |
| 1168 | "Set program scheduling priority."); |
| 1169 | |
| 1170 | #define OS_SETPRIORITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1171 | {"setpriority", (PyCFunction)(void(*)(void))os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1172 | |
| 1173 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1174 | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1175 | |
| 1176 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1177 | os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1178 | { |
| 1179 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1180 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
| 1181 | static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1182 | int which; |
| 1183 | int who; |
| 1184 | int priority; |
| 1185 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1186 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1187 | &which, &who, &priority)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1188 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1189 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1190 | return_value = os_setpriority_impl(module, which, who, priority); |
| 1191 | |
| 1192 | exit: |
| 1193 | return return_value; |
| 1194 | } |
| 1195 | |
| 1196 | #endif /* defined(HAVE_SETPRIORITY) */ |
| 1197 | |
| 1198 | PyDoc_STRVAR(os_rename__doc__, |
| 1199 | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1200 | "--\n" |
| 1201 | "\n" |
| 1202 | "Rename a file or directory.\n" |
| 1203 | "\n" |
| 1204 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1205 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1206 | " should be relative; the path will then be relative to that directory.\n" |
| 1207 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1208 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1209 | |
| 1210 | #define OS_RENAME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1211 | {"rename", (PyCFunction)(void(*)(void))os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1212 | |
| 1213 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1214 | os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 1215 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1216 | |
| 1217 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1218 | os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1219 | { |
| 1220 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1221 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
| 1222 | static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1223 | path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0); |
| 1224 | path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0); |
| 1225 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1226 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1227 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1228 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1229 | path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1230 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1231 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1232 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1233 | |
| 1234 | exit: |
| 1235 | /* Cleanup for src */ |
| 1236 | path_cleanup(&src); |
| 1237 | /* Cleanup for dst */ |
| 1238 | path_cleanup(&dst); |
| 1239 | |
| 1240 | return return_value; |
| 1241 | } |
| 1242 | |
| 1243 | PyDoc_STRVAR(os_replace__doc__, |
| 1244 | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1245 | "--\n" |
| 1246 | "\n" |
| 1247 | "Rename a file or directory, overwriting the destination.\n" |
| 1248 | "\n" |
| 1249 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1250 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1251 | " should be relative; the path will then be relative to that directory.\n" |
| 1252 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1253 | " If they are unavailable, using them will raise a NotImplementedError.\""); |
| 1254 | |
| 1255 | #define OS_REPLACE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1256 | {"replace", (PyCFunction)(void(*)(void))os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1257 | |
| 1258 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1259 | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
| 1260 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1261 | |
| 1262 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1263 | os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1264 | { |
| 1265 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1266 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
| 1267 | static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1268 | path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0); |
| 1269 | path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0); |
| 1270 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1271 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1272 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1273 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1274 | path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1275 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1276 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1277 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1278 | |
| 1279 | exit: |
| 1280 | /* Cleanup for src */ |
| 1281 | path_cleanup(&src); |
| 1282 | /* Cleanup for dst */ |
| 1283 | path_cleanup(&dst); |
| 1284 | |
| 1285 | return return_value; |
| 1286 | } |
| 1287 | |
| 1288 | PyDoc_STRVAR(os_rmdir__doc__, |
| 1289 | "rmdir($module, /, path, *, dir_fd=None)\n" |
| 1290 | "--\n" |
| 1291 | "\n" |
| 1292 | "Remove a directory.\n" |
| 1293 | "\n" |
| 1294 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1295 | " and path should be relative; path will then be relative to that directory.\n" |
| 1296 | "dir_fd may not be implemented on your platform.\n" |
| 1297 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1298 | |
| 1299 | #define OS_RMDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1300 | {"rmdir", (PyCFunction)(void(*)(void))os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1301 | |
| 1302 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1303 | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1304 | |
| 1305 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1306 | os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1307 | { |
| 1308 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1309 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 1310 | static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1311 | path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0); |
| 1312 | int dir_fd = DEFAULT_DIR_FD; |
| 1313 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1314 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1315 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1316 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1317 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1318 | return_value = os_rmdir_impl(module, &path, dir_fd); |
| 1319 | |
| 1320 | exit: |
| 1321 | /* Cleanup for path */ |
| 1322 | path_cleanup(&path); |
| 1323 | |
| 1324 | return return_value; |
| 1325 | } |
| 1326 | |
| 1327 | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
| 1328 | |
| 1329 | PyDoc_STRVAR(os_system__doc__, |
| 1330 | "system($module, /, command)\n" |
| 1331 | "--\n" |
| 1332 | "\n" |
| 1333 | "Execute the command in a subshell."); |
| 1334 | |
| 1335 | #define OS_SYSTEM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1336 | {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1337 | |
| 1338 | static long |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 1339 | os_system_impl(PyObject *module, const Py_UNICODE *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1340 | |
| 1341 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1342 | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1343 | { |
| 1344 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1345 | static const char * const _keywords[] = {"command", NULL}; |
| 1346 | static _PyArg_Parser _parser = {"u:system", _keywords, 0}; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 1347 | const Py_UNICODE *command; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1348 | long _return_value; |
| 1349 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1350 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1351 | &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1352 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1353 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1354 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1355 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1356 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1357 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1358 | return_value = PyLong_FromLong(_return_value); |
| 1359 | |
| 1360 | exit: |
| 1361 | return return_value; |
| 1362 | } |
| 1363 | |
| 1364 | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
| 1365 | |
| 1366 | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
| 1367 | |
| 1368 | PyDoc_STRVAR(os_system__doc__, |
| 1369 | "system($module, /, command)\n" |
| 1370 | "--\n" |
| 1371 | "\n" |
| 1372 | "Execute the command in a subshell."); |
| 1373 | |
| 1374 | #define OS_SYSTEM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1375 | {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1376 | |
| 1377 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1378 | os_system_impl(PyObject *module, PyObject *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1379 | |
| 1380 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1381 | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1382 | { |
| 1383 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1384 | static const char * const _keywords[] = {"command", NULL}; |
| 1385 | static _PyArg_Parser _parser = {"O&:system", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1386 | PyObject *command = NULL; |
| 1387 | long _return_value; |
| 1388 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1389 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1390 | PyUnicode_FSConverter, &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1391 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1392 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1393 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1394 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1395 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1396 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1397 | return_value = PyLong_FromLong(_return_value); |
| 1398 | |
| 1399 | exit: |
| 1400 | /* Cleanup for command */ |
| 1401 | Py_XDECREF(command); |
| 1402 | |
| 1403 | return return_value; |
| 1404 | } |
| 1405 | |
| 1406 | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
| 1407 | |
| 1408 | PyDoc_STRVAR(os_umask__doc__, |
| 1409 | "umask($module, mask, /)\n" |
| 1410 | "--\n" |
| 1411 | "\n" |
| 1412 | "Set the current numeric umask and return the previous umask."); |
| 1413 | |
| 1414 | #define OS_UMASK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1415 | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1416 | |
| 1417 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1418 | os_umask_impl(PyObject *module, int mask); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1419 | |
| 1420 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1421 | os_umask(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1422 | { |
| 1423 | PyObject *return_value = NULL; |
| 1424 | int mask; |
| 1425 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1426 | if (PyFloat_Check(arg)) { |
| 1427 | PyErr_SetString(PyExc_TypeError, |
| 1428 | "integer argument expected, got float" ); |
| 1429 | goto exit; |
| 1430 | } |
| 1431 | mask = _PyLong_AsInt(arg); |
| 1432 | if (mask == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1433 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1434 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1435 | return_value = os_umask_impl(module, mask); |
| 1436 | |
| 1437 | exit: |
| 1438 | return return_value; |
| 1439 | } |
| 1440 | |
| 1441 | PyDoc_STRVAR(os_unlink__doc__, |
| 1442 | "unlink($module, /, path, *, dir_fd=None)\n" |
| 1443 | "--\n" |
| 1444 | "\n" |
| 1445 | "Remove a file (same as remove()).\n" |
| 1446 | "\n" |
| 1447 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1448 | " and path should be relative; path will then be relative to that directory.\n" |
| 1449 | "dir_fd may not be implemented on your platform.\n" |
| 1450 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1451 | |
| 1452 | #define OS_UNLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1453 | {"unlink", (PyCFunction)(void(*)(void))os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1454 | |
| 1455 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1456 | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1457 | |
| 1458 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1459 | os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1460 | { |
| 1461 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1462 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 1463 | static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1464 | path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0); |
| 1465 | int dir_fd = DEFAULT_DIR_FD; |
| 1466 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1467 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1468 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1469 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1470 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1471 | return_value = os_unlink_impl(module, &path, dir_fd); |
| 1472 | |
| 1473 | exit: |
| 1474 | /* Cleanup for path */ |
| 1475 | path_cleanup(&path); |
| 1476 | |
| 1477 | return return_value; |
| 1478 | } |
| 1479 | |
| 1480 | PyDoc_STRVAR(os_remove__doc__, |
| 1481 | "remove($module, /, path, *, dir_fd=None)\n" |
| 1482 | "--\n" |
| 1483 | "\n" |
| 1484 | "Remove a file (same as unlink()).\n" |
| 1485 | "\n" |
| 1486 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1487 | " and path should be relative; path will then be relative to that directory.\n" |
| 1488 | "dir_fd may not be implemented on your platform.\n" |
| 1489 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1490 | |
| 1491 | #define OS_REMOVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1492 | {"remove", (PyCFunction)(void(*)(void))os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1493 | |
| 1494 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1495 | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1496 | |
| 1497 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1498 | os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1499 | { |
| 1500 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1501 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 1502 | static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1503 | path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0); |
| 1504 | int dir_fd = DEFAULT_DIR_FD; |
| 1505 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1506 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1507 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1508 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1509 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1510 | return_value = os_remove_impl(module, &path, dir_fd); |
| 1511 | |
| 1512 | exit: |
| 1513 | /* Cleanup for path */ |
| 1514 | path_cleanup(&path); |
| 1515 | |
| 1516 | return return_value; |
| 1517 | } |
| 1518 | |
| 1519 | #if defined(HAVE_UNAME) |
| 1520 | |
| 1521 | PyDoc_STRVAR(os_uname__doc__, |
| 1522 | "uname($module, /)\n" |
| 1523 | "--\n" |
| 1524 | "\n" |
| 1525 | "Return an object identifying the current operating system.\n" |
| 1526 | "\n" |
| 1527 | "The object behaves like a named tuple with the following fields:\n" |
| 1528 | " (sysname, nodename, release, version, machine)"); |
| 1529 | |
| 1530 | #define OS_UNAME_METHODDEF \ |
| 1531 | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
| 1532 | |
| 1533 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1534 | os_uname_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1535 | |
| 1536 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1537 | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1538 | { |
| 1539 | return os_uname_impl(module); |
| 1540 | } |
| 1541 | |
| 1542 | #endif /* defined(HAVE_UNAME) */ |
| 1543 | |
| 1544 | PyDoc_STRVAR(os_utime__doc__, |
| 1545 | "utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n" |
| 1546 | " follow_symlinks=True)\n" |
| 1547 | "--\n" |
| 1548 | "\n" |
| 1549 | "Set the access and modified time of path.\n" |
| 1550 | "\n" |
| 1551 | "path may always be specified as a string.\n" |
| 1552 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 1553 | " If this functionality is unavailable, using it raises an exception.\n" |
| 1554 | "\n" |
| 1555 | "If times is not None, it must be a tuple (atime, mtime);\n" |
| 1556 | " atime and mtime should be expressed as float seconds since the epoch.\n" |
Martin Panter | 0ff8909 | 2015-09-09 01:56:53 +0000 | [diff] [blame] | 1557 | "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1558 | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
| 1559 | " since the epoch.\n" |
Martin Panter | 0ff8909 | 2015-09-09 01:56:53 +0000 | [diff] [blame] | 1560 | "If times is None and ns is unspecified, utime uses the current time.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1561 | "Specifying tuples for both times and ns is an error.\n" |
| 1562 | "\n" |
| 1563 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1564 | " and path should be relative; path will then be relative to that directory.\n" |
| 1565 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 1566 | " link, utime will modify the symbolic link itself instead of the file the\n" |
| 1567 | " link points to.\n" |
| 1568 | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
| 1569 | " as an open file descriptor.\n" |
| 1570 | "dir_fd and follow_symlinks may not be available on your platform.\n" |
| 1571 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1572 | |
| 1573 | #define OS_UTIME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1574 | {"utime", (PyCFunction)(void(*)(void))os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1575 | |
| 1576 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1577 | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
| 1578 | int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1579 | |
| 1580 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1581 | os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1582 | { |
| 1583 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1584 | static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
| 1585 | static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1586 | path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD); |
| 1587 | PyObject *times = NULL; |
| 1588 | PyObject *ns = NULL; |
| 1589 | int dir_fd = DEFAULT_DIR_FD; |
| 1590 | int follow_symlinks = 1; |
| 1591 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1592 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1593 | path_converter, &path, ×, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1594 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1595 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1596 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
| 1597 | |
| 1598 | exit: |
| 1599 | /* Cleanup for path */ |
| 1600 | path_cleanup(&path); |
| 1601 | |
| 1602 | return return_value; |
| 1603 | } |
| 1604 | |
| 1605 | PyDoc_STRVAR(os__exit__doc__, |
| 1606 | "_exit($module, /, status)\n" |
| 1607 | "--\n" |
| 1608 | "\n" |
| 1609 | "Exit to the system with specified status, without normal exit processing."); |
| 1610 | |
| 1611 | #define OS__EXIT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1612 | {"_exit", (PyCFunction)(void(*)(void))os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1613 | |
| 1614 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1615 | os__exit_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1616 | |
| 1617 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1618 | os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1619 | { |
| 1620 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1621 | static const char * const _keywords[] = {"status", NULL}; |
| 1622 | static _PyArg_Parser _parser = {"i:_exit", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1623 | int status; |
| 1624 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1625 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1626 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1627 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1628 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1629 | return_value = os__exit_impl(module, status); |
| 1630 | |
| 1631 | exit: |
| 1632 | return return_value; |
| 1633 | } |
| 1634 | |
| 1635 | #if defined(HAVE_EXECV) |
| 1636 | |
| 1637 | PyDoc_STRVAR(os_execv__doc__, |
| 1638 | "execv($module, path, argv, /)\n" |
| 1639 | "--\n" |
| 1640 | "\n" |
| 1641 | "Execute an executable path with arguments, replacing current process.\n" |
| 1642 | "\n" |
| 1643 | " path\n" |
| 1644 | " Path of executable file.\n" |
| 1645 | " argv\n" |
| 1646 | " Tuple or list of strings."); |
| 1647 | |
| 1648 | #define OS_EXECV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1649 | {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1650 | |
| 1651 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1652 | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1653 | |
| 1654 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1655 | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1656 | { |
| 1657 | PyObject *return_value = NULL; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1658 | path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1659 | PyObject *argv; |
| 1660 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 1661 | if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1662 | goto exit; |
| 1663 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 1664 | if (!path_converter(args[0], &path)) { |
| 1665 | goto exit; |
| 1666 | } |
| 1667 | argv = args[1]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1668 | return_value = os_execv_impl(module, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1669 | |
| 1670 | exit: |
| 1671 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1672 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1673 | |
| 1674 | return return_value; |
| 1675 | } |
| 1676 | |
| 1677 | #endif /* defined(HAVE_EXECV) */ |
| 1678 | |
| 1679 | #if defined(HAVE_EXECV) |
| 1680 | |
| 1681 | PyDoc_STRVAR(os_execve__doc__, |
| 1682 | "execve($module, /, path, argv, env)\n" |
| 1683 | "--\n" |
| 1684 | "\n" |
| 1685 | "Execute an executable path with arguments, replacing current process.\n" |
| 1686 | "\n" |
| 1687 | " path\n" |
| 1688 | " Path of executable file.\n" |
| 1689 | " argv\n" |
| 1690 | " Tuple or list of strings.\n" |
| 1691 | " env\n" |
| 1692 | " Dictionary of strings mapping to strings."); |
| 1693 | |
| 1694 | #define OS_EXECVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1695 | {"execve", (PyCFunction)(void(*)(void))os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1696 | |
| 1697 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1698 | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1699 | |
| 1700 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1701 | os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1702 | { |
| 1703 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1704 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
| 1705 | static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1706 | path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE); |
| 1707 | PyObject *argv; |
| 1708 | PyObject *env; |
| 1709 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1710 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1711 | path_converter, &path, &argv, &env)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1712 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1713 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1714 | return_value = os_execve_impl(module, &path, argv, env); |
| 1715 | |
| 1716 | exit: |
| 1717 | /* Cleanup for path */ |
| 1718 | path_cleanup(&path); |
| 1719 | |
| 1720 | return return_value; |
| 1721 | } |
| 1722 | |
| 1723 | #endif /* defined(HAVE_EXECV) */ |
| 1724 | |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1725 | #if defined(HAVE_POSIX_SPAWN) |
| 1726 | |
| 1727 | PyDoc_STRVAR(os_posix_spawn__doc__, |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 1728 | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1729 | " setpgroup=None, resetids=False, setsigmask=(),\n" |
| 1730 | " setsigdef=(), scheduler=None)\n" |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1731 | "--\n" |
| 1732 | "\n" |
| 1733 | "Execute the program specified by path in a new process.\n" |
| 1734 | "\n" |
| 1735 | " path\n" |
| 1736 | " Path of executable file.\n" |
| 1737 | " argv\n" |
| 1738 | " Tuple or list of strings.\n" |
| 1739 | " env\n" |
| 1740 | " Dictionary of strings mapping to strings.\n" |
| 1741 | " file_actions\n" |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1742 | " A sequence of file action tuples.\n" |
| 1743 | " setpgroup\n" |
| 1744 | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
| 1745 | " resetids\n" |
| 1746 | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
| 1747 | " setsigmask\n" |
| 1748 | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
| 1749 | " setsigdef\n" |
| 1750 | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
| 1751 | " scheduler\n" |
| 1752 | " A tuple with the scheduler policy (optional) and parameters."); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1753 | |
| 1754 | #define OS_POSIX_SPAWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1755 | {"posix_spawn", (PyCFunction)(void(*)(void))os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__}, |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1756 | |
| 1757 | static PyObject * |
| 1758 | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1759 | PyObject *env, PyObject *file_actions, |
| 1760 | PyObject *setpgroup, int resetids, PyObject *setsigmask, |
| 1761 | PyObject *setsigdef, PyObject *scheduler); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1762 | |
| 1763 | static PyObject * |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1764 | os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1765 | { |
| 1766 | PyObject *return_value = NULL; |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 1767 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL}; |
| 1768 | static _PyArg_Parser _parser = {"O&OO|$OOiOOO:posix_spawn", _keywords, 0}; |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1769 | path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0); |
| 1770 | PyObject *argv; |
| 1771 | PyObject *env; |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 1772 | PyObject *file_actions = NULL; |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1773 | PyObject *setpgroup = NULL; |
| 1774 | int resetids = 0; |
| 1775 | PyObject *setsigmask = NULL; |
| 1776 | PyObject *setsigdef = NULL; |
| 1777 | PyObject *scheduler = NULL; |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1778 | |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1779 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 1780 | path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsigmask, &setsigdef, &scheduler)) { |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1781 | goto exit; |
| 1782 | } |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1783 | return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsigmask, setsigdef, scheduler); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1784 | |
| 1785 | exit: |
| 1786 | /* Cleanup for path */ |
| 1787 | path_cleanup(&path); |
| 1788 | |
| 1789 | return return_value; |
| 1790 | } |
| 1791 | |
| 1792 | #endif /* defined(HAVE_POSIX_SPAWN) */ |
| 1793 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1794 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1795 | |
| 1796 | PyDoc_STRVAR(os_spawnv__doc__, |
| 1797 | "spawnv($module, mode, path, argv, /)\n" |
| 1798 | "--\n" |
| 1799 | "\n" |
| 1800 | "Execute the program specified by path in a new process.\n" |
| 1801 | "\n" |
| 1802 | " mode\n" |
| 1803 | " Mode of process creation.\n" |
| 1804 | " path\n" |
| 1805 | " Path of executable file.\n" |
| 1806 | " argv\n" |
| 1807 | " Tuple or list of strings."); |
| 1808 | |
| 1809 | #define OS_SPAWNV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1810 | {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1811 | |
| 1812 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1813 | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1814 | |
| 1815 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1816 | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1817 | { |
| 1818 | PyObject *return_value = NULL; |
| 1819 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1820 | path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1821 | PyObject *argv; |
| 1822 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 1823 | if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1824 | goto exit; |
| 1825 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 1826 | if (PyFloat_Check(args[0])) { |
| 1827 | PyErr_SetString(PyExc_TypeError, |
| 1828 | "integer argument expected, got float" ); |
| 1829 | goto exit; |
| 1830 | } |
| 1831 | mode = _PyLong_AsInt(args[0]); |
| 1832 | if (mode == -1 && PyErr_Occurred()) { |
| 1833 | goto exit; |
| 1834 | } |
| 1835 | if (!path_converter(args[1], &path)) { |
| 1836 | goto exit; |
| 1837 | } |
| 1838 | argv = args[2]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1839 | return_value = os_spawnv_impl(module, mode, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1840 | |
| 1841 | exit: |
| 1842 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1843 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1844 | |
| 1845 | return return_value; |
| 1846 | } |
| 1847 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1848 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1849 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1850 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1851 | |
| 1852 | PyDoc_STRVAR(os_spawnve__doc__, |
| 1853 | "spawnve($module, mode, path, argv, env, /)\n" |
| 1854 | "--\n" |
| 1855 | "\n" |
| 1856 | "Execute the program specified by path in a new process.\n" |
| 1857 | "\n" |
| 1858 | " mode\n" |
| 1859 | " Mode of process creation.\n" |
| 1860 | " path\n" |
| 1861 | " Path of executable file.\n" |
| 1862 | " argv\n" |
| 1863 | " Tuple or list of strings.\n" |
| 1864 | " env\n" |
| 1865 | " Dictionary of strings mapping to strings."); |
| 1866 | |
| 1867 | #define OS_SPAWNVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1868 | {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1869 | |
| 1870 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1871 | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1872 | PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1873 | |
| 1874 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1875 | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1876 | { |
| 1877 | PyObject *return_value = NULL; |
| 1878 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1879 | path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1880 | PyObject *argv; |
| 1881 | PyObject *env; |
| 1882 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 1883 | if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1884 | goto exit; |
| 1885 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 1886 | if (PyFloat_Check(args[0])) { |
| 1887 | PyErr_SetString(PyExc_TypeError, |
| 1888 | "integer argument expected, got float" ); |
| 1889 | goto exit; |
| 1890 | } |
| 1891 | mode = _PyLong_AsInt(args[0]); |
| 1892 | if (mode == -1 && PyErr_Occurred()) { |
| 1893 | goto exit; |
| 1894 | } |
| 1895 | if (!path_converter(args[1], &path)) { |
| 1896 | goto exit; |
| 1897 | } |
| 1898 | argv = args[2]; |
| 1899 | env = args[3]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1900 | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1901 | |
| 1902 | exit: |
| 1903 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1904 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1905 | |
| 1906 | return return_value; |
| 1907 | } |
| 1908 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1909 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1910 | |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1911 | #if defined(HAVE_FORK) |
| 1912 | |
| 1913 | PyDoc_STRVAR(os_register_at_fork__doc__, |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1914 | "register_at_fork($module, /, *, before=None, after_in_child=None,\n" |
| 1915 | " after_in_parent=None)\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1916 | "--\n" |
| 1917 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1918 | "Register callables to be called when forking a new process.\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1919 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1920 | " before\n" |
| 1921 | " A callable to be called in the parent before the fork() syscall.\n" |
| 1922 | " after_in_child\n" |
| 1923 | " A callable to be called in the child after fork().\n" |
| 1924 | " after_in_parent\n" |
| 1925 | " A callable to be called in the parent after fork().\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1926 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1927 | "\'before\' callbacks are called in reverse order.\n" |
| 1928 | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order."); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1929 | |
| 1930 | #define OS_REGISTER_AT_FORK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1931 | {"register_at_fork", (PyCFunction)(void(*)(void))os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__}, |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1932 | |
| 1933 | static PyObject * |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1934 | os_register_at_fork_impl(PyObject *module, PyObject *before, |
| 1935 | PyObject *after_in_child, PyObject *after_in_parent); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1936 | |
| 1937 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1938 | os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1939 | { |
| 1940 | PyObject *return_value = NULL; |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1941 | static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL}; |
| 1942 | static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0}; |
| 1943 | PyObject *before = NULL; |
| 1944 | PyObject *after_in_child = NULL; |
| 1945 | PyObject *after_in_parent = NULL; |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1946 | |
| 1947 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1948 | &before, &after_in_child, &after_in_parent)) { |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1949 | goto exit; |
| 1950 | } |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1951 | return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1952 | |
| 1953 | exit: |
| 1954 | return return_value; |
| 1955 | } |
| 1956 | |
| 1957 | #endif /* defined(HAVE_FORK) */ |
| 1958 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1959 | #if defined(HAVE_FORK1) |
| 1960 | |
| 1961 | PyDoc_STRVAR(os_fork1__doc__, |
| 1962 | "fork1($module, /)\n" |
| 1963 | "--\n" |
| 1964 | "\n" |
| 1965 | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
| 1966 | "\n" |
| 1967 | "Return 0 to child process and PID of child to parent process."); |
| 1968 | |
| 1969 | #define OS_FORK1_METHODDEF \ |
| 1970 | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
| 1971 | |
| 1972 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1973 | os_fork1_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1974 | |
| 1975 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1976 | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1977 | { |
| 1978 | return os_fork1_impl(module); |
| 1979 | } |
| 1980 | |
| 1981 | #endif /* defined(HAVE_FORK1) */ |
| 1982 | |
| 1983 | #if defined(HAVE_FORK) |
| 1984 | |
| 1985 | PyDoc_STRVAR(os_fork__doc__, |
| 1986 | "fork($module, /)\n" |
| 1987 | "--\n" |
| 1988 | "\n" |
| 1989 | "Fork a child process.\n" |
| 1990 | "\n" |
| 1991 | "Return 0 to child process and PID of child to parent process."); |
| 1992 | |
| 1993 | #define OS_FORK_METHODDEF \ |
| 1994 | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
| 1995 | |
| 1996 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1997 | os_fork_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1998 | |
| 1999 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2000 | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2001 | { |
| 2002 | return os_fork_impl(module); |
| 2003 | } |
| 2004 | |
| 2005 | #endif /* defined(HAVE_FORK) */ |
| 2006 | |
| 2007 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 2008 | |
| 2009 | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
| 2010 | "sched_get_priority_max($module, /, policy)\n" |
| 2011 | "--\n" |
| 2012 | "\n" |
| 2013 | "Get the maximum scheduling priority for policy."); |
| 2014 | |
| 2015 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2016 | {"sched_get_priority_max", (PyCFunction)(void(*)(void))os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2017 | |
| 2018 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2019 | os_sched_get_priority_max_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2020 | |
| 2021 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2022 | os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2023 | { |
| 2024 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2025 | static const char * const _keywords[] = {"policy", NULL}; |
| 2026 | static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2027 | int policy; |
| 2028 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 2029 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2030 | &policy)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2031 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2032 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2033 | return_value = os_sched_get_priority_max_impl(module, policy); |
| 2034 | |
| 2035 | exit: |
| 2036 | return return_value; |
| 2037 | } |
| 2038 | |
| 2039 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 2040 | |
| 2041 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 2042 | |
| 2043 | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
| 2044 | "sched_get_priority_min($module, /, policy)\n" |
| 2045 | "--\n" |
| 2046 | "\n" |
| 2047 | "Get the minimum scheduling priority for policy."); |
| 2048 | |
| 2049 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2050 | {"sched_get_priority_min", (PyCFunction)(void(*)(void))os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2051 | |
| 2052 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2053 | os_sched_get_priority_min_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2054 | |
| 2055 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2056 | os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2057 | { |
| 2058 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2059 | static const char * const _keywords[] = {"policy", NULL}; |
| 2060 | static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2061 | int policy; |
| 2062 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 2063 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2064 | &policy)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2065 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2066 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2067 | return_value = os_sched_get_priority_min_impl(module, policy); |
| 2068 | |
| 2069 | exit: |
| 2070 | return return_value; |
| 2071 | } |
| 2072 | |
| 2073 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 2074 | |
| 2075 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 2076 | |
| 2077 | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
| 2078 | "sched_getscheduler($module, pid, /)\n" |
| 2079 | "--\n" |
| 2080 | "\n" |
| 2081 | "Get the scheduling policy for the process identifiedy by pid.\n" |
| 2082 | "\n" |
| 2083 | "Passing 0 for pid returns the scheduling policy for the calling process."); |
| 2084 | |
| 2085 | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2086 | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2087 | |
| 2088 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2089 | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2090 | |
| 2091 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2092 | os_sched_getscheduler(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2093 | { |
| 2094 | PyObject *return_value = NULL; |
| 2095 | pid_t pid; |
| 2096 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2097 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2098 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2099 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2100 | return_value = os_sched_getscheduler_impl(module, pid); |
| 2101 | |
| 2102 | exit: |
| 2103 | return return_value; |
| 2104 | } |
| 2105 | |
| 2106 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 2107 | |
William Orr | 81574b8 | 2018-10-01 22:19:56 -0700 | [diff] [blame] | 2108 | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2109 | |
| 2110 | PyDoc_STRVAR(os_sched_param__doc__, |
| 2111 | "sched_param(sched_priority)\n" |
| 2112 | "--\n" |
| 2113 | "\n" |
| 2114 | "Current has only one field: sched_priority\");\n" |
| 2115 | "\n" |
| 2116 | " sched_priority\n" |
| 2117 | " A scheduling parameter."); |
| 2118 | |
| 2119 | static PyObject * |
| 2120 | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
| 2121 | |
| 2122 | static PyObject * |
| 2123 | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 2124 | { |
| 2125 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2126 | static const char * const _keywords[] = {"sched_priority", NULL}; |
| 2127 | static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2128 | PyObject *sched_priority; |
| 2129 | |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2130 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2131 | &sched_priority)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2132 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2133 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2134 | return_value = os_sched_param_impl(type, sched_priority); |
| 2135 | |
| 2136 | exit: |
| 2137 | return return_value; |
| 2138 | } |
| 2139 | |
William Orr | 81574b8 | 2018-10-01 22:19:56 -0700 | [diff] [blame] | 2140 | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2141 | |
| 2142 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 2143 | |
| 2144 | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
| 2145 | "sched_setscheduler($module, pid, policy, param, /)\n" |
| 2146 | "--\n" |
| 2147 | "\n" |
| 2148 | "Set the scheduling policy for the process identified by pid.\n" |
| 2149 | "\n" |
| 2150 | "If pid is 0, the calling process is changed.\n" |
| 2151 | "param is an instance of sched_param."); |
| 2152 | |
| 2153 | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2154 | {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2155 | |
| 2156 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2157 | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2158 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2159 | |
| 2160 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2161 | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2162 | { |
| 2163 | PyObject *return_value = NULL; |
| 2164 | pid_t pid; |
| 2165 | int policy; |
| 2166 | struct sched_param param; |
| 2167 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2168 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler", |
| 2169 | &pid, &policy, convert_sched_param, ¶m)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2170 | goto exit; |
| 2171 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2172 | return_value = os_sched_setscheduler_impl(module, pid, policy, ¶m); |
| 2173 | |
| 2174 | exit: |
| 2175 | return return_value; |
| 2176 | } |
| 2177 | |
| 2178 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 2179 | |
| 2180 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2181 | |
| 2182 | PyDoc_STRVAR(os_sched_getparam__doc__, |
| 2183 | "sched_getparam($module, pid, /)\n" |
| 2184 | "--\n" |
| 2185 | "\n" |
| 2186 | "Returns scheduling parameters for the process identified by pid.\n" |
| 2187 | "\n" |
| 2188 | "If pid is 0, returns parameters for the calling process.\n" |
| 2189 | "Return value is an instance of sched_param."); |
| 2190 | |
| 2191 | #define OS_SCHED_GETPARAM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2192 | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2193 | |
| 2194 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2195 | os_sched_getparam_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2196 | |
| 2197 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2198 | os_sched_getparam(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2199 | { |
| 2200 | PyObject *return_value = NULL; |
| 2201 | pid_t pid; |
| 2202 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2203 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2204 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2205 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2206 | return_value = os_sched_getparam_impl(module, pid); |
| 2207 | |
| 2208 | exit: |
| 2209 | return return_value; |
| 2210 | } |
| 2211 | |
| 2212 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2213 | |
| 2214 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2215 | |
| 2216 | PyDoc_STRVAR(os_sched_setparam__doc__, |
| 2217 | "sched_setparam($module, pid, param, /)\n" |
| 2218 | "--\n" |
| 2219 | "\n" |
| 2220 | "Set scheduling parameters for the process identified by pid.\n" |
| 2221 | "\n" |
| 2222 | "If pid is 0, sets parameters for the calling process.\n" |
| 2223 | "param should be an instance of sched_param."); |
| 2224 | |
| 2225 | #define OS_SCHED_SETPARAM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2226 | {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2227 | |
| 2228 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2229 | os_sched_setparam_impl(PyObject *module, pid_t pid, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2230 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2231 | |
| 2232 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2233 | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2234 | { |
| 2235 | PyObject *return_value = NULL; |
| 2236 | pid_t pid; |
| 2237 | struct sched_param param; |
| 2238 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2239 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam", |
| 2240 | &pid, convert_sched_param, ¶m)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2241 | goto exit; |
| 2242 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2243 | return_value = os_sched_setparam_impl(module, pid, ¶m); |
| 2244 | |
| 2245 | exit: |
| 2246 | return return_value; |
| 2247 | } |
| 2248 | |
| 2249 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2250 | |
| 2251 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
| 2252 | |
| 2253 | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
| 2254 | "sched_rr_get_interval($module, pid, /)\n" |
| 2255 | "--\n" |
| 2256 | "\n" |
| 2257 | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
| 2258 | "\n" |
| 2259 | "Value returned is a float."); |
| 2260 | |
| 2261 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2262 | {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2263 | |
| 2264 | static double |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2265 | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2266 | |
| 2267 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2268 | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2269 | { |
| 2270 | PyObject *return_value = NULL; |
| 2271 | pid_t pid; |
| 2272 | double _return_value; |
| 2273 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2274 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2275 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2276 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2277 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2278 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2279 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2280 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2281 | return_value = PyFloat_FromDouble(_return_value); |
| 2282 | |
| 2283 | exit: |
| 2284 | return return_value; |
| 2285 | } |
| 2286 | |
| 2287 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
| 2288 | |
| 2289 | #if defined(HAVE_SCHED_H) |
| 2290 | |
| 2291 | PyDoc_STRVAR(os_sched_yield__doc__, |
| 2292 | "sched_yield($module, /)\n" |
| 2293 | "--\n" |
| 2294 | "\n" |
| 2295 | "Voluntarily relinquish the CPU."); |
| 2296 | |
| 2297 | #define OS_SCHED_YIELD_METHODDEF \ |
| 2298 | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
| 2299 | |
| 2300 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2301 | os_sched_yield_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2302 | |
| 2303 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2304 | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2305 | { |
| 2306 | return os_sched_yield_impl(module); |
| 2307 | } |
| 2308 | |
| 2309 | #endif /* defined(HAVE_SCHED_H) */ |
| 2310 | |
| 2311 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 2312 | |
| 2313 | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
| 2314 | "sched_setaffinity($module, pid, mask, /)\n" |
| 2315 | "--\n" |
| 2316 | "\n" |
| 2317 | "Set the CPU affinity of the process identified by pid to mask.\n" |
| 2318 | "\n" |
| 2319 | "mask should be an iterable of integers identifying CPUs."); |
| 2320 | |
| 2321 | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2322 | {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2323 | |
| 2324 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2325 | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2326 | |
| 2327 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2328 | os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2329 | { |
| 2330 | PyObject *return_value = NULL; |
| 2331 | pid_t pid; |
| 2332 | PyObject *mask; |
| 2333 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2334 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity", |
| 2335 | &pid, &mask)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2336 | goto exit; |
| 2337 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2338 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
| 2339 | |
| 2340 | exit: |
| 2341 | return return_value; |
| 2342 | } |
| 2343 | |
| 2344 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 2345 | |
| 2346 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 2347 | |
| 2348 | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
| 2349 | "sched_getaffinity($module, pid, /)\n" |
| 2350 | "--\n" |
| 2351 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 2352 | "Return the affinity of the process identified by pid (or the current process if zero).\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2353 | "\n" |
| 2354 | "The affinity is returned as a set of CPU identifiers."); |
| 2355 | |
| 2356 | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2357 | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2358 | |
| 2359 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2360 | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2361 | |
| 2362 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2363 | os_sched_getaffinity(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2364 | { |
| 2365 | PyObject *return_value = NULL; |
| 2366 | pid_t pid; |
| 2367 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2368 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2369 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2370 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2371 | return_value = os_sched_getaffinity_impl(module, pid); |
| 2372 | |
| 2373 | exit: |
| 2374 | return return_value; |
| 2375 | } |
| 2376 | |
| 2377 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 2378 | |
| 2379 | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
| 2380 | |
| 2381 | PyDoc_STRVAR(os_openpty__doc__, |
| 2382 | "openpty($module, /)\n" |
| 2383 | "--\n" |
| 2384 | "\n" |
| 2385 | "Open a pseudo-terminal.\n" |
| 2386 | "\n" |
| 2387 | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
| 2388 | "for both the master and slave ends."); |
| 2389 | |
| 2390 | #define OS_OPENPTY_METHODDEF \ |
| 2391 | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
| 2392 | |
| 2393 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2394 | os_openpty_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2395 | |
| 2396 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2397 | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2398 | { |
| 2399 | return os_openpty_impl(module); |
| 2400 | } |
| 2401 | |
| 2402 | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
| 2403 | |
| 2404 | #if defined(HAVE_FORKPTY) |
| 2405 | |
| 2406 | PyDoc_STRVAR(os_forkpty__doc__, |
| 2407 | "forkpty($module, /)\n" |
| 2408 | "--\n" |
| 2409 | "\n" |
| 2410 | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
| 2411 | "\n" |
| 2412 | "Returns a tuple of (pid, master_fd).\n" |
| 2413 | "Like fork(), return pid of 0 to the child process,\n" |
| 2414 | "and pid of child to the parent process.\n" |
| 2415 | "To both, return fd of newly opened pseudo-terminal."); |
| 2416 | |
| 2417 | #define OS_FORKPTY_METHODDEF \ |
| 2418 | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
| 2419 | |
| 2420 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2421 | os_forkpty_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2422 | |
| 2423 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2424 | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2425 | { |
| 2426 | return os_forkpty_impl(module); |
| 2427 | } |
| 2428 | |
| 2429 | #endif /* defined(HAVE_FORKPTY) */ |
| 2430 | |
| 2431 | #if defined(HAVE_GETEGID) |
| 2432 | |
| 2433 | PyDoc_STRVAR(os_getegid__doc__, |
| 2434 | "getegid($module, /)\n" |
| 2435 | "--\n" |
| 2436 | "\n" |
| 2437 | "Return the current process\'s effective group id."); |
| 2438 | |
| 2439 | #define OS_GETEGID_METHODDEF \ |
| 2440 | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
| 2441 | |
| 2442 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2443 | os_getegid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2444 | |
| 2445 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2446 | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2447 | { |
| 2448 | return os_getegid_impl(module); |
| 2449 | } |
| 2450 | |
| 2451 | #endif /* defined(HAVE_GETEGID) */ |
| 2452 | |
| 2453 | #if defined(HAVE_GETEUID) |
| 2454 | |
| 2455 | PyDoc_STRVAR(os_geteuid__doc__, |
| 2456 | "geteuid($module, /)\n" |
| 2457 | "--\n" |
| 2458 | "\n" |
| 2459 | "Return the current process\'s effective user id."); |
| 2460 | |
| 2461 | #define OS_GETEUID_METHODDEF \ |
| 2462 | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
| 2463 | |
| 2464 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2465 | os_geteuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2466 | |
| 2467 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2468 | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2469 | { |
| 2470 | return os_geteuid_impl(module); |
| 2471 | } |
| 2472 | |
| 2473 | #endif /* defined(HAVE_GETEUID) */ |
| 2474 | |
| 2475 | #if defined(HAVE_GETGID) |
| 2476 | |
| 2477 | PyDoc_STRVAR(os_getgid__doc__, |
| 2478 | "getgid($module, /)\n" |
| 2479 | "--\n" |
| 2480 | "\n" |
| 2481 | "Return the current process\'s group id."); |
| 2482 | |
| 2483 | #define OS_GETGID_METHODDEF \ |
| 2484 | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
| 2485 | |
| 2486 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2487 | os_getgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2488 | |
| 2489 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2490 | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2491 | { |
| 2492 | return os_getgid_impl(module); |
| 2493 | } |
| 2494 | |
| 2495 | #endif /* defined(HAVE_GETGID) */ |
| 2496 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 2497 | #if defined(HAVE_GETPID) |
| 2498 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2499 | PyDoc_STRVAR(os_getpid__doc__, |
| 2500 | "getpid($module, /)\n" |
| 2501 | "--\n" |
| 2502 | "\n" |
| 2503 | "Return the current process id."); |
| 2504 | |
| 2505 | #define OS_GETPID_METHODDEF \ |
| 2506 | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
| 2507 | |
| 2508 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2509 | os_getpid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2510 | |
| 2511 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2512 | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2513 | { |
| 2514 | return os_getpid_impl(module); |
| 2515 | } |
| 2516 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 2517 | #endif /* defined(HAVE_GETPID) */ |
| 2518 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2519 | #if defined(HAVE_GETGROUPS) |
| 2520 | |
| 2521 | PyDoc_STRVAR(os_getgroups__doc__, |
| 2522 | "getgroups($module, /)\n" |
| 2523 | "--\n" |
| 2524 | "\n" |
| 2525 | "Return list of supplemental group IDs for the process."); |
| 2526 | |
| 2527 | #define OS_GETGROUPS_METHODDEF \ |
| 2528 | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
| 2529 | |
| 2530 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2531 | os_getgroups_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2532 | |
| 2533 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2534 | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2535 | { |
| 2536 | return os_getgroups_impl(module); |
| 2537 | } |
| 2538 | |
| 2539 | #endif /* defined(HAVE_GETGROUPS) */ |
| 2540 | |
| 2541 | #if defined(HAVE_GETPGID) |
| 2542 | |
| 2543 | PyDoc_STRVAR(os_getpgid__doc__, |
| 2544 | "getpgid($module, /, pid)\n" |
| 2545 | "--\n" |
| 2546 | "\n" |
| 2547 | "Call the system call getpgid(), and return the result."); |
| 2548 | |
| 2549 | #define OS_GETPGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2550 | {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2551 | |
| 2552 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2553 | os_getpgid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2554 | |
| 2555 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2556 | os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2557 | { |
| 2558 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2559 | static const char * const _keywords[] = {"pid", NULL}; |
| 2560 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2561 | pid_t pid; |
| 2562 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 2563 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2564 | &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2565 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2566 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2567 | return_value = os_getpgid_impl(module, pid); |
| 2568 | |
| 2569 | exit: |
| 2570 | return return_value; |
| 2571 | } |
| 2572 | |
| 2573 | #endif /* defined(HAVE_GETPGID) */ |
| 2574 | |
| 2575 | #if defined(HAVE_GETPGRP) |
| 2576 | |
| 2577 | PyDoc_STRVAR(os_getpgrp__doc__, |
| 2578 | "getpgrp($module, /)\n" |
| 2579 | "--\n" |
| 2580 | "\n" |
| 2581 | "Return the current process group id."); |
| 2582 | |
| 2583 | #define OS_GETPGRP_METHODDEF \ |
| 2584 | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
| 2585 | |
| 2586 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2587 | os_getpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2588 | |
| 2589 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2590 | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2591 | { |
| 2592 | return os_getpgrp_impl(module); |
| 2593 | } |
| 2594 | |
| 2595 | #endif /* defined(HAVE_GETPGRP) */ |
| 2596 | |
| 2597 | #if defined(HAVE_SETPGRP) |
| 2598 | |
| 2599 | PyDoc_STRVAR(os_setpgrp__doc__, |
| 2600 | "setpgrp($module, /)\n" |
| 2601 | "--\n" |
| 2602 | "\n" |
| 2603 | "Make the current process the leader of its process group."); |
| 2604 | |
| 2605 | #define OS_SETPGRP_METHODDEF \ |
| 2606 | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
| 2607 | |
| 2608 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2609 | os_setpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2610 | |
| 2611 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2612 | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2613 | { |
| 2614 | return os_setpgrp_impl(module); |
| 2615 | } |
| 2616 | |
| 2617 | #endif /* defined(HAVE_SETPGRP) */ |
| 2618 | |
| 2619 | #if defined(HAVE_GETPPID) |
| 2620 | |
| 2621 | PyDoc_STRVAR(os_getppid__doc__, |
| 2622 | "getppid($module, /)\n" |
| 2623 | "--\n" |
| 2624 | "\n" |
| 2625 | "Return the parent\'s process id.\n" |
| 2626 | "\n" |
| 2627 | "If the parent process has already exited, Windows machines will still\n" |
| 2628 | "return its id; others systems will return the id of the \'init\' process (1)."); |
| 2629 | |
| 2630 | #define OS_GETPPID_METHODDEF \ |
| 2631 | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
| 2632 | |
| 2633 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2634 | os_getppid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2635 | |
| 2636 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2637 | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2638 | { |
| 2639 | return os_getppid_impl(module); |
| 2640 | } |
| 2641 | |
| 2642 | #endif /* defined(HAVE_GETPPID) */ |
| 2643 | |
| 2644 | #if defined(HAVE_GETLOGIN) |
| 2645 | |
| 2646 | PyDoc_STRVAR(os_getlogin__doc__, |
| 2647 | "getlogin($module, /)\n" |
| 2648 | "--\n" |
| 2649 | "\n" |
| 2650 | "Return the actual login name."); |
| 2651 | |
| 2652 | #define OS_GETLOGIN_METHODDEF \ |
| 2653 | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
| 2654 | |
| 2655 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2656 | os_getlogin_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2657 | |
| 2658 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2659 | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2660 | { |
| 2661 | return os_getlogin_impl(module); |
| 2662 | } |
| 2663 | |
| 2664 | #endif /* defined(HAVE_GETLOGIN) */ |
| 2665 | |
| 2666 | #if defined(HAVE_GETUID) |
| 2667 | |
| 2668 | PyDoc_STRVAR(os_getuid__doc__, |
| 2669 | "getuid($module, /)\n" |
| 2670 | "--\n" |
| 2671 | "\n" |
| 2672 | "Return the current process\'s user id."); |
| 2673 | |
| 2674 | #define OS_GETUID_METHODDEF \ |
| 2675 | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
| 2676 | |
| 2677 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2678 | os_getuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2679 | |
| 2680 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2681 | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2682 | { |
| 2683 | return os_getuid_impl(module); |
| 2684 | } |
| 2685 | |
| 2686 | #endif /* defined(HAVE_GETUID) */ |
| 2687 | |
| 2688 | #if defined(HAVE_KILL) |
| 2689 | |
| 2690 | PyDoc_STRVAR(os_kill__doc__, |
| 2691 | "kill($module, pid, signal, /)\n" |
| 2692 | "--\n" |
| 2693 | "\n" |
| 2694 | "Kill a process with a signal."); |
| 2695 | |
| 2696 | #define OS_KILL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2697 | {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2698 | |
| 2699 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2700 | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2701 | |
| 2702 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2703 | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2704 | { |
| 2705 | PyObject *return_value = NULL; |
| 2706 | pid_t pid; |
| 2707 | Py_ssize_t signal; |
| 2708 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2709 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill", |
| 2710 | &pid, &signal)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2711 | goto exit; |
| 2712 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2713 | return_value = os_kill_impl(module, pid, signal); |
| 2714 | |
| 2715 | exit: |
| 2716 | return return_value; |
| 2717 | } |
| 2718 | |
| 2719 | #endif /* defined(HAVE_KILL) */ |
| 2720 | |
| 2721 | #if defined(HAVE_KILLPG) |
| 2722 | |
| 2723 | PyDoc_STRVAR(os_killpg__doc__, |
| 2724 | "killpg($module, pgid, signal, /)\n" |
| 2725 | "--\n" |
| 2726 | "\n" |
| 2727 | "Kill a process group with a signal."); |
| 2728 | |
| 2729 | #define OS_KILLPG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2730 | {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2731 | |
| 2732 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2733 | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2734 | |
| 2735 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2736 | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2737 | { |
| 2738 | PyObject *return_value = NULL; |
| 2739 | pid_t pgid; |
| 2740 | int signal; |
| 2741 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2742 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg", |
| 2743 | &pgid, &signal)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2744 | goto exit; |
| 2745 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2746 | return_value = os_killpg_impl(module, pgid, signal); |
| 2747 | |
| 2748 | exit: |
| 2749 | return return_value; |
| 2750 | } |
| 2751 | |
| 2752 | #endif /* defined(HAVE_KILLPG) */ |
| 2753 | |
| 2754 | #if defined(HAVE_PLOCK) |
| 2755 | |
| 2756 | PyDoc_STRVAR(os_plock__doc__, |
| 2757 | "plock($module, op, /)\n" |
| 2758 | "--\n" |
| 2759 | "\n" |
| 2760 | "Lock program segments into memory.\");"); |
| 2761 | |
| 2762 | #define OS_PLOCK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2763 | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2764 | |
| 2765 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2766 | os_plock_impl(PyObject *module, int op); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2767 | |
| 2768 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2769 | os_plock(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2770 | { |
| 2771 | PyObject *return_value = NULL; |
| 2772 | int op; |
| 2773 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 2774 | if (PyFloat_Check(arg)) { |
| 2775 | PyErr_SetString(PyExc_TypeError, |
| 2776 | "integer argument expected, got float" ); |
| 2777 | goto exit; |
| 2778 | } |
| 2779 | op = _PyLong_AsInt(arg); |
| 2780 | if (op == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2781 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2782 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2783 | return_value = os_plock_impl(module, op); |
| 2784 | |
| 2785 | exit: |
| 2786 | return return_value; |
| 2787 | } |
| 2788 | |
| 2789 | #endif /* defined(HAVE_PLOCK) */ |
| 2790 | |
| 2791 | #if defined(HAVE_SETUID) |
| 2792 | |
| 2793 | PyDoc_STRVAR(os_setuid__doc__, |
| 2794 | "setuid($module, uid, /)\n" |
| 2795 | "--\n" |
| 2796 | "\n" |
| 2797 | "Set the current process\'s user id."); |
| 2798 | |
| 2799 | #define OS_SETUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2800 | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2801 | |
| 2802 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2803 | os_setuid_impl(PyObject *module, uid_t uid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2804 | |
| 2805 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2806 | os_setuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2807 | { |
| 2808 | PyObject *return_value = NULL; |
| 2809 | uid_t uid; |
| 2810 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 2811 | if (!_Py_Uid_Converter(arg, &uid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2812 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2813 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2814 | return_value = os_setuid_impl(module, uid); |
| 2815 | |
| 2816 | exit: |
| 2817 | return return_value; |
| 2818 | } |
| 2819 | |
| 2820 | #endif /* defined(HAVE_SETUID) */ |
| 2821 | |
| 2822 | #if defined(HAVE_SETEUID) |
| 2823 | |
| 2824 | PyDoc_STRVAR(os_seteuid__doc__, |
| 2825 | "seteuid($module, euid, /)\n" |
| 2826 | "--\n" |
| 2827 | "\n" |
| 2828 | "Set the current process\'s effective user id."); |
| 2829 | |
| 2830 | #define OS_SETEUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2831 | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2832 | |
| 2833 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2834 | os_seteuid_impl(PyObject *module, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2835 | |
| 2836 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2837 | os_seteuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2838 | { |
| 2839 | PyObject *return_value = NULL; |
| 2840 | uid_t euid; |
| 2841 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 2842 | if (!_Py_Uid_Converter(arg, &euid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2843 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2844 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2845 | return_value = os_seteuid_impl(module, euid); |
| 2846 | |
| 2847 | exit: |
| 2848 | return return_value; |
| 2849 | } |
| 2850 | |
| 2851 | #endif /* defined(HAVE_SETEUID) */ |
| 2852 | |
| 2853 | #if defined(HAVE_SETEGID) |
| 2854 | |
| 2855 | PyDoc_STRVAR(os_setegid__doc__, |
| 2856 | "setegid($module, egid, /)\n" |
| 2857 | "--\n" |
| 2858 | "\n" |
| 2859 | "Set the current process\'s effective group id."); |
| 2860 | |
| 2861 | #define OS_SETEGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2862 | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2863 | |
| 2864 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2865 | os_setegid_impl(PyObject *module, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2866 | |
| 2867 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2868 | os_setegid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2869 | { |
| 2870 | PyObject *return_value = NULL; |
| 2871 | gid_t egid; |
| 2872 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 2873 | if (!_Py_Gid_Converter(arg, &egid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2874 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2875 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2876 | return_value = os_setegid_impl(module, egid); |
| 2877 | |
| 2878 | exit: |
| 2879 | return return_value; |
| 2880 | } |
| 2881 | |
| 2882 | #endif /* defined(HAVE_SETEGID) */ |
| 2883 | |
| 2884 | #if defined(HAVE_SETREUID) |
| 2885 | |
| 2886 | PyDoc_STRVAR(os_setreuid__doc__, |
| 2887 | "setreuid($module, ruid, euid, /)\n" |
| 2888 | "--\n" |
| 2889 | "\n" |
| 2890 | "Set the current process\'s real and effective user ids."); |
| 2891 | |
| 2892 | #define OS_SETREUID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2893 | {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2894 | |
| 2895 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2896 | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2897 | |
| 2898 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2899 | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2900 | { |
| 2901 | PyObject *return_value = NULL; |
| 2902 | uid_t ruid; |
| 2903 | uid_t euid; |
| 2904 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 2905 | if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { |
| 2906 | goto exit; |
| 2907 | } |
| 2908 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
| 2909 | goto exit; |
| 2910 | } |
| 2911 | if (!_Py_Uid_Converter(args[1], &euid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2912 | goto exit; |
| 2913 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2914 | return_value = os_setreuid_impl(module, ruid, euid); |
| 2915 | |
| 2916 | exit: |
| 2917 | return return_value; |
| 2918 | } |
| 2919 | |
| 2920 | #endif /* defined(HAVE_SETREUID) */ |
| 2921 | |
| 2922 | #if defined(HAVE_SETREGID) |
| 2923 | |
| 2924 | PyDoc_STRVAR(os_setregid__doc__, |
| 2925 | "setregid($module, rgid, egid, /)\n" |
| 2926 | "--\n" |
| 2927 | "\n" |
| 2928 | "Set the current process\'s real and effective group ids."); |
| 2929 | |
| 2930 | #define OS_SETREGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2931 | {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2932 | |
| 2933 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2934 | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2935 | |
| 2936 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2937 | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2938 | { |
| 2939 | PyObject *return_value = NULL; |
| 2940 | gid_t rgid; |
| 2941 | gid_t egid; |
| 2942 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 2943 | if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { |
| 2944 | goto exit; |
| 2945 | } |
| 2946 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
| 2947 | goto exit; |
| 2948 | } |
| 2949 | if (!_Py_Gid_Converter(args[1], &egid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2950 | goto exit; |
| 2951 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2952 | return_value = os_setregid_impl(module, rgid, egid); |
| 2953 | |
| 2954 | exit: |
| 2955 | return return_value; |
| 2956 | } |
| 2957 | |
| 2958 | #endif /* defined(HAVE_SETREGID) */ |
| 2959 | |
| 2960 | #if defined(HAVE_SETGID) |
| 2961 | |
| 2962 | PyDoc_STRVAR(os_setgid__doc__, |
| 2963 | "setgid($module, gid, /)\n" |
| 2964 | "--\n" |
| 2965 | "\n" |
| 2966 | "Set the current process\'s group id."); |
| 2967 | |
| 2968 | #define OS_SETGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2969 | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2970 | |
| 2971 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2972 | os_setgid_impl(PyObject *module, gid_t gid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2973 | |
| 2974 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2975 | os_setgid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2976 | { |
| 2977 | PyObject *return_value = NULL; |
| 2978 | gid_t gid; |
| 2979 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 2980 | if (!_Py_Gid_Converter(arg, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2981 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2982 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2983 | return_value = os_setgid_impl(module, gid); |
| 2984 | |
| 2985 | exit: |
| 2986 | return return_value; |
| 2987 | } |
| 2988 | |
| 2989 | #endif /* defined(HAVE_SETGID) */ |
| 2990 | |
| 2991 | #if defined(HAVE_SETGROUPS) |
| 2992 | |
| 2993 | PyDoc_STRVAR(os_setgroups__doc__, |
| 2994 | "setgroups($module, groups, /)\n" |
| 2995 | "--\n" |
| 2996 | "\n" |
| 2997 | "Set the groups of the current process to list."); |
| 2998 | |
| 2999 | #define OS_SETGROUPS_METHODDEF \ |
| 3000 | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
| 3001 | |
| 3002 | #endif /* defined(HAVE_SETGROUPS) */ |
| 3003 | |
| 3004 | #if defined(HAVE_WAIT3) |
| 3005 | |
| 3006 | PyDoc_STRVAR(os_wait3__doc__, |
| 3007 | "wait3($module, /, options)\n" |
| 3008 | "--\n" |
| 3009 | "\n" |
| 3010 | "Wait for completion of a child process.\n" |
| 3011 | "\n" |
| 3012 | "Returns a tuple of information about the child process:\n" |
| 3013 | " (pid, status, rusage)"); |
| 3014 | |
| 3015 | #define OS_WAIT3_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3016 | {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3017 | |
| 3018 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3019 | os_wait3_impl(PyObject *module, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3020 | |
| 3021 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3022 | os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3023 | { |
| 3024 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3025 | static const char * const _keywords[] = {"options", NULL}; |
| 3026 | static _PyArg_Parser _parser = {"i:wait3", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3027 | int options; |
| 3028 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3029 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3030 | &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3031 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3032 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3033 | return_value = os_wait3_impl(module, options); |
| 3034 | |
| 3035 | exit: |
| 3036 | return return_value; |
| 3037 | } |
| 3038 | |
| 3039 | #endif /* defined(HAVE_WAIT3) */ |
| 3040 | |
| 3041 | #if defined(HAVE_WAIT4) |
| 3042 | |
| 3043 | PyDoc_STRVAR(os_wait4__doc__, |
| 3044 | "wait4($module, /, pid, options)\n" |
| 3045 | "--\n" |
| 3046 | "\n" |
| 3047 | "Wait for completion of a specific child process.\n" |
| 3048 | "\n" |
| 3049 | "Returns a tuple of information about the child process:\n" |
| 3050 | " (pid, status, rusage)"); |
| 3051 | |
| 3052 | #define OS_WAIT4_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3053 | {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3054 | |
| 3055 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3056 | os_wait4_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3057 | |
| 3058 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3059 | os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3060 | { |
| 3061 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3062 | static const char * const _keywords[] = {"pid", "options", NULL}; |
| 3063 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3064 | pid_t pid; |
| 3065 | int options; |
| 3066 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3067 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3068 | &pid, &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3069 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3070 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3071 | return_value = os_wait4_impl(module, pid, options); |
| 3072 | |
| 3073 | exit: |
| 3074 | return return_value; |
| 3075 | } |
| 3076 | |
| 3077 | #endif /* defined(HAVE_WAIT4) */ |
| 3078 | |
| 3079 | #if (defined(HAVE_WAITID) && !defined(__APPLE__)) |
| 3080 | |
| 3081 | PyDoc_STRVAR(os_waitid__doc__, |
| 3082 | "waitid($module, idtype, id, options, /)\n" |
| 3083 | "--\n" |
| 3084 | "\n" |
| 3085 | "Returns the result of waiting for a process or processes.\n" |
| 3086 | "\n" |
| 3087 | " idtype\n" |
| 3088 | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
| 3089 | " id\n" |
| 3090 | " The id to wait on.\n" |
| 3091 | " options\n" |
| 3092 | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
| 3093 | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
| 3094 | "\n" |
| 3095 | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
| 3096 | "no children in a waitable state."); |
| 3097 | |
| 3098 | #define OS_WAITID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3099 | {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3100 | |
| 3101 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3102 | os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3103 | |
| 3104 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3105 | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3106 | { |
| 3107 | PyObject *return_value = NULL; |
| 3108 | idtype_t idtype; |
| 3109 | id_t id; |
| 3110 | int options; |
| 3111 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3112 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid", |
| 3113 | &idtype, &id, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3114 | goto exit; |
| 3115 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3116 | return_value = os_waitid_impl(module, idtype, id, options); |
| 3117 | |
| 3118 | exit: |
| 3119 | return return_value; |
| 3120 | } |
| 3121 | |
| 3122 | #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */ |
| 3123 | |
| 3124 | #if defined(HAVE_WAITPID) |
| 3125 | |
| 3126 | PyDoc_STRVAR(os_waitpid__doc__, |
| 3127 | "waitpid($module, pid, options, /)\n" |
| 3128 | "--\n" |
| 3129 | "\n" |
| 3130 | "Wait for completion of a given child process.\n" |
| 3131 | "\n" |
| 3132 | "Returns a tuple of information regarding the child process:\n" |
| 3133 | " (pid, status)\n" |
| 3134 | "\n" |
| 3135 | "The options argument is ignored on Windows."); |
| 3136 | |
| 3137 | #define OS_WAITPID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3138 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3139 | |
| 3140 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3141 | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3142 | |
| 3143 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3144 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3145 | { |
| 3146 | PyObject *return_value = NULL; |
| 3147 | pid_t pid; |
| 3148 | int options; |
| 3149 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3150 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid", |
| 3151 | &pid, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3152 | goto exit; |
| 3153 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3154 | return_value = os_waitpid_impl(module, pid, options); |
| 3155 | |
| 3156 | exit: |
| 3157 | return return_value; |
| 3158 | } |
| 3159 | |
| 3160 | #endif /* defined(HAVE_WAITPID) */ |
| 3161 | |
| 3162 | #if defined(HAVE_CWAIT) |
| 3163 | |
| 3164 | PyDoc_STRVAR(os_waitpid__doc__, |
| 3165 | "waitpid($module, pid, options, /)\n" |
| 3166 | "--\n" |
| 3167 | "\n" |
| 3168 | "Wait for completion of a given process.\n" |
| 3169 | "\n" |
| 3170 | "Returns a tuple of information regarding the process:\n" |
| 3171 | " (pid, status << 8)\n" |
| 3172 | "\n" |
| 3173 | "The options argument is ignored on Windows."); |
| 3174 | |
| 3175 | #define OS_WAITPID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3176 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3177 | |
| 3178 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3179 | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3180 | |
| 3181 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3182 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3183 | { |
| 3184 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3185 | intptr_t pid; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3186 | int options; |
| 3187 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3188 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid", |
| 3189 | &pid, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3190 | goto exit; |
| 3191 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3192 | return_value = os_waitpid_impl(module, pid, options); |
| 3193 | |
| 3194 | exit: |
| 3195 | return return_value; |
| 3196 | } |
| 3197 | |
| 3198 | #endif /* defined(HAVE_CWAIT) */ |
| 3199 | |
| 3200 | #if defined(HAVE_WAIT) |
| 3201 | |
| 3202 | PyDoc_STRVAR(os_wait__doc__, |
| 3203 | "wait($module, /)\n" |
| 3204 | "--\n" |
| 3205 | "\n" |
| 3206 | "Wait for completion of a child process.\n" |
| 3207 | "\n" |
| 3208 | "Returns a tuple of information about the child process:\n" |
| 3209 | " (pid, status)"); |
| 3210 | |
| 3211 | #define OS_WAIT_METHODDEF \ |
| 3212 | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
| 3213 | |
| 3214 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3215 | os_wait_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3216 | |
| 3217 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3218 | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3219 | { |
| 3220 | return os_wait_impl(module); |
| 3221 | } |
| 3222 | |
| 3223 | #endif /* defined(HAVE_WAIT) */ |
| 3224 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 3225 | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
| 3226 | |
| 3227 | PyDoc_STRVAR(os_readlink__doc__, |
| 3228 | "readlink($module, /, path, *, dir_fd=None)\n" |
| 3229 | "--\n" |
| 3230 | "\n" |
| 3231 | "Return a string representing the path to which the symbolic link points.\n" |
| 3232 | "\n" |
| 3233 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3234 | "and path should be relative; path will then be relative to that directory.\n" |
| 3235 | "\n" |
| 3236 | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
| 3237 | "using it will raise a NotImplementedError."); |
| 3238 | |
| 3239 | #define OS_READLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3240 | {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__}, |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 3241 | |
| 3242 | static PyObject * |
| 3243 | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
| 3244 | |
| 3245 | static PyObject * |
| 3246 | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 3247 | { |
| 3248 | PyObject *return_value = NULL; |
| 3249 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 3250 | static _PyArg_Parser _parser = {"O&|$O&:readlink", _keywords, 0}; |
| 3251 | path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0); |
| 3252 | int dir_fd = DEFAULT_DIR_FD; |
| 3253 | |
| 3254 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 3255 | path_converter, &path, READLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
| 3256 | goto exit; |
| 3257 | } |
| 3258 | return_value = os_readlink_impl(module, &path, dir_fd); |
| 3259 | |
| 3260 | exit: |
| 3261 | /* Cleanup for path */ |
| 3262 | path_cleanup(&path); |
| 3263 | |
| 3264 | return return_value; |
| 3265 | } |
| 3266 | |
| 3267 | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
| 3268 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3269 | #if defined(HAVE_SYMLINK) |
| 3270 | |
| 3271 | PyDoc_STRVAR(os_symlink__doc__, |
| 3272 | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
| 3273 | "--\n" |
| 3274 | "\n" |
| 3275 | "Create a symbolic link pointing to src named dst.\n" |
| 3276 | "\n" |
| 3277 | "target_is_directory is required on Windows if the target is to be\n" |
| 3278 | " interpreted as a directory. (On Windows, symlink requires\n" |
| 3279 | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
| 3280 | " target_is_directory is ignored on non-Windows platforms.\n" |
| 3281 | "\n" |
| 3282 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3283 | " and path should be relative; path will then be relative to that directory.\n" |
| 3284 | "dir_fd may not be implemented on your platform.\n" |
| 3285 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3286 | |
| 3287 | #define OS_SYMLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3288 | {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3289 | |
| 3290 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3291 | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 3292 | int target_is_directory, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3293 | |
| 3294 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3295 | os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3296 | { |
| 3297 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3298 | static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
| 3299 | static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3300 | path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0); |
| 3301 | path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0); |
| 3302 | int target_is_directory = 0; |
| 3303 | int dir_fd = DEFAULT_DIR_FD; |
| 3304 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3305 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3306 | path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3307 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3308 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3309 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
| 3310 | |
| 3311 | exit: |
| 3312 | /* Cleanup for src */ |
| 3313 | path_cleanup(&src); |
| 3314 | /* Cleanup for dst */ |
| 3315 | path_cleanup(&dst); |
| 3316 | |
| 3317 | return return_value; |
| 3318 | } |
| 3319 | |
| 3320 | #endif /* defined(HAVE_SYMLINK) */ |
| 3321 | |
| 3322 | #if defined(HAVE_TIMES) |
| 3323 | |
| 3324 | PyDoc_STRVAR(os_times__doc__, |
| 3325 | "times($module, /)\n" |
| 3326 | "--\n" |
| 3327 | "\n" |
| 3328 | "Return a collection containing process timing information.\n" |
| 3329 | "\n" |
| 3330 | "The object returned behaves like a named tuple with these fields:\n" |
| 3331 | " (utime, stime, cutime, cstime, elapsed_time)\n" |
| 3332 | "All fields are floating point numbers."); |
| 3333 | |
| 3334 | #define OS_TIMES_METHODDEF \ |
| 3335 | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
| 3336 | |
| 3337 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3338 | os_times_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3339 | |
| 3340 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3341 | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3342 | { |
| 3343 | return os_times_impl(module); |
| 3344 | } |
| 3345 | |
| 3346 | #endif /* defined(HAVE_TIMES) */ |
| 3347 | |
| 3348 | #if defined(HAVE_GETSID) |
| 3349 | |
| 3350 | PyDoc_STRVAR(os_getsid__doc__, |
| 3351 | "getsid($module, pid, /)\n" |
| 3352 | "--\n" |
| 3353 | "\n" |
| 3354 | "Call the system call getsid(pid) and return the result."); |
| 3355 | |
| 3356 | #define OS_GETSID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3357 | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3358 | |
| 3359 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3360 | os_getsid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3361 | |
| 3362 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3363 | os_getsid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3364 | { |
| 3365 | PyObject *return_value = NULL; |
| 3366 | pid_t pid; |
| 3367 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3368 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3369 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3370 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3371 | return_value = os_getsid_impl(module, pid); |
| 3372 | |
| 3373 | exit: |
| 3374 | return return_value; |
| 3375 | } |
| 3376 | |
| 3377 | #endif /* defined(HAVE_GETSID) */ |
| 3378 | |
| 3379 | #if defined(HAVE_SETSID) |
| 3380 | |
| 3381 | PyDoc_STRVAR(os_setsid__doc__, |
| 3382 | "setsid($module, /)\n" |
| 3383 | "--\n" |
| 3384 | "\n" |
| 3385 | "Call the system call setsid()."); |
| 3386 | |
| 3387 | #define OS_SETSID_METHODDEF \ |
| 3388 | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
| 3389 | |
| 3390 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3391 | os_setsid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3392 | |
| 3393 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3394 | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3395 | { |
| 3396 | return os_setsid_impl(module); |
| 3397 | } |
| 3398 | |
| 3399 | #endif /* defined(HAVE_SETSID) */ |
| 3400 | |
| 3401 | #if defined(HAVE_SETPGID) |
| 3402 | |
| 3403 | PyDoc_STRVAR(os_setpgid__doc__, |
| 3404 | "setpgid($module, pid, pgrp, /)\n" |
| 3405 | "--\n" |
| 3406 | "\n" |
| 3407 | "Call the system call setpgid(pid, pgrp)."); |
| 3408 | |
| 3409 | #define OS_SETPGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3410 | {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3411 | |
| 3412 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3413 | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3414 | |
| 3415 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3416 | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3417 | { |
| 3418 | PyObject *return_value = NULL; |
| 3419 | pid_t pid; |
| 3420 | pid_t pgrp; |
| 3421 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3422 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid", |
| 3423 | &pid, &pgrp)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3424 | goto exit; |
| 3425 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3426 | return_value = os_setpgid_impl(module, pid, pgrp); |
| 3427 | |
| 3428 | exit: |
| 3429 | return return_value; |
| 3430 | } |
| 3431 | |
| 3432 | #endif /* defined(HAVE_SETPGID) */ |
| 3433 | |
| 3434 | #if defined(HAVE_TCGETPGRP) |
| 3435 | |
| 3436 | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
| 3437 | "tcgetpgrp($module, fd, /)\n" |
| 3438 | "--\n" |
| 3439 | "\n" |
| 3440 | "Return the process group associated with the terminal specified by fd."); |
| 3441 | |
| 3442 | #define OS_TCGETPGRP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3443 | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3444 | |
| 3445 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3446 | os_tcgetpgrp_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3447 | |
| 3448 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3449 | os_tcgetpgrp(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3450 | { |
| 3451 | PyObject *return_value = NULL; |
| 3452 | int fd; |
| 3453 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3454 | if (PyFloat_Check(arg)) { |
| 3455 | PyErr_SetString(PyExc_TypeError, |
| 3456 | "integer argument expected, got float" ); |
| 3457 | goto exit; |
| 3458 | } |
| 3459 | fd = _PyLong_AsInt(arg); |
| 3460 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3461 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3462 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3463 | return_value = os_tcgetpgrp_impl(module, fd); |
| 3464 | |
| 3465 | exit: |
| 3466 | return return_value; |
| 3467 | } |
| 3468 | |
| 3469 | #endif /* defined(HAVE_TCGETPGRP) */ |
| 3470 | |
| 3471 | #if defined(HAVE_TCSETPGRP) |
| 3472 | |
| 3473 | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
| 3474 | "tcsetpgrp($module, fd, pgid, /)\n" |
| 3475 | "--\n" |
| 3476 | "\n" |
| 3477 | "Set the process group associated with the terminal specified by fd."); |
| 3478 | |
| 3479 | #define OS_TCSETPGRP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3480 | {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3481 | |
| 3482 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3483 | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3484 | |
| 3485 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3486 | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3487 | { |
| 3488 | PyObject *return_value = NULL; |
| 3489 | int fd; |
| 3490 | pid_t pgid; |
| 3491 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3492 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp", |
| 3493 | &fd, &pgid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3494 | goto exit; |
| 3495 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3496 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
| 3497 | |
| 3498 | exit: |
| 3499 | return return_value; |
| 3500 | } |
| 3501 | |
| 3502 | #endif /* defined(HAVE_TCSETPGRP) */ |
| 3503 | |
| 3504 | PyDoc_STRVAR(os_open__doc__, |
| 3505 | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
| 3506 | "--\n" |
| 3507 | "\n" |
| 3508 | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
| 3509 | "\n" |
| 3510 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3511 | " and path should be relative; path will then be relative to that directory.\n" |
| 3512 | "dir_fd may not be implemented on your platform.\n" |
| 3513 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3514 | |
| 3515 | #define OS_OPEN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3516 | {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3517 | |
| 3518 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3519 | os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3520 | |
| 3521 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3522 | os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3523 | { |
| 3524 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3525 | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
| 3526 | static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3527 | path_t path = PATH_T_INITIALIZE("open", "path", 0, 0); |
| 3528 | int flags; |
| 3529 | int mode = 511; |
| 3530 | int dir_fd = DEFAULT_DIR_FD; |
| 3531 | int _return_value; |
| 3532 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3533 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3534 | path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3535 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3536 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3537 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3538 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3539 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3540 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3541 | return_value = PyLong_FromLong((long)_return_value); |
| 3542 | |
| 3543 | exit: |
| 3544 | /* Cleanup for path */ |
| 3545 | path_cleanup(&path); |
| 3546 | |
| 3547 | return return_value; |
| 3548 | } |
| 3549 | |
| 3550 | PyDoc_STRVAR(os_close__doc__, |
| 3551 | "close($module, /, fd)\n" |
| 3552 | "--\n" |
| 3553 | "\n" |
| 3554 | "Close a file descriptor."); |
| 3555 | |
| 3556 | #define OS_CLOSE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3557 | {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3558 | |
| 3559 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3560 | os_close_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3561 | |
| 3562 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3563 | os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3564 | { |
| 3565 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3566 | static const char * const _keywords[] = {"fd", NULL}; |
| 3567 | static _PyArg_Parser _parser = {"i:close", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3568 | int fd; |
| 3569 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3570 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3571 | &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3572 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3573 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3574 | return_value = os_close_impl(module, fd); |
| 3575 | |
| 3576 | exit: |
| 3577 | return return_value; |
| 3578 | } |
| 3579 | |
| 3580 | PyDoc_STRVAR(os_closerange__doc__, |
| 3581 | "closerange($module, fd_low, fd_high, /)\n" |
| 3582 | "--\n" |
| 3583 | "\n" |
| 3584 | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
| 3585 | |
| 3586 | #define OS_CLOSERANGE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3587 | {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3588 | |
| 3589 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3590 | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3591 | |
| 3592 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3593 | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3594 | { |
| 3595 | PyObject *return_value = NULL; |
| 3596 | int fd_low; |
| 3597 | int fd_high; |
| 3598 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 3599 | if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { |
| 3600 | goto exit; |
| 3601 | } |
| 3602 | if (PyFloat_Check(args[0])) { |
| 3603 | PyErr_SetString(PyExc_TypeError, |
| 3604 | "integer argument expected, got float" ); |
| 3605 | goto exit; |
| 3606 | } |
| 3607 | fd_low = _PyLong_AsInt(args[0]); |
| 3608 | if (fd_low == -1 && PyErr_Occurred()) { |
| 3609 | goto exit; |
| 3610 | } |
| 3611 | if (PyFloat_Check(args[1])) { |
| 3612 | PyErr_SetString(PyExc_TypeError, |
| 3613 | "integer argument expected, got float" ); |
| 3614 | goto exit; |
| 3615 | } |
| 3616 | fd_high = _PyLong_AsInt(args[1]); |
| 3617 | if (fd_high == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3618 | goto exit; |
| 3619 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3620 | return_value = os_closerange_impl(module, fd_low, fd_high); |
| 3621 | |
| 3622 | exit: |
| 3623 | return return_value; |
| 3624 | } |
| 3625 | |
| 3626 | PyDoc_STRVAR(os_dup__doc__, |
| 3627 | "dup($module, fd, /)\n" |
| 3628 | "--\n" |
| 3629 | "\n" |
| 3630 | "Return a duplicate of a file descriptor."); |
| 3631 | |
| 3632 | #define OS_DUP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3633 | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3634 | |
| 3635 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3636 | os_dup_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3637 | |
| 3638 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3639 | os_dup(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3640 | { |
| 3641 | PyObject *return_value = NULL; |
| 3642 | int fd; |
| 3643 | int _return_value; |
| 3644 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3645 | if (PyFloat_Check(arg)) { |
| 3646 | PyErr_SetString(PyExc_TypeError, |
| 3647 | "integer argument expected, got float" ); |
| 3648 | goto exit; |
| 3649 | } |
| 3650 | fd = _PyLong_AsInt(arg); |
| 3651 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3652 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3653 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3654 | _return_value = os_dup_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3655 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3656 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3657 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3658 | return_value = PyLong_FromLong((long)_return_value); |
| 3659 | |
| 3660 | exit: |
| 3661 | return return_value; |
| 3662 | } |
| 3663 | |
| 3664 | PyDoc_STRVAR(os_dup2__doc__, |
| 3665 | "dup2($module, /, fd, fd2, inheritable=True)\n" |
| 3666 | "--\n" |
| 3667 | "\n" |
| 3668 | "Duplicate file descriptor."); |
| 3669 | |
| 3670 | #define OS_DUP2_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3671 | {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3672 | |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 3673 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3674 | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3675 | |
| 3676 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3677 | os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3678 | { |
| 3679 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3680 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
| 3681 | static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3682 | int fd; |
| 3683 | int fd2; |
| 3684 | int inheritable = 1; |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 3685 | int _return_value; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3686 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3687 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3688 | &fd, &fd2, &inheritable)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3689 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3690 | } |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 3691 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
| 3692 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 3693 | goto exit; |
| 3694 | } |
| 3695 | return_value = PyLong_FromLong((long)_return_value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3696 | |
| 3697 | exit: |
| 3698 | return return_value; |
| 3699 | } |
| 3700 | |
| 3701 | #if defined(HAVE_LOCKF) |
| 3702 | |
| 3703 | PyDoc_STRVAR(os_lockf__doc__, |
| 3704 | "lockf($module, fd, command, length, /)\n" |
| 3705 | "--\n" |
| 3706 | "\n" |
| 3707 | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
| 3708 | "\n" |
| 3709 | " fd\n" |
| 3710 | " An open file descriptor.\n" |
| 3711 | " command\n" |
| 3712 | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
| 3713 | " length\n" |
| 3714 | " The number of bytes to lock, starting at the current position."); |
| 3715 | |
| 3716 | #define OS_LOCKF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3717 | {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3718 | |
| 3719 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3720 | os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3721 | |
| 3722 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3723 | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3724 | { |
| 3725 | PyObject *return_value = NULL; |
| 3726 | int fd; |
| 3727 | int command; |
| 3728 | Py_off_t length; |
| 3729 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 3730 | if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { |
| 3731 | goto exit; |
| 3732 | } |
| 3733 | if (PyFloat_Check(args[0])) { |
| 3734 | PyErr_SetString(PyExc_TypeError, |
| 3735 | "integer argument expected, got float" ); |
| 3736 | goto exit; |
| 3737 | } |
| 3738 | fd = _PyLong_AsInt(args[0]); |
| 3739 | if (fd == -1 && PyErr_Occurred()) { |
| 3740 | goto exit; |
| 3741 | } |
| 3742 | if (PyFloat_Check(args[1])) { |
| 3743 | PyErr_SetString(PyExc_TypeError, |
| 3744 | "integer argument expected, got float" ); |
| 3745 | goto exit; |
| 3746 | } |
| 3747 | command = _PyLong_AsInt(args[1]); |
| 3748 | if (command == -1 && PyErr_Occurred()) { |
| 3749 | goto exit; |
| 3750 | } |
| 3751 | if (!Py_off_t_converter(args[2], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3752 | goto exit; |
| 3753 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3754 | return_value = os_lockf_impl(module, fd, command, length); |
| 3755 | |
| 3756 | exit: |
| 3757 | return return_value; |
| 3758 | } |
| 3759 | |
| 3760 | #endif /* defined(HAVE_LOCKF) */ |
| 3761 | |
| 3762 | PyDoc_STRVAR(os_lseek__doc__, |
| 3763 | "lseek($module, fd, position, how, /)\n" |
| 3764 | "--\n" |
| 3765 | "\n" |
| 3766 | "Set the position of a file descriptor. Return the new position.\n" |
| 3767 | "\n" |
| 3768 | "Return the new cursor position in number of bytes\n" |
| 3769 | "relative to the beginning of the file."); |
| 3770 | |
| 3771 | #define OS_LSEEK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3772 | {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3773 | |
| 3774 | static Py_off_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3775 | os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3776 | |
| 3777 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3778 | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3779 | { |
| 3780 | PyObject *return_value = NULL; |
| 3781 | int fd; |
| 3782 | Py_off_t position; |
| 3783 | int how; |
| 3784 | Py_off_t _return_value; |
| 3785 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 3786 | if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { |
| 3787 | goto exit; |
| 3788 | } |
| 3789 | if (PyFloat_Check(args[0])) { |
| 3790 | PyErr_SetString(PyExc_TypeError, |
| 3791 | "integer argument expected, got float" ); |
| 3792 | goto exit; |
| 3793 | } |
| 3794 | fd = _PyLong_AsInt(args[0]); |
| 3795 | if (fd == -1 && PyErr_Occurred()) { |
| 3796 | goto exit; |
| 3797 | } |
| 3798 | if (!Py_off_t_converter(args[1], &position)) { |
| 3799 | goto exit; |
| 3800 | } |
| 3801 | if (PyFloat_Check(args[2])) { |
| 3802 | PyErr_SetString(PyExc_TypeError, |
| 3803 | "integer argument expected, got float" ); |
| 3804 | goto exit; |
| 3805 | } |
| 3806 | how = _PyLong_AsInt(args[2]); |
| 3807 | if (how == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3808 | goto exit; |
| 3809 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3810 | _return_value = os_lseek_impl(module, fd, position, how); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3811 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3812 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3813 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3814 | return_value = PyLong_FromPy_off_t(_return_value); |
| 3815 | |
| 3816 | exit: |
| 3817 | return return_value; |
| 3818 | } |
| 3819 | |
| 3820 | PyDoc_STRVAR(os_read__doc__, |
| 3821 | "read($module, fd, length, /)\n" |
| 3822 | "--\n" |
| 3823 | "\n" |
| 3824 | "Read from a file descriptor. Returns a bytes object."); |
| 3825 | |
| 3826 | #define OS_READ_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3827 | {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3828 | |
| 3829 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3830 | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3831 | |
| 3832 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3833 | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3834 | { |
| 3835 | PyObject *return_value = NULL; |
| 3836 | int fd; |
| 3837 | Py_ssize_t length; |
| 3838 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 3839 | if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3840 | goto exit; |
| 3841 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 3842 | if (PyFloat_Check(args[0])) { |
| 3843 | PyErr_SetString(PyExc_TypeError, |
| 3844 | "integer argument expected, got float" ); |
| 3845 | goto exit; |
| 3846 | } |
| 3847 | fd = _PyLong_AsInt(args[0]); |
| 3848 | if (fd == -1 && PyErr_Occurred()) { |
| 3849 | goto exit; |
| 3850 | } |
| 3851 | if (PyFloat_Check(args[1])) { |
| 3852 | PyErr_SetString(PyExc_TypeError, |
| 3853 | "integer argument expected, got float" ); |
| 3854 | goto exit; |
| 3855 | } |
| 3856 | { |
| 3857 | Py_ssize_t ival = -1; |
| 3858 | PyObject *iobj = PyNumber_Index(args[1]); |
| 3859 | if (iobj != NULL) { |
| 3860 | ival = PyLong_AsSsize_t(iobj); |
| 3861 | Py_DECREF(iobj); |
| 3862 | } |
| 3863 | if (ival == -1 && PyErr_Occurred()) { |
| 3864 | goto exit; |
| 3865 | } |
| 3866 | length = ival; |
| 3867 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3868 | return_value = os_read_impl(module, fd, length); |
| 3869 | |
| 3870 | exit: |
| 3871 | return return_value; |
| 3872 | } |
| 3873 | |
| 3874 | #if defined(HAVE_READV) |
| 3875 | |
| 3876 | PyDoc_STRVAR(os_readv__doc__, |
| 3877 | "readv($module, fd, buffers, /)\n" |
| 3878 | "--\n" |
| 3879 | "\n" |
| 3880 | "Read from a file descriptor fd into an iterable of buffers.\n" |
| 3881 | "\n" |
| 3882 | "The buffers should be mutable buffers accepting bytes.\n" |
| 3883 | "readv will transfer data into each buffer until it is full\n" |
| 3884 | "and then move on to the next buffer in the sequence to hold\n" |
| 3885 | "the rest of the data.\n" |
| 3886 | "\n" |
| 3887 | "readv returns the total number of bytes read,\n" |
| 3888 | "which may be less than the total capacity of all the buffers."); |
| 3889 | |
| 3890 | #define OS_READV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3891 | {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3892 | |
| 3893 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3894 | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3895 | |
| 3896 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3897 | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3898 | { |
| 3899 | PyObject *return_value = NULL; |
| 3900 | int fd; |
| 3901 | PyObject *buffers; |
| 3902 | Py_ssize_t _return_value; |
| 3903 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 3904 | if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3905 | goto exit; |
| 3906 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 3907 | if (PyFloat_Check(args[0])) { |
| 3908 | PyErr_SetString(PyExc_TypeError, |
| 3909 | "integer argument expected, got float" ); |
| 3910 | goto exit; |
| 3911 | } |
| 3912 | fd = _PyLong_AsInt(args[0]); |
| 3913 | if (fd == -1 && PyErr_Occurred()) { |
| 3914 | goto exit; |
| 3915 | } |
| 3916 | buffers = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3917 | _return_value = os_readv_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3918 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3919 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3920 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3921 | return_value = PyLong_FromSsize_t(_return_value); |
| 3922 | |
| 3923 | exit: |
| 3924 | return return_value; |
| 3925 | } |
| 3926 | |
| 3927 | #endif /* defined(HAVE_READV) */ |
| 3928 | |
| 3929 | #if defined(HAVE_PREAD) |
| 3930 | |
| 3931 | PyDoc_STRVAR(os_pread__doc__, |
| 3932 | "pread($module, fd, length, offset, /)\n" |
| 3933 | "--\n" |
| 3934 | "\n" |
| 3935 | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
| 3936 | "\n" |
| 3937 | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
| 3938 | "the beginning of the file. The file offset remains unchanged."); |
| 3939 | |
| 3940 | #define OS_PREAD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3941 | {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3942 | |
| 3943 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3944 | os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3945 | |
| 3946 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3947 | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3948 | { |
| 3949 | PyObject *return_value = NULL; |
| 3950 | int fd; |
| 3951 | int length; |
| 3952 | Py_off_t offset; |
| 3953 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 3954 | if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { |
| 3955 | goto exit; |
| 3956 | } |
| 3957 | if (PyFloat_Check(args[0])) { |
| 3958 | PyErr_SetString(PyExc_TypeError, |
| 3959 | "integer argument expected, got float" ); |
| 3960 | goto exit; |
| 3961 | } |
| 3962 | fd = _PyLong_AsInt(args[0]); |
| 3963 | if (fd == -1 && PyErr_Occurred()) { |
| 3964 | goto exit; |
| 3965 | } |
| 3966 | if (PyFloat_Check(args[1])) { |
| 3967 | PyErr_SetString(PyExc_TypeError, |
| 3968 | "integer argument expected, got float" ); |
| 3969 | goto exit; |
| 3970 | } |
| 3971 | length = _PyLong_AsInt(args[1]); |
| 3972 | if (length == -1 && PyErr_Occurred()) { |
| 3973 | goto exit; |
| 3974 | } |
| 3975 | if (!Py_off_t_converter(args[2], &offset)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3976 | goto exit; |
| 3977 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3978 | return_value = os_pread_impl(module, fd, length, offset); |
| 3979 | |
| 3980 | exit: |
| 3981 | return return_value; |
| 3982 | } |
| 3983 | |
| 3984 | #endif /* defined(HAVE_PREAD) */ |
| 3985 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 3986 | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
| 3987 | |
| 3988 | PyDoc_STRVAR(os_preadv__doc__, |
| 3989 | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
| 3990 | "--\n" |
| 3991 | "\n" |
| 3992 | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
| 3993 | "\n" |
| 3994 | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
| 3995 | "transfer data into each buffer until it is full and then move on to the next\n" |
| 3996 | "buffer in the sequence to hold the rest of the data. Its fourth argument,\n" |
| 3997 | "specifies the file offset at which the input operation is to be performed. It\n" |
| 3998 | "will return the total number of bytes read (which can be less than the total\n" |
| 3999 | "capacity of all the objects).\n" |
| 4000 | "\n" |
| 4001 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
| 4002 | "\n" |
| 4003 | "- RWF_HIPRI\n" |
| 4004 | "- RWF_NOWAIT\n" |
| 4005 | "\n" |
| 4006 | "Using non-zero flags requires Linux 4.6 or newer."); |
| 4007 | |
| 4008 | #define OS_PREADV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4009 | {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__}, |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4010 | |
| 4011 | static Py_ssize_t |
| 4012 | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
| 4013 | int flags); |
| 4014 | |
| 4015 | static PyObject * |
| 4016 | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 4017 | { |
| 4018 | PyObject *return_value = NULL; |
| 4019 | int fd; |
| 4020 | PyObject *buffers; |
| 4021 | Py_off_t offset; |
| 4022 | int flags = 0; |
| 4023 | Py_ssize_t _return_value; |
| 4024 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4025 | if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4026 | goto exit; |
| 4027 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4028 | if (PyFloat_Check(args[0])) { |
| 4029 | PyErr_SetString(PyExc_TypeError, |
| 4030 | "integer argument expected, got float" ); |
| 4031 | goto exit; |
| 4032 | } |
| 4033 | fd = _PyLong_AsInt(args[0]); |
| 4034 | if (fd == -1 && PyErr_Occurred()) { |
| 4035 | goto exit; |
| 4036 | } |
| 4037 | buffers = args[1]; |
| 4038 | if (!Py_off_t_converter(args[2], &offset)) { |
| 4039 | goto exit; |
| 4040 | } |
| 4041 | if (nargs < 4) { |
| 4042 | goto skip_optional; |
| 4043 | } |
| 4044 | if (PyFloat_Check(args[3])) { |
| 4045 | PyErr_SetString(PyExc_TypeError, |
| 4046 | "integer argument expected, got float" ); |
| 4047 | goto exit; |
| 4048 | } |
| 4049 | flags = _PyLong_AsInt(args[3]); |
| 4050 | if (flags == -1 && PyErr_Occurred()) { |
| 4051 | goto exit; |
| 4052 | } |
| 4053 | skip_optional: |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4054 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
| 4055 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 4056 | goto exit; |
| 4057 | } |
| 4058 | return_value = PyLong_FromSsize_t(_return_value); |
| 4059 | |
| 4060 | exit: |
| 4061 | return return_value; |
| 4062 | } |
| 4063 | |
| 4064 | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
| 4065 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4066 | PyDoc_STRVAR(os_write__doc__, |
| 4067 | "write($module, fd, data, /)\n" |
| 4068 | "--\n" |
| 4069 | "\n" |
| 4070 | "Write a bytes object to a file descriptor."); |
| 4071 | |
| 4072 | #define OS_WRITE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4073 | {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4074 | |
| 4075 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4076 | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4077 | |
| 4078 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4079 | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4080 | { |
| 4081 | PyObject *return_value = NULL; |
| 4082 | int fd; |
| 4083 | Py_buffer data = {NULL, NULL}; |
| 4084 | Py_ssize_t _return_value; |
| 4085 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4086 | if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { |
| 4087 | goto exit; |
| 4088 | } |
| 4089 | if (PyFloat_Check(args[0])) { |
| 4090 | PyErr_SetString(PyExc_TypeError, |
| 4091 | "integer argument expected, got float" ); |
| 4092 | goto exit; |
| 4093 | } |
| 4094 | fd = _PyLong_AsInt(args[0]); |
| 4095 | if (fd == -1 && PyErr_Occurred()) { |
| 4096 | goto exit; |
| 4097 | } |
| 4098 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
| 4099 | goto exit; |
| 4100 | } |
| 4101 | if (!PyBuffer_IsContiguous(&data, 'C')) { |
| 4102 | _PyArg_BadArgument("write", 2, "contiguous buffer", args[1]); |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4103 | goto exit; |
| 4104 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4105 | _return_value = os_write_impl(module, fd, &data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4106 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4107 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4108 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4109 | return_value = PyLong_FromSsize_t(_return_value); |
| 4110 | |
| 4111 | exit: |
| 4112 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4113 | if (data.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4114 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4115 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4116 | |
| 4117 | return return_value; |
| 4118 | } |
| 4119 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4120 | #if defined(__APPLE__) |
| 4121 | |
| 4122 | PyDoc_STRVAR(os__fcopyfile__doc__, |
| 4123 | "_fcopyfile($module, infd, outfd, flags, /)\n" |
| 4124 | "--\n" |
| 4125 | "\n" |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 4126 | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4127 | |
| 4128 | #define OS__FCOPYFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4129 | {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__}, |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4130 | |
| 4131 | static PyObject * |
| 4132 | os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags); |
| 4133 | |
| 4134 | static PyObject * |
| 4135 | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 4136 | { |
| 4137 | PyObject *return_value = NULL; |
| 4138 | int infd; |
| 4139 | int outfd; |
| 4140 | int flags; |
| 4141 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4142 | if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { |
| 4143 | goto exit; |
| 4144 | } |
| 4145 | if (PyFloat_Check(args[0])) { |
| 4146 | PyErr_SetString(PyExc_TypeError, |
| 4147 | "integer argument expected, got float" ); |
| 4148 | goto exit; |
| 4149 | } |
| 4150 | infd = _PyLong_AsInt(args[0]); |
| 4151 | if (infd == -1 && PyErr_Occurred()) { |
| 4152 | goto exit; |
| 4153 | } |
| 4154 | if (PyFloat_Check(args[1])) { |
| 4155 | PyErr_SetString(PyExc_TypeError, |
| 4156 | "integer argument expected, got float" ); |
| 4157 | goto exit; |
| 4158 | } |
| 4159 | outfd = _PyLong_AsInt(args[1]); |
| 4160 | if (outfd == -1 && PyErr_Occurred()) { |
| 4161 | goto exit; |
| 4162 | } |
| 4163 | if (PyFloat_Check(args[2])) { |
| 4164 | PyErr_SetString(PyExc_TypeError, |
| 4165 | "integer argument expected, got float" ); |
| 4166 | goto exit; |
| 4167 | } |
| 4168 | flags = _PyLong_AsInt(args[2]); |
| 4169 | if (flags == -1 && PyErr_Occurred()) { |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4170 | goto exit; |
| 4171 | } |
| 4172 | return_value = os__fcopyfile_impl(module, infd, outfd, flags); |
| 4173 | |
| 4174 | exit: |
| 4175 | return return_value; |
| 4176 | } |
| 4177 | |
| 4178 | #endif /* defined(__APPLE__) */ |
| 4179 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4180 | PyDoc_STRVAR(os_fstat__doc__, |
| 4181 | "fstat($module, /, fd)\n" |
| 4182 | "--\n" |
| 4183 | "\n" |
| 4184 | "Perform a stat system call on the given file descriptor.\n" |
| 4185 | "\n" |
| 4186 | "Like stat(), but for an open file descriptor.\n" |
| 4187 | "Equivalent to os.stat(fd)."); |
| 4188 | |
| 4189 | #define OS_FSTAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4190 | {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4191 | |
| 4192 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4193 | os_fstat_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4194 | |
| 4195 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4196 | os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4197 | { |
| 4198 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4199 | static const char * const _keywords[] = {"fd", NULL}; |
| 4200 | static _PyArg_Parser _parser = {"i:fstat", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4201 | int fd; |
| 4202 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 4203 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4204 | &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4205 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4206 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4207 | return_value = os_fstat_impl(module, fd); |
| 4208 | |
| 4209 | exit: |
| 4210 | return return_value; |
| 4211 | } |
| 4212 | |
| 4213 | PyDoc_STRVAR(os_isatty__doc__, |
| 4214 | "isatty($module, fd, /)\n" |
| 4215 | "--\n" |
| 4216 | "\n" |
| 4217 | "Return True if the fd is connected to a terminal.\n" |
| 4218 | "\n" |
| 4219 | "Return True if the file descriptor is an open file descriptor\n" |
| 4220 | "connected to the slave end of a terminal."); |
| 4221 | |
| 4222 | #define OS_ISATTY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4223 | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4224 | |
| 4225 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4226 | os_isatty_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4227 | |
| 4228 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4229 | os_isatty(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4230 | { |
| 4231 | PyObject *return_value = NULL; |
| 4232 | int fd; |
| 4233 | int _return_value; |
| 4234 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4235 | if (PyFloat_Check(arg)) { |
| 4236 | PyErr_SetString(PyExc_TypeError, |
| 4237 | "integer argument expected, got float" ); |
| 4238 | goto exit; |
| 4239 | } |
| 4240 | fd = _PyLong_AsInt(arg); |
| 4241 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4242 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4243 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4244 | _return_value = os_isatty_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4245 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4246 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4247 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4248 | return_value = PyBool_FromLong((long)_return_value); |
| 4249 | |
| 4250 | exit: |
| 4251 | return return_value; |
| 4252 | } |
| 4253 | |
| 4254 | #if defined(HAVE_PIPE) |
| 4255 | |
| 4256 | PyDoc_STRVAR(os_pipe__doc__, |
| 4257 | "pipe($module, /)\n" |
| 4258 | "--\n" |
| 4259 | "\n" |
| 4260 | "Create a pipe.\n" |
| 4261 | "\n" |
| 4262 | "Returns a tuple of two file descriptors:\n" |
| 4263 | " (read_fd, write_fd)"); |
| 4264 | |
| 4265 | #define OS_PIPE_METHODDEF \ |
| 4266 | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
| 4267 | |
| 4268 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4269 | os_pipe_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4270 | |
| 4271 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4272 | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4273 | { |
| 4274 | return os_pipe_impl(module); |
| 4275 | } |
| 4276 | |
| 4277 | #endif /* defined(HAVE_PIPE) */ |
| 4278 | |
| 4279 | #if defined(HAVE_PIPE2) |
| 4280 | |
| 4281 | PyDoc_STRVAR(os_pipe2__doc__, |
| 4282 | "pipe2($module, flags, /)\n" |
| 4283 | "--\n" |
| 4284 | "\n" |
| 4285 | "Create a pipe with flags set atomically.\n" |
| 4286 | "\n" |
| 4287 | "Returns a tuple of two file descriptors:\n" |
| 4288 | " (read_fd, write_fd)\n" |
| 4289 | "\n" |
| 4290 | "flags can be constructed by ORing together one or more of these values:\n" |
| 4291 | "O_NONBLOCK, O_CLOEXEC."); |
| 4292 | |
| 4293 | #define OS_PIPE2_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4294 | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4295 | |
| 4296 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4297 | os_pipe2_impl(PyObject *module, int flags); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4298 | |
| 4299 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4300 | os_pipe2(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4301 | { |
| 4302 | PyObject *return_value = NULL; |
| 4303 | int flags; |
| 4304 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4305 | if (PyFloat_Check(arg)) { |
| 4306 | PyErr_SetString(PyExc_TypeError, |
| 4307 | "integer argument expected, got float" ); |
| 4308 | goto exit; |
| 4309 | } |
| 4310 | flags = _PyLong_AsInt(arg); |
| 4311 | if (flags == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4312 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4313 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4314 | return_value = os_pipe2_impl(module, flags); |
| 4315 | |
| 4316 | exit: |
| 4317 | return return_value; |
| 4318 | } |
| 4319 | |
| 4320 | #endif /* defined(HAVE_PIPE2) */ |
| 4321 | |
| 4322 | #if defined(HAVE_WRITEV) |
| 4323 | |
| 4324 | PyDoc_STRVAR(os_writev__doc__, |
| 4325 | "writev($module, fd, buffers, /)\n" |
| 4326 | "--\n" |
| 4327 | "\n" |
| 4328 | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
| 4329 | "\n" |
| 4330 | "Returns the total number of bytes written.\n" |
| 4331 | "buffers must be a sequence of bytes-like objects."); |
| 4332 | |
| 4333 | #define OS_WRITEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4334 | {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4335 | |
| 4336 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4337 | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4338 | |
| 4339 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4340 | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4341 | { |
| 4342 | PyObject *return_value = NULL; |
| 4343 | int fd; |
| 4344 | PyObject *buffers; |
| 4345 | Py_ssize_t _return_value; |
| 4346 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4347 | if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4348 | goto exit; |
| 4349 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4350 | if (PyFloat_Check(args[0])) { |
| 4351 | PyErr_SetString(PyExc_TypeError, |
| 4352 | "integer argument expected, got float" ); |
| 4353 | goto exit; |
| 4354 | } |
| 4355 | fd = _PyLong_AsInt(args[0]); |
| 4356 | if (fd == -1 && PyErr_Occurred()) { |
| 4357 | goto exit; |
| 4358 | } |
| 4359 | buffers = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4360 | _return_value = os_writev_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4361 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4362 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4363 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4364 | return_value = PyLong_FromSsize_t(_return_value); |
| 4365 | |
| 4366 | exit: |
| 4367 | return return_value; |
| 4368 | } |
| 4369 | |
| 4370 | #endif /* defined(HAVE_WRITEV) */ |
| 4371 | |
| 4372 | #if defined(HAVE_PWRITE) |
| 4373 | |
| 4374 | PyDoc_STRVAR(os_pwrite__doc__, |
| 4375 | "pwrite($module, fd, buffer, offset, /)\n" |
| 4376 | "--\n" |
| 4377 | "\n" |
| 4378 | "Write bytes to a file descriptor starting at a particular offset.\n" |
| 4379 | "\n" |
| 4380 | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
| 4381 | "the file. Returns the number of bytes writte. Does not change the\n" |
| 4382 | "current file offset."); |
| 4383 | |
| 4384 | #define OS_PWRITE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4385 | {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4386 | |
| 4387 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4388 | os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4389 | |
| 4390 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4391 | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4392 | { |
| 4393 | PyObject *return_value = NULL; |
| 4394 | int fd; |
| 4395 | Py_buffer buffer = {NULL, NULL}; |
| 4396 | Py_off_t offset; |
| 4397 | Py_ssize_t _return_value; |
| 4398 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4399 | if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { |
| 4400 | goto exit; |
| 4401 | } |
| 4402 | if (PyFloat_Check(args[0])) { |
| 4403 | PyErr_SetString(PyExc_TypeError, |
| 4404 | "integer argument expected, got float" ); |
| 4405 | goto exit; |
| 4406 | } |
| 4407 | fd = _PyLong_AsInt(args[0]); |
| 4408 | if (fd == -1 && PyErr_Occurred()) { |
| 4409 | goto exit; |
| 4410 | } |
| 4411 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
| 4412 | goto exit; |
| 4413 | } |
| 4414 | if (!PyBuffer_IsContiguous(&buffer, 'C')) { |
| 4415 | _PyArg_BadArgument("pwrite", 2, "contiguous buffer", args[1]); |
| 4416 | goto exit; |
| 4417 | } |
| 4418 | if (!Py_off_t_converter(args[2], &offset)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4419 | goto exit; |
| 4420 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4421 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4422 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4423 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4424 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4425 | return_value = PyLong_FromSsize_t(_return_value); |
| 4426 | |
| 4427 | exit: |
| 4428 | /* Cleanup for buffer */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4429 | if (buffer.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4430 | PyBuffer_Release(&buffer); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4431 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4432 | |
| 4433 | return return_value; |
| 4434 | } |
| 4435 | |
| 4436 | #endif /* defined(HAVE_PWRITE) */ |
| 4437 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4438 | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
| 4439 | |
| 4440 | PyDoc_STRVAR(os_pwritev__doc__, |
| 4441 | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
| 4442 | "--\n" |
| 4443 | "\n" |
| 4444 | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
| 4445 | "\n" |
| 4446 | "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n" |
| 4447 | "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n" |
| 4448 | "buffer is written before proceeding to second, and so on. The operating system may\n" |
| 4449 | "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n" |
| 4450 | "This function writes the contents of each object to the file descriptor and returns\n" |
| 4451 | "the total number of bytes written.\n" |
| 4452 | "\n" |
| 4453 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
| 4454 | "\n" |
| 4455 | "- RWF_DSYNC\n" |
| 4456 | "- RWF_SYNC\n" |
| 4457 | "\n" |
| 4458 | "Using non-zero flags requires Linux 4.7 or newer."); |
| 4459 | |
| 4460 | #define OS_PWRITEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4461 | {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__}, |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4462 | |
| 4463 | static Py_ssize_t |
| 4464 | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
| 4465 | int flags); |
| 4466 | |
| 4467 | static PyObject * |
| 4468 | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 4469 | { |
| 4470 | PyObject *return_value = NULL; |
| 4471 | int fd; |
| 4472 | PyObject *buffers; |
| 4473 | Py_off_t offset; |
| 4474 | int flags = 0; |
| 4475 | Py_ssize_t _return_value; |
| 4476 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4477 | if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4478 | goto exit; |
| 4479 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4480 | if (PyFloat_Check(args[0])) { |
| 4481 | PyErr_SetString(PyExc_TypeError, |
| 4482 | "integer argument expected, got float" ); |
| 4483 | goto exit; |
| 4484 | } |
| 4485 | fd = _PyLong_AsInt(args[0]); |
| 4486 | if (fd == -1 && PyErr_Occurred()) { |
| 4487 | goto exit; |
| 4488 | } |
| 4489 | buffers = args[1]; |
| 4490 | if (!Py_off_t_converter(args[2], &offset)) { |
| 4491 | goto exit; |
| 4492 | } |
| 4493 | if (nargs < 4) { |
| 4494 | goto skip_optional; |
| 4495 | } |
| 4496 | if (PyFloat_Check(args[3])) { |
| 4497 | PyErr_SetString(PyExc_TypeError, |
| 4498 | "integer argument expected, got float" ); |
| 4499 | goto exit; |
| 4500 | } |
| 4501 | flags = _PyLong_AsInt(args[3]); |
| 4502 | if (flags == -1 && PyErr_Occurred()) { |
| 4503 | goto exit; |
| 4504 | } |
| 4505 | skip_optional: |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4506 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
| 4507 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 4508 | goto exit; |
| 4509 | } |
| 4510 | return_value = PyLong_FromSsize_t(_return_value); |
| 4511 | |
| 4512 | exit: |
| 4513 | return return_value; |
| 4514 | } |
| 4515 | |
| 4516 | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
| 4517 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4518 | #if defined(HAVE_MKFIFO) |
| 4519 | |
| 4520 | PyDoc_STRVAR(os_mkfifo__doc__, |
| 4521 | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
| 4522 | "--\n" |
| 4523 | "\n" |
| 4524 | "Create a \"fifo\" (a POSIX named pipe).\n" |
| 4525 | "\n" |
| 4526 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 4527 | " and path should be relative; path will then be relative to that directory.\n" |
| 4528 | "dir_fd may not be implemented on your platform.\n" |
| 4529 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 4530 | |
| 4531 | #define OS_MKFIFO_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4532 | {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4533 | |
| 4534 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4535 | os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4536 | |
| 4537 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4538 | os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4539 | { |
| 4540 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4541 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
| 4542 | static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4543 | path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0); |
| 4544 | int mode = 438; |
| 4545 | int dir_fd = DEFAULT_DIR_FD; |
| 4546 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 4547 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4548 | path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4549 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4550 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4551 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
| 4552 | |
| 4553 | exit: |
| 4554 | /* Cleanup for path */ |
| 4555 | path_cleanup(&path); |
| 4556 | |
| 4557 | return return_value; |
| 4558 | } |
| 4559 | |
| 4560 | #endif /* defined(HAVE_MKFIFO) */ |
| 4561 | |
| 4562 | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
| 4563 | |
| 4564 | PyDoc_STRVAR(os_mknod__doc__, |
| 4565 | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
| 4566 | "--\n" |
| 4567 | "\n" |
| 4568 | "Create a node in the file system.\n" |
| 4569 | "\n" |
| 4570 | "Create a node in the file system (file, device special file or named pipe)\n" |
| 4571 | "at path. mode specifies both the permissions to use and the\n" |
| 4572 | "type of node to be created, being combined (bitwise OR) with one of\n" |
| 4573 | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
| 4574 | "device defines the newly created device special file (probably using\n" |
| 4575 | "os.makedev()). Otherwise device is ignored.\n" |
| 4576 | "\n" |
| 4577 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 4578 | " and path should be relative; path will then be relative to that directory.\n" |
| 4579 | "dir_fd may not be implemented on your platform.\n" |
| 4580 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 4581 | |
| 4582 | #define OS_MKNOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4583 | {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4584 | |
| 4585 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4586 | os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 4587 | int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4588 | |
| 4589 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4590 | os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4591 | { |
| 4592 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4593 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
| 4594 | static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4595 | path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0); |
| 4596 | int mode = 384; |
| 4597 | dev_t device = 0; |
| 4598 | int dir_fd = DEFAULT_DIR_FD; |
| 4599 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 4600 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4601 | path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4602 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4603 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4604 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
| 4605 | |
| 4606 | exit: |
| 4607 | /* Cleanup for path */ |
| 4608 | path_cleanup(&path); |
| 4609 | |
| 4610 | return return_value; |
| 4611 | } |
| 4612 | |
| 4613 | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
| 4614 | |
| 4615 | #if defined(HAVE_DEVICE_MACROS) |
| 4616 | |
| 4617 | PyDoc_STRVAR(os_major__doc__, |
| 4618 | "major($module, device, /)\n" |
| 4619 | "--\n" |
| 4620 | "\n" |
| 4621 | "Extracts a device major number from a raw device number."); |
| 4622 | |
| 4623 | #define OS_MAJOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4624 | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4625 | |
| 4626 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4627 | os_major_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4628 | |
| 4629 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4630 | os_major(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4631 | { |
| 4632 | PyObject *return_value = NULL; |
| 4633 | dev_t device; |
| 4634 | unsigned int _return_value; |
| 4635 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4636 | if (!_Py_Dev_Converter(arg, &device)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4637 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4638 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4639 | _return_value = os_major_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4640 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4641 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4642 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4643 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 4644 | |
| 4645 | exit: |
| 4646 | return return_value; |
| 4647 | } |
| 4648 | |
| 4649 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 4650 | |
| 4651 | #if defined(HAVE_DEVICE_MACROS) |
| 4652 | |
| 4653 | PyDoc_STRVAR(os_minor__doc__, |
| 4654 | "minor($module, device, /)\n" |
| 4655 | "--\n" |
| 4656 | "\n" |
| 4657 | "Extracts a device minor number from a raw device number."); |
| 4658 | |
| 4659 | #define OS_MINOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4660 | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4661 | |
| 4662 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4663 | os_minor_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4664 | |
| 4665 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4666 | os_minor(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4667 | { |
| 4668 | PyObject *return_value = NULL; |
| 4669 | dev_t device; |
| 4670 | unsigned int _return_value; |
| 4671 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4672 | if (!_Py_Dev_Converter(arg, &device)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4673 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4674 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4675 | _return_value = os_minor_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4676 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4677 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4678 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4679 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 4680 | |
| 4681 | exit: |
| 4682 | return return_value; |
| 4683 | } |
| 4684 | |
| 4685 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 4686 | |
| 4687 | #if defined(HAVE_DEVICE_MACROS) |
| 4688 | |
| 4689 | PyDoc_STRVAR(os_makedev__doc__, |
| 4690 | "makedev($module, major, minor, /)\n" |
| 4691 | "--\n" |
| 4692 | "\n" |
| 4693 | "Composes a raw device number from the major and minor device numbers."); |
| 4694 | |
| 4695 | #define OS_MAKEDEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4696 | {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4697 | |
| 4698 | static dev_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4699 | os_makedev_impl(PyObject *module, int major, int minor); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4700 | |
| 4701 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4702 | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4703 | { |
| 4704 | PyObject *return_value = NULL; |
| 4705 | int major; |
| 4706 | int minor; |
| 4707 | dev_t _return_value; |
| 4708 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4709 | if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { |
| 4710 | goto exit; |
| 4711 | } |
| 4712 | if (PyFloat_Check(args[0])) { |
| 4713 | PyErr_SetString(PyExc_TypeError, |
| 4714 | "integer argument expected, got float" ); |
| 4715 | goto exit; |
| 4716 | } |
| 4717 | major = _PyLong_AsInt(args[0]); |
| 4718 | if (major == -1 && PyErr_Occurred()) { |
| 4719 | goto exit; |
| 4720 | } |
| 4721 | if (PyFloat_Check(args[1])) { |
| 4722 | PyErr_SetString(PyExc_TypeError, |
| 4723 | "integer argument expected, got float" ); |
| 4724 | goto exit; |
| 4725 | } |
| 4726 | minor = _PyLong_AsInt(args[1]); |
| 4727 | if (minor == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4728 | goto exit; |
| 4729 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4730 | _return_value = os_makedev_impl(module, major, minor); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4731 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4732 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4733 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4734 | return_value = _PyLong_FromDev(_return_value); |
| 4735 | |
| 4736 | exit: |
| 4737 | return return_value; |
| 4738 | } |
| 4739 | |
| 4740 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 4741 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4742 | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4743 | |
| 4744 | PyDoc_STRVAR(os_ftruncate__doc__, |
| 4745 | "ftruncate($module, fd, length, /)\n" |
| 4746 | "--\n" |
| 4747 | "\n" |
| 4748 | "Truncate a file, specified by file descriptor, to a specific length."); |
| 4749 | |
| 4750 | #define OS_FTRUNCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4751 | {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4752 | |
| 4753 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4754 | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4755 | |
| 4756 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4757 | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4758 | { |
| 4759 | PyObject *return_value = NULL; |
| 4760 | int fd; |
| 4761 | Py_off_t length; |
| 4762 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4763 | if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { |
| 4764 | goto exit; |
| 4765 | } |
| 4766 | if (PyFloat_Check(args[0])) { |
| 4767 | PyErr_SetString(PyExc_TypeError, |
| 4768 | "integer argument expected, got float" ); |
| 4769 | goto exit; |
| 4770 | } |
| 4771 | fd = _PyLong_AsInt(args[0]); |
| 4772 | if (fd == -1 && PyErr_Occurred()) { |
| 4773 | goto exit; |
| 4774 | } |
| 4775 | if (!Py_off_t_converter(args[1], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4776 | goto exit; |
| 4777 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4778 | return_value = os_ftruncate_impl(module, fd, length); |
| 4779 | |
| 4780 | exit: |
| 4781 | return return_value; |
| 4782 | } |
| 4783 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4784 | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4785 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4786 | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4787 | |
| 4788 | PyDoc_STRVAR(os_truncate__doc__, |
| 4789 | "truncate($module, /, path, length)\n" |
| 4790 | "--\n" |
| 4791 | "\n" |
| 4792 | "Truncate a file, specified by path, to a specific length.\n" |
| 4793 | "\n" |
| 4794 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 4795 | " If this functionality is unavailable, using it raises an exception."); |
| 4796 | |
| 4797 | #define OS_TRUNCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4798 | {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4799 | |
| 4800 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4801 | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4802 | |
| 4803 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4804 | os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4805 | { |
| 4806 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4807 | static const char * const _keywords[] = {"path", "length", NULL}; |
| 4808 | static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4809 | path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE); |
| 4810 | Py_off_t length; |
| 4811 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 4812 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4813 | path_converter, &path, Py_off_t_converter, &length)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4814 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4815 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4816 | return_value = os_truncate_impl(module, &path, length); |
| 4817 | |
| 4818 | exit: |
| 4819 | /* Cleanup for path */ |
| 4820 | path_cleanup(&path); |
| 4821 | |
| 4822 | return return_value; |
| 4823 | } |
| 4824 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4825 | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4826 | |
| 4827 | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 4828 | |
| 4829 | PyDoc_STRVAR(os_posix_fallocate__doc__, |
| 4830 | "posix_fallocate($module, fd, offset, length, /)\n" |
| 4831 | "--\n" |
| 4832 | "\n" |
| 4833 | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
| 4834 | "\n" |
| 4835 | "Ensure that the file specified by fd encompasses a range of bytes\n" |
| 4836 | "starting at offset bytes from the beginning and continuing for length bytes."); |
| 4837 | |
| 4838 | #define OS_POSIX_FALLOCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4839 | {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4840 | |
| 4841 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4842 | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 4843 | Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4844 | |
| 4845 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4846 | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4847 | { |
| 4848 | PyObject *return_value = NULL; |
| 4849 | int fd; |
| 4850 | Py_off_t offset; |
| 4851 | Py_off_t length; |
| 4852 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4853 | if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { |
| 4854 | goto exit; |
| 4855 | } |
| 4856 | if (PyFloat_Check(args[0])) { |
| 4857 | PyErr_SetString(PyExc_TypeError, |
| 4858 | "integer argument expected, got float" ); |
| 4859 | goto exit; |
| 4860 | } |
| 4861 | fd = _PyLong_AsInt(args[0]); |
| 4862 | if (fd == -1 && PyErr_Occurred()) { |
| 4863 | goto exit; |
| 4864 | } |
| 4865 | if (!Py_off_t_converter(args[1], &offset)) { |
| 4866 | goto exit; |
| 4867 | } |
| 4868 | if (!Py_off_t_converter(args[2], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4869 | goto exit; |
| 4870 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4871 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
| 4872 | |
| 4873 | exit: |
| 4874 | return return_value; |
| 4875 | } |
| 4876 | |
| 4877 | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 4878 | |
| 4879 | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 4880 | |
| 4881 | PyDoc_STRVAR(os_posix_fadvise__doc__, |
| 4882 | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
| 4883 | "--\n" |
| 4884 | "\n" |
| 4885 | "Announce an intention to access data in a specific pattern.\n" |
| 4886 | "\n" |
| 4887 | "Announce an intention to access data in a specific pattern, thus allowing\n" |
| 4888 | "the kernel to make optimizations.\n" |
| 4889 | "The advice applies to the region of the file specified by fd starting at\n" |
| 4890 | "offset and continuing for length bytes.\n" |
| 4891 | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
| 4892 | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
| 4893 | "POSIX_FADV_DONTNEED."); |
| 4894 | |
| 4895 | #define OS_POSIX_FADVISE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4896 | {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4897 | |
| 4898 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4899 | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 4900 | Py_off_t length, int advice); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4901 | |
| 4902 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4903 | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4904 | { |
| 4905 | PyObject *return_value = NULL; |
| 4906 | int fd; |
| 4907 | Py_off_t offset; |
| 4908 | Py_off_t length; |
| 4909 | int advice; |
| 4910 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4911 | if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { |
| 4912 | goto exit; |
| 4913 | } |
| 4914 | if (PyFloat_Check(args[0])) { |
| 4915 | PyErr_SetString(PyExc_TypeError, |
| 4916 | "integer argument expected, got float" ); |
| 4917 | goto exit; |
| 4918 | } |
| 4919 | fd = _PyLong_AsInt(args[0]); |
| 4920 | if (fd == -1 && PyErr_Occurred()) { |
| 4921 | goto exit; |
| 4922 | } |
| 4923 | if (!Py_off_t_converter(args[1], &offset)) { |
| 4924 | goto exit; |
| 4925 | } |
| 4926 | if (!Py_off_t_converter(args[2], &length)) { |
| 4927 | goto exit; |
| 4928 | } |
| 4929 | if (PyFloat_Check(args[3])) { |
| 4930 | PyErr_SetString(PyExc_TypeError, |
| 4931 | "integer argument expected, got float" ); |
| 4932 | goto exit; |
| 4933 | } |
| 4934 | advice = _PyLong_AsInt(args[3]); |
| 4935 | if (advice == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4936 | goto exit; |
| 4937 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4938 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
| 4939 | |
| 4940 | exit: |
| 4941 | return return_value; |
| 4942 | } |
| 4943 | |
| 4944 | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 4945 | |
| 4946 | #if defined(HAVE_PUTENV) && defined(MS_WINDOWS) |
| 4947 | |
| 4948 | PyDoc_STRVAR(os_putenv__doc__, |
| 4949 | "putenv($module, name, value, /)\n" |
| 4950 | "--\n" |
| 4951 | "\n" |
| 4952 | "Change or add an environment variable."); |
| 4953 | |
| 4954 | #define OS_PUTENV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4955 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4956 | |
| 4957 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4958 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4959 | |
| 4960 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4961 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4962 | { |
| 4963 | PyObject *return_value = NULL; |
| 4964 | PyObject *name; |
| 4965 | PyObject *value; |
| 4966 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4967 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4968 | goto exit; |
| 4969 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 4970 | if (!PyUnicode_Check(args[0])) { |
| 4971 | _PyArg_BadArgument("putenv", 1, "str", args[0]); |
| 4972 | goto exit; |
| 4973 | } |
| 4974 | if (PyUnicode_READY(args[0]) == -1) { |
| 4975 | goto exit; |
| 4976 | } |
| 4977 | name = args[0]; |
| 4978 | if (!PyUnicode_Check(args[1])) { |
| 4979 | _PyArg_BadArgument("putenv", 2, "str", args[1]); |
| 4980 | goto exit; |
| 4981 | } |
| 4982 | if (PyUnicode_READY(args[1]) == -1) { |
| 4983 | goto exit; |
| 4984 | } |
| 4985 | value = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4986 | return_value = os_putenv_impl(module, name, value); |
| 4987 | |
| 4988 | exit: |
| 4989 | return return_value; |
| 4990 | } |
| 4991 | |
| 4992 | #endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */ |
| 4993 | |
| 4994 | #if defined(HAVE_PUTENV) && !defined(MS_WINDOWS) |
| 4995 | |
| 4996 | PyDoc_STRVAR(os_putenv__doc__, |
| 4997 | "putenv($module, name, value, /)\n" |
| 4998 | "--\n" |
| 4999 | "\n" |
| 5000 | "Change or add an environment variable."); |
| 5001 | |
| 5002 | #define OS_PUTENV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5003 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5004 | |
| 5005 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5006 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5007 | |
| 5008 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5009 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5010 | { |
| 5011 | PyObject *return_value = NULL; |
| 5012 | PyObject *name = NULL; |
| 5013 | PyObject *value = NULL; |
| 5014 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 5015 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
| 5016 | goto exit; |
| 5017 | } |
| 5018 | if (!PyUnicode_FSConverter(args[0], &name)) { |
| 5019 | goto exit; |
| 5020 | } |
| 5021 | if (!PyUnicode_FSConverter(args[1], &value)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5022 | goto exit; |
| 5023 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5024 | return_value = os_putenv_impl(module, name, value); |
| 5025 | |
| 5026 | exit: |
| 5027 | /* Cleanup for name */ |
| 5028 | Py_XDECREF(name); |
| 5029 | /* Cleanup for value */ |
| 5030 | Py_XDECREF(value); |
| 5031 | |
| 5032 | return return_value; |
| 5033 | } |
| 5034 | |
| 5035 | #endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */ |
| 5036 | |
| 5037 | #if defined(HAVE_UNSETENV) |
| 5038 | |
| 5039 | PyDoc_STRVAR(os_unsetenv__doc__, |
| 5040 | "unsetenv($module, name, /)\n" |
| 5041 | "--\n" |
| 5042 | "\n" |
| 5043 | "Delete an environment variable."); |
| 5044 | |
| 5045 | #define OS_UNSETENV_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5046 | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5047 | |
| 5048 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5049 | os_unsetenv_impl(PyObject *module, PyObject *name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5050 | |
| 5051 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5052 | os_unsetenv(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5053 | { |
| 5054 | PyObject *return_value = NULL; |
| 5055 | PyObject *name = NULL; |
| 5056 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5057 | if (!PyUnicode_FSConverter(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5058 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5059 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5060 | return_value = os_unsetenv_impl(module, name); |
| 5061 | |
| 5062 | exit: |
| 5063 | /* Cleanup for name */ |
| 5064 | Py_XDECREF(name); |
| 5065 | |
| 5066 | return return_value; |
| 5067 | } |
| 5068 | |
| 5069 | #endif /* defined(HAVE_UNSETENV) */ |
| 5070 | |
| 5071 | PyDoc_STRVAR(os_strerror__doc__, |
| 5072 | "strerror($module, code, /)\n" |
| 5073 | "--\n" |
| 5074 | "\n" |
| 5075 | "Translate an error code to a message string."); |
| 5076 | |
| 5077 | #define OS_STRERROR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5078 | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5079 | |
| 5080 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5081 | os_strerror_impl(PyObject *module, int code); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5082 | |
| 5083 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5084 | os_strerror(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5085 | { |
| 5086 | PyObject *return_value = NULL; |
| 5087 | int code; |
| 5088 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5089 | if (PyFloat_Check(arg)) { |
| 5090 | PyErr_SetString(PyExc_TypeError, |
| 5091 | "integer argument expected, got float" ); |
| 5092 | goto exit; |
| 5093 | } |
| 5094 | code = _PyLong_AsInt(arg); |
| 5095 | if (code == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5096 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5097 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5098 | return_value = os_strerror_impl(module, code); |
| 5099 | |
| 5100 | exit: |
| 5101 | return return_value; |
| 5102 | } |
| 5103 | |
| 5104 | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
| 5105 | |
| 5106 | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
| 5107 | "WCOREDUMP($module, status, /)\n" |
| 5108 | "--\n" |
| 5109 | "\n" |
| 5110 | "Return True if the process returning status was dumped to a core file."); |
| 5111 | |
| 5112 | #define OS_WCOREDUMP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5113 | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5114 | |
| 5115 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5116 | os_WCOREDUMP_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5117 | |
| 5118 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5119 | os_WCOREDUMP(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5120 | { |
| 5121 | PyObject *return_value = NULL; |
| 5122 | int status; |
| 5123 | int _return_value; |
| 5124 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5125 | if (PyFloat_Check(arg)) { |
| 5126 | PyErr_SetString(PyExc_TypeError, |
| 5127 | "integer argument expected, got float" ); |
| 5128 | goto exit; |
| 5129 | } |
| 5130 | status = _PyLong_AsInt(arg); |
| 5131 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5132 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5133 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5134 | _return_value = os_WCOREDUMP_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5135 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5136 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5137 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5138 | return_value = PyBool_FromLong((long)_return_value); |
| 5139 | |
| 5140 | exit: |
| 5141 | return return_value; |
| 5142 | } |
| 5143 | |
| 5144 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
| 5145 | |
| 5146 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
| 5147 | |
| 5148 | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
| 5149 | "WIFCONTINUED($module, /, status)\n" |
| 5150 | "--\n" |
| 5151 | "\n" |
| 5152 | "Return True if a particular process was continued from a job control stop.\n" |
| 5153 | "\n" |
| 5154 | "Return True if the process returning status was continued from a\n" |
| 5155 | "job control stop."); |
| 5156 | |
| 5157 | #define OS_WIFCONTINUED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5158 | {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5159 | |
| 5160 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5161 | os_WIFCONTINUED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5162 | |
| 5163 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5164 | os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5165 | { |
| 5166 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5167 | static const char * const _keywords[] = {"status", NULL}; |
| 5168 | static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5169 | int status; |
| 5170 | int _return_value; |
| 5171 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5172 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5173 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5174 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5175 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5176 | _return_value = os_WIFCONTINUED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5177 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5178 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5179 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5180 | return_value = PyBool_FromLong((long)_return_value); |
| 5181 | |
| 5182 | exit: |
| 5183 | return return_value; |
| 5184 | } |
| 5185 | |
| 5186 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
| 5187 | |
| 5188 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
| 5189 | |
| 5190 | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
| 5191 | "WIFSTOPPED($module, /, status)\n" |
| 5192 | "--\n" |
| 5193 | "\n" |
| 5194 | "Return True if the process returning status was stopped."); |
| 5195 | |
| 5196 | #define OS_WIFSTOPPED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5197 | {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5198 | |
| 5199 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5200 | os_WIFSTOPPED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5201 | |
| 5202 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5203 | os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5204 | { |
| 5205 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5206 | static const char * const _keywords[] = {"status", NULL}; |
| 5207 | static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5208 | int status; |
| 5209 | int _return_value; |
| 5210 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5211 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5212 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5213 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5214 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5215 | _return_value = os_WIFSTOPPED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5216 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5217 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5218 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5219 | return_value = PyBool_FromLong((long)_return_value); |
| 5220 | |
| 5221 | exit: |
| 5222 | return return_value; |
| 5223 | } |
| 5224 | |
| 5225 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
| 5226 | |
| 5227 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
| 5228 | |
| 5229 | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
| 5230 | "WIFSIGNALED($module, /, status)\n" |
| 5231 | "--\n" |
| 5232 | "\n" |
| 5233 | "Return True if the process returning status was terminated by a signal."); |
| 5234 | |
| 5235 | #define OS_WIFSIGNALED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5236 | {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5237 | |
| 5238 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5239 | os_WIFSIGNALED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5240 | |
| 5241 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5242 | os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5243 | { |
| 5244 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5245 | static const char * const _keywords[] = {"status", NULL}; |
| 5246 | static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5247 | int status; |
| 5248 | int _return_value; |
| 5249 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5250 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5251 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5252 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5253 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5254 | _return_value = os_WIFSIGNALED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5255 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5256 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5257 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5258 | return_value = PyBool_FromLong((long)_return_value); |
| 5259 | |
| 5260 | exit: |
| 5261 | return return_value; |
| 5262 | } |
| 5263 | |
| 5264 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
| 5265 | |
| 5266 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
| 5267 | |
| 5268 | PyDoc_STRVAR(os_WIFEXITED__doc__, |
| 5269 | "WIFEXITED($module, /, status)\n" |
| 5270 | "--\n" |
| 5271 | "\n" |
| 5272 | "Return True if the process returning status exited via the exit() system call."); |
| 5273 | |
| 5274 | #define OS_WIFEXITED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5275 | {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5276 | |
| 5277 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5278 | os_WIFEXITED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5279 | |
| 5280 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5281 | os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5282 | { |
| 5283 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5284 | static const char * const _keywords[] = {"status", NULL}; |
| 5285 | static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5286 | int status; |
| 5287 | int _return_value; |
| 5288 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5289 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5290 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5291 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5292 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5293 | _return_value = os_WIFEXITED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5294 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5295 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5296 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5297 | return_value = PyBool_FromLong((long)_return_value); |
| 5298 | |
| 5299 | exit: |
| 5300 | return return_value; |
| 5301 | } |
| 5302 | |
| 5303 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
| 5304 | |
| 5305 | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
| 5306 | |
| 5307 | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
| 5308 | "WEXITSTATUS($module, /, status)\n" |
| 5309 | "--\n" |
| 5310 | "\n" |
| 5311 | "Return the process return code from status."); |
| 5312 | |
| 5313 | #define OS_WEXITSTATUS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5314 | {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5315 | |
| 5316 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5317 | os_WEXITSTATUS_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5318 | |
| 5319 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5320 | os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5321 | { |
| 5322 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5323 | static const char * const _keywords[] = {"status", NULL}; |
| 5324 | static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5325 | int status; |
| 5326 | int _return_value; |
| 5327 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5328 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5329 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5330 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5331 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5332 | _return_value = os_WEXITSTATUS_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5333 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5334 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5335 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5336 | return_value = PyLong_FromLong((long)_return_value); |
| 5337 | |
| 5338 | exit: |
| 5339 | return return_value; |
| 5340 | } |
| 5341 | |
| 5342 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
| 5343 | |
| 5344 | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
| 5345 | |
| 5346 | PyDoc_STRVAR(os_WTERMSIG__doc__, |
| 5347 | "WTERMSIG($module, /, status)\n" |
| 5348 | "--\n" |
| 5349 | "\n" |
| 5350 | "Return the signal that terminated the process that provided the status value."); |
| 5351 | |
| 5352 | #define OS_WTERMSIG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5353 | {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5354 | |
| 5355 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5356 | os_WTERMSIG_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5357 | |
| 5358 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5359 | os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5360 | { |
| 5361 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5362 | static const char * const _keywords[] = {"status", NULL}; |
| 5363 | static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5364 | int status; |
| 5365 | int _return_value; |
| 5366 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5367 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5368 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5369 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5370 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5371 | _return_value = os_WTERMSIG_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5372 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5373 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5374 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5375 | return_value = PyLong_FromLong((long)_return_value); |
| 5376 | |
| 5377 | exit: |
| 5378 | return return_value; |
| 5379 | } |
| 5380 | |
| 5381 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
| 5382 | |
| 5383 | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
| 5384 | |
| 5385 | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
| 5386 | "WSTOPSIG($module, /, status)\n" |
| 5387 | "--\n" |
| 5388 | "\n" |
| 5389 | "Return the signal that stopped the process that provided the status value."); |
| 5390 | |
| 5391 | #define OS_WSTOPSIG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5392 | {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5393 | |
| 5394 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5395 | os_WSTOPSIG_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5396 | |
| 5397 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5398 | os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5399 | { |
| 5400 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5401 | static const char * const _keywords[] = {"status", NULL}; |
| 5402 | static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5403 | int status; |
| 5404 | int _return_value; |
| 5405 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5406 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5407 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5408 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5409 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5410 | _return_value = os_WSTOPSIG_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5411 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5412 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5413 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5414 | return_value = PyLong_FromLong((long)_return_value); |
| 5415 | |
| 5416 | exit: |
| 5417 | return return_value; |
| 5418 | } |
| 5419 | |
| 5420 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
| 5421 | |
| 5422 | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 5423 | |
| 5424 | PyDoc_STRVAR(os_fstatvfs__doc__, |
| 5425 | "fstatvfs($module, fd, /)\n" |
| 5426 | "--\n" |
| 5427 | "\n" |
| 5428 | "Perform an fstatvfs system call on the given fd.\n" |
| 5429 | "\n" |
| 5430 | "Equivalent to statvfs(fd)."); |
| 5431 | |
| 5432 | #define OS_FSTATVFS_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5433 | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5434 | |
| 5435 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5436 | os_fstatvfs_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5437 | |
| 5438 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5439 | os_fstatvfs(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5440 | { |
| 5441 | PyObject *return_value = NULL; |
| 5442 | int fd; |
| 5443 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5444 | if (PyFloat_Check(arg)) { |
| 5445 | PyErr_SetString(PyExc_TypeError, |
| 5446 | "integer argument expected, got float" ); |
| 5447 | goto exit; |
| 5448 | } |
| 5449 | fd = _PyLong_AsInt(arg); |
| 5450 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5451 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5452 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5453 | return_value = os_fstatvfs_impl(module, fd); |
| 5454 | |
| 5455 | exit: |
| 5456 | return return_value; |
| 5457 | } |
| 5458 | |
| 5459 | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 5460 | |
| 5461 | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 5462 | |
| 5463 | PyDoc_STRVAR(os_statvfs__doc__, |
| 5464 | "statvfs($module, /, path)\n" |
| 5465 | "--\n" |
| 5466 | "\n" |
| 5467 | "Perform a statvfs system call on the given path.\n" |
| 5468 | "\n" |
| 5469 | "path may always be specified as a string.\n" |
| 5470 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 5471 | " If this functionality is unavailable, using it raises an exception."); |
| 5472 | |
| 5473 | #define OS_STATVFS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5474 | {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5475 | |
| 5476 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5477 | os_statvfs_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5478 | |
| 5479 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5480 | os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5481 | { |
| 5482 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5483 | static const char * const _keywords[] = {"path", NULL}; |
| 5484 | static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5485 | path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS); |
| 5486 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5487 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5488 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5489 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5490 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5491 | return_value = os_statvfs_impl(module, &path); |
| 5492 | |
| 5493 | exit: |
| 5494 | /* Cleanup for path */ |
| 5495 | path_cleanup(&path); |
| 5496 | |
| 5497 | return return_value; |
| 5498 | } |
| 5499 | |
| 5500 | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 5501 | |
| 5502 | #if defined(MS_WINDOWS) |
| 5503 | |
| 5504 | PyDoc_STRVAR(os__getdiskusage__doc__, |
| 5505 | "_getdiskusage($module, /, path)\n" |
| 5506 | "--\n" |
| 5507 | "\n" |
| 5508 | "Return disk usage statistics about the given path as a (total, free) tuple."); |
| 5509 | |
| 5510 | #define OS__GETDISKUSAGE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5511 | {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5512 | |
| 5513 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5514 | os__getdiskusage_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5515 | |
| 5516 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5517 | os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5518 | { |
| 5519 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5520 | static const char * const _keywords[] = {"path", NULL}; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5521 | static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0}; |
| 5522 | path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5523 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5524 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5525 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5526 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5527 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5528 | return_value = os__getdiskusage_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5529 | |
| 5530 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5531 | /* Cleanup for path */ |
| 5532 | path_cleanup(&path); |
| 5533 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5534 | return return_value; |
| 5535 | } |
| 5536 | |
| 5537 | #endif /* defined(MS_WINDOWS) */ |
| 5538 | |
| 5539 | #if defined(HAVE_FPATHCONF) |
| 5540 | |
| 5541 | PyDoc_STRVAR(os_fpathconf__doc__, |
| 5542 | "fpathconf($module, fd, name, /)\n" |
| 5543 | "--\n" |
| 5544 | "\n" |
| 5545 | "Return the configuration limit name for the file descriptor fd.\n" |
| 5546 | "\n" |
| 5547 | "If there is no limit, return -1."); |
| 5548 | |
| 5549 | #define OS_FPATHCONF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5550 | {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5551 | |
| 5552 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5553 | os_fpathconf_impl(PyObject *module, int fd, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5554 | |
| 5555 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5556 | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5557 | { |
| 5558 | PyObject *return_value = NULL; |
| 5559 | int fd; |
| 5560 | int name; |
| 5561 | long _return_value; |
| 5562 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 5563 | if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { |
| 5564 | goto exit; |
| 5565 | } |
| 5566 | if (PyFloat_Check(args[0])) { |
| 5567 | PyErr_SetString(PyExc_TypeError, |
| 5568 | "integer argument expected, got float" ); |
| 5569 | goto exit; |
| 5570 | } |
| 5571 | fd = _PyLong_AsInt(args[0]); |
| 5572 | if (fd == -1 && PyErr_Occurred()) { |
| 5573 | goto exit; |
| 5574 | } |
| 5575 | if (!conv_path_confname(args[1], &name)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5576 | goto exit; |
| 5577 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5578 | _return_value = os_fpathconf_impl(module, fd, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5579 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5580 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5581 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5582 | return_value = PyLong_FromLong(_return_value); |
| 5583 | |
| 5584 | exit: |
| 5585 | return return_value; |
| 5586 | } |
| 5587 | |
| 5588 | #endif /* defined(HAVE_FPATHCONF) */ |
| 5589 | |
| 5590 | #if defined(HAVE_PATHCONF) |
| 5591 | |
| 5592 | PyDoc_STRVAR(os_pathconf__doc__, |
| 5593 | "pathconf($module, /, path, name)\n" |
| 5594 | "--\n" |
| 5595 | "\n" |
| 5596 | "Return the configuration limit name for the file or directory path.\n" |
| 5597 | "\n" |
| 5598 | "If there is no limit, return -1.\n" |
| 5599 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 5600 | " If this functionality is unavailable, using it raises an exception."); |
| 5601 | |
| 5602 | #define OS_PATHCONF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5603 | {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5604 | |
| 5605 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5606 | os_pathconf_impl(PyObject *module, path_t *path, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5607 | |
| 5608 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5609 | os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5610 | { |
| 5611 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5612 | static const char * const _keywords[] = {"path", "name", NULL}; |
| 5613 | static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5614 | path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF); |
| 5615 | int name; |
| 5616 | long _return_value; |
| 5617 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5618 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5619 | path_converter, &path, conv_path_confname, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5620 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5621 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5622 | _return_value = os_pathconf_impl(module, &path, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5623 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5624 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5625 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5626 | return_value = PyLong_FromLong(_return_value); |
| 5627 | |
| 5628 | exit: |
| 5629 | /* Cleanup for path */ |
| 5630 | path_cleanup(&path); |
| 5631 | |
| 5632 | return return_value; |
| 5633 | } |
| 5634 | |
| 5635 | #endif /* defined(HAVE_PATHCONF) */ |
| 5636 | |
| 5637 | #if defined(HAVE_CONFSTR) |
| 5638 | |
| 5639 | PyDoc_STRVAR(os_confstr__doc__, |
| 5640 | "confstr($module, name, /)\n" |
| 5641 | "--\n" |
| 5642 | "\n" |
| 5643 | "Return a string-valued system configuration variable."); |
| 5644 | |
| 5645 | #define OS_CONFSTR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5646 | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5647 | |
| 5648 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5649 | os_confstr_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5650 | |
| 5651 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5652 | os_confstr(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5653 | { |
| 5654 | PyObject *return_value = NULL; |
| 5655 | int name; |
| 5656 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5657 | if (!conv_confstr_confname(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5658 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5659 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5660 | return_value = os_confstr_impl(module, name); |
| 5661 | |
| 5662 | exit: |
| 5663 | return return_value; |
| 5664 | } |
| 5665 | |
| 5666 | #endif /* defined(HAVE_CONFSTR) */ |
| 5667 | |
| 5668 | #if defined(HAVE_SYSCONF) |
| 5669 | |
| 5670 | PyDoc_STRVAR(os_sysconf__doc__, |
| 5671 | "sysconf($module, name, /)\n" |
| 5672 | "--\n" |
| 5673 | "\n" |
| 5674 | "Return an integer-valued system configuration variable."); |
| 5675 | |
| 5676 | #define OS_SYSCONF_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5677 | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5678 | |
| 5679 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5680 | os_sysconf_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5681 | |
| 5682 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5683 | os_sysconf(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5684 | { |
| 5685 | PyObject *return_value = NULL; |
| 5686 | int name; |
| 5687 | long _return_value; |
| 5688 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5689 | if (!conv_sysconf_confname(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5690 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5691 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5692 | _return_value = os_sysconf_impl(module, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5693 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5694 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5695 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5696 | return_value = PyLong_FromLong(_return_value); |
| 5697 | |
| 5698 | exit: |
| 5699 | return return_value; |
| 5700 | } |
| 5701 | |
| 5702 | #endif /* defined(HAVE_SYSCONF) */ |
| 5703 | |
| 5704 | PyDoc_STRVAR(os_abort__doc__, |
| 5705 | "abort($module, /)\n" |
| 5706 | "--\n" |
| 5707 | "\n" |
| 5708 | "Abort the interpreter immediately.\n" |
| 5709 | "\n" |
| 5710 | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
| 5711 | "on the hosting operating system. This function never returns."); |
| 5712 | |
| 5713 | #define OS_ABORT_METHODDEF \ |
| 5714 | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
| 5715 | |
| 5716 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5717 | os_abort_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5718 | |
| 5719 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5720 | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5721 | { |
| 5722 | return os_abort_impl(module); |
| 5723 | } |
| 5724 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5725 | #if defined(MS_WINDOWS) |
| 5726 | |
| 5727 | PyDoc_STRVAR(os_startfile__doc__, |
| 5728 | "startfile($module, /, filepath, operation=None)\n" |
| 5729 | "--\n" |
| 5730 | "\n" |
| 5731 | "startfile(filepath [, operation])\n" |
| 5732 | "\n" |
| 5733 | "Start a file with its associated application.\n" |
| 5734 | "\n" |
| 5735 | "When \"operation\" is not specified or \"open\", this acts like\n" |
| 5736 | "double-clicking the file in Explorer, or giving the file name as an\n" |
| 5737 | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
| 5738 | "application (if any) its extension is associated.\n" |
| 5739 | "When another \"operation\" is given, it specifies what should be done with\n" |
| 5740 | "the file. A typical operation is \"print\".\n" |
| 5741 | "\n" |
| 5742 | "startfile returns as soon as the associated application is launched.\n" |
| 5743 | "There is no option to wait for the application to close, and no way\n" |
| 5744 | "to retrieve the application\'s exit status.\n" |
| 5745 | "\n" |
| 5746 | "The filepath is relative to the current directory. If you want to use\n" |
| 5747 | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
| 5748 | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
| 5749 | |
| 5750 | #define OS_STARTFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5751 | {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__}, |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5752 | |
| 5753 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 5754 | os_startfile_impl(PyObject *module, path_t *filepath, |
| 5755 | const Py_UNICODE *operation); |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5756 | |
| 5757 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5758 | os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5759 | { |
| 5760 | PyObject *return_value = NULL; |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5761 | static const char * const _keywords[] = {"filepath", "operation", NULL}; |
| 5762 | static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0}; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5763 | path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0); |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 5764 | const Py_UNICODE *operation = NULL; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5765 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5766 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5767 | path_converter, &filepath, &operation)) { |
| 5768 | goto exit; |
| 5769 | } |
| 5770 | return_value = os_startfile_impl(module, &filepath, operation); |
| 5771 | |
| 5772 | exit: |
| 5773 | /* Cleanup for filepath */ |
| 5774 | path_cleanup(&filepath); |
| 5775 | |
| 5776 | return return_value; |
| 5777 | } |
| 5778 | |
| 5779 | #endif /* defined(MS_WINDOWS) */ |
| 5780 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5781 | #if defined(HAVE_GETLOADAVG) |
| 5782 | |
| 5783 | PyDoc_STRVAR(os_getloadavg__doc__, |
| 5784 | "getloadavg($module, /)\n" |
| 5785 | "--\n" |
| 5786 | "\n" |
| 5787 | "Return average recent system load information.\n" |
| 5788 | "\n" |
| 5789 | "Return the number of processes in the system run queue averaged over\n" |
| 5790 | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
| 5791 | "Raises OSError if the load average was unobtainable."); |
| 5792 | |
| 5793 | #define OS_GETLOADAVG_METHODDEF \ |
| 5794 | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
| 5795 | |
| 5796 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5797 | os_getloadavg_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5798 | |
| 5799 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5800 | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5801 | { |
| 5802 | return os_getloadavg_impl(module); |
| 5803 | } |
| 5804 | |
| 5805 | #endif /* defined(HAVE_GETLOADAVG) */ |
| 5806 | |
| 5807 | PyDoc_STRVAR(os_device_encoding__doc__, |
| 5808 | "device_encoding($module, /, fd)\n" |
| 5809 | "--\n" |
| 5810 | "\n" |
| 5811 | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
| 5812 | "\n" |
| 5813 | "The file descriptor must be attached to a terminal.\n" |
| 5814 | "If the device is not a terminal, return None."); |
| 5815 | |
| 5816 | #define OS_DEVICE_ENCODING_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5817 | {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5818 | |
| 5819 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5820 | os_device_encoding_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5821 | |
| 5822 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5823 | os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5824 | { |
| 5825 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5826 | static const char * const _keywords[] = {"fd", NULL}; |
| 5827 | static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5828 | int fd; |
| 5829 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5830 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5831 | &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5832 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5833 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5834 | return_value = os_device_encoding_impl(module, fd); |
| 5835 | |
| 5836 | exit: |
| 5837 | return return_value; |
| 5838 | } |
| 5839 | |
| 5840 | #if defined(HAVE_SETRESUID) |
| 5841 | |
| 5842 | PyDoc_STRVAR(os_setresuid__doc__, |
| 5843 | "setresuid($module, ruid, euid, suid, /)\n" |
| 5844 | "--\n" |
| 5845 | "\n" |
| 5846 | "Set the current process\'s real, effective, and saved user ids."); |
| 5847 | |
| 5848 | #define OS_SETRESUID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5849 | {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5850 | |
| 5851 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5852 | os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5853 | |
| 5854 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5855 | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5856 | { |
| 5857 | PyObject *return_value = NULL; |
| 5858 | uid_t ruid; |
| 5859 | uid_t euid; |
| 5860 | uid_t suid; |
| 5861 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 5862 | if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { |
| 5863 | goto exit; |
| 5864 | } |
| 5865 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
| 5866 | goto exit; |
| 5867 | } |
| 5868 | if (!_Py_Uid_Converter(args[1], &euid)) { |
| 5869 | goto exit; |
| 5870 | } |
| 5871 | if (!_Py_Uid_Converter(args[2], &suid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5872 | goto exit; |
| 5873 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5874 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
| 5875 | |
| 5876 | exit: |
| 5877 | return return_value; |
| 5878 | } |
| 5879 | |
| 5880 | #endif /* defined(HAVE_SETRESUID) */ |
| 5881 | |
| 5882 | #if defined(HAVE_SETRESGID) |
| 5883 | |
| 5884 | PyDoc_STRVAR(os_setresgid__doc__, |
| 5885 | "setresgid($module, rgid, egid, sgid, /)\n" |
| 5886 | "--\n" |
| 5887 | "\n" |
| 5888 | "Set the current process\'s real, effective, and saved group ids."); |
| 5889 | |
| 5890 | #define OS_SETRESGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5891 | {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5892 | |
| 5893 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5894 | os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5895 | |
| 5896 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5897 | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5898 | { |
| 5899 | PyObject *return_value = NULL; |
| 5900 | gid_t rgid; |
| 5901 | gid_t egid; |
| 5902 | gid_t sgid; |
| 5903 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 5904 | if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { |
| 5905 | goto exit; |
| 5906 | } |
| 5907 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
| 5908 | goto exit; |
| 5909 | } |
| 5910 | if (!_Py_Gid_Converter(args[1], &egid)) { |
| 5911 | goto exit; |
| 5912 | } |
| 5913 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5914 | goto exit; |
| 5915 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5916 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
| 5917 | |
| 5918 | exit: |
| 5919 | return return_value; |
| 5920 | } |
| 5921 | |
| 5922 | #endif /* defined(HAVE_SETRESGID) */ |
| 5923 | |
| 5924 | #if defined(HAVE_GETRESUID) |
| 5925 | |
| 5926 | PyDoc_STRVAR(os_getresuid__doc__, |
| 5927 | "getresuid($module, /)\n" |
| 5928 | "--\n" |
| 5929 | "\n" |
| 5930 | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
| 5931 | |
| 5932 | #define OS_GETRESUID_METHODDEF \ |
| 5933 | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
| 5934 | |
| 5935 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5936 | os_getresuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5937 | |
| 5938 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5939 | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5940 | { |
| 5941 | return os_getresuid_impl(module); |
| 5942 | } |
| 5943 | |
| 5944 | #endif /* defined(HAVE_GETRESUID) */ |
| 5945 | |
| 5946 | #if defined(HAVE_GETRESGID) |
| 5947 | |
| 5948 | PyDoc_STRVAR(os_getresgid__doc__, |
| 5949 | "getresgid($module, /)\n" |
| 5950 | "--\n" |
| 5951 | "\n" |
| 5952 | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
| 5953 | |
| 5954 | #define OS_GETRESGID_METHODDEF \ |
| 5955 | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
| 5956 | |
| 5957 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5958 | os_getresgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5959 | |
| 5960 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5961 | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5962 | { |
| 5963 | return os_getresgid_impl(module); |
| 5964 | } |
| 5965 | |
| 5966 | #endif /* defined(HAVE_GETRESGID) */ |
| 5967 | |
| 5968 | #if defined(USE_XATTRS) |
| 5969 | |
| 5970 | PyDoc_STRVAR(os_getxattr__doc__, |
| 5971 | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 5972 | "--\n" |
| 5973 | "\n" |
| 5974 | "Return the value of extended attribute attribute on path.\n" |
| 5975 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 5976 | "path may be either a string, a path-like object, or an open file descriptor.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5977 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 5978 | " link, getxattr will examine the symbolic link itself instead of the file\n" |
| 5979 | " the link points to."); |
| 5980 | |
| 5981 | #define OS_GETXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5982 | {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5983 | |
| 5984 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5985 | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 5986 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5987 | |
| 5988 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5989 | os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5990 | { |
| 5991 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5992 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
| 5993 | static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5994 | path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1); |
| 5995 | path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0); |
| 5996 | int follow_symlinks = 1; |
| 5997 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5998 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5999 | path_converter, &path, path_converter, &attribute, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6000 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6001 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6002 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
| 6003 | |
| 6004 | exit: |
| 6005 | /* Cleanup for path */ |
| 6006 | path_cleanup(&path); |
| 6007 | /* Cleanup for attribute */ |
| 6008 | path_cleanup(&attribute); |
| 6009 | |
| 6010 | return return_value; |
| 6011 | } |
| 6012 | |
| 6013 | #endif /* defined(USE_XATTRS) */ |
| 6014 | |
| 6015 | #if defined(USE_XATTRS) |
| 6016 | |
| 6017 | PyDoc_STRVAR(os_setxattr__doc__, |
| 6018 | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
| 6019 | " follow_symlinks=True)\n" |
| 6020 | "--\n" |
| 6021 | "\n" |
| 6022 | "Set extended attribute attribute on path to value.\n" |
| 6023 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 6024 | "path may be either a string, a path-like object, or an open file descriptor.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6025 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 6026 | " link, setxattr will modify the symbolic link itself instead of the file\n" |
| 6027 | " the link points to."); |
| 6028 | |
| 6029 | #define OS_SETXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6030 | {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6031 | |
| 6032 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6033 | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 6034 | Py_buffer *value, int flags, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6035 | |
| 6036 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6037 | os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6038 | { |
| 6039 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6040 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
| 6041 | static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6042 | path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1); |
| 6043 | path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0); |
| 6044 | Py_buffer value = {NULL, NULL}; |
| 6045 | int flags = 0; |
| 6046 | int follow_symlinks = 1; |
| 6047 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6048 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6049 | path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6050 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6051 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6052 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
| 6053 | |
| 6054 | exit: |
| 6055 | /* Cleanup for path */ |
| 6056 | path_cleanup(&path); |
| 6057 | /* Cleanup for attribute */ |
| 6058 | path_cleanup(&attribute); |
| 6059 | /* Cleanup for value */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6060 | if (value.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6061 | PyBuffer_Release(&value); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6062 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6063 | |
| 6064 | return return_value; |
| 6065 | } |
| 6066 | |
| 6067 | #endif /* defined(USE_XATTRS) */ |
| 6068 | |
| 6069 | #if defined(USE_XATTRS) |
| 6070 | |
| 6071 | PyDoc_STRVAR(os_removexattr__doc__, |
| 6072 | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 6073 | "--\n" |
| 6074 | "\n" |
| 6075 | "Remove extended attribute attribute on path.\n" |
| 6076 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 6077 | "path may be either a string, a path-like object, or an open file descriptor.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6078 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 6079 | " link, removexattr will modify the symbolic link itself instead of the file\n" |
| 6080 | " the link points to."); |
| 6081 | |
| 6082 | #define OS_REMOVEXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6083 | {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6084 | |
| 6085 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6086 | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 6087 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6088 | |
| 6089 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6090 | os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6091 | { |
| 6092 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6093 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
| 6094 | static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6095 | path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1); |
| 6096 | path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0); |
| 6097 | int follow_symlinks = 1; |
| 6098 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6099 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6100 | path_converter, &path, path_converter, &attribute, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6101 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6102 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6103 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
| 6104 | |
| 6105 | exit: |
| 6106 | /* Cleanup for path */ |
| 6107 | path_cleanup(&path); |
| 6108 | /* Cleanup for attribute */ |
| 6109 | path_cleanup(&attribute); |
| 6110 | |
| 6111 | return return_value; |
| 6112 | } |
| 6113 | |
| 6114 | #endif /* defined(USE_XATTRS) */ |
| 6115 | |
| 6116 | #if defined(USE_XATTRS) |
| 6117 | |
| 6118 | PyDoc_STRVAR(os_listxattr__doc__, |
| 6119 | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
| 6120 | "--\n" |
| 6121 | "\n" |
| 6122 | "Return a list of extended attributes on path.\n" |
| 6123 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 6124 | "path may be either None, a string, a path-like object, or an open file descriptor.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6125 | "if path is None, listxattr will examine the current directory.\n" |
| 6126 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 6127 | " link, listxattr will examine the symbolic link itself instead of the file\n" |
| 6128 | " the link points to."); |
| 6129 | |
| 6130 | #define OS_LISTXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6131 | {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6132 | |
| 6133 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6134 | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6135 | |
| 6136 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6137 | os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6138 | { |
| 6139 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6140 | static const char * const _keywords[] = {"path", "follow_symlinks", NULL}; |
| 6141 | static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6142 | path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1); |
| 6143 | int follow_symlinks = 1; |
| 6144 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6145 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6146 | path_converter, &path, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6147 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6148 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6149 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
| 6150 | |
| 6151 | exit: |
| 6152 | /* Cleanup for path */ |
| 6153 | path_cleanup(&path); |
| 6154 | |
| 6155 | return return_value; |
| 6156 | } |
| 6157 | |
| 6158 | #endif /* defined(USE_XATTRS) */ |
| 6159 | |
| 6160 | PyDoc_STRVAR(os_urandom__doc__, |
| 6161 | "urandom($module, size, /)\n" |
| 6162 | "--\n" |
| 6163 | "\n" |
| 6164 | "Return a bytes object containing random bytes suitable for cryptographic use."); |
| 6165 | |
| 6166 | #define OS_URANDOM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6167 | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6168 | |
| 6169 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6170 | os_urandom_impl(PyObject *module, Py_ssize_t size); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6171 | |
| 6172 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6173 | os_urandom(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6174 | { |
| 6175 | PyObject *return_value = NULL; |
| 6176 | Py_ssize_t size; |
| 6177 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6178 | if (PyFloat_Check(arg)) { |
| 6179 | PyErr_SetString(PyExc_TypeError, |
| 6180 | "integer argument expected, got float" ); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6181 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6182 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6183 | { |
| 6184 | Py_ssize_t ival = -1; |
| 6185 | PyObject *iobj = PyNumber_Index(arg); |
| 6186 | if (iobj != NULL) { |
| 6187 | ival = PyLong_AsSsize_t(iobj); |
| 6188 | Py_DECREF(iobj); |
| 6189 | } |
| 6190 | if (ival == -1 && PyErr_Occurred()) { |
| 6191 | goto exit; |
| 6192 | } |
| 6193 | size = ival; |
| 6194 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6195 | return_value = os_urandom_impl(module, size); |
| 6196 | |
| 6197 | exit: |
| 6198 | return return_value; |
| 6199 | } |
| 6200 | |
| 6201 | PyDoc_STRVAR(os_cpu_count__doc__, |
| 6202 | "cpu_count($module, /)\n" |
| 6203 | "--\n" |
| 6204 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 6205 | "Return the number of CPUs in the system; return None if indeterminable.\n" |
| 6206 | "\n" |
| 6207 | "This number is not equivalent to the number of CPUs the current process can\n" |
| 6208 | "use. The number of usable CPUs can be obtained with\n" |
| 6209 | "``len(os.sched_getaffinity(0))``"); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6210 | |
| 6211 | #define OS_CPU_COUNT_METHODDEF \ |
| 6212 | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
| 6213 | |
| 6214 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6215 | os_cpu_count_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6216 | |
| 6217 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6218 | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6219 | { |
| 6220 | return os_cpu_count_impl(module); |
| 6221 | } |
| 6222 | |
| 6223 | PyDoc_STRVAR(os_get_inheritable__doc__, |
| 6224 | "get_inheritable($module, fd, /)\n" |
| 6225 | "--\n" |
| 6226 | "\n" |
| 6227 | "Get the close-on-exe flag of the specified file descriptor."); |
| 6228 | |
| 6229 | #define OS_GET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6230 | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6231 | |
| 6232 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6233 | os_get_inheritable_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6234 | |
| 6235 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6236 | os_get_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6237 | { |
| 6238 | PyObject *return_value = NULL; |
| 6239 | int fd; |
| 6240 | int _return_value; |
| 6241 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6242 | if (PyFloat_Check(arg)) { |
| 6243 | PyErr_SetString(PyExc_TypeError, |
| 6244 | "integer argument expected, got float" ); |
| 6245 | goto exit; |
| 6246 | } |
| 6247 | fd = _PyLong_AsInt(arg); |
| 6248 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6249 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6250 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6251 | _return_value = os_get_inheritable_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6252 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6253 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6254 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6255 | return_value = PyBool_FromLong((long)_return_value); |
| 6256 | |
| 6257 | exit: |
| 6258 | return return_value; |
| 6259 | } |
| 6260 | |
| 6261 | PyDoc_STRVAR(os_set_inheritable__doc__, |
| 6262 | "set_inheritable($module, fd, inheritable, /)\n" |
| 6263 | "--\n" |
| 6264 | "\n" |
| 6265 | "Set the inheritable flag of the specified file descriptor."); |
| 6266 | |
| 6267 | #define OS_SET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6268 | {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6269 | |
| 6270 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6271 | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6272 | |
| 6273 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6274 | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6275 | { |
| 6276 | PyObject *return_value = NULL; |
| 6277 | int fd; |
| 6278 | int inheritable; |
| 6279 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 6280 | if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { |
| 6281 | goto exit; |
| 6282 | } |
| 6283 | if (PyFloat_Check(args[0])) { |
| 6284 | PyErr_SetString(PyExc_TypeError, |
| 6285 | "integer argument expected, got float" ); |
| 6286 | goto exit; |
| 6287 | } |
| 6288 | fd = _PyLong_AsInt(args[0]); |
| 6289 | if (fd == -1 && PyErr_Occurred()) { |
| 6290 | goto exit; |
| 6291 | } |
| 6292 | if (PyFloat_Check(args[1])) { |
| 6293 | PyErr_SetString(PyExc_TypeError, |
| 6294 | "integer argument expected, got float" ); |
| 6295 | goto exit; |
| 6296 | } |
| 6297 | inheritable = _PyLong_AsInt(args[1]); |
| 6298 | if (inheritable == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6299 | goto exit; |
| 6300 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6301 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
| 6302 | |
| 6303 | exit: |
| 6304 | return return_value; |
| 6305 | } |
| 6306 | |
| 6307 | #if defined(MS_WINDOWS) |
| 6308 | |
| 6309 | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
| 6310 | "get_handle_inheritable($module, handle, /)\n" |
| 6311 | "--\n" |
| 6312 | "\n" |
| 6313 | "Get the close-on-exe flag of the specified file descriptor."); |
| 6314 | |
| 6315 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6316 | {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6317 | |
| 6318 | static int |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 6319 | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6320 | |
| 6321 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6322 | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6323 | { |
| 6324 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 6325 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6326 | int _return_value; |
| 6327 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6328 | if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6329 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6330 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6331 | _return_value = os_get_handle_inheritable_impl(module, handle); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6332 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6333 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6334 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6335 | return_value = PyBool_FromLong((long)_return_value); |
| 6336 | |
| 6337 | exit: |
| 6338 | return return_value; |
| 6339 | } |
| 6340 | |
| 6341 | #endif /* defined(MS_WINDOWS) */ |
| 6342 | |
| 6343 | #if defined(MS_WINDOWS) |
| 6344 | |
| 6345 | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
| 6346 | "set_handle_inheritable($module, handle, inheritable, /)\n" |
| 6347 | "--\n" |
| 6348 | "\n" |
| 6349 | "Set the inheritable flag of the specified handle."); |
| 6350 | |
| 6351 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6352 | {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6353 | |
| 6354 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 6355 | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 6356 | int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6357 | |
| 6358 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6359 | os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6360 | { |
| 6361 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 6362 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6363 | int inheritable; |
| 6364 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 6365 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable", |
| 6366 | &handle, &inheritable)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6367 | goto exit; |
| 6368 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6369 | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
| 6370 | |
| 6371 | exit: |
| 6372 | return return_value; |
| 6373 | } |
| 6374 | |
| 6375 | #endif /* defined(MS_WINDOWS) */ |
| 6376 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 6377 | #if !defined(MS_WINDOWS) |
| 6378 | |
| 6379 | PyDoc_STRVAR(os_get_blocking__doc__, |
| 6380 | "get_blocking($module, fd, /)\n" |
| 6381 | "--\n" |
| 6382 | "\n" |
| 6383 | "Get the blocking mode of the file descriptor.\n" |
| 6384 | "\n" |
| 6385 | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared."); |
| 6386 | |
| 6387 | #define OS_GET_BLOCKING_METHODDEF \ |
| 6388 | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
| 6389 | |
| 6390 | static int |
| 6391 | os_get_blocking_impl(PyObject *module, int fd); |
| 6392 | |
| 6393 | static PyObject * |
| 6394 | os_get_blocking(PyObject *module, PyObject *arg) |
| 6395 | { |
| 6396 | PyObject *return_value = NULL; |
| 6397 | int fd; |
| 6398 | int _return_value; |
| 6399 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6400 | if (PyFloat_Check(arg)) { |
| 6401 | PyErr_SetString(PyExc_TypeError, |
| 6402 | "integer argument expected, got float" ); |
| 6403 | goto exit; |
| 6404 | } |
| 6405 | fd = _PyLong_AsInt(arg); |
| 6406 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 6407 | goto exit; |
| 6408 | } |
| 6409 | _return_value = os_get_blocking_impl(module, fd); |
| 6410 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 6411 | goto exit; |
| 6412 | } |
| 6413 | return_value = PyBool_FromLong((long)_return_value); |
| 6414 | |
| 6415 | exit: |
| 6416 | return return_value; |
| 6417 | } |
| 6418 | |
| 6419 | #endif /* !defined(MS_WINDOWS) */ |
| 6420 | |
| 6421 | #if !defined(MS_WINDOWS) |
| 6422 | |
| 6423 | PyDoc_STRVAR(os_set_blocking__doc__, |
| 6424 | "set_blocking($module, fd, blocking, /)\n" |
| 6425 | "--\n" |
| 6426 | "\n" |
| 6427 | "Set the blocking mode of the specified file descriptor.\n" |
| 6428 | "\n" |
| 6429 | "Set the O_NONBLOCK flag if blocking is False,\n" |
| 6430 | "clear the O_NONBLOCK flag otherwise."); |
| 6431 | |
| 6432 | #define OS_SET_BLOCKING_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6433 | {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__}, |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 6434 | |
| 6435 | static PyObject * |
| 6436 | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
| 6437 | |
| 6438 | static PyObject * |
| 6439 | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 6440 | { |
| 6441 | PyObject *return_value = NULL; |
| 6442 | int fd; |
| 6443 | int blocking; |
| 6444 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 6445 | if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { |
| 6446 | goto exit; |
| 6447 | } |
| 6448 | if (PyFloat_Check(args[0])) { |
| 6449 | PyErr_SetString(PyExc_TypeError, |
| 6450 | "integer argument expected, got float" ); |
| 6451 | goto exit; |
| 6452 | } |
| 6453 | fd = _PyLong_AsInt(args[0]); |
| 6454 | if (fd == -1 && PyErr_Occurred()) { |
| 6455 | goto exit; |
| 6456 | } |
| 6457 | if (PyFloat_Check(args[1])) { |
| 6458 | PyErr_SetString(PyExc_TypeError, |
| 6459 | "integer argument expected, got float" ); |
| 6460 | goto exit; |
| 6461 | } |
| 6462 | blocking = _PyLong_AsInt(args[1]); |
| 6463 | if (blocking == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 6464 | goto exit; |
| 6465 | } |
| 6466 | return_value = os_set_blocking_impl(module, fd, blocking); |
| 6467 | |
| 6468 | exit: |
| 6469 | return return_value; |
| 6470 | } |
| 6471 | |
| 6472 | #endif /* !defined(MS_WINDOWS) */ |
| 6473 | |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6474 | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
| 6475 | "is_symlink($self, /)\n" |
| 6476 | "--\n" |
| 6477 | "\n" |
| 6478 | "Return True if the entry is a symbolic link; cached per entry."); |
| 6479 | |
| 6480 | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
| 6481 | {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__}, |
| 6482 | |
| 6483 | static int |
| 6484 | os_DirEntry_is_symlink_impl(DirEntry *self); |
| 6485 | |
| 6486 | static PyObject * |
| 6487 | os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 6488 | { |
| 6489 | PyObject *return_value = NULL; |
| 6490 | int _return_value; |
| 6491 | |
| 6492 | _return_value = os_DirEntry_is_symlink_impl(self); |
| 6493 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 6494 | goto exit; |
| 6495 | } |
| 6496 | return_value = PyBool_FromLong((long)_return_value); |
| 6497 | |
| 6498 | exit: |
| 6499 | return return_value; |
| 6500 | } |
| 6501 | |
| 6502 | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
| 6503 | "stat($self, /, *, follow_symlinks=True)\n" |
| 6504 | "--\n" |
| 6505 | "\n" |
| 6506 | "Return stat_result object for the entry; cached per entry."); |
| 6507 | |
| 6508 | #define OS_DIRENTRY_STAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6509 | {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__}, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6510 | |
| 6511 | static PyObject * |
| 6512 | os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks); |
| 6513 | |
| 6514 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6515 | os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6516 | { |
| 6517 | PyObject *return_value = NULL; |
| 6518 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
| 6519 | static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0}; |
| 6520 | int follow_symlinks = 1; |
| 6521 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6522 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6523 | &follow_symlinks)) { |
| 6524 | goto exit; |
| 6525 | } |
| 6526 | return_value = os_DirEntry_stat_impl(self, follow_symlinks); |
| 6527 | |
| 6528 | exit: |
| 6529 | return return_value; |
| 6530 | } |
| 6531 | |
| 6532 | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
| 6533 | "is_dir($self, /, *, follow_symlinks=True)\n" |
| 6534 | "--\n" |
| 6535 | "\n" |
| 6536 | "Return True if the entry is a directory; cached per entry."); |
| 6537 | |
| 6538 | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6539 | {"is_dir", (PyCFunction)(void(*)(void))os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__}, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6540 | |
| 6541 | static int |
| 6542 | os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks); |
| 6543 | |
| 6544 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6545 | os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6546 | { |
| 6547 | PyObject *return_value = NULL; |
| 6548 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
| 6549 | static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0}; |
| 6550 | int follow_symlinks = 1; |
| 6551 | int _return_value; |
| 6552 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6553 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6554 | &follow_symlinks)) { |
| 6555 | goto exit; |
| 6556 | } |
| 6557 | _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks); |
| 6558 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 6559 | goto exit; |
| 6560 | } |
| 6561 | return_value = PyBool_FromLong((long)_return_value); |
| 6562 | |
| 6563 | exit: |
| 6564 | return return_value; |
| 6565 | } |
| 6566 | |
| 6567 | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
| 6568 | "is_file($self, /, *, follow_symlinks=True)\n" |
| 6569 | "--\n" |
| 6570 | "\n" |
| 6571 | "Return True if the entry is a file; cached per entry."); |
| 6572 | |
| 6573 | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6574 | {"is_file", (PyCFunction)(void(*)(void))os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__}, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6575 | |
| 6576 | static int |
| 6577 | os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks); |
| 6578 | |
| 6579 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6580 | os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6581 | { |
| 6582 | PyObject *return_value = NULL; |
| 6583 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
| 6584 | static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0}; |
| 6585 | int follow_symlinks = 1; |
| 6586 | int _return_value; |
| 6587 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6588 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6589 | &follow_symlinks)) { |
| 6590 | goto exit; |
| 6591 | } |
| 6592 | _return_value = os_DirEntry_is_file_impl(self, follow_symlinks); |
| 6593 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 6594 | goto exit; |
| 6595 | } |
| 6596 | return_value = PyBool_FromLong((long)_return_value); |
| 6597 | |
| 6598 | exit: |
| 6599 | return return_value; |
| 6600 | } |
| 6601 | |
| 6602 | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
| 6603 | "inode($self, /)\n" |
| 6604 | "--\n" |
| 6605 | "\n" |
| 6606 | "Return inode of the entry; cached per entry."); |
| 6607 | |
| 6608 | #define OS_DIRENTRY_INODE_METHODDEF \ |
| 6609 | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
| 6610 | |
| 6611 | static PyObject * |
| 6612 | os_DirEntry_inode_impl(DirEntry *self); |
| 6613 | |
| 6614 | static PyObject * |
| 6615 | os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 6616 | { |
| 6617 | return os_DirEntry_inode_impl(self); |
| 6618 | } |
| 6619 | |
| 6620 | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
| 6621 | "__fspath__($self, /)\n" |
| 6622 | "--\n" |
| 6623 | "\n" |
| 6624 | "Returns the path for the entry."); |
| 6625 | |
| 6626 | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
| 6627 | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
| 6628 | |
| 6629 | static PyObject * |
| 6630 | os_DirEntry___fspath___impl(DirEntry *self); |
| 6631 | |
| 6632 | static PyObject * |
| 6633 | os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 6634 | { |
| 6635 | return os_DirEntry___fspath___impl(self); |
| 6636 | } |
| 6637 | |
| 6638 | PyDoc_STRVAR(os_scandir__doc__, |
| 6639 | "scandir($module, /, path=None)\n" |
| 6640 | "--\n" |
| 6641 | "\n" |
| 6642 | "Return an iterator of DirEntry objects for given path.\n" |
| 6643 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 6644 | "path can be specified as either str, bytes, or a path-like object. If path\n" |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6645 | "is bytes, the names of yielded DirEntry objects will also be bytes; in\n" |
| 6646 | "all other circumstances they will be str.\n" |
| 6647 | "\n" |
| 6648 | "If path is None, uses the path=\'.\'."); |
| 6649 | |
| 6650 | #define OS_SCANDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6651 | {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__}, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6652 | |
| 6653 | static PyObject * |
| 6654 | os_scandir_impl(PyObject *module, path_t *path); |
| 6655 | |
| 6656 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6657 | os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6658 | { |
| 6659 | PyObject *return_value = NULL; |
| 6660 | static const char * const _keywords[] = {"path", NULL}; |
| 6661 | static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0}; |
Serhiy Storchaka | ea720fe | 2017-03-30 09:12:31 +0300 | [diff] [blame] | 6662 | path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR); |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6663 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6664 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6665 | path_converter, &path)) { |
| 6666 | goto exit; |
| 6667 | } |
| 6668 | return_value = os_scandir_impl(module, &path); |
| 6669 | |
| 6670 | exit: |
| 6671 | /* Cleanup for path */ |
| 6672 | path_cleanup(&path); |
| 6673 | |
| 6674 | return return_value; |
| 6675 | } |
| 6676 | |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6677 | PyDoc_STRVAR(os_fspath__doc__, |
| 6678 | "fspath($module, /, path)\n" |
| 6679 | "--\n" |
| 6680 | "\n" |
| 6681 | "Return the file system path representation of the object.\n" |
| 6682 | "\n" |
Brett Cannon | b4f43e9 | 2016-06-09 14:32:08 -0700 | [diff] [blame] | 6683 | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
| 6684 | "object defines __fspath__(), then return the result of that method. All other\n" |
| 6685 | "types raise a TypeError."); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6686 | |
| 6687 | #define OS_FSPATH_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6688 | {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__}, |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6689 | |
| 6690 | static PyObject * |
Serhiy Storchaka | 2954f83 | 2016-07-07 18:20:03 +0300 | [diff] [blame] | 6691 | os_fspath_impl(PyObject *module, PyObject *path); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6692 | |
| 6693 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6694 | os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6695 | { |
| 6696 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6697 | static const char * const _keywords[] = {"path", NULL}; |
| 6698 | static _PyArg_Parser _parser = {"O:fspath", _keywords, 0}; |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6699 | PyObject *path; |
| 6700 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6701 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6702 | &path)) { |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6703 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6704 | } |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6705 | return_value = os_fspath_impl(module, path); |
| 6706 | |
| 6707 | exit: |
| 6708 | return return_value; |
| 6709 | } |
| 6710 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 6711 | #if defined(HAVE_GETRANDOM_SYSCALL) |
| 6712 | |
| 6713 | PyDoc_STRVAR(os_getrandom__doc__, |
| 6714 | "getrandom($module, /, size, flags=0)\n" |
| 6715 | "--\n" |
| 6716 | "\n" |
| 6717 | "Obtain a series of random bytes."); |
| 6718 | |
| 6719 | #define OS_GETRANDOM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6720 | {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__}, |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 6721 | |
| 6722 | static PyObject * |
| 6723 | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
| 6724 | |
| 6725 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6726 | os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 6727 | { |
| 6728 | PyObject *return_value = NULL; |
| 6729 | static const char * const _keywords[] = {"size", "flags", NULL}; |
| 6730 | static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0}; |
| 6731 | Py_ssize_t size; |
| 6732 | int flags = 0; |
| 6733 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6734 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 6735 | &size, &flags)) { |
| 6736 | goto exit; |
| 6737 | } |
| 6738 | return_value = os_getrandom_impl(module, size, flags); |
| 6739 | |
| 6740 | exit: |
| 6741 | return return_value; |
| 6742 | } |
| 6743 | |
| 6744 | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
| 6745 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6746 | #ifndef OS_TTYNAME_METHODDEF |
| 6747 | #define OS_TTYNAME_METHODDEF |
| 6748 | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
| 6749 | |
| 6750 | #ifndef OS_CTERMID_METHODDEF |
| 6751 | #define OS_CTERMID_METHODDEF |
| 6752 | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
| 6753 | |
| 6754 | #ifndef OS_FCHDIR_METHODDEF |
| 6755 | #define OS_FCHDIR_METHODDEF |
| 6756 | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
| 6757 | |
| 6758 | #ifndef OS_FCHMOD_METHODDEF |
| 6759 | #define OS_FCHMOD_METHODDEF |
| 6760 | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
| 6761 | |
| 6762 | #ifndef OS_LCHMOD_METHODDEF |
| 6763 | #define OS_LCHMOD_METHODDEF |
| 6764 | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
| 6765 | |
| 6766 | #ifndef OS_CHFLAGS_METHODDEF |
| 6767 | #define OS_CHFLAGS_METHODDEF |
| 6768 | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
| 6769 | |
| 6770 | #ifndef OS_LCHFLAGS_METHODDEF |
| 6771 | #define OS_LCHFLAGS_METHODDEF |
| 6772 | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
| 6773 | |
| 6774 | #ifndef OS_CHROOT_METHODDEF |
| 6775 | #define OS_CHROOT_METHODDEF |
| 6776 | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
| 6777 | |
| 6778 | #ifndef OS_FSYNC_METHODDEF |
| 6779 | #define OS_FSYNC_METHODDEF |
| 6780 | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
| 6781 | |
| 6782 | #ifndef OS_SYNC_METHODDEF |
| 6783 | #define OS_SYNC_METHODDEF |
| 6784 | #endif /* !defined(OS_SYNC_METHODDEF) */ |
| 6785 | |
| 6786 | #ifndef OS_FDATASYNC_METHODDEF |
| 6787 | #define OS_FDATASYNC_METHODDEF |
| 6788 | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
| 6789 | |
| 6790 | #ifndef OS_CHOWN_METHODDEF |
| 6791 | #define OS_CHOWN_METHODDEF |
| 6792 | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
| 6793 | |
| 6794 | #ifndef OS_FCHOWN_METHODDEF |
| 6795 | #define OS_FCHOWN_METHODDEF |
| 6796 | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
| 6797 | |
| 6798 | #ifndef OS_LCHOWN_METHODDEF |
| 6799 | #define OS_LCHOWN_METHODDEF |
| 6800 | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
| 6801 | |
| 6802 | #ifndef OS_LINK_METHODDEF |
| 6803 | #define OS_LINK_METHODDEF |
| 6804 | #endif /* !defined(OS_LINK_METHODDEF) */ |
| 6805 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 6806 | #ifndef OS__GETFULLPATHNAME_METHODDEF |
| 6807 | #define OS__GETFULLPATHNAME_METHODDEF |
| 6808 | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
| 6809 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6810 | #ifndef OS__GETFINALPATHNAME_METHODDEF |
| 6811 | #define OS__GETFINALPATHNAME_METHODDEF |
| 6812 | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
| 6813 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 6814 | #ifndef OS__ISDIR_METHODDEF |
| 6815 | #define OS__ISDIR_METHODDEF |
| 6816 | #endif /* !defined(OS__ISDIR_METHODDEF) */ |
| 6817 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6818 | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
| 6819 | #define OS__GETVOLUMEPATHNAME_METHODDEF |
| 6820 | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
| 6821 | |
| 6822 | #ifndef OS_NICE_METHODDEF |
| 6823 | #define OS_NICE_METHODDEF |
| 6824 | #endif /* !defined(OS_NICE_METHODDEF) */ |
| 6825 | |
| 6826 | #ifndef OS_GETPRIORITY_METHODDEF |
| 6827 | #define OS_GETPRIORITY_METHODDEF |
| 6828 | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
| 6829 | |
| 6830 | #ifndef OS_SETPRIORITY_METHODDEF |
| 6831 | #define OS_SETPRIORITY_METHODDEF |
| 6832 | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
| 6833 | |
| 6834 | #ifndef OS_SYSTEM_METHODDEF |
| 6835 | #define OS_SYSTEM_METHODDEF |
| 6836 | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
| 6837 | |
| 6838 | #ifndef OS_UNAME_METHODDEF |
| 6839 | #define OS_UNAME_METHODDEF |
| 6840 | #endif /* !defined(OS_UNAME_METHODDEF) */ |
| 6841 | |
| 6842 | #ifndef OS_EXECV_METHODDEF |
| 6843 | #define OS_EXECV_METHODDEF |
| 6844 | #endif /* !defined(OS_EXECV_METHODDEF) */ |
| 6845 | |
| 6846 | #ifndef OS_EXECVE_METHODDEF |
| 6847 | #define OS_EXECVE_METHODDEF |
| 6848 | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
| 6849 | |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 6850 | #ifndef OS_POSIX_SPAWN_METHODDEF |
| 6851 | #define OS_POSIX_SPAWN_METHODDEF |
| 6852 | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
| 6853 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6854 | #ifndef OS_SPAWNV_METHODDEF |
| 6855 | #define OS_SPAWNV_METHODDEF |
| 6856 | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
| 6857 | |
| 6858 | #ifndef OS_SPAWNVE_METHODDEF |
| 6859 | #define OS_SPAWNVE_METHODDEF |
| 6860 | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
| 6861 | |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 6862 | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
| 6863 | #define OS_REGISTER_AT_FORK_METHODDEF |
| 6864 | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
| 6865 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6866 | #ifndef OS_FORK1_METHODDEF |
| 6867 | #define OS_FORK1_METHODDEF |
| 6868 | #endif /* !defined(OS_FORK1_METHODDEF) */ |
| 6869 | |
| 6870 | #ifndef OS_FORK_METHODDEF |
| 6871 | #define OS_FORK_METHODDEF |
| 6872 | #endif /* !defined(OS_FORK_METHODDEF) */ |
| 6873 | |
| 6874 | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 6875 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 6876 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
| 6877 | |
| 6878 | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 6879 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 6880 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
| 6881 | |
| 6882 | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
| 6883 | #define OS_SCHED_GETSCHEDULER_METHODDEF |
| 6884 | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
| 6885 | |
| 6886 | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
| 6887 | #define OS_SCHED_SETSCHEDULER_METHODDEF |
| 6888 | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
| 6889 | |
| 6890 | #ifndef OS_SCHED_GETPARAM_METHODDEF |
| 6891 | #define OS_SCHED_GETPARAM_METHODDEF |
| 6892 | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
| 6893 | |
| 6894 | #ifndef OS_SCHED_SETPARAM_METHODDEF |
| 6895 | #define OS_SCHED_SETPARAM_METHODDEF |
| 6896 | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
| 6897 | |
| 6898 | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 6899 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 6900 | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
| 6901 | |
| 6902 | #ifndef OS_SCHED_YIELD_METHODDEF |
| 6903 | #define OS_SCHED_YIELD_METHODDEF |
| 6904 | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
| 6905 | |
| 6906 | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
| 6907 | #define OS_SCHED_SETAFFINITY_METHODDEF |
| 6908 | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
| 6909 | |
| 6910 | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
| 6911 | #define OS_SCHED_GETAFFINITY_METHODDEF |
| 6912 | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
| 6913 | |
| 6914 | #ifndef OS_OPENPTY_METHODDEF |
| 6915 | #define OS_OPENPTY_METHODDEF |
| 6916 | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
| 6917 | |
| 6918 | #ifndef OS_FORKPTY_METHODDEF |
| 6919 | #define OS_FORKPTY_METHODDEF |
| 6920 | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
| 6921 | |
| 6922 | #ifndef OS_GETEGID_METHODDEF |
| 6923 | #define OS_GETEGID_METHODDEF |
| 6924 | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
| 6925 | |
| 6926 | #ifndef OS_GETEUID_METHODDEF |
| 6927 | #define OS_GETEUID_METHODDEF |
| 6928 | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
| 6929 | |
| 6930 | #ifndef OS_GETGID_METHODDEF |
| 6931 | #define OS_GETGID_METHODDEF |
| 6932 | #endif /* !defined(OS_GETGID_METHODDEF) */ |
| 6933 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 6934 | #ifndef OS_GETPID_METHODDEF |
| 6935 | #define OS_GETPID_METHODDEF |
| 6936 | #endif /* !defined(OS_GETPID_METHODDEF) */ |
| 6937 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6938 | #ifndef OS_GETGROUPS_METHODDEF |
| 6939 | #define OS_GETGROUPS_METHODDEF |
| 6940 | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
| 6941 | |
| 6942 | #ifndef OS_GETPGID_METHODDEF |
| 6943 | #define OS_GETPGID_METHODDEF |
| 6944 | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
| 6945 | |
| 6946 | #ifndef OS_GETPGRP_METHODDEF |
| 6947 | #define OS_GETPGRP_METHODDEF |
| 6948 | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
| 6949 | |
| 6950 | #ifndef OS_SETPGRP_METHODDEF |
| 6951 | #define OS_SETPGRP_METHODDEF |
| 6952 | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
| 6953 | |
| 6954 | #ifndef OS_GETPPID_METHODDEF |
| 6955 | #define OS_GETPPID_METHODDEF |
| 6956 | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
| 6957 | |
| 6958 | #ifndef OS_GETLOGIN_METHODDEF |
| 6959 | #define OS_GETLOGIN_METHODDEF |
| 6960 | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
| 6961 | |
| 6962 | #ifndef OS_GETUID_METHODDEF |
| 6963 | #define OS_GETUID_METHODDEF |
| 6964 | #endif /* !defined(OS_GETUID_METHODDEF) */ |
| 6965 | |
| 6966 | #ifndef OS_KILL_METHODDEF |
| 6967 | #define OS_KILL_METHODDEF |
| 6968 | #endif /* !defined(OS_KILL_METHODDEF) */ |
| 6969 | |
| 6970 | #ifndef OS_KILLPG_METHODDEF |
| 6971 | #define OS_KILLPG_METHODDEF |
| 6972 | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
| 6973 | |
| 6974 | #ifndef OS_PLOCK_METHODDEF |
| 6975 | #define OS_PLOCK_METHODDEF |
| 6976 | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
| 6977 | |
| 6978 | #ifndef OS_SETUID_METHODDEF |
| 6979 | #define OS_SETUID_METHODDEF |
| 6980 | #endif /* !defined(OS_SETUID_METHODDEF) */ |
| 6981 | |
| 6982 | #ifndef OS_SETEUID_METHODDEF |
| 6983 | #define OS_SETEUID_METHODDEF |
| 6984 | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
| 6985 | |
| 6986 | #ifndef OS_SETEGID_METHODDEF |
| 6987 | #define OS_SETEGID_METHODDEF |
| 6988 | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
| 6989 | |
| 6990 | #ifndef OS_SETREUID_METHODDEF |
| 6991 | #define OS_SETREUID_METHODDEF |
| 6992 | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
| 6993 | |
| 6994 | #ifndef OS_SETREGID_METHODDEF |
| 6995 | #define OS_SETREGID_METHODDEF |
| 6996 | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
| 6997 | |
| 6998 | #ifndef OS_SETGID_METHODDEF |
| 6999 | #define OS_SETGID_METHODDEF |
| 7000 | #endif /* !defined(OS_SETGID_METHODDEF) */ |
| 7001 | |
| 7002 | #ifndef OS_SETGROUPS_METHODDEF |
| 7003 | #define OS_SETGROUPS_METHODDEF |
| 7004 | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
| 7005 | |
| 7006 | #ifndef OS_WAIT3_METHODDEF |
| 7007 | #define OS_WAIT3_METHODDEF |
| 7008 | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
| 7009 | |
| 7010 | #ifndef OS_WAIT4_METHODDEF |
| 7011 | #define OS_WAIT4_METHODDEF |
| 7012 | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
| 7013 | |
| 7014 | #ifndef OS_WAITID_METHODDEF |
| 7015 | #define OS_WAITID_METHODDEF |
| 7016 | #endif /* !defined(OS_WAITID_METHODDEF) */ |
| 7017 | |
| 7018 | #ifndef OS_WAITPID_METHODDEF |
| 7019 | #define OS_WAITPID_METHODDEF |
| 7020 | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
| 7021 | |
| 7022 | #ifndef OS_WAIT_METHODDEF |
| 7023 | #define OS_WAIT_METHODDEF |
| 7024 | #endif /* !defined(OS_WAIT_METHODDEF) */ |
| 7025 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7026 | #ifndef OS_READLINK_METHODDEF |
| 7027 | #define OS_READLINK_METHODDEF |
| 7028 | #endif /* !defined(OS_READLINK_METHODDEF) */ |
| 7029 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7030 | #ifndef OS_SYMLINK_METHODDEF |
| 7031 | #define OS_SYMLINK_METHODDEF |
| 7032 | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
| 7033 | |
| 7034 | #ifndef OS_TIMES_METHODDEF |
| 7035 | #define OS_TIMES_METHODDEF |
| 7036 | #endif /* !defined(OS_TIMES_METHODDEF) */ |
| 7037 | |
| 7038 | #ifndef OS_GETSID_METHODDEF |
| 7039 | #define OS_GETSID_METHODDEF |
| 7040 | #endif /* !defined(OS_GETSID_METHODDEF) */ |
| 7041 | |
| 7042 | #ifndef OS_SETSID_METHODDEF |
| 7043 | #define OS_SETSID_METHODDEF |
| 7044 | #endif /* !defined(OS_SETSID_METHODDEF) */ |
| 7045 | |
| 7046 | #ifndef OS_SETPGID_METHODDEF |
| 7047 | #define OS_SETPGID_METHODDEF |
| 7048 | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
| 7049 | |
| 7050 | #ifndef OS_TCGETPGRP_METHODDEF |
| 7051 | #define OS_TCGETPGRP_METHODDEF |
| 7052 | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
| 7053 | |
| 7054 | #ifndef OS_TCSETPGRP_METHODDEF |
| 7055 | #define OS_TCSETPGRP_METHODDEF |
| 7056 | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
| 7057 | |
| 7058 | #ifndef OS_LOCKF_METHODDEF |
| 7059 | #define OS_LOCKF_METHODDEF |
| 7060 | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
| 7061 | |
| 7062 | #ifndef OS_READV_METHODDEF |
| 7063 | #define OS_READV_METHODDEF |
| 7064 | #endif /* !defined(OS_READV_METHODDEF) */ |
| 7065 | |
| 7066 | #ifndef OS_PREAD_METHODDEF |
| 7067 | #define OS_PREAD_METHODDEF |
| 7068 | #endif /* !defined(OS_PREAD_METHODDEF) */ |
| 7069 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 7070 | #ifndef OS_PREADV_METHODDEF |
| 7071 | #define OS_PREADV_METHODDEF |
| 7072 | #endif /* !defined(OS_PREADV_METHODDEF) */ |
| 7073 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 7074 | #ifndef OS__FCOPYFILE_METHODDEF |
| 7075 | #define OS__FCOPYFILE_METHODDEF |
| 7076 | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
| 7077 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7078 | #ifndef OS_PIPE_METHODDEF |
| 7079 | #define OS_PIPE_METHODDEF |
| 7080 | #endif /* !defined(OS_PIPE_METHODDEF) */ |
| 7081 | |
| 7082 | #ifndef OS_PIPE2_METHODDEF |
| 7083 | #define OS_PIPE2_METHODDEF |
| 7084 | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
| 7085 | |
| 7086 | #ifndef OS_WRITEV_METHODDEF |
| 7087 | #define OS_WRITEV_METHODDEF |
| 7088 | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
| 7089 | |
| 7090 | #ifndef OS_PWRITE_METHODDEF |
| 7091 | #define OS_PWRITE_METHODDEF |
| 7092 | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
| 7093 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 7094 | #ifndef OS_PWRITEV_METHODDEF |
| 7095 | #define OS_PWRITEV_METHODDEF |
| 7096 | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
| 7097 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7098 | #ifndef OS_MKFIFO_METHODDEF |
| 7099 | #define OS_MKFIFO_METHODDEF |
| 7100 | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
| 7101 | |
| 7102 | #ifndef OS_MKNOD_METHODDEF |
| 7103 | #define OS_MKNOD_METHODDEF |
| 7104 | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
| 7105 | |
| 7106 | #ifndef OS_MAJOR_METHODDEF |
| 7107 | #define OS_MAJOR_METHODDEF |
| 7108 | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
| 7109 | |
| 7110 | #ifndef OS_MINOR_METHODDEF |
| 7111 | #define OS_MINOR_METHODDEF |
| 7112 | #endif /* !defined(OS_MINOR_METHODDEF) */ |
| 7113 | |
| 7114 | #ifndef OS_MAKEDEV_METHODDEF |
| 7115 | #define OS_MAKEDEV_METHODDEF |
| 7116 | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
| 7117 | |
| 7118 | #ifndef OS_FTRUNCATE_METHODDEF |
| 7119 | #define OS_FTRUNCATE_METHODDEF |
| 7120 | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
| 7121 | |
| 7122 | #ifndef OS_TRUNCATE_METHODDEF |
| 7123 | #define OS_TRUNCATE_METHODDEF |
| 7124 | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
| 7125 | |
| 7126 | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
| 7127 | #define OS_POSIX_FALLOCATE_METHODDEF |
| 7128 | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
| 7129 | |
| 7130 | #ifndef OS_POSIX_FADVISE_METHODDEF |
| 7131 | #define OS_POSIX_FADVISE_METHODDEF |
| 7132 | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
| 7133 | |
| 7134 | #ifndef OS_PUTENV_METHODDEF |
| 7135 | #define OS_PUTENV_METHODDEF |
| 7136 | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
| 7137 | |
| 7138 | #ifndef OS_UNSETENV_METHODDEF |
| 7139 | #define OS_UNSETENV_METHODDEF |
| 7140 | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
| 7141 | |
| 7142 | #ifndef OS_WCOREDUMP_METHODDEF |
| 7143 | #define OS_WCOREDUMP_METHODDEF |
| 7144 | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
| 7145 | |
| 7146 | #ifndef OS_WIFCONTINUED_METHODDEF |
| 7147 | #define OS_WIFCONTINUED_METHODDEF |
| 7148 | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
| 7149 | |
| 7150 | #ifndef OS_WIFSTOPPED_METHODDEF |
| 7151 | #define OS_WIFSTOPPED_METHODDEF |
| 7152 | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
| 7153 | |
| 7154 | #ifndef OS_WIFSIGNALED_METHODDEF |
| 7155 | #define OS_WIFSIGNALED_METHODDEF |
| 7156 | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
| 7157 | |
| 7158 | #ifndef OS_WIFEXITED_METHODDEF |
| 7159 | #define OS_WIFEXITED_METHODDEF |
| 7160 | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
| 7161 | |
| 7162 | #ifndef OS_WEXITSTATUS_METHODDEF |
| 7163 | #define OS_WEXITSTATUS_METHODDEF |
| 7164 | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
| 7165 | |
| 7166 | #ifndef OS_WTERMSIG_METHODDEF |
| 7167 | #define OS_WTERMSIG_METHODDEF |
| 7168 | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
| 7169 | |
| 7170 | #ifndef OS_WSTOPSIG_METHODDEF |
| 7171 | #define OS_WSTOPSIG_METHODDEF |
| 7172 | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
| 7173 | |
| 7174 | #ifndef OS_FSTATVFS_METHODDEF |
| 7175 | #define OS_FSTATVFS_METHODDEF |
| 7176 | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
| 7177 | |
| 7178 | #ifndef OS_STATVFS_METHODDEF |
| 7179 | #define OS_STATVFS_METHODDEF |
| 7180 | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
| 7181 | |
| 7182 | #ifndef OS__GETDISKUSAGE_METHODDEF |
| 7183 | #define OS__GETDISKUSAGE_METHODDEF |
| 7184 | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
| 7185 | |
| 7186 | #ifndef OS_FPATHCONF_METHODDEF |
| 7187 | #define OS_FPATHCONF_METHODDEF |
| 7188 | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
| 7189 | |
| 7190 | #ifndef OS_PATHCONF_METHODDEF |
| 7191 | #define OS_PATHCONF_METHODDEF |
| 7192 | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
| 7193 | |
| 7194 | #ifndef OS_CONFSTR_METHODDEF |
| 7195 | #define OS_CONFSTR_METHODDEF |
| 7196 | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
| 7197 | |
| 7198 | #ifndef OS_SYSCONF_METHODDEF |
| 7199 | #define OS_SYSCONF_METHODDEF |
| 7200 | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
| 7201 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 7202 | #ifndef OS_STARTFILE_METHODDEF |
| 7203 | #define OS_STARTFILE_METHODDEF |
| 7204 | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
| 7205 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7206 | #ifndef OS_GETLOADAVG_METHODDEF |
| 7207 | #define OS_GETLOADAVG_METHODDEF |
| 7208 | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
| 7209 | |
| 7210 | #ifndef OS_SETRESUID_METHODDEF |
| 7211 | #define OS_SETRESUID_METHODDEF |
| 7212 | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
| 7213 | |
| 7214 | #ifndef OS_SETRESGID_METHODDEF |
| 7215 | #define OS_SETRESGID_METHODDEF |
| 7216 | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
| 7217 | |
| 7218 | #ifndef OS_GETRESUID_METHODDEF |
| 7219 | #define OS_GETRESUID_METHODDEF |
| 7220 | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
| 7221 | |
| 7222 | #ifndef OS_GETRESGID_METHODDEF |
| 7223 | #define OS_GETRESGID_METHODDEF |
| 7224 | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
| 7225 | |
| 7226 | #ifndef OS_GETXATTR_METHODDEF |
| 7227 | #define OS_GETXATTR_METHODDEF |
| 7228 | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
| 7229 | |
| 7230 | #ifndef OS_SETXATTR_METHODDEF |
| 7231 | #define OS_SETXATTR_METHODDEF |
| 7232 | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
| 7233 | |
| 7234 | #ifndef OS_REMOVEXATTR_METHODDEF |
| 7235 | #define OS_REMOVEXATTR_METHODDEF |
| 7236 | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
| 7237 | |
| 7238 | #ifndef OS_LISTXATTR_METHODDEF |
| 7239 | #define OS_LISTXATTR_METHODDEF |
| 7240 | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
| 7241 | |
| 7242 | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 7243 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 7244 | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
| 7245 | |
| 7246 | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 7247 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 7248 | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 7249 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7250 | #ifndef OS_GET_BLOCKING_METHODDEF |
| 7251 | #define OS_GET_BLOCKING_METHODDEF |
| 7252 | #endif /* !defined(OS_GET_BLOCKING_METHODDEF) */ |
| 7253 | |
| 7254 | #ifndef OS_SET_BLOCKING_METHODDEF |
| 7255 | #define OS_SET_BLOCKING_METHODDEF |
| 7256 | #endif /* !defined(OS_SET_BLOCKING_METHODDEF) */ |
| 7257 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 7258 | #ifndef OS_GETRANDOM_METHODDEF |
| 7259 | #define OS_GETRANDOM_METHODDEF |
| 7260 | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 7261 | /*[clinic end generated code: output=febc1e16c9024e40 input=a9049054013a1b77]*/ |