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}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 41 | static _PyArg_Parser _parser = {NULL, _keywords, "stat", 0}; |
| 42 | PyObject *argsbuf[3]; |
| 43 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 44 | path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1); |
| 45 | int dir_fd = DEFAULT_DIR_FD; |
| 46 | int follow_symlinks = 1; |
| 47 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 48 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 49 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 50 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 51 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 52 | if (!path_converter(args[0], &path)) { |
| 53 | goto exit; |
| 54 | } |
| 55 | if (!noptargs) { |
| 56 | goto skip_optional_kwonly; |
| 57 | } |
| 58 | if (args[1]) { |
| 59 | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 60 | goto exit; |
| 61 | } |
| 62 | if (!--noptargs) { |
| 63 | goto skip_optional_kwonly; |
| 64 | } |
| 65 | } |
| 66 | follow_symlinks = PyObject_IsTrue(args[2]); |
| 67 | if (follow_symlinks < 0) { |
| 68 | goto exit; |
| 69 | } |
| 70 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 71 | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
| 72 | |
| 73 | exit: |
| 74 | /* Cleanup for path */ |
| 75 | path_cleanup(&path); |
| 76 | |
| 77 | return return_value; |
| 78 | } |
| 79 | |
| 80 | PyDoc_STRVAR(os_lstat__doc__, |
| 81 | "lstat($module, /, path, *, dir_fd=None)\n" |
| 82 | "--\n" |
| 83 | "\n" |
| 84 | "Perform a stat system call on the given path, without following symbolic links.\n" |
| 85 | "\n" |
| 86 | "Like stat(), but do not follow symbolic links.\n" |
| 87 | "Equivalent to stat(path, follow_symlinks=False)."); |
| 88 | |
| 89 | #define OS_LSTAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 90 | {"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] | 91 | |
| 92 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 93 | os_lstat_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 94 | |
| 95 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 96 | 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] | 97 | { |
| 98 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 99 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 100 | static _PyArg_Parser _parser = {NULL, _keywords, "lstat", 0}; |
| 101 | PyObject *argsbuf[2]; |
| 102 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 103 | path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0); |
| 104 | int dir_fd = DEFAULT_DIR_FD; |
| 105 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 106 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 107 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 108 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 109 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 110 | if (!path_converter(args[0], &path)) { |
| 111 | goto exit; |
| 112 | } |
| 113 | if (!noptargs) { |
| 114 | goto skip_optional_kwonly; |
| 115 | } |
| 116 | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 117 | goto exit; |
| 118 | } |
| 119 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 120 | return_value = os_lstat_impl(module, &path, dir_fd); |
| 121 | |
| 122 | exit: |
| 123 | /* Cleanup for path */ |
| 124 | path_cleanup(&path); |
| 125 | |
| 126 | return return_value; |
| 127 | } |
| 128 | |
| 129 | PyDoc_STRVAR(os_access__doc__, |
| 130 | "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n" |
| 131 | " follow_symlinks=True)\n" |
| 132 | "--\n" |
| 133 | "\n" |
| 134 | "Use the real uid/gid to test for access to a path.\n" |
| 135 | "\n" |
| 136 | " path\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 137 | " 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] | 138 | " mode\n" |
| 139 | " Operating-system mode bitfield. Can be F_OK to test existence,\n" |
| 140 | " or the inclusive-OR of R_OK, W_OK, and X_OK.\n" |
| 141 | " dir_fd\n" |
| 142 | " If not None, it should be a file descriptor open to a directory,\n" |
| 143 | " and path should be relative; path will then be relative to that\n" |
| 144 | " directory.\n" |
| 145 | " effective_ids\n" |
| 146 | " If True, access will use the effective uid/gid instead of\n" |
| 147 | " the real uid/gid.\n" |
| 148 | " follow_symlinks\n" |
| 149 | " If False, and the last element of the path is a symbolic link,\n" |
| 150 | " access will examine the symbolic link itself instead of the file\n" |
| 151 | " the link points to.\n" |
| 152 | "\n" |
| 153 | "dir_fd, effective_ids, and follow_symlinks may not be implemented\n" |
| 154 | " on your platform. If they are unavailable, using them will raise a\n" |
| 155 | " NotImplementedError.\n" |
| 156 | "\n" |
| 157 | "Note that most operations will use the effective uid/gid, therefore this\n" |
| 158 | " routine can be used in a suid/sgid environment to test if the invoking user\n" |
| 159 | " has the specified access to the path."); |
| 160 | |
| 161 | #define OS_ACCESS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 162 | {"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] | 163 | |
| 164 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 165 | 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] | 166 | int effective_ids, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 167 | |
| 168 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 169 | 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] | 170 | { |
| 171 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 172 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 173 | static _PyArg_Parser _parser = {NULL, _keywords, "access", 0}; |
| 174 | PyObject *argsbuf[5]; |
| 175 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Benjamin Peterson | 768f3b4 | 2016-09-05 15:29:33 -0700 | [diff] [blame] | 176 | path_t path = PATH_T_INITIALIZE("access", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 177 | int mode; |
| 178 | int dir_fd = DEFAULT_DIR_FD; |
| 179 | int effective_ids = 0; |
| 180 | int follow_symlinks = 1; |
| 181 | int _return_value; |
| 182 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 183 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 184 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 185 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 186 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 187 | if (!path_converter(args[0], &path)) { |
| 188 | goto exit; |
| 189 | } |
| 190 | if (PyFloat_Check(args[1])) { |
| 191 | PyErr_SetString(PyExc_TypeError, |
| 192 | "integer argument expected, got float" ); |
| 193 | goto exit; |
| 194 | } |
| 195 | mode = _PyLong_AsInt(args[1]); |
| 196 | if (mode == -1 && PyErr_Occurred()) { |
| 197 | goto exit; |
| 198 | } |
| 199 | if (!noptargs) { |
| 200 | goto skip_optional_kwonly; |
| 201 | } |
| 202 | if (args[2]) { |
| 203 | if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
| 204 | goto exit; |
| 205 | } |
| 206 | if (!--noptargs) { |
| 207 | goto skip_optional_kwonly; |
| 208 | } |
| 209 | } |
| 210 | if (args[3]) { |
| 211 | effective_ids = PyObject_IsTrue(args[3]); |
| 212 | if (effective_ids < 0) { |
| 213 | goto exit; |
| 214 | } |
| 215 | if (!--noptargs) { |
| 216 | goto skip_optional_kwonly; |
| 217 | } |
| 218 | } |
| 219 | follow_symlinks = PyObject_IsTrue(args[4]); |
| 220 | if (follow_symlinks < 0) { |
| 221 | goto exit; |
| 222 | } |
| 223 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 224 | _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] | 225 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 226 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 227 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 228 | return_value = PyBool_FromLong((long)_return_value); |
| 229 | |
| 230 | exit: |
| 231 | /* Cleanup for path */ |
| 232 | path_cleanup(&path); |
| 233 | |
| 234 | return return_value; |
| 235 | } |
| 236 | |
| 237 | #if defined(HAVE_TTYNAME) |
| 238 | |
| 239 | PyDoc_STRVAR(os_ttyname__doc__, |
| 240 | "ttyname($module, fd, /)\n" |
| 241 | "--\n" |
| 242 | "\n" |
| 243 | "Return the name of the terminal device connected to \'fd\'.\n" |
| 244 | "\n" |
| 245 | " fd\n" |
| 246 | " Integer file descriptor handle."); |
| 247 | |
| 248 | #define OS_TTYNAME_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 249 | {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 250 | |
Serhiy Storchaka | 4db62e1 | 2018-12-17 16:47:45 +0200 | [diff] [blame] | 251 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 252 | os_ttyname_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 253 | |
| 254 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 255 | os_ttyname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 256 | { |
| 257 | PyObject *return_value = NULL; |
| 258 | int fd; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 259 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 260 | if (PyFloat_Check(arg)) { |
| 261 | PyErr_SetString(PyExc_TypeError, |
| 262 | "integer argument expected, got float" ); |
| 263 | goto exit; |
| 264 | } |
| 265 | fd = _PyLong_AsInt(arg); |
| 266 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 267 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 268 | } |
Serhiy Storchaka | 4db62e1 | 2018-12-17 16:47:45 +0200 | [diff] [blame] | 269 | return_value = os_ttyname_impl(module, fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 270 | |
| 271 | exit: |
| 272 | return return_value; |
| 273 | } |
| 274 | |
| 275 | #endif /* defined(HAVE_TTYNAME) */ |
| 276 | |
| 277 | #if defined(HAVE_CTERMID) |
| 278 | |
| 279 | PyDoc_STRVAR(os_ctermid__doc__, |
| 280 | "ctermid($module, /)\n" |
| 281 | "--\n" |
| 282 | "\n" |
| 283 | "Return the name of the controlling terminal for this process."); |
| 284 | |
| 285 | #define OS_CTERMID_METHODDEF \ |
| 286 | {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, |
| 287 | |
| 288 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 289 | os_ctermid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 290 | |
| 291 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 292 | os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 293 | { |
| 294 | return os_ctermid_impl(module); |
| 295 | } |
| 296 | |
| 297 | #endif /* defined(HAVE_CTERMID) */ |
| 298 | |
| 299 | PyDoc_STRVAR(os_chdir__doc__, |
| 300 | "chdir($module, /, path)\n" |
| 301 | "--\n" |
| 302 | "\n" |
| 303 | "Change the current working directory to the specified path.\n" |
| 304 | "\n" |
| 305 | "path may always be specified as a string.\n" |
| 306 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 307 | " If this functionality is unavailable, using it raises an exception."); |
| 308 | |
| 309 | #define OS_CHDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 310 | {"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] | 311 | |
| 312 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 313 | os_chdir_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 314 | |
| 315 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 316 | 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] | 317 | { |
| 318 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 319 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 320 | static _PyArg_Parser _parser = {NULL, _keywords, "chdir", 0}; |
| 321 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 322 | path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR); |
| 323 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 324 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 325 | if (!args) { |
| 326 | goto exit; |
| 327 | } |
| 328 | if (!path_converter(args[0], &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 329 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 330 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 331 | return_value = os_chdir_impl(module, &path); |
| 332 | |
| 333 | exit: |
| 334 | /* Cleanup for path */ |
| 335 | path_cleanup(&path); |
| 336 | |
| 337 | return return_value; |
| 338 | } |
| 339 | |
| 340 | #if defined(HAVE_FCHDIR) |
| 341 | |
| 342 | PyDoc_STRVAR(os_fchdir__doc__, |
| 343 | "fchdir($module, /, fd)\n" |
| 344 | "--\n" |
| 345 | "\n" |
| 346 | "Change to the directory of the given file descriptor.\n" |
| 347 | "\n" |
| 348 | "fd must be opened on a directory, not a file.\n" |
| 349 | "Equivalent to os.chdir(fd)."); |
| 350 | |
| 351 | #define OS_FCHDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 352 | {"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] | 353 | |
| 354 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 355 | os_fchdir_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 356 | |
| 357 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 358 | 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] | 359 | { |
| 360 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 361 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 362 | static _PyArg_Parser _parser = {NULL, _keywords, "fchdir", 0}; |
| 363 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 364 | int fd; |
| 365 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 366 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 367 | if (!args) { |
| 368 | goto exit; |
| 369 | } |
| 370 | if (!fildes_converter(args[0], &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 371 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 372 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 373 | return_value = os_fchdir_impl(module, fd); |
| 374 | |
| 375 | exit: |
| 376 | return return_value; |
| 377 | } |
| 378 | |
| 379 | #endif /* defined(HAVE_FCHDIR) */ |
| 380 | |
| 381 | PyDoc_STRVAR(os_chmod__doc__, |
| 382 | "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n" |
| 383 | "--\n" |
| 384 | "\n" |
| 385 | "Change the access permissions of a file.\n" |
| 386 | "\n" |
| 387 | " path\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 388 | " 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] | 389 | " On some platforms, path may also be specified as an open file descriptor.\n" |
| 390 | " If this functionality is unavailable, using it raises an exception.\n" |
| 391 | " mode\n" |
| 392 | " Operating-system mode bitfield.\n" |
| 393 | " dir_fd\n" |
| 394 | " If not None, it should be a file descriptor open to a directory,\n" |
| 395 | " and path should be relative; path will then be relative to that\n" |
| 396 | " directory.\n" |
| 397 | " follow_symlinks\n" |
| 398 | " If False, and the last element of the path is a symbolic link,\n" |
| 399 | " chmod will modify the symbolic link itself instead of the file\n" |
| 400 | " the link points to.\n" |
| 401 | "\n" |
| 402 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 403 | " an open file descriptor.\n" |
| 404 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 405 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 406 | |
| 407 | #define OS_CHMOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 408 | {"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] | 409 | |
| 410 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 411 | 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] | 412 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 413 | |
| 414 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 415 | 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] | 416 | { |
| 417 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 418 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 419 | static _PyArg_Parser _parser = {NULL, _keywords, "chmod", 0}; |
| 420 | PyObject *argsbuf[4]; |
| 421 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 422 | path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD); |
| 423 | int mode; |
| 424 | int dir_fd = DEFAULT_DIR_FD; |
| 425 | int follow_symlinks = 1; |
| 426 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 427 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 428 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 429 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 430 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 431 | if (!path_converter(args[0], &path)) { |
| 432 | goto exit; |
| 433 | } |
| 434 | if (PyFloat_Check(args[1])) { |
| 435 | PyErr_SetString(PyExc_TypeError, |
| 436 | "integer argument expected, got float" ); |
| 437 | goto exit; |
| 438 | } |
| 439 | mode = _PyLong_AsInt(args[1]); |
| 440 | if (mode == -1 && PyErr_Occurred()) { |
| 441 | goto exit; |
| 442 | } |
| 443 | if (!noptargs) { |
| 444 | goto skip_optional_kwonly; |
| 445 | } |
| 446 | if (args[2]) { |
| 447 | if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
| 448 | goto exit; |
| 449 | } |
| 450 | if (!--noptargs) { |
| 451 | goto skip_optional_kwonly; |
| 452 | } |
| 453 | } |
| 454 | follow_symlinks = PyObject_IsTrue(args[3]); |
| 455 | if (follow_symlinks < 0) { |
| 456 | goto exit; |
| 457 | } |
| 458 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 459 | return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); |
| 460 | |
| 461 | exit: |
| 462 | /* Cleanup for path */ |
| 463 | path_cleanup(&path); |
| 464 | |
| 465 | return return_value; |
| 466 | } |
| 467 | |
| 468 | #if defined(HAVE_FCHMOD) |
| 469 | |
| 470 | PyDoc_STRVAR(os_fchmod__doc__, |
| 471 | "fchmod($module, /, fd, mode)\n" |
| 472 | "--\n" |
| 473 | "\n" |
| 474 | "Change the access permissions of the file given by file descriptor fd.\n" |
| 475 | "\n" |
| 476 | "Equivalent to os.chmod(fd, mode)."); |
| 477 | |
| 478 | #define OS_FCHMOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 479 | {"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] | 480 | |
| 481 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 482 | os_fchmod_impl(PyObject *module, int fd, int mode); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 483 | |
| 484 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 485 | 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] | 486 | { |
| 487 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 488 | static const char * const _keywords[] = {"fd", "mode", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 489 | static _PyArg_Parser _parser = {NULL, _keywords, "fchmod", 0}; |
| 490 | PyObject *argsbuf[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 491 | int fd; |
| 492 | int mode; |
| 493 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 494 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 495 | if (!args) { |
| 496 | goto exit; |
| 497 | } |
| 498 | if (PyFloat_Check(args[0])) { |
| 499 | PyErr_SetString(PyExc_TypeError, |
| 500 | "integer argument expected, got float" ); |
| 501 | goto exit; |
| 502 | } |
| 503 | fd = _PyLong_AsInt(args[0]); |
| 504 | if (fd == -1 && PyErr_Occurred()) { |
| 505 | goto exit; |
| 506 | } |
| 507 | if (PyFloat_Check(args[1])) { |
| 508 | PyErr_SetString(PyExc_TypeError, |
| 509 | "integer argument expected, got float" ); |
| 510 | goto exit; |
| 511 | } |
| 512 | mode = _PyLong_AsInt(args[1]); |
| 513 | if (mode == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 514 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 515 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 516 | return_value = os_fchmod_impl(module, fd, mode); |
| 517 | |
| 518 | exit: |
| 519 | return return_value; |
| 520 | } |
| 521 | |
| 522 | #endif /* defined(HAVE_FCHMOD) */ |
| 523 | |
| 524 | #if defined(HAVE_LCHMOD) |
| 525 | |
| 526 | PyDoc_STRVAR(os_lchmod__doc__, |
| 527 | "lchmod($module, /, path, mode)\n" |
| 528 | "--\n" |
| 529 | "\n" |
| 530 | "Change the access permissions of a file, without following symbolic links.\n" |
| 531 | "\n" |
| 532 | "If path is a symlink, this affects the link itself rather than the target.\n" |
| 533 | "Equivalent to chmod(path, mode, follow_symlinks=False).\""); |
| 534 | |
| 535 | #define OS_LCHMOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 536 | {"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] | 537 | |
| 538 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 539 | os_lchmod_impl(PyObject *module, path_t *path, int mode); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 540 | |
| 541 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 542 | 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] | 543 | { |
| 544 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 545 | static const char * const _keywords[] = {"path", "mode", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 546 | static _PyArg_Parser _parser = {NULL, _keywords, "lchmod", 0}; |
| 547 | PyObject *argsbuf[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 548 | path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0); |
| 549 | int mode; |
| 550 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 551 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 552 | if (!args) { |
| 553 | goto exit; |
| 554 | } |
| 555 | if (!path_converter(args[0], &path)) { |
| 556 | goto exit; |
| 557 | } |
| 558 | if (PyFloat_Check(args[1])) { |
| 559 | PyErr_SetString(PyExc_TypeError, |
| 560 | "integer argument expected, got float" ); |
| 561 | goto exit; |
| 562 | } |
| 563 | mode = _PyLong_AsInt(args[1]); |
| 564 | if (mode == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 565 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 566 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 567 | return_value = os_lchmod_impl(module, &path, mode); |
| 568 | |
| 569 | exit: |
| 570 | /* Cleanup for path */ |
| 571 | path_cleanup(&path); |
| 572 | |
| 573 | return return_value; |
| 574 | } |
| 575 | |
| 576 | #endif /* defined(HAVE_LCHMOD) */ |
| 577 | |
| 578 | #if defined(HAVE_CHFLAGS) |
| 579 | |
| 580 | PyDoc_STRVAR(os_chflags__doc__, |
| 581 | "chflags($module, /, path, flags, follow_symlinks=True)\n" |
| 582 | "--\n" |
| 583 | "\n" |
| 584 | "Set file flags.\n" |
| 585 | "\n" |
| 586 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 587 | " link, chflags will change flags on the symbolic link itself instead of the\n" |
| 588 | " file the link points to.\n" |
| 589 | "follow_symlinks may not be implemented on your platform. If it is\n" |
| 590 | "unavailable, using it will raise a NotImplementedError."); |
| 591 | |
| 592 | #define OS_CHFLAGS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 593 | {"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] | 594 | |
| 595 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 596 | os_chflags_impl(PyObject *module, path_t *path, unsigned long flags, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 597 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 598 | |
| 599 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 600 | 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] | 601 | { |
| 602 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 603 | static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 604 | static _PyArg_Parser _parser = {NULL, _keywords, "chflags", 0}; |
| 605 | PyObject *argsbuf[3]; |
| 606 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 607 | path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0); |
| 608 | unsigned long flags; |
| 609 | int follow_symlinks = 1; |
| 610 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 611 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
| 612 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 613 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 614 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 615 | if (!path_converter(args[0], &path)) { |
| 616 | goto exit; |
| 617 | } |
| 618 | if (!PyLong_Check(args[1])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 619 | _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 620 | goto exit; |
| 621 | } |
| 622 | flags = PyLong_AsUnsignedLongMask(args[1]); |
| 623 | if (!noptargs) { |
| 624 | goto skip_optional_pos; |
| 625 | } |
| 626 | follow_symlinks = PyObject_IsTrue(args[2]); |
| 627 | if (follow_symlinks < 0) { |
| 628 | goto exit; |
| 629 | } |
| 630 | skip_optional_pos: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 631 | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
| 632 | |
| 633 | exit: |
| 634 | /* Cleanup for path */ |
| 635 | path_cleanup(&path); |
| 636 | |
| 637 | return return_value; |
| 638 | } |
| 639 | |
| 640 | #endif /* defined(HAVE_CHFLAGS) */ |
| 641 | |
| 642 | #if defined(HAVE_LCHFLAGS) |
| 643 | |
| 644 | PyDoc_STRVAR(os_lchflags__doc__, |
| 645 | "lchflags($module, /, path, flags)\n" |
| 646 | "--\n" |
| 647 | "\n" |
| 648 | "Set file flags.\n" |
| 649 | "\n" |
| 650 | "This function will not follow symbolic links.\n" |
| 651 | "Equivalent to chflags(path, flags, follow_symlinks=False)."); |
| 652 | |
| 653 | #define OS_LCHFLAGS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 654 | {"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] | 655 | |
| 656 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 657 | os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 658 | |
| 659 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 660 | 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] | 661 | { |
| 662 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 663 | static const char * const _keywords[] = {"path", "flags", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 664 | static _PyArg_Parser _parser = {NULL, _keywords, "lchflags", 0}; |
| 665 | PyObject *argsbuf[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 666 | path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0); |
| 667 | unsigned long flags; |
| 668 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 669 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 670 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 671 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 672 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 673 | if (!path_converter(args[0], &path)) { |
| 674 | goto exit; |
| 675 | } |
| 676 | if (!PyLong_Check(args[1])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 677 | _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 678 | goto exit; |
| 679 | } |
| 680 | flags = PyLong_AsUnsignedLongMask(args[1]); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 681 | return_value = os_lchflags_impl(module, &path, flags); |
| 682 | |
| 683 | exit: |
| 684 | /* Cleanup for path */ |
| 685 | path_cleanup(&path); |
| 686 | |
| 687 | return return_value; |
| 688 | } |
| 689 | |
| 690 | #endif /* defined(HAVE_LCHFLAGS) */ |
| 691 | |
| 692 | #if defined(HAVE_CHROOT) |
| 693 | |
| 694 | PyDoc_STRVAR(os_chroot__doc__, |
| 695 | "chroot($module, /, path)\n" |
| 696 | "--\n" |
| 697 | "\n" |
| 698 | "Change root directory to path."); |
| 699 | |
| 700 | #define OS_CHROOT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 701 | {"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] | 702 | |
| 703 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 704 | os_chroot_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 705 | |
| 706 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 707 | 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] | 708 | { |
| 709 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 710 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 711 | static _PyArg_Parser _parser = {NULL, _keywords, "chroot", 0}; |
| 712 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 713 | path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0); |
| 714 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 715 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 716 | if (!args) { |
| 717 | goto exit; |
| 718 | } |
| 719 | if (!path_converter(args[0], &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 720 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 721 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 722 | return_value = os_chroot_impl(module, &path); |
| 723 | |
| 724 | exit: |
| 725 | /* Cleanup for path */ |
| 726 | path_cleanup(&path); |
| 727 | |
| 728 | return return_value; |
| 729 | } |
| 730 | |
| 731 | #endif /* defined(HAVE_CHROOT) */ |
| 732 | |
| 733 | #if defined(HAVE_FSYNC) |
| 734 | |
| 735 | PyDoc_STRVAR(os_fsync__doc__, |
| 736 | "fsync($module, /, fd)\n" |
| 737 | "--\n" |
| 738 | "\n" |
| 739 | "Force write of fd to disk."); |
| 740 | |
| 741 | #define OS_FSYNC_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 742 | {"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] | 743 | |
| 744 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 745 | os_fsync_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 746 | |
| 747 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 748 | 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] | 749 | { |
| 750 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 751 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 752 | static _PyArg_Parser _parser = {NULL, _keywords, "fsync", 0}; |
| 753 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 754 | int fd; |
| 755 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 756 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 757 | if (!args) { |
| 758 | goto exit; |
| 759 | } |
| 760 | if (!fildes_converter(args[0], &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 761 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 762 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 763 | return_value = os_fsync_impl(module, fd); |
| 764 | |
| 765 | exit: |
| 766 | return return_value; |
| 767 | } |
| 768 | |
| 769 | #endif /* defined(HAVE_FSYNC) */ |
| 770 | |
| 771 | #if defined(HAVE_SYNC) |
| 772 | |
| 773 | PyDoc_STRVAR(os_sync__doc__, |
| 774 | "sync($module, /)\n" |
| 775 | "--\n" |
| 776 | "\n" |
| 777 | "Force write of everything to disk."); |
| 778 | |
| 779 | #define OS_SYNC_METHODDEF \ |
| 780 | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
| 781 | |
| 782 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 783 | os_sync_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 784 | |
| 785 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 786 | os_sync(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 787 | { |
| 788 | return os_sync_impl(module); |
| 789 | } |
| 790 | |
| 791 | #endif /* defined(HAVE_SYNC) */ |
| 792 | |
| 793 | #if defined(HAVE_FDATASYNC) |
| 794 | |
| 795 | PyDoc_STRVAR(os_fdatasync__doc__, |
| 796 | "fdatasync($module, /, fd)\n" |
| 797 | "--\n" |
| 798 | "\n" |
| 799 | "Force write of fd to disk without forcing update of metadata."); |
| 800 | |
| 801 | #define OS_FDATASYNC_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 802 | {"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] | 803 | |
| 804 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 805 | os_fdatasync_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 806 | |
| 807 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 808 | 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] | 809 | { |
| 810 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 811 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 812 | static _PyArg_Parser _parser = {NULL, _keywords, "fdatasync", 0}; |
| 813 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 814 | int fd; |
| 815 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 816 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 817 | if (!args) { |
| 818 | goto exit; |
| 819 | } |
| 820 | if (!fildes_converter(args[0], &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 821 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 822 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 823 | return_value = os_fdatasync_impl(module, fd); |
| 824 | |
| 825 | exit: |
| 826 | return return_value; |
| 827 | } |
| 828 | |
| 829 | #endif /* defined(HAVE_FDATASYNC) */ |
| 830 | |
| 831 | #if defined(HAVE_CHOWN) |
| 832 | |
| 833 | PyDoc_STRVAR(os_chown__doc__, |
| 834 | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
| 835 | "--\n" |
| 836 | "\n" |
| 837 | "Change the owner and group id of path to the numeric uid and gid.\\\n" |
| 838 | "\n" |
| 839 | " path\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 840 | " 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] | 841 | " dir_fd\n" |
| 842 | " If not None, it should be a file descriptor open to a directory,\n" |
| 843 | " and path should be relative; path will then be relative to that\n" |
| 844 | " directory.\n" |
| 845 | " follow_symlinks\n" |
| 846 | " If False, and the last element of the path is a symbolic link,\n" |
| 847 | " stat will examine the symbolic link itself instead of the file\n" |
| 848 | " the link points to.\n" |
| 849 | "\n" |
| 850 | "path may always be specified as a string.\n" |
| 851 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 852 | " If this functionality is unavailable, using it raises an exception.\n" |
| 853 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 854 | " and path should be relative; path will then be relative to that directory.\n" |
| 855 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 856 | " link, chown will modify the symbolic link itself instead of the file the\n" |
| 857 | " link points to.\n" |
| 858 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 859 | " an open file descriptor.\n" |
| 860 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 861 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 862 | |
| 863 | #define OS_CHOWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 864 | {"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] | 865 | |
| 866 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 867 | 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] | 868 | int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 869 | |
| 870 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 871 | 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] | 872 | { |
| 873 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 874 | static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 875 | static _PyArg_Parser _parser = {NULL, _keywords, "chown", 0}; |
| 876 | PyObject *argsbuf[5]; |
| 877 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 878 | path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN); |
| 879 | uid_t uid; |
| 880 | gid_t gid; |
| 881 | int dir_fd = DEFAULT_DIR_FD; |
| 882 | int follow_symlinks = 1; |
| 883 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 884 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 885 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 886 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 887 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 888 | if (!path_converter(args[0], &path)) { |
| 889 | goto exit; |
| 890 | } |
| 891 | if (!_Py_Uid_Converter(args[1], &uid)) { |
| 892 | goto exit; |
| 893 | } |
| 894 | if (!_Py_Gid_Converter(args[2], &gid)) { |
| 895 | goto exit; |
| 896 | } |
| 897 | if (!noptargs) { |
| 898 | goto skip_optional_kwonly; |
| 899 | } |
| 900 | if (args[3]) { |
| 901 | if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
| 902 | goto exit; |
| 903 | } |
| 904 | if (!--noptargs) { |
| 905 | goto skip_optional_kwonly; |
| 906 | } |
| 907 | } |
| 908 | follow_symlinks = PyObject_IsTrue(args[4]); |
| 909 | if (follow_symlinks < 0) { |
| 910 | goto exit; |
| 911 | } |
| 912 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 913 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
| 914 | |
| 915 | exit: |
| 916 | /* Cleanup for path */ |
| 917 | path_cleanup(&path); |
| 918 | |
| 919 | return return_value; |
| 920 | } |
| 921 | |
| 922 | #endif /* defined(HAVE_CHOWN) */ |
| 923 | |
| 924 | #if defined(HAVE_FCHOWN) |
| 925 | |
| 926 | PyDoc_STRVAR(os_fchown__doc__, |
| 927 | "fchown($module, /, fd, uid, gid)\n" |
| 928 | "--\n" |
| 929 | "\n" |
| 930 | "Change the owner and group id of the file specified by file descriptor.\n" |
| 931 | "\n" |
| 932 | "Equivalent to os.chown(fd, uid, gid)."); |
| 933 | |
| 934 | #define OS_FCHOWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 935 | {"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] | 936 | |
| 937 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 938 | 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] | 939 | |
| 940 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 941 | 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] | 942 | { |
| 943 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 944 | static const char * const _keywords[] = {"fd", "uid", "gid", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 945 | static _PyArg_Parser _parser = {NULL, _keywords, "fchown", 0}; |
| 946 | PyObject *argsbuf[3]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 947 | int fd; |
| 948 | uid_t uid; |
| 949 | gid_t gid; |
| 950 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 951 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 952 | if (!args) { |
| 953 | goto exit; |
| 954 | } |
| 955 | if (PyFloat_Check(args[0])) { |
| 956 | PyErr_SetString(PyExc_TypeError, |
| 957 | "integer argument expected, got float" ); |
| 958 | goto exit; |
| 959 | } |
| 960 | fd = _PyLong_AsInt(args[0]); |
| 961 | if (fd == -1 && PyErr_Occurred()) { |
| 962 | goto exit; |
| 963 | } |
| 964 | if (!_Py_Uid_Converter(args[1], &uid)) { |
| 965 | goto exit; |
| 966 | } |
| 967 | if (!_Py_Gid_Converter(args[2], &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 968 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 969 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 970 | return_value = os_fchown_impl(module, fd, uid, gid); |
| 971 | |
| 972 | exit: |
| 973 | return return_value; |
| 974 | } |
| 975 | |
| 976 | #endif /* defined(HAVE_FCHOWN) */ |
| 977 | |
| 978 | #if defined(HAVE_LCHOWN) |
| 979 | |
| 980 | PyDoc_STRVAR(os_lchown__doc__, |
| 981 | "lchown($module, /, path, uid, gid)\n" |
| 982 | "--\n" |
| 983 | "\n" |
| 984 | "Change the owner and group id of path to the numeric uid and gid.\n" |
| 985 | "\n" |
| 986 | "This function will not follow symbolic links.\n" |
| 987 | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); |
| 988 | |
| 989 | #define OS_LCHOWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 990 | {"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] | 991 | |
| 992 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 993 | 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] | 994 | |
| 995 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 996 | 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] | 997 | { |
| 998 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 999 | static const char * const _keywords[] = {"path", "uid", "gid", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1000 | static _PyArg_Parser _parser = {NULL, _keywords, "lchown", 0}; |
| 1001 | PyObject *argsbuf[3]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1002 | path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0); |
| 1003 | uid_t uid; |
| 1004 | gid_t gid; |
| 1005 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1006 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 1007 | if (!args) { |
| 1008 | goto exit; |
| 1009 | } |
| 1010 | if (!path_converter(args[0], &path)) { |
| 1011 | goto exit; |
| 1012 | } |
| 1013 | if (!_Py_Uid_Converter(args[1], &uid)) { |
| 1014 | goto exit; |
| 1015 | } |
| 1016 | if (!_Py_Gid_Converter(args[2], &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1017 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1018 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1019 | return_value = os_lchown_impl(module, &path, uid, gid); |
| 1020 | |
| 1021 | exit: |
| 1022 | /* Cleanup for path */ |
| 1023 | path_cleanup(&path); |
| 1024 | |
| 1025 | return return_value; |
| 1026 | } |
| 1027 | |
| 1028 | #endif /* defined(HAVE_LCHOWN) */ |
| 1029 | |
| 1030 | PyDoc_STRVAR(os_getcwd__doc__, |
| 1031 | "getcwd($module, /)\n" |
| 1032 | "--\n" |
| 1033 | "\n" |
| 1034 | "Return a unicode string representing the current working directory."); |
| 1035 | |
| 1036 | #define OS_GETCWD_METHODDEF \ |
| 1037 | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
| 1038 | |
| 1039 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1040 | os_getcwd_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1041 | |
| 1042 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1043 | os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1044 | { |
| 1045 | return os_getcwd_impl(module); |
| 1046 | } |
| 1047 | |
| 1048 | PyDoc_STRVAR(os_getcwdb__doc__, |
| 1049 | "getcwdb($module, /)\n" |
| 1050 | "--\n" |
| 1051 | "\n" |
| 1052 | "Return a bytes string representing the current working directory."); |
| 1053 | |
| 1054 | #define OS_GETCWDB_METHODDEF \ |
| 1055 | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
| 1056 | |
| 1057 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1058 | os_getcwdb_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1059 | |
| 1060 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1061 | os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1062 | { |
| 1063 | return os_getcwdb_impl(module); |
| 1064 | } |
| 1065 | |
| 1066 | #if defined(HAVE_LINK) |
| 1067 | |
| 1068 | PyDoc_STRVAR(os_link__doc__, |
| 1069 | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
| 1070 | " follow_symlinks=True)\n" |
| 1071 | "--\n" |
| 1072 | "\n" |
| 1073 | "Create a hard link to a file.\n" |
| 1074 | "\n" |
| 1075 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1076 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1077 | " should be relative; the path will then be relative to that directory.\n" |
| 1078 | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
| 1079 | " link, link will create a link to the symbolic link itself instead of the\n" |
| 1080 | " file the link points to.\n" |
| 1081 | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" |
| 1082 | " platform. If they are unavailable, using them will raise a\n" |
| 1083 | " NotImplementedError."); |
| 1084 | |
| 1085 | #define OS_LINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1086 | {"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] | 1087 | |
| 1088 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1089 | 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] | 1090 | int dst_dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1091 | |
| 1092 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1093 | 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] | 1094 | { |
| 1095 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1096 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1097 | static _PyArg_Parser _parser = {NULL, _keywords, "link", 0}; |
| 1098 | PyObject *argsbuf[5]; |
| 1099 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1100 | path_t src = PATH_T_INITIALIZE("link", "src", 0, 0); |
| 1101 | path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0); |
| 1102 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1103 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1104 | int follow_symlinks = 1; |
| 1105 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1106 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1107 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1108 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1109 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1110 | if (!path_converter(args[0], &src)) { |
| 1111 | goto exit; |
| 1112 | } |
| 1113 | if (!path_converter(args[1], &dst)) { |
| 1114 | goto exit; |
| 1115 | } |
| 1116 | if (!noptargs) { |
| 1117 | goto skip_optional_kwonly; |
| 1118 | } |
| 1119 | if (args[2]) { |
| 1120 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
| 1121 | goto exit; |
| 1122 | } |
| 1123 | if (!--noptargs) { |
| 1124 | goto skip_optional_kwonly; |
| 1125 | } |
| 1126 | } |
| 1127 | if (args[3]) { |
| 1128 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
| 1129 | goto exit; |
| 1130 | } |
| 1131 | if (!--noptargs) { |
| 1132 | goto skip_optional_kwonly; |
| 1133 | } |
| 1134 | } |
| 1135 | follow_symlinks = PyObject_IsTrue(args[4]); |
| 1136 | if (follow_symlinks < 0) { |
| 1137 | goto exit; |
| 1138 | } |
| 1139 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1140 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
| 1141 | |
| 1142 | exit: |
| 1143 | /* Cleanup for src */ |
| 1144 | path_cleanup(&src); |
| 1145 | /* Cleanup for dst */ |
| 1146 | path_cleanup(&dst); |
| 1147 | |
| 1148 | return return_value; |
| 1149 | } |
| 1150 | |
| 1151 | #endif /* defined(HAVE_LINK) */ |
| 1152 | |
| 1153 | PyDoc_STRVAR(os_listdir__doc__, |
| 1154 | "listdir($module, /, path=None)\n" |
| 1155 | "--\n" |
| 1156 | "\n" |
| 1157 | "Return a list containing the names of the files in the directory.\n" |
| 1158 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 1159 | "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] | 1160 | " the filenames returned will also be bytes; in all other circumstances\n" |
| 1161 | " the filenames returned will be str.\n" |
| 1162 | "If path is None, uses the path=\'.\'.\n" |
| 1163 | "On some platforms, path may also be specified as an open file descriptor;\\\n" |
| 1164 | " the file descriptor must refer to a directory.\n" |
| 1165 | " If this functionality is unavailable, using it raises NotImplementedError.\n" |
| 1166 | "\n" |
| 1167 | "The list is in arbitrary order. It does not include the special\n" |
| 1168 | "entries \'.\' and \'..\' even if they are present in the directory."); |
| 1169 | |
| 1170 | #define OS_LISTDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1171 | {"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] | 1172 | |
| 1173 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1174 | os_listdir_impl(PyObject *module, path_t *path); |
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_listdir(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[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1181 | static _PyArg_Parser _parser = {NULL, _keywords, "listdir", 0}; |
| 1182 | PyObject *argsbuf[1]; |
| 1183 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1184 | path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR); |
| 1185 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1186 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 1187 | if (!args) { |
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 | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1190 | if (!noptargs) { |
| 1191 | goto skip_optional_pos; |
| 1192 | } |
| 1193 | if (!path_converter(args[0], &path)) { |
| 1194 | goto exit; |
| 1195 | } |
| 1196 | skip_optional_pos: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1197 | return_value = os_listdir_impl(module, &path); |
| 1198 | |
| 1199 | exit: |
| 1200 | /* Cleanup for path */ |
| 1201 | path_cleanup(&path); |
| 1202 | |
| 1203 | return return_value; |
| 1204 | } |
| 1205 | |
| 1206 | #if defined(MS_WINDOWS) |
| 1207 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1208 | PyDoc_STRVAR(os__getfullpathname__doc__, |
| 1209 | "_getfullpathname($module, path, /)\n" |
| 1210 | "--\n" |
| 1211 | "\n"); |
| 1212 | |
| 1213 | #define OS__GETFULLPATHNAME_METHODDEF \ |
| 1214 | {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__}, |
| 1215 | |
| 1216 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1217 | os__getfullpathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1218 | |
| 1219 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1220 | os__getfullpathname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1221 | { |
| 1222 | PyObject *return_value = NULL; |
| 1223 | path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0); |
| 1224 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1225 | if (!path_converter(arg, &path)) { |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1226 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1227 | } |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1228 | return_value = os__getfullpathname_impl(module, &path); |
| 1229 | |
| 1230 | exit: |
| 1231 | /* Cleanup for path */ |
| 1232 | path_cleanup(&path); |
| 1233 | |
| 1234 | return return_value; |
| 1235 | } |
| 1236 | |
| 1237 | #endif /* defined(MS_WINDOWS) */ |
| 1238 | |
| 1239 | #if defined(MS_WINDOWS) |
| 1240 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1241 | PyDoc_STRVAR(os__getfinalpathname__doc__, |
| 1242 | "_getfinalpathname($module, path, /)\n" |
| 1243 | "--\n" |
| 1244 | "\n" |
| 1245 | "A helper function for samepath on windows."); |
| 1246 | |
| 1247 | #define OS__GETFINALPATHNAME_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1248 | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1249 | |
| 1250 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1251 | os__getfinalpathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1252 | |
| 1253 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1254 | os__getfinalpathname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1255 | { |
| 1256 | PyObject *return_value = NULL; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1257 | path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1258 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1259 | if (!path_converter(arg, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1260 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1261 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1262 | return_value = os__getfinalpathname_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1263 | |
| 1264 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1265 | /* Cleanup for path */ |
| 1266 | path_cleanup(&path); |
| 1267 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1268 | return return_value; |
| 1269 | } |
| 1270 | |
| 1271 | #endif /* defined(MS_WINDOWS) */ |
| 1272 | |
| 1273 | #if defined(MS_WINDOWS) |
| 1274 | |
| 1275 | PyDoc_STRVAR(os__getvolumepathname__doc__, |
| 1276 | "_getvolumepathname($module, /, path)\n" |
| 1277 | "--\n" |
| 1278 | "\n" |
| 1279 | "A helper function for ismount on Win32."); |
| 1280 | |
| 1281 | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1282 | {"_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] | 1283 | |
| 1284 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1285 | os__getvolumepathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1286 | |
| 1287 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1288 | 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] | 1289 | { |
| 1290 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1291 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1292 | static _PyArg_Parser _parser = {NULL, _keywords, "_getvolumepathname", 0}; |
| 1293 | PyObject *argsbuf[1]; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1294 | path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1295 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1296 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1297 | if (!args) { |
| 1298 | goto exit; |
| 1299 | } |
| 1300 | if (!path_converter(args[0], &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1301 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1302 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1303 | return_value = os__getvolumepathname_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1304 | |
| 1305 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1306 | /* Cleanup for path */ |
| 1307 | path_cleanup(&path); |
| 1308 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1309 | return return_value; |
| 1310 | } |
| 1311 | |
| 1312 | #endif /* defined(MS_WINDOWS) */ |
| 1313 | |
| 1314 | PyDoc_STRVAR(os_mkdir__doc__, |
| 1315 | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
| 1316 | "--\n" |
| 1317 | "\n" |
| 1318 | "Create a directory.\n" |
| 1319 | "\n" |
| 1320 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1321 | " and path should be relative; path will then be relative to that directory.\n" |
| 1322 | "dir_fd may not be implemented on your platform.\n" |
| 1323 | " If it is unavailable, using it will raise a NotImplementedError.\n" |
| 1324 | "\n" |
| 1325 | "The mode argument is ignored on Windows."); |
| 1326 | |
| 1327 | #define OS_MKDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1328 | {"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] | 1329 | |
| 1330 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1331 | 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] | 1332 | |
| 1333 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1334 | 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] | 1335 | { |
| 1336 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1337 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1338 | static _PyArg_Parser _parser = {NULL, _keywords, "mkdir", 0}; |
| 1339 | PyObject *argsbuf[3]; |
| 1340 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1341 | path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0); |
| 1342 | int mode = 511; |
| 1343 | int dir_fd = DEFAULT_DIR_FD; |
| 1344 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1345 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 1346 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1347 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1348 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1349 | if (!path_converter(args[0], &path)) { |
| 1350 | goto exit; |
| 1351 | } |
| 1352 | if (!noptargs) { |
| 1353 | goto skip_optional_pos; |
| 1354 | } |
| 1355 | if (args[1]) { |
| 1356 | if (PyFloat_Check(args[1])) { |
| 1357 | PyErr_SetString(PyExc_TypeError, |
| 1358 | "integer argument expected, got float" ); |
| 1359 | goto exit; |
| 1360 | } |
| 1361 | mode = _PyLong_AsInt(args[1]); |
| 1362 | if (mode == -1 && PyErr_Occurred()) { |
| 1363 | goto exit; |
| 1364 | } |
| 1365 | if (!--noptargs) { |
| 1366 | goto skip_optional_pos; |
| 1367 | } |
| 1368 | } |
| 1369 | skip_optional_pos: |
| 1370 | if (!noptargs) { |
| 1371 | goto skip_optional_kwonly; |
| 1372 | } |
| 1373 | if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
| 1374 | goto exit; |
| 1375 | } |
| 1376 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1377 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
| 1378 | |
| 1379 | exit: |
| 1380 | /* Cleanup for path */ |
| 1381 | path_cleanup(&path); |
| 1382 | |
| 1383 | return return_value; |
| 1384 | } |
| 1385 | |
| 1386 | #if defined(HAVE_NICE) |
| 1387 | |
| 1388 | PyDoc_STRVAR(os_nice__doc__, |
| 1389 | "nice($module, increment, /)\n" |
| 1390 | "--\n" |
| 1391 | "\n" |
| 1392 | "Add increment to the priority of process and return the new priority."); |
| 1393 | |
| 1394 | #define OS_NICE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1395 | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1396 | |
| 1397 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1398 | os_nice_impl(PyObject *module, int increment); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1399 | |
| 1400 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1401 | os_nice(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1402 | { |
| 1403 | PyObject *return_value = NULL; |
| 1404 | int increment; |
| 1405 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1406 | if (PyFloat_Check(arg)) { |
| 1407 | PyErr_SetString(PyExc_TypeError, |
| 1408 | "integer argument expected, got float" ); |
| 1409 | goto exit; |
| 1410 | } |
| 1411 | increment = _PyLong_AsInt(arg); |
| 1412 | if (increment == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1413 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1414 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1415 | return_value = os_nice_impl(module, increment); |
| 1416 | |
| 1417 | exit: |
| 1418 | return return_value; |
| 1419 | } |
| 1420 | |
| 1421 | #endif /* defined(HAVE_NICE) */ |
| 1422 | |
| 1423 | #if defined(HAVE_GETPRIORITY) |
| 1424 | |
| 1425 | PyDoc_STRVAR(os_getpriority__doc__, |
| 1426 | "getpriority($module, /, which, who)\n" |
| 1427 | "--\n" |
| 1428 | "\n" |
| 1429 | "Return program scheduling priority."); |
| 1430 | |
| 1431 | #define OS_GETPRIORITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1432 | {"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] | 1433 | |
| 1434 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1435 | os_getpriority_impl(PyObject *module, int which, int who); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1436 | |
| 1437 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1438 | 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] | 1439 | { |
| 1440 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1441 | static const char * const _keywords[] = {"which", "who", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1442 | static _PyArg_Parser _parser = {NULL, _keywords, "getpriority", 0}; |
| 1443 | PyObject *argsbuf[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1444 | int which; |
| 1445 | int who; |
| 1446 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1447 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1448 | if (!args) { |
| 1449 | goto exit; |
| 1450 | } |
| 1451 | if (PyFloat_Check(args[0])) { |
| 1452 | PyErr_SetString(PyExc_TypeError, |
| 1453 | "integer argument expected, got float" ); |
| 1454 | goto exit; |
| 1455 | } |
| 1456 | which = _PyLong_AsInt(args[0]); |
| 1457 | if (which == -1 && PyErr_Occurred()) { |
| 1458 | goto exit; |
| 1459 | } |
| 1460 | if (PyFloat_Check(args[1])) { |
| 1461 | PyErr_SetString(PyExc_TypeError, |
| 1462 | "integer argument expected, got float" ); |
| 1463 | goto exit; |
| 1464 | } |
| 1465 | who = _PyLong_AsInt(args[1]); |
| 1466 | if (who == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1467 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1468 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1469 | return_value = os_getpriority_impl(module, which, who); |
| 1470 | |
| 1471 | exit: |
| 1472 | return return_value; |
| 1473 | } |
| 1474 | |
| 1475 | #endif /* defined(HAVE_GETPRIORITY) */ |
| 1476 | |
| 1477 | #if defined(HAVE_SETPRIORITY) |
| 1478 | |
| 1479 | PyDoc_STRVAR(os_setpriority__doc__, |
| 1480 | "setpriority($module, /, which, who, priority)\n" |
| 1481 | "--\n" |
| 1482 | "\n" |
| 1483 | "Set program scheduling priority."); |
| 1484 | |
| 1485 | #define OS_SETPRIORITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1486 | {"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] | 1487 | |
| 1488 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1489 | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1490 | |
| 1491 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1492 | 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] | 1493 | { |
| 1494 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1495 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1496 | static _PyArg_Parser _parser = {NULL, _keywords, "setpriority", 0}; |
| 1497 | PyObject *argsbuf[3]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1498 | int which; |
| 1499 | int who; |
| 1500 | int priority; |
| 1501 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1502 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 1503 | if (!args) { |
| 1504 | goto exit; |
| 1505 | } |
| 1506 | if (PyFloat_Check(args[0])) { |
| 1507 | PyErr_SetString(PyExc_TypeError, |
| 1508 | "integer argument expected, got float" ); |
| 1509 | goto exit; |
| 1510 | } |
| 1511 | which = _PyLong_AsInt(args[0]); |
| 1512 | if (which == -1 && PyErr_Occurred()) { |
| 1513 | goto exit; |
| 1514 | } |
| 1515 | if (PyFloat_Check(args[1])) { |
| 1516 | PyErr_SetString(PyExc_TypeError, |
| 1517 | "integer argument expected, got float" ); |
| 1518 | goto exit; |
| 1519 | } |
| 1520 | who = _PyLong_AsInt(args[1]); |
| 1521 | if (who == -1 && PyErr_Occurred()) { |
| 1522 | goto exit; |
| 1523 | } |
| 1524 | if (PyFloat_Check(args[2])) { |
| 1525 | PyErr_SetString(PyExc_TypeError, |
| 1526 | "integer argument expected, got float" ); |
| 1527 | goto exit; |
| 1528 | } |
| 1529 | priority = _PyLong_AsInt(args[2]); |
| 1530 | if (priority == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1531 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1532 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1533 | return_value = os_setpriority_impl(module, which, who, priority); |
| 1534 | |
| 1535 | exit: |
| 1536 | return return_value; |
| 1537 | } |
| 1538 | |
| 1539 | #endif /* defined(HAVE_SETPRIORITY) */ |
| 1540 | |
| 1541 | PyDoc_STRVAR(os_rename__doc__, |
| 1542 | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1543 | "--\n" |
| 1544 | "\n" |
| 1545 | "Rename a file or directory.\n" |
| 1546 | "\n" |
| 1547 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1548 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1549 | " should be relative; the path will then be relative to that directory.\n" |
| 1550 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1551 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1552 | |
| 1553 | #define OS_RENAME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1554 | {"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] | 1555 | |
| 1556 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1557 | 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] | 1558 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1559 | |
| 1560 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1561 | 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] | 1562 | { |
| 1563 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1564 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1565 | static _PyArg_Parser _parser = {NULL, _keywords, "rename", 0}; |
| 1566 | PyObject *argsbuf[4]; |
| 1567 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1568 | path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0); |
| 1569 | path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0); |
| 1570 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1571 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1572 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1573 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1574 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1575 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1576 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1577 | if (!path_converter(args[0], &src)) { |
| 1578 | goto exit; |
| 1579 | } |
| 1580 | if (!path_converter(args[1], &dst)) { |
| 1581 | goto exit; |
| 1582 | } |
| 1583 | if (!noptargs) { |
| 1584 | goto skip_optional_kwonly; |
| 1585 | } |
| 1586 | if (args[2]) { |
| 1587 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
| 1588 | goto exit; |
| 1589 | } |
| 1590 | if (!--noptargs) { |
| 1591 | goto skip_optional_kwonly; |
| 1592 | } |
| 1593 | } |
| 1594 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
| 1595 | goto exit; |
| 1596 | } |
| 1597 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1598 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1599 | |
| 1600 | exit: |
| 1601 | /* Cleanup for src */ |
| 1602 | path_cleanup(&src); |
| 1603 | /* Cleanup for dst */ |
| 1604 | path_cleanup(&dst); |
| 1605 | |
| 1606 | return return_value; |
| 1607 | } |
| 1608 | |
| 1609 | PyDoc_STRVAR(os_replace__doc__, |
| 1610 | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1611 | "--\n" |
| 1612 | "\n" |
| 1613 | "Rename a file or directory, overwriting the destination.\n" |
| 1614 | "\n" |
| 1615 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1616 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1617 | " should be relative; the path will then be relative to that directory.\n" |
| 1618 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
Anthony Sottile | 73d6002 | 2019-02-12 23:15:54 -0500 | [diff] [blame] | 1619 | " If they are unavailable, using them will raise a NotImplementedError."); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1620 | |
| 1621 | #define OS_REPLACE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1622 | {"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] | 1623 | |
| 1624 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1625 | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
| 1626 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1627 | |
| 1628 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1629 | 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] | 1630 | { |
| 1631 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1632 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1633 | static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0}; |
| 1634 | PyObject *argsbuf[4]; |
| 1635 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1636 | path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0); |
| 1637 | path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0); |
| 1638 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1639 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1640 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1641 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1642 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1643 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1644 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1645 | if (!path_converter(args[0], &src)) { |
| 1646 | goto exit; |
| 1647 | } |
| 1648 | if (!path_converter(args[1], &dst)) { |
| 1649 | goto exit; |
| 1650 | } |
| 1651 | if (!noptargs) { |
| 1652 | goto skip_optional_kwonly; |
| 1653 | } |
| 1654 | if (args[2]) { |
| 1655 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
| 1656 | goto exit; |
| 1657 | } |
| 1658 | if (!--noptargs) { |
| 1659 | goto skip_optional_kwonly; |
| 1660 | } |
| 1661 | } |
| 1662 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
| 1663 | goto exit; |
| 1664 | } |
| 1665 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1666 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1667 | |
| 1668 | exit: |
| 1669 | /* Cleanup for src */ |
| 1670 | path_cleanup(&src); |
| 1671 | /* Cleanup for dst */ |
| 1672 | path_cleanup(&dst); |
| 1673 | |
| 1674 | return return_value; |
| 1675 | } |
| 1676 | |
| 1677 | PyDoc_STRVAR(os_rmdir__doc__, |
| 1678 | "rmdir($module, /, path, *, dir_fd=None)\n" |
| 1679 | "--\n" |
| 1680 | "\n" |
| 1681 | "Remove a directory.\n" |
| 1682 | "\n" |
| 1683 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1684 | " and path should be relative; path will then be relative to that directory.\n" |
| 1685 | "dir_fd may not be implemented on your platform.\n" |
| 1686 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1687 | |
| 1688 | #define OS_RMDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1689 | {"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] | 1690 | |
| 1691 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1692 | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1693 | |
| 1694 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1695 | 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] | 1696 | { |
| 1697 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1698 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1699 | static _PyArg_Parser _parser = {NULL, _keywords, "rmdir", 0}; |
| 1700 | PyObject *argsbuf[2]; |
| 1701 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1702 | path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0); |
| 1703 | int dir_fd = DEFAULT_DIR_FD; |
| 1704 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1705 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1706 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1707 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1708 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1709 | if (!path_converter(args[0], &path)) { |
| 1710 | goto exit; |
| 1711 | } |
| 1712 | if (!noptargs) { |
| 1713 | goto skip_optional_kwonly; |
| 1714 | } |
| 1715 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 1716 | goto exit; |
| 1717 | } |
| 1718 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1719 | return_value = os_rmdir_impl(module, &path, dir_fd); |
| 1720 | |
| 1721 | exit: |
| 1722 | /* Cleanup for path */ |
| 1723 | path_cleanup(&path); |
| 1724 | |
| 1725 | return return_value; |
| 1726 | } |
| 1727 | |
| 1728 | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
| 1729 | |
| 1730 | PyDoc_STRVAR(os_system__doc__, |
| 1731 | "system($module, /, command)\n" |
| 1732 | "--\n" |
| 1733 | "\n" |
| 1734 | "Execute the command in a subshell."); |
| 1735 | |
| 1736 | #define OS_SYSTEM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1737 | {"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] | 1738 | |
| 1739 | static long |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 1740 | os_system_impl(PyObject *module, const Py_UNICODE *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1741 | |
| 1742 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1743 | 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] | 1744 | { |
| 1745 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1746 | static const char * const _keywords[] = {"command", NULL}; |
| 1747 | static _PyArg_Parser _parser = {"u:system", _keywords, 0}; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 1748 | const Py_UNICODE *command; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1749 | long _return_value; |
| 1750 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1751 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1752 | &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1753 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1754 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1755 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1756 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1757 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1758 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1759 | return_value = PyLong_FromLong(_return_value); |
| 1760 | |
| 1761 | exit: |
| 1762 | return return_value; |
| 1763 | } |
| 1764 | |
| 1765 | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
| 1766 | |
| 1767 | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
| 1768 | |
| 1769 | PyDoc_STRVAR(os_system__doc__, |
| 1770 | "system($module, /, command)\n" |
| 1771 | "--\n" |
| 1772 | "\n" |
| 1773 | "Execute the command in a subshell."); |
| 1774 | |
| 1775 | #define OS_SYSTEM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1776 | {"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] | 1777 | |
| 1778 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1779 | os_system_impl(PyObject *module, PyObject *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1780 | |
| 1781 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1782 | 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] | 1783 | { |
| 1784 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1785 | static const char * const _keywords[] = {"command", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1786 | static _PyArg_Parser _parser = {NULL, _keywords, "system", 0}; |
| 1787 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1788 | PyObject *command = NULL; |
| 1789 | long _return_value; |
| 1790 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1791 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1792 | if (!args) { |
| 1793 | goto exit; |
| 1794 | } |
| 1795 | if (!PyUnicode_FSConverter(args[0], &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1796 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1797 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1798 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1799 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1800 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1801 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1802 | return_value = PyLong_FromLong(_return_value); |
| 1803 | |
| 1804 | exit: |
| 1805 | /* Cleanup for command */ |
| 1806 | Py_XDECREF(command); |
| 1807 | |
| 1808 | return return_value; |
| 1809 | } |
| 1810 | |
| 1811 | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
| 1812 | |
| 1813 | PyDoc_STRVAR(os_umask__doc__, |
| 1814 | "umask($module, mask, /)\n" |
| 1815 | "--\n" |
| 1816 | "\n" |
| 1817 | "Set the current numeric umask and return the previous umask."); |
| 1818 | |
| 1819 | #define OS_UMASK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1820 | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1821 | |
| 1822 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1823 | os_umask_impl(PyObject *module, int mask); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1824 | |
| 1825 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1826 | os_umask(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1827 | { |
| 1828 | PyObject *return_value = NULL; |
| 1829 | int mask; |
| 1830 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1831 | if (PyFloat_Check(arg)) { |
| 1832 | PyErr_SetString(PyExc_TypeError, |
| 1833 | "integer argument expected, got float" ); |
| 1834 | goto exit; |
| 1835 | } |
| 1836 | mask = _PyLong_AsInt(arg); |
| 1837 | if (mask == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1838 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1839 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1840 | return_value = os_umask_impl(module, mask); |
| 1841 | |
| 1842 | exit: |
| 1843 | return return_value; |
| 1844 | } |
| 1845 | |
| 1846 | PyDoc_STRVAR(os_unlink__doc__, |
| 1847 | "unlink($module, /, path, *, dir_fd=None)\n" |
| 1848 | "--\n" |
| 1849 | "\n" |
| 1850 | "Remove a file (same as remove()).\n" |
| 1851 | "\n" |
| 1852 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1853 | " and path should be relative; path will then be relative to that directory.\n" |
| 1854 | "dir_fd may not be implemented on your platform.\n" |
| 1855 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1856 | |
| 1857 | #define OS_UNLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1858 | {"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] | 1859 | |
| 1860 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1861 | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1862 | |
| 1863 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1864 | 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] | 1865 | { |
| 1866 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1867 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1868 | static _PyArg_Parser _parser = {NULL, _keywords, "unlink", 0}; |
| 1869 | PyObject *argsbuf[2]; |
| 1870 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1871 | path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0); |
| 1872 | int dir_fd = DEFAULT_DIR_FD; |
| 1873 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1874 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1875 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1876 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1877 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1878 | if (!path_converter(args[0], &path)) { |
| 1879 | goto exit; |
| 1880 | } |
| 1881 | if (!noptargs) { |
| 1882 | goto skip_optional_kwonly; |
| 1883 | } |
| 1884 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 1885 | goto exit; |
| 1886 | } |
| 1887 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1888 | return_value = os_unlink_impl(module, &path, dir_fd); |
| 1889 | |
| 1890 | exit: |
| 1891 | /* Cleanup for path */ |
| 1892 | path_cleanup(&path); |
| 1893 | |
| 1894 | return return_value; |
| 1895 | } |
| 1896 | |
| 1897 | PyDoc_STRVAR(os_remove__doc__, |
| 1898 | "remove($module, /, path, *, dir_fd=None)\n" |
| 1899 | "--\n" |
| 1900 | "\n" |
| 1901 | "Remove a file (same as unlink()).\n" |
| 1902 | "\n" |
| 1903 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1904 | " and path should be relative; path will then be relative to that directory.\n" |
| 1905 | "dir_fd may not be implemented on your platform.\n" |
| 1906 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1907 | |
| 1908 | #define OS_REMOVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1909 | {"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] | 1910 | |
| 1911 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1912 | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1913 | |
| 1914 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1915 | 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] | 1916 | { |
| 1917 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1918 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1919 | static _PyArg_Parser _parser = {NULL, _keywords, "remove", 0}; |
| 1920 | PyObject *argsbuf[2]; |
| 1921 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1922 | path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0); |
| 1923 | int dir_fd = DEFAULT_DIR_FD; |
| 1924 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1925 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1926 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1927 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1928 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1929 | if (!path_converter(args[0], &path)) { |
| 1930 | goto exit; |
| 1931 | } |
| 1932 | if (!noptargs) { |
| 1933 | goto skip_optional_kwonly; |
| 1934 | } |
| 1935 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 1936 | goto exit; |
| 1937 | } |
| 1938 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1939 | return_value = os_remove_impl(module, &path, dir_fd); |
| 1940 | |
| 1941 | exit: |
| 1942 | /* Cleanup for path */ |
| 1943 | path_cleanup(&path); |
| 1944 | |
| 1945 | return return_value; |
| 1946 | } |
| 1947 | |
| 1948 | #if defined(HAVE_UNAME) |
| 1949 | |
| 1950 | PyDoc_STRVAR(os_uname__doc__, |
| 1951 | "uname($module, /)\n" |
| 1952 | "--\n" |
| 1953 | "\n" |
| 1954 | "Return an object identifying the current operating system.\n" |
| 1955 | "\n" |
| 1956 | "The object behaves like a named tuple with the following fields:\n" |
| 1957 | " (sysname, nodename, release, version, machine)"); |
| 1958 | |
| 1959 | #define OS_UNAME_METHODDEF \ |
| 1960 | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
| 1961 | |
| 1962 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1963 | os_uname_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1964 | |
| 1965 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1966 | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1967 | { |
| 1968 | return os_uname_impl(module); |
| 1969 | } |
| 1970 | |
| 1971 | #endif /* defined(HAVE_UNAME) */ |
| 1972 | |
| 1973 | PyDoc_STRVAR(os_utime__doc__, |
Serhiy Storchaka | 279f446 | 2019-09-14 12:24:05 +0300 | [diff] [blame] | 1974 | "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n" |
| 1975 | " dir_fd=None, follow_symlinks=True)\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1976 | "--\n" |
| 1977 | "\n" |
| 1978 | "Set the access and modified time of path.\n" |
| 1979 | "\n" |
| 1980 | "path may always be specified as a string.\n" |
| 1981 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 1982 | " If this functionality is unavailable, using it raises an exception.\n" |
| 1983 | "\n" |
| 1984 | "If times is not None, it must be a tuple (atime, mtime);\n" |
| 1985 | " atime and mtime should be expressed as float seconds since the epoch.\n" |
Martin Panter | 0ff8909 | 2015-09-09 01:56:53 +0000 | [diff] [blame] | 1986 | "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] | 1987 | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
| 1988 | " since the epoch.\n" |
Martin Panter | 0ff8909 | 2015-09-09 01:56:53 +0000 | [diff] [blame] | 1989 | "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] | 1990 | "Specifying tuples for both times and ns is an error.\n" |
| 1991 | "\n" |
| 1992 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1993 | " and path should be relative; path will then be relative to that directory.\n" |
| 1994 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 1995 | " link, utime will modify the symbolic link itself instead of the file the\n" |
| 1996 | " link points to.\n" |
| 1997 | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
| 1998 | " as an open file descriptor.\n" |
| 1999 | "dir_fd and follow_symlinks may not be available on your platform.\n" |
| 2000 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 2001 | |
| 2002 | #define OS_UTIME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2003 | {"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] | 2004 | |
| 2005 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2006 | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
| 2007 | int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2008 | |
| 2009 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2010 | 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] | 2011 | { |
| 2012 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2013 | static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2014 | static _PyArg_Parser _parser = {NULL, _keywords, "utime", 0}; |
| 2015 | PyObject *argsbuf[5]; |
| 2016 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2017 | path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD); |
Serhiy Storchaka | 279f446 | 2019-09-14 12:24:05 +0300 | [diff] [blame] | 2018 | PyObject *times = Py_None; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2019 | PyObject *ns = NULL; |
| 2020 | int dir_fd = DEFAULT_DIR_FD; |
| 2021 | int follow_symlinks = 1; |
| 2022 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2023 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 2024 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2025 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2026 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2027 | if (!path_converter(args[0], &path)) { |
| 2028 | goto exit; |
| 2029 | } |
| 2030 | if (!noptargs) { |
| 2031 | goto skip_optional_pos; |
| 2032 | } |
| 2033 | if (args[1]) { |
| 2034 | times = args[1]; |
| 2035 | if (!--noptargs) { |
| 2036 | goto skip_optional_pos; |
| 2037 | } |
| 2038 | } |
| 2039 | skip_optional_pos: |
| 2040 | if (!noptargs) { |
| 2041 | goto skip_optional_kwonly; |
| 2042 | } |
| 2043 | if (args[2]) { |
| 2044 | ns = args[2]; |
| 2045 | if (!--noptargs) { |
| 2046 | goto skip_optional_kwonly; |
| 2047 | } |
| 2048 | } |
| 2049 | if (args[3]) { |
| 2050 | if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
| 2051 | goto exit; |
| 2052 | } |
| 2053 | if (!--noptargs) { |
| 2054 | goto skip_optional_kwonly; |
| 2055 | } |
| 2056 | } |
| 2057 | follow_symlinks = PyObject_IsTrue(args[4]); |
| 2058 | if (follow_symlinks < 0) { |
| 2059 | goto exit; |
| 2060 | } |
| 2061 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2062 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
| 2063 | |
| 2064 | exit: |
| 2065 | /* Cleanup for path */ |
| 2066 | path_cleanup(&path); |
| 2067 | |
| 2068 | return return_value; |
| 2069 | } |
| 2070 | |
| 2071 | PyDoc_STRVAR(os__exit__doc__, |
| 2072 | "_exit($module, /, status)\n" |
| 2073 | "--\n" |
| 2074 | "\n" |
| 2075 | "Exit to the system with specified status, without normal exit processing."); |
| 2076 | |
| 2077 | #define OS__EXIT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2078 | {"_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] | 2079 | |
| 2080 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2081 | os__exit_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2082 | |
| 2083 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2084 | 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] | 2085 | { |
| 2086 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2087 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2088 | static _PyArg_Parser _parser = {NULL, _keywords, "_exit", 0}; |
| 2089 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2090 | int status; |
| 2091 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2092 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 2093 | if (!args) { |
| 2094 | goto exit; |
| 2095 | } |
| 2096 | if (PyFloat_Check(args[0])) { |
| 2097 | PyErr_SetString(PyExc_TypeError, |
| 2098 | "integer argument expected, got float" ); |
| 2099 | goto exit; |
| 2100 | } |
| 2101 | status = _PyLong_AsInt(args[0]); |
| 2102 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2103 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2104 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2105 | return_value = os__exit_impl(module, status); |
| 2106 | |
| 2107 | exit: |
| 2108 | return return_value; |
| 2109 | } |
| 2110 | |
| 2111 | #if defined(HAVE_EXECV) |
| 2112 | |
| 2113 | PyDoc_STRVAR(os_execv__doc__, |
| 2114 | "execv($module, path, argv, /)\n" |
| 2115 | "--\n" |
| 2116 | "\n" |
| 2117 | "Execute an executable path with arguments, replacing current process.\n" |
| 2118 | "\n" |
| 2119 | " path\n" |
| 2120 | " Path of executable file.\n" |
| 2121 | " argv\n" |
| 2122 | " Tuple or list of strings."); |
| 2123 | |
| 2124 | #define OS_EXECV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2125 | {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2126 | |
| 2127 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2128 | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2129 | |
| 2130 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2131 | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2132 | { |
| 2133 | PyObject *return_value = NULL; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2134 | path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2135 | PyObject *argv; |
| 2136 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2137 | if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2138 | goto exit; |
| 2139 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2140 | if (!path_converter(args[0], &path)) { |
| 2141 | goto exit; |
| 2142 | } |
| 2143 | argv = args[1]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2144 | return_value = os_execv_impl(module, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2145 | |
| 2146 | exit: |
| 2147 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2148 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2149 | |
| 2150 | return return_value; |
| 2151 | } |
| 2152 | |
| 2153 | #endif /* defined(HAVE_EXECV) */ |
| 2154 | |
| 2155 | #if defined(HAVE_EXECV) |
| 2156 | |
| 2157 | PyDoc_STRVAR(os_execve__doc__, |
| 2158 | "execve($module, /, path, argv, env)\n" |
| 2159 | "--\n" |
| 2160 | "\n" |
| 2161 | "Execute an executable path with arguments, replacing current process.\n" |
| 2162 | "\n" |
| 2163 | " path\n" |
| 2164 | " Path of executable file.\n" |
| 2165 | " argv\n" |
| 2166 | " Tuple or list of strings.\n" |
| 2167 | " env\n" |
| 2168 | " Dictionary of strings mapping to strings."); |
| 2169 | |
| 2170 | #define OS_EXECVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2171 | {"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] | 2172 | |
| 2173 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2174 | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2175 | |
| 2176 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2177 | 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] | 2178 | { |
| 2179 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2180 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2181 | static _PyArg_Parser _parser = {NULL, _keywords, "execve", 0}; |
| 2182 | PyObject *argsbuf[3]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2183 | path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE); |
| 2184 | PyObject *argv; |
| 2185 | PyObject *env; |
| 2186 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2187 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 2188 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2189 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2190 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2191 | if (!path_converter(args[0], &path)) { |
| 2192 | goto exit; |
| 2193 | } |
| 2194 | argv = args[1]; |
| 2195 | env = args[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2196 | return_value = os_execve_impl(module, &path, argv, env); |
| 2197 | |
| 2198 | exit: |
| 2199 | /* Cleanup for path */ |
| 2200 | path_cleanup(&path); |
| 2201 | |
| 2202 | return return_value; |
| 2203 | } |
| 2204 | |
| 2205 | #endif /* defined(HAVE_EXECV) */ |
| 2206 | |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2207 | #if defined(HAVE_POSIX_SPAWN) |
| 2208 | |
| 2209 | PyDoc_STRVAR(os_posix_spawn__doc__, |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 2210 | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
Serhiy Storchaka | 279f446 | 2019-09-14 12:24:05 +0300 | [diff] [blame] | 2211 | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
| 2212 | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2213 | "--\n" |
| 2214 | "\n" |
| 2215 | "Execute the program specified by path in a new process.\n" |
| 2216 | "\n" |
| 2217 | " path\n" |
| 2218 | " Path of executable file.\n" |
| 2219 | " argv\n" |
| 2220 | " Tuple or list of strings.\n" |
| 2221 | " env\n" |
| 2222 | " Dictionary of strings mapping to strings.\n" |
| 2223 | " file_actions\n" |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2224 | " A sequence of file action tuples.\n" |
| 2225 | " setpgroup\n" |
| 2226 | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
| 2227 | " resetids\n" |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2228 | " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n" |
| 2229 | " setsid\n" |
| 2230 | " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2231 | " setsigmask\n" |
| 2232 | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
| 2233 | " setsigdef\n" |
| 2234 | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
| 2235 | " scheduler\n" |
| 2236 | " A tuple with the scheduler policy (optional) and parameters."); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2237 | |
| 2238 | #define OS_POSIX_SPAWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2239 | {"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] | 2240 | |
| 2241 | static PyObject * |
| 2242 | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2243 | PyObject *env, PyObject *file_actions, |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2244 | PyObject *setpgroup, int resetids, int setsid, |
| 2245 | PyObject *setsigmask, PyObject *setsigdef, |
| 2246 | PyObject *scheduler); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2247 | |
| 2248 | static PyObject * |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2249 | 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] | 2250 | { |
| 2251 | PyObject *return_value = NULL; |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2252 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2253 | static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawn", 0}; |
| 2254 | PyObject *argsbuf[10]; |
| 2255 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2256 | path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0); |
| 2257 | PyObject *argv; |
| 2258 | PyObject *env; |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 2259 | PyObject *file_actions = NULL; |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2260 | PyObject *setpgroup = NULL; |
| 2261 | int resetids = 0; |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2262 | int setsid = 0; |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2263 | PyObject *setsigmask = NULL; |
| 2264 | PyObject *setsigdef = NULL; |
| 2265 | PyObject *scheduler = NULL; |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2266 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2267 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 2268 | if (!args) { |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2269 | goto exit; |
| 2270 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2271 | if (!path_converter(args[0], &path)) { |
| 2272 | goto exit; |
| 2273 | } |
| 2274 | argv = args[1]; |
| 2275 | env = args[2]; |
| 2276 | if (!noptargs) { |
| 2277 | goto skip_optional_kwonly; |
| 2278 | } |
| 2279 | if (args[3]) { |
| 2280 | file_actions = args[3]; |
| 2281 | if (!--noptargs) { |
| 2282 | goto skip_optional_kwonly; |
| 2283 | } |
| 2284 | } |
| 2285 | if (args[4]) { |
| 2286 | setpgroup = args[4]; |
| 2287 | if (!--noptargs) { |
| 2288 | goto skip_optional_kwonly; |
| 2289 | } |
| 2290 | } |
| 2291 | if (args[5]) { |
| 2292 | if (PyFloat_Check(args[5])) { |
| 2293 | PyErr_SetString(PyExc_TypeError, |
| 2294 | "integer argument expected, got float" ); |
| 2295 | goto exit; |
| 2296 | } |
| 2297 | resetids = _PyLong_AsInt(args[5]); |
| 2298 | if (resetids == -1 && PyErr_Occurred()) { |
| 2299 | goto exit; |
| 2300 | } |
| 2301 | if (!--noptargs) { |
| 2302 | goto skip_optional_kwonly; |
| 2303 | } |
| 2304 | } |
| 2305 | if (args[6]) { |
| 2306 | if (PyFloat_Check(args[6])) { |
| 2307 | PyErr_SetString(PyExc_TypeError, |
| 2308 | "integer argument expected, got float" ); |
| 2309 | goto exit; |
| 2310 | } |
| 2311 | setsid = _PyLong_AsInt(args[6]); |
| 2312 | if (setsid == -1 && PyErr_Occurred()) { |
| 2313 | goto exit; |
| 2314 | } |
| 2315 | if (!--noptargs) { |
| 2316 | goto skip_optional_kwonly; |
| 2317 | } |
| 2318 | } |
| 2319 | if (args[7]) { |
| 2320 | setsigmask = args[7]; |
| 2321 | if (!--noptargs) { |
| 2322 | goto skip_optional_kwonly; |
| 2323 | } |
| 2324 | } |
| 2325 | if (args[8]) { |
| 2326 | setsigdef = args[8]; |
| 2327 | if (!--noptargs) { |
| 2328 | goto skip_optional_kwonly; |
| 2329 | } |
| 2330 | } |
| 2331 | scheduler = args[9]; |
| 2332 | skip_optional_kwonly: |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2333 | return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2334 | |
| 2335 | exit: |
| 2336 | /* Cleanup for path */ |
| 2337 | path_cleanup(&path); |
| 2338 | |
| 2339 | return return_value; |
| 2340 | } |
| 2341 | |
| 2342 | #endif /* defined(HAVE_POSIX_SPAWN) */ |
| 2343 | |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2344 | #if defined(HAVE_POSIX_SPAWNP) |
| 2345 | |
| 2346 | PyDoc_STRVAR(os_posix_spawnp__doc__, |
| 2347 | "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n" |
Serhiy Storchaka | 279f446 | 2019-09-14 12:24:05 +0300 | [diff] [blame] | 2348 | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
| 2349 | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2350 | "--\n" |
| 2351 | "\n" |
| 2352 | "Execute the program specified by path in a new process.\n" |
| 2353 | "\n" |
| 2354 | " path\n" |
| 2355 | " Path of executable file.\n" |
| 2356 | " argv\n" |
| 2357 | " Tuple or list of strings.\n" |
| 2358 | " env\n" |
| 2359 | " Dictionary of strings mapping to strings.\n" |
| 2360 | " file_actions\n" |
| 2361 | " A sequence of file action tuples.\n" |
| 2362 | " setpgroup\n" |
| 2363 | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
| 2364 | " resetids\n" |
| 2365 | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2366 | " setsid\n" |
| 2367 | " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2368 | " setsigmask\n" |
| 2369 | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
| 2370 | " setsigdef\n" |
| 2371 | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
| 2372 | " scheduler\n" |
| 2373 | " A tuple with the scheduler policy (optional) and parameters."); |
| 2374 | |
| 2375 | #define OS_POSIX_SPAWNP_METHODDEF \ |
| 2376 | {"posix_spawnp", (PyCFunction)(void(*)(void))os_posix_spawnp, METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__}, |
| 2377 | |
| 2378 | static PyObject * |
| 2379 | os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv, |
| 2380 | PyObject *env, PyObject *file_actions, |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2381 | PyObject *setpgroup, int resetids, int setsid, |
| 2382 | PyObject *setsigmask, PyObject *setsigdef, |
| 2383 | PyObject *scheduler); |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2384 | |
| 2385 | static PyObject * |
| 2386 | os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 2387 | { |
| 2388 | PyObject *return_value = NULL; |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2389 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2390 | static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawnp", 0}; |
| 2391 | PyObject *argsbuf[10]; |
| 2392 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2393 | path_t path = PATH_T_INITIALIZE("posix_spawnp", "path", 0, 0); |
| 2394 | PyObject *argv; |
| 2395 | PyObject *env; |
| 2396 | PyObject *file_actions = NULL; |
| 2397 | PyObject *setpgroup = NULL; |
| 2398 | int resetids = 0; |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2399 | int setsid = 0; |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2400 | PyObject *setsigmask = NULL; |
| 2401 | PyObject *setsigdef = NULL; |
| 2402 | PyObject *scheduler = NULL; |
| 2403 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2404 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 2405 | if (!args) { |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2406 | goto exit; |
| 2407 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2408 | if (!path_converter(args[0], &path)) { |
| 2409 | goto exit; |
| 2410 | } |
| 2411 | argv = args[1]; |
| 2412 | env = args[2]; |
| 2413 | if (!noptargs) { |
| 2414 | goto skip_optional_kwonly; |
| 2415 | } |
| 2416 | if (args[3]) { |
| 2417 | file_actions = args[3]; |
| 2418 | if (!--noptargs) { |
| 2419 | goto skip_optional_kwonly; |
| 2420 | } |
| 2421 | } |
| 2422 | if (args[4]) { |
| 2423 | setpgroup = args[4]; |
| 2424 | if (!--noptargs) { |
| 2425 | goto skip_optional_kwonly; |
| 2426 | } |
| 2427 | } |
| 2428 | if (args[5]) { |
| 2429 | if (PyFloat_Check(args[5])) { |
| 2430 | PyErr_SetString(PyExc_TypeError, |
| 2431 | "integer argument expected, got float" ); |
| 2432 | goto exit; |
| 2433 | } |
| 2434 | resetids = _PyLong_AsInt(args[5]); |
| 2435 | if (resetids == -1 && PyErr_Occurred()) { |
| 2436 | goto exit; |
| 2437 | } |
| 2438 | if (!--noptargs) { |
| 2439 | goto skip_optional_kwonly; |
| 2440 | } |
| 2441 | } |
| 2442 | if (args[6]) { |
| 2443 | if (PyFloat_Check(args[6])) { |
| 2444 | PyErr_SetString(PyExc_TypeError, |
| 2445 | "integer argument expected, got float" ); |
| 2446 | goto exit; |
| 2447 | } |
| 2448 | setsid = _PyLong_AsInt(args[6]); |
| 2449 | if (setsid == -1 && PyErr_Occurred()) { |
| 2450 | goto exit; |
| 2451 | } |
| 2452 | if (!--noptargs) { |
| 2453 | goto skip_optional_kwonly; |
| 2454 | } |
| 2455 | } |
| 2456 | if (args[7]) { |
| 2457 | setsigmask = args[7]; |
| 2458 | if (!--noptargs) { |
| 2459 | goto skip_optional_kwonly; |
| 2460 | } |
| 2461 | } |
| 2462 | if (args[8]) { |
| 2463 | setsigdef = args[8]; |
| 2464 | if (!--noptargs) { |
| 2465 | goto skip_optional_kwonly; |
| 2466 | } |
| 2467 | } |
| 2468 | scheduler = args[9]; |
| 2469 | skip_optional_kwonly: |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2470 | return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2471 | |
| 2472 | exit: |
| 2473 | /* Cleanup for path */ |
| 2474 | path_cleanup(&path); |
| 2475 | |
| 2476 | return return_value; |
| 2477 | } |
| 2478 | |
| 2479 | #endif /* defined(HAVE_POSIX_SPAWNP) */ |
| 2480 | |
pxinwr | f2d7ac7 | 2019-05-21 18:46:37 +0800 | [diff] [blame] | 2481 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2482 | |
| 2483 | PyDoc_STRVAR(os_spawnv__doc__, |
| 2484 | "spawnv($module, mode, path, argv, /)\n" |
| 2485 | "--\n" |
| 2486 | "\n" |
| 2487 | "Execute the program specified by path in a new process.\n" |
| 2488 | "\n" |
| 2489 | " mode\n" |
| 2490 | " Mode of process creation.\n" |
| 2491 | " path\n" |
| 2492 | " Path of executable file.\n" |
| 2493 | " argv\n" |
| 2494 | " Tuple or list of strings."); |
| 2495 | |
| 2496 | #define OS_SPAWNV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2497 | {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2498 | |
| 2499 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2500 | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2501 | |
| 2502 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2503 | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2504 | { |
| 2505 | PyObject *return_value = NULL; |
| 2506 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2507 | path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2508 | PyObject *argv; |
| 2509 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2510 | if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2511 | goto exit; |
| 2512 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2513 | if (PyFloat_Check(args[0])) { |
| 2514 | PyErr_SetString(PyExc_TypeError, |
| 2515 | "integer argument expected, got float" ); |
| 2516 | goto exit; |
| 2517 | } |
| 2518 | mode = _PyLong_AsInt(args[0]); |
| 2519 | if (mode == -1 && PyErr_Occurred()) { |
| 2520 | goto exit; |
| 2521 | } |
| 2522 | if (!path_converter(args[1], &path)) { |
| 2523 | goto exit; |
| 2524 | } |
| 2525 | argv = args[2]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2526 | return_value = os_spawnv_impl(module, mode, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2527 | |
| 2528 | exit: |
| 2529 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2530 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2531 | |
| 2532 | return return_value; |
| 2533 | } |
| 2534 | |
pxinwr | f2d7ac7 | 2019-05-21 18:46:37 +0800 | [diff] [blame] | 2535 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2536 | |
pxinwr | f2d7ac7 | 2019-05-21 18:46:37 +0800 | [diff] [blame] | 2537 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2538 | |
| 2539 | PyDoc_STRVAR(os_spawnve__doc__, |
| 2540 | "spawnve($module, mode, path, argv, env, /)\n" |
| 2541 | "--\n" |
| 2542 | "\n" |
| 2543 | "Execute the program specified by path in a new process.\n" |
| 2544 | "\n" |
| 2545 | " mode\n" |
| 2546 | " Mode of process creation.\n" |
| 2547 | " path\n" |
| 2548 | " Path of executable file.\n" |
| 2549 | " argv\n" |
| 2550 | " Tuple or list of strings.\n" |
| 2551 | " env\n" |
| 2552 | " Dictionary of strings mapping to strings."); |
| 2553 | |
| 2554 | #define OS_SPAWNVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2555 | {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2556 | |
| 2557 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2558 | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2559 | PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2560 | |
| 2561 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2562 | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2563 | { |
| 2564 | PyObject *return_value = NULL; |
| 2565 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2566 | path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2567 | PyObject *argv; |
| 2568 | PyObject *env; |
| 2569 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2570 | if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2571 | goto exit; |
| 2572 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2573 | if (PyFloat_Check(args[0])) { |
| 2574 | PyErr_SetString(PyExc_TypeError, |
| 2575 | "integer argument expected, got float" ); |
| 2576 | goto exit; |
| 2577 | } |
| 2578 | mode = _PyLong_AsInt(args[0]); |
| 2579 | if (mode == -1 && PyErr_Occurred()) { |
| 2580 | goto exit; |
| 2581 | } |
| 2582 | if (!path_converter(args[1], &path)) { |
| 2583 | goto exit; |
| 2584 | } |
| 2585 | argv = args[2]; |
| 2586 | env = args[3]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2587 | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2588 | |
| 2589 | exit: |
| 2590 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2591 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2592 | |
| 2593 | return return_value; |
| 2594 | } |
| 2595 | |
pxinwr | f2d7ac7 | 2019-05-21 18:46:37 +0800 | [diff] [blame] | 2596 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2597 | |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2598 | #if defined(HAVE_FORK) |
| 2599 | |
| 2600 | PyDoc_STRVAR(os_register_at_fork__doc__, |
Serhiy Storchaka | 279f446 | 2019-09-14 12:24:05 +0300 | [diff] [blame] | 2601 | "register_at_fork($module, /, *, before=<unrepresentable>,\n" |
| 2602 | " after_in_child=<unrepresentable>,\n" |
| 2603 | " after_in_parent=<unrepresentable>)\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2604 | "--\n" |
| 2605 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2606 | "Register callables to be called when forking a new process.\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2607 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2608 | " before\n" |
| 2609 | " A callable to be called in the parent before the fork() syscall.\n" |
| 2610 | " after_in_child\n" |
| 2611 | " A callable to be called in the child after fork().\n" |
| 2612 | " after_in_parent\n" |
| 2613 | " A callable to be called in the parent after fork().\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2614 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2615 | "\'before\' callbacks are called in reverse order.\n" |
| 2616 | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order."); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2617 | |
| 2618 | #define OS_REGISTER_AT_FORK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2619 | {"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] | 2620 | |
| 2621 | static PyObject * |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2622 | os_register_at_fork_impl(PyObject *module, PyObject *before, |
| 2623 | PyObject *after_in_child, PyObject *after_in_parent); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2624 | |
| 2625 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2626 | 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] | 2627 | { |
| 2628 | PyObject *return_value = NULL; |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2629 | static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2630 | static _PyArg_Parser _parser = {NULL, _keywords, "register_at_fork", 0}; |
| 2631 | PyObject *argsbuf[3]; |
| 2632 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2633 | PyObject *before = NULL; |
| 2634 | PyObject *after_in_child = NULL; |
| 2635 | PyObject *after_in_parent = NULL; |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2636 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2637 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 2638 | if (!args) { |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2639 | goto exit; |
| 2640 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2641 | if (!noptargs) { |
| 2642 | goto skip_optional_kwonly; |
| 2643 | } |
| 2644 | if (args[0]) { |
| 2645 | before = args[0]; |
| 2646 | if (!--noptargs) { |
| 2647 | goto skip_optional_kwonly; |
| 2648 | } |
| 2649 | } |
| 2650 | if (args[1]) { |
| 2651 | after_in_child = args[1]; |
| 2652 | if (!--noptargs) { |
| 2653 | goto skip_optional_kwonly; |
| 2654 | } |
| 2655 | } |
| 2656 | after_in_parent = args[2]; |
| 2657 | skip_optional_kwonly: |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2658 | 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] | 2659 | |
| 2660 | exit: |
| 2661 | return return_value; |
| 2662 | } |
| 2663 | |
| 2664 | #endif /* defined(HAVE_FORK) */ |
| 2665 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2666 | #if defined(HAVE_FORK1) |
| 2667 | |
| 2668 | PyDoc_STRVAR(os_fork1__doc__, |
| 2669 | "fork1($module, /)\n" |
| 2670 | "--\n" |
| 2671 | "\n" |
| 2672 | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
| 2673 | "\n" |
| 2674 | "Return 0 to child process and PID of child to parent process."); |
| 2675 | |
| 2676 | #define OS_FORK1_METHODDEF \ |
| 2677 | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
| 2678 | |
| 2679 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2680 | os_fork1_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2681 | |
| 2682 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2683 | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2684 | { |
| 2685 | return os_fork1_impl(module); |
| 2686 | } |
| 2687 | |
| 2688 | #endif /* defined(HAVE_FORK1) */ |
| 2689 | |
| 2690 | #if defined(HAVE_FORK) |
| 2691 | |
| 2692 | PyDoc_STRVAR(os_fork__doc__, |
| 2693 | "fork($module, /)\n" |
| 2694 | "--\n" |
| 2695 | "\n" |
| 2696 | "Fork a child process.\n" |
| 2697 | "\n" |
| 2698 | "Return 0 to child process and PID of child to parent process."); |
| 2699 | |
| 2700 | #define OS_FORK_METHODDEF \ |
| 2701 | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
| 2702 | |
| 2703 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2704 | os_fork_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2705 | |
| 2706 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2707 | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2708 | { |
| 2709 | return os_fork_impl(module); |
| 2710 | } |
| 2711 | |
| 2712 | #endif /* defined(HAVE_FORK) */ |
| 2713 | |
| 2714 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 2715 | |
| 2716 | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
| 2717 | "sched_get_priority_max($module, /, policy)\n" |
| 2718 | "--\n" |
| 2719 | "\n" |
| 2720 | "Get the maximum scheduling priority for policy."); |
| 2721 | |
| 2722 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2723 | {"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] | 2724 | |
| 2725 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2726 | os_sched_get_priority_max_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2727 | |
| 2728 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2729 | 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] | 2730 | { |
| 2731 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2732 | static const char * const _keywords[] = {"policy", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2733 | static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_max", 0}; |
| 2734 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2735 | int policy; |
| 2736 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2737 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 2738 | if (!args) { |
| 2739 | goto exit; |
| 2740 | } |
| 2741 | if (PyFloat_Check(args[0])) { |
| 2742 | PyErr_SetString(PyExc_TypeError, |
| 2743 | "integer argument expected, got float" ); |
| 2744 | goto exit; |
| 2745 | } |
| 2746 | policy = _PyLong_AsInt(args[0]); |
| 2747 | if (policy == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2748 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2749 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2750 | return_value = os_sched_get_priority_max_impl(module, policy); |
| 2751 | |
| 2752 | exit: |
| 2753 | return return_value; |
| 2754 | } |
| 2755 | |
| 2756 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 2757 | |
| 2758 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 2759 | |
| 2760 | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
| 2761 | "sched_get_priority_min($module, /, policy)\n" |
| 2762 | "--\n" |
| 2763 | "\n" |
| 2764 | "Get the minimum scheduling priority for policy."); |
| 2765 | |
| 2766 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2767 | {"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] | 2768 | |
| 2769 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2770 | os_sched_get_priority_min_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2771 | |
| 2772 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2773 | 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] | 2774 | { |
| 2775 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2776 | static const char * const _keywords[] = {"policy", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2777 | static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_min", 0}; |
| 2778 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2779 | int policy; |
| 2780 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2781 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 2782 | if (!args) { |
| 2783 | goto exit; |
| 2784 | } |
| 2785 | if (PyFloat_Check(args[0])) { |
| 2786 | PyErr_SetString(PyExc_TypeError, |
| 2787 | "integer argument expected, got float" ); |
| 2788 | goto exit; |
| 2789 | } |
| 2790 | policy = _PyLong_AsInt(args[0]); |
| 2791 | if (policy == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2792 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2793 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2794 | return_value = os_sched_get_priority_min_impl(module, policy); |
| 2795 | |
| 2796 | exit: |
| 2797 | return return_value; |
| 2798 | } |
| 2799 | |
| 2800 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 2801 | |
| 2802 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 2803 | |
| 2804 | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
| 2805 | "sched_getscheduler($module, pid, /)\n" |
| 2806 | "--\n" |
| 2807 | "\n" |
Min ho Kim | c4cacc8 | 2019-07-31 08:16:13 +1000 | [diff] [blame] | 2808 | "Get the scheduling policy for the process identified by pid.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2809 | "\n" |
| 2810 | "Passing 0 for pid returns the scheduling policy for the calling process."); |
| 2811 | |
| 2812 | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2813 | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2814 | |
| 2815 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2816 | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2817 | |
| 2818 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2819 | os_sched_getscheduler(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2820 | { |
| 2821 | PyObject *return_value = NULL; |
| 2822 | pid_t pid; |
| 2823 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2824 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2825 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2826 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2827 | return_value = os_sched_getscheduler_impl(module, pid); |
| 2828 | |
| 2829 | exit: |
| 2830 | return return_value; |
| 2831 | } |
| 2832 | |
| 2833 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 2834 | |
William Orr | 81574b8 | 2018-10-01 22:19:56 -0700 | [diff] [blame] | 2835 | #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] | 2836 | |
| 2837 | PyDoc_STRVAR(os_sched_param__doc__, |
| 2838 | "sched_param(sched_priority)\n" |
| 2839 | "--\n" |
| 2840 | "\n" |
| 2841 | "Current has only one field: sched_priority\");\n" |
| 2842 | "\n" |
| 2843 | " sched_priority\n" |
| 2844 | " A scheduling parameter."); |
| 2845 | |
| 2846 | static PyObject * |
| 2847 | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
| 2848 | |
| 2849 | static PyObject * |
| 2850 | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 2851 | { |
| 2852 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2853 | static const char * const _keywords[] = {"sched_priority", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2854 | static _PyArg_Parser _parser = {NULL, _keywords, "sched_param", 0}; |
| 2855 | PyObject *argsbuf[1]; |
| 2856 | PyObject * const *fastargs; |
| 2857 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2858 | PyObject *sched_priority; |
| 2859 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2860 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf); |
| 2861 | if (!fastargs) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2862 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2863 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2864 | sched_priority = fastargs[0]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2865 | return_value = os_sched_param_impl(type, sched_priority); |
| 2866 | |
| 2867 | exit: |
| 2868 | return return_value; |
| 2869 | } |
| 2870 | |
William Orr | 81574b8 | 2018-10-01 22:19:56 -0700 | [diff] [blame] | 2871 | #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] | 2872 | |
| 2873 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 2874 | |
| 2875 | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
| 2876 | "sched_setscheduler($module, pid, policy, param, /)\n" |
| 2877 | "--\n" |
| 2878 | "\n" |
| 2879 | "Set the scheduling policy for the process identified by pid.\n" |
| 2880 | "\n" |
| 2881 | "If pid is 0, the calling process is changed.\n" |
| 2882 | "param is an instance of sched_param."); |
| 2883 | |
| 2884 | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2885 | {"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] | 2886 | |
| 2887 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2888 | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2889 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2890 | |
| 2891 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2892 | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2893 | { |
| 2894 | PyObject *return_value = NULL; |
| 2895 | pid_t pid; |
| 2896 | int policy; |
| 2897 | struct sched_param param; |
| 2898 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2899 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler", |
| 2900 | &pid, &policy, convert_sched_param, ¶m)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2901 | goto exit; |
| 2902 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2903 | return_value = os_sched_setscheduler_impl(module, pid, policy, ¶m); |
| 2904 | |
| 2905 | exit: |
| 2906 | return return_value; |
| 2907 | } |
| 2908 | |
| 2909 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 2910 | |
| 2911 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2912 | |
| 2913 | PyDoc_STRVAR(os_sched_getparam__doc__, |
| 2914 | "sched_getparam($module, pid, /)\n" |
| 2915 | "--\n" |
| 2916 | "\n" |
| 2917 | "Returns scheduling parameters for the process identified by pid.\n" |
| 2918 | "\n" |
| 2919 | "If pid is 0, returns parameters for the calling process.\n" |
| 2920 | "Return value is an instance of sched_param."); |
| 2921 | |
| 2922 | #define OS_SCHED_GETPARAM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2923 | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2924 | |
| 2925 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2926 | os_sched_getparam_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2927 | |
| 2928 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2929 | os_sched_getparam(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2930 | { |
| 2931 | PyObject *return_value = NULL; |
| 2932 | pid_t pid; |
| 2933 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2934 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2935 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2936 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2937 | return_value = os_sched_getparam_impl(module, pid); |
| 2938 | |
| 2939 | exit: |
| 2940 | return return_value; |
| 2941 | } |
| 2942 | |
| 2943 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2944 | |
| 2945 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2946 | |
| 2947 | PyDoc_STRVAR(os_sched_setparam__doc__, |
| 2948 | "sched_setparam($module, pid, param, /)\n" |
| 2949 | "--\n" |
| 2950 | "\n" |
| 2951 | "Set scheduling parameters for the process identified by pid.\n" |
| 2952 | "\n" |
| 2953 | "If pid is 0, sets parameters for the calling process.\n" |
| 2954 | "param should be an instance of sched_param."); |
| 2955 | |
| 2956 | #define OS_SCHED_SETPARAM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2957 | {"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] | 2958 | |
| 2959 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2960 | os_sched_setparam_impl(PyObject *module, pid_t pid, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2961 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2962 | |
| 2963 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2964 | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2965 | { |
| 2966 | PyObject *return_value = NULL; |
| 2967 | pid_t pid; |
| 2968 | struct sched_param param; |
| 2969 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2970 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam", |
| 2971 | &pid, convert_sched_param, ¶m)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2972 | goto exit; |
| 2973 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2974 | return_value = os_sched_setparam_impl(module, pid, ¶m); |
| 2975 | |
| 2976 | exit: |
| 2977 | return return_value; |
| 2978 | } |
| 2979 | |
| 2980 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2981 | |
| 2982 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
| 2983 | |
| 2984 | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
| 2985 | "sched_rr_get_interval($module, pid, /)\n" |
| 2986 | "--\n" |
| 2987 | "\n" |
| 2988 | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
| 2989 | "\n" |
| 2990 | "Value returned is a float."); |
| 2991 | |
| 2992 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2993 | {"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] | 2994 | |
| 2995 | static double |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2996 | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2997 | |
| 2998 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2999 | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3000 | { |
| 3001 | PyObject *return_value = NULL; |
| 3002 | pid_t pid; |
| 3003 | double _return_value; |
| 3004 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3005 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3006 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3007 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3008 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3009 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3010 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3011 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3012 | return_value = PyFloat_FromDouble(_return_value); |
| 3013 | |
| 3014 | exit: |
| 3015 | return return_value; |
| 3016 | } |
| 3017 | |
| 3018 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
| 3019 | |
| 3020 | #if defined(HAVE_SCHED_H) |
| 3021 | |
| 3022 | PyDoc_STRVAR(os_sched_yield__doc__, |
| 3023 | "sched_yield($module, /)\n" |
| 3024 | "--\n" |
| 3025 | "\n" |
| 3026 | "Voluntarily relinquish the CPU."); |
| 3027 | |
| 3028 | #define OS_SCHED_YIELD_METHODDEF \ |
| 3029 | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
| 3030 | |
| 3031 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3032 | os_sched_yield_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3033 | |
| 3034 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3035 | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3036 | { |
| 3037 | return os_sched_yield_impl(module); |
| 3038 | } |
| 3039 | |
| 3040 | #endif /* defined(HAVE_SCHED_H) */ |
| 3041 | |
| 3042 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 3043 | |
| 3044 | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
| 3045 | "sched_setaffinity($module, pid, mask, /)\n" |
| 3046 | "--\n" |
| 3047 | "\n" |
| 3048 | "Set the CPU affinity of the process identified by pid to mask.\n" |
| 3049 | "\n" |
| 3050 | "mask should be an iterable of integers identifying CPUs."); |
| 3051 | |
| 3052 | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3053 | {"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] | 3054 | |
| 3055 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3056 | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
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_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3060 | { |
| 3061 | PyObject *return_value = NULL; |
| 3062 | pid_t pid; |
| 3063 | PyObject *mask; |
| 3064 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3065 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity", |
| 3066 | &pid, &mask)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3067 | goto exit; |
| 3068 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3069 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
| 3070 | |
| 3071 | exit: |
| 3072 | return return_value; |
| 3073 | } |
| 3074 | |
| 3075 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 3076 | |
| 3077 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 3078 | |
| 3079 | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
| 3080 | "sched_getaffinity($module, pid, /)\n" |
| 3081 | "--\n" |
| 3082 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 3083 | "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] | 3084 | "\n" |
| 3085 | "The affinity is returned as a set of CPU identifiers."); |
| 3086 | |
| 3087 | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3088 | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3089 | |
| 3090 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3091 | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3092 | |
| 3093 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3094 | os_sched_getaffinity(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3095 | { |
| 3096 | PyObject *return_value = NULL; |
| 3097 | pid_t pid; |
| 3098 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3099 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3100 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3101 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3102 | return_value = os_sched_getaffinity_impl(module, pid); |
| 3103 | |
| 3104 | exit: |
| 3105 | return return_value; |
| 3106 | } |
| 3107 | |
| 3108 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 3109 | |
| 3110 | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
| 3111 | |
| 3112 | PyDoc_STRVAR(os_openpty__doc__, |
| 3113 | "openpty($module, /)\n" |
| 3114 | "--\n" |
| 3115 | "\n" |
| 3116 | "Open a pseudo-terminal.\n" |
| 3117 | "\n" |
| 3118 | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
| 3119 | "for both the master and slave ends."); |
| 3120 | |
| 3121 | #define OS_OPENPTY_METHODDEF \ |
| 3122 | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
| 3123 | |
| 3124 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3125 | os_openpty_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3126 | |
| 3127 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3128 | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3129 | { |
| 3130 | return os_openpty_impl(module); |
| 3131 | } |
| 3132 | |
| 3133 | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
| 3134 | |
| 3135 | #if defined(HAVE_FORKPTY) |
| 3136 | |
| 3137 | PyDoc_STRVAR(os_forkpty__doc__, |
| 3138 | "forkpty($module, /)\n" |
| 3139 | "--\n" |
| 3140 | "\n" |
| 3141 | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
| 3142 | "\n" |
| 3143 | "Returns a tuple of (pid, master_fd).\n" |
| 3144 | "Like fork(), return pid of 0 to the child process,\n" |
| 3145 | "and pid of child to the parent process.\n" |
| 3146 | "To both, return fd of newly opened pseudo-terminal."); |
| 3147 | |
| 3148 | #define OS_FORKPTY_METHODDEF \ |
| 3149 | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
| 3150 | |
| 3151 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3152 | os_forkpty_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3153 | |
| 3154 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3155 | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3156 | { |
| 3157 | return os_forkpty_impl(module); |
| 3158 | } |
| 3159 | |
| 3160 | #endif /* defined(HAVE_FORKPTY) */ |
| 3161 | |
| 3162 | #if defined(HAVE_GETEGID) |
| 3163 | |
| 3164 | PyDoc_STRVAR(os_getegid__doc__, |
| 3165 | "getegid($module, /)\n" |
| 3166 | "--\n" |
| 3167 | "\n" |
| 3168 | "Return the current process\'s effective group id."); |
| 3169 | |
| 3170 | #define OS_GETEGID_METHODDEF \ |
| 3171 | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
| 3172 | |
| 3173 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3174 | os_getegid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3175 | |
| 3176 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3177 | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3178 | { |
| 3179 | return os_getegid_impl(module); |
| 3180 | } |
| 3181 | |
| 3182 | #endif /* defined(HAVE_GETEGID) */ |
| 3183 | |
| 3184 | #if defined(HAVE_GETEUID) |
| 3185 | |
| 3186 | PyDoc_STRVAR(os_geteuid__doc__, |
| 3187 | "geteuid($module, /)\n" |
| 3188 | "--\n" |
| 3189 | "\n" |
| 3190 | "Return the current process\'s effective user id."); |
| 3191 | |
| 3192 | #define OS_GETEUID_METHODDEF \ |
| 3193 | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
| 3194 | |
| 3195 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3196 | os_geteuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3197 | |
| 3198 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3199 | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3200 | { |
| 3201 | return os_geteuid_impl(module); |
| 3202 | } |
| 3203 | |
| 3204 | #endif /* defined(HAVE_GETEUID) */ |
| 3205 | |
| 3206 | #if defined(HAVE_GETGID) |
| 3207 | |
| 3208 | PyDoc_STRVAR(os_getgid__doc__, |
| 3209 | "getgid($module, /)\n" |
| 3210 | "--\n" |
| 3211 | "\n" |
| 3212 | "Return the current process\'s group id."); |
| 3213 | |
| 3214 | #define OS_GETGID_METHODDEF \ |
| 3215 | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
| 3216 | |
| 3217 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3218 | os_getgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3219 | |
| 3220 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3221 | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3222 | { |
| 3223 | return os_getgid_impl(module); |
| 3224 | } |
| 3225 | |
| 3226 | #endif /* defined(HAVE_GETGID) */ |
| 3227 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 3228 | #if defined(HAVE_GETPID) |
| 3229 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3230 | PyDoc_STRVAR(os_getpid__doc__, |
| 3231 | "getpid($module, /)\n" |
| 3232 | "--\n" |
| 3233 | "\n" |
| 3234 | "Return the current process id."); |
| 3235 | |
| 3236 | #define OS_GETPID_METHODDEF \ |
| 3237 | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
| 3238 | |
| 3239 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3240 | os_getpid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3241 | |
| 3242 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3243 | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3244 | { |
| 3245 | return os_getpid_impl(module); |
| 3246 | } |
| 3247 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 3248 | #endif /* defined(HAVE_GETPID) */ |
| 3249 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3250 | #if defined(HAVE_GETGROUPS) |
| 3251 | |
| 3252 | PyDoc_STRVAR(os_getgroups__doc__, |
| 3253 | "getgroups($module, /)\n" |
| 3254 | "--\n" |
| 3255 | "\n" |
| 3256 | "Return list of supplemental group IDs for the process."); |
| 3257 | |
| 3258 | #define OS_GETGROUPS_METHODDEF \ |
| 3259 | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
| 3260 | |
| 3261 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3262 | os_getgroups_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3263 | |
| 3264 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3265 | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3266 | { |
| 3267 | return os_getgroups_impl(module); |
| 3268 | } |
| 3269 | |
| 3270 | #endif /* defined(HAVE_GETGROUPS) */ |
| 3271 | |
| 3272 | #if defined(HAVE_GETPGID) |
| 3273 | |
| 3274 | PyDoc_STRVAR(os_getpgid__doc__, |
| 3275 | "getpgid($module, /, pid)\n" |
| 3276 | "--\n" |
| 3277 | "\n" |
| 3278 | "Call the system call getpgid(), and return the result."); |
| 3279 | |
| 3280 | #define OS_GETPGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3281 | {"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] | 3282 | |
| 3283 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3284 | os_getpgid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3285 | |
| 3286 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3287 | 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] | 3288 | { |
| 3289 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3290 | static const char * const _keywords[] = {"pid", NULL}; |
| 3291 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3292 | pid_t pid; |
| 3293 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3294 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3295 | &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3296 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3297 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3298 | return_value = os_getpgid_impl(module, pid); |
| 3299 | |
| 3300 | exit: |
| 3301 | return return_value; |
| 3302 | } |
| 3303 | |
| 3304 | #endif /* defined(HAVE_GETPGID) */ |
| 3305 | |
| 3306 | #if defined(HAVE_GETPGRP) |
| 3307 | |
| 3308 | PyDoc_STRVAR(os_getpgrp__doc__, |
| 3309 | "getpgrp($module, /)\n" |
| 3310 | "--\n" |
| 3311 | "\n" |
| 3312 | "Return the current process group id."); |
| 3313 | |
| 3314 | #define OS_GETPGRP_METHODDEF \ |
| 3315 | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
| 3316 | |
| 3317 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3318 | os_getpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3319 | |
| 3320 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3321 | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3322 | { |
| 3323 | return os_getpgrp_impl(module); |
| 3324 | } |
| 3325 | |
| 3326 | #endif /* defined(HAVE_GETPGRP) */ |
| 3327 | |
| 3328 | #if defined(HAVE_SETPGRP) |
| 3329 | |
| 3330 | PyDoc_STRVAR(os_setpgrp__doc__, |
| 3331 | "setpgrp($module, /)\n" |
| 3332 | "--\n" |
| 3333 | "\n" |
| 3334 | "Make the current process the leader of its process group."); |
| 3335 | |
| 3336 | #define OS_SETPGRP_METHODDEF \ |
| 3337 | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
| 3338 | |
| 3339 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3340 | os_setpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3341 | |
| 3342 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3343 | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3344 | { |
| 3345 | return os_setpgrp_impl(module); |
| 3346 | } |
| 3347 | |
| 3348 | #endif /* defined(HAVE_SETPGRP) */ |
| 3349 | |
| 3350 | #if defined(HAVE_GETPPID) |
| 3351 | |
| 3352 | PyDoc_STRVAR(os_getppid__doc__, |
| 3353 | "getppid($module, /)\n" |
| 3354 | "--\n" |
| 3355 | "\n" |
| 3356 | "Return the parent\'s process id.\n" |
| 3357 | "\n" |
| 3358 | "If the parent process has already exited, Windows machines will still\n" |
| 3359 | "return its id; others systems will return the id of the \'init\' process (1)."); |
| 3360 | |
| 3361 | #define OS_GETPPID_METHODDEF \ |
| 3362 | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
| 3363 | |
| 3364 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3365 | os_getppid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3366 | |
| 3367 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3368 | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3369 | { |
| 3370 | return os_getppid_impl(module); |
| 3371 | } |
| 3372 | |
| 3373 | #endif /* defined(HAVE_GETPPID) */ |
| 3374 | |
| 3375 | #if defined(HAVE_GETLOGIN) |
| 3376 | |
| 3377 | PyDoc_STRVAR(os_getlogin__doc__, |
| 3378 | "getlogin($module, /)\n" |
| 3379 | "--\n" |
| 3380 | "\n" |
| 3381 | "Return the actual login name."); |
| 3382 | |
| 3383 | #define OS_GETLOGIN_METHODDEF \ |
| 3384 | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
| 3385 | |
| 3386 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3387 | os_getlogin_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3388 | |
| 3389 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3390 | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3391 | { |
| 3392 | return os_getlogin_impl(module); |
| 3393 | } |
| 3394 | |
| 3395 | #endif /* defined(HAVE_GETLOGIN) */ |
| 3396 | |
| 3397 | #if defined(HAVE_GETUID) |
| 3398 | |
| 3399 | PyDoc_STRVAR(os_getuid__doc__, |
| 3400 | "getuid($module, /)\n" |
| 3401 | "--\n" |
| 3402 | "\n" |
| 3403 | "Return the current process\'s user id."); |
| 3404 | |
| 3405 | #define OS_GETUID_METHODDEF \ |
| 3406 | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
| 3407 | |
| 3408 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3409 | os_getuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3410 | |
| 3411 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3412 | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3413 | { |
| 3414 | return os_getuid_impl(module); |
| 3415 | } |
| 3416 | |
| 3417 | #endif /* defined(HAVE_GETUID) */ |
| 3418 | |
| 3419 | #if defined(HAVE_KILL) |
| 3420 | |
| 3421 | PyDoc_STRVAR(os_kill__doc__, |
| 3422 | "kill($module, pid, signal, /)\n" |
| 3423 | "--\n" |
| 3424 | "\n" |
| 3425 | "Kill a process with a signal."); |
| 3426 | |
| 3427 | #define OS_KILL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3428 | {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3429 | |
| 3430 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3431 | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3432 | |
| 3433 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3434 | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3435 | { |
| 3436 | PyObject *return_value = NULL; |
| 3437 | pid_t pid; |
| 3438 | Py_ssize_t signal; |
| 3439 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3440 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill", |
| 3441 | &pid, &signal)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3442 | goto exit; |
| 3443 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3444 | return_value = os_kill_impl(module, pid, signal); |
| 3445 | |
| 3446 | exit: |
| 3447 | return return_value; |
| 3448 | } |
| 3449 | |
| 3450 | #endif /* defined(HAVE_KILL) */ |
| 3451 | |
| 3452 | #if defined(HAVE_KILLPG) |
| 3453 | |
| 3454 | PyDoc_STRVAR(os_killpg__doc__, |
| 3455 | "killpg($module, pgid, signal, /)\n" |
| 3456 | "--\n" |
| 3457 | "\n" |
| 3458 | "Kill a process group with a signal."); |
| 3459 | |
| 3460 | #define OS_KILLPG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3461 | {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3462 | |
| 3463 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3464 | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3465 | |
| 3466 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3467 | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3468 | { |
| 3469 | PyObject *return_value = NULL; |
| 3470 | pid_t pgid; |
| 3471 | int signal; |
| 3472 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3473 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg", |
| 3474 | &pgid, &signal)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3475 | goto exit; |
| 3476 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3477 | return_value = os_killpg_impl(module, pgid, signal); |
| 3478 | |
| 3479 | exit: |
| 3480 | return return_value; |
| 3481 | } |
| 3482 | |
| 3483 | #endif /* defined(HAVE_KILLPG) */ |
| 3484 | |
| 3485 | #if defined(HAVE_PLOCK) |
| 3486 | |
| 3487 | PyDoc_STRVAR(os_plock__doc__, |
| 3488 | "plock($module, op, /)\n" |
| 3489 | "--\n" |
| 3490 | "\n" |
| 3491 | "Lock program segments into memory.\");"); |
| 3492 | |
| 3493 | #define OS_PLOCK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3494 | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3495 | |
| 3496 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3497 | os_plock_impl(PyObject *module, int op); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3498 | |
| 3499 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3500 | os_plock(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3501 | { |
| 3502 | PyObject *return_value = NULL; |
| 3503 | int op; |
| 3504 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3505 | if (PyFloat_Check(arg)) { |
| 3506 | PyErr_SetString(PyExc_TypeError, |
| 3507 | "integer argument expected, got float" ); |
| 3508 | goto exit; |
| 3509 | } |
| 3510 | op = _PyLong_AsInt(arg); |
| 3511 | if (op == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3512 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3513 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3514 | return_value = os_plock_impl(module, op); |
| 3515 | |
| 3516 | exit: |
| 3517 | return return_value; |
| 3518 | } |
| 3519 | |
| 3520 | #endif /* defined(HAVE_PLOCK) */ |
| 3521 | |
| 3522 | #if defined(HAVE_SETUID) |
| 3523 | |
| 3524 | PyDoc_STRVAR(os_setuid__doc__, |
| 3525 | "setuid($module, uid, /)\n" |
| 3526 | "--\n" |
| 3527 | "\n" |
| 3528 | "Set the current process\'s user id."); |
| 3529 | |
| 3530 | #define OS_SETUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3531 | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3532 | |
| 3533 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3534 | os_setuid_impl(PyObject *module, uid_t uid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3535 | |
| 3536 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3537 | os_setuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3538 | { |
| 3539 | PyObject *return_value = NULL; |
| 3540 | uid_t uid; |
| 3541 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3542 | if (!_Py_Uid_Converter(arg, &uid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3543 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3544 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3545 | return_value = os_setuid_impl(module, uid); |
| 3546 | |
| 3547 | exit: |
| 3548 | return return_value; |
| 3549 | } |
| 3550 | |
| 3551 | #endif /* defined(HAVE_SETUID) */ |
| 3552 | |
| 3553 | #if defined(HAVE_SETEUID) |
| 3554 | |
| 3555 | PyDoc_STRVAR(os_seteuid__doc__, |
| 3556 | "seteuid($module, euid, /)\n" |
| 3557 | "--\n" |
| 3558 | "\n" |
| 3559 | "Set the current process\'s effective user id."); |
| 3560 | |
| 3561 | #define OS_SETEUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3562 | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3563 | |
| 3564 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3565 | os_seteuid_impl(PyObject *module, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3566 | |
| 3567 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3568 | os_seteuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3569 | { |
| 3570 | PyObject *return_value = NULL; |
| 3571 | uid_t euid; |
| 3572 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3573 | if (!_Py_Uid_Converter(arg, &euid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3574 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3575 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3576 | return_value = os_seteuid_impl(module, euid); |
| 3577 | |
| 3578 | exit: |
| 3579 | return return_value; |
| 3580 | } |
| 3581 | |
| 3582 | #endif /* defined(HAVE_SETEUID) */ |
| 3583 | |
| 3584 | #if defined(HAVE_SETEGID) |
| 3585 | |
| 3586 | PyDoc_STRVAR(os_setegid__doc__, |
| 3587 | "setegid($module, egid, /)\n" |
| 3588 | "--\n" |
| 3589 | "\n" |
| 3590 | "Set the current process\'s effective group id."); |
| 3591 | |
| 3592 | #define OS_SETEGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3593 | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3594 | |
| 3595 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3596 | os_setegid_impl(PyObject *module, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3597 | |
| 3598 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3599 | os_setegid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3600 | { |
| 3601 | PyObject *return_value = NULL; |
| 3602 | gid_t egid; |
| 3603 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3604 | if (!_Py_Gid_Converter(arg, &egid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3605 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3606 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3607 | return_value = os_setegid_impl(module, egid); |
| 3608 | |
| 3609 | exit: |
| 3610 | return return_value; |
| 3611 | } |
| 3612 | |
| 3613 | #endif /* defined(HAVE_SETEGID) */ |
| 3614 | |
| 3615 | #if defined(HAVE_SETREUID) |
| 3616 | |
| 3617 | PyDoc_STRVAR(os_setreuid__doc__, |
| 3618 | "setreuid($module, ruid, euid, /)\n" |
| 3619 | "--\n" |
| 3620 | "\n" |
| 3621 | "Set the current process\'s real and effective user ids."); |
| 3622 | |
| 3623 | #define OS_SETREUID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3624 | {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3625 | |
| 3626 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3627 | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3628 | |
| 3629 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3630 | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3631 | { |
| 3632 | PyObject *return_value = NULL; |
| 3633 | uid_t ruid; |
| 3634 | uid_t euid; |
| 3635 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3636 | if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { |
| 3637 | goto exit; |
| 3638 | } |
| 3639 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
| 3640 | goto exit; |
| 3641 | } |
| 3642 | if (!_Py_Uid_Converter(args[1], &euid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3643 | goto exit; |
| 3644 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3645 | return_value = os_setreuid_impl(module, ruid, euid); |
| 3646 | |
| 3647 | exit: |
| 3648 | return return_value; |
| 3649 | } |
| 3650 | |
| 3651 | #endif /* defined(HAVE_SETREUID) */ |
| 3652 | |
| 3653 | #if defined(HAVE_SETREGID) |
| 3654 | |
| 3655 | PyDoc_STRVAR(os_setregid__doc__, |
| 3656 | "setregid($module, rgid, egid, /)\n" |
| 3657 | "--\n" |
| 3658 | "\n" |
| 3659 | "Set the current process\'s real and effective group ids."); |
| 3660 | |
| 3661 | #define OS_SETREGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3662 | {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3663 | |
| 3664 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3665 | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3666 | |
| 3667 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3668 | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3669 | { |
| 3670 | PyObject *return_value = NULL; |
| 3671 | gid_t rgid; |
| 3672 | gid_t egid; |
| 3673 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3674 | if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { |
| 3675 | goto exit; |
| 3676 | } |
| 3677 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
| 3678 | goto exit; |
| 3679 | } |
| 3680 | if (!_Py_Gid_Converter(args[1], &egid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3681 | goto exit; |
| 3682 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3683 | return_value = os_setregid_impl(module, rgid, egid); |
| 3684 | |
| 3685 | exit: |
| 3686 | return return_value; |
| 3687 | } |
| 3688 | |
| 3689 | #endif /* defined(HAVE_SETREGID) */ |
| 3690 | |
| 3691 | #if defined(HAVE_SETGID) |
| 3692 | |
| 3693 | PyDoc_STRVAR(os_setgid__doc__, |
| 3694 | "setgid($module, gid, /)\n" |
| 3695 | "--\n" |
| 3696 | "\n" |
| 3697 | "Set the current process\'s group id."); |
| 3698 | |
| 3699 | #define OS_SETGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3700 | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3701 | |
| 3702 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3703 | os_setgid_impl(PyObject *module, gid_t gid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3704 | |
| 3705 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3706 | os_setgid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3707 | { |
| 3708 | PyObject *return_value = NULL; |
| 3709 | gid_t gid; |
| 3710 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3711 | if (!_Py_Gid_Converter(arg, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3712 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3713 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3714 | return_value = os_setgid_impl(module, gid); |
| 3715 | |
| 3716 | exit: |
| 3717 | return return_value; |
| 3718 | } |
| 3719 | |
| 3720 | #endif /* defined(HAVE_SETGID) */ |
| 3721 | |
| 3722 | #if defined(HAVE_SETGROUPS) |
| 3723 | |
| 3724 | PyDoc_STRVAR(os_setgroups__doc__, |
| 3725 | "setgroups($module, groups, /)\n" |
| 3726 | "--\n" |
| 3727 | "\n" |
| 3728 | "Set the groups of the current process to list."); |
| 3729 | |
| 3730 | #define OS_SETGROUPS_METHODDEF \ |
| 3731 | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
| 3732 | |
| 3733 | #endif /* defined(HAVE_SETGROUPS) */ |
| 3734 | |
| 3735 | #if defined(HAVE_WAIT3) |
| 3736 | |
| 3737 | PyDoc_STRVAR(os_wait3__doc__, |
| 3738 | "wait3($module, /, options)\n" |
| 3739 | "--\n" |
| 3740 | "\n" |
| 3741 | "Wait for completion of a child process.\n" |
| 3742 | "\n" |
| 3743 | "Returns a tuple of information about the child process:\n" |
| 3744 | " (pid, status, rusage)"); |
| 3745 | |
| 3746 | #define OS_WAIT3_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3747 | {"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] | 3748 | |
| 3749 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3750 | os_wait3_impl(PyObject *module, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3751 | |
| 3752 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3753 | 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] | 3754 | { |
| 3755 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3756 | static const char * const _keywords[] = {"options", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 3757 | static _PyArg_Parser _parser = {NULL, _keywords, "wait3", 0}; |
| 3758 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3759 | int options; |
| 3760 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 3761 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 3762 | if (!args) { |
| 3763 | goto exit; |
| 3764 | } |
| 3765 | if (PyFloat_Check(args[0])) { |
| 3766 | PyErr_SetString(PyExc_TypeError, |
| 3767 | "integer argument expected, got float" ); |
| 3768 | goto exit; |
| 3769 | } |
| 3770 | options = _PyLong_AsInt(args[0]); |
| 3771 | if (options == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3772 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3773 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3774 | return_value = os_wait3_impl(module, options); |
| 3775 | |
| 3776 | exit: |
| 3777 | return return_value; |
| 3778 | } |
| 3779 | |
| 3780 | #endif /* defined(HAVE_WAIT3) */ |
| 3781 | |
| 3782 | #if defined(HAVE_WAIT4) |
| 3783 | |
| 3784 | PyDoc_STRVAR(os_wait4__doc__, |
| 3785 | "wait4($module, /, pid, options)\n" |
| 3786 | "--\n" |
| 3787 | "\n" |
| 3788 | "Wait for completion of a specific child process.\n" |
| 3789 | "\n" |
| 3790 | "Returns a tuple of information about the child process:\n" |
| 3791 | " (pid, status, rusage)"); |
| 3792 | |
| 3793 | #define OS_WAIT4_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3794 | {"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] | 3795 | |
| 3796 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3797 | os_wait4_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3798 | |
| 3799 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3800 | 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] | 3801 | { |
| 3802 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3803 | static const char * const _keywords[] = {"pid", "options", NULL}; |
| 3804 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3805 | pid_t pid; |
| 3806 | int options; |
| 3807 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3808 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3809 | &pid, &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3810 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3811 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3812 | return_value = os_wait4_impl(module, pid, options); |
| 3813 | |
| 3814 | exit: |
| 3815 | return return_value; |
| 3816 | } |
| 3817 | |
| 3818 | #endif /* defined(HAVE_WAIT4) */ |
| 3819 | |
| 3820 | #if (defined(HAVE_WAITID) && !defined(__APPLE__)) |
| 3821 | |
| 3822 | PyDoc_STRVAR(os_waitid__doc__, |
| 3823 | "waitid($module, idtype, id, options, /)\n" |
| 3824 | "--\n" |
| 3825 | "\n" |
| 3826 | "Returns the result of waiting for a process or processes.\n" |
| 3827 | "\n" |
| 3828 | " idtype\n" |
| 3829 | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
| 3830 | " id\n" |
| 3831 | " The id to wait on.\n" |
| 3832 | " options\n" |
| 3833 | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
| 3834 | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
| 3835 | "\n" |
| 3836 | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
| 3837 | "no children in a waitable state."); |
| 3838 | |
| 3839 | #define OS_WAITID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3840 | {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3841 | |
| 3842 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3843 | 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] | 3844 | |
| 3845 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3846 | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3847 | { |
| 3848 | PyObject *return_value = NULL; |
| 3849 | idtype_t idtype; |
| 3850 | id_t id; |
| 3851 | int options; |
| 3852 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3853 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid", |
| 3854 | &idtype, &id, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3855 | goto exit; |
| 3856 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3857 | return_value = os_waitid_impl(module, idtype, id, options); |
| 3858 | |
| 3859 | exit: |
| 3860 | return return_value; |
| 3861 | } |
| 3862 | |
| 3863 | #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */ |
| 3864 | |
| 3865 | #if defined(HAVE_WAITPID) |
| 3866 | |
| 3867 | PyDoc_STRVAR(os_waitpid__doc__, |
| 3868 | "waitpid($module, pid, options, /)\n" |
| 3869 | "--\n" |
| 3870 | "\n" |
| 3871 | "Wait for completion of a given child process.\n" |
| 3872 | "\n" |
| 3873 | "Returns a tuple of information regarding the child process:\n" |
| 3874 | " (pid, status)\n" |
| 3875 | "\n" |
| 3876 | "The options argument is ignored on Windows."); |
| 3877 | |
| 3878 | #define OS_WAITPID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3879 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3880 | |
| 3881 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3882 | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3883 | |
| 3884 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3885 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3886 | { |
| 3887 | PyObject *return_value = NULL; |
| 3888 | pid_t pid; |
| 3889 | int options; |
| 3890 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3891 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid", |
| 3892 | &pid, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3893 | goto exit; |
| 3894 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3895 | return_value = os_waitpid_impl(module, pid, options); |
| 3896 | |
| 3897 | exit: |
| 3898 | return return_value; |
| 3899 | } |
| 3900 | |
| 3901 | #endif /* defined(HAVE_WAITPID) */ |
| 3902 | |
| 3903 | #if defined(HAVE_CWAIT) |
| 3904 | |
| 3905 | PyDoc_STRVAR(os_waitpid__doc__, |
| 3906 | "waitpid($module, pid, options, /)\n" |
| 3907 | "--\n" |
| 3908 | "\n" |
| 3909 | "Wait for completion of a given process.\n" |
| 3910 | "\n" |
| 3911 | "Returns a tuple of information regarding the process:\n" |
| 3912 | " (pid, status << 8)\n" |
| 3913 | "\n" |
| 3914 | "The options argument is ignored on Windows."); |
| 3915 | |
| 3916 | #define OS_WAITPID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3917 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3918 | |
| 3919 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3920 | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3921 | |
| 3922 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3923 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3924 | { |
| 3925 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3926 | intptr_t pid; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3927 | int options; |
| 3928 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3929 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid", |
| 3930 | &pid, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3931 | goto exit; |
| 3932 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3933 | return_value = os_waitpid_impl(module, pid, options); |
| 3934 | |
| 3935 | exit: |
| 3936 | return return_value; |
| 3937 | } |
| 3938 | |
| 3939 | #endif /* defined(HAVE_CWAIT) */ |
| 3940 | |
| 3941 | #if defined(HAVE_WAIT) |
| 3942 | |
| 3943 | PyDoc_STRVAR(os_wait__doc__, |
| 3944 | "wait($module, /)\n" |
| 3945 | "--\n" |
| 3946 | "\n" |
| 3947 | "Wait for completion of a child process.\n" |
| 3948 | "\n" |
| 3949 | "Returns a tuple of information about the child process:\n" |
| 3950 | " (pid, status)"); |
| 3951 | |
| 3952 | #define OS_WAIT_METHODDEF \ |
| 3953 | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
| 3954 | |
| 3955 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3956 | os_wait_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3957 | |
| 3958 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3959 | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3960 | { |
| 3961 | return os_wait_impl(module); |
| 3962 | } |
| 3963 | |
| 3964 | #endif /* defined(HAVE_WAIT) */ |
| 3965 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 3966 | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
| 3967 | |
| 3968 | PyDoc_STRVAR(os_readlink__doc__, |
| 3969 | "readlink($module, /, path, *, dir_fd=None)\n" |
| 3970 | "--\n" |
| 3971 | "\n" |
| 3972 | "Return a string representing the path to which the symbolic link points.\n" |
| 3973 | "\n" |
| 3974 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3975 | "and path should be relative; path will then be relative to that directory.\n" |
| 3976 | "\n" |
| 3977 | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
| 3978 | "using it will raise a NotImplementedError."); |
| 3979 | |
| 3980 | #define OS_READLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3981 | {"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] | 3982 | |
| 3983 | static PyObject * |
| 3984 | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
| 3985 | |
| 3986 | static PyObject * |
| 3987 | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 3988 | { |
| 3989 | PyObject *return_value = NULL; |
| 3990 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 3991 | static _PyArg_Parser _parser = {NULL, _keywords, "readlink", 0}; |
| 3992 | PyObject *argsbuf[2]; |
| 3993 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 3994 | path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0); |
| 3995 | int dir_fd = DEFAULT_DIR_FD; |
| 3996 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 3997 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 3998 | if (!args) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 3999 | goto exit; |
| 4000 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4001 | if (!path_converter(args[0], &path)) { |
| 4002 | goto exit; |
| 4003 | } |
| 4004 | if (!noptargs) { |
| 4005 | goto skip_optional_kwonly; |
| 4006 | } |
| 4007 | if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 4008 | goto exit; |
| 4009 | } |
| 4010 | skip_optional_kwonly: |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 4011 | return_value = os_readlink_impl(module, &path, dir_fd); |
| 4012 | |
| 4013 | exit: |
| 4014 | /* Cleanup for path */ |
| 4015 | path_cleanup(&path); |
| 4016 | |
| 4017 | return return_value; |
| 4018 | } |
| 4019 | |
| 4020 | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
| 4021 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4022 | #if defined(HAVE_SYMLINK) |
| 4023 | |
| 4024 | PyDoc_STRVAR(os_symlink__doc__, |
| 4025 | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
| 4026 | "--\n" |
| 4027 | "\n" |
| 4028 | "Create a symbolic link pointing to src named dst.\n" |
| 4029 | "\n" |
| 4030 | "target_is_directory is required on Windows if the target is to be\n" |
| 4031 | " interpreted as a directory. (On Windows, symlink requires\n" |
| 4032 | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
| 4033 | " target_is_directory is ignored on non-Windows platforms.\n" |
| 4034 | "\n" |
| 4035 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 4036 | " and path should be relative; path will then be relative to that directory.\n" |
| 4037 | "dir_fd may not be implemented on your platform.\n" |
| 4038 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 4039 | |
| 4040 | #define OS_SYMLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4041 | {"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] | 4042 | |
| 4043 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4044 | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 4045 | int target_is_directory, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4046 | |
| 4047 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4048 | 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] | 4049 | { |
| 4050 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4051 | static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4052 | static _PyArg_Parser _parser = {NULL, _keywords, "symlink", 0}; |
| 4053 | PyObject *argsbuf[4]; |
| 4054 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4055 | path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0); |
| 4056 | path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0); |
| 4057 | int target_is_directory = 0; |
| 4058 | int dir_fd = DEFAULT_DIR_FD; |
| 4059 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4060 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
| 4061 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4062 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4063 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4064 | if (!path_converter(args[0], &src)) { |
| 4065 | goto exit; |
| 4066 | } |
| 4067 | if (!path_converter(args[1], &dst)) { |
| 4068 | goto exit; |
| 4069 | } |
| 4070 | if (!noptargs) { |
| 4071 | goto skip_optional_pos; |
| 4072 | } |
| 4073 | if (args[2]) { |
| 4074 | target_is_directory = PyObject_IsTrue(args[2]); |
| 4075 | if (target_is_directory < 0) { |
| 4076 | goto exit; |
| 4077 | } |
| 4078 | if (!--noptargs) { |
| 4079 | goto skip_optional_pos; |
| 4080 | } |
| 4081 | } |
| 4082 | skip_optional_pos: |
| 4083 | if (!noptargs) { |
| 4084 | goto skip_optional_kwonly; |
| 4085 | } |
| 4086 | if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
| 4087 | goto exit; |
| 4088 | } |
| 4089 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4090 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
| 4091 | |
| 4092 | exit: |
| 4093 | /* Cleanup for src */ |
| 4094 | path_cleanup(&src); |
| 4095 | /* Cleanup for dst */ |
| 4096 | path_cleanup(&dst); |
| 4097 | |
| 4098 | return return_value; |
| 4099 | } |
| 4100 | |
| 4101 | #endif /* defined(HAVE_SYMLINK) */ |
| 4102 | |
| 4103 | #if defined(HAVE_TIMES) |
| 4104 | |
| 4105 | PyDoc_STRVAR(os_times__doc__, |
| 4106 | "times($module, /)\n" |
| 4107 | "--\n" |
| 4108 | "\n" |
| 4109 | "Return a collection containing process timing information.\n" |
| 4110 | "\n" |
| 4111 | "The object returned behaves like a named tuple with these fields:\n" |
| 4112 | " (utime, stime, cutime, cstime, elapsed_time)\n" |
| 4113 | "All fields are floating point numbers."); |
| 4114 | |
| 4115 | #define OS_TIMES_METHODDEF \ |
| 4116 | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
| 4117 | |
| 4118 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4119 | os_times_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4120 | |
| 4121 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4122 | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4123 | { |
| 4124 | return os_times_impl(module); |
| 4125 | } |
| 4126 | |
| 4127 | #endif /* defined(HAVE_TIMES) */ |
| 4128 | |
| 4129 | #if defined(HAVE_GETSID) |
| 4130 | |
| 4131 | PyDoc_STRVAR(os_getsid__doc__, |
| 4132 | "getsid($module, pid, /)\n" |
| 4133 | "--\n" |
| 4134 | "\n" |
| 4135 | "Call the system call getsid(pid) and return the result."); |
| 4136 | |
| 4137 | #define OS_GETSID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4138 | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4139 | |
| 4140 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4141 | os_getsid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4142 | |
| 4143 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4144 | os_getsid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4145 | { |
| 4146 | PyObject *return_value = NULL; |
| 4147 | pid_t pid; |
| 4148 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4149 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4150 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4151 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4152 | return_value = os_getsid_impl(module, pid); |
| 4153 | |
| 4154 | exit: |
| 4155 | return return_value; |
| 4156 | } |
| 4157 | |
| 4158 | #endif /* defined(HAVE_GETSID) */ |
| 4159 | |
| 4160 | #if defined(HAVE_SETSID) |
| 4161 | |
| 4162 | PyDoc_STRVAR(os_setsid__doc__, |
| 4163 | "setsid($module, /)\n" |
| 4164 | "--\n" |
| 4165 | "\n" |
| 4166 | "Call the system call setsid()."); |
| 4167 | |
| 4168 | #define OS_SETSID_METHODDEF \ |
| 4169 | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
| 4170 | |
| 4171 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4172 | os_setsid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4173 | |
| 4174 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4175 | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4176 | { |
| 4177 | return os_setsid_impl(module); |
| 4178 | } |
| 4179 | |
| 4180 | #endif /* defined(HAVE_SETSID) */ |
| 4181 | |
| 4182 | #if defined(HAVE_SETPGID) |
| 4183 | |
| 4184 | PyDoc_STRVAR(os_setpgid__doc__, |
| 4185 | "setpgid($module, pid, pgrp, /)\n" |
| 4186 | "--\n" |
| 4187 | "\n" |
| 4188 | "Call the system call setpgid(pid, pgrp)."); |
| 4189 | |
| 4190 | #define OS_SETPGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4191 | {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4192 | |
| 4193 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4194 | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4195 | |
| 4196 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4197 | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4198 | { |
| 4199 | PyObject *return_value = NULL; |
| 4200 | pid_t pid; |
| 4201 | pid_t pgrp; |
| 4202 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 4203 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid", |
| 4204 | &pid, &pgrp)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4205 | goto exit; |
| 4206 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4207 | return_value = os_setpgid_impl(module, pid, pgrp); |
| 4208 | |
| 4209 | exit: |
| 4210 | return return_value; |
| 4211 | } |
| 4212 | |
| 4213 | #endif /* defined(HAVE_SETPGID) */ |
| 4214 | |
| 4215 | #if defined(HAVE_TCGETPGRP) |
| 4216 | |
| 4217 | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
| 4218 | "tcgetpgrp($module, fd, /)\n" |
| 4219 | "--\n" |
| 4220 | "\n" |
| 4221 | "Return the process group associated with the terminal specified by fd."); |
| 4222 | |
| 4223 | #define OS_TCGETPGRP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4224 | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4225 | |
| 4226 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4227 | os_tcgetpgrp_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4228 | |
| 4229 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4230 | os_tcgetpgrp(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4231 | { |
| 4232 | PyObject *return_value = NULL; |
| 4233 | int fd; |
| 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_tcgetpgrp_impl(module, fd); |
| 4245 | |
| 4246 | exit: |
| 4247 | return return_value; |
| 4248 | } |
| 4249 | |
| 4250 | #endif /* defined(HAVE_TCGETPGRP) */ |
| 4251 | |
| 4252 | #if defined(HAVE_TCSETPGRP) |
| 4253 | |
| 4254 | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
| 4255 | "tcsetpgrp($module, fd, pgid, /)\n" |
| 4256 | "--\n" |
| 4257 | "\n" |
| 4258 | "Set the process group associated with the terminal specified by fd."); |
| 4259 | |
| 4260 | #define OS_TCSETPGRP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4261 | {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4262 | |
| 4263 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4264 | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4265 | |
| 4266 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4267 | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4268 | { |
| 4269 | PyObject *return_value = NULL; |
| 4270 | int fd; |
| 4271 | pid_t pgid; |
| 4272 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 4273 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp", |
| 4274 | &fd, &pgid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4275 | goto exit; |
| 4276 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4277 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
| 4278 | |
| 4279 | exit: |
| 4280 | return return_value; |
| 4281 | } |
| 4282 | |
| 4283 | #endif /* defined(HAVE_TCSETPGRP) */ |
| 4284 | |
| 4285 | PyDoc_STRVAR(os_open__doc__, |
| 4286 | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
| 4287 | "--\n" |
| 4288 | "\n" |
| 4289 | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
| 4290 | "\n" |
| 4291 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 4292 | " and path should be relative; path will then be relative to that directory.\n" |
| 4293 | "dir_fd may not be implemented on your platform.\n" |
| 4294 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 4295 | |
| 4296 | #define OS_OPEN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4297 | {"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] | 4298 | |
| 4299 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4300 | 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] | 4301 | |
| 4302 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4303 | 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] | 4304 | { |
| 4305 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4306 | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4307 | static _PyArg_Parser _parser = {NULL, _keywords, "open", 0}; |
| 4308 | PyObject *argsbuf[4]; |
| 4309 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4310 | path_t path = PATH_T_INITIALIZE("open", "path", 0, 0); |
| 4311 | int flags; |
| 4312 | int mode = 511; |
| 4313 | int dir_fd = DEFAULT_DIR_FD; |
| 4314 | int _return_value; |
| 4315 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4316 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
| 4317 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4318 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4319 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4320 | if (!path_converter(args[0], &path)) { |
| 4321 | goto exit; |
| 4322 | } |
| 4323 | if (PyFloat_Check(args[1])) { |
| 4324 | PyErr_SetString(PyExc_TypeError, |
| 4325 | "integer argument expected, got float" ); |
| 4326 | goto exit; |
| 4327 | } |
| 4328 | flags = _PyLong_AsInt(args[1]); |
| 4329 | if (flags == -1 && PyErr_Occurred()) { |
| 4330 | goto exit; |
| 4331 | } |
| 4332 | if (!noptargs) { |
| 4333 | goto skip_optional_pos; |
| 4334 | } |
| 4335 | if (args[2]) { |
| 4336 | if (PyFloat_Check(args[2])) { |
| 4337 | PyErr_SetString(PyExc_TypeError, |
| 4338 | "integer argument expected, got float" ); |
| 4339 | goto exit; |
| 4340 | } |
| 4341 | mode = _PyLong_AsInt(args[2]); |
| 4342 | if (mode == -1 && PyErr_Occurred()) { |
| 4343 | goto exit; |
| 4344 | } |
| 4345 | if (!--noptargs) { |
| 4346 | goto skip_optional_pos; |
| 4347 | } |
| 4348 | } |
| 4349 | skip_optional_pos: |
| 4350 | if (!noptargs) { |
| 4351 | goto skip_optional_kwonly; |
| 4352 | } |
| 4353 | if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
| 4354 | goto exit; |
| 4355 | } |
| 4356 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4357 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4358 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4359 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4360 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4361 | return_value = PyLong_FromLong((long)_return_value); |
| 4362 | |
| 4363 | exit: |
| 4364 | /* Cleanup for path */ |
| 4365 | path_cleanup(&path); |
| 4366 | |
| 4367 | return return_value; |
| 4368 | } |
| 4369 | |
| 4370 | PyDoc_STRVAR(os_close__doc__, |
| 4371 | "close($module, /, fd)\n" |
| 4372 | "--\n" |
| 4373 | "\n" |
| 4374 | "Close a file descriptor."); |
| 4375 | |
| 4376 | #define OS_CLOSE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4377 | {"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] | 4378 | |
| 4379 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4380 | os_close_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4381 | |
| 4382 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4383 | 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] | 4384 | { |
| 4385 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4386 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4387 | static _PyArg_Parser _parser = {NULL, _keywords, "close", 0}; |
| 4388 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4389 | int fd; |
| 4390 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4391 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 4392 | if (!args) { |
| 4393 | goto exit; |
| 4394 | } |
| 4395 | if (PyFloat_Check(args[0])) { |
| 4396 | PyErr_SetString(PyExc_TypeError, |
| 4397 | "integer argument expected, got float" ); |
| 4398 | goto exit; |
| 4399 | } |
| 4400 | fd = _PyLong_AsInt(args[0]); |
| 4401 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4402 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4403 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4404 | return_value = os_close_impl(module, fd); |
| 4405 | |
| 4406 | exit: |
| 4407 | return return_value; |
| 4408 | } |
| 4409 | |
| 4410 | PyDoc_STRVAR(os_closerange__doc__, |
| 4411 | "closerange($module, fd_low, fd_high, /)\n" |
| 4412 | "--\n" |
| 4413 | "\n" |
| 4414 | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
| 4415 | |
| 4416 | #define OS_CLOSERANGE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4417 | {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4418 | |
| 4419 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4420 | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4421 | |
| 4422 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4423 | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4424 | { |
| 4425 | PyObject *return_value = NULL; |
| 4426 | int fd_low; |
| 4427 | int fd_high; |
| 4428 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4429 | if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { |
| 4430 | goto exit; |
| 4431 | } |
| 4432 | if (PyFloat_Check(args[0])) { |
| 4433 | PyErr_SetString(PyExc_TypeError, |
| 4434 | "integer argument expected, got float" ); |
| 4435 | goto exit; |
| 4436 | } |
| 4437 | fd_low = _PyLong_AsInt(args[0]); |
| 4438 | if (fd_low == -1 && PyErr_Occurred()) { |
| 4439 | goto exit; |
| 4440 | } |
| 4441 | if (PyFloat_Check(args[1])) { |
| 4442 | PyErr_SetString(PyExc_TypeError, |
| 4443 | "integer argument expected, got float" ); |
| 4444 | goto exit; |
| 4445 | } |
| 4446 | fd_high = _PyLong_AsInt(args[1]); |
| 4447 | if (fd_high == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4448 | goto exit; |
| 4449 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4450 | return_value = os_closerange_impl(module, fd_low, fd_high); |
| 4451 | |
| 4452 | exit: |
| 4453 | return return_value; |
| 4454 | } |
| 4455 | |
| 4456 | PyDoc_STRVAR(os_dup__doc__, |
| 4457 | "dup($module, fd, /)\n" |
| 4458 | "--\n" |
| 4459 | "\n" |
| 4460 | "Return a duplicate of a file descriptor."); |
| 4461 | |
| 4462 | #define OS_DUP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4463 | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4464 | |
| 4465 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4466 | os_dup_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4467 | |
| 4468 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4469 | os_dup(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4470 | { |
| 4471 | PyObject *return_value = NULL; |
| 4472 | int fd; |
| 4473 | int _return_value; |
| 4474 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4475 | if (PyFloat_Check(arg)) { |
| 4476 | PyErr_SetString(PyExc_TypeError, |
| 4477 | "integer argument expected, got float" ); |
| 4478 | goto exit; |
| 4479 | } |
| 4480 | fd = _PyLong_AsInt(arg); |
| 4481 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4482 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4483 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4484 | _return_value = os_dup_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4485 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4486 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4487 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4488 | return_value = PyLong_FromLong((long)_return_value); |
| 4489 | |
| 4490 | exit: |
| 4491 | return return_value; |
| 4492 | } |
| 4493 | |
| 4494 | PyDoc_STRVAR(os_dup2__doc__, |
| 4495 | "dup2($module, /, fd, fd2, inheritable=True)\n" |
| 4496 | "--\n" |
| 4497 | "\n" |
| 4498 | "Duplicate file descriptor."); |
| 4499 | |
| 4500 | #define OS_DUP2_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4501 | {"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] | 4502 | |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 4503 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4504 | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4505 | |
| 4506 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4507 | 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] | 4508 | { |
| 4509 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4510 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4511 | static _PyArg_Parser _parser = {NULL, _keywords, "dup2", 0}; |
| 4512 | PyObject *argsbuf[3]; |
| 4513 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4514 | int fd; |
| 4515 | int fd2; |
| 4516 | int inheritable = 1; |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 4517 | int _return_value; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4518 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4519 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
| 4520 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4521 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4522 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4523 | if (PyFloat_Check(args[0])) { |
| 4524 | PyErr_SetString(PyExc_TypeError, |
| 4525 | "integer argument expected, got float" ); |
| 4526 | goto exit; |
| 4527 | } |
| 4528 | fd = _PyLong_AsInt(args[0]); |
| 4529 | if (fd == -1 && PyErr_Occurred()) { |
| 4530 | goto exit; |
| 4531 | } |
| 4532 | if (PyFloat_Check(args[1])) { |
| 4533 | PyErr_SetString(PyExc_TypeError, |
| 4534 | "integer argument expected, got float" ); |
| 4535 | goto exit; |
| 4536 | } |
| 4537 | fd2 = _PyLong_AsInt(args[1]); |
| 4538 | if (fd2 == -1 && PyErr_Occurred()) { |
| 4539 | goto exit; |
| 4540 | } |
| 4541 | if (!noptargs) { |
| 4542 | goto skip_optional_pos; |
| 4543 | } |
| 4544 | inheritable = PyObject_IsTrue(args[2]); |
| 4545 | if (inheritable < 0) { |
| 4546 | goto exit; |
| 4547 | } |
| 4548 | skip_optional_pos: |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 4549 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
| 4550 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 4551 | goto exit; |
| 4552 | } |
| 4553 | return_value = PyLong_FromLong((long)_return_value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4554 | |
| 4555 | exit: |
| 4556 | return return_value; |
| 4557 | } |
| 4558 | |
| 4559 | #if defined(HAVE_LOCKF) |
| 4560 | |
| 4561 | PyDoc_STRVAR(os_lockf__doc__, |
| 4562 | "lockf($module, fd, command, length, /)\n" |
| 4563 | "--\n" |
| 4564 | "\n" |
| 4565 | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
| 4566 | "\n" |
| 4567 | " fd\n" |
| 4568 | " An open file descriptor.\n" |
| 4569 | " command\n" |
| 4570 | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
| 4571 | " length\n" |
| 4572 | " The number of bytes to lock, starting at the current position."); |
| 4573 | |
| 4574 | #define OS_LOCKF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4575 | {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4576 | |
| 4577 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4578 | 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] | 4579 | |
| 4580 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4581 | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4582 | { |
| 4583 | PyObject *return_value = NULL; |
| 4584 | int fd; |
| 4585 | int command; |
| 4586 | Py_off_t length; |
| 4587 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4588 | if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { |
| 4589 | goto exit; |
| 4590 | } |
| 4591 | if (PyFloat_Check(args[0])) { |
| 4592 | PyErr_SetString(PyExc_TypeError, |
| 4593 | "integer argument expected, got float" ); |
| 4594 | goto exit; |
| 4595 | } |
| 4596 | fd = _PyLong_AsInt(args[0]); |
| 4597 | if (fd == -1 && PyErr_Occurred()) { |
| 4598 | goto exit; |
| 4599 | } |
| 4600 | if (PyFloat_Check(args[1])) { |
| 4601 | PyErr_SetString(PyExc_TypeError, |
| 4602 | "integer argument expected, got float" ); |
| 4603 | goto exit; |
| 4604 | } |
| 4605 | command = _PyLong_AsInt(args[1]); |
| 4606 | if (command == -1 && PyErr_Occurred()) { |
| 4607 | goto exit; |
| 4608 | } |
| 4609 | if (!Py_off_t_converter(args[2], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4610 | goto exit; |
| 4611 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4612 | return_value = os_lockf_impl(module, fd, command, length); |
| 4613 | |
| 4614 | exit: |
| 4615 | return return_value; |
| 4616 | } |
| 4617 | |
| 4618 | #endif /* defined(HAVE_LOCKF) */ |
| 4619 | |
| 4620 | PyDoc_STRVAR(os_lseek__doc__, |
| 4621 | "lseek($module, fd, position, how, /)\n" |
| 4622 | "--\n" |
| 4623 | "\n" |
| 4624 | "Set the position of a file descriptor. Return the new position.\n" |
| 4625 | "\n" |
| 4626 | "Return the new cursor position in number of bytes\n" |
| 4627 | "relative to the beginning of the file."); |
| 4628 | |
| 4629 | #define OS_LSEEK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4630 | {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4631 | |
| 4632 | static Py_off_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4633 | 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] | 4634 | |
| 4635 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4636 | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4637 | { |
| 4638 | PyObject *return_value = NULL; |
| 4639 | int fd; |
| 4640 | Py_off_t position; |
| 4641 | int how; |
| 4642 | Py_off_t _return_value; |
| 4643 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4644 | if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { |
| 4645 | goto exit; |
| 4646 | } |
| 4647 | if (PyFloat_Check(args[0])) { |
| 4648 | PyErr_SetString(PyExc_TypeError, |
| 4649 | "integer argument expected, got float" ); |
| 4650 | goto exit; |
| 4651 | } |
| 4652 | fd = _PyLong_AsInt(args[0]); |
| 4653 | if (fd == -1 && PyErr_Occurred()) { |
| 4654 | goto exit; |
| 4655 | } |
| 4656 | if (!Py_off_t_converter(args[1], &position)) { |
| 4657 | goto exit; |
| 4658 | } |
| 4659 | if (PyFloat_Check(args[2])) { |
| 4660 | PyErr_SetString(PyExc_TypeError, |
| 4661 | "integer argument expected, got float" ); |
| 4662 | goto exit; |
| 4663 | } |
| 4664 | how = _PyLong_AsInt(args[2]); |
| 4665 | if (how == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4666 | goto exit; |
| 4667 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4668 | _return_value = os_lseek_impl(module, fd, position, how); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4669 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4670 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4671 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4672 | return_value = PyLong_FromPy_off_t(_return_value); |
| 4673 | |
| 4674 | exit: |
| 4675 | return return_value; |
| 4676 | } |
| 4677 | |
| 4678 | PyDoc_STRVAR(os_read__doc__, |
| 4679 | "read($module, fd, length, /)\n" |
| 4680 | "--\n" |
| 4681 | "\n" |
| 4682 | "Read from a file descriptor. Returns a bytes object."); |
| 4683 | |
| 4684 | #define OS_READ_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4685 | {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4686 | |
| 4687 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4688 | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4689 | |
| 4690 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4691 | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4692 | { |
| 4693 | PyObject *return_value = NULL; |
| 4694 | int fd; |
| 4695 | Py_ssize_t length; |
| 4696 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4697 | if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4698 | goto exit; |
| 4699 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4700 | if (PyFloat_Check(args[0])) { |
| 4701 | PyErr_SetString(PyExc_TypeError, |
| 4702 | "integer argument expected, got float" ); |
| 4703 | goto exit; |
| 4704 | } |
| 4705 | fd = _PyLong_AsInt(args[0]); |
| 4706 | if (fd == -1 && PyErr_Occurred()) { |
| 4707 | goto exit; |
| 4708 | } |
| 4709 | if (PyFloat_Check(args[1])) { |
| 4710 | PyErr_SetString(PyExc_TypeError, |
| 4711 | "integer argument expected, got float" ); |
| 4712 | goto exit; |
| 4713 | } |
| 4714 | { |
| 4715 | Py_ssize_t ival = -1; |
| 4716 | PyObject *iobj = PyNumber_Index(args[1]); |
| 4717 | if (iobj != NULL) { |
| 4718 | ival = PyLong_AsSsize_t(iobj); |
| 4719 | Py_DECREF(iobj); |
| 4720 | } |
| 4721 | if (ival == -1 && PyErr_Occurred()) { |
| 4722 | goto exit; |
| 4723 | } |
| 4724 | length = ival; |
| 4725 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4726 | return_value = os_read_impl(module, fd, length); |
| 4727 | |
| 4728 | exit: |
| 4729 | return return_value; |
| 4730 | } |
| 4731 | |
| 4732 | #if defined(HAVE_READV) |
| 4733 | |
| 4734 | PyDoc_STRVAR(os_readv__doc__, |
| 4735 | "readv($module, fd, buffers, /)\n" |
| 4736 | "--\n" |
| 4737 | "\n" |
| 4738 | "Read from a file descriptor fd into an iterable of buffers.\n" |
| 4739 | "\n" |
| 4740 | "The buffers should be mutable buffers accepting bytes.\n" |
| 4741 | "readv will transfer data into each buffer until it is full\n" |
| 4742 | "and then move on to the next buffer in the sequence to hold\n" |
| 4743 | "the rest of the data.\n" |
| 4744 | "\n" |
| 4745 | "readv returns the total number of bytes read,\n" |
| 4746 | "which may be less than the total capacity of all the buffers."); |
| 4747 | |
| 4748 | #define OS_READV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4749 | {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4750 | |
| 4751 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4752 | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4753 | |
| 4754 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4755 | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4756 | { |
| 4757 | PyObject *return_value = NULL; |
| 4758 | int fd; |
| 4759 | PyObject *buffers; |
| 4760 | Py_ssize_t _return_value; |
| 4761 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4762 | if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4763 | goto exit; |
| 4764 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4765 | if (PyFloat_Check(args[0])) { |
| 4766 | PyErr_SetString(PyExc_TypeError, |
| 4767 | "integer argument expected, got float" ); |
| 4768 | goto exit; |
| 4769 | } |
| 4770 | fd = _PyLong_AsInt(args[0]); |
| 4771 | if (fd == -1 && PyErr_Occurred()) { |
| 4772 | goto exit; |
| 4773 | } |
| 4774 | buffers = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4775 | _return_value = os_readv_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4776 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4777 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4778 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4779 | return_value = PyLong_FromSsize_t(_return_value); |
| 4780 | |
| 4781 | exit: |
| 4782 | return return_value; |
| 4783 | } |
| 4784 | |
| 4785 | #endif /* defined(HAVE_READV) */ |
| 4786 | |
| 4787 | #if defined(HAVE_PREAD) |
| 4788 | |
| 4789 | PyDoc_STRVAR(os_pread__doc__, |
| 4790 | "pread($module, fd, length, offset, /)\n" |
| 4791 | "--\n" |
| 4792 | "\n" |
| 4793 | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
| 4794 | "\n" |
| 4795 | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
| 4796 | "the beginning of the file. The file offset remains unchanged."); |
| 4797 | |
| 4798 | #define OS_PREAD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4799 | {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4800 | |
| 4801 | static PyObject * |
Dong-hee Na | ad7736f | 2019-09-25 14:47:04 +0900 | [diff] [blame] | 4802 | os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4803 | |
| 4804 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4805 | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4806 | { |
| 4807 | PyObject *return_value = NULL; |
| 4808 | int fd; |
Dong-hee Na | ad7736f | 2019-09-25 14:47:04 +0900 | [diff] [blame] | 4809 | Py_ssize_t length; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4810 | Py_off_t offset; |
| 4811 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4812 | if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { |
| 4813 | goto exit; |
| 4814 | } |
| 4815 | if (PyFloat_Check(args[0])) { |
| 4816 | PyErr_SetString(PyExc_TypeError, |
| 4817 | "integer argument expected, got float" ); |
| 4818 | goto exit; |
| 4819 | } |
| 4820 | fd = _PyLong_AsInt(args[0]); |
| 4821 | if (fd == -1 && PyErr_Occurred()) { |
| 4822 | goto exit; |
| 4823 | } |
| 4824 | if (PyFloat_Check(args[1])) { |
| 4825 | PyErr_SetString(PyExc_TypeError, |
| 4826 | "integer argument expected, got float" ); |
| 4827 | goto exit; |
| 4828 | } |
Dong-hee Na | ad7736f | 2019-09-25 14:47:04 +0900 | [diff] [blame] | 4829 | { |
| 4830 | Py_ssize_t ival = -1; |
| 4831 | PyObject *iobj = PyNumber_Index(args[1]); |
| 4832 | if (iobj != NULL) { |
| 4833 | ival = PyLong_AsSsize_t(iobj); |
| 4834 | Py_DECREF(iobj); |
| 4835 | } |
| 4836 | if (ival == -1 && PyErr_Occurred()) { |
| 4837 | goto exit; |
| 4838 | } |
| 4839 | length = ival; |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4840 | } |
| 4841 | if (!Py_off_t_converter(args[2], &offset)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4842 | goto exit; |
| 4843 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4844 | return_value = os_pread_impl(module, fd, length, offset); |
| 4845 | |
| 4846 | exit: |
| 4847 | return return_value; |
| 4848 | } |
| 4849 | |
| 4850 | #endif /* defined(HAVE_PREAD) */ |
| 4851 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4852 | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
| 4853 | |
| 4854 | PyDoc_STRVAR(os_preadv__doc__, |
| 4855 | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
| 4856 | "--\n" |
| 4857 | "\n" |
| 4858 | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
| 4859 | "\n" |
| 4860 | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
| 4861 | "transfer data into each buffer until it is full and then move on to the next\n" |
| 4862 | "buffer in the sequence to hold the rest of the data. Its fourth argument,\n" |
| 4863 | "specifies the file offset at which the input operation is to be performed. It\n" |
| 4864 | "will return the total number of bytes read (which can be less than the total\n" |
| 4865 | "capacity of all the objects).\n" |
| 4866 | "\n" |
| 4867 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
| 4868 | "\n" |
| 4869 | "- RWF_HIPRI\n" |
| 4870 | "- RWF_NOWAIT\n" |
| 4871 | "\n" |
| 4872 | "Using non-zero flags requires Linux 4.6 or newer."); |
| 4873 | |
| 4874 | #define OS_PREADV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4875 | {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__}, |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4876 | |
| 4877 | static Py_ssize_t |
| 4878 | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
| 4879 | int flags); |
| 4880 | |
| 4881 | static PyObject * |
| 4882 | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 4883 | { |
| 4884 | PyObject *return_value = NULL; |
| 4885 | int fd; |
| 4886 | PyObject *buffers; |
| 4887 | Py_off_t offset; |
| 4888 | int flags = 0; |
| 4889 | Py_ssize_t _return_value; |
| 4890 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4891 | if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4892 | goto exit; |
| 4893 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4894 | if (PyFloat_Check(args[0])) { |
| 4895 | PyErr_SetString(PyExc_TypeError, |
| 4896 | "integer argument expected, got float" ); |
| 4897 | goto exit; |
| 4898 | } |
| 4899 | fd = _PyLong_AsInt(args[0]); |
| 4900 | if (fd == -1 && PyErr_Occurred()) { |
| 4901 | goto exit; |
| 4902 | } |
| 4903 | buffers = args[1]; |
| 4904 | if (!Py_off_t_converter(args[2], &offset)) { |
| 4905 | goto exit; |
| 4906 | } |
| 4907 | if (nargs < 4) { |
| 4908 | goto skip_optional; |
| 4909 | } |
| 4910 | if (PyFloat_Check(args[3])) { |
| 4911 | PyErr_SetString(PyExc_TypeError, |
| 4912 | "integer argument expected, got float" ); |
| 4913 | goto exit; |
| 4914 | } |
| 4915 | flags = _PyLong_AsInt(args[3]); |
| 4916 | if (flags == -1 && PyErr_Occurred()) { |
| 4917 | goto exit; |
| 4918 | } |
| 4919 | skip_optional: |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4920 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
| 4921 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 4922 | goto exit; |
| 4923 | } |
| 4924 | return_value = PyLong_FromSsize_t(_return_value); |
| 4925 | |
| 4926 | exit: |
| 4927 | return return_value; |
| 4928 | } |
| 4929 | |
| 4930 | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
| 4931 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4932 | PyDoc_STRVAR(os_write__doc__, |
| 4933 | "write($module, fd, data, /)\n" |
| 4934 | "--\n" |
| 4935 | "\n" |
| 4936 | "Write a bytes object to a file descriptor."); |
| 4937 | |
| 4938 | #define OS_WRITE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4939 | {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4940 | |
| 4941 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4942 | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4943 | |
| 4944 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4945 | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4946 | { |
| 4947 | PyObject *return_value = NULL; |
| 4948 | int fd; |
| 4949 | Py_buffer data = {NULL, NULL}; |
| 4950 | Py_ssize_t _return_value; |
| 4951 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4952 | if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { |
| 4953 | goto exit; |
| 4954 | } |
| 4955 | if (PyFloat_Check(args[0])) { |
| 4956 | PyErr_SetString(PyExc_TypeError, |
| 4957 | "integer argument expected, got float" ); |
| 4958 | goto exit; |
| 4959 | } |
| 4960 | fd = _PyLong_AsInt(args[0]); |
| 4961 | if (fd == -1 && PyErr_Occurred()) { |
| 4962 | goto exit; |
| 4963 | } |
| 4964 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
| 4965 | goto exit; |
| 4966 | } |
| 4967 | if (!PyBuffer_IsContiguous(&data, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 4968 | _PyArg_BadArgument("write", "argument 2", "contiguous buffer", args[1]); |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4969 | goto exit; |
| 4970 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4971 | _return_value = os_write_impl(module, fd, &data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4972 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4973 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4974 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4975 | return_value = PyLong_FromSsize_t(_return_value); |
| 4976 | |
| 4977 | exit: |
| 4978 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4979 | if (data.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4980 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4981 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4982 | |
| 4983 | return return_value; |
| 4984 | } |
| 4985 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4986 | #if defined(__APPLE__) |
| 4987 | |
| 4988 | PyDoc_STRVAR(os__fcopyfile__doc__, |
Serhiy Storchaka | 140a7d1 | 2019-10-13 11:59:31 +0300 | [diff] [blame] | 4989 | "_fcopyfile($module, in_fd, out_fd, flags, /)\n" |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4990 | "--\n" |
| 4991 | "\n" |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 4992 | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4993 | |
| 4994 | #define OS__FCOPYFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4995 | {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__}, |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4996 | |
| 4997 | static PyObject * |
Serhiy Storchaka | 140a7d1 | 2019-10-13 11:59:31 +0300 | [diff] [blame] | 4998 | os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags); |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4999 | |
| 5000 | static PyObject * |
| 5001 | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 5002 | { |
| 5003 | PyObject *return_value = NULL; |
Serhiy Storchaka | 140a7d1 | 2019-10-13 11:59:31 +0300 | [diff] [blame] | 5004 | int in_fd; |
| 5005 | int out_fd; |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 5006 | int flags; |
| 5007 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5008 | if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { |
| 5009 | goto exit; |
| 5010 | } |
| 5011 | if (PyFloat_Check(args[0])) { |
| 5012 | PyErr_SetString(PyExc_TypeError, |
| 5013 | "integer argument expected, got float" ); |
| 5014 | goto exit; |
| 5015 | } |
Serhiy Storchaka | 140a7d1 | 2019-10-13 11:59:31 +0300 | [diff] [blame] | 5016 | in_fd = _PyLong_AsInt(args[0]); |
| 5017 | if (in_fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5018 | goto exit; |
| 5019 | } |
| 5020 | if (PyFloat_Check(args[1])) { |
| 5021 | PyErr_SetString(PyExc_TypeError, |
| 5022 | "integer argument expected, got float" ); |
| 5023 | goto exit; |
| 5024 | } |
Serhiy Storchaka | 140a7d1 | 2019-10-13 11:59:31 +0300 | [diff] [blame] | 5025 | out_fd = _PyLong_AsInt(args[1]); |
| 5026 | if (out_fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5027 | goto exit; |
| 5028 | } |
| 5029 | if (PyFloat_Check(args[2])) { |
| 5030 | PyErr_SetString(PyExc_TypeError, |
| 5031 | "integer argument expected, got float" ); |
| 5032 | goto exit; |
| 5033 | } |
| 5034 | flags = _PyLong_AsInt(args[2]); |
| 5035 | if (flags == -1 && PyErr_Occurred()) { |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 5036 | goto exit; |
| 5037 | } |
Serhiy Storchaka | 140a7d1 | 2019-10-13 11:59:31 +0300 | [diff] [blame] | 5038 | return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags); |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 5039 | |
| 5040 | exit: |
| 5041 | return return_value; |
| 5042 | } |
| 5043 | |
| 5044 | #endif /* defined(__APPLE__) */ |
| 5045 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5046 | PyDoc_STRVAR(os_fstat__doc__, |
| 5047 | "fstat($module, /, fd)\n" |
| 5048 | "--\n" |
| 5049 | "\n" |
| 5050 | "Perform a stat system call on the given file descriptor.\n" |
| 5051 | "\n" |
| 5052 | "Like stat(), but for an open file descriptor.\n" |
| 5053 | "Equivalent to os.stat(fd)."); |
| 5054 | |
| 5055 | #define OS_FSTAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5056 | {"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] | 5057 | |
| 5058 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5059 | os_fstat_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5060 | |
| 5061 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5062 | 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] | 5063 | { |
| 5064 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5065 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5066 | static _PyArg_Parser _parser = {NULL, _keywords, "fstat", 0}; |
| 5067 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5068 | int fd; |
| 5069 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5070 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 5071 | if (!args) { |
| 5072 | goto exit; |
| 5073 | } |
| 5074 | if (PyFloat_Check(args[0])) { |
| 5075 | PyErr_SetString(PyExc_TypeError, |
| 5076 | "integer argument expected, got float" ); |
| 5077 | goto exit; |
| 5078 | } |
| 5079 | fd = _PyLong_AsInt(args[0]); |
| 5080 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5081 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5082 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5083 | return_value = os_fstat_impl(module, fd); |
| 5084 | |
| 5085 | exit: |
| 5086 | return return_value; |
| 5087 | } |
| 5088 | |
| 5089 | PyDoc_STRVAR(os_isatty__doc__, |
| 5090 | "isatty($module, fd, /)\n" |
| 5091 | "--\n" |
| 5092 | "\n" |
| 5093 | "Return True if the fd is connected to a terminal.\n" |
| 5094 | "\n" |
| 5095 | "Return True if the file descriptor is an open file descriptor\n" |
| 5096 | "connected to the slave end of a terminal."); |
| 5097 | |
| 5098 | #define OS_ISATTY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5099 | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5100 | |
| 5101 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5102 | os_isatty_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5103 | |
| 5104 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5105 | os_isatty(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5106 | { |
| 5107 | PyObject *return_value = NULL; |
| 5108 | int fd; |
| 5109 | int _return_value; |
| 5110 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5111 | if (PyFloat_Check(arg)) { |
| 5112 | PyErr_SetString(PyExc_TypeError, |
| 5113 | "integer argument expected, got float" ); |
| 5114 | goto exit; |
| 5115 | } |
| 5116 | fd = _PyLong_AsInt(arg); |
| 5117 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5118 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5119 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5120 | _return_value = os_isatty_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5121 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5122 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5123 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5124 | return_value = PyBool_FromLong((long)_return_value); |
| 5125 | |
| 5126 | exit: |
| 5127 | return return_value; |
| 5128 | } |
| 5129 | |
| 5130 | #if defined(HAVE_PIPE) |
| 5131 | |
| 5132 | PyDoc_STRVAR(os_pipe__doc__, |
| 5133 | "pipe($module, /)\n" |
| 5134 | "--\n" |
| 5135 | "\n" |
| 5136 | "Create a pipe.\n" |
| 5137 | "\n" |
| 5138 | "Returns a tuple of two file descriptors:\n" |
| 5139 | " (read_fd, write_fd)"); |
| 5140 | |
| 5141 | #define OS_PIPE_METHODDEF \ |
| 5142 | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
| 5143 | |
| 5144 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5145 | os_pipe_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5146 | |
| 5147 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5148 | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5149 | { |
| 5150 | return os_pipe_impl(module); |
| 5151 | } |
| 5152 | |
| 5153 | #endif /* defined(HAVE_PIPE) */ |
| 5154 | |
| 5155 | #if defined(HAVE_PIPE2) |
| 5156 | |
| 5157 | PyDoc_STRVAR(os_pipe2__doc__, |
| 5158 | "pipe2($module, flags, /)\n" |
| 5159 | "--\n" |
| 5160 | "\n" |
| 5161 | "Create a pipe with flags set atomically.\n" |
| 5162 | "\n" |
| 5163 | "Returns a tuple of two file descriptors:\n" |
| 5164 | " (read_fd, write_fd)\n" |
| 5165 | "\n" |
| 5166 | "flags can be constructed by ORing together one or more of these values:\n" |
| 5167 | "O_NONBLOCK, O_CLOEXEC."); |
| 5168 | |
| 5169 | #define OS_PIPE2_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5170 | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5171 | |
| 5172 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5173 | os_pipe2_impl(PyObject *module, int flags); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5174 | |
| 5175 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5176 | os_pipe2(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5177 | { |
| 5178 | PyObject *return_value = NULL; |
| 5179 | int flags; |
| 5180 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5181 | if (PyFloat_Check(arg)) { |
| 5182 | PyErr_SetString(PyExc_TypeError, |
| 5183 | "integer argument expected, got float" ); |
| 5184 | goto exit; |
| 5185 | } |
| 5186 | flags = _PyLong_AsInt(arg); |
| 5187 | if (flags == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5188 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5189 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5190 | return_value = os_pipe2_impl(module, flags); |
| 5191 | |
| 5192 | exit: |
| 5193 | return return_value; |
| 5194 | } |
| 5195 | |
| 5196 | #endif /* defined(HAVE_PIPE2) */ |
| 5197 | |
| 5198 | #if defined(HAVE_WRITEV) |
| 5199 | |
| 5200 | PyDoc_STRVAR(os_writev__doc__, |
| 5201 | "writev($module, fd, buffers, /)\n" |
| 5202 | "--\n" |
| 5203 | "\n" |
| 5204 | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
| 5205 | "\n" |
| 5206 | "Returns the total number of bytes written.\n" |
| 5207 | "buffers must be a sequence of bytes-like objects."); |
| 5208 | |
| 5209 | #define OS_WRITEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5210 | {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5211 | |
| 5212 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5213 | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5214 | |
| 5215 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5216 | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5217 | { |
| 5218 | PyObject *return_value = NULL; |
| 5219 | int fd; |
| 5220 | PyObject *buffers; |
| 5221 | Py_ssize_t _return_value; |
| 5222 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5223 | if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5224 | goto exit; |
| 5225 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5226 | if (PyFloat_Check(args[0])) { |
| 5227 | PyErr_SetString(PyExc_TypeError, |
| 5228 | "integer argument expected, got float" ); |
| 5229 | goto exit; |
| 5230 | } |
| 5231 | fd = _PyLong_AsInt(args[0]); |
| 5232 | if (fd == -1 && PyErr_Occurred()) { |
| 5233 | goto exit; |
| 5234 | } |
| 5235 | buffers = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5236 | _return_value = os_writev_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5237 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5238 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5239 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5240 | return_value = PyLong_FromSsize_t(_return_value); |
| 5241 | |
| 5242 | exit: |
| 5243 | return return_value; |
| 5244 | } |
| 5245 | |
| 5246 | #endif /* defined(HAVE_WRITEV) */ |
| 5247 | |
| 5248 | #if defined(HAVE_PWRITE) |
| 5249 | |
| 5250 | PyDoc_STRVAR(os_pwrite__doc__, |
| 5251 | "pwrite($module, fd, buffer, offset, /)\n" |
| 5252 | "--\n" |
| 5253 | "\n" |
| 5254 | "Write bytes to a file descriptor starting at a particular offset.\n" |
| 5255 | "\n" |
| 5256 | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
| 5257 | "the file. Returns the number of bytes writte. Does not change the\n" |
| 5258 | "current file offset."); |
| 5259 | |
| 5260 | #define OS_PWRITE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5261 | {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5262 | |
| 5263 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5264 | 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] | 5265 | |
| 5266 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5267 | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5268 | { |
| 5269 | PyObject *return_value = NULL; |
| 5270 | int fd; |
| 5271 | Py_buffer buffer = {NULL, NULL}; |
| 5272 | Py_off_t offset; |
| 5273 | Py_ssize_t _return_value; |
| 5274 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5275 | if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { |
| 5276 | goto exit; |
| 5277 | } |
| 5278 | if (PyFloat_Check(args[0])) { |
| 5279 | PyErr_SetString(PyExc_TypeError, |
| 5280 | "integer argument expected, got float" ); |
| 5281 | goto exit; |
| 5282 | } |
| 5283 | fd = _PyLong_AsInt(args[0]); |
| 5284 | if (fd == -1 && PyErr_Occurred()) { |
| 5285 | goto exit; |
| 5286 | } |
| 5287 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
| 5288 | goto exit; |
| 5289 | } |
| 5290 | if (!PyBuffer_IsContiguous(&buffer, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 5291 | _PyArg_BadArgument("pwrite", "argument 2", "contiguous buffer", args[1]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5292 | goto exit; |
| 5293 | } |
| 5294 | if (!Py_off_t_converter(args[2], &offset)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5295 | goto exit; |
| 5296 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5297 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5298 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5299 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5300 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5301 | return_value = PyLong_FromSsize_t(_return_value); |
| 5302 | |
| 5303 | exit: |
| 5304 | /* Cleanup for buffer */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5305 | if (buffer.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5306 | PyBuffer_Release(&buffer); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5307 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5308 | |
| 5309 | return return_value; |
| 5310 | } |
| 5311 | |
| 5312 | #endif /* defined(HAVE_PWRITE) */ |
| 5313 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 5314 | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
| 5315 | |
| 5316 | PyDoc_STRVAR(os_pwritev__doc__, |
| 5317 | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
| 5318 | "--\n" |
| 5319 | "\n" |
| 5320 | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
| 5321 | "\n" |
| 5322 | "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n" |
| 5323 | "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n" |
| 5324 | "buffer is written before proceeding to second, and so on. The operating system may\n" |
| 5325 | "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n" |
| 5326 | "This function writes the contents of each object to the file descriptor and returns\n" |
| 5327 | "the total number of bytes written.\n" |
| 5328 | "\n" |
| 5329 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
| 5330 | "\n" |
| 5331 | "- RWF_DSYNC\n" |
| 5332 | "- RWF_SYNC\n" |
| 5333 | "\n" |
| 5334 | "Using non-zero flags requires Linux 4.7 or newer."); |
| 5335 | |
| 5336 | #define OS_PWRITEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5337 | {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__}, |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 5338 | |
| 5339 | static Py_ssize_t |
| 5340 | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
| 5341 | int flags); |
| 5342 | |
| 5343 | static PyObject * |
| 5344 | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 5345 | { |
| 5346 | PyObject *return_value = NULL; |
| 5347 | int fd; |
| 5348 | PyObject *buffers; |
| 5349 | Py_off_t offset; |
| 5350 | int flags = 0; |
| 5351 | Py_ssize_t _return_value; |
| 5352 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5353 | if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 5354 | goto exit; |
| 5355 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5356 | if (PyFloat_Check(args[0])) { |
| 5357 | PyErr_SetString(PyExc_TypeError, |
| 5358 | "integer argument expected, got float" ); |
| 5359 | goto exit; |
| 5360 | } |
| 5361 | fd = _PyLong_AsInt(args[0]); |
| 5362 | if (fd == -1 && PyErr_Occurred()) { |
| 5363 | goto exit; |
| 5364 | } |
| 5365 | buffers = args[1]; |
| 5366 | if (!Py_off_t_converter(args[2], &offset)) { |
| 5367 | goto exit; |
| 5368 | } |
| 5369 | if (nargs < 4) { |
| 5370 | goto skip_optional; |
| 5371 | } |
| 5372 | if (PyFloat_Check(args[3])) { |
| 5373 | PyErr_SetString(PyExc_TypeError, |
| 5374 | "integer argument expected, got float" ); |
| 5375 | goto exit; |
| 5376 | } |
| 5377 | flags = _PyLong_AsInt(args[3]); |
| 5378 | if (flags == -1 && PyErr_Occurred()) { |
| 5379 | goto exit; |
| 5380 | } |
| 5381 | skip_optional: |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 5382 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
| 5383 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 5384 | goto exit; |
| 5385 | } |
| 5386 | return_value = PyLong_FromSsize_t(_return_value); |
| 5387 | |
| 5388 | exit: |
| 5389 | return return_value; |
| 5390 | } |
| 5391 | |
| 5392 | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
| 5393 | |
Pablo Galindo | aac4d03 | 2019-05-31 19:39:47 +0100 | [diff] [blame] | 5394 | #if defined(HAVE_COPY_FILE_RANGE) |
| 5395 | |
| 5396 | PyDoc_STRVAR(os_copy_file_range__doc__, |
| 5397 | "copy_file_range($module, /, src, dst, count, offset_src=None,\n" |
| 5398 | " offset_dst=None)\n" |
| 5399 | "--\n" |
| 5400 | "\n" |
| 5401 | "Copy count bytes from one file descriptor to another.\n" |
| 5402 | "\n" |
| 5403 | " src\n" |
| 5404 | " Source file descriptor.\n" |
| 5405 | " dst\n" |
| 5406 | " Destination file descriptor.\n" |
| 5407 | " count\n" |
| 5408 | " Number of bytes to copy.\n" |
| 5409 | " offset_src\n" |
| 5410 | " Starting offset in src.\n" |
| 5411 | " offset_dst\n" |
| 5412 | " Starting offset in dst.\n" |
| 5413 | "\n" |
| 5414 | "If offset_src is None, then src is read from the current position;\n" |
| 5415 | "respectively for offset_dst."); |
| 5416 | |
| 5417 | #define OS_COPY_FILE_RANGE_METHODDEF \ |
| 5418 | {"copy_file_range", (PyCFunction)(void(*)(void))os_copy_file_range, METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__}, |
| 5419 | |
| 5420 | static PyObject * |
| 5421 | os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
| 5422 | PyObject *offset_src, PyObject *offset_dst); |
| 5423 | |
| 5424 | static PyObject * |
| 5425 | os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 5426 | { |
| 5427 | PyObject *return_value = NULL; |
| 5428 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL}; |
| 5429 | static _PyArg_Parser _parser = {NULL, _keywords, "copy_file_range", 0}; |
| 5430 | PyObject *argsbuf[5]; |
| 5431 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
| 5432 | int src; |
| 5433 | int dst; |
| 5434 | Py_ssize_t count; |
| 5435 | PyObject *offset_src = Py_None; |
| 5436 | PyObject *offset_dst = Py_None; |
| 5437 | |
| 5438 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 5, 0, argsbuf); |
| 5439 | if (!args) { |
| 5440 | goto exit; |
| 5441 | } |
| 5442 | if (PyFloat_Check(args[0])) { |
| 5443 | PyErr_SetString(PyExc_TypeError, |
| 5444 | "integer argument expected, got float" ); |
| 5445 | goto exit; |
| 5446 | } |
| 5447 | src = _PyLong_AsInt(args[0]); |
| 5448 | if (src == -1 && PyErr_Occurred()) { |
| 5449 | goto exit; |
| 5450 | } |
| 5451 | if (PyFloat_Check(args[1])) { |
| 5452 | PyErr_SetString(PyExc_TypeError, |
| 5453 | "integer argument expected, got float" ); |
| 5454 | goto exit; |
| 5455 | } |
| 5456 | dst = _PyLong_AsInt(args[1]); |
| 5457 | if (dst == -1 && PyErr_Occurred()) { |
| 5458 | goto exit; |
| 5459 | } |
| 5460 | if (PyFloat_Check(args[2])) { |
| 5461 | PyErr_SetString(PyExc_TypeError, |
| 5462 | "integer argument expected, got float" ); |
| 5463 | goto exit; |
| 5464 | } |
| 5465 | { |
| 5466 | Py_ssize_t ival = -1; |
| 5467 | PyObject *iobj = PyNumber_Index(args[2]); |
| 5468 | if (iobj != NULL) { |
| 5469 | ival = PyLong_AsSsize_t(iobj); |
| 5470 | Py_DECREF(iobj); |
| 5471 | } |
| 5472 | if (ival == -1 && PyErr_Occurred()) { |
| 5473 | goto exit; |
| 5474 | } |
| 5475 | count = ival; |
| 5476 | } |
| 5477 | if (!noptargs) { |
| 5478 | goto skip_optional_pos; |
| 5479 | } |
| 5480 | if (args[3]) { |
| 5481 | offset_src = args[3]; |
| 5482 | if (!--noptargs) { |
| 5483 | goto skip_optional_pos; |
| 5484 | } |
| 5485 | } |
| 5486 | offset_dst = args[4]; |
| 5487 | skip_optional_pos: |
| 5488 | return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst); |
| 5489 | |
| 5490 | exit: |
| 5491 | return return_value; |
| 5492 | } |
| 5493 | |
| 5494 | #endif /* defined(HAVE_COPY_FILE_RANGE) */ |
| 5495 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5496 | #if defined(HAVE_MKFIFO) |
| 5497 | |
| 5498 | PyDoc_STRVAR(os_mkfifo__doc__, |
| 5499 | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
| 5500 | "--\n" |
| 5501 | "\n" |
| 5502 | "Create a \"fifo\" (a POSIX named pipe).\n" |
| 5503 | "\n" |
| 5504 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 5505 | " and path should be relative; path will then be relative to that directory.\n" |
| 5506 | "dir_fd may not be implemented on your platform.\n" |
| 5507 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 5508 | |
| 5509 | #define OS_MKFIFO_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5510 | {"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] | 5511 | |
| 5512 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5513 | 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] | 5514 | |
| 5515 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5516 | 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] | 5517 | { |
| 5518 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5519 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5520 | static _PyArg_Parser _parser = {NULL, _keywords, "mkfifo", 0}; |
| 5521 | PyObject *argsbuf[3]; |
| 5522 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5523 | path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0); |
| 5524 | int mode = 438; |
| 5525 | int dir_fd = DEFAULT_DIR_FD; |
| 5526 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5527 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 5528 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5529 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5530 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5531 | if (!path_converter(args[0], &path)) { |
| 5532 | goto exit; |
| 5533 | } |
| 5534 | if (!noptargs) { |
| 5535 | goto skip_optional_pos; |
| 5536 | } |
| 5537 | if (args[1]) { |
| 5538 | if (PyFloat_Check(args[1])) { |
| 5539 | PyErr_SetString(PyExc_TypeError, |
| 5540 | "integer argument expected, got float" ); |
| 5541 | goto exit; |
| 5542 | } |
| 5543 | mode = _PyLong_AsInt(args[1]); |
| 5544 | if (mode == -1 && PyErr_Occurred()) { |
| 5545 | goto exit; |
| 5546 | } |
| 5547 | if (!--noptargs) { |
| 5548 | goto skip_optional_pos; |
| 5549 | } |
| 5550 | } |
| 5551 | skip_optional_pos: |
| 5552 | if (!noptargs) { |
| 5553 | goto skip_optional_kwonly; |
| 5554 | } |
| 5555 | if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
| 5556 | goto exit; |
| 5557 | } |
| 5558 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5559 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
| 5560 | |
| 5561 | exit: |
| 5562 | /* Cleanup for path */ |
| 5563 | path_cleanup(&path); |
| 5564 | |
| 5565 | return return_value; |
| 5566 | } |
| 5567 | |
| 5568 | #endif /* defined(HAVE_MKFIFO) */ |
| 5569 | |
| 5570 | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
| 5571 | |
| 5572 | PyDoc_STRVAR(os_mknod__doc__, |
| 5573 | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
| 5574 | "--\n" |
| 5575 | "\n" |
| 5576 | "Create a node in the file system.\n" |
| 5577 | "\n" |
| 5578 | "Create a node in the file system (file, device special file or named pipe)\n" |
| 5579 | "at path. mode specifies both the permissions to use and the\n" |
| 5580 | "type of node to be created, being combined (bitwise OR) with one of\n" |
| 5581 | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
| 5582 | "device defines the newly created device special file (probably using\n" |
| 5583 | "os.makedev()). Otherwise device is ignored.\n" |
| 5584 | "\n" |
| 5585 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 5586 | " and path should be relative; path will then be relative to that directory.\n" |
| 5587 | "dir_fd may not be implemented on your platform.\n" |
| 5588 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 5589 | |
| 5590 | #define OS_MKNOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5591 | {"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] | 5592 | |
| 5593 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5594 | 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] | 5595 | int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5596 | |
| 5597 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5598 | 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] | 5599 | { |
| 5600 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5601 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5602 | static _PyArg_Parser _parser = {NULL, _keywords, "mknod", 0}; |
| 5603 | PyObject *argsbuf[4]; |
| 5604 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5605 | path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0); |
| 5606 | int mode = 384; |
| 5607 | dev_t device = 0; |
| 5608 | int dir_fd = DEFAULT_DIR_FD; |
| 5609 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5610 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); |
| 5611 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5612 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5613 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5614 | if (!path_converter(args[0], &path)) { |
| 5615 | goto exit; |
| 5616 | } |
| 5617 | if (!noptargs) { |
| 5618 | goto skip_optional_pos; |
| 5619 | } |
| 5620 | if (args[1]) { |
| 5621 | if (PyFloat_Check(args[1])) { |
| 5622 | PyErr_SetString(PyExc_TypeError, |
| 5623 | "integer argument expected, got float" ); |
| 5624 | goto exit; |
| 5625 | } |
| 5626 | mode = _PyLong_AsInt(args[1]); |
| 5627 | if (mode == -1 && PyErr_Occurred()) { |
| 5628 | goto exit; |
| 5629 | } |
| 5630 | if (!--noptargs) { |
| 5631 | goto skip_optional_pos; |
| 5632 | } |
| 5633 | } |
| 5634 | if (args[2]) { |
| 5635 | if (!_Py_Dev_Converter(args[2], &device)) { |
| 5636 | goto exit; |
| 5637 | } |
| 5638 | if (!--noptargs) { |
| 5639 | goto skip_optional_pos; |
| 5640 | } |
| 5641 | } |
| 5642 | skip_optional_pos: |
| 5643 | if (!noptargs) { |
| 5644 | goto skip_optional_kwonly; |
| 5645 | } |
| 5646 | if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
| 5647 | goto exit; |
| 5648 | } |
| 5649 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5650 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
| 5651 | |
| 5652 | exit: |
| 5653 | /* Cleanup for path */ |
| 5654 | path_cleanup(&path); |
| 5655 | |
| 5656 | return return_value; |
| 5657 | } |
| 5658 | |
| 5659 | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
| 5660 | |
| 5661 | #if defined(HAVE_DEVICE_MACROS) |
| 5662 | |
| 5663 | PyDoc_STRVAR(os_major__doc__, |
| 5664 | "major($module, device, /)\n" |
| 5665 | "--\n" |
| 5666 | "\n" |
| 5667 | "Extracts a device major number from a raw device number."); |
| 5668 | |
| 5669 | #define OS_MAJOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5670 | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5671 | |
| 5672 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5673 | os_major_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5674 | |
| 5675 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5676 | os_major(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5677 | { |
| 5678 | PyObject *return_value = NULL; |
| 5679 | dev_t device; |
| 5680 | unsigned int _return_value; |
| 5681 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5682 | if (!_Py_Dev_Converter(arg, &device)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5683 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5684 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5685 | _return_value = os_major_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5686 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5687 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5688 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5689 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 5690 | |
| 5691 | exit: |
| 5692 | return return_value; |
| 5693 | } |
| 5694 | |
| 5695 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 5696 | |
| 5697 | #if defined(HAVE_DEVICE_MACROS) |
| 5698 | |
| 5699 | PyDoc_STRVAR(os_minor__doc__, |
| 5700 | "minor($module, device, /)\n" |
| 5701 | "--\n" |
| 5702 | "\n" |
| 5703 | "Extracts a device minor number from a raw device number."); |
| 5704 | |
| 5705 | #define OS_MINOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5706 | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5707 | |
| 5708 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5709 | os_minor_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5710 | |
| 5711 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5712 | os_minor(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5713 | { |
| 5714 | PyObject *return_value = NULL; |
| 5715 | dev_t device; |
| 5716 | unsigned int _return_value; |
| 5717 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5718 | if (!_Py_Dev_Converter(arg, &device)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5719 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5720 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5721 | _return_value = os_minor_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5722 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5723 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5724 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5725 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 5726 | |
| 5727 | exit: |
| 5728 | return return_value; |
| 5729 | } |
| 5730 | |
| 5731 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 5732 | |
| 5733 | #if defined(HAVE_DEVICE_MACROS) |
| 5734 | |
| 5735 | PyDoc_STRVAR(os_makedev__doc__, |
| 5736 | "makedev($module, major, minor, /)\n" |
| 5737 | "--\n" |
| 5738 | "\n" |
| 5739 | "Composes a raw device number from the major and minor device numbers."); |
| 5740 | |
| 5741 | #define OS_MAKEDEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5742 | {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5743 | |
| 5744 | static dev_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5745 | os_makedev_impl(PyObject *module, int major, int minor); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5746 | |
| 5747 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5748 | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5749 | { |
| 5750 | PyObject *return_value = NULL; |
| 5751 | int major; |
| 5752 | int minor; |
| 5753 | dev_t _return_value; |
| 5754 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5755 | if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { |
| 5756 | goto exit; |
| 5757 | } |
| 5758 | if (PyFloat_Check(args[0])) { |
| 5759 | PyErr_SetString(PyExc_TypeError, |
| 5760 | "integer argument expected, got float" ); |
| 5761 | goto exit; |
| 5762 | } |
| 5763 | major = _PyLong_AsInt(args[0]); |
| 5764 | if (major == -1 && PyErr_Occurred()) { |
| 5765 | goto exit; |
| 5766 | } |
| 5767 | if (PyFloat_Check(args[1])) { |
| 5768 | PyErr_SetString(PyExc_TypeError, |
| 5769 | "integer argument expected, got float" ); |
| 5770 | goto exit; |
| 5771 | } |
| 5772 | minor = _PyLong_AsInt(args[1]); |
| 5773 | if (minor == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5774 | goto exit; |
| 5775 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5776 | _return_value = os_makedev_impl(module, major, minor); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5777 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5778 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5779 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5780 | return_value = _PyLong_FromDev(_return_value); |
| 5781 | |
| 5782 | exit: |
| 5783 | return return_value; |
| 5784 | } |
| 5785 | |
| 5786 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 5787 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 5788 | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5789 | |
| 5790 | PyDoc_STRVAR(os_ftruncate__doc__, |
| 5791 | "ftruncate($module, fd, length, /)\n" |
| 5792 | "--\n" |
| 5793 | "\n" |
| 5794 | "Truncate a file, specified by file descriptor, to a specific length."); |
| 5795 | |
| 5796 | #define OS_FTRUNCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5797 | {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__}, |
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_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5801 | |
| 5802 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5803 | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5804 | { |
| 5805 | PyObject *return_value = NULL; |
| 5806 | int fd; |
| 5807 | Py_off_t length; |
| 5808 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5809 | if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { |
| 5810 | goto exit; |
| 5811 | } |
| 5812 | if (PyFloat_Check(args[0])) { |
| 5813 | PyErr_SetString(PyExc_TypeError, |
| 5814 | "integer argument expected, got float" ); |
| 5815 | goto exit; |
| 5816 | } |
| 5817 | fd = _PyLong_AsInt(args[0]); |
| 5818 | if (fd == -1 && PyErr_Occurred()) { |
| 5819 | goto exit; |
| 5820 | } |
| 5821 | if (!Py_off_t_converter(args[1], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5822 | goto exit; |
| 5823 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5824 | return_value = os_ftruncate_impl(module, fd, length); |
| 5825 | |
| 5826 | exit: |
| 5827 | return return_value; |
| 5828 | } |
| 5829 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 5830 | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5831 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 5832 | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5833 | |
| 5834 | PyDoc_STRVAR(os_truncate__doc__, |
| 5835 | "truncate($module, /, path, length)\n" |
| 5836 | "--\n" |
| 5837 | "\n" |
| 5838 | "Truncate a file, specified by path, to a specific length.\n" |
| 5839 | "\n" |
| 5840 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 5841 | " If this functionality is unavailable, using it raises an exception."); |
| 5842 | |
| 5843 | #define OS_TRUNCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5844 | {"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] | 5845 | |
| 5846 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5847 | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5848 | |
| 5849 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5850 | 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] | 5851 | { |
| 5852 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5853 | static const char * const _keywords[] = {"path", "length", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5854 | static _PyArg_Parser _parser = {NULL, _keywords, "truncate", 0}; |
| 5855 | PyObject *argsbuf[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5856 | path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE); |
| 5857 | Py_off_t length; |
| 5858 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5859 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 5860 | if (!args) { |
| 5861 | goto exit; |
| 5862 | } |
| 5863 | if (!path_converter(args[0], &path)) { |
| 5864 | goto exit; |
| 5865 | } |
| 5866 | if (!Py_off_t_converter(args[1], &length)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5867 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5868 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5869 | return_value = os_truncate_impl(module, &path, length); |
| 5870 | |
| 5871 | exit: |
| 5872 | /* Cleanup for path */ |
| 5873 | path_cleanup(&path); |
| 5874 | |
| 5875 | return return_value; |
| 5876 | } |
| 5877 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 5878 | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5879 | |
| 5880 | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 5881 | |
| 5882 | PyDoc_STRVAR(os_posix_fallocate__doc__, |
| 5883 | "posix_fallocate($module, fd, offset, length, /)\n" |
| 5884 | "--\n" |
| 5885 | "\n" |
| 5886 | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
| 5887 | "\n" |
| 5888 | "Ensure that the file specified by fd encompasses a range of bytes\n" |
| 5889 | "starting at offset bytes from the beginning and continuing for length bytes."); |
| 5890 | |
| 5891 | #define OS_POSIX_FALLOCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5892 | {"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] | 5893 | |
| 5894 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5895 | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 5896 | Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5897 | |
| 5898 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5899 | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5900 | { |
| 5901 | PyObject *return_value = NULL; |
| 5902 | int fd; |
| 5903 | Py_off_t offset; |
| 5904 | Py_off_t length; |
| 5905 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5906 | if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { |
| 5907 | goto exit; |
| 5908 | } |
| 5909 | if (PyFloat_Check(args[0])) { |
| 5910 | PyErr_SetString(PyExc_TypeError, |
| 5911 | "integer argument expected, got float" ); |
| 5912 | goto exit; |
| 5913 | } |
| 5914 | fd = _PyLong_AsInt(args[0]); |
| 5915 | if (fd == -1 && PyErr_Occurred()) { |
| 5916 | goto exit; |
| 5917 | } |
| 5918 | if (!Py_off_t_converter(args[1], &offset)) { |
| 5919 | goto exit; |
| 5920 | } |
| 5921 | if (!Py_off_t_converter(args[2], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5922 | goto exit; |
| 5923 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5924 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
| 5925 | |
| 5926 | exit: |
| 5927 | return return_value; |
| 5928 | } |
| 5929 | |
| 5930 | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 5931 | |
| 5932 | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 5933 | |
| 5934 | PyDoc_STRVAR(os_posix_fadvise__doc__, |
| 5935 | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
| 5936 | "--\n" |
| 5937 | "\n" |
| 5938 | "Announce an intention to access data in a specific pattern.\n" |
| 5939 | "\n" |
| 5940 | "Announce an intention to access data in a specific pattern, thus allowing\n" |
| 5941 | "the kernel to make optimizations.\n" |
| 5942 | "The advice applies to the region of the file specified by fd starting at\n" |
| 5943 | "offset and continuing for length bytes.\n" |
| 5944 | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
| 5945 | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
| 5946 | "POSIX_FADV_DONTNEED."); |
| 5947 | |
| 5948 | #define OS_POSIX_FADVISE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5949 | {"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] | 5950 | |
| 5951 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5952 | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 5953 | Py_off_t length, int advice); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5954 | |
| 5955 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5956 | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5957 | { |
| 5958 | PyObject *return_value = NULL; |
| 5959 | int fd; |
| 5960 | Py_off_t offset; |
| 5961 | Py_off_t length; |
| 5962 | int advice; |
| 5963 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5964 | if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { |
| 5965 | goto exit; |
| 5966 | } |
| 5967 | if (PyFloat_Check(args[0])) { |
| 5968 | PyErr_SetString(PyExc_TypeError, |
| 5969 | "integer argument expected, got float" ); |
| 5970 | goto exit; |
| 5971 | } |
| 5972 | fd = _PyLong_AsInt(args[0]); |
| 5973 | if (fd == -1 && PyErr_Occurred()) { |
| 5974 | goto exit; |
| 5975 | } |
| 5976 | if (!Py_off_t_converter(args[1], &offset)) { |
| 5977 | goto exit; |
| 5978 | } |
| 5979 | if (!Py_off_t_converter(args[2], &length)) { |
| 5980 | goto exit; |
| 5981 | } |
| 5982 | if (PyFloat_Check(args[3])) { |
| 5983 | PyErr_SetString(PyExc_TypeError, |
| 5984 | "integer argument expected, got float" ); |
| 5985 | goto exit; |
| 5986 | } |
| 5987 | advice = _PyLong_AsInt(args[3]); |
| 5988 | if (advice == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5989 | goto exit; |
| 5990 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5991 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
| 5992 | |
| 5993 | exit: |
| 5994 | return return_value; |
| 5995 | } |
| 5996 | |
| 5997 | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 5998 | |
| 5999 | #if defined(HAVE_PUTENV) && defined(MS_WINDOWS) |
| 6000 | |
| 6001 | PyDoc_STRVAR(os_putenv__doc__, |
| 6002 | "putenv($module, name, value, /)\n" |
| 6003 | "--\n" |
| 6004 | "\n" |
| 6005 | "Change or add an environment variable."); |
| 6006 | |
| 6007 | #define OS_PUTENV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6008 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6009 | |
| 6010 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6011 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6012 | |
| 6013 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6014 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6015 | { |
| 6016 | PyObject *return_value = NULL; |
| 6017 | PyObject *name; |
| 6018 | PyObject *value; |
| 6019 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6020 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6021 | goto exit; |
| 6022 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6023 | if (!PyUnicode_Check(args[0])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 6024 | _PyArg_BadArgument("putenv", "argument 1", "str", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6025 | goto exit; |
| 6026 | } |
| 6027 | if (PyUnicode_READY(args[0]) == -1) { |
| 6028 | goto exit; |
| 6029 | } |
| 6030 | name = args[0]; |
| 6031 | if (!PyUnicode_Check(args[1])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 6032 | _PyArg_BadArgument("putenv", "argument 2", "str", args[1]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6033 | goto exit; |
| 6034 | } |
| 6035 | if (PyUnicode_READY(args[1]) == -1) { |
| 6036 | goto exit; |
| 6037 | } |
| 6038 | value = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6039 | return_value = os_putenv_impl(module, name, value); |
| 6040 | |
| 6041 | exit: |
| 6042 | return return_value; |
| 6043 | } |
| 6044 | |
| 6045 | #endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */ |
| 6046 | |
| 6047 | #if defined(HAVE_PUTENV) && !defined(MS_WINDOWS) |
| 6048 | |
| 6049 | PyDoc_STRVAR(os_putenv__doc__, |
| 6050 | "putenv($module, name, value, /)\n" |
| 6051 | "--\n" |
| 6052 | "\n" |
| 6053 | "Change or add an environment variable."); |
| 6054 | |
| 6055 | #define OS_PUTENV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6056 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6057 | |
| 6058 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6059 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6060 | |
| 6061 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6062 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6063 | { |
| 6064 | PyObject *return_value = NULL; |
| 6065 | PyObject *name = NULL; |
| 6066 | PyObject *value = NULL; |
| 6067 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6068 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
| 6069 | goto exit; |
| 6070 | } |
| 6071 | if (!PyUnicode_FSConverter(args[0], &name)) { |
| 6072 | goto exit; |
| 6073 | } |
| 6074 | if (!PyUnicode_FSConverter(args[1], &value)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6075 | goto exit; |
| 6076 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6077 | return_value = os_putenv_impl(module, name, value); |
| 6078 | |
| 6079 | exit: |
| 6080 | /* Cleanup for name */ |
| 6081 | Py_XDECREF(name); |
| 6082 | /* Cleanup for value */ |
| 6083 | Py_XDECREF(value); |
| 6084 | |
| 6085 | return return_value; |
| 6086 | } |
| 6087 | |
| 6088 | #endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */ |
| 6089 | |
| 6090 | #if defined(HAVE_UNSETENV) |
| 6091 | |
| 6092 | PyDoc_STRVAR(os_unsetenv__doc__, |
| 6093 | "unsetenv($module, name, /)\n" |
| 6094 | "--\n" |
| 6095 | "\n" |
| 6096 | "Delete an environment variable."); |
| 6097 | |
| 6098 | #define OS_UNSETENV_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6099 | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6100 | |
| 6101 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6102 | os_unsetenv_impl(PyObject *module, PyObject *name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6103 | |
| 6104 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6105 | os_unsetenv(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6106 | { |
| 6107 | PyObject *return_value = NULL; |
| 6108 | PyObject *name = NULL; |
| 6109 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6110 | if (!PyUnicode_FSConverter(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6111 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6112 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6113 | return_value = os_unsetenv_impl(module, name); |
| 6114 | |
| 6115 | exit: |
| 6116 | /* Cleanup for name */ |
| 6117 | Py_XDECREF(name); |
| 6118 | |
| 6119 | return return_value; |
| 6120 | } |
| 6121 | |
| 6122 | #endif /* defined(HAVE_UNSETENV) */ |
| 6123 | |
| 6124 | PyDoc_STRVAR(os_strerror__doc__, |
| 6125 | "strerror($module, code, /)\n" |
| 6126 | "--\n" |
| 6127 | "\n" |
| 6128 | "Translate an error code to a message string."); |
| 6129 | |
| 6130 | #define OS_STRERROR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6131 | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__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_strerror_impl(PyObject *module, int code); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6135 | |
| 6136 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6137 | os_strerror(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6138 | { |
| 6139 | PyObject *return_value = NULL; |
| 6140 | int code; |
| 6141 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6142 | if (PyFloat_Check(arg)) { |
| 6143 | PyErr_SetString(PyExc_TypeError, |
| 6144 | "integer argument expected, got float" ); |
| 6145 | goto exit; |
| 6146 | } |
| 6147 | code = _PyLong_AsInt(arg); |
| 6148 | if (code == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6149 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6150 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6151 | return_value = os_strerror_impl(module, code); |
| 6152 | |
| 6153 | exit: |
| 6154 | return return_value; |
| 6155 | } |
| 6156 | |
| 6157 | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
| 6158 | |
| 6159 | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
| 6160 | "WCOREDUMP($module, status, /)\n" |
| 6161 | "--\n" |
| 6162 | "\n" |
| 6163 | "Return True if the process returning status was dumped to a core file."); |
| 6164 | |
| 6165 | #define OS_WCOREDUMP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6166 | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6167 | |
| 6168 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6169 | os_WCOREDUMP_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6170 | |
| 6171 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6172 | os_WCOREDUMP(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6173 | { |
| 6174 | PyObject *return_value = NULL; |
| 6175 | int status; |
| 6176 | int _return_value; |
| 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" ); |
| 6181 | goto exit; |
| 6182 | } |
| 6183 | status = _PyLong_AsInt(arg); |
| 6184 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6185 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6186 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6187 | _return_value = os_WCOREDUMP_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6188 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6189 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6190 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6191 | return_value = PyBool_FromLong((long)_return_value); |
| 6192 | |
| 6193 | exit: |
| 6194 | return return_value; |
| 6195 | } |
| 6196 | |
| 6197 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
| 6198 | |
| 6199 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
| 6200 | |
| 6201 | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
| 6202 | "WIFCONTINUED($module, /, status)\n" |
| 6203 | "--\n" |
| 6204 | "\n" |
| 6205 | "Return True if a particular process was continued from a job control stop.\n" |
| 6206 | "\n" |
| 6207 | "Return True if the process returning status was continued from a\n" |
| 6208 | "job control stop."); |
| 6209 | |
| 6210 | #define OS_WIFCONTINUED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6211 | {"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] | 6212 | |
| 6213 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6214 | os_WIFCONTINUED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6215 | |
| 6216 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6217 | 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] | 6218 | { |
| 6219 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6220 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6221 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFCONTINUED", 0}; |
| 6222 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6223 | int status; |
| 6224 | int _return_value; |
| 6225 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6226 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6227 | if (!args) { |
| 6228 | goto exit; |
| 6229 | } |
| 6230 | if (PyFloat_Check(args[0])) { |
| 6231 | PyErr_SetString(PyExc_TypeError, |
| 6232 | "integer argument expected, got float" ); |
| 6233 | goto exit; |
| 6234 | } |
| 6235 | status = _PyLong_AsInt(args[0]); |
| 6236 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6237 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6238 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6239 | _return_value = os_WIFCONTINUED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6240 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6241 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6242 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6243 | return_value = PyBool_FromLong((long)_return_value); |
| 6244 | |
| 6245 | exit: |
| 6246 | return return_value; |
| 6247 | } |
| 6248 | |
| 6249 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
| 6250 | |
| 6251 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
| 6252 | |
| 6253 | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
| 6254 | "WIFSTOPPED($module, /, status)\n" |
| 6255 | "--\n" |
| 6256 | "\n" |
| 6257 | "Return True if the process returning status was stopped."); |
| 6258 | |
| 6259 | #define OS_WIFSTOPPED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6260 | {"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] | 6261 | |
| 6262 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6263 | os_WIFSTOPPED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6264 | |
| 6265 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6266 | 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] | 6267 | { |
| 6268 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6269 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6270 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFSTOPPED", 0}; |
| 6271 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6272 | int status; |
| 6273 | int _return_value; |
| 6274 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6275 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6276 | if (!args) { |
| 6277 | goto exit; |
| 6278 | } |
| 6279 | if (PyFloat_Check(args[0])) { |
| 6280 | PyErr_SetString(PyExc_TypeError, |
| 6281 | "integer argument expected, got float" ); |
| 6282 | goto exit; |
| 6283 | } |
| 6284 | status = _PyLong_AsInt(args[0]); |
| 6285 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6286 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6287 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6288 | _return_value = os_WIFSTOPPED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6289 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6290 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6291 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6292 | return_value = PyBool_FromLong((long)_return_value); |
| 6293 | |
| 6294 | exit: |
| 6295 | return return_value; |
| 6296 | } |
| 6297 | |
| 6298 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
| 6299 | |
| 6300 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
| 6301 | |
| 6302 | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
| 6303 | "WIFSIGNALED($module, /, status)\n" |
| 6304 | "--\n" |
| 6305 | "\n" |
| 6306 | "Return True if the process returning status was terminated by a signal."); |
| 6307 | |
| 6308 | #define OS_WIFSIGNALED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6309 | {"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] | 6310 | |
| 6311 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6312 | os_WIFSIGNALED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6313 | |
| 6314 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6315 | 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] | 6316 | { |
| 6317 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6318 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6319 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFSIGNALED", 0}; |
| 6320 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6321 | int status; |
| 6322 | int _return_value; |
| 6323 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6324 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6325 | if (!args) { |
| 6326 | goto exit; |
| 6327 | } |
| 6328 | if (PyFloat_Check(args[0])) { |
| 6329 | PyErr_SetString(PyExc_TypeError, |
| 6330 | "integer argument expected, got float" ); |
| 6331 | goto exit; |
| 6332 | } |
| 6333 | status = _PyLong_AsInt(args[0]); |
| 6334 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6335 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6336 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6337 | _return_value = os_WIFSIGNALED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6338 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6339 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6340 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6341 | return_value = PyBool_FromLong((long)_return_value); |
| 6342 | |
| 6343 | exit: |
| 6344 | return return_value; |
| 6345 | } |
| 6346 | |
| 6347 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
| 6348 | |
| 6349 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
| 6350 | |
| 6351 | PyDoc_STRVAR(os_WIFEXITED__doc__, |
| 6352 | "WIFEXITED($module, /, status)\n" |
| 6353 | "--\n" |
| 6354 | "\n" |
| 6355 | "Return True if the process returning status exited via the exit() system call."); |
| 6356 | |
| 6357 | #define OS_WIFEXITED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6358 | {"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] | 6359 | |
| 6360 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6361 | os_WIFEXITED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6362 | |
| 6363 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6364 | 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] | 6365 | { |
| 6366 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6367 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6368 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFEXITED", 0}; |
| 6369 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6370 | int status; |
| 6371 | int _return_value; |
| 6372 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6373 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6374 | if (!args) { |
| 6375 | goto exit; |
| 6376 | } |
| 6377 | if (PyFloat_Check(args[0])) { |
| 6378 | PyErr_SetString(PyExc_TypeError, |
| 6379 | "integer argument expected, got float" ); |
| 6380 | goto exit; |
| 6381 | } |
| 6382 | status = _PyLong_AsInt(args[0]); |
| 6383 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6384 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6385 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6386 | _return_value = os_WIFEXITED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6387 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6388 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6389 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6390 | return_value = PyBool_FromLong((long)_return_value); |
| 6391 | |
| 6392 | exit: |
| 6393 | return return_value; |
| 6394 | } |
| 6395 | |
| 6396 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
| 6397 | |
| 6398 | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
| 6399 | |
| 6400 | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
| 6401 | "WEXITSTATUS($module, /, status)\n" |
| 6402 | "--\n" |
| 6403 | "\n" |
| 6404 | "Return the process return code from status."); |
| 6405 | |
| 6406 | #define OS_WEXITSTATUS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6407 | {"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] | 6408 | |
| 6409 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6410 | os_WEXITSTATUS_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6411 | |
| 6412 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6413 | 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] | 6414 | { |
| 6415 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6416 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6417 | static _PyArg_Parser _parser = {NULL, _keywords, "WEXITSTATUS", 0}; |
| 6418 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6419 | int status; |
| 6420 | int _return_value; |
| 6421 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6422 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6423 | if (!args) { |
| 6424 | goto exit; |
| 6425 | } |
| 6426 | if (PyFloat_Check(args[0])) { |
| 6427 | PyErr_SetString(PyExc_TypeError, |
| 6428 | "integer argument expected, got float" ); |
| 6429 | goto exit; |
| 6430 | } |
| 6431 | status = _PyLong_AsInt(args[0]); |
| 6432 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6433 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6434 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6435 | _return_value = os_WEXITSTATUS_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6436 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6437 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6438 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6439 | return_value = PyLong_FromLong((long)_return_value); |
| 6440 | |
| 6441 | exit: |
| 6442 | return return_value; |
| 6443 | } |
| 6444 | |
| 6445 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
| 6446 | |
| 6447 | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
| 6448 | |
| 6449 | PyDoc_STRVAR(os_WTERMSIG__doc__, |
| 6450 | "WTERMSIG($module, /, status)\n" |
| 6451 | "--\n" |
| 6452 | "\n" |
| 6453 | "Return the signal that terminated the process that provided the status value."); |
| 6454 | |
| 6455 | #define OS_WTERMSIG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6456 | {"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] | 6457 | |
| 6458 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6459 | os_WTERMSIG_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6460 | |
| 6461 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6462 | 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] | 6463 | { |
| 6464 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6465 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6466 | static _PyArg_Parser _parser = {NULL, _keywords, "WTERMSIG", 0}; |
| 6467 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6468 | int status; |
| 6469 | int _return_value; |
| 6470 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6471 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6472 | if (!args) { |
| 6473 | goto exit; |
| 6474 | } |
| 6475 | if (PyFloat_Check(args[0])) { |
| 6476 | PyErr_SetString(PyExc_TypeError, |
| 6477 | "integer argument expected, got float" ); |
| 6478 | goto exit; |
| 6479 | } |
| 6480 | status = _PyLong_AsInt(args[0]); |
| 6481 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6482 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6483 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6484 | _return_value = os_WTERMSIG_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6485 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6486 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6487 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6488 | return_value = PyLong_FromLong((long)_return_value); |
| 6489 | |
| 6490 | exit: |
| 6491 | return return_value; |
| 6492 | } |
| 6493 | |
| 6494 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
| 6495 | |
| 6496 | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
| 6497 | |
| 6498 | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
| 6499 | "WSTOPSIG($module, /, status)\n" |
| 6500 | "--\n" |
| 6501 | "\n" |
| 6502 | "Return the signal that stopped the process that provided the status value."); |
| 6503 | |
| 6504 | #define OS_WSTOPSIG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6505 | {"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] | 6506 | |
| 6507 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6508 | os_WSTOPSIG_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6509 | |
| 6510 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6511 | 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] | 6512 | { |
| 6513 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6514 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6515 | static _PyArg_Parser _parser = {NULL, _keywords, "WSTOPSIG", 0}; |
| 6516 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6517 | int status; |
| 6518 | int _return_value; |
| 6519 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6520 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6521 | if (!args) { |
| 6522 | goto exit; |
| 6523 | } |
| 6524 | if (PyFloat_Check(args[0])) { |
| 6525 | PyErr_SetString(PyExc_TypeError, |
| 6526 | "integer argument expected, got float" ); |
| 6527 | goto exit; |
| 6528 | } |
| 6529 | status = _PyLong_AsInt(args[0]); |
| 6530 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6531 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6532 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6533 | _return_value = os_WSTOPSIG_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6534 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6535 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6536 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6537 | return_value = PyLong_FromLong((long)_return_value); |
| 6538 | |
| 6539 | exit: |
| 6540 | return return_value; |
| 6541 | } |
| 6542 | |
| 6543 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
| 6544 | |
| 6545 | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 6546 | |
| 6547 | PyDoc_STRVAR(os_fstatvfs__doc__, |
| 6548 | "fstatvfs($module, fd, /)\n" |
| 6549 | "--\n" |
| 6550 | "\n" |
| 6551 | "Perform an fstatvfs system call on the given fd.\n" |
| 6552 | "\n" |
| 6553 | "Equivalent to statvfs(fd)."); |
| 6554 | |
| 6555 | #define OS_FSTATVFS_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6556 | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6557 | |
| 6558 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6559 | os_fstatvfs_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6560 | |
| 6561 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6562 | os_fstatvfs(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6563 | { |
| 6564 | PyObject *return_value = NULL; |
| 6565 | int fd; |
| 6566 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6567 | if (PyFloat_Check(arg)) { |
| 6568 | PyErr_SetString(PyExc_TypeError, |
| 6569 | "integer argument expected, got float" ); |
| 6570 | goto exit; |
| 6571 | } |
| 6572 | fd = _PyLong_AsInt(arg); |
| 6573 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6574 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6575 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6576 | return_value = os_fstatvfs_impl(module, fd); |
| 6577 | |
| 6578 | exit: |
| 6579 | return return_value; |
| 6580 | } |
| 6581 | |
| 6582 | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 6583 | |
| 6584 | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 6585 | |
| 6586 | PyDoc_STRVAR(os_statvfs__doc__, |
| 6587 | "statvfs($module, /, path)\n" |
| 6588 | "--\n" |
| 6589 | "\n" |
| 6590 | "Perform a statvfs system call on the given path.\n" |
| 6591 | "\n" |
| 6592 | "path may always be specified as a string.\n" |
| 6593 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 6594 | " If this functionality is unavailable, using it raises an exception."); |
| 6595 | |
| 6596 | #define OS_STATVFS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6597 | {"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] | 6598 | |
| 6599 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6600 | os_statvfs_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6601 | |
| 6602 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6603 | 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] | 6604 | { |
| 6605 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6606 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6607 | static _PyArg_Parser _parser = {NULL, _keywords, "statvfs", 0}; |
| 6608 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6609 | path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS); |
| 6610 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6611 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6612 | if (!args) { |
| 6613 | goto exit; |
| 6614 | } |
| 6615 | if (!path_converter(args[0], &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6616 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6617 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6618 | return_value = os_statvfs_impl(module, &path); |
| 6619 | |
| 6620 | exit: |
| 6621 | /* Cleanup for path */ |
| 6622 | path_cleanup(&path); |
| 6623 | |
| 6624 | return return_value; |
| 6625 | } |
| 6626 | |
| 6627 | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 6628 | |
| 6629 | #if defined(MS_WINDOWS) |
| 6630 | |
| 6631 | PyDoc_STRVAR(os__getdiskusage__doc__, |
| 6632 | "_getdiskusage($module, /, path)\n" |
| 6633 | "--\n" |
| 6634 | "\n" |
| 6635 | "Return disk usage statistics about the given path as a (total, free) tuple."); |
| 6636 | |
| 6637 | #define OS__GETDISKUSAGE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6638 | {"_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] | 6639 | |
| 6640 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 6641 | os__getdiskusage_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6642 | |
| 6643 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6644 | 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] | 6645 | { |
| 6646 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6647 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6648 | static _PyArg_Parser _parser = {NULL, _keywords, "_getdiskusage", 0}; |
| 6649 | PyObject *argsbuf[1]; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 6650 | path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6651 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6652 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6653 | if (!args) { |
| 6654 | goto exit; |
| 6655 | } |
| 6656 | if (!path_converter(args[0], &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6657 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6658 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 6659 | return_value = os__getdiskusage_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6660 | |
| 6661 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 6662 | /* Cleanup for path */ |
| 6663 | path_cleanup(&path); |
| 6664 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6665 | return return_value; |
| 6666 | } |
| 6667 | |
| 6668 | #endif /* defined(MS_WINDOWS) */ |
| 6669 | |
| 6670 | #if defined(HAVE_FPATHCONF) |
| 6671 | |
| 6672 | PyDoc_STRVAR(os_fpathconf__doc__, |
| 6673 | "fpathconf($module, fd, name, /)\n" |
| 6674 | "--\n" |
| 6675 | "\n" |
| 6676 | "Return the configuration limit name for the file descriptor fd.\n" |
| 6677 | "\n" |
| 6678 | "If there is no limit, return -1."); |
| 6679 | |
| 6680 | #define OS_FPATHCONF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6681 | {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6682 | |
| 6683 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6684 | os_fpathconf_impl(PyObject *module, int fd, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6685 | |
| 6686 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6687 | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6688 | { |
| 6689 | PyObject *return_value = NULL; |
| 6690 | int fd; |
| 6691 | int name; |
| 6692 | long _return_value; |
| 6693 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6694 | if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { |
| 6695 | goto exit; |
| 6696 | } |
| 6697 | if (PyFloat_Check(args[0])) { |
| 6698 | PyErr_SetString(PyExc_TypeError, |
| 6699 | "integer argument expected, got float" ); |
| 6700 | goto exit; |
| 6701 | } |
| 6702 | fd = _PyLong_AsInt(args[0]); |
| 6703 | if (fd == -1 && PyErr_Occurred()) { |
| 6704 | goto exit; |
| 6705 | } |
| 6706 | if (!conv_path_confname(args[1], &name)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6707 | goto exit; |
| 6708 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6709 | _return_value = os_fpathconf_impl(module, fd, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6710 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6711 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6712 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6713 | return_value = PyLong_FromLong(_return_value); |
| 6714 | |
| 6715 | exit: |
| 6716 | return return_value; |
| 6717 | } |
| 6718 | |
| 6719 | #endif /* defined(HAVE_FPATHCONF) */ |
| 6720 | |
| 6721 | #if defined(HAVE_PATHCONF) |
| 6722 | |
| 6723 | PyDoc_STRVAR(os_pathconf__doc__, |
| 6724 | "pathconf($module, /, path, name)\n" |
| 6725 | "--\n" |
| 6726 | "\n" |
| 6727 | "Return the configuration limit name for the file or directory path.\n" |
| 6728 | "\n" |
| 6729 | "If there is no limit, return -1.\n" |
| 6730 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 6731 | " If this functionality is unavailable, using it raises an exception."); |
| 6732 | |
| 6733 | #define OS_PATHCONF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6734 | {"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] | 6735 | |
| 6736 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6737 | os_pathconf_impl(PyObject *module, path_t *path, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6738 | |
| 6739 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6740 | 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] | 6741 | { |
| 6742 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6743 | static const char * const _keywords[] = {"path", "name", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6744 | static _PyArg_Parser _parser = {NULL, _keywords, "pathconf", 0}; |
| 6745 | PyObject *argsbuf[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6746 | path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF); |
| 6747 | int name; |
| 6748 | long _return_value; |
| 6749 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6750 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 6751 | if (!args) { |
| 6752 | goto exit; |
| 6753 | } |
| 6754 | if (!path_converter(args[0], &path)) { |
| 6755 | goto exit; |
| 6756 | } |
| 6757 | if (!conv_path_confname(args[1], &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6758 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6759 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6760 | _return_value = os_pathconf_impl(module, &path, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6761 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6762 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6763 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6764 | return_value = PyLong_FromLong(_return_value); |
| 6765 | |
| 6766 | exit: |
| 6767 | /* Cleanup for path */ |
| 6768 | path_cleanup(&path); |
| 6769 | |
| 6770 | return return_value; |
| 6771 | } |
| 6772 | |
| 6773 | #endif /* defined(HAVE_PATHCONF) */ |
| 6774 | |
| 6775 | #if defined(HAVE_CONFSTR) |
| 6776 | |
| 6777 | PyDoc_STRVAR(os_confstr__doc__, |
| 6778 | "confstr($module, name, /)\n" |
| 6779 | "--\n" |
| 6780 | "\n" |
| 6781 | "Return a string-valued system configuration variable."); |
| 6782 | |
| 6783 | #define OS_CONFSTR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6784 | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6785 | |
| 6786 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6787 | os_confstr_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6788 | |
| 6789 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6790 | os_confstr(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6791 | { |
| 6792 | PyObject *return_value = NULL; |
| 6793 | int name; |
| 6794 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6795 | if (!conv_confstr_confname(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6796 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6797 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6798 | return_value = os_confstr_impl(module, name); |
| 6799 | |
| 6800 | exit: |
| 6801 | return return_value; |
| 6802 | } |
| 6803 | |
| 6804 | #endif /* defined(HAVE_CONFSTR) */ |
| 6805 | |
| 6806 | #if defined(HAVE_SYSCONF) |
| 6807 | |
| 6808 | PyDoc_STRVAR(os_sysconf__doc__, |
| 6809 | "sysconf($module, name, /)\n" |
| 6810 | "--\n" |
| 6811 | "\n" |
| 6812 | "Return an integer-valued system configuration variable."); |
| 6813 | |
| 6814 | #define OS_SYSCONF_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6815 | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6816 | |
| 6817 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6818 | os_sysconf_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6819 | |
| 6820 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6821 | os_sysconf(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6822 | { |
| 6823 | PyObject *return_value = NULL; |
| 6824 | int name; |
| 6825 | long _return_value; |
| 6826 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6827 | if (!conv_sysconf_confname(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6828 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6829 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6830 | _return_value = os_sysconf_impl(module, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6831 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6832 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6833 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6834 | return_value = PyLong_FromLong(_return_value); |
| 6835 | |
| 6836 | exit: |
| 6837 | return return_value; |
| 6838 | } |
| 6839 | |
| 6840 | #endif /* defined(HAVE_SYSCONF) */ |
| 6841 | |
| 6842 | PyDoc_STRVAR(os_abort__doc__, |
| 6843 | "abort($module, /)\n" |
| 6844 | "--\n" |
| 6845 | "\n" |
| 6846 | "Abort the interpreter immediately.\n" |
| 6847 | "\n" |
| 6848 | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
| 6849 | "on the hosting operating system. This function never returns."); |
| 6850 | |
| 6851 | #define OS_ABORT_METHODDEF \ |
| 6852 | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
| 6853 | |
| 6854 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6855 | os_abort_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6856 | |
| 6857 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6858 | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6859 | { |
| 6860 | return os_abort_impl(module); |
| 6861 | } |
| 6862 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6863 | #if defined(MS_WINDOWS) |
| 6864 | |
| 6865 | PyDoc_STRVAR(os_startfile__doc__, |
Serhiy Storchaka | 279f446 | 2019-09-14 12:24:05 +0300 | [diff] [blame] | 6866 | "startfile($module, /, filepath, operation=<unrepresentable>)\n" |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6867 | "--\n" |
| 6868 | "\n" |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6869 | "Start a file with its associated application.\n" |
| 6870 | "\n" |
| 6871 | "When \"operation\" is not specified or \"open\", this acts like\n" |
| 6872 | "double-clicking the file in Explorer, or giving the file name as an\n" |
| 6873 | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
| 6874 | "application (if any) its extension is associated.\n" |
| 6875 | "When another \"operation\" is given, it specifies what should be done with\n" |
| 6876 | "the file. A typical operation is \"print\".\n" |
| 6877 | "\n" |
| 6878 | "startfile returns as soon as the associated application is launched.\n" |
| 6879 | "There is no option to wait for the application to close, and no way\n" |
| 6880 | "to retrieve the application\'s exit status.\n" |
| 6881 | "\n" |
| 6882 | "The filepath is relative to the current directory. If you want to use\n" |
| 6883 | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
| 6884 | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
| 6885 | |
| 6886 | #define OS_STARTFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6887 | {"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] | 6888 | |
| 6889 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 6890 | os_startfile_impl(PyObject *module, path_t *filepath, |
| 6891 | const Py_UNICODE *operation); |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6892 | |
| 6893 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6894 | 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] | 6895 | { |
| 6896 | PyObject *return_value = NULL; |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 6897 | static const char * const _keywords[] = {"filepath", "operation", NULL}; |
| 6898 | static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0}; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6899 | path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0); |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 6900 | const Py_UNICODE *operation = NULL; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6901 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6902 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6903 | path_converter, &filepath, &operation)) { |
| 6904 | goto exit; |
| 6905 | } |
| 6906 | return_value = os_startfile_impl(module, &filepath, operation); |
| 6907 | |
| 6908 | exit: |
| 6909 | /* Cleanup for filepath */ |
| 6910 | path_cleanup(&filepath); |
| 6911 | |
| 6912 | return return_value; |
| 6913 | } |
| 6914 | |
| 6915 | #endif /* defined(MS_WINDOWS) */ |
| 6916 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6917 | #if defined(HAVE_GETLOADAVG) |
| 6918 | |
| 6919 | PyDoc_STRVAR(os_getloadavg__doc__, |
| 6920 | "getloadavg($module, /)\n" |
| 6921 | "--\n" |
| 6922 | "\n" |
| 6923 | "Return average recent system load information.\n" |
| 6924 | "\n" |
| 6925 | "Return the number of processes in the system run queue averaged over\n" |
| 6926 | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
| 6927 | "Raises OSError if the load average was unobtainable."); |
| 6928 | |
| 6929 | #define OS_GETLOADAVG_METHODDEF \ |
| 6930 | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
| 6931 | |
| 6932 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6933 | os_getloadavg_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6934 | |
| 6935 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6936 | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6937 | { |
| 6938 | return os_getloadavg_impl(module); |
| 6939 | } |
| 6940 | |
| 6941 | #endif /* defined(HAVE_GETLOADAVG) */ |
| 6942 | |
| 6943 | PyDoc_STRVAR(os_device_encoding__doc__, |
| 6944 | "device_encoding($module, /, fd)\n" |
| 6945 | "--\n" |
| 6946 | "\n" |
| 6947 | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
| 6948 | "\n" |
| 6949 | "The file descriptor must be attached to a terminal.\n" |
| 6950 | "If the device is not a terminal, return None."); |
| 6951 | |
| 6952 | #define OS_DEVICE_ENCODING_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6953 | {"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] | 6954 | |
| 6955 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6956 | os_device_encoding_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6957 | |
| 6958 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6959 | 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] | 6960 | { |
| 6961 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6962 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6963 | static _PyArg_Parser _parser = {NULL, _keywords, "device_encoding", 0}; |
| 6964 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6965 | int fd; |
| 6966 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6967 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6968 | if (!args) { |
| 6969 | goto exit; |
| 6970 | } |
| 6971 | if (PyFloat_Check(args[0])) { |
| 6972 | PyErr_SetString(PyExc_TypeError, |
| 6973 | "integer argument expected, got float" ); |
| 6974 | goto exit; |
| 6975 | } |
| 6976 | fd = _PyLong_AsInt(args[0]); |
| 6977 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6978 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6979 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6980 | return_value = os_device_encoding_impl(module, fd); |
| 6981 | |
| 6982 | exit: |
| 6983 | return return_value; |
| 6984 | } |
| 6985 | |
| 6986 | #if defined(HAVE_SETRESUID) |
| 6987 | |
| 6988 | PyDoc_STRVAR(os_setresuid__doc__, |
| 6989 | "setresuid($module, ruid, euid, suid, /)\n" |
| 6990 | "--\n" |
| 6991 | "\n" |
| 6992 | "Set the current process\'s real, effective, and saved user ids."); |
| 6993 | |
| 6994 | #define OS_SETRESUID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6995 | {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6996 | |
| 6997 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6998 | 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] | 6999 | |
| 7000 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7001 | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7002 | { |
| 7003 | PyObject *return_value = NULL; |
| 7004 | uid_t ruid; |
| 7005 | uid_t euid; |
| 7006 | uid_t suid; |
| 7007 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 7008 | if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { |
| 7009 | goto exit; |
| 7010 | } |
| 7011 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
| 7012 | goto exit; |
| 7013 | } |
| 7014 | if (!_Py_Uid_Converter(args[1], &euid)) { |
| 7015 | goto exit; |
| 7016 | } |
| 7017 | if (!_Py_Uid_Converter(args[2], &suid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 7018 | goto exit; |
| 7019 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7020 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
| 7021 | |
| 7022 | exit: |
| 7023 | return return_value; |
| 7024 | } |
| 7025 | |
| 7026 | #endif /* defined(HAVE_SETRESUID) */ |
| 7027 | |
| 7028 | #if defined(HAVE_SETRESGID) |
| 7029 | |
| 7030 | PyDoc_STRVAR(os_setresgid__doc__, |
| 7031 | "setresgid($module, rgid, egid, sgid, /)\n" |
| 7032 | "--\n" |
| 7033 | "\n" |
| 7034 | "Set the current process\'s real, effective, and saved group ids."); |
| 7035 | |
| 7036 | #define OS_SETRESGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7037 | {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7038 | |
| 7039 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7040 | 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] | 7041 | |
| 7042 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7043 | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7044 | { |
| 7045 | PyObject *return_value = NULL; |
| 7046 | gid_t rgid; |
| 7047 | gid_t egid; |
| 7048 | gid_t sgid; |
| 7049 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 7050 | if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { |
| 7051 | goto exit; |
| 7052 | } |
| 7053 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
| 7054 | goto exit; |
| 7055 | } |
| 7056 | if (!_Py_Gid_Converter(args[1], &egid)) { |
| 7057 | goto exit; |
| 7058 | } |
| 7059 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 7060 | goto exit; |
| 7061 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7062 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
| 7063 | |
| 7064 | exit: |
| 7065 | return return_value; |
| 7066 | } |
| 7067 | |
| 7068 | #endif /* defined(HAVE_SETRESGID) */ |
| 7069 | |
| 7070 | #if defined(HAVE_GETRESUID) |
| 7071 | |
| 7072 | PyDoc_STRVAR(os_getresuid__doc__, |
| 7073 | "getresuid($module, /)\n" |
| 7074 | "--\n" |
| 7075 | "\n" |
| 7076 | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
| 7077 | |
| 7078 | #define OS_GETRESUID_METHODDEF \ |
| 7079 | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
| 7080 | |
| 7081 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7082 | os_getresuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7083 | |
| 7084 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7085 | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7086 | { |
| 7087 | return os_getresuid_impl(module); |
| 7088 | } |
| 7089 | |
| 7090 | #endif /* defined(HAVE_GETRESUID) */ |
| 7091 | |
| 7092 | #if defined(HAVE_GETRESGID) |
| 7093 | |
| 7094 | PyDoc_STRVAR(os_getresgid__doc__, |
| 7095 | "getresgid($module, /)\n" |
| 7096 | "--\n" |
| 7097 | "\n" |
| 7098 | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
| 7099 | |
| 7100 | #define OS_GETRESGID_METHODDEF \ |
| 7101 | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
| 7102 | |
| 7103 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7104 | os_getresgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7105 | |
| 7106 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7107 | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7108 | { |
| 7109 | return os_getresgid_impl(module); |
| 7110 | } |
| 7111 | |
| 7112 | #endif /* defined(HAVE_GETRESGID) */ |
| 7113 | |
| 7114 | #if defined(USE_XATTRS) |
| 7115 | |
| 7116 | PyDoc_STRVAR(os_getxattr__doc__, |
| 7117 | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 7118 | "--\n" |
| 7119 | "\n" |
| 7120 | "Return the value of extended attribute attribute on path.\n" |
| 7121 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7122 | "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] | 7123 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 7124 | " link, getxattr will examine the symbolic link itself instead of the file\n" |
| 7125 | " the link points to."); |
| 7126 | |
| 7127 | #define OS_GETXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7128 | {"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] | 7129 | |
| 7130 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7131 | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 7132 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7133 | |
| 7134 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7135 | 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] | 7136 | { |
| 7137 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 7138 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7139 | static _PyArg_Parser _parser = {NULL, _keywords, "getxattr", 0}; |
| 7140 | PyObject *argsbuf[3]; |
| 7141 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7142 | path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1); |
| 7143 | path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0); |
| 7144 | int follow_symlinks = 1; |
| 7145 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7146 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 7147 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7148 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7149 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7150 | if (!path_converter(args[0], &path)) { |
| 7151 | goto exit; |
| 7152 | } |
| 7153 | if (!path_converter(args[1], &attribute)) { |
| 7154 | goto exit; |
| 7155 | } |
| 7156 | if (!noptargs) { |
| 7157 | goto skip_optional_kwonly; |
| 7158 | } |
| 7159 | follow_symlinks = PyObject_IsTrue(args[2]); |
| 7160 | if (follow_symlinks < 0) { |
| 7161 | goto exit; |
| 7162 | } |
| 7163 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7164 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
| 7165 | |
| 7166 | exit: |
| 7167 | /* Cleanup for path */ |
| 7168 | path_cleanup(&path); |
| 7169 | /* Cleanup for attribute */ |
| 7170 | path_cleanup(&attribute); |
| 7171 | |
| 7172 | return return_value; |
| 7173 | } |
| 7174 | |
| 7175 | #endif /* defined(USE_XATTRS) */ |
| 7176 | |
| 7177 | #if defined(USE_XATTRS) |
| 7178 | |
| 7179 | PyDoc_STRVAR(os_setxattr__doc__, |
| 7180 | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
| 7181 | " follow_symlinks=True)\n" |
| 7182 | "--\n" |
| 7183 | "\n" |
| 7184 | "Set extended attribute attribute on path to value.\n" |
| 7185 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7186 | "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] | 7187 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 7188 | " link, setxattr will modify the symbolic link itself instead of the file\n" |
| 7189 | " the link points to."); |
| 7190 | |
| 7191 | #define OS_SETXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7192 | {"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] | 7193 | |
| 7194 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7195 | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 7196 | Py_buffer *value, int flags, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7197 | |
| 7198 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7199 | 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] | 7200 | { |
| 7201 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 7202 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7203 | static _PyArg_Parser _parser = {NULL, _keywords, "setxattr", 0}; |
| 7204 | PyObject *argsbuf[5]; |
| 7205 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7206 | path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1); |
| 7207 | path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0); |
| 7208 | Py_buffer value = {NULL, NULL}; |
| 7209 | int flags = 0; |
| 7210 | int follow_symlinks = 1; |
| 7211 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7212 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf); |
| 7213 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7214 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7215 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7216 | if (!path_converter(args[0], &path)) { |
| 7217 | goto exit; |
| 7218 | } |
| 7219 | if (!path_converter(args[1], &attribute)) { |
| 7220 | goto exit; |
| 7221 | } |
| 7222 | if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) { |
| 7223 | goto exit; |
| 7224 | } |
| 7225 | if (!PyBuffer_IsContiguous(&value, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 7226 | _PyArg_BadArgument("setxattr", "argument 'value'", "contiguous buffer", args[2]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7227 | goto exit; |
| 7228 | } |
| 7229 | if (!noptargs) { |
| 7230 | goto skip_optional_pos; |
| 7231 | } |
| 7232 | if (args[3]) { |
| 7233 | if (PyFloat_Check(args[3])) { |
| 7234 | PyErr_SetString(PyExc_TypeError, |
| 7235 | "integer argument expected, got float" ); |
| 7236 | goto exit; |
| 7237 | } |
| 7238 | flags = _PyLong_AsInt(args[3]); |
| 7239 | if (flags == -1 && PyErr_Occurred()) { |
| 7240 | goto exit; |
| 7241 | } |
| 7242 | if (!--noptargs) { |
| 7243 | goto skip_optional_pos; |
| 7244 | } |
| 7245 | } |
| 7246 | skip_optional_pos: |
| 7247 | if (!noptargs) { |
| 7248 | goto skip_optional_kwonly; |
| 7249 | } |
| 7250 | follow_symlinks = PyObject_IsTrue(args[4]); |
| 7251 | if (follow_symlinks < 0) { |
| 7252 | goto exit; |
| 7253 | } |
| 7254 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7255 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
| 7256 | |
| 7257 | exit: |
| 7258 | /* Cleanup for path */ |
| 7259 | path_cleanup(&path); |
| 7260 | /* Cleanup for attribute */ |
| 7261 | path_cleanup(&attribute); |
| 7262 | /* Cleanup for value */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7263 | if (value.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7264 | PyBuffer_Release(&value); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7265 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7266 | |
| 7267 | return return_value; |
| 7268 | } |
| 7269 | |
| 7270 | #endif /* defined(USE_XATTRS) */ |
| 7271 | |
| 7272 | #if defined(USE_XATTRS) |
| 7273 | |
| 7274 | PyDoc_STRVAR(os_removexattr__doc__, |
| 7275 | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 7276 | "--\n" |
| 7277 | "\n" |
| 7278 | "Remove extended attribute attribute on path.\n" |
| 7279 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7280 | "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] | 7281 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 7282 | " link, removexattr will modify the symbolic link itself instead of the file\n" |
| 7283 | " the link points to."); |
| 7284 | |
| 7285 | #define OS_REMOVEXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7286 | {"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] | 7287 | |
| 7288 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7289 | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 7290 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7291 | |
| 7292 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7293 | 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] | 7294 | { |
| 7295 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 7296 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7297 | static _PyArg_Parser _parser = {NULL, _keywords, "removexattr", 0}; |
| 7298 | PyObject *argsbuf[3]; |
| 7299 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7300 | path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1); |
| 7301 | path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0); |
| 7302 | int follow_symlinks = 1; |
| 7303 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7304 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 7305 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7306 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7307 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7308 | if (!path_converter(args[0], &path)) { |
| 7309 | goto exit; |
| 7310 | } |
| 7311 | if (!path_converter(args[1], &attribute)) { |
| 7312 | goto exit; |
| 7313 | } |
| 7314 | if (!noptargs) { |
| 7315 | goto skip_optional_kwonly; |
| 7316 | } |
| 7317 | follow_symlinks = PyObject_IsTrue(args[2]); |
| 7318 | if (follow_symlinks < 0) { |
| 7319 | goto exit; |
| 7320 | } |
| 7321 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7322 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
| 7323 | |
| 7324 | exit: |
| 7325 | /* Cleanup for path */ |
| 7326 | path_cleanup(&path); |
| 7327 | /* Cleanup for attribute */ |
| 7328 | path_cleanup(&attribute); |
| 7329 | |
| 7330 | return return_value; |
| 7331 | } |
| 7332 | |
| 7333 | #endif /* defined(USE_XATTRS) */ |
| 7334 | |
| 7335 | #if defined(USE_XATTRS) |
| 7336 | |
| 7337 | PyDoc_STRVAR(os_listxattr__doc__, |
| 7338 | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
| 7339 | "--\n" |
| 7340 | "\n" |
| 7341 | "Return a list of extended attributes on path.\n" |
| 7342 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7343 | "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] | 7344 | "if path is None, listxattr will examine the current directory.\n" |
| 7345 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 7346 | " link, listxattr will examine the symbolic link itself instead of the file\n" |
| 7347 | " the link points to."); |
| 7348 | |
| 7349 | #define OS_LISTXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7350 | {"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] | 7351 | |
| 7352 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7353 | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7354 | |
| 7355 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7356 | 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] | 7357 | { |
| 7358 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 7359 | static const char * const _keywords[] = {"path", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7360 | static _PyArg_Parser _parser = {NULL, _keywords, "listxattr", 0}; |
| 7361 | PyObject *argsbuf[2]; |
| 7362 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7363 | path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1); |
| 7364 | int follow_symlinks = 1; |
| 7365 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7366 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 7367 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7368 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7369 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7370 | if (!noptargs) { |
| 7371 | goto skip_optional_pos; |
| 7372 | } |
| 7373 | if (args[0]) { |
| 7374 | if (!path_converter(args[0], &path)) { |
| 7375 | goto exit; |
| 7376 | } |
| 7377 | if (!--noptargs) { |
| 7378 | goto skip_optional_pos; |
| 7379 | } |
| 7380 | } |
| 7381 | skip_optional_pos: |
| 7382 | if (!noptargs) { |
| 7383 | goto skip_optional_kwonly; |
| 7384 | } |
| 7385 | follow_symlinks = PyObject_IsTrue(args[1]); |
| 7386 | if (follow_symlinks < 0) { |
| 7387 | goto exit; |
| 7388 | } |
| 7389 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7390 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
| 7391 | |
| 7392 | exit: |
| 7393 | /* Cleanup for path */ |
| 7394 | path_cleanup(&path); |
| 7395 | |
| 7396 | return return_value; |
| 7397 | } |
| 7398 | |
| 7399 | #endif /* defined(USE_XATTRS) */ |
| 7400 | |
| 7401 | PyDoc_STRVAR(os_urandom__doc__, |
| 7402 | "urandom($module, size, /)\n" |
| 7403 | "--\n" |
| 7404 | "\n" |
| 7405 | "Return a bytes object containing random bytes suitable for cryptographic use."); |
| 7406 | |
| 7407 | #define OS_URANDOM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 7408 | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7409 | |
| 7410 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7411 | os_urandom_impl(PyObject *module, Py_ssize_t size); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7412 | |
| 7413 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7414 | os_urandom(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7415 | { |
| 7416 | PyObject *return_value = NULL; |
| 7417 | Py_ssize_t size; |
| 7418 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 7419 | if (PyFloat_Check(arg)) { |
| 7420 | PyErr_SetString(PyExc_TypeError, |
| 7421 | "integer argument expected, got float" ); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7422 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7423 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 7424 | { |
| 7425 | Py_ssize_t ival = -1; |
| 7426 | PyObject *iobj = PyNumber_Index(arg); |
| 7427 | if (iobj != NULL) { |
| 7428 | ival = PyLong_AsSsize_t(iobj); |
| 7429 | Py_DECREF(iobj); |
| 7430 | } |
| 7431 | if (ival == -1 && PyErr_Occurred()) { |
| 7432 | goto exit; |
| 7433 | } |
| 7434 | size = ival; |
| 7435 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7436 | return_value = os_urandom_impl(module, size); |
| 7437 | |
| 7438 | exit: |
| 7439 | return return_value; |
| 7440 | } |
| 7441 | |
Zackery Spytz | 43fdbd2 | 2019-05-29 13:57:07 -0600 | [diff] [blame] | 7442 | #if defined(HAVE_MEMFD_CREATE) |
| 7443 | |
| 7444 | PyDoc_STRVAR(os_memfd_create__doc__, |
| 7445 | "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n" |
| 7446 | "--\n" |
| 7447 | "\n"); |
| 7448 | |
| 7449 | #define OS_MEMFD_CREATE_METHODDEF \ |
| 7450 | {"memfd_create", (PyCFunction)(void(*)(void))os_memfd_create, METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__}, |
| 7451 | |
| 7452 | static PyObject * |
| 7453 | os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags); |
| 7454 | |
| 7455 | static PyObject * |
| 7456 | os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 7457 | { |
| 7458 | PyObject *return_value = NULL; |
| 7459 | static const char * const _keywords[] = {"name", "flags", NULL}; |
| 7460 | static _PyArg_Parser _parser = {NULL, _keywords, "memfd_create", 0}; |
| 7461 | PyObject *argsbuf[2]; |
| 7462 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 7463 | PyObject *name = NULL; |
| 7464 | unsigned int flags = MFD_CLOEXEC; |
| 7465 | |
| 7466 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 7467 | if (!args) { |
| 7468 | goto exit; |
| 7469 | } |
| 7470 | if (!PyUnicode_FSConverter(args[0], &name)) { |
| 7471 | goto exit; |
| 7472 | } |
| 7473 | if (!noptargs) { |
| 7474 | goto skip_optional_pos; |
| 7475 | } |
| 7476 | if (PyFloat_Check(args[1])) { |
| 7477 | PyErr_SetString(PyExc_TypeError, |
| 7478 | "integer argument expected, got float" ); |
| 7479 | goto exit; |
| 7480 | } |
| 7481 | flags = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); |
| 7482 | if (flags == (unsigned int)-1 && PyErr_Occurred()) { |
| 7483 | goto exit; |
| 7484 | } |
| 7485 | skip_optional_pos: |
| 7486 | return_value = os_memfd_create_impl(module, name, flags); |
| 7487 | |
| 7488 | exit: |
| 7489 | /* Cleanup for name */ |
| 7490 | Py_XDECREF(name); |
| 7491 | |
| 7492 | return return_value; |
| 7493 | } |
| 7494 | |
| 7495 | #endif /* defined(HAVE_MEMFD_CREATE) */ |
| 7496 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7497 | PyDoc_STRVAR(os_cpu_count__doc__, |
| 7498 | "cpu_count($module, /)\n" |
| 7499 | "--\n" |
| 7500 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 7501 | "Return the number of CPUs in the system; return None if indeterminable.\n" |
| 7502 | "\n" |
| 7503 | "This number is not equivalent to the number of CPUs the current process can\n" |
| 7504 | "use. The number of usable CPUs can be obtained with\n" |
| 7505 | "``len(os.sched_getaffinity(0))``"); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7506 | |
| 7507 | #define OS_CPU_COUNT_METHODDEF \ |
| 7508 | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
| 7509 | |
| 7510 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7511 | os_cpu_count_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7512 | |
| 7513 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7514 | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7515 | { |
| 7516 | return os_cpu_count_impl(module); |
| 7517 | } |
| 7518 | |
| 7519 | PyDoc_STRVAR(os_get_inheritable__doc__, |
| 7520 | "get_inheritable($module, fd, /)\n" |
| 7521 | "--\n" |
| 7522 | "\n" |
| 7523 | "Get the close-on-exe flag of the specified file descriptor."); |
| 7524 | |
| 7525 | #define OS_GET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 7526 | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7527 | |
| 7528 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7529 | os_get_inheritable_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7530 | |
| 7531 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7532 | os_get_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7533 | { |
| 7534 | PyObject *return_value = NULL; |
| 7535 | int fd; |
| 7536 | int _return_value; |
| 7537 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 7538 | if (PyFloat_Check(arg)) { |
| 7539 | PyErr_SetString(PyExc_TypeError, |
| 7540 | "integer argument expected, got float" ); |
| 7541 | goto exit; |
| 7542 | } |
| 7543 | fd = _PyLong_AsInt(arg); |
| 7544 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7545 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7546 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7547 | _return_value = os_get_inheritable_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7548 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7549 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7550 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7551 | return_value = PyBool_FromLong((long)_return_value); |
| 7552 | |
| 7553 | exit: |
| 7554 | return return_value; |
| 7555 | } |
| 7556 | |
| 7557 | PyDoc_STRVAR(os_set_inheritable__doc__, |
| 7558 | "set_inheritable($module, fd, inheritable, /)\n" |
| 7559 | "--\n" |
| 7560 | "\n" |
| 7561 | "Set the inheritable flag of the specified file descriptor."); |
| 7562 | |
| 7563 | #define OS_SET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7564 | {"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] | 7565 | |
| 7566 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7567 | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7568 | |
| 7569 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7570 | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7571 | { |
| 7572 | PyObject *return_value = NULL; |
| 7573 | int fd; |
| 7574 | int inheritable; |
| 7575 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 7576 | if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { |
| 7577 | goto exit; |
| 7578 | } |
| 7579 | if (PyFloat_Check(args[0])) { |
| 7580 | PyErr_SetString(PyExc_TypeError, |
| 7581 | "integer argument expected, got float" ); |
| 7582 | goto exit; |
| 7583 | } |
| 7584 | fd = _PyLong_AsInt(args[0]); |
| 7585 | if (fd == -1 && PyErr_Occurred()) { |
| 7586 | goto exit; |
| 7587 | } |
| 7588 | if (PyFloat_Check(args[1])) { |
| 7589 | PyErr_SetString(PyExc_TypeError, |
| 7590 | "integer argument expected, got float" ); |
| 7591 | goto exit; |
| 7592 | } |
| 7593 | inheritable = _PyLong_AsInt(args[1]); |
| 7594 | if (inheritable == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 7595 | goto exit; |
| 7596 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7597 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
| 7598 | |
| 7599 | exit: |
| 7600 | return return_value; |
| 7601 | } |
| 7602 | |
| 7603 | #if defined(MS_WINDOWS) |
| 7604 | |
| 7605 | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
| 7606 | "get_handle_inheritable($module, handle, /)\n" |
| 7607 | "--\n" |
| 7608 | "\n" |
| 7609 | "Get the close-on-exe flag of the specified file descriptor."); |
| 7610 | |
| 7611 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 7612 | {"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] | 7613 | |
| 7614 | static int |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 7615 | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7616 | |
| 7617 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7618 | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7619 | { |
| 7620 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 7621 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7622 | int _return_value; |
| 7623 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7624 | if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7625 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7626 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7627 | _return_value = os_get_handle_inheritable_impl(module, handle); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7628 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7629 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7630 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7631 | return_value = PyBool_FromLong((long)_return_value); |
| 7632 | |
| 7633 | exit: |
| 7634 | return return_value; |
| 7635 | } |
| 7636 | |
| 7637 | #endif /* defined(MS_WINDOWS) */ |
| 7638 | |
| 7639 | #if defined(MS_WINDOWS) |
| 7640 | |
| 7641 | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
| 7642 | "set_handle_inheritable($module, handle, inheritable, /)\n" |
| 7643 | "--\n" |
| 7644 | "\n" |
| 7645 | "Set the inheritable flag of the specified handle."); |
| 7646 | |
| 7647 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7648 | {"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] | 7649 | |
| 7650 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 7651 | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 7652 | int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7653 | |
| 7654 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7655 | 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] | 7656 | { |
| 7657 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 7658 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7659 | int inheritable; |
| 7660 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 7661 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable", |
| 7662 | &handle, &inheritable)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 7663 | goto exit; |
| 7664 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7665 | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
| 7666 | |
| 7667 | exit: |
| 7668 | return return_value; |
| 7669 | } |
| 7670 | |
| 7671 | #endif /* defined(MS_WINDOWS) */ |
| 7672 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7673 | #if !defined(MS_WINDOWS) |
| 7674 | |
| 7675 | PyDoc_STRVAR(os_get_blocking__doc__, |
| 7676 | "get_blocking($module, fd, /)\n" |
| 7677 | "--\n" |
| 7678 | "\n" |
| 7679 | "Get the blocking mode of the file descriptor.\n" |
| 7680 | "\n" |
| 7681 | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared."); |
| 7682 | |
| 7683 | #define OS_GET_BLOCKING_METHODDEF \ |
| 7684 | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
| 7685 | |
| 7686 | static int |
| 7687 | os_get_blocking_impl(PyObject *module, int fd); |
| 7688 | |
| 7689 | static PyObject * |
| 7690 | os_get_blocking(PyObject *module, PyObject *arg) |
| 7691 | { |
| 7692 | PyObject *return_value = NULL; |
| 7693 | int fd; |
| 7694 | int _return_value; |
| 7695 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 7696 | if (PyFloat_Check(arg)) { |
| 7697 | PyErr_SetString(PyExc_TypeError, |
| 7698 | "integer argument expected, got float" ); |
| 7699 | goto exit; |
| 7700 | } |
| 7701 | fd = _PyLong_AsInt(arg); |
| 7702 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7703 | goto exit; |
| 7704 | } |
| 7705 | _return_value = os_get_blocking_impl(module, fd); |
| 7706 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 7707 | goto exit; |
| 7708 | } |
| 7709 | return_value = PyBool_FromLong((long)_return_value); |
| 7710 | |
| 7711 | exit: |
| 7712 | return return_value; |
| 7713 | } |
| 7714 | |
| 7715 | #endif /* !defined(MS_WINDOWS) */ |
| 7716 | |
| 7717 | #if !defined(MS_WINDOWS) |
| 7718 | |
| 7719 | PyDoc_STRVAR(os_set_blocking__doc__, |
| 7720 | "set_blocking($module, fd, blocking, /)\n" |
| 7721 | "--\n" |
| 7722 | "\n" |
| 7723 | "Set the blocking mode of the specified file descriptor.\n" |
| 7724 | "\n" |
| 7725 | "Set the O_NONBLOCK flag if blocking is False,\n" |
| 7726 | "clear the O_NONBLOCK flag otherwise."); |
| 7727 | |
| 7728 | #define OS_SET_BLOCKING_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7729 | {"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] | 7730 | |
| 7731 | static PyObject * |
| 7732 | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
| 7733 | |
| 7734 | static PyObject * |
| 7735 | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 7736 | { |
| 7737 | PyObject *return_value = NULL; |
| 7738 | int fd; |
| 7739 | int blocking; |
| 7740 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 7741 | if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { |
| 7742 | goto exit; |
| 7743 | } |
| 7744 | if (PyFloat_Check(args[0])) { |
| 7745 | PyErr_SetString(PyExc_TypeError, |
| 7746 | "integer argument expected, got float" ); |
| 7747 | goto exit; |
| 7748 | } |
| 7749 | fd = _PyLong_AsInt(args[0]); |
| 7750 | if (fd == -1 && PyErr_Occurred()) { |
| 7751 | goto exit; |
| 7752 | } |
| 7753 | if (PyFloat_Check(args[1])) { |
| 7754 | PyErr_SetString(PyExc_TypeError, |
| 7755 | "integer argument expected, got float" ); |
| 7756 | goto exit; |
| 7757 | } |
| 7758 | blocking = _PyLong_AsInt(args[1]); |
| 7759 | if (blocking == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7760 | goto exit; |
| 7761 | } |
| 7762 | return_value = os_set_blocking_impl(module, fd, blocking); |
| 7763 | |
| 7764 | exit: |
| 7765 | return return_value; |
| 7766 | } |
| 7767 | |
| 7768 | #endif /* !defined(MS_WINDOWS) */ |
| 7769 | |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7770 | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
| 7771 | "is_symlink($self, /)\n" |
| 7772 | "--\n" |
| 7773 | "\n" |
| 7774 | "Return True if the entry is a symbolic link; cached per entry."); |
| 7775 | |
| 7776 | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
| 7777 | {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__}, |
| 7778 | |
| 7779 | static int |
| 7780 | os_DirEntry_is_symlink_impl(DirEntry *self); |
| 7781 | |
| 7782 | static PyObject * |
| 7783 | os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 7784 | { |
| 7785 | PyObject *return_value = NULL; |
| 7786 | int _return_value; |
| 7787 | |
| 7788 | _return_value = os_DirEntry_is_symlink_impl(self); |
| 7789 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 7790 | goto exit; |
| 7791 | } |
| 7792 | return_value = PyBool_FromLong((long)_return_value); |
| 7793 | |
| 7794 | exit: |
| 7795 | return return_value; |
| 7796 | } |
| 7797 | |
| 7798 | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
| 7799 | "stat($self, /, *, follow_symlinks=True)\n" |
| 7800 | "--\n" |
| 7801 | "\n" |
| 7802 | "Return stat_result object for the entry; cached per entry."); |
| 7803 | |
| 7804 | #define OS_DIRENTRY_STAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7805 | {"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] | 7806 | |
| 7807 | static PyObject * |
| 7808 | os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks); |
| 7809 | |
| 7810 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7811 | 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] | 7812 | { |
| 7813 | PyObject *return_value = NULL; |
| 7814 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7815 | static _PyArg_Parser _parser = {NULL, _keywords, "stat", 0}; |
| 7816 | PyObject *argsbuf[1]; |
| 7817 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7818 | int follow_symlinks = 1; |
| 7819 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7820 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 7821 | if (!args) { |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7822 | goto exit; |
| 7823 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7824 | if (!noptargs) { |
| 7825 | goto skip_optional_kwonly; |
| 7826 | } |
| 7827 | follow_symlinks = PyObject_IsTrue(args[0]); |
| 7828 | if (follow_symlinks < 0) { |
| 7829 | goto exit; |
| 7830 | } |
| 7831 | skip_optional_kwonly: |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7832 | return_value = os_DirEntry_stat_impl(self, follow_symlinks); |
| 7833 | |
| 7834 | exit: |
| 7835 | return return_value; |
| 7836 | } |
| 7837 | |
| 7838 | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
| 7839 | "is_dir($self, /, *, follow_symlinks=True)\n" |
| 7840 | "--\n" |
| 7841 | "\n" |
| 7842 | "Return True if the entry is a directory; cached per entry."); |
| 7843 | |
| 7844 | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7845 | {"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] | 7846 | |
| 7847 | static int |
| 7848 | os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks); |
| 7849 | |
| 7850 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7851 | 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] | 7852 | { |
| 7853 | PyObject *return_value = NULL; |
| 7854 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7855 | static _PyArg_Parser _parser = {NULL, _keywords, "is_dir", 0}; |
| 7856 | PyObject *argsbuf[1]; |
| 7857 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7858 | int follow_symlinks = 1; |
| 7859 | int _return_value; |
| 7860 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7861 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 7862 | if (!args) { |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7863 | goto exit; |
| 7864 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7865 | if (!noptargs) { |
| 7866 | goto skip_optional_kwonly; |
| 7867 | } |
| 7868 | follow_symlinks = PyObject_IsTrue(args[0]); |
| 7869 | if (follow_symlinks < 0) { |
| 7870 | goto exit; |
| 7871 | } |
| 7872 | skip_optional_kwonly: |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7873 | _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks); |
| 7874 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 7875 | goto exit; |
| 7876 | } |
| 7877 | return_value = PyBool_FromLong((long)_return_value); |
| 7878 | |
| 7879 | exit: |
| 7880 | return return_value; |
| 7881 | } |
| 7882 | |
| 7883 | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
| 7884 | "is_file($self, /, *, follow_symlinks=True)\n" |
| 7885 | "--\n" |
| 7886 | "\n" |
| 7887 | "Return True if the entry is a file; cached per entry."); |
| 7888 | |
| 7889 | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7890 | {"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] | 7891 | |
| 7892 | static int |
| 7893 | os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks); |
| 7894 | |
| 7895 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7896 | 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] | 7897 | { |
| 7898 | PyObject *return_value = NULL; |
| 7899 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7900 | static _PyArg_Parser _parser = {NULL, _keywords, "is_file", 0}; |
| 7901 | PyObject *argsbuf[1]; |
| 7902 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7903 | int follow_symlinks = 1; |
| 7904 | int _return_value; |
| 7905 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7906 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 7907 | if (!args) { |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7908 | goto exit; |
| 7909 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7910 | if (!noptargs) { |
| 7911 | goto skip_optional_kwonly; |
| 7912 | } |
| 7913 | follow_symlinks = PyObject_IsTrue(args[0]); |
| 7914 | if (follow_symlinks < 0) { |
| 7915 | goto exit; |
| 7916 | } |
| 7917 | skip_optional_kwonly: |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7918 | _return_value = os_DirEntry_is_file_impl(self, follow_symlinks); |
| 7919 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 7920 | goto exit; |
| 7921 | } |
| 7922 | return_value = PyBool_FromLong((long)_return_value); |
| 7923 | |
| 7924 | exit: |
| 7925 | return return_value; |
| 7926 | } |
| 7927 | |
| 7928 | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
| 7929 | "inode($self, /)\n" |
| 7930 | "--\n" |
| 7931 | "\n" |
| 7932 | "Return inode of the entry; cached per entry."); |
| 7933 | |
| 7934 | #define OS_DIRENTRY_INODE_METHODDEF \ |
| 7935 | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
| 7936 | |
| 7937 | static PyObject * |
| 7938 | os_DirEntry_inode_impl(DirEntry *self); |
| 7939 | |
| 7940 | static PyObject * |
| 7941 | os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 7942 | { |
| 7943 | return os_DirEntry_inode_impl(self); |
| 7944 | } |
| 7945 | |
| 7946 | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
| 7947 | "__fspath__($self, /)\n" |
| 7948 | "--\n" |
| 7949 | "\n" |
| 7950 | "Returns the path for the entry."); |
| 7951 | |
| 7952 | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
| 7953 | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
| 7954 | |
| 7955 | static PyObject * |
| 7956 | os_DirEntry___fspath___impl(DirEntry *self); |
| 7957 | |
| 7958 | static PyObject * |
| 7959 | os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 7960 | { |
| 7961 | return os_DirEntry___fspath___impl(self); |
| 7962 | } |
| 7963 | |
| 7964 | PyDoc_STRVAR(os_scandir__doc__, |
| 7965 | "scandir($module, /, path=None)\n" |
| 7966 | "--\n" |
| 7967 | "\n" |
| 7968 | "Return an iterator of DirEntry objects for given path.\n" |
| 7969 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7970 | "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] | 7971 | "is bytes, the names of yielded DirEntry objects will also be bytes; in\n" |
| 7972 | "all other circumstances they will be str.\n" |
| 7973 | "\n" |
| 7974 | "If path is None, uses the path=\'.\'."); |
| 7975 | |
| 7976 | #define OS_SCANDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7977 | {"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] | 7978 | |
| 7979 | static PyObject * |
| 7980 | os_scandir_impl(PyObject *module, path_t *path); |
| 7981 | |
| 7982 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7983 | 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] | 7984 | { |
| 7985 | PyObject *return_value = NULL; |
| 7986 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7987 | static _PyArg_Parser _parser = {NULL, _keywords, "scandir", 0}; |
| 7988 | PyObject *argsbuf[1]; |
| 7989 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | ea720fe | 2017-03-30 09:12:31 +0300 | [diff] [blame] | 7990 | path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR); |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7991 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7992 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 7993 | if (!args) { |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7994 | goto exit; |
| 7995 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7996 | if (!noptargs) { |
| 7997 | goto skip_optional_pos; |
| 7998 | } |
| 7999 | if (!path_converter(args[0], &path)) { |
| 8000 | goto exit; |
| 8001 | } |
| 8002 | skip_optional_pos: |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 8003 | return_value = os_scandir_impl(module, &path); |
| 8004 | |
| 8005 | exit: |
| 8006 | /* Cleanup for path */ |
| 8007 | path_cleanup(&path); |
| 8008 | |
| 8009 | return return_value; |
| 8010 | } |
| 8011 | |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 8012 | PyDoc_STRVAR(os_fspath__doc__, |
| 8013 | "fspath($module, /, path)\n" |
| 8014 | "--\n" |
| 8015 | "\n" |
| 8016 | "Return the file system path representation of the object.\n" |
| 8017 | "\n" |
Brett Cannon | b4f43e9 | 2016-06-09 14:32:08 -0700 | [diff] [blame] | 8018 | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
| 8019 | "object defines __fspath__(), then return the result of that method. All other\n" |
| 8020 | "types raise a TypeError."); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 8021 | |
| 8022 | #define OS_FSPATH_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 8023 | {"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] | 8024 | |
| 8025 | static PyObject * |
Serhiy Storchaka | 2954f83 | 2016-07-07 18:20:03 +0300 | [diff] [blame] | 8026 | os_fspath_impl(PyObject *module, PyObject *path); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 8027 | |
| 8028 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 8029 | 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] | 8030 | { |
| 8031 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 8032 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 8033 | static _PyArg_Parser _parser = {NULL, _keywords, "fspath", 0}; |
| 8034 | PyObject *argsbuf[1]; |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 8035 | PyObject *path; |
| 8036 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 8037 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 8038 | if (!args) { |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 8039 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 8040 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 8041 | path = args[0]; |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 8042 | return_value = os_fspath_impl(module, path); |
| 8043 | |
| 8044 | exit: |
| 8045 | return return_value; |
| 8046 | } |
| 8047 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 8048 | #if defined(HAVE_GETRANDOM_SYSCALL) |
| 8049 | |
| 8050 | PyDoc_STRVAR(os_getrandom__doc__, |
| 8051 | "getrandom($module, /, size, flags=0)\n" |
| 8052 | "--\n" |
| 8053 | "\n" |
| 8054 | "Obtain a series of random bytes."); |
| 8055 | |
| 8056 | #define OS_GETRANDOM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 8057 | {"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] | 8058 | |
| 8059 | static PyObject * |
| 8060 | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
| 8061 | |
| 8062 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 8063 | 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] | 8064 | { |
| 8065 | PyObject *return_value = NULL; |
| 8066 | static const char * const _keywords[] = {"size", "flags", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 8067 | static _PyArg_Parser _parser = {NULL, _keywords, "getrandom", 0}; |
| 8068 | PyObject *argsbuf[2]; |
| 8069 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 8070 | Py_ssize_t size; |
| 8071 | int flags = 0; |
| 8072 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 8073 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 8074 | if (!args) { |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 8075 | goto exit; |
| 8076 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 8077 | if (PyFloat_Check(args[0])) { |
| 8078 | PyErr_SetString(PyExc_TypeError, |
| 8079 | "integer argument expected, got float" ); |
| 8080 | goto exit; |
| 8081 | } |
| 8082 | { |
| 8083 | Py_ssize_t ival = -1; |
| 8084 | PyObject *iobj = PyNumber_Index(args[0]); |
| 8085 | if (iobj != NULL) { |
| 8086 | ival = PyLong_AsSsize_t(iobj); |
| 8087 | Py_DECREF(iobj); |
| 8088 | } |
| 8089 | if (ival == -1 && PyErr_Occurred()) { |
| 8090 | goto exit; |
| 8091 | } |
| 8092 | size = ival; |
| 8093 | } |
| 8094 | if (!noptargs) { |
| 8095 | goto skip_optional_pos; |
| 8096 | } |
| 8097 | if (PyFloat_Check(args[1])) { |
| 8098 | PyErr_SetString(PyExc_TypeError, |
| 8099 | "integer argument expected, got float" ); |
| 8100 | goto exit; |
| 8101 | } |
| 8102 | flags = _PyLong_AsInt(args[1]); |
| 8103 | if (flags == -1 && PyErr_Occurred()) { |
| 8104 | goto exit; |
| 8105 | } |
| 8106 | skip_optional_pos: |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 8107 | return_value = os_getrandom_impl(module, size, flags); |
| 8108 | |
| 8109 | exit: |
| 8110 | return return_value; |
| 8111 | } |
| 8112 | |
| 8113 | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
| 8114 | |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 8115 | #if defined(MS_WINDOWS) |
| 8116 | |
| 8117 | PyDoc_STRVAR(os__add_dll_directory__doc__, |
| 8118 | "_add_dll_directory($module, /, path)\n" |
| 8119 | "--\n" |
| 8120 | "\n" |
| 8121 | "Add a path to the DLL search path.\n" |
| 8122 | "\n" |
| 8123 | "This search path is used when resolving dependencies for imported\n" |
| 8124 | "extension modules (the module itself is resolved through sys.path),\n" |
| 8125 | "and also by ctypes.\n" |
| 8126 | "\n" |
| 8127 | "Returns an opaque value that may be passed to os.remove_dll_directory\n" |
| 8128 | "to remove this directory from the search path."); |
| 8129 | |
| 8130 | #define OS__ADD_DLL_DIRECTORY_METHODDEF \ |
| 8131 | {"_add_dll_directory", (PyCFunction)(void(*)(void))os__add_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__}, |
| 8132 | |
| 8133 | static PyObject * |
| 8134 | os__add_dll_directory_impl(PyObject *module, path_t *path); |
| 8135 | |
| 8136 | static PyObject * |
| 8137 | os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 8138 | { |
| 8139 | PyObject *return_value = NULL; |
| 8140 | static const char * const _keywords[] = {"path", NULL}; |
| 8141 | static _PyArg_Parser _parser = {NULL, _keywords, "_add_dll_directory", 0}; |
| 8142 | PyObject *argsbuf[1]; |
| 8143 | path_t path = PATH_T_INITIALIZE("_add_dll_directory", "path", 0, 0); |
| 8144 | |
| 8145 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 8146 | if (!args) { |
| 8147 | goto exit; |
| 8148 | } |
| 8149 | if (!path_converter(args[0], &path)) { |
| 8150 | goto exit; |
| 8151 | } |
| 8152 | return_value = os__add_dll_directory_impl(module, &path); |
| 8153 | |
| 8154 | exit: |
| 8155 | /* Cleanup for path */ |
| 8156 | path_cleanup(&path); |
| 8157 | |
| 8158 | return return_value; |
| 8159 | } |
| 8160 | |
| 8161 | #endif /* defined(MS_WINDOWS) */ |
| 8162 | |
| 8163 | #if defined(MS_WINDOWS) |
| 8164 | |
| 8165 | PyDoc_STRVAR(os__remove_dll_directory__doc__, |
| 8166 | "_remove_dll_directory($module, /, cookie)\n" |
| 8167 | "--\n" |
| 8168 | "\n" |
| 8169 | "Removes a path from the DLL search path.\n" |
| 8170 | "\n" |
| 8171 | "The parameter is an opaque value that was returned from\n" |
| 8172 | "os.add_dll_directory. You can only remove directories that you added\n" |
| 8173 | "yourself."); |
| 8174 | |
| 8175 | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \ |
| 8176 | {"_remove_dll_directory", (PyCFunction)(void(*)(void))os__remove_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__}, |
| 8177 | |
| 8178 | static PyObject * |
| 8179 | os__remove_dll_directory_impl(PyObject *module, PyObject *cookie); |
| 8180 | |
| 8181 | static PyObject * |
| 8182 | os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 8183 | { |
| 8184 | PyObject *return_value = NULL; |
| 8185 | static const char * const _keywords[] = {"cookie", NULL}; |
| 8186 | static _PyArg_Parser _parser = {NULL, _keywords, "_remove_dll_directory", 0}; |
| 8187 | PyObject *argsbuf[1]; |
| 8188 | PyObject *cookie; |
| 8189 | |
| 8190 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 8191 | if (!args) { |
| 8192 | goto exit; |
| 8193 | } |
| 8194 | cookie = args[0]; |
| 8195 | return_value = os__remove_dll_directory_impl(module, cookie); |
| 8196 | |
| 8197 | exit: |
| 8198 | return return_value; |
| 8199 | } |
| 8200 | |
| 8201 | #endif /* defined(MS_WINDOWS) */ |
| 8202 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8203 | #ifndef OS_TTYNAME_METHODDEF |
| 8204 | #define OS_TTYNAME_METHODDEF |
| 8205 | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
| 8206 | |
| 8207 | #ifndef OS_CTERMID_METHODDEF |
| 8208 | #define OS_CTERMID_METHODDEF |
| 8209 | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
| 8210 | |
| 8211 | #ifndef OS_FCHDIR_METHODDEF |
| 8212 | #define OS_FCHDIR_METHODDEF |
| 8213 | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
| 8214 | |
| 8215 | #ifndef OS_FCHMOD_METHODDEF |
| 8216 | #define OS_FCHMOD_METHODDEF |
| 8217 | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
| 8218 | |
| 8219 | #ifndef OS_LCHMOD_METHODDEF |
| 8220 | #define OS_LCHMOD_METHODDEF |
| 8221 | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
| 8222 | |
| 8223 | #ifndef OS_CHFLAGS_METHODDEF |
| 8224 | #define OS_CHFLAGS_METHODDEF |
| 8225 | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
| 8226 | |
| 8227 | #ifndef OS_LCHFLAGS_METHODDEF |
| 8228 | #define OS_LCHFLAGS_METHODDEF |
| 8229 | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
| 8230 | |
| 8231 | #ifndef OS_CHROOT_METHODDEF |
| 8232 | #define OS_CHROOT_METHODDEF |
| 8233 | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
| 8234 | |
| 8235 | #ifndef OS_FSYNC_METHODDEF |
| 8236 | #define OS_FSYNC_METHODDEF |
| 8237 | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
| 8238 | |
| 8239 | #ifndef OS_SYNC_METHODDEF |
| 8240 | #define OS_SYNC_METHODDEF |
| 8241 | #endif /* !defined(OS_SYNC_METHODDEF) */ |
| 8242 | |
| 8243 | #ifndef OS_FDATASYNC_METHODDEF |
| 8244 | #define OS_FDATASYNC_METHODDEF |
| 8245 | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
| 8246 | |
| 8247 | #ifndef OS_CHOWN_METHODDEF |
| 8248 | #define OS_CHOWN_METHODDEF |
| 8249 | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
| 8250 | |
| 8251 | #ifndef OS_FCHOWN_METHODDEF |
| 8252 | #define OS_FCHOWN_METHODDEF |
| 8253 | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
| 8254 | |
| 8255 | #ifndef OS_LCHOWN_METHODDEF |
| 8256 | #define OS_LCHOWN_METHODDEF |
| 8257 | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
| 8258 | |
| 8259 | #ifndef OS_LINK_METHODDEF |
| 8260 | #define OS_LINK_METHODDEF |
| 8261 | #endif /* !defined(OS_LINK_METHODDEF) */ |
| 8262 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 8263 | #ifndef OS__GETFULLPATHNAME_METHODDEF |
| 8264 | #define OS__GETFULLPATHNAME_METHODDEF |
| 8265 | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
| 8266 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8267 | #ifndef OS__GETFINALPATHNAME_METHODDEF |
| 8268 | #define OS__GETFINALPATHNAME_METHODDEF |
| 8269 | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
| 8270 | |
| 8271 | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
| 8272 | #define OS__GETVOLUMEPATHNAME_METHODDEF |
| 8273 | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
| 8274 | |
| 8275 | #ifndef OS_NICE_METHODDEF |
| 8276 | #define OS_NICE_METHODDEF |
| 8277 | #endif /* !defined(OS_NICE_METHODDEF) */ |
| 8278 | |
| 8279 | #ifndef OS_GETPRIORITY_METHODDEF |
| 8280 | #define OS_GETPRIORITY_METHODDEF |
| 8281 | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
| 8282 | |
| 8283 | #ifndef OS_SETPRIORITY_METHODDEF |
| 8284 | #define OS_SETPRIORITY_METHODDEF |
| 8285 | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
| 8286 | |
| 8287 | #ifndef OS_SYSTEM_METHODDEF |
| 8288 | #define OS_SYSTEM_METHODDEF |
| 8289 | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
| 8290 | |
| 8291 | #ifndef OS_UNAME_METHODDEF |
| 8292 | #define OS_UNAME_METHODDEF |
| 8293 | #endif /* !defined(OS_UNAME_METHODDEF) */ |
| 8294 | |
| 8295 | #ifndef OS_EXECV_METHODDEF |
| 8296 | #define OS_EXECV_METHODDEF |
| 8297 | #endif /* !defined(OS_EXECV_METHODDEF) */ |
| 8298 | |
| 8299 | #ifndef OS_EXECVE_METHODDEF |
| 8300 | #define OS_EXECVE_METHODDEF |
| 8301 | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
| 8302 | |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 8303 | #ifndef OS_POSIX_SPAWN_METHODDEF |
| 8304 | #define OS_POSIX_SPAWN_METHODDEF |
| 8305 | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
| 8306 | |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 8307 | #ifndef OS_POSIX_SPAWNP_METHODDEF |
| 8308 | #define OS_POSIX_SPAWNP_METHODDEF |
| 8309 | #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */ |
| 8310 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8311 | #ifndef OS_SPAWNV_METHODDEF |
| 8312 | #define OS_SPAWNV_METHODDEF |
| 8313 | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
| 8314 | |
| 8315 | #ifndef OS_SPAWNVE_METHODDEF |
| 8316 | #define OS_SPAWNVE_METHODDEF |
| 8317 | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
| 8318 | |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 8319 | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
| 8320 | #define OS_REGISTER_AT_FORK_METHODDEF |
| 8321 | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
| 8322 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8323 | #ifndef OS_FORK1_METHODDEF |
| 8324 | #define OS_FORK1_METHODDEF |
| 8325 | #endif /* !defined(OS_FORK1_METHODDEF) */ |
| 8326 | |
| 8327 | #ifndef OS_FORK_METHODDEF |
| 8328 | #define OS_FORK_METHODDEF |
| 8329 | #endif /* !defined(OS_FORK_METHODDEF) */ |
| 8330 | |
| 8331 | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 8332 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 8333 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
| 8334 | |
| 8335 | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 8336 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 8337 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
| 8338 | |
| 8339 | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
| 8340 | #define OS_SCHED_GETSCHEDULER_METHODDEF |
| 8341 | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
| 8342 | |
| 8343 | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
| 8344 | #define OS_SCHED_SETSCHEDULER_METHODDEF |
| 8345 | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
| 8346 | |
| 8347 | #ifndef OS_SCHED_GETPARAM_METHODDEF |
| 8348 | #define OS_SCHED_GETPARAM_METHODDEF |
| 8349 | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
| 8350 | |
| 8351 | #ifndef OS_SCHED_SETPARAM_METHODDEF |
| 8352 | #define OS_SCHED_SETPARAM_METHODDEF |
| 8353 | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
| 8354 | |
| 8355 | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 8356 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 8357 | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
| 8358 | |
| 8359 | #ifndef OS_SCHED_YIELD_METHODDEF |
| 8360 | #define OS_SCHED_YIELD_METHODDEF |
| 8361 | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
| 8362 | |
| 8363 | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
| 8364 | #define OS_SCHED_SETAFFINITY_METHODDEF |
| 8365 | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
| 8366 | |
| 8367 | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
| 8368 | #define OS_SCHED_GETAFFINITY_METHODDEF |
| 8369 | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
| 8370 | |
| 8371 | #ifndef OS_OPENPTY_METHODDEF |
| 8372 | #define OS_OPENPTY_METHODDEF |
| 8373 | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
| 8374 | |
| 8375 | #ifndef OS_FORKPTY_METHODDEF |
| 8376 | #define OS_FORKPTY_METHODDEF |
| 8377 | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
| 8378 | |
| 8379 | #ifndef OS_GETEGID_METHODDEF |
| 8380 | #define OS_GETEGID_METHODDEF |
| 8381 | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
| 8382 | |
| 8383 | #ifndef OS_GETEUID_METHODDEF |
| 8384 | #define OS_GETEUID_METHODDEF |
| 8385 | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
| 8386 | |
| 8387 | #ifndef OS_GETGID_METHODDEF |
| 8388 | #define OS_GETGID_METHODDEF |
| 8389 | #endif /* !defined(OS_GETGID_METHODDEF) */ |
| 8390 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 8391 | #ifndef OS_GETPID_METHODDEF |
| 8392 | #define OS_GETPID_METHODDEF |
| 8393 | #endif /* !defined(OS_GETPID_METHODDEF) */ |
| 8394 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8395 | #ifndef OS_GETGROUPS_METHODDEF |
| 8396 | #define OS_GETGROUPS_METHODDEF |
| 8397 | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
| 8398 | |
| 8399 | #ifndef OS_GETPGID_METHODDEF |
| 8400 | #define OS_GETPGID_METHODDEF |
| 8401 | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
| 8402 | |
| 8403 | #ifndef OS_GETPGRP_METHODDEF |
| 8404 | #define OS_GETPGRP_METHODDEF |
| 8405 | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
| 8406 | |
| 8407 | #ifndef OS_SETPGRP_METHODDEF |
| 8408 | #define OS_SETPGRP_METHODDEF |
| 8409 | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
| 8410 | |
| 8411 | #ifndef OS_GETPPID_METHODDEF |
| 8412 | #define OS_GETPPID_METHODDEF |
| 8413 | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
| 8414 | |
| 8415 | #ifndef OS_GETLOGIN_METHODDEF |
| 8416 | #define OS_GETLOGIN_METHODDEF |
| 8417 | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
| 8418 | |
| 8419 | #ifndef OS_GETUID_METHODDEF |
| 8420 | #define OS_GETUID_METHODDEF |
| 8421 | #endif /* !defined(OS_GETUID_METHODDEF) */ |
| 8422 | |
| 8423 | #ifndef OS_KILL_METHODDEF |
| 8424 | #define OS_KILL_METHODDEF |
| 8425 | #endif /* !defined(OS_KILL_METHODDEF) */ |
| 8426 | |
| 8427 | #ifndef OS_KILLPG_METHODDEF |
| 8428 | #define OS_KILLPG_METHODDEF |
| 8429 | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
| 8430 | |
| 8431 | #ifndef OS_PLOCK_METHODDEF |
| 8432 | #define OS_PLOCK_METHODDEF |
| 8433 | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
| 8434 | |
| 8435 | #ifndef OS_SETUID_METHODDEF |
| 8436 | #define OS_SETUID_METHODDEF |
| 8437 | #endif /* !defined(OS_SETUID_METHODDEF) */ |
| 8438 | |
| 8439 | #ifndef OS_SETEUID_METHODDEF |
| 8440 | #define OS_SETEUID_METHODDEF |
| 8441 | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
| 8442 | |
| 8443 | #ifndef OS_SETEGID_METHODDEF |
| 8444 | #define OS_SETEGID_METHODDEF |
| 8445 | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
| 8446 | |
| 8447 | #ifndef OS_SETREUID_METHODDEF |
| 8448 | #define OS_SETREUID_METHODDEF |
| 8449 | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
| 8450 | |
| 8451 | #ifndef OS_SETREGID_METHODDEF |
| 8452 | #define OS_SETREGID_METHODDEF |
| 8453 | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
| 8454 | |
| 8455 | #ifndef OS_SETGID_METHODDEF |
| 8456 | #define OS_SETGID_METHODDEF |
| 8457 | #endif /* !defined(OS_SETGID_METHODDEF) */ |
| 8458 | |
| 8459 | #ifndef OS_SETGROUPS_METHODDEF |
| 8460 | #define OS_SETGROUPS_METHODDEF |
| 8461 | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
| 8462 | |
| 8463 | #ifndef OS_WAIT3_METHODDEF |
| 8464 | #define OS_WAIT3_METHODDEF |
| 8465 | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
| 8466 | |
| 8467 | #ifndef OS_WAIT4_METHODDEF |
| 8468 | #define OS_WAIT4_METHODDEF |
| 8469 | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
| 8470 | |
| 8471 | #ifndef OS_WAITID_METHODDEF |
| 8472 | #define OS_WAITID_METHODDEF |
| 8473 | #endif /* !defined(OS_WAITID_METHODDEF) */ |
| 8474 | |
| 8475 | #ifndef OS_WAITPID_METHODDEF |
| 8476 | #define OS_WAITPID_METHODDEF |
| 8477 | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
| 8478 | |
| 8479 | #ifndef OS_WAIT_METHODDEF |
| 8480 | #define OS_WAIT_METHODDEF |
| 8481 | #endif /* !defined(OS_WAIT_METHODDEF) */ |
| 8482 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 8483 | #ifndef OS_READLINK_METHODDEF |
| 8484 | #define OS_READLINK_METHODDEF |
| 8485 | #endif /* !defined(OS_READLINK_METHODDEF) */ |
| 8486 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8487 | #ifndef OS_SYMLINK_METHODDEF |
| 8488 | #define OS_SYMLINK_METHODDEF |
| 8489 | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
| 8490 | |
| 8491 | #ifndef OS_TIMES_METHODDEF |
| 8492 | #define OS_TIMES_METHODDEF |
| 8493 | #endif /* !defined(OS_TIMES_METHODDEF) */ |
| 8494 | |
| 8495 | #ifndef OS_GETSID_METHODDEF |
| 8496 | #define OS_GETSID_METHODDEF |
| 8497 | #endif /* !defined(OS_GETSID_METHODDEF) */ |
| 8498 | |
| 8499 | #ifndef OS_SETSID_METHODDEF |
| 8500 | #define OS_SETSID_METHODDEF |
| 8501 | #endif /* !defined(OS_SETSID_METHODDEF) */ |
| 8502 | |
| 8503 | #ifndef OS_SETPGID_METHODDEF |
| 8504 | #define OS_SETPGID_METHODDEF |
| 8505 | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
| 8506 | |
| 8507 | #ifndef OS_TCGETPGRP_METHODDEF |
| 8508 | #define OS_TCGETPGRP_METHODDEF |
| 8509 | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
| 8510 | |
| 8511 | #ifndef OS_TCSETPGRP_METHODDEF |
| 8512 | #define OS_TCSETPGRP_METHODDEF |
| 8513 | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
| 8514 | |
| 8515 | #ifndef OS_LOCKF_METHODDEF |
| 8516 | #define OS_LOCKF_METHODDEF |
| 8517 | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
| 8518 | |
| 8519 | #ifndef OS_READV_METHODDEF |
| 8520 | #define OS_READV_METHODDEF |
| 8521 | #endif /* !defined(OS_READV_METHODDEF) */ |
| 8522 | |
| 8523 | #ifndef OS_PREAD_METHODDEF |
| 8524 | #define OS_PREAD_METHODDEF |
| 8525 | #endif /* !defined(OS_PREAD_METHODDEF) */ |
| 8526 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 8527 | #ifndef OS_PREADV_METHODDEF |
| 8528 | #define OS_PREADV_METHODDEF |
| 8529 | #endif /* !defined(OS_PREADV_METHODDEF) */ |
| 8530 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 8531 | #ifndef OS__FCOPYFILE_METHODDEF |
| 8532 | #define OS__FCOPYFILE_METHODDEF |
| 8533 | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
| 8534 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8535 | #ifndef OS_PIPE_METHODDEF |
| 8536 | #define OS_PIPE_METHODDEF |
| 8537 | #endif /* !defined(OS_PIPE_METHODDEF) */ |
| 8538 | |
| 8539 | #ifndef OS_PIPE2_METHODDEF |
| 8540 | #define OS_PIPE2_METHODDEF |
| 8541 | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
| 8542 | |
| 8543 | #ifndef OS_WRITEV_METHODDEF |
| 8544 | #define OS_WRITEV_METHODDEF |
| 8545 | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
| 8546 | |
| 8547 | #ifndef OS_PWRITE_METHODDEF |
| 8548 | #define OS_PWRITE_METHODDEF |
| 8549 | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
| 8550 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 8551 | #ifndef OS_PWRITEV_METHODDEF |
| 8552 | #define OS_PWRITEV_METHODDEF |
| 8553 | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
| 8554 | |
Pablo Galindo | aac4d03 | 2019-05-31 19:39:47 +0100 | [diff] [blame] | 8555 | #ifndef OS_COPY_FILE_RANGE_METHODDEF |
| 8556 | #define OS_COPY_FILE_RANGE_METHODDEF |
| 8557 | #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */ |
| 8558 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8559 | #ifndef OS_MKFIFO_METHODDEF |
| 8560 | #define OS_MKFIFO_METHODDEF |
| 8561 | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
| 8562 | |
| 8563 | #ifndef OS_MKNOD_METHODDEF |
| 8564 | #define OS_MKNOD_METHODDEF |
| 8565 | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
| 8566 | |
| 8567 | #ifndef OS_MAJOR_METHODDEF |
| 8568 | #define OS_MAJOR_METHODDEF |
| 8569 | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
| 8570 | |
| 8571 | #ifndef OS_MINOR_METHODDEF |
| 8572 | #define OS_MINOR_METHODDEF |
| 8573 | #endif /* !defined(OS_MINOR_METHODDEF) */ |
| 8574 | |
| 8575 | #ifndef OS_MAKEDEV_METHODDEF |
| 8576 | #define OS_MAKEDEV_METHODDEF |
| 8577 | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
| 8578 | |
| 8579 | #ifndef OS_FTRUNCATE_METHODDEF |
| 8580 | #define OS_FTRUNCATE_METHODDEF |
| 8581 | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
| 8582 | |
| 8583 | #ifndef OS_TRUNCATE_METHODDEF |
| 8584 | #define OS_TRUNCATE_METHODDEF |
| 8585 | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
| 8586 | |
| 8587 | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
| 8588 | #define OS_POSIX_FALLOCATE_METHODDEF |
| 8589 | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
| 8590 | |
| 8591 | #ifndef OS_POSIX_FADVISE_METHODDEF |
| 8592 | #define OS_POSIX_FADVISE_METHODDEF |
| 8593 | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
| 8594 | |
| 8595 | #ifndef OS_PUTENV_METHODDEF |
| 8596 | #define OS_PUTENV_METHODDEF |
| 8597 | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
| 8598 | |
| 8599 | #ifndef OS_UNSETENV_METHODDEF |
| 8600 | #define OS_UNSETENV_METHODDEF |
| 8601 | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
| 8602 | |
| 8603 | #ifndef OS_WCOREDUMP_METHODDEF |
| 8604 | #define OS_WCOREDUMP_METHODDEF |
| 8605 | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
| 8606 | |
| 8607 | #ifndef OS_WIFCONTINUED_METHODDEF |
| 8608 | #define OS_WIFCONTINUED_METHODDEF |
| 8609 | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
| 8610 | |
| 8611 | #ifndef OS_WIFSTOPPED_METHODDEF |
| 8612 | #define OS_WIFSTOPPED_METHODDEF |
| 8613 | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
| 8614 | |
| 8615 | #ifndef OS_WIFSIGNALED_METHODDEF |
| 8616 | #define OS_WIFSIGNALED_METHODDEF |
| 8617 | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
| 8618 | |
| 8619 | #ifndef OS_WIFEXITED_METHODDEF |
| 8620 | #define OS_WIFEXITED_METHODDEF |
| 8621 | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
| 8622 | |
| 8623 | #ifndef OS_WEXITSTATUS_METHODDEF |
| 8624 | #define OS_WEXITSTATUS_METHODDEF |
| 8625 | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
| 8626 | |
| 8627 | #ifndef OS_WTERMSIG_METHODDEF |
| 8628 | #define OS_WTERMSIG_METHODDEF |
| 8629 | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
| 8630 | |
| 8631 | #ifndef OS_WSTOPSIG_METHODDEF |
| 8632 | #define OS_WSTOPSIG_METHODDEF |
| 8633 | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
| 8634 | |
| 8635 | #ifndef OS_FSTATVFS_METHODDEF |
| 8636 | #define OS_FSTATVFS_METHODDEF |
| 8637 | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
| 8638 | |
| 8639 | #ifndef OS_STATVFS_METHODDEF |
| 8640 | #define OS_STATVFS_METHODDEF |
| 8641 | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
| 8642 | |
| 8643 | #ifndef OS__GETDISKUSAGE_METHODDEF |
| 8644 | #define OS__GETDISKUSAGE_METHODDEF |
| 8645 | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
| 8646 | |
| 8647 | #ifndef OS_FPATHCONF_METHODDEF |
| 8648 | #define OS_FPATHCONF_METHODDEF |
| 8649 | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
| 8650 | |
| 8651 | #ifndef OS_PATHCONF_METHODDEF |
| 8652 | #define OS_PATHCONF_METHODDEF |
| 8653 | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
| 8654 | |
| 8655 | #ifndef OS_CONFSTR_METHODDEF |
| 8656 | #define OS_CONFSTR_METHODDEF |
| 8657 | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
| 8658 | |
| 8659 | #ifndef OS_SYSCONF_METHODDEF |
| 8660 | #define OS_SYSCONF_METHODDEF |
| 8661 | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
| 8662 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 8663 | #ifndef OS_STARTFILE_METHODDEF |
| 8664 | #define OS_STARTFILE_METHODDEF |
| 8665 | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
| 8666 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8667 | #ifndef OS_GETLOADAVG_METHODDEF |
| 8668 | #define OS_GETLOADAVG_METHODDEF |
| 8669 | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
| 8670 | |
| 8671 | #ifndef OS_SETRESUID_METHODDEF |
| 8672 | #define OS_SETRESUID_METHODDEF |
| 8673 | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
| 8674 | |
| 8675 | #ifndef OS_SETRESGID_METHODDEF |
| 8676 | #define OS_SETRESGID_METHODDEF |
| 8677 | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
| 8678 | |
| 8679 | #ifndef OS_GETRESUID_METHODDEF |
| 8680 | #define OS_GETRESUID_METHODDEF |
| 8681 | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
| 8682 | |
| 8683 | #ifndef OS_GETRESGID_METHODDEF |
| 8684 | #define OS_GETRESGID_METHODDEF |
| 8685 | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
| 8686 | |
| 8687 | #ifndef OS_GETXATTR_METHODDEF |
| 8688 | #define OS_GETXATTR_METHODDEF |
| 8689 | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
| 8690 | |
| 8691 | #ifndef OS_SETXATTR_METHODDEF |
| 8692 | #define OS_SETXATTR_METHODDEF |
| 8693 | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
| 8694 | |
| 8695 | #ifndef OS_REMOVEXATTR_METHODDEF |
| 8696 | #define OS_REMOVEXATTR_METHODDEF |
| 8697 | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
| 8698 | |
| 8699 | #ifndef OS_LISTXATTR_METHODDEF |
| 8700 | #define OS_LISTXATTR_METHODDEF |
| 8701 | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
| 8702 | |
Zackery Spytz | 43fdbd2 | 2019-05-29 13:57:07 -0600 | [diff] [blame] | 8703 | #ifndef OS_MEMFD_CREATE_METHODDEF |
| 8704 | #define OS_MEMFD_CREATE_METHODDEF |
| 8705 | #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */ |
| 8706 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8707 | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 8708 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 8709 | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
| 8710 | |
| 8711 | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 8712 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 8713 | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 8714 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 8715 | #ifndef OS_GET_BLOCKING_METHODDEF |
| 8716 | #define OS_GET_BLOCKING_METHODDEF |
| 8717 | #endif /* !defined(OS_GET_BLOCKING_METHODDEF) */ |
| 8718 | |
| 8719 | #ifndef OS_SET_BLOCKING_METHODDEF |
| 8720 | #define OS_SET_BLOCKING_METHODDEF |
| 8721 | #endif /* !defined(OS_SET_BLOCKING_METHODDEF) */ |
| 8722 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 8723 | #ifndef OS_GETRANDOM_METHODDEF |
| 8724 | #define OS_GETRANDOM_METHODDEF |
| 8725 | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 8726 | |
| 8727 | #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF |
| 8728 | #define OS__ADD_DLL_DIRECTORY_METHODDEF |
| 8729 | #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */ |
| 8730 | |
| 8731 | #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF |
| 8732 | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF |
| 8733 | #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */ |
Serhiy Storchaka | 140a7d1 | 2019-10-13 11:59:31 +0300 | [diff] [blame] | 8734 | /*[clinic end generated code: output=fe7897441fed5402 input=a9049054013a1b77]*/ |