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])) { |
| 619 | _PyArg_BadArgument("chflags", 2, "int", args[1]); |
| 620 | goto exit; |
| 621 | } |
| 622 | flags = PyLong_AsUnsignedLongMask(args[1]); |
| 623 | if (!noptargs) { |
| 624 | goto skip_optional_pos; |
| 625 | } |
| 626 | follow_symlinks = PyObject_IsTrue(args[2]); |
| 627 | if (follow_symlinks < 0) { |
| 628 | goto exit; |
| 629 | } |
| 630 | skip_optional_pos: |
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])) { |
| 677 | _PyArg_BadArgument("lchflags", 2, "int", args[1]); |
| 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 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1275 | PyDoc_STRVAR(os__isdir__doc__, |
| 1276 | "_isdir($module, path, /)\n" |
| 1277 | "--\n" |
Serhiy Storchaka | 579f038 | 2016-11-08 20:21:22 +0200 | [diff] [blame] | 1278 | "\n" |
| 1279 | "Return true if the pathname refers to an existing directory."); |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1280 | |
| 1281 | #define OS__ISDIR_METHODDEF \ |
| 1282 | {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__}, |
| 1283 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1284 | #endif /* defined(MS_WINDOWS) */ |
| 1285 | |
| 1286 | #if defined(MS_WINDOWS) |
| 1287 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1288 | PyDoc_STRVAR(os__getvolumepathname__doc__, |
| 1289 | "_getvolumepathname($module, /, path)\n" |
| 1290 | "--\n" |
| 1291 | "\n" |
| 1292 | "A helper function for ismount on Win32."); |
| 1293 | |
| 1294 | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1295 | {"_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] | 1296 | |
| 1297 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1298 | os__getvolumepathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1299 | |
| 1300 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1301 | 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] | 1302 | { |
| 1303 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1304 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1305 | static _PyArg_Parser _parser = {NULL, _keywords, "_getvolumepathname", 0}; |
| 1306 | PyObject *argsbuf[1]; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1307 | path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1308 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1309 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1310 | if (!args) { |
| 1311 | goto exit; |
| 1312 | } |
| 1313 | if (!path_converter(args[0], &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1314 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1315 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1316 | return_value = os__getvolumepathname_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1317 | |
| 1318 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1319 | /* Cleanup for path */ |
| 1320 | path_cleanup(&path); |
| 1321 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1322 | return return_value; |
| 1323 | } |
| 1324 | |
| 1325 | #endif /* defined(MS_WINDOWS) */ |
| 1326 | |
| 1327 | PyDoc_STRVAR(os_mkdir__doc__, |
| 1328 | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
| 1329 | "--\n" |
| 1330 | "\n" |
| 1331 | "Create a directory.\n" |
| 1332 | "\n" |
| 1333 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1334 | " and path should be relative; path will then be relative to that directory.\n" |
| 1335 | "dir_fd may not be implemented on your platform.\n" |
| 1336 | " If it is unavailable, using it will raise a NotImplementedError.\n" |
| 1337 | "\n" |
| 1338 | "The mode argument is ignored on Windows."); |
| 1339 | |
| 1340 | #define OS_MKDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1341 | {"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] | 1342 | |
| 1343 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1344 | 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] | 1345 | |
| 1346 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1347 | 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] | 1348 | { |
| 1349 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1350 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1351 | static _PyArg_Parser _parser = {NULL, _keywords, "mkdir", 0}; |
| 1352 | PyObject *argsbuf[3]; |
| 1353 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1354 | path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0); |
| 1355 | int mode = 511; |
| 1356 | int dir_fd = DEFAULT_DIR_FD; |
| 1357 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1358 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 1359 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1360 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1361 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1362 | if (!path_converter(args[0], &path)) { |
| 1363 | goto exit; |
| 1364 | } |
| 1365 | if (!noptargs) { |
| 1366 | goto skip_optional_pos; |
| 1367 | } |
| 1368 | if (args[1]) { |
| 1369 | if (PyFloat_Check(args[1])) { |
| 1370 | PyErr_SetString(PyExc_TypeError, |
| 1371 | "integer argument expected, got float" ); |
| 1372 | goto exit; |
| 1373 | } |
| 1374 | mode = _PyLong_AsInt(args[1]); |
| 1375 | if (mode == -1 && PyErr_Occurred()) { |
| 1376 | goto exit; |
| 1377 | } |
| 1378 | if (!--noptargs) { |
| 1379 | goto skip_optional_pos; |
| 1380 | } |
| 1381 | } |
| 1382 | skip_optional_pos: |
| 1383 | if (!noptargs) { |
| 1384 | goto skip_optional_kwonly; |
| 1385 | } |
| 1386 | if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
| 1387 | goto exit; |
| 1388 | } |
| 1389 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1390 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
| 1391 | |
| 1392 | exit: |
| 1393 | /* Cleanup for path */ |
| 1394 | path_cleanup(&path); |
| 1395 | |
| 1396 | return return_value; |
| 1397 | } |
| 1398 | |
| 1399 | #if defined(HAVE_NICE) |
| 1400 | |
| 1401 | PyDoc_STRVAR(os_nice__doc__, |
| 1402 | "nice($module, increment, /)\n" |
| 1403 | "--\n" |
| 1404 | "\n" |
| 1405 | "Add increment to the priority of process and return the new priority."); |
| 1406 | |
| 1407 | #define OS_NICE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1408 | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1409 | |
| 1410 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1411 | os_nice_impl(PyObject *module, int increment); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1412 | |
| 1413 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1414 | os_nice(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1415 | { |
| 1416 | PyObject *return_value = NULL; |
| 1417 | int increment; |
| 1418 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1419 | if (PyFloat_Check(arg)) { |
| 1420 | PyErr_SetString(PyExc_TypeError, |
| 1421 | "integer argument expected, got float" ); |
| 1422 | goto exit; |
| 1423 | } |
| 1424 | increment = _PyLong_AsInt(arg); |
| 1425 | if (increment == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1426 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1427 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1428 | return_value = os_nice_impl(module, increment); |
| 1429 | |
| 1430 | exit: |
| 1431 | return return_value; |
| 1432 | } |
| 1433 | |
| 1434 | #endif /* defined(HAVE_NICE) */ |
| 1435 | |
| 1436 | #if defined(HAVE_GETPRIORITY) |
| 1437 | |
| 1438 | PyDoc_STRVAR(os_getpriority__doc__, |
| 1439 | "getpriority($module, /, which, who)\n" |
| 1440 | "--\n" |
| 1441 | "\n" |
| 1442 | "Return program scheduling priority."); |
| 1443 | |
| 1444 | #define OS_GETPRIORITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1445 | {"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] | 1446 | |
| 1447 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1448 | os_getpriority_impl(PyObject *module, int which, int who); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1449 | |
| 1450 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1451 | 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] | 1452 | { |
| 1453 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1454 | static const char * const _keywords[] = {"which", "who", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1455 | static _PyArg_Parser _parser = {NULL, _keywords, "getpriority", 0}; |
| 1456 | PyObject *argsbuf[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1457 | int which; |
| 1458 | int who; |
| 1459 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1460 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1461 | if (!args) { |
| 1462 | goto exit; |
| 1463 | } |
| 1464 | if (PyFloat_Check(args[0])) { |
| 1465 | PyErr_SetString(PyExc_TypeError, |
| 1466 | "integer argument expected, got float" ); |
| 1467 | goto exit; |
| 1468 | } |
| 1469 | which = _PyLong_AsInt(args[0]); |
| 1470 | if (which == -1 && PyErr_Occurred()) { |
| 1471 | goto exit; |
| 1472 | } |
| 1473 | if (PyFloat_Check(args[1])) { |
| 1474 | PyErr_SetString(PyExc_TypeError, |
| 1475 | "integer argument expected, got float" ); |
| 1476 | goto exit; |
| 1477 | } |
| 1478 | who = _PyLong_AsInt(args[1]); |
| 1479 | if (who == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1480 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1481 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1482 | return_value = os_getpriority_impl(module, which, who); |
| 1483 | |
| 1484 | exit: |
| 1485 | return return_value; |
| 1486 | } |
| 1487 | |
| 1488 | #endif /* defined(HAVE_GETPRIORITY) */ |
| 1489 | |
| 1490 | #if defined(HAVE_SETPRIORITY) |
| 1491 | |
| 1492 | PyDoc_STRVAR(os_setpriority__doc__, |
| 1493 | "setpriority($module, /, which, who, priority)\n" |
| 1494 | "--\n" |
| 1495 | "\n" |
| 1496 | "Set program scheduling priority."); |
| 1497 | |
| 1498 | #define OS_SETPRIORITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1499 | {"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] | 1500 | |
| 1501 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1502 | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1503 | |
| 1504 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1505 | 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] | 1506 | { |
| 1507 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1508 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1509 | static _PyArg_Parser _parser = {NULL, _keywords, "setpriority", 0}; |
| 1510 | PyObject *argsbuf[3]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1511 | int which; |
| 1512 | int who; |
| 1513 | int priority; |
| 1514 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1515 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 1516 | if (!args) { |
| 1517 | goto exit; |
| 1518 | } |
| 1519 | if (PyFloat_Check(args[0])) { |
| 1520 | PyErr_SetString(PyExc_TypeError, |
| 1521 | "integer argument expected, got float" ); |
| 1522 | goto exit; |
| 1523 | } |
| 1524 | which = _PyLong_AsInt(args[0]); |
| 1525 | if (which == -1 && PyErr_Occurred()) { |
| 1526 | goto exit; |
| 1527 | } |
| 1528 | if (PyFloat_Check(args[1])) { |
| 1529 | PyErr_SetString(PyExc_TypeError, |
| 1530 | "integer argument expected, got float" ); |
| 1531 | goto exit; |
| 1532 | } |
| 1533 | who = _PyLong_AsInt(args[1]); |
| 1534 | if (who == -1 && PyErr_Occurred()) { |
| 1535 | goto exit; |
| 1536 | } |
| 1537 | if (PyFloat_Check(args[2])) { |
| 1538 | PyErr_SetString(PyExc_TypeError, |
| 1539 | "integer argument expected, got float" ); |
| 1540 | goto exit; |
| 1541 | } |
| 1542 | priority = _PyLong_AsInt(args[2]); |
| 1543 | if (priority == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1544 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1545 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1546 | return_value = os_setpriority_impl(module, which, who, priority); |
| 1547 | |
| 1548 | exit: |
| 1549 | return return_value; |
| 1550 | } |
| 1551 | |
| 1552 | #endif /* defined(HAVE_SETPRIORITY) */ |
| 1553 | |
| 1554 | PyDoc_STRVAR(os_rename__doc__, |
| 1555 | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1556 | "--\n" |
| 1557 | "\n" |
| 1558 | "Rename a file or directory.\n" |
| 1559 | "\n" |
| 1560 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1561 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1562 | " should be relative; the path will then be relative to that directory.\n" |
| 1563 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1564 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1565 | |
| 1566 | #define OS_RENAME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1567 | {"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] | 1568 | |
| 1569 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1570 | 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] | 1571 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1572 | |
| 1573 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1574 | 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] | 1575 | { |
| 1576 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1577 | 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] | 1578 | static _PyArg_Parser _parser = {NULL, _keywords, "rename", 0}; |
| 1579 | PyObject *argsbuf[4]; |
| 1580 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1581 | path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0); |
| 1582 | path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0); |
| 1583 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1584 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1585 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1586 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1587 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1588 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1589 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1590 | if (!path_converter(args[0], &src)) { |
| 1591 | goto exit; |
| 1592 | } |
| 1593 | if (!path_converter(args[1], &dst)) { |
| 1594 | goto exit; |
| 1595 | } |
| 1596 | if (!noptargs) { |
| 1597 | goto skip_optional_kwonly; |
| 1598 | } |
| 1599 | if (args[2]) { |
| 1600 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
| 1601 | goto exit; |
| 1602 | } |
| 1603 | if (!--noptargs) { |
| 1604 | goto skip_optional_kwonly; |
| 1605 | } |
| 1606 | } |
| 1607 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
| 1608 | goto exit; |
| 1609 | } |
| 1610 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1611 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1612 | |
| 1613 | exit: |
| 1614 | /* Cleanup for src */ |
| 1615 | path_cleanup(&src); |
| 1616 | /* Cleanup for dst */ |
| 1617 | path_cleanup(&dst); |
| 1618 | |
| 1619 | return return_value; |
| 1620 | } |
| 1621 | |
| 1622 | PyDoc_STRVAR(os_replace__doc__, |
| 1623 | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1624 | "--\n" |
| 1625 | "\n" |
| 1626 | "Rename a file or directory, overwriting the destination.\n" |
| 1627 | "\n" |
| 1628 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1629 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1630 | " should be relative; the path will then be relative to that directory.\n" |
| 1631 | "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] | 1632 | " If they are unavailable, using them will raise a NotImplementedError."); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1633 | |
| 1634 | #define OS_REPLACE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1635 | {"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] | 1636 | |
| 1637 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1638 | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
| 1639 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1640 | |
| 1641 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1642 | 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] | 1643 | { |
| 1644 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1645 | 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] | 1646 | static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0}; |
| 1647 | PyObject *argsbuf[4]; |
| 1648 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1649 | path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0); |
| 1650 | path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0); |
| 1651 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1652 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1653 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1654 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1655 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1656 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1657 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1658 | if (!path_converter(args[0], &src)) { |
| 1659 | goto exit; |
| 1660 | } |
| 1661 | if (!path_converter(args[1], &dst)) { |
| 1662 | goto exit; |
| 1663 | } |
| 1664 | if (!noptargs) { |
| 1665 | goto skip_optional_kwonly; |
| 1666 | } |
| 1667 | if (args[2]) { |
| 1668 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
| 1669 | goto exit; |
| 1670 | } |
| 1671 | if (!--noptargs) { |
| 1672 | goto skip_optional_kwonly; |
| 1673 | } |
| 1674 | } |
| 1675 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
| 1676 | goto exit; |
| 1677 | } |
| 1678 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1679 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1680 | |
| 1681 | exit: |
| 1682 | /* Cleanup for src */ |
| 1683 | path_cleanup(&src); |
| 1684 | /* Cleanup for dst */ |
| 1685 | path_cleanup(&dst); |
| 1686 | |
| 1687 | return return_value; |
| 1688 | } |
| 1689 | |
| 1690 | PyDoc_STRVAR(os_rmdir__doc__, |
| 1691 | "rmdir($module, /, path, *, dir_fd=None)\n" |
| 1692 | "--\n" |
| 1693 | "\n" |
| 1694 | "Remove a directory.\n" |
| 1695 | "\n" |
| 1696 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1697 | " and path should be relative; path will then be relative to that directory.\n" |
| 1698 | "dir_fd may not be implemented on your platform.\n" |
| 1699 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1700 | |
| 1701 | #define OS_RMDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1702 | {"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] | 1703 | |
| 1704 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1705 | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1706 | |
| 1707 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1708 | 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] | 1709 | { |
| 1710 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1711 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1712 | static _PyArg_Parser _parser = {NULL, _keywords, "rmdir", 0}; |
| 1713 | PyObject *argsbuf[2]; |
| 1714 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1715 | path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0); |
| 1716 | int dir_fd = DEFAULT_DIR_FD; |
| 1717 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1718 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1719 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1720 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1721 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1722 | if (!path_converter(args[0], &path)) { |
| 1723 | goto exit; |
| 1724 | } |
| 1725 | if (!noptargs) { |
| 1726 | goto skip_optional_kwonly; |
| 1727 | } |
| 1728 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 1729 | goto exit; |
| 1730 | } |
| 1731 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1732 | return_value = os_rmdir_impl(module, &path, dir_fd); |
| 1733 | |
| 1734 | exit: |
| 1735 | /* Cleanup for path */ |
| 1736 | path_cleanup(&path); |
| 1737 | |
| 1738 | return return_value; |
| 1739 | } |
| 1740 | |
| 1741 | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
| 1742 | |
| 1743 | PyDoc_STRVAR(os_system__doc__, |
| 1744 | "system($module, /, command)\n" |
| 1745 | "--\n" |
| 1746 | "\n" |
| 1747 | "Execute the command in a subshell."); |
| 1748 | |
| 1749 | #define OS_SYSTEM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1750 | {"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] | 1751 | |
| 1752 | static long |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 1753 | os_system_impl(PyObject *module, const Py_UNICODE *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1754 | |
| 1755 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1756 | 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] | 1757 | { |
| 1758 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1759 | static const char * const _keywords[] = {"command", NULL}; |
| 1760 | static _PyArg_Parser _parser = {"u:system", _keywords, 0}; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 1761 | const Py_UNICODE *command; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1762 | long _return_value; |
| 1763 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1764 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1765 | &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1766 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1767 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1768 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1769 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1770 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1771 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1772 | return_value = PyLong_FromLong(_return_value); |
| 1773 | |
| 1774 | exit: |
| 1775 | return return_value; |
| 1776 | } |
| 1777 | |
| 1778 | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
| 1779 | |
| 1780 | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
| 1781 | |
| 1782 | PyDoc_STRVAR(os_system__doc__, |
| 1783 | "system($module, /, command)\n" |
| 1784 | "--\n" |
| 1785 | "\n" |
| 1786 | "Execute the command in a subshell."); |
| 1787 | |
| 1788 | #define OS_SYSTEM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1789 | {"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] | 1790 | |
| 1791 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1792 | os_system_impl(PyObject *module, PyObject *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1793 | |
| 1794 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1795 | 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] | 1796 | { |
| 1797 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1798 | static const char * const _keywords[] = {"command", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1799 | static _PyArg_Parser _parser = {NULL, _keywords, "system", 0}; |
| 1800 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1801 | PyObject *command = NULL; |
| 1802 | long _return_value; |
| 1803 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1804 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1805 | if (!args) { |
| 1806 | goto exit; |
| 1807 | } |
| 1808 | if (!PyUnicode_FSConverter(args[0], &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1809 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1810 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1811 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1812 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1813 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1814 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1815 | return_value = PyLong_FromLong(_return_value); |
| 1816 | |
| 1817 | exit: |
| 1818 | /* Cleanup for command */ |
| 1819 | Py_XDECREF(command); |
| 1820 | |
| 1821 | return return_value; |
| 1822 | } |
| 1823 | |
| 1824 | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
| 1825 | |
| 1826 | PyDoc_STRVAR(os_umask__doc__, |
| 1827 | "umask($module, mask, /)\n" |
| 1828 | "--\n" |
| 1829 | "\n" |
| 1830 | "Set the current numeric umask and return the previous umask."); |
| 1831 | |
| 1832 | #define OS_UMASK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1833 | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1834 | |
| 1835 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1836 | os_umask_impl(PyObject *module, int mask); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1837 | |
| 1838 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1839 | os_umask(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1840 | { |
| 1841 | PyObject *return_value = NULL; |
| 1842 | int mask; |
| 1843 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1844 | if (PyFloat_Check(arg)) { |
| 1845 | PyErr_SetString(PyExc_TypeError, |
| 1846 | "integer argument expected, got float" ); |
| 1847 | goto exit; |
| 1848 | } |
| 1849 | mask = _PyLong_AsInt(arg); |
| 1850 | if (mask == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1851 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1852 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1853 | return_value = os_umask_impl(module, mask); |
| 1854 | |
| 1855 | exit: |
| 1856 | return return_value; |
| 1857 | } |
| 1858 | |
| 1859 | PyDoc_STRVAR(os_unlink__doc__, |
| 1860 | "unlink($module, /, path, *, dir_fd=None)\n" |
| 1861 | "--\n" |
| 1862 | "\n" |
| 1863 | "Remove a file (same as remove()).\n" |
| 1864 | "\n" |
| 1865 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1866 | " and path should be relative; path will then be relative to that directory.\n" |
| 1867 | "dir_fd may not be implemented on your platform.\n" |
| 1868 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1869 | |
| 1870 | #define OS_UNLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1871 | {"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] | 1872 | |
| 1873 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1874 | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1875 | |
| 1876 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1877 | 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] | 1878 | { |
| 1879 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1880 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1881 | static _PyArg_Parser _parser = {NULL, _keywords, "unlink", 0}; |
| 1882 | PyObject *argsbuf[2]; |
| 1883 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1884 | path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0); |
| 1885 | int dir_fd = DEFAULT_DIR_FD; |
| 1886 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1887 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1888 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1889 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1890 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1891 | if (!path_converter(args[0], &path)) { |
| 1892 | goto exit; |
| 1893 | } |
| 1894 | if (!noptargs) { |
| 1895 | goto skip_optional_kwonly; |
| 1896 | } |
| 1897 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 1898 | goto exit; |
| 1899 | } |
| 1900 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1901 | return_value = os_unlink_impl(module, &path, dir_fd); |
| 1902 | |
| 1903 | exit: |
| 1904 | /* Cleanup for path */ |
| 1905 | path_cleanup(&path); |
| 1906 | |
| 1907 | return return_value; |
| 1908 | } |
| 1909 | |
| 1910 | PyDoc_STRVAR(os_remove__doc__, |
| 1911 | "remove($module, /, path, *, dir_fd=None)\n" |
| 1912 | "--\n" |
| 1913 | "\n" |
| 1914 | "Remove a file (same as unlink()).\n" |
| 1915 | "\n" |
| 1916 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1917 | " and path should be relative; path will then be relative to that directory.\n" |
| 1918 | "dir_fd may not be implemented on your platform.\n" |
| 1919 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1920 | |
| 1921 | #define OS_REMOVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1922 | {"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] | 1923 | |
| 1924 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1925 | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1926 | |
| 1927 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1928 | 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] | 1929 | { |
| 1930 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1931 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1932 | static _PyArg_Parser _parser = {NULL, _keywords, "remove", 0}; |
| 1933 | PyObject *argsbuf[2]; |
| 1934 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1935 | path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0); |
| 1936 | int dir_fd = DEFAULT_DIR_FD; |
| 1937 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1938 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1939 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1940 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1941 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1942 | if (!path_converter(args[0], &path)) { |
| 1943 | goto exit; |
| 1944 | } |
| 1945 | if (!noptargs) { |
| 1946 | goto skip_optional_kwonly; |
| 1947 | } |
| 1948 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 1949 | goto exit; |
| 1950 | } |
| 1951 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1952 | return_value = os_remove_impl(module, &path, dir_fd); |
| 1953 | |
| 1954 | exit: |
| 1955 | /* Cleanup for path */ |
| 1956 | path_cleanup(&path); |
| 1957 | |
| 1958 | return return_value; |
| 1959 | } |
| 1960 | |
| 1961 | #if defined(HAVE_UNAME) |
| 1962 | |
| 1963 | PyDoc_STRVAR(os_uname__doc__, |
| 1964 | "uname($module, /)\n" |
| 1965 | "--\n" |
| 1966 | "\n" |
| 1967 | "Return an object identifying the current operating system.\n" |
| 1968 | "\n" |
| 1969 | "The object behaves like a named tuple with the following fields:\n" |
| 1970 | " (sysname, nodename, release, version, machine)"); |
| 1971 | |
| 1972 | #define OS_UNAME_METHODDEF \ |
| 1973 | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
| 1974 | |
| 1975 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1976 | os_uname_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1977 | |
| 1978 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1979 | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1980 | { |
| 1981 | return os_uname_impl(module); |
| 1982 | } |
| 1983 | |
| 1984 | #endif /* defined(HAVE_UNAME) */ |
| 1985 | |
| 1986 | PyDoc_STRVAR(os_utime__doc__, |
| 1987 | "utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n" |
| 1988 | " follow_symlinks=True)\n" |
| 1989 | "--\n" |
| 1990 | "\n" |
| 1991 | "Set the access and modified time of path.\n" |
| 1992 | "\n" |
| 1993 | "path may always be specified as a string.\n" |
| 1994 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 1995 | " If this functionality is unavailable, using it raises an exception.\n" |
| 1996 | "\n" |
| 1997 | "If times is not None, it must be a tuple (atime, mtime);\n" |
| 1998 | " 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] | 1999 | "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] | 2000 | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
| 2001 | " since the epoch.\n" |
Martin Panter | 0ff8909 | 2015-09-09 01:56:53 +0000 | [diff] [blame] | 2002 | "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] | 2003 | "Specifying tuples for both times and ns is an error.\n" |
| 2004 | "\n" |
| 2005 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 2006 | " and path should be relative; path will then be relative to that directory.\n" |
| 2007 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 2008 | " link, utime will modify the symbolic link itself instead of the file the\n" |
| 2009 | " link points to.\n" |
| 2010 | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
| 2011 | " as an open file descriptor.\n" |
| 2012 | "dir_fd and follow_symlinks may not be available on your platform.\n" |
| 2013 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 2014 | |
| 2015 | #define OS_UTIME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2016 | {"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] | 2017 | |
| 2018 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2019 | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
| 2020 | int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2021 | |
| 2022 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2023 | 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] | 2024 | { |
| 2025 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2026 | 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] | 2027 | static _PyArg_Parser _parser = {NULL, _keywords, "utime", 0}; |
| 2028 | PyObject *argsbuf[5]; |
| 2029 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2030 | path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD); |
| 2031 | PyObject *times = NULL; |
| 2032 | PyObject *ns = NULL; |
| 2033 | int dir_fd = DEFAULT_DIR_FD; |
| 2034 | int follow_symlinks = 1; |
| 2035 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2036 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 2037 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2038 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2039 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2040 | if (!path_converter(args[0], &path)) { |
| 2041 | goto exit; |
| 2042 | } |
| 2043 | if (!noptargs) { |
| 2044 | goto skip_optional_pos; |
| 2045 | } |
| 2046 | if (args[1]) { |
| 2047 | times = args[1]; |
| 2048 | if (!--noptargs) { |
| 2049 | goto skip_optional_pos; |
| 2050 | } |
| 2051 | } |
| 2052 | skip_optional_pos: |
| 2053 | if (!noptargs) { |
| 2054 | goto skip_optional_kwonly; |
| 2055 | } |
| 2056 | if (args[2]) { |
| 2057 | ns = args[2]; |
| 2058 | if (!--noptargs) { |
| 2059 | goto skip_optional_kwonly; |
| 2060 | } |
| 2061 | } |
| 2062 | if (args[3]) { |
| 2063 | if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
| 2064 | goto exit; |
| 2065 | } |
| 2066 | if (!--noptargs) { |
| 2067 | goto skip_optional_kwonly; |
| 2068 | } |
| 2069 | } |
| 2070 | follow_symlinks = PyObject_IsTrue(args[4]); |
| 2071 | if (follow_symlinks < 0) { |
| 2072 | goto exit; |
| 2073 | } |
| 2074 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2075 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
| 2076 | |
| 2077 | exit: |
| 2078 | /* Cleanup for path */ |
| 2079 | path_cleanup(&path); |
| 2080 | |
| 2081 | return return_value; |
| 2082 | } |
| 2083 | |
| 2084 | PyDoc_STRVAR(os__exit__doc__, |
| 2085 | "_exit($module, /, status)\n" |
| 2086 | "--\n" |
| 2087 | "\n" |
| 2088 | "Exit to the system with specified status, without normal exit processing."); |
| 2089 | |
| 2090 | #define OS__EXIT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2091 | {"_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] | 2092 | |
| 2093 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2094 | os__exit_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2095 | |
| 2096 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2097 | 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] | 2098 | { |
| 2099 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2100 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2101 | static _PyArg_Parser _parser = {NULL, _keywords, "_exit", 0}; |
| 2102 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2103 | int status; |
| 2104 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2105 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 2106 | if (!args) { |
| 2107 | goto exit; |
| 2108 | } |
| 2109 | if (PyFloat_Check(args[0])) { |
| 2110 | PyErr_SetString(PyExc_TypeError, |
| 2111 | "integer argument expected, got float" ); |
| 2112 | goto exit; |
| 2113 | } |
| 2114 | status = _PyLong_AsInt(args[0]); |
| 2115 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2116 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2117 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2118 | return_value = os__exit_impl(module, status); |
| 2119 | |
| 2120 | exit: |
| 2121 | return return_value; |
| 2122 | } |
| 2123 | |
| 2124 | #if defined(HAVE_EXECV) |
| 2125 | |
| 2126 | PyDoc_STRVAR(os_execv__doc__, |
| 2127 | "execv($module, path, argv, /)\n" |
| 2128 | "--\n" |
| 2129 | "\n" |
| 2130 | "Execute an executable path with arguments, replacing current process.\n" |
| 2131 | "\n" |
| 2132 | " path\n" |
| 2133 | " Path of executable file.\n" |
| 2134 | " argv\n" |
| 2135 | " Tuple or list of strings."); |
| 2136 | |
| 2137 | #define OS_EXECV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2138 | {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2139 | |
| 2140 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2141 | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2142 | |
| 2143 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2144 | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2145 | { |
| 2146 | PyObject *return_value = NULL; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2147 | path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2148 | PyObject *argv; |
| 2149 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2150 | if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2151 | goto exit; |
| 2152 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2153 | if (!path_converter(args[0], &path)) { |
| 2154 | goto exit; |
| 2155 | } |
| 2156 | argv = args[1]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2157 | return_value = os_execv_impl(module, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2158 | |
| 2159 | exit: |
| 2160 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2161 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2162 | |
| 2163 | return return_value; |
| 2164 | } |
| 2165 | |
| 2166 | #endif /* defined(HAVE_EXECV) */ |
| 2167 | |
| 2168 | #if defined(HAVE_EXECV) |
| 2169 | |
| 2170 | PyDoc_STRVAR(os_execve__doc__, |
| 2171 | "execve($module, /, path, argv, env)\n" |
| 2172 | "--\n" |
| 2173 | "\n" |
| 2174 | "Execute an executable path with arguments, replacing current process.\n" |
| 2175 | "\n" |
| 2176 | " path\n" |
| 2177 | " Path of executable file.\n" |
| 2178 | " argv\n" |
| 2179 | " Tuple or list of strings.\n" |
| 2180 | " env\n" |
| 2181 | " Dictionary of strings mapping to strings."); |
| 2182 | |
| 2183 | #define OS_EXECVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2184 | {"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] | 2185 | |
| 2186 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2187 | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2188 | |
| 2189 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2190 | 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] | 2191 | { |
| 2192 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2193 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2194 | static _PyArg_Parser _parser = {NULL, _keywords, "execve", 0}; |
| 2195 | PyObject *argsbuf[3]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2196 | path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE); |
| 2197 | PyObject *argv; |
| 2198 | PyObject *env; |
| 2199 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2200 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 2201 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2202 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2203 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2204 | if (!path_converter(args[0], &path)) { |
| 2205 | goto exit; |
| 2206 | } |
| 2207 | argv = args[1]; |
| 2208 | env = args[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2209 | return_value = os_execve_impl(module, &path, argv, env); |
| 2210 | |
| 2211 | exit: |
| 2212 | /* Cleanup for path */ |
| 2213 | path_cleanup(&path); |
| 2214 | |
| 2215 | return return_value; |
| 2216 | } |
| 2217 | |
| 2218 | #endif /* defined(HAVE_EXECV) */ |
| 2219 | |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2220 | #if defined(HAVE_POSIX_SPAWN) |
| 2221 | |
| 2222 | PyDoc_STRVAR(os_posix_spawn__doc__, |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 2223 | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2224 | " setpgroup=None, resetids=False, setsid=False,\n" |
| 2225 | " setsigmask=(), setsigdef=(), scheduler=None)\n" |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2226 | "--\n" |
| 2227 | "\n" |
| 2228 | "Execute the program specified by path in a new process.\n" |
| 2229 | "\n" |
| 2230 | " path\n" |
| 2231 | " Path of executable file.\n" |
| 2232 | " argv\n" |
| 2233 | " Tuple or list of strings.\n" |
| 2234 | " env\n" |
| 2235 | " Dictionary of strings mapping to strings.\n" |
| 2236 | " file_actions\n" |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2237 | " A sequence of file action tuples.\n" |
| 2238 | " setpgroup\n" |
| 2239 | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
| 2240 | " resetids\n" |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2241 | " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n" |
| 2242 | " setsid\n" |
| 2243 | " 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] | 2244 | " setsigmask\n" |
| 2245 | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
| 2246 | " setsigdef\n" |
| 2247 | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
| 2248 | " scheduler\n" |
| 2249 | " A tuple with the scheduler policy (optional) and parameters."); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2250 | |
| 2251 | #define OS_POSIX_SPAWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2252 | {"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] | 2253 | |
| 2254 | static PyObject * |
| 2255 | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2256 | PyObject *env, PyObject *file_actions, |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2257 | PyObject *setpgroup, int resetids, int setsid, |
| 2258 | PyObject *setsigmask, PyObject *setsigdef, |
| 2259 | PyObject *scheduler); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2260 | |
| 2261 | static PyObject * |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2262 | 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] | 2263 | { |
| 2264 | PyObject *return_value = NULL; |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2265 | 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] | 2266 | static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawn", 0}; |
| 2267 | PyObject *argsbuf[10]; |
| 2268 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2269 | path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0); |
| 2270 | PyObject *argv; |
| 2271 | PyObject *env; |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 2272 | PyObject *file_actions = NULL; |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2273 | PyObject *setpgroup = NULL; |
| 2274 | int resetids = 0; |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2275 | int setsid = 0; |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 2276 | PyObject *setsigmask = NULL; |
| 2277 | PyObject *setsigdef = NULL; |
| 2278 | PyObject *scheduler = NULL; |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2279 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2280 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 2281 | if (!args) { |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 2282 | goto exit; |
| 2283 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2284 | if (!path_converter(args[0], &path)) { |
| 2285 | goto exit; |
| 2286 | } |
| 2287 | argv = args[1]; |
| 2288 | env = args[2]; |
| 2289 | if (!noptargs) { |
| 2290 | goto skip_optional_kwonly; |
| 2291 | } |
| 2292 | if (args[3]) { |
| 2293 | file_actions = args[3]; |
| 2294 | if (!--noptargs) { |
| 2295 | goto skip_optional_kwonly; |
| 2296 | } |
| 2297 | } |
| 2298 | if (args[4]) { |
| 2299 | setpgroup = args[4]; |
| 2300 | if (!--noptargs) { |
| 2301 | goto skip_optional_kwonly; |
| 2302 | } |
| 2303 | } |
| 2304 | if (args[5]) { |
| 2305 | if (PyFloat_Check(args[5])) { |
| 2306 | PyErr_SetString(PyExc_TypeError, |
| 2307 | "integer argument expected, got float" ); |
| 2308 | goto exit; |
| 2309 | } |
| 2310 | resetids = _PyLong_AsInt(args[5]); |
| 2311 | if (resetids == -1 && PyErr_Occurred()) { |
| 2312 | goto exit; |
| 2313 | } |
| 2314 | if (!--noptargs) { |
| 2315 | goto skip_optional_kwonly; |
| 2316 | } |
| 2317 | } |
| 2318 | if (args[6]) { |
| 2319 | if (PyFloat_Check(args[6])) { |
| 2320 | PyErr_SetString(PyExc_TypeError, |
| 2321 | "integer argument expected, got float" ); |
| 2322 | goto exit; |
| 2323 | } |
| 2324 | setsid = _PyLong_AsInt(args[6]); |
| 2325 | if (setsid == -1 && PyErr_Occurred()) { |
| 2326 | goto exit; |
| 2327 | } |
| 2328 | if (!--noptargs) { |
| 2329 | goto skip_optional_kwonly; |
| 2330 | } |
| 2331 | } |
| 2332 | if (args[7]) { |
| 2333 | setsigmask = args[7]; |
| 2334 | if (!--noptargs) { |
| 2335 | goto skip_optional_kwonly; |
| 2336 | } |
| 2337 | } |
| 2338 | if (args[8]) { |
| 2339 | setsigdef = args[8]; |
| 2340 | if (!--noptargs) { |
| 2341 | goto skip_optional_kwonly; |
| 2342 | } |
| 2343 | } |
| 2344 | scheduler = args[9]; |
| 2345 | skip_optional_kwonly: |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2346 | 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] | 2347 | |
| 2348 | exit: |
| 2349 | /* Cleanup for path */ |
| 2350 | path_cleanup(&path); |
| 2351 | |
| 2352 | return return_value; |
| 2353 | } |
| 2354 | |
| 2355 | #endif /* defined(HAVE_POSIX_SPAWN) */ |
| 2356 | |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2357 | #if defined(HAVE_POSIX_SPAWNP) |
| 2358 | |
| 2359 | PyDoc_STRVAR(os_posix_spawnp__doc__, |
| 2360 | "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n" |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2361 | " setpgroup=None, resetids=False, setsid=False,\n" |
| 2362 | " setsigmask=(), setsigdef=(), scheduler=None)\n" |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2363 | "--\n" |
| 2364 | "\n" |
| 2365 | "Execute the program specified by path in a new process.\n" |
| 2366 | "\n" |
| 2367 | " path\n" |
| 2368 | " Path of executable file.\n" |
| 2369 | " argv\n" |
| 2370 | " Tuple or list of strings.\n" |
| 2371 | " env\n" |
| 2372 | " Dictionary of strings mapping to strings.\n" |
| 2373 | " file_actions\n" |
| 2374 | " A sequence of file action tuples.\n" |
| 2375 | " setpgroup\n" |
| 2376 | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
| 2377 | " resetids\n" |
| 2378 | " 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] | 2379 | " setsid\n" |
| 2380 | " 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] | 2381 | " setsigmask\n" |
| 2382 | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
| 2383 | " setsigdef\n" |
| 2384 | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
| 2385 | " scheduler\n" |
| 2386 | " A tuple with the scheduler policy (optional) and parameters."); |
| 2387 | |
| 2388 | #define OS_POSIX_SPAWNP_METHODDEF \ |
| 2389 | {"posix_spawnp", (PyCFunction)(void(*)(void))os_posix_spawnp, METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__}, |
| 2390 | |
| 2391 | static PyObject * |
| 2392 | os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv, |
| 2393 | PyObject *env, PyObject *file_actions, |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2394 | PyObject *setpgroup, int resetids, int setsid, |
| 2395 | PyObject *setsigmask, PyObject *setsigdef, |
| 2396 | PyObject *scheduler); |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2397 | |
| 2398 | static PyObject * |
| 2399 | os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 2400 | { |
| 2401 | PyObject *return_value = NULL; |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2402 | 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] | 2403 | static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawnp", 0}; |
| 2404 | PyObject *argsbuf[10]; |
| 2405 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2406 | path_t path = PATH_T_INITIALIZE("posix_spawnp", "path", 0, 0); |
| 2407 | PyObject *argv; |
| 2408 | PyObject *env; |
| 2409 | PyObject *file_actions = NULL; |
| 2410 | PyObject *setpgroup = NULL; |
| 2411 | int resetids = 0; |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2412 | int setsid = 0; |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2413 | PyObject *setsigmask = NULL; |
| 2414 | PyObject *setsigdef = NULL; |
| 2415 | PyObject *scheduler = NULL; |
| 2416 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2417 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
| 2418 | if (!args) { |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 2419 | goto exit; |
| 2420 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2421 | if (!path_converter(args[0], &path)) { |
| 2422 | goto exit; |
| 2423 | } |
| 2424 | argv = args[1]; |
| 2425 | env = args[2]; |
| 2426 | if (!noptargs) { |
| 2427 | goto skip_optional_kwonly; |
| 2428 | } |
| 2429 | if (args[3]) { |
| 2430 | file_actions = args[3]; |
| 2431 | if (!--noptargs) { |
| 2432 | goto skip_optional_kwonly; |
| 2433 | } |
| 2434 | } |
| 2435 | if (args[4]) { |
| 2436 | setpgroup = args[4]; |
| 2437 | if (!--noptargs) { |
| 2438 | goto skip_optional_kwonly; |
| 2439 | } |
| 2440 | } |
| 2441 | if (args[5]) { |
| 2442 | if (PyFloat_Check(args[5])) { |
| 2443 | PyErr_SetString(PyExc_TypeError, |
| 2444 | "integer argument expected, got float" ); |
| 2445 | goto exit; |
| 2446 | } |
| 2447 | resetids = _PyLong_AsInt(args[5]); |
| 2448 | if (resetids == -1 && PyErr_Occurred()) { |
| 2449 | goto exit; |
| 2450 | } |
| 2451 | if (!--noptargs) { |
| 2452 | goto skip_optional_kwonly; |
| 2453 | } |
| 2454 | } |
| 2455 | if (args[6]) { |
| 2456 | if (PyFloat_Check(args[6])) { |
| 2457 | PyErr_SetString(PyExc_TypeError, |
| 2458 | "integer argument expected, got float" ); |
| 2459 | goto exit; |
| 2460 | } |
| 2461 | setsid = _PyLong_AsInt(args[6]); |
| 2462 | if (setsid == -1 && PyErr_Occurred()) { |
| 2463 | goto exit; |
| 2464 | } |
| 2465 | if (!--noptargs) { |
| 2466 | goto skip_optional_kwonly; |
| 2467 | } |
| 2468 | } |
| 2469 | if (args[7]) { |
| 2470 | setsigmask = args[7]; |
| 2471 | if (!--noptargs) { |
| 2472 | goto skip_optional_kwonly; |
| 2473 | } |
| 2474 | } |
| 2475 | if (args[8]) { |
| 2476 | setsigdef = args[8]; |
| 2477 | if (!--noptargs) { |
| 2478 | goto skip_optional_kwonly; |
| 2479 | } |
| 2480 | } |
| 2481 | scheduler = args[9]; |
| 2482 | skip_optional_kwonly: |
Joannah Nanjekye | 80c5dfe | 2019-02-01 13:05:22 +0300 | [diff] [blame] | 2483 | 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] | 2484 | |
| 2485 | exit: |
| 2486 | /* Cleanup for path */ |
| 2487 | path_cleanup(&path); |
| 2488 | |
| 2489 | return return_value; |
| 2490 | } |
| 2491 | |
| 2492 | #endif /* defined(HAVE_POSIX_SPAWNP) */ |
| 2493 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2494 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2495 | |
| 2496 | PyDoc_STRVAR(os_spawnv__doc__, |
| 2497 | "spawnv($module, mode, path, argv, /)\n" |
| 2498 | "--\n" |
| 2499 | "\n" |
| 2500 | "Execute the program specified by path in a new process.\n" |
| 2501 | "\n" |
| 2502 | " mode\n" |
| 2503 | " Mode of process creation.\n" |
| 2504 | " path\n" |
| 2505 | " Path of executable file.\n" |
| 2506 | " argv\n" |
| 2507 | " Tuple or list of strings."); |
| 2508 | |
| 2509 | #define OS_SPAWNV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2510 | {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2511 | |
| 2512 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2513 | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2514 | |
| 2515 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2516 | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2517 | { |
| 2518 | PyObject *return_value = NULL; |
| 2519 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2520 | path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2521 | PyObject *argv; |
| 2522 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2523 | if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2524 | goto exit; |
| 2525 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2526 | if (PyFloat_Check(args[0])) { |
| 2527 | PyErr_SetString(PyExc_TypeError, |
| 2528 | "integer argument expected, got float" ); |
| 2529 | goto exit; |
| 2530 | } |
| 2531 | mode = _PyLong_AsInt(args[0]); |
| 2532 | if (mode == -1 && PyErr_Occurred()) { |
| 2533 | goto exit; |
| 2534 | } |
| 2535 | if (!path_converter(args[1], &path)) { |
| 2536 | goto exit; |
| 2537 | } |
| 2538 | argv = args[2]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2539 | return_value = os_spawnv_impl(module, mode, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2540 | |
| 2541 | exit: |
| 2542 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2543 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2544 | |
| 2545 | return return_value; |
| 2546 | } |
| 2547 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2548 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2549 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2550 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2551 | |
| 2552 | PyDoc_STRVAR(os_spawnve__doc__, |
| 2553 | "spawnve($module, mode, path, argv, env, /)\n" |
| 2554 | "--\n" |
| 2555 | "\n" |
| 2556 | "Execute the program specified by path in a new process.\n" |
| 2557 | "\n" |
| 2558 | " mode\n" |
| 2559 | " Mode of process creation.\n" |
| 2560 | " path\n" |
| 2561 | " Path of executable file.\n" |
| 2562 | " argv\n" |
| 2563 | " Tuple or list of strings.\n" |
| 2564 | " env\n" |
| 2565 | " Dictionary of strings mapping to strings."); |
| 2566 | |
| 2567 | #define OS_SPAWNVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2568 | {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2569 | |
| 2570 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2571 | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2572 | PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2573 | |
| 2574 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2575 | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2576 | { |
| 2577 | PyObject *return_value = NULL; |
| 2578 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2579 | path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2580 | PyObject *argv; |
| 2581 | PyObject *env; |
| 2582 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2583 | if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2584 | goto exit; |
| 2585 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2586 | if (PyFloat_Check(args[0])) { |
| 2587 | PyErr_SetString(PyExc_TypeError, |
| 2588 | "integer argument expected, got float" ); |
| 2589 | goto exit; |
| 2590 | } |
| 2591 | mode = _PyLong_AsInt(args[0]); |
| 2592 | if (mode == -1 && PyErr_Occurred()) { |
| 2593 | goto exit; |
| 2594 | } |
| 2595 | if (!path_converter(args[1], &path)) { |
| 2596 | goto exit; |
| 2597 | } |
| 2598 | argv = args[2]; |
| 2599 | env = args[3]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2600 | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2601 | |
| 2602 | exit: |
| 2603 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2604 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2605 | |
| 2606 | return return_value; |
| 2607 | } |
| 2608 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 2609 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2610 | |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2611 | #if defined(HAVE_FORK) |
| 2612 | |
| 2613 | PyDoc_STRVAR(os_register_at_fork__doc__, |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2614 | "register_at_fork($module, /, *, before=None, after_in_child=None,\n" |
| 2615 | " after_in_parent=None)\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2616 | "--\n" |
| 2617 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2618 | "Register callables to be called when forking a new process.\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2619 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2620 | " before\n" |
| 2621 | " A callable to be called in the parent before the fork() syscall.\n" |
| 2622 | " after_in_child\n" |
| 2623 | " A callable to be called in the child after fork().\n" |
| 2624 | " after_in_parent\n" |
| 2625 | " A callable to be called in the parent after fork().\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2626 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2627 | "\'before\' callbacks are called in reverse order.\n" |
| 2628 | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order."); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2629 | |
| 2630 | #define OS_REGISTER_AT_FORK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2631 | {"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] | 2632 | |
| 2633 | static PyObject * |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2634 | os_register_at_fork_impl(PyObject *module, PyObject *before, |
| 2635 | PyObject *after_in_child, PyObject *after_in_parent); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2636 | |
| 2637 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2638 | 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] | 2639 | { |
| 2640 | PyObject *return_value = NULL; |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2641 | 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] | 2642 | static _PyArg_Parser _parser = {NULL, _keywords, "register_at_fork", 0}; |
| 2643 | PyObject *argsbuf[3]; |
| 2644 | 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] | 2645 | PyObject *before = NULL; |
| 2646 | PyObject *after_in_child = NULL; |
| 2647 | PyObject *after_in_parent = NULL; |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2648 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2649 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 2650 | if (!args) { |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2651 | goto exit; |
| 2652 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2653 | if (!noptargs) { |
| 2654 | goto skip_optional_kwonly; |
| 2655 | } |
| 2656 | if (args[0]) { |
| 2657 | before = args[0]; |
| 2658 | if (!--noptargs) { |
| 2659 | goto skip_optional_kwonly; |
| 2660 | } |
| 2661 | } |
| 2662 | if (args[1]) { |
| 2663 | after_in_child = args[1]; |
| 2664 | if (!--noptargs) { |
| 2665 | goto skip_optional_kwonly; |
| 2666 | } |
| 2667 | } |
| 2668 | after_in_parent = args[2]; |
| 2669 | skip_optional_kwonly: |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2670 | 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] | 2671 | |
| 2672 | exit: |
| 2673 | return return_value; |
| 2674 | } |
| 2675 | |
| 2676 | #endif /* defined(HAVE_FORK) */ |
| 2677 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2678 | #if defined(HAVE_FORK1) |
| 2679 | |
| 2680 | PyDoc_STRVAR(os_fork1__doc__, |
| 2681 | "fork1($module, /)\n" |
| 2682 | "--\n" |
| 2683 | "\n" |
| 2684 | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
| 2685 | "\n" |
| 2686 | "Return 0 to child process and PID of child to parent process."); |
| 2687 | |
| 2688 | #define OS_FORK1_METHODDEF \ |
| 2689 | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
| 2690 | |
| 2691 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2692 | os_fork1_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2693 | |
| 2694 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2695 | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2696 | { |
| 2697 | return os_fork1_impl(module); |
| 2698 | } |
| 2699 | |
| 2700 | #endif /* defined(HAVE_FORK1) */ |
| 2701 | |
| 2702 | #if defined(HAVE_FORK) |
| 2703 | |
| 2704 | PyDoc_STRVAR(os_fork__doc__, |
| 2705 | "fork($module, /)\n" |
| 2706 | "--\n" |
| 2707 | "\n" |
| 2708 | "Fork a child process.\n" |
| 2709 | "\n" |
| 2710 | "Return 0 to child process and PID of child to parent process."); |
| 2711 | |
| 2712 | #define OS_FORK_METHODDEF \ |
| 2713 | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
| 2714 | |
| 2715 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2716 | os_fork_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2717 | |
| 2718 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2719 | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2720 | { |
| 2721 | return os_fork_impl(module); |
| 2722 | } |
| 2723 | |
| 2724 | #endif /* defined(HAVE_FORK) */ |
| 2725 | |
| 2726 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 2727 | |
| 2728 | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
| 2729 | "sched_get_priority_max($module, /, policy)\n" |
| 2730 | "--\n" |
| 2731 | "\n" |
| 2732 | "Get the maximum scheduling priority for policy."); |
| 2733 | |
| 2734 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2735 | {"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] | 2736 | |
| 2737 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2738 | os_sched_get_priority_max_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2739 | |
| 2740 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2741 | 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] | 2742 | { |
| 2743 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2744 | static const char * const _keywords[] = {"policy", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2745 | static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_max", 0}; |
| 2746 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2747 | int policy; |
| 2748 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2749 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 2750 | if (!args) { |
| 2751 | goto exit; |
| 2752 | } |
| 2753 | if (PyFloat_Check(args[0])) { |
| 2754 | PyErr_SetString(PyExc_TypeError, |
| 2755 | "integer argument expected, got float" ); |
| 2756 | goto exit; |
| 2757 | } |
| 2758 | policy = _PyLong_AsInt(args[0]); |
| 2759 | if (policy == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2760 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2761 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2762 | return_value = os_sched_get_priority_max_impl(module, policy); |
| 2763 | |
| 2764 | exit: |
| 2765 | return return_value; |
| 2766 | } |
| 2767 | |
| 2768 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 2769 | |
| 2770 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 2771 | |
| 2772 | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
| 2773 | "sched_get_priority_min($module, /, policy)\n" |
| 2774 | "--\n" |
| 2775 | "\n" |
| 2776 | "Get the minimum scheduling priority for policy."); |
| 2777 | |
| 2778 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2779 | {"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] | 2780 | |
| 2781 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2782 | os_sched_get_priority_min_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2783 | |
| 2784 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2785 | 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] | 2786 | { |
| 2787 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2788 | static const char * const _keywords[] = {"policy", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2789 | static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_min", 0}; |
| 2790 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2791 | int policy; |
| 2792 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2793 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 2794 | if (!args) { |
| 2795 | goto exit; |
| 2796 | } |
| 2797 | if (PyFloat_Check(args[0])) { |
| 2798 | PyErr_SetString(PyExc_TypeError, |
| 2799 | "integer argument expected, got float" ); |
| 2800 | goto exit; |
| 2801 | } |
| 2802 | policy = _PyLong_AsInt(args[0]); |
| 2803 | if (policy == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2804 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2805 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2806 | return_value = os_sched_get_priority_min_impl(module, policy); |
| 2807 | |
| 2808 | exit: |
| 2809 | return return_value; |
| 2810 | } |
| 2811 | |
| 2812 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 2813 | |
| 2814 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 2815 | |
| 2816 | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
| 2817 | "sched_getscheduler($module, pid, /)\n" |
| 2818 | "--\n" |
| 2819 | "\n" |
| 2820 | "Get the scheduling policy for the process identifiedy by pid.\n" |
| 2821 | "\n" |
| 2822 | "Passing 0 for pid returns the scheduling policy for the calling process."); |
| 2823 | |
| 2824 | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2825 | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2826 | |
| 2827 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2828 | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2829 | |
| 2830 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2831 | os_sched_getscheduler(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2832 | { |
| 2833 | PyObject *return_value = NULL; |
| 2834 | pid_t pid; |
| 2835 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2836 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2837 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2838 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2839 | return_value = os_sched_getscheduler_impl(module, pid); |
| 2840 | |
| 2841 | exit: |
| 2842 | return return_value; |
| 2843 | } |
| 2844 | |
| 2845 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 2846 | |
William Orr | 81574b8 | 2018-10-01 22:19:56 -0700 | [diff] [blame] | 2847 | #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] | 2848 | |
| 2849 | PyDoc_STRVAR(os_sched_param__doc__, |
| 2850 | "sched_param(sched_priority)\n" |
| 2851 | "--\n" |
| 2852 | "\n" |
| 2853 | "Current has only one field: sched_priority\");\n" |
| 2854 | "\n" |
| 2855 | " sched_priority\n" |
| 2856 | " A scheduling parameter."); |
| 2857 | |
| 2858 | static PyObject * |
| 2859 | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
| 2860 | |
| 2861 | static PyObject * |
| 2862 | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 2863 | { |
| 2864 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2865 | static const char * const _keywords[] = {"sched_priority", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2866 | static _PyArg_Parser _parser = {NULL, _keywords, "sched_param", 0}; |
| 2867 | PyObject *argsbuf[1]; |
| 2868 | PyObject * const *fastargs; |
| 2869 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2870 | PyObject *sched_priority; |
| 2871 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2872 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf); |
| 2873 | if (!fastargs) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2874 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2875 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 2876 | sched_priority = fastargs[0]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2877 | return_value = os_sched_param_impl(type, sched_priority); |
| 2878 | |
| 2879 | exit: |
| 2880 | return return_value; |
| 2881 | } |
| 2882 | |
William Orr | 81574b8 | 2018-10-01 22:19:56 -0700 | [diff] [blame] | 2883 | #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] | 2884 | |
| 2885 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 2886 | |
| 2887 | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
| 2888 | "sched_setscheduler($module, pid, policy, param, /)\n" |
| 2889 | "--\n" |
| 2890 | "\n" |
| 2891 | "Set the scheduling policy for the process identified by pid.\n" |
| 2892 | "\n" |
| 2893 | "If pid is 0, the calling process is changed.\n" |
| 2894 | "param is an instance of sched_param."); |
| 2895 | |
| 2896 | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2897 | {"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] | 2898 | |
| 2899 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2900 | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2901 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2902 | |
| 2903 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2904 | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2905 | { |
| 2906 | PyObject *return_value = NULL; |
| 2907 | pid_t pid; |
| 2908 | int policy; |
| 2909 | struct sched_param param; |
| 2910 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2911 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler", |
| 2912 | &pid, &policy, convert_sched_param, ¶m)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2913 | goto exit; |
| 2914 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2915 | return_value = os_sched_setscheduler_impl(module, pid, policy, ¶m); |
| 2916 | |
| 2917 | exit: |
| 2918 | return return_value; |
| 2919 | } |
| 2920 | |
| 2921 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 2922 | |
| 2923 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2924 | |
| 2925 | PyDoc_STRVAR(os_sched_getparam__doc__, |
| 2926 | "sched_getparam($module, pid, /)\n" |
| 2927 | "--\n" |
| 2928 | "\n" |
| 2929 | "Returns scheduling parameters for the process identified by pid.\n" |
| 2930 | "\n" |
| 2931 | "If pid is 0, returns parameters for the calling process.\n" |
| 2932 | "Return value is an instance of sched_param."); |
| 2933 | |
| 2934 | #define OS_SCHED_GETPARAM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2935 | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2936 | |
| 2937 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2938 | os_sched_getparam_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2939 | |
| 2940 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2941 | os_sched_getparam(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2942 | { |
| 2943 | PyObject *return_value = NULL; |
| 2944 | pid_t pid; |
| 2945 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2946 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2947 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2948 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2949 | return_value = os_sched_getparam_impl(module, pid); |
| 2950 | |
| 2951 | exit: |
| 2952 | return return_value; |
| 2953 | } |
| 2954 | |
| 2955 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2956 | |
| 2957 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2958 | |
| 2959 | PyDoc_STRVAR(os_sched_setparam__doc__, |
| 2960 | "sched_setparam($module, pid, param, /)\n" |
| 2961 | "--\n" |
| 2962 | "\n" |
| 2963 | "Set scheduling parameters for the process identified by pid.\n" |
| 2964 | "\n" |
| 2965 | "If pid is 0, sets parameters for the calling process.\n" |
| 2966 | "param should be an instance of sched_param."); |
| 2967 | |
| 2968 | #define OS_SCHED_SETPARAM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2969 | {"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] | 2970 | |
| 2971 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2972 | os_sched_setparam_impl(PyObject *module, pid_t pid, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2973 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2974 | |
| 2975 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2976 | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2977 | { |
| 2978 | PyObject *return_value = NULL; |
| 2979 | pid_t pid; |
| 2980 | struct sched_param param; |
| 2981 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2982 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam", |
| 2983 | &pid, convert_sched_param, ¶m)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2984 | goto exit; |
| 2985 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2986 | return_value = os_sched_setparam_impl(module, pid, ¶m); |
| 2987 | |
| 2988 | exit: |
| 2989 | return return_value; |
| 2990 | } |
| 2991 | |
| 2992 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2993 | |
| 2994 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
| 2995 | |
| 2996 | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
| 2997 | "sched_rr_get_interval($module, pid, /)\n" |
| 2998 | "--\n" |
| 2999 | "\n" |
| 3000 | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
| 3001 | "\n" |
| 3002 | "Value returned is a float."); |
| 3003 | |
| 3004 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3005 | {"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] | 3006 | |
| 3007 | static double |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3008 | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3009 | |
| 3010 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3011 | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3012 | { |
| 3013 | PyObject *return_value = NULL; |
| 3014 | pid_t pid; |
| 3015 | double _return_value; |
| 3016 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3017 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3018 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3019 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3020 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3021 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3022 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3023 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3024 | return_value = PyFloat_FromDouble(_return_value); |
| 3025 | |
| 3026 | exit: |
| 3027 | return return_value; |
| 3028 | } |
| 3029 | |
| 3030 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
| 3031 | |
| 3032 | #if defined(HAVE_SCHED_H) |
| 3033 | |
| 3034 | PyDoc_STRVAR(os_sched_yield__doc__, |
| 3035 | "sched_yield($module, /)\n" |
| 3036 | "--\n" |
| 3037 | "\n" |
| 3038 | "Voluntarily relinquish the CPU."); |
| 3039 | |
| 3040 | #define OS_SCHED_YIELD_METHODDEF \ |
| 3041 | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
| 3042 | |
| 3043 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3044 | os_sched_yield_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3045 | |
| 3046 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3047 | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3048 | { |
| 3049 | return os_sched_yield_impl(module); |
| 3050 | } |
| 3051 | |
| 3052 | #endif /* defined(HAVE_SCHED_H) */ |
| 3053 | |
| 3054 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 3055 | |
| 3056 | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
| 3057 | "sched_setaffinity($module, pid, mask, /)\n" |
| 3058 | "--\n" |
| 3059 | "\n" |
| 3060 | "Set the CPU affinity of the process identified by pid to mask.\n" |
| 3061 | "\n" |
| 3062 | "mask should be an iterable of integers identifying CPUs."); |
| 3063 | |
| 3064 | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3065 | {"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] | 3066 | |
| 3067 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3068 | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3069 | |
| 3070 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3071 | os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3072 | { |
| 3073 | PyObject *return_value = NULL; |
| 3074 | pid_t pid; |
| 3075 | PyObject *mask; |
| 3076 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3077 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity", |
| 3078 | &pid, &mask)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3079 | goto exit; |
| 3080 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3081 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
| 3082 | |
| 3083 | exit: |
| 3084 | return return_value; |
| 3085 | } |
| 3086 | |
| 3087 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 3088 | |
| 3089 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 3090 | |
| 3091 | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
| 3092 | "sched_getaffinity($module, pid, /)\n" |
| 3093 | "--\n" |
| 3094 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 3095 | "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] | 3096 | "\n" |
| 3097 | "The affinity is returned as a set of CPU identifiers."); |
| 3098 | |
| 3099 | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3100 | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3101 | |
| 3102 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3103 | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3104 | |
| 3105 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3106 | os_sched_getaffinity(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3107 | { |
| 3108 | PyObject *return_value = NULL; |
| 3109 | pid_t pid; |
| 3110 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3111 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3112 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3113 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3114 | return_value = os_sched_getaffinity_impl(module, pid); |
| 3115 | |
| 3116 | exit: |
| 3117 | return return_value; |
| 3118 | } |
| 3119 | |
| 3120 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 3121 | |
| 3122 | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
| 3123 | |
| 3124 | PyDoc_STRVAR(os_openpty__doc__, |
| 3125 | "openpty($module, /)\n" |
| 3126 | "--\n" |
| 3127 | "\n" |
| 3128 | "Open a pseudo-terminal.\n" |
| 3129 | "\n" |
| 3130 | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
| 3131 | "for both the master and slave ends."); |
| 3132 | |
| 3133 | #define OS_OPENPTY_METHODDEF \ |
| 3134 | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
| 3135 | |
| 3136 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3137 | os_openpty_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3138 | |
| 3139 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3140 | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3141 | { |
| 3142 | return os_openpty_impl(module); |
| 3143 | } |
| 3144 | |
| 3145 | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
| 3146 | |
| 3147 | #if defined(HAVE_FORKPTY) |
| 3148 | |
| 3149 | PyDoc_STRVAR(os_forkpty__doc__, |
| 3150 | "forkpty($module, /)\n" |
| 3151 | "--\n" |
| 3152 | "\n" |
| 3153 | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
| 3154 | "\n" |
| 3155 | "Returns a tuple of (pid, master_fd).\n" |
| 3156 | "Like fork(), return pid of 0 to the child process,\n" |
| 3157 | "and pid of child to the parent process.\n" |
| 3158 | "To both, return fd of newly opened pseudo-terminal."); |
| 3159 | |
| 3160 | #define OS_FORKPTY_METHODDEF \ |
| 3161 | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
| 3162 | |
| 3163 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3164 | os_forkpty_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3165 | |
| 3166 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3167 | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3168 | { |
| 3169 | return os_forkpty_impl(module); |
| 3170 | } |
| 3171 | |
| 3172 | #endif /* defined(HAVE_FORKPTY) */ |
| 3173 | |
| 3174 | #if defined(HAVE_GETEGID) |
| 3175 | |
| 3176 | PyDoc_STRVAR(os_getegid__doc__, |
| 3177 | "getegid($module, /)\n" |
| 3178 | "--\n" |
| 3179 | "\n" |
| 3180 | "Return the current process\'s effective group id."); |
| 3181 | |
| 3182 | #define OS_GETEGID_METHODDEF \ |
| 3183 | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
| 3184 | |
| 3185 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3186 | os_getegid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3187 | |
| 3188 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3189 | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3190 | { |
| 3191 | return os_getegid_impl(module); |
| 3192 | } |
| 3193 | |
| 3194 | #endif /* defined(HAVE_GETEGID) */ |
| 3195 | |
| 3196 | #if defined(HAVE_GETEUID) |
| 3197 | |
| 3198 | PyDoc_STRVAR(os_geteuid__doc__, |
| 3199 | "geteuid($module, /)\n" |
| 3200 | "--\n" |
| 3201 | "\n" |
| 3202 | "Return the current process\'s effective user id."); |
| 3203 | |
| 3204 | #define OS_GETEUID_METHODDEF \ |
| 3205 | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
| 3206 | |
| 3207 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3208 | os_geteuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3209 | |
| 3210 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3211 | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3212 | { |
| 3213 | return os_geteuid_impl(module); |
| 3214 | } |
| 3215 | |
| 3216 | #endif /* defined(HAVE_GETEUID) */ |
| 3217 | |
| 3218 | #if defined(HAVE_GETGID) |
| 3219 | |
| 3220 | PyDoc_STRVAR(os_getgid__doc__, |
| 3221 | "getgid($module, /)\n" |
| 3222 | "--\n" |
| 3223 | "\n" |
| 3224 | "Return the current process\'s group id."); |
| 3225 | |
| 3226 | #define OS_GETGID_METHODDEF \ |
| 3227 | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
| 3228 | |
| 3229 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3230 | os_getgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3231 | |
| 3232 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3233 | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3234 | { |
| 3235 | return os_getgid_impl(module); |
| 3236 | } |
| 3237 | |
| 3238 | #endif /* defined(HAVE_GETGID) */ |
| 3239 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 3240 | #if defined(HAVE_GETPID) |
| 3241 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3242 | PyDoc_STRVAR(os_getpid__doc__, |
| 3243 | "getpid($module, /)\n" |
| 3244 | "--\n" |
| 3245 | "\n" |
| 3246 | "Return the current process id."); |
| 3247 | |
| 3248 | #define OS_GETPID_METHODDEF \ |
| 3249 | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
| 3250 | |
| 3251 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3252 | os_getpid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3253 | |
| 3254 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3255 | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3256 | { |
| 3257 | return os_getpid_impl(module); |
| 3258 | } |
| 3259 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 3260 | #endif /* defined(HAVE_GETPID) */ |
| 3261 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3262 | #if defined(HAVE_GETGROUPS) |
| 3263 | |
| 3264 | PyDoc_STRVAR(os_getgroups__doc__, |
| 3265 | "getgroups($module, /)\n" |
| 3266 | "--\n" |
| 3267 | "\n" |
| 3268 | "Return list of supplemental group IDs for the process."); |
| 3269 | |
| 3270 | #define OS_GETGROUPS_METHODDEF \ |
| 3271 | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
| 3272 | |
| 3273 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3274 | os_getgroups_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3275 | |
| 3276 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3277 | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3278 | { |
| 3279 | return os_getgroups_impl(module); |
| 3280 | } |
| 3281 | |
| 3282 | #endif /* defined(HAVE_GETGROUPS) */ |
| 3283 | |
| 3284 | #if defined(HAVE_GETPGID) |
| 3285 | |
| 3286 | PyDoc_STRVAR(os_getpgid__doc__, |
| 3287 | "getpgid($module, /, pid)\n" |
| 3288 | "--\n" |
| 3289 | "\n" |
| 3290 | "Call the system call getpgid(), and return the result."); |
| 3291 | |
| 3292 | #define OS_GETPGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3293 | {"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] | 3294 | |
| 3295 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3296 | os_getpgid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3297 | |
| 3298 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3299 | 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] | 3300 | { |
| 3301 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3302 | static const char * const _keywords[] = {"pid", NULL}; |
| 3303 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3304 | pid_t pid; |
| 3305 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3306 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3307 | &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3308 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3309 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3310 | return_value = os_getpgid_impl(module, pid); |
| 3311 | |
| 3312 | exit: |
| 3313 | return return_value; |
| 3314 | } |
| 3315 | |
| 3316 | #endif /* defined(HAVE_GETPGID) */ |
| 3317 | |
| 3318 | #if defined(HAVE_GETPGRP) |
| 3319 | |
| 3320 | PyDoc_STRVAR(os_getpgrp__doc__, |
| 3321 | "getpgrp($module, /)\n" |
| 3322 | "--\n" |
| 3323 | "\n" |
| 3324 | "Return the current process group id."); |
| 3325 | |
| 3326 | #define OS_GETPGRP_METHODDEF \ |
| 3327 | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
| 3328 | |
| 3329 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3330 | os_getpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3331 | |
| 3332 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3333 | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3334 | { |
| 3335 | return os_getpgrp_impl(module); |
| 3336 | } |
| 3337 | |
| 3338 | #endif /* defined(HAVE_GETPGRP) */ |
| 3339 | |
| 3340 | #if defined(HAVE_SETPGRP) |
| 3341 | |
| 3342 | PyDoc_STRVAR(os_setpgrp__doc__, |
| 3343 | "setpgrp($module, /)\n" |
| 3344 | "--\n" |
| 3345 | "\n" |
| 3346 | "Make the current process the leader of its process group."); |
| 3347 | |
| 3348 | #define OS_SETPGRP_METHODDEF \ |
| 3349 | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
| 3350 | |
| 3351 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3352 | os_setpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3353 | |
| 3354 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3355 | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3356 | { |
| 3357 | return os_setpgrp_impl(module); |
| 3358 | } |
| 3359 | |
| 3360 | #endif /* defined(HAVE_SETPGRP) */ |
| 3361 | |
| 3362 | #if defined(HAVE_GETPPID) |
| 3363 | |
| 3364 | PyDoc_STRVAR(os_getppid__doc__, |
| 3365 | "getppid($module, /)\n" |
| 3366 | "--\n" |
| 3367 | "\n" |
| 3368 | "Return the parent\'s process id.\n" |
| 3369 | "\n" |
| 3370 | "If the parent process has already exited, Windows machines will still\n" |
| 3371 | "return its id; others systems will return the id of the \'init\' process (1)."); |
| 3372 | |
| 3373 | #define OS_GETPPID_METHODDEF \ |
| 3374 | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
| 3375 | |
| 3376 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3377 | os_getppid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3378 | |
| 3379 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3380 | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3381 | { |
| 3382 | return os_getppid_impl(module); |
| 3383 | } |
| 3384 | |
| 3385 | #endif /* defined(HAVE_GETPPID) */ |
| 3386 | |
| 3387 | #if defined(HAVE_GETLOGIN) |
| 3388 | |
| 3389 | PyDoc_STRVAR(os_getlogin__doc__, |
| 3390 | "getlogin($module, /)\n" |
| 3391 | "--\n" |
| 3392 | "\n" |
| 3393 | "Return the actual login name."); |
| 3394 | |
| 3395 | #define OS_GETLOGIN_METHODDEF \ |
| 3396 | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
| 3397 | |
| 3398 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3399 | os_getlogin_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3400 | |
| 3401 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3402 | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3403 | { |
| 3404 | return os_getlogin_impl(module); |
| 3405 | } |
| 3406 | |
| 3407 | #endif /* defined(HAVE_GETLOGIN) */ |
| 3408 | |
| 3409 | #if defined(HAVE_GETUID) |
| 3410 | |
| 3411 | PyDoc_STRVAR(os_getuid__doc__, |
| 3412 | "getuid($module, /)\n" |
| 3413 | "--\n" |
| 3414 | "\n" |
| 3415 | "Return the current process\'s user id."); |
| 3416 | |
| 3417 | #define OS_GETUID_METHODDEF \ |
| 3418 | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
| 3419 | |
| 3420 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3421 | os_getuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3422 | |
| 3423 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3424 | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3425 | { |
| 3426 | return os_getuid_impl(module); |
| 3427 | } |
| 3428 | |
| 3429 | #endif /* defined(HAVE_GETUID) */ |
| 3430 | |
| 3431 | #if defined(HAVE_KILL) |
| 3432 | |
| 3433 | PyDoc_STRVAR(os_kill__doc__, |
| 3434 | "kill($module, pid, signal, /)\n" |
| 3435 | "--\n" |
| 3436 | "\n" |
| 3437 | "Kill a process with a signal."); |
| 3438 | |
| 3439 | #define OS_KILL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3440 | {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3441 | |
| 3442 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3443 | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3444 | |
| 3445 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3446 | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3447 | { |
| 3448 | PyObject *return_value = NULL; |
| 3449 | pid_t pid; |
| 3450 | Py_ssize_t signal; |
| 3451 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3452 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill", |
| 3453 | &pid, &signal)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3454 | goto exit; |
| 3455 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3456 | return_value = os_kill_impl(module, pid, signal); |
| 3457 | |
| 3458 | exit: |
| 3459 | return return_value; |
| 3460 | } |
| 3461 | |
| 3462 | #endif /* defined(HAVE_KILL) */ |
| 3463 | |
| 3464 | #if defined(HAVE_KILLPG) |
| 3465 | |
| 3466 | PyDoc_STRVAR(os_killpg__doc__, |
| 3467 | "killpg($module, pgid, signal, /)\n" |
| 3468 | "--\n" |
| 3469 | "\n" |
| 3470 | "Kill a process group with a signal."); |
| 3471 | |
| 3472 | #define OS_KILLPG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3473 | {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3474 | |
| 3475 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3476 | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3477 | |
| 3478 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3479 | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3480 | { |
| 3481 | PyObject *return_value = NULL; |
| 3482 | pid_t pgid; |
| 3483 | int signal; |
| 3484 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3485 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg", |
| 3486 | &pgid, &signal)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3487 | goto exit; |
| 3488 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3489 | return_value = os_killpg_impl(module, pgid, signal); |
| 3490 | |
| 3491 | exit: |
| 3492 | return return_value; |
| 3493 | } |
| 3494 | |
| 3495 | #endif /* defined(HAVE_KILLPG) */ |
| 3496 | |
| 3497 | #if defined(HAVE_PLOCK) |
| 3498 | |
| 3499 | PyDoc_STRVAR(os_plock__doc__, |
| 3500 | "plock($module, op, /)\n" |
| 3501 | "--\n" |
| 3502 | "\n" |
| 3503 | "Lock program segments into memory.\");"); |
| 3504 | |
| 3505 | #define OS_PLOCK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3506 | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3507 | |
| 3508 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3509 | os_plock_impl(PyObject *module, int op); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3510 | |
| 3511 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3512 | os_plock(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3513 | { |
| 3514 | PyObject *return_value = NULL; |
| 3515 | int op; |
| 3516 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3517 | if (PyFloat_Check(arg)) { |
| 3518 | PyErr_SetString(PyExc_TypeError, |
| 3519 | "integer argument expected, got float" ); |
| 3520 | goto exit; |
| 3521 | } |
| 3522 | op = _PyLong_AsInt(arg); |
| 3523 | if (op == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3524 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3525 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3526 | return_value = os_plock_impl(module, op); |
| 3527 | |
| 3528 | exit: |
| 3529 | return return_value; |
| 3530 | } |
| 3531 | |
| 3532 | #endif /* defined(HAVE_PLOCK) */ |
| 3533 | |
| 3534 | #if defined(HAVE_SETUID) |
| 3535 | |
| 3536 | PyDoc_STRVAR(os_setuid__doc__, |
| 3537 | "setuid($module, uid, /)\n" |
| 3538 | "--\n" |
| 3539 | "\n" |
| 3540 | "Set the current process\'s user id."); |
| 3541 | |
| 3542 | #define OS_SETUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3543 | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3544 | |
| 3545 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3546 | os_setuid_impl(PyObject *module, uid_t uid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3547 | |
| 3548 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3549 | os_setuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3550 | { |
| 3551 | PyObject *return_value = NULL; |
| 3552 | uid_t uid; |
| 3553 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3554 | if (!_Py_Uid_Converter(arg, &uid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3555 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3556 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3557 | return_value = os_setuid_impl(module, uid); |
| 3558 | |
| 3559 | exit: |
| 3560 | return return_value; |
| 3561 | } |
| 3562 | |
| 3563 | #endif /* defined(HAVE_SETUID) */ |
| 3564 | |
| 3565 | #if defined(HAVE_SETEUID) |
| 3566 | |
| 3567 | PyDoc_STRVAR(os_seteuid__doc__, |
| 3568 | "seteuid($module, euid, /)\n" |
| 3569 | "--\n" |
| 3570 | "\n" |
| 3571 | "Set the current process\'s effective user id."); |
| 3572 | |
| 3573 | #define OS_SETEUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3574 | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3575 | |
| 3576 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3577 | os_seteuid_impl(PyObject *module, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3578 | |
| 3579 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3580 | os_seteuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3581 | { |
| 3582 | PyObject *return_value = NULL; |
| 3583 | uid_t euid; |
| 3584 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3585 | if (!_Py_Uid_Converter(arg, &euid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3586 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3587 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3588 | return_value = os_seteuid_impl(module, euid); |
| 3589 | |
| 3590 | exit: |
| 3591 | return return_value; |
| 3592 | } |
| 3593 | |
| 3594 | #endif /* defined(HAVE_SETEUID) */ |
| 3595 | |
| 3596 | #if defined(HAVE_SETEGID) |
| 3597 | |
| 3598 | PyDoc_STRVAR(os_setegid__doc__, |
| 3599 | "setegid($module, egid, /)\n" |
| 3600 | "--\n" |
| 3601 | "\n" |
| 3602 | "Set the current process\'s effective group id."); |
| 3603 | |
| 3604 | #define OS_SETEGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3605 | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3606 | |
| 3607 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3608 | os_setegid_impl(PyObject *module, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3609 | |
| 3610 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3611 | os_setegid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3612 | { |
| 3613 | PyObject *return_value = NULL; |
| 3614 | gid_t egid; |
| 3615 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3616 | if (!_Py_Gid_Converter(arg, &egid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3617 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3618 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3619 | return_value = os_setegid_impl(module, egid); |
| 3620 | |
| 3621 | exit: |
| 3622 | return return_value; |
| 3623 | } |
| 3624 | |
| 3625 | #endif /* defined(HAVE_SETEGID) */ |
| 3626 | |
| 3627 | #if defined(HAVE_SETREUID) |
| 3628 | |
| 3629 | PyDoc_STRVAR(os_setreuid__doc__, |
| 3630 | "setreuid($module, ruid, euid, /)\n" |
| 3631 | "--\n" |
| 3632 | "\n" |
| 3633 | "Set the current process\'s real and effective user ids."); |
| 3634 | |
| 3635 | #define OS_SETREUID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3636 | {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3637 | |
| 3638 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3639 | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3640 | |
| 3641 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3642 | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3643 | { |
| 3644 | PyObject *return_value = NULL; |
| 3645 | uid_t ruid; |
| 3646 | uid_t euid; |
| 3647 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3648 | if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { |
| 3649 | goto exit; |
| 3650 | } |
| 3651 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
| 3652 | goto exit; |
| 3653 | } |
| 3654 | if (!_Py_Uid_Converter(args[1], &euid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3655 | goto exit; |
| 3656 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3657 | return_value = os_setreuid_impl(module, ruid, euid); |
| 3658 | |
| 3659 | exit: |
| 3660 | return return_value; |
| 3661 | } |
| 3662 | |
| 3663 | #endif /* defined(HAVE_SETREUID) */ |
| 3664 | |
| 3665 | #if defined(HAVE_SETREGID) |
| 3666 | |
| 3667 | PyDoc_STRVAR(os_setregid__doc__, |
| 3668 | "setregid($module, rgid, egid, /)\n" |
| 3669 | "--\n" |
| 3670 | "\n" |
| 3671 | "Set the current process\'s real and effective group ids."); |
| 3672 | |
| 3673 | #define OS_SETREGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3674 | {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3675 | |
| 3676 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3677 | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3678 | |
| 3679 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3680 | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3681 | { |
| 3682 | PyObject *return_value = NULL; |
| 3683 | gid_t rgid; |
| 3684 | gid_t egid; |
| 3685 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3686 | if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { |
| 3687 | goto exit; |
| 3688 | } |
| 3689 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
| 3690 | goto exit; |
| 3691 | } |
| 3692 | if (!_Py_Gid_Converter(args[1], &egid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3693 | goto exit; |
| 3694 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3695 | return_value = os_setregid_impl(module, rgid, egid); |
| 3696 | |
| 3697 | exit: |
| 3698 | return return_value; |
| 3699 | } |
| 3700 | |
| 3701 | #endif /* defined(HAVE_SETREGID) */ |
| 3702 | |
| 3703 | #if defined(HAVE_SETGID) |
| 3704 | |
| 3705 | PyDoc_STRVAR(os_setgid__doc__, |
| 3706 | "setgid($module, gid, /)\n" |
| 3707 | "--\n" |
| 3708 | "\n" |
| 3709 | "Set the current process\'s group id."); |
| 3710 | |
| 3711 | #define OS_SETGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3712 | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3713 | |
| 3714 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3715 | os_setgid_impl(PyObject *module, gid_t gid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3716 | |
| 3717 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3718 | os_setgid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3719 | { |
| 3720 | PyObject *return_value = NULL; |
| 3721 | gid_t gid; |
| 3722 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3723 | if (!_Py_Gid_Converter(arg, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3724 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3725 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3726 | return_value = os_setgid_impl(module, gid); |
| 3727 | |
| 3728 | exit: |
| 3729 | return return_value; |
| 3730 | } |
| 3731 | |
| 3732 | #endif /* defined(HAVE_SETGID) */ |
| 3733 | |
| 3734 | #if defined(HAVE_SETGROUPS) |
| 3735 | |
| 3736 | PyDoc_STRVAR(os_setgroups__doc__, |
| 3737 | "setgroups($module, groups, /)\n" |
| 3738 | "--\n" |
| 3739 | "\n" |
| 3740 | "Set the groups of the current process to list."); |
| 3741 | |
| 3742 | #define OS_SETGROUPS_METHODDEF \ |
| 3743 | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
| 3744 | |
| 3745 | #endif /* defined(HAVE_SETGROUPS) */ |
| 3746 | |
| 3747 | #if defined(HAVE_WAIT3) |
| 3748 | |
| 3749 | PyDoc_STRVAR(os_wait3__doc__, |
| 3750 | "wait3($module, /, options)\n" |
| 3751 | "--\n" |
| 3752 | "\n" |
| 3753 | "Wait for completion of a child process.\n" |
| 3754 | "\n" |
| 3755 | "Returns a tuple of information about the child process:\n" |
| 3756 | " (pid, status, rusage)"); |
| 3757 | |
| 3758 | #define OS_WAIT3_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3759 | {"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] | 3760 | |
| 3761 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3762 | os_wait3_impl(PyObject *module, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3763 | |
| 3764 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3765 | 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] | 3766 | { |
| 3767 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3768 | static const char * const _keywords[] = {"options", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 3769 | static _PyArg_Parser _parser = {NULL, _keywords, "wait3", 0}; |
| 3770 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3771 | int options; |
| 3772 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 3773 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 3774 | if (!args) { |
| 3775 | goto exit; |
| 3776 | } |
| 3777 | if (PyFloat_Check(args[0])) { |
| 3778 | PyErr_SetString(PyExc_TypeError, |
| 3779 | "integer argument expected, got float" ); |
| 3780 | goto exit; |
| 3781 | } |
| 3782 | options = _PyLong_AsInt(args[0]); |
| 3783 | if (options == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3784 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3785 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3786 | return_value = os_wait3_impl(module, options); |
| 3787 | |
| 3788 | exit: |
| 3789 | return return_value; |
| 3790 | } |
| 3791 | |
| 3792 | #endif /* defined(HAVE_WAIT3) */ |
| 3793 | |
| 3794 | #if defined(HAVE_WAIT4) |
| 3795 | |
| 3796 | PyDoc_STRVAR(os_wait4__doc__, |
| 3797 | "wait4($module, /, pid, options)\n" |
| 3798 | "--\n" |
| 3799 | "\n" |
| 3800 | "Wait for completion of a specific child process.\n" |
| 3801 | "\n" |
| 3802 | "Returns a tuple of information about the child process:\n" |
| 3803 | " (pid, status, rusage)"); |
| 3804 | |
| 3805 | #define OS_WAIT4_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3806 | {"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] | 3807 | |
| 3808 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3809 | os_wait4_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3810 | |
| 3811 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3812 | 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] | 3813 | { |
| 3814 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3815 | static const char * const _keywords[] = {"pid", "options", NULL}; |
| 3816 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3817 | pid_t pid; |
| 3818 | int options; |
| 3819 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3820 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3821 | &pid, &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3822 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3823 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3824 | return_value = os_wait4_impl(module, pid, options); |
| 3825 | |
| 3826 | exit: |
| 3827 | return return_value; |
| 3828 | } |
| 3829 | |
| 3830 | #endif /* defined(HAVE_WAIT4) */ |
| 3831 | |
| 3832 | #if (defined(HAVE_WAITID) && !defined(__APPLE__)) |
| 3833 | |
| 3834 | PyDoc_STRVAR(os_waitid__doc__, |
| 3835 | "waitid($module, idtype, id, options, /)\n" |
| 3836 | "--\n" |
| 3837 | "\n" |
| 3838 | "Returns the result of waiting for a process or processes.\n" |
| 3839 | "\n" |
| 3840 | " idtype\n" |
| 3841 | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
| 3842 | " id\n" |
| 3843 | " The id to wait on.\n" |
| 3844 | " options\n" |
| 3845 | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
| 3846 | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
| 3847 | "\n" |
| 3848 | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
| 3849 | "no children in a waitable state."); |
| 3850 | |
| 3851 | #define OS_WAITID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3852 | {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3853 | |
| 3854 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3855 | 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] | 3856 | |
| 3857 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3858 | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3859 | { |
| 3860 | PyObject *return_value = NULL; |
| 3861 | idtype_t idtype; |
| 3862 | id_t id; |
| 3863 | int options; |
| 3864 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3865 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid", |
| 3866 | &idtype, &id, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3867 | goto exit; |
| 3868 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3869 | return_value = os_waitid_impl(module, idtype, id, options); |
| 3870 | |
| 3871 | exit: |
| 3872 | return return_value; |
| 3873 | } |
| 3874 | |
| 3875 | #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */ |
| 3876 | |
| 3877 | #if defined(HAVE_WAITPID) |
| 3878 | |
| 3879 | PyDoc_STRVAR(os_waitpid__doc__, |
| 3880 | "waitpid($module, pid, options, /)\n" |
| 3881 | "--\n" |
| 3882 | "\n" |
| 3883 | "Wait for completion of a given child process.\n" |
| 3884 | "\n" |
| 3885 | "Returns a tuple of information regarding the child process:\n" |
| 3886 | " (pid, status)\n" |
| 3887 | "\n" |
| 3888 | "The options argument is ignored on Windows."); |
| 3889 | |
| 3890 | #define OS_WAITPID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3891 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3892 | |
| 3893 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3894 | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3895 | |
| 3896 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3897 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3898 | { |
| 3899 | PyObject *return_value = NULL; |
| 3900 | pid_t pid; |
| 3901 | int options; |
| 3902 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3903 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid", |
| 3904 | &pid, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3905 | goto exit; |
| 3906 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3907 | return_value = os_waitpid_impl(module, pid, options); |
| 3908 | |
| 3909 | exit: |
| 3910 | return return_value; |
| 3911 | } |
| 3912 | |
| 3913 | #endif /* defined(HAVE_WAITPID) */ |
| 3914 | |
| 3915 | #if defined(HAVE_CWAIT) |
| 3916 | |
| 3917 | PyDoc_STRVAR(os_waitpid__doc__, |
| 3918 | "waitpid($module, pid, options, /)\n" |
| 3919 | "--\n" |
| 3920 | "\n" |
| 3921 | "Wait for completion of a given process.\n" |
| 3922 | "\n" |
| 3923 | "Returns a tuple of information regarding the process:\n" |
| 3924 | " (pid, status << 8)\n" |
| 3925 | "\n" |
| 3926 | "The options argument is ignored on Windows."); |
| 3927 | |
| 3928 | #define OS_WAITPID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3929 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3930 | |
| 3931 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3932 | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3933 | |
| 3934 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3935 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3936 | { |
| 3937 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3938 | intptr_t pid; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3939 | int options; |
| 3940 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3941 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid", |
| 3942 | &pid, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3943 | goto exit; |
| 3944 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3945 | return_value = os_waitpid_impl(module, pid, options); |
| 3946 | |
| 3947 | exit: |
| 3948 | return return_value; |
| 3949 | } |
| 3950 | |
| 3951 | #endif /* defined(HAVE_CWAIT) */ |
| 3952 | |
| 3953 | #if defined(HAVE_WAIT) |
| 3954 | |
| 3955 | PyDoc_STRVAR(os_wait__doc__, |
| 3956 | "wait($module, /)\n" |
| 3957 | "--\n" |
| 3958 | "\n" |
| 3959 | "Wait for completion of a child process.\n" |
| 3960 | "\n" |
| 3961 | "Returns a tuple of information about the child process:\n" |
| 3962 | " (pid, status)"); |
| 3963 | |
| 3964 | #define OS_WAIT_METHODDEF \ |
| 3965 | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
| 3966 | |
| 3967 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3968 | os_wait_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3969 | |
| 3970 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3971 | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3972 | { |
| 3973 | return os_wait_impl(module); |
| 3974 | } |
| 3975 | |
| 3976 | #endif /* defined(HAVE_WAIT) */ |
| 3977 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 3978 | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
| 3979 | |
| 3980 | PyDoc_STRVAR(os_readlink__doc__, |
| 3981 | "readlink($module, /, path, *, dir_fd=None)\n" |
| 3982 | "--\n" |
| 3983 | "\n" |
| 3984 | "Return a string representing the path to which the symbolic link points.\n" |
| 3985 | "\n" |
| 3986 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3987 | "and path should be relative; path will then be relative to that directory.\n" |
| 3988 | "\n" |
| 3989 | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
| 3990 | "using it will raise a NotImplementedError."); |
| 3991 | |
| 3992 | #define OS_READLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3993 | {"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] | 3994 | |
| 3995 | static PyObject * |
| 3996 | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
| 3997 | |
| 3998 | static PyObject * |
| 3999 | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 4000 | { |
| 4001 | PyObject *return_value = NULL; |
| 4002 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4003 | static _PyArg_Parser _parser = {NULL, _keywords, "readlink", 0}; |
| 4004 | PyObject *argsbuf[2]; |
| 4005 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 4006 | path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0); |
| 4007 | int dir_fd = DEFAULT_DIR_FD; |
| 4008 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4009 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 4010 | if (!args) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 4011 | goto exit; |
| 4012 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4013 | if (!path_converter(args[0], &path)) { |
| 4014 | goto exit; |
| 4015 | } |
| 4016 | if (!noptargs) { |
| 4017 | goto skip_optional_kwonly; |
| 4018 | } |
| 4019 | if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
| 4020 | goto exit; |
| 4021 | } |
| 4022 | skip_optional_kwonly: |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 4023 | return_value = os_readlink_impl(module, &path, dir_fd); |
| 4024 | |
| 4025 | exit: |
| 4026 | /* Cleanup for path */ |
| 4027 | path_cleanup(&path); |
| 4028 | |
| 4029 | return return_value; |
| 4030 | } |
| 4031 | |
| 4032 | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
| 4033 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4034 | #if defined(HAVE_SYMLINK) |
| 4035 | |
| 4036 | PyDoc_STRVAR(os_symlink__doc__, |
| 4037 | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
| 4038 | "--\n" |
| 4039 | "\n" |
| 4040 | "Create a symbolic link pointing to src named dst.\n" |
| 4041 | "\n" |
| 4042 | "target_is_directory is required on Windows if the target is to be\n" |
| 4043 | " interpreted as a directory. (On Windows, symlink requires\n" |
| 4044 | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
| 4045 | " target_is_directory is ignored on non-Windows platforms.\n" |
| 4046 | "\n" |
| 4047 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 4048 | " and path should be relative; path will then be relative to that directory.\n" |
| 4049 | "dir_fd may not be implemented on your platform.\n" |
| 4050 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 4051 | |
| 4052 | #define OS_SYMLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4053 | {"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] | 4054 | |
| 4055 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4056 | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 4057 | int target_is_directory, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4058 | |
| 4059 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4060 | 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] | 4061 | { |
| 4062 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4063 | 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] | 4064 | static _PyArg_Parser _parser = {NULL, _keywords, "symlink", 0}; |
| 4065 | PyObject *argsbuf[4]; |
| 4066 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4067 | path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0); |
| 4068 | path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0); |
| 4069 | int target_is_directory = 0; |
| 4070 | int dir_fd = DEFAULT_DIR_FD; |
| 4071 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4072 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
| 4073 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4074 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4075 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4076 | if (!path_converter(args[0], &src)) { |
| 4077 | goto exit; |
| 4078 | } |
| 4079 | if (!path_converter(args[1], &dst)) { |
| 4080 | goto exit; |
| 4081 | } |
| 4082 | if (!noptargs) { |
| 4083 | goto skip_optional_pos; |
| 4084 | } |
| 4085 | if (args[2]) { |
| 4086 | target_is_directory = PyObject_IsTrue(args[2]); |
| 4087 | if (target_is_directory < 0) { |
| 4088 | goto exit; |
| 4089 | } |
| 4090 | if (!--noptargs) { |
| 4091 | goto skip_optional_pos; |
| 4092 | } |
| 4093 | } |
| 4094 | skip_optional_pos: |
| 4095 | if (!noptargs) { |
| 4096 | goto skip_optional_kwonly; |
| 4097 | } |
| 4098 | if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
| 4099 | goto exit; |
| 4100 | } |
| 4101 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4102 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
| 4103 | |
| 4104 | exit: |
| 4105 | /* Cleanup for src */ |
| 4106 | path_cleanup(&src); |
| 4107 | /* Cleanup for dst */ |
| 4108 | path_cleanup(&dst); |
| 4109 | |
| 4110 | return return_value; |
| 4111 | } |
| 4112 | |
| 4113 | #endif /* defined(HAVE_SYMLINK) */ |
| 4114 | |
| 4115 | #if defined(HAVE_TIMES) |
| 4116 | |
| 4117 | PyDoc_STRVAR(os_times__doc__, |
| 4118 | "times($module, /)\n" |
| 4119 | "--\n" |
| 4120 | "\n" |
| 4121 | "Return a collection containing process timing information.\n" |
| 4122 | "\n" |
| 4123 | "The object returned behaves like a named tuple with these fields:\n" |
| 4124 | " (utime, stime, cutime, cstime, elapsed_time)\n" |
| 4125 | "All fields are floating point numbers."); |
| 4126 | |
| 4127 | #define OS_TIMES_METHODDEF \ |
| 4128 | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
| 4129 | |
| 4130 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4131 | os_times_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4132 | |
| 4133 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4134 | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4135 | { |
| 4136 | return os_times_impl(module); |
| 4137 | } |
| 4138 | |
| 4139 | #endif /* defined(HAVE_TIMES) */ |
| 4140 | |
| 4141 | #if defined(HAVE_GETSID) |
| 4142 | |
| 4143 | PyDoc_STRVAR(os_getsid__doc__, |
| 4144 | "getsid($module, pid, /)\n" |
| 4145 | "--\n" |
| 4146 | "\n" |
| 4147 | "Call the system call getsid(pid) and return the result."); |
| 4148 | |
| 4149 | #define OS_GETSID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4150 | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4151 | |
| 4152 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4153 | os_getsid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4154 | |
| 4155 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4156 | os_getsid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4157 | { |
| 4158 | PyObject *return_value = NULL; |
| 4159 | pid_t pid; |
| 4160 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4161 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4162 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4163 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4164 | return_value = os_getsid_impl(module, pid); |
| 4165 | |
| 4166 | exit: |
| 4167 | return return_value; |
| 4168 | } |
| 4169 | |
| 4170 | #endif /* defined(HAVE_GETSID) */ |
| 4171 | |
| 4172 | #if defined(HAVE_SETSID) |
| 4173 | |
| 4174 | PyDoc_STRVAR(os_setsid__doc__, |
| 4175 | "setsid($module, /)\n" |
| 4176 | "--\n" |
| 4177 | "\n" |
| 4178 | "Call the system call setsid()."); |
| 4179 | |
| 4180 | #define OS_SETSID_METHODDEF \ |
| 4181 | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
| 4182 | |
| 4183 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4184 | os_setsid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4185 | |
| 4186 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4187 | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4188 | { |
| 4189 | return os_setsid_impl(module); |
| 4190 | } |
| 4191 | |
| 4192 | #endif /* defined(HAVE_SETSID) */ |
| 4193 | |
| 4194 | #if defined(HAVE_SETPGID) |
| 4195 | |
| 4196 | PyDoc_STRVAR(os_setpgid__doc__, |
| 4197 | "setpgid($module, pid, pgrp, /)\n" |
| 4198 | "--\n" |
| 4199 | "\n" |
| 4200 | "Call the system call setpgid(pid, pgrp)."); |
| 4201 | |
| 4202 | #define OS_SETPGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4203 | {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4204 | |
| 4205 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4206 | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4207 | |
| 4208 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4209 | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4210 | { |
| 4211 | PyObject *return_value = NULL; |
| 4212 | pid_t pid; |
| 4213 | pid_t pgrp; |
| 4214 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 4215 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid", |
| 4216 | &pid, &pgrp)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4217 | goto exit; |
| 4218 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4219 | return_value = os_setpgid_impl(module, pid, pgrp); |
| 4220 | |
| 4221 | exit: |
| 4222 | return return_value; |
| 4223 | } |
| 4224 | |
| 4225 | #endif /* defined(HAVE_SETPGID) */ |
| 4226 | |
| 4227 | #if defined(HAVE_TCGETPGRP) |
| 4228 | |
| 4229 | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
| 4230 | "tcgetpgrp($module, fd, /)\n" |
| 4231 | "--\n" |
| 4232 | "\n" |
| 4233 | "Return the process group associated with the terminal specified by fd."); |
| 4234 | |
| 4235 | #define OS_TCGETPGRP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4236 | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4237 | |
| 4238 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4239 | os_tcgetpgrp_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4240 | |
| 4241 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4242 | os_tcgetpgrp(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4243 | { |
| 4244 | PyObject *return_value = NULL; |
| 4245 | int fd; |
| 4246 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4247 | if (PyFloat_Check(arg)) { |
| 4248 | PyErr_SetString(PyExc_TypeError, |
| 4249 | "integer argument expected, got float" ); |
| 4250 | goto exit; |
| 4251 | } |
| 4252 | fd = _PyLong_AsInt(arg); |
| 4253 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4254 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4255 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4256 | return_value = os_tcgetpgrp_impl(module, fd); |
| 4257 | |
| 4258 | exit: |
| 4259 | return return_value; |
| 4260 | } |
| 4261 | |
| 4262 | #endif /* defined(HAVE_TCGETPGRP) */ |
| 4263 | |
| 4264 | #if defined(HAVE_TCSETPGRP) |
| 4265 | |
| 4266 | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
| 4267 | "tcsetpgrp($module, fd, pgid, /)\n" |
| 4268 | "--\n" |
| 4269 | "\n" |
| 4270 | "Set the process group associated with the terminal specified by fd."); |
| 4271 | |
| 4272 | #define OS_TCSETPGRP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4273 | {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4274 | |
| 4275 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4276 | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4277 | |
| 4278 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4279 | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4280 | { |
| 4281 | PyObject *return_value = NULL; |
| 4282 | int fd; |
| 4283 | pid_t pgid; |
| 4284 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 4285 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp", |
| 4286 | &fd, &pgid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4287 | goto exit; |
| 4288 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4289 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
| 4290 | |
| 4291 | exit: |
| 4292 | return return_value; |
| 4293 | } |
| 4294 | |
| 4295 | #endif /* defined(HAVE_TCSETPGRP) */ |
| 4296 | |
| 4297 | PyDoc_STRVAR(os_open__doc__, |
| 4298 | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
| 4299 | "--\n" |
| 4300 | "\n" |
| 4301 | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
| 4302 | "\n" |
| 4303 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 4304 | " and path should be relative; path will then be relative to that directory.\n" |
| 4305 | "dir_fd may not be implemented on your platform.\n" |
| 4306 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 4307 | |
| 4308 | #define OS_OPEN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4309 | {"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] | 4310 | |
| 4311 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4312 | 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] | 4313 | |
| 4314 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4315 | 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] | 4316 | { |
| 4317 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4318 | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4319 | static _PyArg_Parser _parser = {NULL, _keywords, "open", 0}; |
| 4320 | PyObject *argsbuf[4]; |
| 4321 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4322 | path_t path = PATH_T_INITIALIZE("open", "path", 0, 0); |
| 4323 | int flags; |
| 4324 | int mode = 511; |
| 4325 | int dir_fd = DEFAULT_DIR_FD; |
| 4326 | int _return_value; |
| 4327 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4328 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
| 4329 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4330 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4331 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4332 | if (!path_converter(args[0], &path)) { |
| 4333 | goto exit; |
| 4334 | } |
| 4335 | if (PyFloat_Check(args[1])) { |
| 4336 | PyErr_SetString(PyExc_TypeError, |
| 4337 | "integer argument expected, got float" ); |
| 4338 | goto exit; |
| 4339 | } |
| 4340 | flags = _PyLong_AsInt(args[1]); |
| 4341 | if (flags == -1 && PyErr_Occurred()) { |
| 4342 | goto exit; |
| 4343 | } |
| 4344 | if (!noptargs) { |
| 4345 | goto skip_optional_pos; |
| 4346 | } |
| 4347 | if (args[2]) { |
| 4348 | if (PyFloat_Check(args[2])) { |
| 4349 | PyErr_SetString(PyExc_TypeError, |
| 4350 | "integer argument expected, got float" ); |
| 4351 | goto exit; |
| 4352 | } |
| 4353 | mode = _PyLong_AsInt(args[2]); |
| 4354 | if (mode == -1 && PyErr_Occurred()) { |
| 4355 | goto exit; |
| 4356 | } |
| 4357 | if (!--noptargs) { |
| 4358 | goto skip_optional_pos; |
| 4359 | } |
| 4360 | } |
| 4361 | skip_optional_pos: |
| 4362 | if (!noptargs) { |
| 4363 | goto skip_optional_kwonly; |
| 4364 | } |
| 4365 | if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
| 4366 | goto exit; |
| 4367 | } |
| 4368 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4369 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4370 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4371 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4372 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4373 | return_value = PyLong_FromLong((long)_return_value); |
| 4374 | |
| 4375 | exit: |
| 4376 | /* Cleanup for path */ |
| 4377 | path_cleanup(&path); |
| 4378 | |
| 4379 | return return_value; |
| 4380 | } |
| 4381 | |
| 4382 | PyDoc_STRVAR(os_close__doc__, |
| 4383 | "close($module, /, fd)\n" |
| 4384 | "--\n" |
| 4385 | "\n" |
| 4386 | "Close a file descriptor."); |
| 4387 | |
| 4388 | #define OS_CLOSE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4389 | {"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] | 4390 | |
| 4391 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4392 | os_close_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4393 | |
| 4394 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4395 | 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] | 4396 | { |
| 4397 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4398 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4399 | static _PyArg_Parser _parser = {NULL, _keywords, "close", 0}; |
| 4400 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4401 | int fd; |
| 4402 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4403 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 4404 | if (!args) { |
| 4405 | goto exit; |
| 4406 | } |
| 4407 | if (PyFloat_Check(args[0])) { |
| 4408 | PyErr_SetString(PyExc_TypeError, |
| 4409 | "integer argument expected, got float" ); |
| 4410 | goto exit; |
| 4411 | } |
| 4412 | fd = _PyLong_AsInt(args[0]); |
| 4413 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4414 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4415 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4416 | return_value = os_close_impl(module, fd); |
| 4417 | |
| 4418 | exit: |
| 4419 | return return_value; |
| 4420 | } |
| 4421 | |
| 4422 | PyDoc_STRVAR(os_closerange__doc__, |
| 4423 | "closerange($module, fd_low, fd_high, /)\n" |
| 4424 | "--\n" |
| 4425 | "\n" |
| 4426 | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
| 4427 | |
| 4428 | #define OS_CLOSERANGE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4429 | {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4430 | |
| 4431 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4432 | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4433 | |
| 4434 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4435 | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4436 | { |
| 4437 | PyObject *return_value = NULL; |
| 4438 | int fd_low; |
| 4439 | int fd_high; |
| 4440 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4441 | if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { |
| 4442 | goto exit; |
| 4443 | } |
| 4444 | if (PyFloat_Check(args[0])) { |
| 4445 | PyErr_SetString(PyExc_TypeError, |
| 4446 | "integer argument expected, got float" ); |
| 4447 | goto exit; |
| 4448 | } |
| 4449 | fd_low = _PyLong_AsInt(args[0]); |
| 4450 | if (fd_low == -1 && PyErr_Occurred()) { |
| 4451 | goto exit; |
| 4452 | } |
| 4453 | if (PyFloat_Check(args[1])) { |
| 4454 | PyErr_SetString(PyExc_TypeError, |
| 4455 | "integer argument expected, got float" ); |
| 4456 | goto exit; |
| 4457 | } |
| 4458 | fd_high = _PyLong_AsInt(args[1]); |
| 4459 | if (fd_high == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4460 | goto exit; |
| 4461 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4462 | return_value = os_closerange_impl(module, fd_low, fd_high); |
| 4463 | |
| 4464 | exit: |
| 4465 | return return_value; |
| 4466 | } |
| 4467 | |
| 4468 | PyDoc_STRVAR(os_dup__doc__, |
| 4469 | "dup($module, fd, /)\n" |
| 4470 | "--\n" |
| 4471 | "\n" |
| 4472 | "Return a duplicate of a file descriptor."); |
| 4473 | |
| 4474 | #define OS_DUP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4475 | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4476 | |
| 4477 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4478 | os_dup_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4479 | |
| 4480 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4481 | os_dup(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4482 | { |
| 4483 | PyObject *return_value = NULL; |
| 4484 | int fd; |
| 4485 | int _return_value; |
| 4486 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4487 | if (PyFloat_Check(arg)) { |
| 4488 | PyErr_SetString(PyExc_TypeError, |
| 4489 | "integer argument expected, got float" ); |
| 4490 | goto exit; |
| 4491 | } |
| 4492 | fd = _PyLong_AsInt(arg); |
| 4493 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4494 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4495 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4496 | _return_value = os_dup_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4497 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4498 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4499 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4500 | return_value = PyLong_FromLong((long)_return_value); |
| 4501 | |
| 4502 | exit: |
| 4503 | return return_value; |
| 4504 | } |
| 4505 | |
| 4506 | PyDoc_STRVAR(os_dup2__doc__, |
| 4507 | "dup2($module, /, fd, fd2, inheritable=True)\n" |
| 4508 | "--\n" |
| 4509 | "\n" |
| 4510 | "Duplicate file descriptor."); |
| 4511 | |
| 4512 | #define OS_DUP2_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4513 | {"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] | 4514 | |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 4515 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4516 | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4517 | |
| 4518 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4519 | 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] | 4520 | { |
| 4521 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4522 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4523 | static _PyArg_Parser _parser = {NULL, _keywords, "dup2", 0}; |
| 4524 | PyObject *argsbuf[3]; |
| 4525 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4526 | int fd; |
| 4527 | int fd2; |
| 4528 | int inheritable = 1; |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 4529 | int _return_value; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4530 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4531 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
| 4532 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4533 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4534 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 4535 | if (PyFloat_Check(args[0])) { |
| 4536 | PyErr_SetString(PyExc_TypeError, |
| 4537 | "integer argument expected, got float" ); |
| 4538 | goto exit; |
| 4539 | } |
| 4540 | fd = _PyLong_AsInt(args[0]); |
| 4541 | if (fd == -1 && PyErr_Occurred()) { |
| 4542 | goto exit; |
| 4543 | } |
| 4544 | if (PyFloat_Check(args[1])) { |
| 4545 | PyErr_SetString(PyExc_TypeError, |
| 4546 | "integer argument expected, got float" ); |
| 4547 | goto exit; |
| 4548 | } |
| 4549 | fd2 = _PyLong_AsInt(args[1]); |
| 4550 | if (fd2 == -1 && PyErr_Occurred()) { |
| 4551 | goto exit; |
| 4552 | } |
| 4553 | if (!noptargs) { |
| 4554 | goto skip_optional_pos; |
| 4555 | } |
| 4556 | inheritable = PyObject_IsTrue(args[2]); |
| 4557 | if (inheritable < 0) { |
| 4558 | goto exit; |
| 4559 | } |
| 4560 | skip_optional_pos: |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 4561 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
| 4562 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 4563 | goto exit; |
| 4564 | } |
| 4565 | return_value = PyLong_FromLong((long)_return_value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4566 | |
| 4567 | exit: |
| 4568 | return return_value; |
| 4569 | } |
| 4570 | |
| 4571 | #if defined(HAVE_LOCKF) |
| 4572 | |
| 4573 | PyDoc_STRVAR(os_lockf__doc__, |
| 4574 | "lockf($module, fd, command, length, /)\n" |
| 4575 | "--\n" |
| 4576 | "\n" |
| 4577 | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
| 4578 | "\n" |
| 4579 | " fd\n" |
| 4580 | " An open file descriptor.\n" |
| 4581 | " command\n" |
| 4582 | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
| 4583 | " length\n" |
| 4584 | " The number of bytes to lock, starting at the current position."); |
| 4585 | |
| 4586 | #define OS_LOCKF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4587 | {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4588 | |
| 4589 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4590 | 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] | 4591 | |
| 4592 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4593 | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4594 | { |
| 4595 | PyObject *return_value = NULL; |
| 4596 | int fd; |
| 4597 | int command; |
| 4598 | Py_off_t length; |
| 4599 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4600 | if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { |
| 4601 | goto exit; |
| 4602 | } |
| 4603 | if (PyFloat_Check(args[0])) { |
| 4604 | PyErr_SetString(PyExc_TypeError, |
| 4605 | "integer argument expected, got float" ); |
| 4606 | goto exit; |
| 4607 | } |
| 4608 | fd = _PyLong_AsInt(args[0]); |
| 4609 | if (fd == -1 && PyErr_Occurred()) { |
| 4610 | goto exit; |
| 4611 | } |
| 4612 | if (PyFloat_Check(args[1])) { |
| 4613 | PyErr_SetString(PyExc_TypeError, |
| 4614 | "integer argument expected, got float" ); |
| 4615 | goto exit; |
| 4616 | } |
| 4617 | command = _PyLong_AsInt(args[1]); |
| 4618 | if (command == -1 && PyErr_Occurred()) { |
| 4619 | goto exit; |
| 4620 | } |
| 4621 | if (!Py_off_t_converter(args[2], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4622 | goto exit; |
| 4623 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4624 | return_value = os_lockf_impl(module, fd, command, length); |
| 4625 | |
| 4626 | exit: |
| 4627 | return return_value; |
| 4628 | } |
| 4629 | |
| 4630 | #endif /* defined(HAVE_LOCKF) */ |
| 4631 | |
| 4632 | PyDoc_STRVAR(os_lseek__doc__, |
| 4633 | "lseek($module, fd, position, how, /)\n" |
| 4634 | "--\n" |
| 4635 | "\n" |
| 4636 | "Set the position of a file descriptor. Return the new position.\n" |
| 4637 | "\n" |
| 4638 | "Return the new cursor position in number of bytes\n" |
| 4639 | "relative to the beginning of the file."); |
| 4640 | |
| 4641 | #define OS_LSEEK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4642 | {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4643 | |
| 4644 | static Py_off_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4645 | 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] | 4646 | |
| 4647 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4648 | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4649 | { |
| 4650 | PyObject *return_value = NULL; |
| 4651 | int fd; |
| 4652 | Py_off_t position; |
| 4653 | int how; |
| 4654 | Py_off_t _return_value; |
| 4655 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4656 | if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { |
| 4657 | goto exit; |
| 4658 | } |
| 4659 | if (PyFloat_Check(args[0])) { |
| 4660 | PyErr_SetString(PyExc_TypeError, |
| 4661 | "integer argument expected, got float" ); |
| 4662 | goto exit; |
| 4663 | } |
| 4664 | fd = _PyLong_AsInt(args[0]); |
| 4665 | if (fd == -1 && PyErr_Occurred()) { |
| 4666 | goto exit; |
| 4667 | } |
| 4668 | if (!Py_off_t_converter(args[1], &position)) { |
| 4669 | goto exit; |
| 4670 | } |
| 4671 | if (PyFloat_Check(args[2])) { |
| 4672 | PyErr_SetString(PyExc_TypeError, |
| 4673 | "integer argument expected, got float" ); |
| 4674 | goto exit; |
| 4675 | } |
| 4676 | how = _PyLong_AsInt(args[2]); |
| 4677 | if (how == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4678 | goto exit; |
| 4679 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4680 | _return_value = os_lseek_impl(module, fd, position, how); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4681 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4682 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4683 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4684 | return_value = PyLong_FromPy_off_t(_return_value); |
| 4685 | |
| 4686 | exit: |
| 4687 | return return_value; |
| 4688 | } |
| 4689 | |
| 4690 | PyDoc_STRVAR(os_read__doc__, |
| 4691 | "read($module, fd, length, /)\n" |
| 4692 | "--\n" |
| 4693 | "\n" |
| 4694 | "Read from a file descriptor. Returns a bytes object."); |
| 4695 | |
| 4696 | #define OS_READ_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4697 | {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4698 | |
| 4699 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4700 | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4701 | |
| 4702 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4703 | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4704 | { |
| 4705 | PyObject *return_value = NULL; |
| 4706 | int fd; |
| 4707 | Py_ssize_t length; |
| 4708 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4709 | if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4710 | goto exit; |
| 4711 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4712 | if (PyFloat_Check(args[0])) { |
| 4713 | PyErr_SetString(PyExc_TypeError, |
| 4714 | "integer argument expected, got float" ); |
| 4715 | goto exit; |
| 4716 | } |
| 4717 | fd = _PyLong_AsInt(args[0]); |
| 4718 | if (fd == -1 && PyErr_Occurred()) { |
| 4719 | goto exit; |
| 4720 | } |
| 4721 | if (PyFloat_Check(args[1])) { |
| 4722 | PyErr_SetString(PyExc_TypeError, |
| 4723 | "integer argument expected, got float" ); |
| 4724 | goto exit; |
| 4725 | } |
| 4726 | { |
| 4727 | Py_ssize_t ival = -1; |
| 4728 | PyObject *iobj = PyNumber_Index(args[1]); |
| 4729 | if (iobj != NULL) { |
| 4730 | ival = PyLong_AsSsize_t(iobj); |
| 4731 | Py_DECREF(iobj); |
| 4732 | } |
| 4733 | if (ival == -1 && PyErr_Occurred()) { |
| 4734 | goto exit; |
| 4735 | } |
| 4736 | length = ival; |
| 4737 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4738 | return_value = os_read_impl(module, fd, length); |
| 4739 | |
| 4740 | exit: |
| 4741 | return return_value; |
| 4742 | } |
| 4743 | |
| 4744 | #if defined(HAVE_READV) |
| 4745 | |
| 4746 | PyDoc_STRVAR(os_readv__doc__, |
| 4747 | "readv($module, fd, buffers, /)\n" |
| 4748 | "--\n" |
| 4749 | "\n" |
| 4750 | "Read from a file descriptor fd into an iterable of buffers.\n" |
| 4751 | "\n" |
| 4752 | "The buffers should be mutable buffers accepting bytes.\n" |
| 4753 | "readv will transfer data into each buffer until it is full\n" |
| 4754 | "and then move on to the next buffer in the sequence to hold\n" |
| 4755 | "the rest of the data.\n" |
| 4756 | "\n" |
| 4757 | "readv returns the total number of bytes read,\n" |
| 4758 | "which may be less than the total capacity of all the buffers."); |
| 4759 | |
| 4760 | #define OS_READV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4761 | {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4762 | |
| 4763 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4764 | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4765 | |
| 4766 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4767 | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4768 | { |
| 4769 | PyObject *return_value = NULL; |
| 4770 | int fd; |
| 4771 | PyObject *buffers; |
| 4772 | Py_ssize_t _return_value; |
| 4773 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4774 | if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4775 | goto exit; |
| 4776 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4777 | if (PyFloat_Check(args[0])) { |
| 4778 | PyErr_SetString(PyExc_TypeError, |
| 4779 | "integer argument expected, got float" ); |
| 4780 | goto exit; |
| 4781 | } |
| 4782 | fd = _PyLong_AsInt(args[0]); |
| 4783 | if (fd == -1 && PyErr_Occurred()) { |
| 4784 | goto exit; |
| 4785 | } |
| 4786 | buffers = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4787 | _return_value = os_readv_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4788 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4789 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4790 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4791 | return_value = PyLong_FromSsize_t(_return_value); |
| 4792 | |
| 4793 | exit: |
| 4794 | return return_value; |
| 4795 | } |
| 4796 | |
| 4797 | #endif /* defined(HAVE_READV) */ |
| 4798 | |
| 4799 | #if defined(HAVE_PREAD) |
| 4800 | |
| 4801 | PyDoc_STRVAR(os_pread__doc__, |
| 4802 | "pread($module, fd, length, offset, /)\n" |
| 4803 | "--\n" |
| 4804 | "\n" |
| 4805 | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
| 4806 | "\n" |
| 4807 | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
| 4808 | "the beginning of the file. The file offset remains unchanged."); |
| 4809 | |
| 4810 | #define OS_PREAD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4811 | {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4812 | |
| 4813 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4814 | os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4815 | |
| 4816 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4817 | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4818 | { |
| 4819 | PyObject *return_value = NULL; |
| 4820 | int fd; |
| 4821 | int length; |
| 4822 | Py_off_t offset; |
| 4823 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4824 | if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { |
| 4825 | goto exit; |
| 4826 | } |
| 4827 | if (PyFloat_Check(args[0])) { |
| 4828 | PyErr_SetString(PyExc_TypeError, |
| 4829 | "integer argument expected, got float" ); |
| 4830 | goto exit; |
| 4831 | } |
| 4832 | fd = _PyLong_AsInt(args[0]); |
| 4833 | if (fd == -1 && PyErr_Occurred()) { |
| 4834 | goto exit; |
| 4835 | } |
| 4836 | if (PyFloat_Check(args[1])) { |
| 4837 | PyErr_SetString(PyExc_TypeError, |
| 4838 | "integer argument expected, got float" ); |
| 4839 | goto exit; |
| 4840 | } |
| 4841 | length = _PyLong_AsInt(args[1]); |
| 4842 | if (length == -1 && PyErr_Occurred()) { |
| 4843 | goto exit; |
| 4844 | } |
| 4845 | if (!Py_off_t_converter(args[2], &offset)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4846 | goto exit; |
| 4847 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4848 | return_value = os_pread_impl(module, fd, length, offset); |
| 4849 | |
| 4850 | exit: |
| 4851 | return return_value; |
| 4852 | } |
| 4853 | |
| 4854 | #endif /* defined(HAVE_PREAD) */ |
| 4855 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4856 | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
| 4857 | |
| 4858 | PyDoc_STRVAR(os_preadv__doc__, |
| 4859 | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
| 4860 | "--\n" |
| 4861 | "\n" |
| 4862 | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
| 4863 | "\n" |
| 4864 | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
| 4865 | "transfer data into each buffer until it is full and then move on to the next\n" |
| 4866 | "buffer in the sequence to hold the rest of the data. Its fourth argument,\n" |
| 4867 | "specifies the file offset at which the input operation is to be performed. It\n" |
| 4868 | "will return the total number of bytes read (which can be less than the total\n" |
| 4869 | "capacity of all the objects).\n" |
| 4870 | "\n" |
| 4871 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
| 4872 | "\n" |
| 4873 | "- RWF_HIPRI\n" |
| 4874 | "- RWF_NOWAIT\n" |
| 4875 | "\n" |
| 4876 | "Using non-zero flags requires Linux 4.6 or newer."); |
| 4877 | |
| 4878 | #define OS_PREADV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4879 | {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__}, |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4880 | |
| 4881 | static Py_ssize_t |
| 4882 | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
| 4883 | int flags); |
| 4884 | |
| 4885 | static PyObject * |
| 4886 | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 4887 | { |
| 4888 | PyObject *return_value = NULL; |
| 4889 | int fd; |
| 4890 | PyObject *buffers; |
| 4891 | Py_off_t offset; |
| 4892 | int flags = 0; |
| 4893 | Py_ssize_t _return_value; |
| 4894 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4895 | if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4896 | goto exit; |
| 4897 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4898 | if (PyFloat_Check(args[0])) { |
| 4899 | PyErr_SetString(PyExc_TypeError, |
| 4900 | "integer argument expected, got float" ); |
| 4901 | goto exit; |
| 4902 | } |
| 4903 | fd = _PyLong_AsInt(args[0]); |
| 4904 | if (fd == -1 && PyErr_Occurred()) { |
| 4905 | goto exit; |
| 4906 | } |
| 4907 | buffers = args[1]; |
| 4908 | if (!Py_off_t_converter(args[2], &offset)) { |
| 4909 | goto exit; |
| 4910 | } |
| 4911 | if (nargs < 4) { |
| 4912 | goto skip_optional; |
| 4913 | } |
| 4914 | if (PyFloat_Check(args[3])) { |
| 4915 | PyErr_SetString(PyExc_TypeError, |
| 4916 | "integer argument expected, got float" ); |
| 4917 | goto exit; |
| 4918 | } |
| 4919 | flags = _PyLong_AsInt(args[3]); |
| 4920 | if (flags == -1 && PyErr_Occurred()) { |
| 4921 | goto exit; |
| 4922 | } |
| 4923 | skip_optional: |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4924 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
| 4925 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 4926 | goto exit; |
| 4927 | } |
| 4928 | return_value = PyLong_FromSsize_t(_return_value); |
| 4929 | |
| 4930 | exit: |
| 4931 | return return_value; |
| 4932 | } |
| 4933 | |
| 4934 | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
| 4935 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4936 | PyDoc_STRVAR(os_write__doc__, |
| 4937 | "write($module, fd, data, /)\n" |
| 4938 | "--\n" |
| 4939 | "\n" |
| 4940 | "Write a bytes object to a file descriptor."); |
| 4941 | |
| 4942 | #define OS_WRITE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4943 | {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4944 | |
| 4945 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4946 | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4947 | |
| 4948 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4949 | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4950 | { |
| 4951 | PyObject *return_value = NULL; |
| 4952 | int fd; |
| 4953 | Py_buffer data = {NULL, NULL}; |
| 4954 | Py_ssize_t _return_value; |
| 4955 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4956 | if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { |
| 4957 | goto exit; |
| 4958 | } |
| 4959 | if (PyFloat_Check(args[0])) { |
| 4960 | PyErr_SetString(PyExc_TypeError, |
| 4961 | "integer argument expected, got float" ); |
| 4962 | goto exit; |
| 4963 | } |
| 4964 | fd = _PyLong_AsInt(args[0]); |
| 4965 | if (fd == -1 && PyErr_Occurred()) { |
| 4966 | goto exit; |
| 4967 | } |
| 4968 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
| 4969 | goto exit; |
| 4970 | } |
| 4971 | if (!PyBuffer_IsContiguous(&data, 'C')) { |
| 4972 | _PyArg_BadArgument("write", 2, "contiguous buffer", args[1]); |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4973 | goto exit; |
| 4974 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4975 | _return_value = os_write_impl(module, fd, &data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4976 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4977 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4978 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4979 | return_value = PyLong_FromSsize_t(_return_value); |
| 4980 | |
| 4981 | exit: |
| 4982 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4983 | if (data.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4984 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4985 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4986 | |
| 4987 | return return_value; |
| 4988 | } |
| 4989 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4990 | #if defined(__APPLE__) |
| 4991 | |
| 4992 | PyDoc_STRVAR(os__fcopyfile__doc__, |
| 4993 | "_fcopyfile($module, infd, outfd, flags, /)\n" |
| 4994 | "--\n" |
| 4995 | "\n" |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 4996 | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4997 | |
| 4998 | #define OS__FCOPYFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4999 | {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__}, |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 5000 | |
| 5001 | static PyObject * |
| 5002 | os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags); |
| 5003 | |
| 5004 | static PyObject * |
| 5005 | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 5006 | { |
| 5007 | PyObject *return_value = NULL; |
| 5008 | int infd; |
| 5009 | int outfd; |
| 5010 | int flags; |
| 5011 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5012 | if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { |
| 5013 | goto exit; |
| 5014 | } |
| 5015 | if (PyFloat_Check(args[0])) { |
| 5016 | PyErr_SetString(PyExc_TypeError, |
| 5017 | "integer argument expected, got float" ); |
| 5018 | goto exit; |
| 5019 | } |
| 5020 | infd = _PyLong_AsInt(args[0]); |
| 5021 | if (infd == -1 && PyErr_Occurred()) { |
| 5022 | goto exit; |
| 5023 | } |
| 5024 | if (PyFloat_Check(args[1])) { |
| 5025 | PyErr_SetString(PyExc_TypeError, |
| 5026 | "integer argument expected, got float" ); |
| 5027 | goto exit; |
| 5028 | } |
| 5029 | outfd = _PyLong_AsInt(args[1]); |
| 5030 | if (outfd == -1 && PyErr_Occurred()) { |
| 5031 | goto exit; |
| 5032 | } |
| 5033 | if (PyFloat_Check(args[2])) { |
| 5034 | PyErr_SetString(PyExc_TypeError, |
| 5035 | "integer argument expected, got float" ); |
| 5036 | goto exit; |
| 5037 | } |
| 5038 | flags = _PyLong_AsInt(args[2]); |
| 5039 | if (flags == -1 && PyErr_Occurred()) { |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 5040 | goto exit; |
| 5041 | } |
| 5042 | return_value = os__fcopyfile_impl(module, infd, outfd, flags); |
| 5043 | |
| 5044 | exit: |
| 5045 | return return_value; |
| 5046 | } |
| 5047 | |
| 5048 | #endif /* defined(__APPLE__) */ |
| 5049 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5050 | PyDoc_STRVAR(os_fstat__doc__, |
| 5051 | "fstat($module, /, fd)\n" |
| 5052 | "--\n" |
| 5053 | "\n" |
| 5054 | "Perform a stat system call on the given file descriptor.\n" |
| 5055 | "\n" |
| 5056 | "Like stat(), but for an open file descriptor.\n" |
| 5057 | "Equivalent to os.stat(fd)."); |
| 5058 | |
| 5059 | #define OS_FSTAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5060 | {"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] | 5061 | |
| 5062 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5063 | os_fstat_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5064 | |
| 5065 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5066 | 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] | 5067 | { |
| 5068 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5069 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5070 | static _PyArg_Parser _parser = {NULL, _keywords, "fstat", 0}; |
| 5071 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5072 | int fd; |
| 5073 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5074 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 5075 | if (!args) { |
| 5076 | goto exit; |
| 5077 | } |
| 5078 | if (PyFloat_Check(args[0])) { |
| 5079 | PyErr_SetString(PyExc_TypeError, |
| 5080 | "integer argument expected, got float" ); |
| 5081 | goto exit; |
| 5082 | } |
| 5083 | fd = _PyLong_AsInt(args[0]); |
| 5084 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5085 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5086 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5087 | return_value = os_fstat_impl(module, fd); |
| 5088 | |
| 5089 | exit: |
| 5090 | return return_value; |
| 5091 | } |
| 5092 | |
| 5093 | PyDoc_STRVAR(os_isatty__doc__, |
| 5094 | "isatty($module, fd, /)\n" |
| 5095 | "--\n" |
| 5096 | "\n" |
| 5097 | "Return True if the fd is connected to a terminal.\n" |
| 5098 | "\n" |
| 5099 | "Return True if the file descriptor is an open file descriptor\n" |
| 5100 | "connected to the slave end of a terminal."); |
| 5101 | |
| 5102 | #define OS_ISATTY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5103 | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5104 | |
| 5105 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5106 | os_isatty_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5107 | |
| 5108 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5109 | os_isatty(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5110 | { |
| 5111 | PyObject *return_value = NULL; |
| 5112 | int fd; |
| 5113 | int _return_value; |
| 5114 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5115 | if (PyFloat_Check(arg)) { |
| 5116 | PyErr_SetString(PyExc_TypeError, |
| 5117 | "integer argument expected, got float" ); |
| 5118 | goto exit; |
| 5119 | } |
| 5120 | fd = _PyLong_AsInt(arg); |
| 5121 | if (fd == -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 = os_isatty_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5125 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5126 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5127 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5128 | return_value = PyBool_FromLong((long)_return_value); |
| 5129 | |
| 5130 | exit: |
| 5131 | return return_value; |
| 5132 | } |
| 5133 | |
| 5134 | #if defined(HAVE_PIPE) |
| 5135 | |
| 5136 | PyDoc_STRVAR(os_pipe__doc__, |
| 5137 | "pipe($module, /)\n" |
| 5138 | "--\n" |
| 5139 | "\n" |
| 5140 | "Create a pipe.\n" |
| 5141 | "\n" |
| 5142 | "Returns a tuple of two file descriptors:\n" |
| 5143 | " (read_fd, write_fd)"); |
| 5144 | |
| 5145 | #define OS_PIPE_METHODDEF \ |
| 5146 | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
| 5147 | |
| 5148 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5149 | os_pipe_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5150 | |
| 5151 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5152 | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5153 | { |
| 5154 | return os_pipe_impl(module); |
| 5155 | } |
| 5156 | |
| 5157 | #endif /* defined(HAVE_PIPE) */ |
| 5158 | |
| 5159 | #if defined(HAVE_PIPE2) |
| 5160 | |
| 5161 | PyDoc_STRVAR(os_pipe2__doc__, |
| 5162 | "pipe2($module, flags, /)\n" |
| 5163 | "--\n" |
| 5164 | "\n" |
| 5165 | "Create a pipe with flags set atomically.\n" |
| 5166 | "\n" |
| 5167 | "Returns a tuple of two file descriptors:\n" |
| 5168 | " (read_fd, write_fd)\n" |
| 5169 | "\n" |
| 5170 | "flags can be constructed by ORing together one or more of these values:\n" |
| 5171 | "O_NONBLOCK, O_CLOEXEC."); |
| 5172 | |
| 5173 | #define OS_PIPE2_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5174 | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5175 | |
| 5176 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5177 | os_pipe2_impl(PyObject *module, int flags); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5178 | |
| 5179 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5180 | os_pipe2(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5181 | { |
| 5182 | PyObject *return_value = NULL; |
| 5183 | int flags; |
| 5184 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5185 | if (PyFloat_Check(arg)) { |
| 5186 | PyErr_SetString(PyExc_TypeError, |
| 5187 | "integer argument expected, got float" ); |
| 5188 | goto exit; |
| 5189 | } |
| 5190 | flags = _PyLong_AsInt(arg); |
| 5191 | if (flags == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5192 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5193 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5194 | return_value = os_pipe2_impl(module, flags); |
| 5195 | |
| 5196 | exit: |
| 5197 | return return_value; |
| 5198 | } |
| 5199 | |
| 5200 | #endif /* defined(HAVE_PIPE2) */ |
| 5201 | |
| 5202 | #if defined(HAVE_WRITEV) |
| 5203 | |
| 5204 | PyDoc_STRVAR(os_writev__doc__, |
| 5205 | "writev($module, fd, buffers, /)\n" |
| 5206 | "--\n" |
| 5207 | "\n" |
| 5208 | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
| 5209 | "\n" |
| 5210 | "Returns the total number of bytes written.\n" |
| 5211 | "buffers must be a sequence of bytes-like objects."); |
| 5212 | |
| 5213 | #define OS_WRITEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5214 | {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5215 | |
| 5216 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5217 | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5218 | |
| 5219 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5220 | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5221 | { |
| 5222 | PyObject *return_value = NULL; |
| 5223 | int fd; |
| 5224 | PyObject *buffers; |
| 5225 | Py_ssize_t _return_value; |
| 5226 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5227 | if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5228 | goto exit; |
| 5229 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5230 | if (PyFloat_Check(args[0])) { |
| 5231 | PyErr_SetString(PyExc_TypeError, |
| 5232 | "integer argument expected, got float" ); |
| 5233 | goto exit; |
| 5234 | } |
| 5235 | fd = _PyLong_AsInt(args[0]); |
| 5236 | if (fd == -1 && PyErr_Occurred()) { |
| 5237 | goto exit; |
| 5238 | } |
| 5239 | buffers = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5240 | _return_value = os_writev_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5241 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5242 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5243 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5244 | return_value = PyLong_FromSsize_t(_return_value); |
| 5245 | |
| 5246 | exit: |
| 5247 | return return_value; |
| 5248 | } |
| 5249 | |
| 5250 | #endif /* defined(HAVE_WRITEV) */ |
| 5251 | |
| 5252 | #if defined(HAVE_PWRITE) |
| 5253 | |
| 5254 | PyDoc_STRVAR(os_pwrite__doc__, |
| 5255 | "pwrite($module, fd, buffer, offset, /)\n" |
| 5256 | "--\n" |
| 5257 | "\n" |
| 5258 | "Write bytes to a file descriptor starting at a particular offset.\n" |
| 5259 | "\n" |
| 5260 | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
| 5261 | "the file. Returns the number of bytes writte. Does not change the\n" |
| 5262 | "current file offset."); |
| 5263 | |
| 5264 | #define OS_PWRITE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5265 | {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5266 | |
| 5267 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5268 | 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] | 5269 | |
| 5270 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5271 | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5272 | { |
| 5273 | PyObject *return_value = NULL; |
| 5274 | int fd; |
| 5275 | Py_buffer buffer = {NULL, NULL}; |
| 5276 | Py_off_t offset; |
| 5277 | Py_ssize_t _return_value; |
| 5278 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5279 | if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { |
| 5280 | goto exit; |
| 5281 | } |
| 5282 | if (PyFloat_Check(args[0])) { |
| 5283 | PyErr_SetString(PyExc_TypeError, |
| 5284 | "integer argument expected, got float" ); |
| 5285 | goto exit; |
| 5286 | } |
| 5287 | fd = _PyLong_AsInt(args[0]); |
| 5288 | if (fd == -1 && PyErr_Occurred()) { |
| 5289 | goto exit; |
| 5290 | } |
| 5291 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
| 5292 | goto exit; |
| 5293 | } |
| 5294 | if (!PyBuffer_IsContiguous(&buffer, 'C')) { |
| 5295 | _PyArg_BadArgument("pwrite", 2, "contiguous buffer", args[1]); |
| 5296 | goto exit; |
| 5297 | } |
| 5298 | if (!Py_off_t_converter(args[2], &offset)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5299 | goto exit; |
| 5300 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5301 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5302 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5303 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5304 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5305 | return_value = PyLong_FromSsize_t(_return_value); |
| 5306 | |
| 5307 | exit: |
| 5308 | /* Cleanup for buffer */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5309 | if (buffer.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5310 | PyBuffer_Release(&buffer); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5311 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5312 | |
| 5313 | return return_value; |
| 5314 | } |
| 5315 | |
| 5316 | #endif /* defined(HAVE_PWRITE) */ |
| 5317 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 5318 | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
| 5319 | |
| 5320 | PyDoc_STRVAR(os_pwritev__doc__, |
| 5321 | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
| 5322 | "--\n" |
| 5323 | "\n" |
| 5324 | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
| 5325 | "\n" |
| 5326 | "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n" |
| 5327 | "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n" |
| 5328 | "buffer is written before proceeding to second, and so on. The operating system may\n" |
| 5329 | "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n" |
| 5330 | "This function writes the contents of each object to the file descriptor and returns\n" |
| 5331 | "the total number of bytes written.\n" |
| 5332 | "\n" |
| 5333 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
| 5334 | "\n" |
| 5335 | "- RWF_DSYNC\n" |
| 5336 | "- RWF_SYNC\n" |
| 5337 | "\n" |
| 5338 | "Using non-zero flags requires Linux 4.7 or newer."); |
| 5339 | |
| 5340 | #define OS_PWRITEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5341 | {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__}, |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 5342 | |
| 5343 | static Py_ssize_t |
| 5344 | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
| 5345 | int flags); |
| 5346 | |
| 5347 | static PyObject * |
| 5348 | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 5349 | { |
| 5350 | PyObject *return_value = NULL; |
| 5351 | int fd; |
| 5352 | PyObject *buffers; |
| 5353 | Py_off_t offset; |
| 5354 | int flags = 0; |
| 5355 | Py_ssize_t _return_value; |
| 5356 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5357 | if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 5358 | goto exit; |
| 5359 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5360 | if (PyFloat_Check(args[0])) { |
| 5361 | PyErr_SetString(PyExc_TypeError, |
| 5362 | "integer argument expected, got float" ); |
| 5363 | goto exit; |
| 5364 | } |
| 5365 | fd = _PyLong_AsInt(args[0]); |
| 5366 | if (fd == -1 && PyErr_Occurred()) { |
| 5367 | goto exit; |
| 5368 | } |
| 5369 | buffers = args[1]; |
| 5370 | if (!Py_off_t_converter(args[2], &offset)) { |
| 5371 | goto exit; |
| 5372 | } |
| 5373 | if (nargs < 4) { |
| 5374 | goto skip_optional; |
| 5375 | } |
| 5376 | if (PyFloat_Check(args[3])) { |
| 5377 | PyErr_SetString(PyExc_TypeError, |
| 5378 | "integer argument expected, got float" ); |
| 5379 | goto exit; |
| 5380 | } |
| 5381 | flags = _PyLong_AsInt(args[3]); |
| 5382 | if (flags == -1 && PyErr_Occurred()) { |
| 5383 | goto exit; |
| 5384 | } |
| 5385 | skip_optional: |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 5386 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
| 5387 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 5388 | goto exit; |
| 5389 | } |
| 5390 | return_value = PyLong_FromSsize_t(_return_value); |
| 5391 | |
| 5392 | exit: |
| 5393 | return return_value; |
| 5394 | } |
| 5395 | |
| 5396 | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
| 5397 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5398 | #if defined(HAVE_MKFIFO) |
| 5399 | |
| 5400 | PyDoc_STRVAR(os_mkfifo__doc__, |
| 5401 | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
| 5402 | "--\n" |
| 5403 | "\n" |
| 5404 | "Create a \"fifo\" (a POSIX named pipe).\n" |
| 5405 | "\n" |
| 5406 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 5407 | " and path should be relative; path will then be relative to that directory.\n" |
| 5408 | "dir_fd may not be implemented on your platform.\n" |
| 5409 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 5410 | |
| 5411 | #define OS_MKFIFO_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5412 | {"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] | 5413 | |
| 5414 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5415 | 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] | 5416 | |
| 5417 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5418 | 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] | 5419 | { |
| 5420 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5421 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5422 | static _PyArg_Parser _parser = {NULL, _keywords, "mkfifo", 0}; |
| 5423 | PyObject *argsbuf[3]; |
| 5424 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5425 | path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0); |
| 5426 | int mode = 438; |
| 5427 | int dir_fd = DEFAULT_DIR_FD; |
| 5428 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5429 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 5430 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5431 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5432 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5433 | if (!path_converter(args[0], &path)) { |
| 5434 | goto exit; |
| 5435 | } |
| 5436 | if (!noptargs) { |
| 5437 | goto skip_optional_pos; |
| 5438 | } |
| 5439 | if (args[1]) { |
| 5440 | if (PyFloat_Check(args[1])) { |
| 5441 | PyErr_SetString(PyExc_TypeError, |
| 5442 | "integer argument expected, got float" ); |
| 5443 | goto exit; |
| 5444 | } |
| 5445 | mode = _PyLong_AsInt(args[1]); |
| 5446 | if (mode == -1 && PyErr_Occurred()) { |
| 5447 | goto exit; |
| 5448 | } |
| 5449 | if (!--noptargs) { |
| 5450 | goto skip_optional_pos; |
| 5451 | } |
| 5452 | } |
| 5453 | skip_optional_pos: |
| 5454 | if (!noptargs) { |
| 5455 | goto skip_optional_kwonly; |
| 5456 | } |
| 5457 | if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
| 5458 | goto exit; |
| 5459 | } |
| 5460 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5461 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
| 5462 | |
| 5463 | exit: |
| 5464 | /* Cleanup for path */ |
| 5465 | path_cleanup(&path); |
| 5466 | |
| 5467 | return return_value; |
| 5468 | } |
| 5469 | |
| 5470 | #endif /* defined(HAVE_MKFIFO) */ |
| 5471 | |
| 5472 | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
| 5473 | |
| 5474 | PyDoc_STRVAR(os_mknod__doc__, |
| 5475 | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
| 5476 | "--\n" |
| 5477 | "\n" |
| 5478 | "Create a node in the file system.\n" |
| 5479 | "\n" |
| 5480 | "Create a node in the file system (file, device special file or named pipe)\n" |
| 5481 | "at path. mode specifies both the permissions to use and the\n" |
| 5482 | "type of node to be created, being combined (bitwise OR) with one of\n" |
| 5483 | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
| 5484 | "device defines the newly created device special file (probably using\n" |
| 5485 | "os.makedev()). Otherwise device is ignored.\n" |
| 5486 | "\n" |
| 5487 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 5488 | " and path should be relative; path will then be relative to that directory.\n" |
| 5489 | "dir_fd may not be implemented on your platform.\n" |
| 5490 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 5491 | |
| 5492 | #define OS_MKNOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5493 | {"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] | 5494 | |
| 5495 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5496 | 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] | 5497 | int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5498 | |
| 5499 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5500 | 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] | 5501 | { |
| 5502 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5503 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5504 | static _PyArg_Parser _parser = {NULL, _keywords, "mknod", 0}; |
| 5505 | PyObject *argsbuf[4]; |
| 5506 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5507 | path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0); |
| 5508 | int mode = 384; |
| 5509 | dev_t device = 0; |
| 5510 | int dir_fd = DEFAULT_DIR_FD; |
| 5511 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5512 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); |
| 5513 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5514 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5515 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5516 | if (!path_converter(args[0], &path)) { |
| 5517 | goto exit; |
| 5518 | } |
| 5519 | if (!noptargs) { |
| 5520 | goto skip_optional_pos; |
| 5521 | } |
| 5522 | if (args[1]) { |
| 5523 | if (PyFloat_Check(args[1])) { |
| 5524 | PyErr_SetString(PyExc_TypeError, |
| 5525 | "integer argument expected, got float" ); |
| 5526 | goto exit; |
| 5527 | } |
| 5528 | mode = _PyLong_AsInt(args[1]); |
| 5529 | if (mode == -1 && PyErr_Occurred()) { |
| 5530 | goto exit; |
| 5531 | } |
| 5532 | if (!--noptargs) { |
| 5533 | goto skip_optional_pos; |
| 5534 | } |
| 5535 | } |
| 5536 | if (args[2]) { |
| 5537 | if (!_Py_Dev_Converter(args[2], &device)) { |
| 5538 | goto exit; |
| 5539 | } |
| 5540 | if (!--noptargs) { |
| 5541 | goto skip_optional_pos; |
| 5542 | } |
| 5543 | } |
| 5544 | skip_optional_pos: |
| 5545 | if (!noptargs) { |
| 5546 | goto skip_optional_kwonly; |
| 5547 | } |
| 5548 | if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
| 5549 | goto exit; |
| 5550 | } |
| 5551 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5552 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
| 5553 | |
| 5554 | exit: |
| 5555 | /* Cleanup for path */ |
| 5556 | path_cleanup(&path); |
| 5557 | |
| 5558 | return return_value; |
| 5559 | } |
| 5560 | |
| 5561 | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
| 5562 | |
| 5563 | #if defined(HAVE_DEVICE_MACROS) |
| 5564 | |
| 5565 | PyDoc_STRVAR(os_major__doc__, |
| 5566 | "major($module, device, /)\n" |
| 5567 | "--\n" |
| 5568 | "\n" |
| 5569 | "Extracts a device major number from a raw device number."); |
| 5570 | |
| 5571 | #define OS_MAJOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5572 | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5573 | |
| 5574 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5575 | os_major_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5576 | |
| 5577 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5578 | os_major(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5579 | { |
| 5580 | PyObject *return_value = NULL; |
| 5581 | dev_t device; |
| 5582 | unsigned int _return_value; |
| 5583 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5584 | if (!_Py_Dev_Converter(arg, &device)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5585 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5586 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5587 | _return_value = os_major_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5588 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5589 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5590 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5591 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 5592 | |
| 5593 | exit: |
| 5594 | return return_value; |
| 5595 | } |
| 5596 | |
| 5597 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 5598 | |
| 5599 | #if defined(HAVE_DEVICE_MACROS) |
| 5600 | |
| 5601 | PyDoc_STRVAR(os_minor__doc__, |
| 5602 | "minor($module, device, /)\n" |
| 5603 | "--\n" |
| 5604 | "\n" |
| 5605 | "Extracts a device minor number from a raw device number."); |
| 5606 | |
| 5607 | #define OS_MINOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5608 | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5609 | |
| 5610 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5611 | os_minor_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5612 | |
| 5613 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5614 | os_minor(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5615 | { |
| 5616 | PyObject *return_value = NULL; |
| 5617 | dev_t device; |
| 5618 | unsigned int _return_value; |
| 5619 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5620 | if (!_Py_Dev_Converter(arg, &device)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5621 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5622 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5623 | _return_value = os_minor_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5624 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5625 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5626 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5627 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 5628 | |
| 5629 | exit: |
| 5630 | return return_value; |
| 5631 | } |
| 5632 | |
| 5633 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 5634 | |
| 5635 | #if defined(HAVE_DEVICE_MACROS) |
| 5636 | |
| 5637 | PyDoc_STRVAR(os_makedev__doc__, |
| 5638 | "makedev($module, major, minor, /)\n" |
| 5639 | "--\n" |
| 5640 | "\n" |
| 5641 | "Composes a raw device number from the major and minor device numbers."); |
| 5642 | |
| 5643 | #define OS_MAKEDEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5644 | {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5645 | |
| 5646 | static dev_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5647 | os_makedev_impl(PyObject *module, int major, int minor); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5648 | |
| 5649 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5650 | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5651 | { |
| 5652 | PyObject *return_value = NULL; |
| 5653 | int major; |
| 5654 | int minor; |
| 5655 | dev_t _return_value; |
| 5656 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5657 | if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { |
| 5658 | goto exit; |
| 5659 | } |
| 5660 | if (PyFloat_Check(args[0])) { |
| 5661 | PyErr_SetString(PyExc_TypeError, |
| 5662 | "integer argument expected, got float" ); |
| 5663 | goto exit; |
| 5664 | } |
| 5665 | major = _PyLong_AsInt(args[0]); |
| 5666 | if (major == -1 && PyErr_Occurred()) { |
| 5667 | goto exit; |
| 5668 | } |
| 5669 | if (PyFloat_Check(args[1])) { |
| 5670 | PyErr_SetString(PyExc_TypeError, |
| 5671 | "integer argument expected, got float" ); |
| 5672 | goto exit; |
| 5673 | } |
| 5674 | minor = _PyLong_AsInt(args[1]); |
| 5675 | if (minor == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5676 | goto exit; |
| 5677 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5678 | _return_value = os_makedev_impl(module, major, minor); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5679 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5680 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5681 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5682 | return_value = _PyLong_FromDev(_return_value); |
| 5683 | |
| 5684 | exit: |
| 5685 | return return_value; |
| 5686 | } |
| 5687 | |
| 5688 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 5689 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 5690 | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5691 | |
| 5692 | PyDoc_STRVAR(os_ftruncate__doc__, |
| 5693 | "ftruncate($module, fd, length, /)\n" |
| 5694 | "--\n" |
| 5695 | "\n" |
| 5696 | "Truncate a file, specified by file descriptor, to a specific length."); |
| 5697 | |
| 5698 | #define OS_FTRUNCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5699 | {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5700 | |
| 5701 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5702 | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5703 | |
| 5704 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5705 | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5706 | { |
| 5707 | PyObject *return_value = NULL; |
| 5708 | int fd; |
| 5709 | Py_off_t length; |
| 5710 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5711 | if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { |
| 5712 | goto exit; |
| 5713 | } |
| 5714 | if (PyFloat_Check(args[0])) { |
| 5715 | PyErr_SetString(PyExc_TypeError, |
| 5716 | "integer argument expected, got float" ); |
| 5717 | goto exit; |
| 5718 | } |
| 5719 | fd = _PyLong_AsInt(args[0]); |
| 5720 | if (fd == -1 && PyErr_Occurred()) { |
| 5721 | goto exit; |
| 5722 | } |
| 5723 | if (!Py_off_t_converter(args[1], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5724 | goto exit; |
| 5725 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5726 | return_value = os_ftruncate_impl(module, fd, length); |
| 5727 | |
| 5728 | exit: |
| 5729 | return return_value; |
| 5730 | } |
| 5731 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 5732 | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5733 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 5734 | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5735 | |
| 5736 | PyDoc_STRVAR(os_truncate__doc__, |
| 5737 | "truncate($module, /, path, length)\n" |
| 5738 | "--\n" |
| 5739 | "\n" |
| 5740 | "Truncate a file, specified by path, to a specific length.\n" |
| 5741 | "\n" |
| 5742 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 5743 | " If this functionality is unavailable, using it raises an exception."); |
| 5744 | |
| 5745 | #define OS_TRUNCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5746 | {"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] | 5747 | |
| 5748 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5749 | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5750 | |
| 5751 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5752 | 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] | 5753 | { |
| 5754 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5755 | static const char * const _keywords[] = {"path", "length", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5756 | static _PyArg_Parser _parser = {NULL, _keywords, "truncate", 0}; |
| 5757 | PyObject *argsbuf[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5758 | path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE); |
| 5759 | Py_off_t length; |
| 5760 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 5761 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 5762 | if (!args) { |
| 5763 | goto exit; |
| 5764 | } |
| 5765 | if (!path_converter(args[0], &path)) { |
| 5766 | goto exit; |
| 5767 | } |
| 5768 | if (!Py_off_t_converter(args[1], &length)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5769 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5770 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5771 | return_value = os_truncate_impl(module, &path, length); |
| 5772 | |
| 5773 | exit: |
| 5774 | /* Cleanup for path */ |
| 5775 | path_cleanup(&path); |
| 5776 | |
| 5777 | return return_value; |
| 5778 | } |
| 5779 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 5780 | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5781 | |
| 5782 | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 5783 | |
| 5784 | PyDoc_STRVAR(os_posix_fallocate__doc__, |
| 5785 | "posix_fallocate($module, fd, offset, length, /)\n" |
| 5786 | "--\n" |
| 5787 | "\n" |
| 5788 | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
| 5789 | "\n" |
| 5790 | "Ensure that the file specified by fd encompasses a range of bytes\n" |
| 5791 | "starting at offset bytes from the beginning and continuing for length bytes."); |
| 5792 | |
| 5793 | #define OS_POSIX_FALLOCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5794 | {"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] | 5795 | |
| 5796 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5797 | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 5798 | Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5799 | |
| 5800 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5801 | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5802 | { |
| 5803 | PyObject *return_value = NULL; |
| 5804 | int fd; |
| 5805 | Py_off_t offset; |
| 5806 | Py_off_t length; |
| 5807 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5808 | if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { |
| 5809 | goto exit; |
| 5810 | } |
| 5811 | if (PyFloat_Check(args[0])) { |
| 5812 | PyErr_SetString(PyExc_TypeError, |
| 5813 | "integer argument expected, got float" ); |
| 5814 | goto exit; |
| 5815 | } |
| 5816 | fd = _PyLong_AsInt(args[0]); |
| 5817 | if (fd == -1 && PyErr_Occurred()) { |
| 5818 | goto exit; |
| 5819 | } |
| 5820 | if (!Py_off_t_converter(args[1], &offset)) { |
| 5821 | goto exit; |
| 5822 | } |
| 5823 | if (!Py_off_t_converter(args[2], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5824 | goto exit; |
| 5825 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5826 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
| 5827 | |
| 5828 | exit: |
| 5829 | return return_value; |
| 5830 | } |
| 5831 | |
| 5832 | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 5833 | |
| 5834 | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 5835 | |
| 5836 | PyDoc_STRVAR(os_posix_fadvise__doc__, |
| 5837 | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
| 5838 | "--\n" |
| 5839 | "\n" |
| 5840 | "Announce an intention to access data in a specific pattern.\n" |
| 5841 | "\n" |
| 5842 | "Announce an intention to access data in a specific pattern, thus allowing\n" |
| 5843 | "the kernel to make optimizations.\n" |
| 5844 | "The advice applies to the region of the file specified by fd starting at\n" |
| 5845 | "offset and continuing for length bytes.\n" |
| 5846 | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
| 5847 | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
| 5848 | "POSIX_FADV_DONTNEED."); |
| 5849 | |
| 5850 | #define OS_POSIX_FADVISE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5851 | {"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] | 5852 | |
| 5853 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5854 | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 5855 | Py_off_t length, int advice); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5856 | |
| 5857 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5858 | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5859 | { |
| 5860 | PyObject *return_value = NULL; |
| 5861 | int fd; |
| 5862 | Py_off_t offset; |
| 5863 | Py_off_t length; |
| 5864 | int advice; |
| 5865 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5866 | if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { |
| 5867 | goto exit; |
| 5868 | } |
| 5869 | if (PyFloat_Check(args[0])) { |
| 5870 | PyErr_SetString(PyExc_TypeError, |
| 5871 | "integer argument expected, got float" ); |
| 5872 | goto exit; |
| 5873 | } |
| 5874 | fd = _PyLong_AsInt(args[0]); |
| 5875 | if (fd == -1 && PyErr_Occurred()) { |
| 5876 | goto exit; |
| 5877 | } |
| 5878 | if (!Py_off_t_converter(args[1], &offset)) { |
| 5879 | goto exit; |
| 5880 | } |
| 5881 | if (!Py_off_t_converter(args[2], &length)) { |
| 5882 | goto exit; |
| 5883 | } |
| 5884 | if (PyFloat_Check(args[3])) { |
| 5885 | PyErr_SetString(PyExc_TypeError, |
| 5886 | "integer argument expected, got float" ); |
| 5887 | goto exit; |
| 5888 | } |
| 5889 | advice = _PyLong_AsInt(args[3]); |
| 5890 | if (advice == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5891 | goto exit; |
| 5892 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5893 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
| 5894 | |
| 5895 | exit: |
| 5896 | return return_value; |
| 5897 | } |
| 5898 | |
| 5899 | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 5900 | |
| 5901 | #if defined(HAVE_PUTENV) && defined(MS_WINDOWS) |
| 5902 | |
| 5903 | PyDoc_STRVAR(os_putenv__doc__, |
| 5904 | "putenv($module, name, value, /)\n" |
| 5905 | "--\n" |
| 5906 | "\n" |
| 5907 | "Change or add an environment variable."); |
| 5908 | |
| 5909 | #define OS_PUTENV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5910 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5911 | |
| 5912 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5913 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5914 | |
| 5915 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5916 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5917 | { |
| 5918 | PyObject *return_value = NULL; |
| 5919 | PyObject *name; |
| 5920 | PyObject *value; |
| 5921 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5922 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5923 | goto exit; |
| 5924 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5925 | if (!PyUnicode_Check(args[0])) { |
| 5926 | _PyArg_BadArgument("putenv", 1, "str", args[0]); |
| 5927 | goto exit; |
| 5928 | } |
| 5929 | if (PyUnicode_READY(args[0]) == -1) { |
| 5930 | goto exit; |
| 5931 | } |
| 5932 | name = args[0]; |
| 5933 | if (!PyUnicode_Check(args[1])) { |
| 5934 | _PyArg_BadArgument("putenv", 2, "str", args[1]); |
| 5935 | goto exit; |
| 5936 | } |
| 5937 | if (PyUnicode_READY(args[1]) == -1) { |
| 5938 | goto exit; |
| 5939 | } |
| 5940 | value = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5941 | return_value = os_putenv_impl(module, name, value); |
| 5942 | |
| 5943 | exit: |
| 5944 | return return_value; |
| 5945 | } |
| 5946 | |
| 5947 | #endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */ |
| 5948 | |
| 5949 | #if defined(HAVE_PUTENV) && !defined(MS_WINDOWS) |
| 5950 | |
| 5951 | PyDoc_STRVAR(os_putenv__doc__, |
| 5952 | "putenv($module, name, value, /)\n" |
| 5953 | "--\n" |
| 5954 | "\n" |
| 5955 | "Change or add an environment variable."); |
| 5956 | |
| 5957 | #define OS_PUTENV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5958 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5959 | |
| 5960 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5961 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5962 | |
| 5963 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5964 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5965 | { |
| 5966 | PyObject *return_value = NULL; |
| 5967 | PyObject *name = NULL; |
| 5968 | PyObject *value = NULL; |
| 5969 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5970 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
| 5971 | goto exit; |
| 5972 | } |
| 5973 | if (!PyUnicode_FSConverter(args[0], &name)) { |
| 5974 | goto exit; |
| 5975 | } |
| 5976 | if (!PyUnicode_FSConverter(args[1], &value)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5977 | goto exit; |
| 5978 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5979 | return_value = os_putenv_impl(module, name, value); |
| 5980 | |
| 5981 | exit: |
| 5982 | /* Cleanup for name */ |
| 5983 | Py_XDECREF(name); |
| 5984 | /* Cleanup for value */ |
| 5985 | Py_XDECREF(value); |
| 5986 | |
| 5987 | return return_value; |
| 5988 | } |
| 5989 | |
| 5990 | #endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */ |
| 5991 | |
| 5992 | #if defined(HAVE_UNSETENV) |
| 5993 | |
| 5994 | PyDoc_STRVAR(os_unsetenv__doc__, |
| 5995 | "unsetenv($module, name, /)\n" |
| 5996 | "--\n" |
| 5997 | "\n" |
| 5998 | "Delete an environment variable."); |
| 5999 | |
| 6000 | #define OS_UNSETENV_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6001 | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6002 | |
| 6003 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6004 | os_unsetenv_impl(PyObject *module, PyObject *name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6005 | |
| 6006 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6007 | os_unsetenv(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6008 | { |
| 6009 | PyObject *return_value = NULL; |
| 6010 | PyObject *name = NULL; |
| 6011 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6012 | if (!PyUnicode_FSConverter(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6013 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6014 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6015 | return_value = os_unsetenv_impl(module, name); |
| 6016 | |
| 6017 | exit: |
| 6018 | /* Cleanup for name */ |
| 6019 | Py_XDECREF(name); |
| 6020 | |
| 6021 | return return_value; |
| 6022 | } |
| 6023 | |
| 6024 | #endif /* defined(HAVE_UNSETENV) */ |
| 6025 | |
| 6026 | PyDoc_STRVAR(os_strerror__doc__, |
| 6027 | "strerror($module, code, /)\n" |
| 6028 | "--\n" |
| 6029 | "\n" |
| 6030 | "Translate an error code to a message string."); |
| 6031 | |
| 6032 | #define OS_STRERROR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6033 | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6034 | |
| 6035 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6036 | os_strerror_impl(PyObject *module, int code); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6037 | |
| 6038 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6039 | os_strerror(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6040 | { |
| 6041 | PyObject *return_value = NULL; |
| 6042 | int code; |
| 6043 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6044 | if (PyFloat_Check(arg)) { |
| 6045 | PyErr_SetString(PyExc_TypeError, |
| 6046 | "integer argument expected, got float" ); |
| 6047 | goto exit; |
| 6048 | } |
| 6049 | code = _PyLong_AsInt(arg); |
| 6050 | if (code == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6051 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6052 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6053 | return_value = os_strerror_impl(module, code); |
| 6054 | |
| 6055 | exit: |
| 6056 | return return_value; |
| 6057 | } |
| 6058 | |
| 6059 | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
| 6060 | |
| 6061 | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
| 6062 | "WCOREDUMP($module, status, /)\n" |
| 6063 | "--\n" |
| 6064 | "\n" |
| 6065 | "Return True if the process returning status was dumped to a core file."); |
| 6066 | |
| 6067 | #define OS_WCOREDUMP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6068 | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6069 | |
| 6070 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6071 | os_WCOREDUMP_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6072 | |
| 6073 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6074 | os_WCOREDUMP(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6075 | { |
| 6076 | PyObject *return_value = NULL; |
| 6077 | int status; |
| 6078 | int _return_value; |
| 6079 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6080 | if (PyFloat_Check(arg)) { |
| 6081 | PyErr_SetString(PyExc_TypeError, |
| 6082 | "integer argument expected, got float" ); |
| 6083 | goto exit; |
| 6084 | } |
| 6085 | status = _PyLong_AsInt(arg); |
| 6086 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6087 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6088 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6089 | _return_value = os_WCOREDUMP_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6090 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6091 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6092 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6093 | return_value = PyBool_FromLong((long)_return_value); |
| 6094 | |
| 6095 | exit: |
| 6096 | return return_value; |
| 6097 | } |
| 6098 | |
| 6099 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
| 6100 | |
| 6101 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
| 6102 | |
| 6103 | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
| 6104 | "WIFCONTINUED($module, /, status)\n" |
| 6105 | "--\n" |
| 6106 | "\n" |
| 6107 | "Return True if a particular process was continued from a job control stop.\n" |
| 6108 | "\n" |
| 6109 | "Return True if the process returning status was continued from a\n" |
| 6110 | "job control stop."); |
| 6111 | |
| 6112 | #define OS_WIFCONTINUED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6113 | {"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] | 6114 | |
| 6115 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6116 | os_WIFCONTINUED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6117 | |
| 6118 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6119 | 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] | 6120 | { |
| 6121 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6122 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6123 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFCONTINUED", 0}; |
| 6124 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6125 | int status; |
| 6126 | int _return_value; |
| 6127 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6128 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6129 | if (!args) { |
| 6130 | goto exit; |
| 6131 | } |
| 6132 | if (PyFloat_Check(args[0])) { |
| 6133 | PyErr_SetString(PyExc_TypeError, |
| 6134 | "integer argument expected, got float" ); |
| 6135 | goto exit; |
| 6136 | } |
| 6137 | status = _PyLong_AsInt(args[0]); |
| 6138 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6139 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6140 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6141 | _return_value = os_WIFCONTINUED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6142 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6143 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6144 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6145 | return_value = PyBool_FromLong((long)_return_value); |
| 6146 | |
| 6147 | exit: |
| 6148 | return return_value; |
| 6149 | } |
| 6150 | |
| 6151 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
| 6152 | |
| 6153 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
| 6154 | |
| 6155 | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
| 6156 | "WIFSTOPPED($module, /, status)\n" |
| 6157 | "--\n" |
| 6158 | "\n" |
| 6159 | "Return True if the process returning status was stopped."); |
| 6160 | |
| 6161 | #define OS_WIFSTOPPED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6162 | {"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] | 6163 | |
| 6164 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6165 | os_WIFSTOPPED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6166 | |
| 6167 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6168 | 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] | 6169 | { |
| 6170 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6171 | static const char * const _keywords[] = {"status", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6172 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFSTOPPED", 0}; |
| 6173 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6174 | int status; |
| 6175 | int _return_value; |
| 6176 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6177 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6178 | if (!args) { |
| 6179 | goto exit; |
| 6180 | } |
| 6181 | if (PyFloat_Check(args[0])) { |
| 6182 | PyErr_SetString(PyExc_TypeError, |
| 6183 | "integer argument expected, got float" ); |
| 6184 | goto exit; |
| 6185 | } |
| 6186 | status = _PyLong_AsInt(args[0]); |
| 6187 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6188 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6189 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6190 | _return_value = os_WIFSTOPPED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6191 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6192 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6193 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6194 | return_value = PyBool_FromLong((long)_return_value); |
| 6195 | |
| 6196 | exit: |
| 6197 | return return_value; |
| 6198 | } |
| 6199 | |
| 6200 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
| 6201 | |
| 6202 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
| 6203 | |
| 6204 | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
| 6205 | "WIFSIGNALED($module, /, status)\n" |
| 6206 | "--\n" |
| 6207 | "\n" |
| 6208 | "Return True if the process returning status was terminated by a signal."); |
| 6209 | |
| 6210 | #define OS_WIFSIGNALED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6211 | {"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] | 6212 | |
| 6213 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6214 | os_WIFSIGNALED_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_WIFSIGNALED(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, "WIFSIGNALED", 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_WIFSIGNALED_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(WIFSIGNALED) */ |
| 6250 | |
| 6251 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
| 6252 | |
| 6253 | PyDoc_STRVAR(os_WIFEXITED__doc__, |
| 6254 | "WIFEXITED($module, /, status)\n" |
| 6255 | "--\n" |
| 6256 | "\n" |
| 6257 | "Return True if the process returning status exited via the exit() system call."); |
| 6258 | |
| 6259 | #define OS_WIFEXITED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6260 | {"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] | 6261 | |
| 6262 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6263 | os_WIFEXITED_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_WIFEXITED(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, "WIFEXITED", 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_WIFEXITED_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(WIFEXITED) */ |
| 6299 | |
| 6300 | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
| 6301 | |
| 6302 | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
| 6303 | "WEXITSTATUS($module, /, status)\n" |
| 6304 | "--\n" |
| 6305 | "\n" |
| 6306 | "Return the process return code from status."); |
| 6307 | |
| 6308 | #define OS_WEXITSTATUS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6309 | {"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] | 6310 | |
| 6311 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6312 | os_WEXITSTATUS_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_WEXITSTATUS(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, "WEXITSTATUS", 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_WEXITSTATUS_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 = PyLong_FromLong((long)_return_value); |
| 6342 | |
| 6343 | exit: |
| 6344 | return return_value; |
| 6345 | } |
| 6346 | |
| 6347 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
| 6348 | |
| 6349 | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
| 6350 | |
| 6351 | PyDoc_STRVAR(os_WTERMSIG__doc__, |
| 6352 | "WTERMSIG($module, /, status)\n" |
| 6353 | "--\n" |
| 6354 | "\n" |
| 6355 | "Return the signal that terminated the process that provided the status value."); |
| 6356 | |
| 6357 | #define OS_WTERMSIG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6358 | {"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] | 6359 | |
| 6360 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6361 | os_WTERMSIG_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_WTERMSIG(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, "WTERMSIG", 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_WTERMSIG_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 = PyLong_FromLong((long)_return_value); |
| 6391 | |
| 6392 | exit: |
| 6393 | return return_value; |
| 6394 | } |
| 6395 | |
| 6396 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
| 6397 | |
| 6398 | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
| 6399 | |
| 6400 | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
| 6401 | "WSTOPSIG($module, /, status)\n" |
| 6402 | "--\n" |
| 6403 | "\n" |
| 6404 | "Return the signal that stopped the process that provided the status value."); |
| 6405 | |
| 6406 | #define OS_WSTOPSIG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6407 | {"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] | 6408 | |
| 6409 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6410 | os_WSTOPSIG_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_WSTOPSIG(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, "WSTOPSIG", 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_WSTOPSIG_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(WSTOPSIG) */ |
| 6446 | |
| 6447 | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 6448 | |
| 6449 | PyDoc_STRVAR(os_fstatvfs__doc__, |
| 6450 | "fstatvfs($module, fd, /)\n" |
| 6451 | "--\n" |
| 6452 | "\n" |
| 6453 | "Perform an fstatvfs system call on the given fd.\n" |
| 6454 | "\n" |
| 6455 | "Equivalent to statvfs(fd)."); |
| 6456 | |
| 6457 | #define OS_FSTATVFS_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6458 | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6459 | |
| 6460 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6461 | os_fstatvfs_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6462 | |
| 6463 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6464 | os_fstatvfs(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6465 | { |
| 6466 | PyObject *return_value = NULL; |
| 6467 | int fd; |
| 6468 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6469 | if (PyFloat_Check(arg)) { |
| 6470 | PyErr_SetString(PyExc_TypeError, |
| 6471 | "integer argument expected, got float" ); |
| 6472 | goto exit; |
| 6473 | } |
| 6474 | fd = _PyLong_AsInt(arg); |
| 6475 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6476 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6477 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6478 | return_value = os_fstatvfs_impl(module, fd); |
| 6479 | |
| 6480 | exit: |
| 6481 | return return_value; |
| 6482 | } |
| 6483 | |
| 6484 | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 6485 | |
| 6486 | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 6487 | |
| 6488 | PyDoc_STRVAR(os_statvfs__doc__, |
| 6489 | "statvfs($module, /, path)\n" |
| 6490 | "--\n" |
| 6491 | "\n" |
| 6492 | "Perform a statvfs system call on the given path.\n" |
| 6493 | "\n" |
| 6494 | "path may always be specified as a string.\n" |
| 6495 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 6496 | " If this functionality is unavailable, using it raises an exception."); |
| 6497 | |
| 6498 | #define OS_STATVFS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6499 | {"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] | 6500 | |
| 6501 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6502 | os_statvfs_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6503 | |
| 6504 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6505 | 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] | 6506 | { |
| 6507 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6508 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6509 | static _PyArg_Parser _parser = {NULL, _keywords, "statvfs", 0}; |
| 6510 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6511 | path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS); |
| 6512 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6513 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6514 | if (!args) { |
| 6515 | goto exit; |
| 6516 | } |
| 6517 | if (!path_converter(args[0], &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6518 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6519 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6520 | return_value = os_statvfs_impl(module, &path); |
| 6521 | |
| 6522 | exit: |
| 6523 | /* Cleanup for path */ |
| 6524 | path_cleanup(&path); |
| 6525 | |
| 6526 | return return_value; |
| 6527 | } |
| 6528 | |
| 6529 | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 6530 | |
| 6531 | #if defined(MS_WINDOWS) |
| 6532 | |
| 6533 | PyDoc_STRVAR(os__getdiskusage__doc__, |
| 6534 | "_getdiskusage($module, /, path)\n" |
| 6535 | "--\n" |
| 6536 | "\n" |
| 6537 | "Return disk usage statistics about the given path as a (total, free) tuple."); |
| 6538 | |
| 6539 | #define OS__GETDISKUSAGE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6540 | {"_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] | 6541 | |
| 6542 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 6543 | os__getdiskusage_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6544 | |
| 6545 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6546 | 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] | 6547 | { |
| 6548 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6549 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6550 | static _PyArg_Parser _parser = {NULL, _keywords, "_getdiskusage", 0}; |
| 6551 | PyObject *argsbuf[1]; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 6552 | path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6553 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6554 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6555 | if (!args) { |
| 6556 | goto exit; |
| 6557 | } |
| 6558 | if (!path_converter(args[0], &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6559 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6560 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 6561 | return_value = os__getdiskusage_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6562 | |
| 6563 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 6564 | /* Cleanup for path */ |
| 6565 | path_cleanup(&path); |
| 6566 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6567 | return return_value; |
| 6568 | } |
| 6569 | |
| 6570 | #endif /* defined(MS_WINDOWS) */ |
| 6571 | |
| 6572 | #if defined(HAVE_FPATHCONF) |
| 6573 | |
| 6574 | PyDoc_STRVAR(os_fpathconf__doc__, |
| 6575 | "fpathconf($module, fd, name, /)\n" |
| 6576 | "--\n" |
| 6577 | "\n" |
| 6578 | "Return the configuration limit name for the file descriptor fd.\n" |
| 6579 | "\n" |
| 6580 | "If there is no limit, return -1."); |
| 6581 | |
| 6582 | #define OS_FPATHCONF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6583 | {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6584 | |
| 6585 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6586 | os_fpathconf_impl(PyObject *module, int fd, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6587 | |
| 6588 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6589 | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6590 | { |
| 6591 | PyObject *return_value = NULL; |
| 6592 | int fd; |
| 6593 | int name; |
| 6594 | long _return_value; |
| 6595 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6596 | if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { |
| 6597 | goto exit; |
| 6598 | } |
| 6599 | if (PyFloat_Check(args[0])) { |
| 6600 | PyErr_SetString(PyExc_TypeError, |
| 6601 | "integer argument expected, got float" ); |
| 6602 | goto exit; |
| 6603 | } |
| 6604 | fd = _PyLong_AsInt(args[0]); |
| 6605 | if (fd == -1 && PyErr_Occurred()) { |
| 6606 | goto exit; |
| 6607 | } |
| 6608 | if (!conv_path_confname(args[1], &name)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6609 | goto exit; |
| 6610 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6611 | _return_value = os_fpathconf_impl(module, fd, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6612 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6613 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6614 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6615 | return_value = PyLong_FromLong(_return_value); |
| 6616 | |
| 6617 | exit: |
| 6618 | return return_value; |
| 6619 | } |
| 6620 | |
| 6621 | #endif /* defined(HAVE_FPATHCONF) */ |
| 6622 | |
| 6623 | #if defined(HAVE_PATHCONF) |
| 6624 | |
| 6625 | PyDoc_STRVAR(os_pathconf__doc__, |
| 6626 | "pathconf($module, /, path, name)\n" |
| 6627 | "--\n" |
| 6628 | "\n" |
| 6629 | "Return the configuration limit name for the file or directory path.\n" |
| 6630 | "\n" |
| 6631 | "If there is no limit, return -1.\n" |
| 6632 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 6633 | " If this functionality is unavailable, using it raises an exception."); |
| 6634 | |
| 6635 | #define OS_PATHCONF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6636 | {"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] | 6637 | |
| 6638 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6639 | os_pathconf_impl(PyObject *module, path_t *path, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6640 | |
| 6641 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6642 | 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] | 6643 | { |
| 6644 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6645 | static const char * const _keywords[] = {"path", "name", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6646 | static _PyArg_Parser _parser = {NULL, _keywords, "pathconf", 0}; |
| 6647 | PyObject *argsbuf[2]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6648 | path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF); |
| 6649 | int name; |
| 6650 | long _return_value; |
| 6651 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6652 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 6653 | if (!args) { |
| 6654 | goto exit; |
| 6655 | } |
| 6656 | if (!path_converter(args[0], &path)) { |
| 6657 | goto exit; |
| 6658 | } |
| 6659 | if (!conv_path_confname(args[1], &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6660 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6661 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6662 | _return_value = os_pathconf_impl(module, &path, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6663 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6664 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6665 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6666 | return_value = PyLong_FromLong(_return_value); |
| 6667 | |
| 6668 | exit: |
| 6669 | /* Cleanup for path */ |
| 6670 | path_cleanup(&path); |
| 6671 | |
| 6672 | return return_value; |
| 6673 | } |
| 6674 | |
| 6675 | #endif /* defined(HAVE_PATHCONF) */ |
| 6676 | |
| 6677 | #if defined(HAVE_CONFSTR) |
| 6678 | |
| 6679 | PyDoc_STRVAR(os_confstr__doc__, |
| 6680 | "confstr($module, name, /)\n" |
| 6681 | "--\n" |
| 6682 | "\n" |
| 6683 | "Return a string-valued system configuration variable."); |
| 6684 | |
| 6685 | #define OS_CONFSTR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6686 | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6687 | |
| 6688 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6689 | os_confstr_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6690 | |
| 6691 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6692 | os_confstr(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6693 | { |
| 6694 | PyObject *return_value = NULL; |
| 6695 | int name; |
| 6696 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6697 | if (!conv_confstr_confname(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6698 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6699 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6700 | return_value = os_confstr_impl(module, name); |
| 6701 | |
| 6702 | exit: |
| 6703 | return return_value; |
| 6704 | } |
| 6705 | |
| 6706 | #endif /* defined(HAVE_CONFSTR) */ |
| 6707 | |
| 6708 | #if defined(HAVE_SYSCONF) |
| 6709 | |
| 6710 | PyDoc_STRVAR(os_sysconf__doc__, |
| 6711 | "sysconf($module, name, /)\n" |
| 6712 | "--\n" |
| 6713 | "\n" |
| 6714 | "Return an integer-valued system configuration variable."); |
| 6715 | |
| 6716 | #define OS_SYSCONF_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6717 | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6718 | |
| 6719 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6720 | os_sysconf_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6721 | |
| 6722 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6723 | os_sysconf(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6724 | { |
| 6725 | PyObject *return_value = NULL; |
| 6726 | int name; |
| 6727 | long _return_value; |
| 6728 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6729 | if (!conv_sysconf_confname(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6730 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6731 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6732 | _return_value = os_sysconf_impl(module, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6733 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6734 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6735 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6736 | return_value = PyLong_FromLong(_return_value); |
| 6737 | |
| 6738 | exit: |
| 6739 | return return_value; |
| 6740 | } |
| 6741 | |
| 6742 | #endif /* defined(HAVE_SYSCONF) */ |
| 6743 | |
| 6744 | PyDoc_STRVAR(os_abort__doc__, |
| 6745 | "abort($module, /)\n" |
| 6746 | "--\n" |
| 6747 | "\n" |
| 6748 | "Abort the interpreter immediately.\n" |
| 6749 | "\n" |
| 6750 | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
| 6751 | "on the hosting operating system. This function never returns."); |
| 6752 | |
| 6753 | #define OS_ABORT_METHODDEF \ |
| 6754 | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
| 6755 | |
| 6756 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6757 | os_abort_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6758 | |
| 6759 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6760 | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6761 | { |
| 6762 | return os_abort_impl(module); |
| 6763 | } |
| 6764 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6765 | #if defined(MS_WINDOWS) |
| 6766 | |
| 6767 | PyDoc_STRVAR(os_startfile__doc__, |
| 6768 | "startfile($module, /, filepath, operation=None)\n" |
| 6769 | "--\n" |
| 6770 | "\n" |
| 6771 | "startfile(filepath [, operation])\n" |
| 6772 | "\n" |
| 6773 | "Start a file with its associated application.\n" |
| 6774 | "\n" |
| 6775 | "When \"operation\" is not specified or \"open\", this acts like\n" |
| 6776 | "double-clicking the file in Explorer, or giving the file name as an\n" |
| 6777 | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
| 6778 | "application (if any) its extension is associated.\n" |
| 6779 | "When another \"operation\" is given, it specifies what should be done with\n" |
| 6780 | "the file. A typical operation is \"print\".\n" |
| 6781 | "\n" |
| 6782 | "startfile returns as soon as the associated application is launched.\n" |
| 6783 | "There is no option to wait for the application to close, and no way\n" |
| 6784 | "to retrieve the application\'s exit status.\n" |
| 6785 | "\n" |
| 6786 | "The filepath is relative to the current directory. If you want to use\n" |
| 6787 | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
| 6788 | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
| 6789 | |
| 6790 | #define OS_STARTFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6791 | {"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] | 6792 | |
| 6793 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 6794 | os_startfile_impl(PyObject *module, path_t *filepath, |
| 6795 | const Py_UNICODE *operation); |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6796 | |
| 6797 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6798 | 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] | 6799 | { |
| 6800 | PyObject *return_value = NULL; |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 6801 | static const char * const _keywords[] = {"filepath", "operation", NULL}; |
| 6802 | static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0}; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6803 | path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0); |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 6804 | const Py_UNICODE *operation = NULL; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6805 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6806 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6807 | path_converter, &filepath, &operation)) { |
| 6808 | goto exit; |
| 6809 | } |
| 6810 | return_value = os_startfile_impl(module, &filepath, operation); |
| 6811 | |
| 6812 | exit: |
| 6813 | /* Cleanup for filepath */ |
| 6814 | path_cleanup(&filepath); |
| 6815 | |
| 6816 | return return_value; |
| 6817 | } |
| 6818 | |
| 6819 | #endif /* defined(MS_WINDOWS) */ |
| 6820 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6821 | #if defined(HAVE_GETLOADAVG) |
| 6822 | |
| 6823 | PyDoc_STRVAR(os_getloadavg__doc__, |
| 6824 | "getloadavg($module, /)\n" |
| 6825 | "--\n" |
| 6826 | "\n" |
| 6827 | "Return average recent system load information.\n" |
| 6828 | "\n" |
| 6829 | "Return the number of processes in the system run queue averaged over\n" |
| 6830 | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
| 6831 | "Raises OSError if the load average was unobtainable."); |
| 6832 | |
| 6833 | #define OS_GETLOADAVG_METHODDEF \ |
| 6834 | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
| 6835 | |
| 6836 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6837 | os_getloadavg_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6838 | |
| 6839 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6840 | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6841 | { |
| 6842 | return os_getloadavg_impl(module); |
| 6843 | } |
| 6844 | |
| 6845 | #endif /* defined(HAVE_GETLOADAVG) */ |
| 6846 | |
| 6847 | PyDoc_STRVAR(os_device_encoding__doc__, |
| 6848 | "device_encoding($module, /, fd)\n" |
| 6849 | "--\n" |
| 6850 | "\n" |
| 6851 | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
| 6852 | "\n" |
| 6853 | "The file descriptor must be attached to a terminal.\n" |
| 6854 | "If the device is not a terminal, return None."); |
| 6855 | |
| 6856 | #define OS_DEVICE_ENCODING_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6857 | {"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] | 6858 | |
| 6859 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6860 | os_device_encoding_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6861 | |
| 6862 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6863 | 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] | 6864 | { |
| 6865 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6866 | static const char * const _keywords[] = {"fd", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6867 | static _PyArg_Parser _parser = {NULL, _keywords, "device_encoding", 0}; |
| 6868 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6869 | int fd; |
| 6870 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 6871 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 6872 | if (!args) { |
| 6873 | goto exit; |
| 6874 | } |
| 6875 | if (PyFloat_Check(args[0])) { |
| 6876 | PyErr_SetString(PyExc_TypeError, |
| 6877 | "integer argument expected, got float" ); |
| 6878 | goto exit; |
| 6879 | } |
| 6880 | fd = _PyLong_AsInt(args[0]); |
| 6881 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6882 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6883 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6884 | return_value = os_device_encoding_impl(module, fd); |
| 6885 | |
| 6886 | exit: |
| 6887 | return return_value; |
| 6888 | } |
| 6889 | |
| 6890 | #if defined(HAVE_SETRESUID) |
| 6891 | |
| 6892 | PyDoc_STRVAR(os_setresuid__doc__, |
| 6893 | "setresuid($module, ruid, euid, suid, /)\n" |
| 6894 | "--\n" |
| 6895 | "\n" |
| 6896 | "Set the current process\'s real, effective, and saved user ids."); |
| 6897 | |
| 6898 | #define OS_SETRESUID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6899 | {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6900 | |
| 6901 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6902 | 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] | 6903 | |
| 6904 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6905 | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6906 | { |
| 6907 | PyObject *return_value = NULL; |
| 6908 | uid_t ruid; |
| 6909 | uid_t euid; |
| 6910 | uid_t suid; |
| 6911 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6912 | if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { |
| 6913 | goto exit; |
| 6914 | } |
| 6915 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
| 6916 | goto exit; |
| 6917 | } |
| 6918 | if (!_Py_Uid_Converter(args[1], &euid)) { |
| 6919 | goto exit; |
| 6920 | } |
| 6921 | if (!_Py_Uid_Converter(args[2], &suid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6922 | goto exit; |
| 6923 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6924 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
| 6925 | |
| 6926 | exit: |
| 6927 | return return_value; |
| 6928 | } |
| 6929 | |
| 6930 | #endif /* defined(HAVE_SETRESUID) */ |
| 6931 | |
| 6932 | #if defined(HAVE_SETRESGID) |
| 6933 | |
| 6934 | PyDoc_STRVAR(os_setresgid__doc__, |
| 6935 | "setresgid($module, rgid, egid, sgid, /)\n" |
| 6936 | "--\n" |
| 6937 | "\n" |
| 6938 | "Set the current process\'s real, effective, and saved group ids."); |
| 6939 | |
| 6940 | #define OS_SETRESGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6941 | {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6942 | |
| 6943 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6944 | 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] | 6945 | |
| 6946 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6947 | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6948 | { |
| 6949 | PyObject *return_value = NULL; |
| 6950 | gid_t rgid; |
| 6951 | gid_t egid; |
| 6952 | gid_t sgid; |
| 6953 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6954 | if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { |
| 6955 | goto exit; |
| 6956 | } |
| 6957 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
| 6958 | goto exit; |
| 6959 | } |
| 6960 | if (!_Py_Gid_Converter(args[1], &egid)) { |
| 6961 | goto exit; |
| 6962 | } |
| 6963 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6964 | goto exit; |
| 6965 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6966 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
| 6967 | |
| 6968 | exit: |
| 6969 | return return_value; |
| 6970 | } |
| 6971 | |
| 6972 | #endif /* defined(HAVE_SETRESGID) */ |
| 6973 | |
| 6974 | #if defined(HAVE_GETRESUID) |
| 6975 | |
| 6976 | PyDoc_STRVAR(os_getresuid__doc__, |
| 6977 | "getresuid($module, /)\n" |
| 6978 | "--\n" |
| 6979 | "\n" |
| 6980 | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
| 6981 | |
| 6982 | #define OS_GETRESUID_METHODDEF \ |
| 6983 | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
| 6984 | |
| 6985 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6986 | os_getresuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6987 | |
| 6988 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6989 | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6990 | { |
| 6991 | return os_getresuid_impl(module); |
| 6992 | } |
| 6993 | |
| 6994 | #endif /* defined(HAVE_GETRESUID) */ |
| 6995 | |
| 6996 | #if defined(HAVE_GETRESGID) |
| 6997 | |
| 6998 | PyDoc_STRVAR(os_getresgid__doc__, |
| 6999 | "getresgid($module, /)\n" |
| 7000 | "--\n" |
| 7001 | "\n" |
| 7002 | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
| 7003 | |
| 7004 | #define OS_GETRESGID_METHODDEF \ |
| 7005 | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
| 7006 | |
| 7007 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7008 | os_getresgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7009 | |
| 7010 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7011 | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7012 | { |
| 7013 | return os_getresgid_impl(module); |
| 7014 | } |
| 7015 | |
| 7016 | #endif /* defined(HAVE_GETRESGID) */ |
| 7017 | |
| 7018 | #if defined(USE_XATTRS) |
| 7019 | |
| 7020 | PyDoc_STRVAR(os_getxattr__doc__, |
| 7021 | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 7022 | "--\n" |
| 7023 | "\n" |
| 7024 | "Return the value of extended attribute attribute on path.\n" |
| 7025 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7026 | "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] | 7027 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 7028 | " link, getxattr will examine the symbolic link itself instead of the file\n" |
| 7029 | " the link points to."); |
| 7030 | |
| 7031 | #define OS_GETXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7032 | {"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] | 7033 | |
| 7034 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7035 | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 7036 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7037 | |
| 7038 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7039 | 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] | 7040 | { |
| 7041 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 7042 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7043 | static _PyArg_Parser _parser = {NULL, _keywords, "getxattr", 0}; |
| 7044 | PyObject *argsbuf[3]; |
| 7045 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7046 | path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1); |
| 7047 | path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0); |
| 7048 | int follow_symlinks = 1; |
| 7049 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7050 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 7051 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7052 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7053 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7054 | if (!path_converter(args[0], &path)) { |
| 7055 | goto exit; |
| 7056 | } |
| 7057 | if (!path_converter(args[1], &attribute)) { |
| 7058 | goto exit; |
| 7059 | } |
| 7060 | if (!noptargs) { |
| 7061 | goto skip_optional_kwonly; |
| 7062 | } |
| 7063 | follow_symlinks = PyObject_IsTrue(args[2]); |
| 7064 | if (follow_symlinks < 0) { |
| 7065 | goto exit; |
| 7066 | } |
| 7067 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7068 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
| 7069 | |
| 7070 | exit: |
| 7071 | /* Cleanup for path */ |
| 7072 | path_cleanup(&path); |
| 7073 | /* Cleanup for attribute */ |
| 7074 | path_cleanup(&attribute); |
| 7075 | |
| 7076 | return return_value; |
| 7077 | } |
| 7078 | |
| 7079 | #endif /* defined(USE_XATTRS) */ |
| 7080 | |
| 7081 | #if defined(USE_XATTRS) |
| 7082 | |
| 7083 | PyDoc_STRVAR(os_setxattr__doc__, |
| 7084 | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
| 7085 | " follow_symlinks=True)\n" |
| 7086 | "--\n" |
| 7087 | "\n" |
| 7088 | "Set extended attribute attribute on path to value.\n" |
| 7089 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7090 | "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] | 7091 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 7092 | " link, setxattr will modify the symbolic link itself instead of the file\n" |
| 7093 | " the link points to."); |
| 7094 | |
| 7095 | #define OS_SETXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7096 | {"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] | 7097 | |
| 7098 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7099 | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 7100 | Py_buffer *value, int flags, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7101 | |
| 7102 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7103 | 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] | 7104 | { |
| 7105 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 7106 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7107 | static _PyArg_Parser _parser = {NULL, _keywords, "setxattr", 0}; |
| 7108 | PyObject *argsbuf[5]; |
| 7109 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7110 | path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1); |
| 7111 | path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0); |
| 7112 | Py_buffer value = {NULL, NULL}; |
| 7113 | int flags = 0; |
| 7114 | int follow_symlinks = 1; |
| 7115 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7116 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf); |
| 7117 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7118 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7119 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7120 | if (!path_converter(args[0], &path)) { |
| 7121 | goto exit; |
| 7122 | } |
| 7123 | if (!path_converter(args[1], &attribute)) { |
| 7124 | goto exit; |
| 7125 | } |
| 7126 | if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) { |
| 7127 | goto exit; |
| 7128 | } |
| 7129 | if (!PyBuffer_IsContiguous(&value, 'C')) { |
| 7130 | _PyArg_BadArgument("setxattr", 3, "contiguous buffer", args[2]); |
| 7131 | goto exit; |
| 7132 | } |
| 7133 | if (!noptargs) { |
| 7134 | goto skip_optional_pos; |
| 7135 | } |
| 7136 | if (args[3]) { |
| 7137 | if (PyFloat_Check(args[3])) { |
| 7138 | PyErr_SetString(PyExc_TypeError, |
| 7139 | "integer argument expected, got float" ); |
| 7140 | goto exit; |
| 7141 | } |
| 7142 | flags = _PyLong_AsInt(args[3]); |
| 7143 | if (flags == -1 && PyErr_Occurred()) { |
| 7144 | goto exit; |
| 7145 | } |
| 7146 | if (!--noptargs) { |
| 7147 | goto skip_optional_pos; |
| 7148 | } |
| 7149 | } |
| 7150 | skip_optional_pos: |
| 7151 | if (!noptargs) { |
| 7152 | goto skip_optional_kwonly; |
| 7153 | } |
| 7154 | follow_symlinks = PyObject_IsTrue(args[4]); |
| 7155 | if (follow_symlinks < 0) { |
| 7156 | goto exit; |
| 7157 | } |
| 7158 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7159 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
| 7160 | |
| 7161 | exit: |
| 7162 | /* Cleanup for path */ |
| 7163 | path_cleanup(&path); |
| 7164 | /* Cleanup for attribute */ |
| 7165 | path_cleanup(&attribute); |
| 7166 | /* Cleanup for value */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7167 | if (value.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7168 | PyBuffer_Release(&value); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7169 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7170 | |
| 7171 | return return_value; |
| 7172 | } |
| 7173 | |
| 7174 | #endif /* defined(USE_XATTRS) */ |
| 7175 | |
| 7176 | #if defined(USE_XATTRS) |
| 7177 | |
| 7178 | PyDoc_STRVAR(os_removexattr__doc__, |
| 7179 | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 7180 | "--\n" |
| 7181 | "\n" |
| 7182 | "Remove extended attribute attribute on path.\n" |
| 7183 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7184 | "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] | 7185 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 7186 | " link, removexattr will modify the symbolic link itself instead of the file\n" |
| 7187 | " the link points to."); |
| 7188 | |
| 7189 | #define OS_REMOVEXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7190 | {"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] | 7191 | |
| 7192 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7193 | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 7194 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7195 | |
| 7196 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7197 | 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] | 7198 | { |
| 7199 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 7200 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7201 | static _PyArg_Parser _parser = {NULL, _keywords, "removexattr", 0}; |
| 7202 | PyObject *argsbuf[3]; |
| 7203 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7204 | path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1); |
| 7205 | path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0); |
| 7206 | int follow_symlinks = 1; |
| 7207 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7208 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 7209 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7210 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7211 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7212 | if (!path_converter(args[0], &path)) { |
| 7213 | goto exit; |
| 7214 | } |
| 7215 | if (!path_converter(args[1], &attribute)) { |
| 7216 | goto exit; |
| 7217 | } |
| 7218 | if (!noptargs) { |
| 7219 | goto skip_optional_kwonly; |
| 7220 | } |
| 7221 | follow_symlinks = PyObject_IsTrue(args[2]); |
| 7222 | if (follow_symlinks < 0) { |
| 7223 | goto exit; |
| 7224 | } |
| 7225 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7226 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
| 7227 | |
| 7228 | exit: |
| 7229 | /* Cleanup for path */ |
| 7230 | path_cleanup(&path); |
| 7231 | /* Cleanup for attribute */ |
| 7232 | path_cleanup(&attribute); |
| 7233 | |
| 7234 | return return_value; |
| 7235 | } |
| 7236 | |
| 7237 | #endif /* defined(USE_XATTRS) */ |
| 7238 | |
| 7239 | #if defined(USE_XATTRS) |
| 7240 | |
| 7241 | PyDoc_STRVAR(os_listxattr__doc__, |
| 7242 | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
| 7243 | "--\n" |
| 7244 | "\n" |
| 7245 | "Return a list of extended attributes on path.\n" |
| 7246 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7247 | "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] | 7248 | "if path is None, listxattr will examine the current directory.\n" |
| 7249 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 7250 | " link, listxattr will examine the symbolic link itself instead of the file\n" |
| 7251 | " the link points to."); |
| 7252 | |
| 7253 | #define OS_LISTXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7254 | {"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] | 7255 | |
| 7256 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7257 | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7258 | |
| 7259 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7260 | 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] | 7261 | { |
| 7262 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 7263 | static const char * const _keywords[] = {"path", "follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7264 | static _PyArg_Parser _parser = {NULL, _keywords, "listxattr", 0}; |
| 7265 | PyObject *argsbuf[2]; |
| 7266 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7267 | path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1); |
| 7268 | int follow_symlinks = 1; |
| 7269 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7270 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 7271 | if (!args) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7272 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7273 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7274 | if (!noptargs) { |
| 7275 | goto skip_optional_pos; |
| 7276 | } |
| 7277 | if (args[0]) { |
| 7278 | if (!path_converter(args[0], &path)) { |
| 7279 | goto exit; |
| 7280 | } |
| 7281 | if (!--noptargs) { |
| 7282 | goto skip_optional_pos; |
| 7283 | } |
| 7284 | } |
| 7285 | skip_optional_pos: |
| 7286 | if (!noptargs) { |
| 7287 | goto skip_optional_kwonly; |
| 7288 | } |
| 7289 | follow_symlinks = PyObject_IsTrue(args[1]); |
| 7290 | if (follow_symlinks < 0) { |
| 7291 | goto exit; |
| 7292 | } |
| 7293 | skip_optional_kwonly: |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7294 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
| 7295 | |
| 7296 | exit: |
| 7297 | /* Cleanup for path */ |
| 7298 | path_cleanup(&path); |
| 7299 | |
| 7300 | return return_value; |
| 7301 | } |
| 7302 | |
| 7303 | #endif /* defined(USE_XATTRS) */ |
| 7304 | |
| 7305 | PyDoc_STRVAR(os_urandom__doc__, |
| 7306 | "urandom($module, size, /)\n" |
| 7307 | "--\n" |
| 7308 | "\n" |
| 7309 | "Return a bytes object containing random bytes suitable for cryptographic use."); |
| 7310 | |
| 7311 | #define OS_URANDOM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 7312 | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7313 | |
| 7314 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7315 | os_urandom_impl(PyObject *module, Py_ssize_t size); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7316 | |
| 7317 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7318 | os_urandom(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7319 | { |
| 7320 | PyObject *return_value = NULL; |
| 7321 | Py_ssize_t size; |
| 7322 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 7323 | if (PyFloat_Check(arg)) { |
| 7324 | PyErr_SetString(PyExc_TypeError, |
| 7325 | "integer argument expected, got float" ); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7326 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7327 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 7328 | { |
| 7329 | Py_ssize_t ival = -1; |
| 7330 | PyObject *iobj = PyNumber_Index(arg); |
| 7331 | if (iobj != NULL) { |
| 7332 | ival = PyLong_AsSsize_t(iobj); |
| 7333 | Py_DECREF(iobj); |
| 7334 | } |
| 7335 | if (ival == -1 && PyErr_Occurred()) { |
| 7336 | goto exit; |
| 7337 | } |
| 7338 | size = ival; |
| 7339 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7340 | return_value = os_urandom_impl(module, size); |
| 7341 | |
| 7342 | exit: |
| 7343 | return return_value; |
| 7344 | } |
| 7345 | |
| 7346 | PyDoc_STRVAR(os_cpu_count__doc__, |
| 7347 | "cpu_count($module, /)\n" |
| 7348 | "--\n" |
| 7349 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 7350 | "Return the number of CPUs in the system; return None if indeterminable.\n" |
| 7351 | "\n" |
| 7352 | "This number is not equivalent to the number of CPUs the current process can\n" |
| 7353 | "use. The number of usable CPUs can be obtained with\n" |
| 7354 | "``len(os.sched_getaffinity(0))``"); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7355 | |
| 7356 | #define OS_CPU_COUNT_METHODDEF \ |
| 7357 | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
| 7358 | |
| 7359 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7360 | os_cpu_count_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7361 | |
| 7362 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7363 | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7364 | { |
| 7365 | return os_cpu_count_impl(module); |
| 7366 | } |
| 7367 | |
| 7368 | PyDoc_STRVAR(os_get_inheritable__doc__, |
| 7369 | "get_inheritable($module, fd, /)\n" |
| 7370 | "--\n" |
| 7371 | "\n" |
| 7372 | "Get the close-on-exe flag of the specified file descriptor."); |
| 7373 | |
| 7374 | #define OS_GET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 7375 | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7376 | |
| 7377 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7378 | os_get_inheritable_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7379 | |
| 7380 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7381 | os_get_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7382 | { |
| 7383 | PyObject *return_value = NULL; |
| 7384 | int fd; |
| 7385 | int _return_value; |
| 7386 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 7387 | if (PyFloat_Check(arg)) { |
| 7388 | PyErr_SetString(PyExc_TypeError, |
| 7389 | "integer argument expected, got float" ); |
| 7390 | goto exit; |
| 7391 | } |
| 7392 | fd = _PyLong_AsInt(arg); |
| 7393 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7394 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7395 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7396 | _return_value = os_get_inheritable_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7397 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7398 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7399 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7400 | return_value = PyBool_FromLong((long)_return_value); |
| 7401 | |
| 7402 | exit: |
| 7403 | return return_value; |
| 7404 | } |
| 7405 | |
| 7406 | PyDoc_STRVAR(os_set_inheritable__doc__, |
| 7407 | "set_inheritable($module, fd, inheritable, /)\n" |
| 7408 | "--\n" |
| 7409 | "\n" |
| 7410 | "Set the inheritable flag of the specified file descriptor."); |
| 7411 | |
| 7412 | #define OS_SET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7413 | {"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] | 7414 | |
| 7415 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7416 | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7417 | |
| 7418 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7419 | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7420 | { |
| 7421 | PyObject *return_value = NULL; |
| 7422 | int fd; |
| 7423 | int inheritable; |
| 7424 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 7425 | if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { |
| 7426 | goto exit; |
| 7427 | } |
| 7428 | if (PyFloat_Check(args[0])) { |
| 7429 | PyErr_SetString(PyExc_TypeError, |
| 7430 | "integer argument expected, got float" ); |
| 7431 | goto exit; |
| 7432 | } |
| 7433 | fd = _PyLong_AsInt(args[0]); |
| 7434 | if (fd == -1 && PyErr_Occurred()) { |
| 7435 | goto exit; |
| 7436 | } |
| 7437 | if (PyFloat_Check(args[1])) { |
| 7438 | PyErr_SetString(PyExc_TypeError, |
| 7439 | "integer argument expected, got float" ); |
| 7440 | goto exit; |
| 7441 | } |
| 7442 | inheritable = _PyLong_AsInt(args[1]); |
| 7443 | if (inheritable == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 7444 | goto exit; |
| 7445 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7446 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
| 7447 | |
| 7448 | exit: |
| 7449 | return return_value; |
| 7450 | } |
| 7451 | |
| 7452 | #if defined(MS_WINDOWS) |
| 7453 | |
| 7454 | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
| 7455 | "get_handle_inheritable($module, handle, /)\n" |
| 7456 | "--\n" |
| 7457 | "\n" |
| 7458 | "Get the close-on-exe flag of the specified file descriptor."); |
| 7459 | |
| 7460 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 7461 | {"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] | 7462 | |
| 7463 | static int |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 7464 | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7465 | |
| 7466 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 7467 | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7468 | { |
| 7469 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 7470 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7471 | int _return_value; |
| 7472 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7473 | if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7474 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7475 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7476 | _return_value = os_get_handle_inheritable_impl(module, handle); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7477 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7478 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7479 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7480 | return_value = PyBool_FromLong((long)_return_value); |
| 7481 | |
| 7482 | exit: |
| 7483 | return return_value; |
| 7484 | } |
| 7485 | |
| 7486 | #endif /* defined(MS_WINDOWS) */ |
| 7487 | |
| 7488 | #if defined(MS_WINDOWS) |
| 7489 | |
| 7490 | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
| 7491 | "set_handle_inheritable($module, handle, inheritable, /)\n" |
| 7492 | "--\n" |
| 7493 | "\n" |
| 7494 | "Set the inheritable flag of the specified handle."); |
| 7495 | |
| 7496 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7497 | {"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] | 7498 | |
| 7499 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 7500 | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 7501 | int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7502 | |
| 7503 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7504 | 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] | 7505 | { |
| 7506 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 7507 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7508 | int inheritable; |
| 7509 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 7510 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable", |
| 7511 | &handle, &inheritable)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 7512 | goto exit; |
| 7513 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7514 | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
| 7515 | |
| 7516 | exit: |
| 7517 | return return_value; |
| 7518 | } |
| 7519 | |
| 7520 | #endif /* defined(MS_WINDOWS) */ |
| 7521 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7522 | #if !defined(MS_WINDOWS) |
| 7523 | |
| 7524 | PyDoc_STRVAR(os_get_blocking__doc__, |
| 7525 | "get_blocking($module, fd, /)\n" |
| 7526 | "--\n" |
| 7527 | "\n" |
| 7528 | "Get the blocking mode of the file descriptor.\n" |
| 7529 | "\n" |
| 7530 | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared."); |
| 7531 | |
| 7532 | #define OS_GET_BLOCKING_METHODDEF \ |
| 7533 | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
| 7534 | |
| 7535 | static int |
| 7536 | os_get_blocking_impl(PyObject *module, int fd); |
| 7537 | |
| 7538 | static PyObject * |
| 7539 | os_get_blocking(PyObject *module, PyObject *arg) |
| 7540 | { |
| 7541 | PyObject *return_value = NULL; |
| 7542 | int fd; |
| 7543 | int _return_value; |
| 7544 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 7545 | if (PyFloat_Check(arg)) { |
| 7546 | PyErr_SetString(PyExc_TypeError, |
| 7547 | "integer argument expected, got float" ); |
| 7548 | goto exit; |
| 7549 | } |
| 7550 | fd = _PyLong_AsInt(arg); |
| 7551 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7552 | goto exit; |
| 7553 | } |
| 7554 | _return_value = os_get_blocking_impl(module, fd); |
| 7555 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 7556 | goto exit; |
| 7557 | } |
| 7558 | return_value = PyBool_FromLong((long)_return_value); |
| 7559 | |
| 7560 | exit: |
| 7561 | return return_value; |
| 7562 | } |
| 7563 | |
| 7564 | #endif /* !defined(MS_WINDOWS) */ |
| 7565 | |
| 7566 | #if !defined(MS_WINDOWS) |
| 7567 | |
| 7568 | PyDoc_STRVAR(os_set_blocking__doc__, |
| 7569 | "set_blocking($module, fd, blocking, /)\n" |
| 7570 | "--\n" |
| 7571 | "\n" |
| 7572 | "Set the blocking mode of the specified file descriptor.\n" |
| 7573 | "\n" |
| 7574 | "Set the O_NONBLOCK flag if blocking is False,\n" |
| 7575 | "clear the O_NONBLOCK flag otherwise."); |
| 7576 | |
| 7577 | #define OS_SET_BLOCKING_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7578 | {"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] | 7579 | |
| 7580 | static PyObject * |
| 7581 | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
| 7582 | |
| 7583 | static PyObject * |
| 7584 | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 7585 | { |
| 7586 | PyObject *return_value = NULL; |
| 7587 | int fd; |
| 7588 | int blocking; |
| 7589 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 7590 | if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { |
| 7591 | goto exit; |
| 7592 | } |
| 7593 | if (PyFloat_Check(args[0])) { |
| 7594 | PyErr_SetString(PyExc_TypeError, |
| 7595 | "integer argument expected, got float" ); |
| 7596 | goto exit; |
| 7597 | } |
| 7598 | fd = _PyLong_AsInt(args[0]); |
| 7599 | if (fd == -1 && PyErr_Occurred()) { |
| 7600 | goto exit; |
| 7601 | } |
| 7602 | if (PyFloat_Check(args[1])) { |
| 7603 | PyErr_SetString(PyExc_TypeError, |
| 7604 | "integer argument expected, got float" ); |
| 7605 | goto exit; |
| 7606 | } |
| 7607 | blocking = _PyLong_AsInt(args[1]); |
| 7608 | if (blocking == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7609 | goto exit; |
| 7610 | } |
| 7611 | return_value = os_set_blocking_impl(module, fd, blocking); |
| 7612 | |
| 7613 | exit: |
| 7614 | return return_value; |
| 7615 | } |
| 7616 | |
| 7617 | #endif /* !defined(MS_WINDOWS) */ |
| 7618 | |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7619 | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
| 7620 | "is_symlink($self, /)\n" |
| 7621 | "--\n" |
| 7622 | "\n" |
| 7623 | "Return True if the entry is a symbolic link; cached per entry."); |
| 7624 | |
| 7625 | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
| 7626 | {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__}, |
| 7627 | |
| 7628 | static int |
| 7629 | os_DirEntry_is_symlink_impl(DirEntry *self); |
| 7630 | |
| 7631 | static PyObject * |
| 7632 | os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 7633 | { |
| 7634 | PyObject *return_value = NULL; |
| 7635 | int _return_value; |
| 7636 | |
| 7637 | _return_value = os_DirEntry_is_symlink_impl(self); |
| 7638 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 7639 | goto exit; |
| 7640 | } |
| 7641 | return_value = PyBool_FromLong((long)_return_value); |
| 7642 | |
| 7643 | exit: |
| 7644 | return return_value; |
| 7645 | } |
| 7646 | |
| 7647 | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
| 7648 | "stat($self, /, *, follow_symlinks=True)\n" |
| 7649 | "--\n" |
| 7650 | "\n" |
| 7651 | "Return stat_result object for the entry; cached per entry."); |
| 7652 | |
| 7653 | #define OS_DIRENTRY_STAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7654 | {"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] | 7655 | |
| 7656 | static PyObject * |
| 7657 | os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks); |
| 7658 | |
| 7659 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7660 | 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] | 7661 | { |
| 7662 | PyObject *return_value = NULL; |
| 7663 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7664 | static _PyArg_Parser _parser = {NULL, _keywords, "stat", 0}; |
| 7665 | PyObject *argsbuf[1]; |
| 7666 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7667 | int follow_symlinks = 1; |
| 7668 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7669 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 7670 | if (!args) { |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7671 | goto exit; |
| 7672 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7673 | if (!noptargs) { |
| 7674 | goto skip_optional_kwonly; |
| 7675 | } |
| 7676 | follow_symlinks = PyObject_IsTrue(args[0]); |
| 7677 | if (follow_symlinks < 0) { |
| 7678 | goto exit; |
| 7679 | } |
| 7680 | skip_optional_kwonly: |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7681 | return_value = os_DirEntry_stat_impl(self, follow_symlinks); |
| 7682 | |
| 7683 | exit: |
| 7684 | return return_value; |
| 7685 | } |
| 7686 | |
| 7687 | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
| 7688 | "is_dir($self, /, *, follow_symlinks=True)\n" |
| 7689 | "--\n" |
| 7690 | "\n" |
| 7691 | "Return True if the entry is a directory; cached per entry."); |
| 7692 | |
| 7693 | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7694 | {"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] | 7695 | |
| 7696 | static int |
| 7697 | os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks); |
| 7698 | |
| 7699 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7700 | 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] | 7701 | { |
| 7702 | PyObject *return_value = NULL; |
| 7703 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7704 | static _PyArg_Parser _parser = {NULL, _keywords, "is_dir", 0}; |
| 7705 | PyObject *argsbuf[1]; |
| 7706 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7707 | int follow_symlinks = 1; |
| 7708 | int _return_value; |
| 7709 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7710 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 7711 | if (!args) { |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7712 | goto exit; |
| 7713 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7714 | if (!noptargs) { |
| 7715 | goto skip_optional_kwonly; |
| 7716 | } |
| 7717 | follow_symlinks = PyObject_IsTrue(args[0]); |
| 7718 | if (follow_symlinks < 0) { |
| 7719 | goto exit; |
| 7720 | } |
| 7721 | skip_optional_kwonly: |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7722 | _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks); |
| 7723 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 7724 | goto exit; |
| 7725 | } |
| 7726 | return_value = PyBool_FromLong((long)_return_value); |
| 7727 | |
| 7728 | exit: |
| 7729 | return return_value; |
| 7730 | } |
| 7731 | |
| 7732 | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
| 7733 | "is_file($self, /, *, follow_symlinks=True)\n" |
| 7734 | "--\n" |
| 7735 | "\n" |
| 7736 | "Return True if the entry is a file; cached per entry."); |
| 7737 | |
| 7738 | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7739 | {"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] | 7740 | |
| 7741 | static int |
| 7742 | os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks); |
| 7743 | |
| 7744 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7745 | 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] | 7746 | { |
| 7747 | PyObject *return_value = NULL; |
| 7748 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7749 | static _PyArg_Parser _parser = {NULL, _keywords, "is_file", 0}; |
| 7750 | PyObject *argsbuf[1]; |
| 7751 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7752 | int follow_symlinks = 1; |
| 7753 | int _return_value; |
| 7754 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7755 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 7756 | if (!args) { |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7757 | goto exit; |
| 7758 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7759 | if (!noptargs) { |
| 7760 | goto skip_optional_kwonly; |
| 7761 | } |
| 7762 | follow_symlinks = PyObject_IsTrue(args[0]); |
| 7763 | if (follow_symlinks < 0) { |
| 7764 | goto exit; |
| 7765 | } |
| 7766 | skip_optional_kwonly: |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7767 | _return_value = os_DirEntry_is_file_impl(self, follow_symlinks); |
| 7768 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 7769 | goto exit; |
| 7770 | } |
| 7771 | return_value = PyBool_FromLong((long)_return_value); |
| 7772 | |
| 7773 | exit: |
| 7774 | return return_value; |
| 7775 | } |
| 7776 | |
| 7777 | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
| 7778 | "inode($self, /)\n" |
| 7779 | "--\n" |
| 7780 | "\n" |
| 7781 | "Return inode of the entry; cached per entry."); |
| 7782 | |
| 7783 | #define OS_DIRENTRY_INODE_METHODDEF \ |
| 7784 | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
| 7785 | |
| 7786 | static PyObject * |
| 7787 | os_DirEntry_inode_impl(DirEntry *self); |
| 7788 | |
| 7789 | static PyObject * |
| 7790 | os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 7791 | { |
| 7792 | return os_DirEntry_inode_impl(self); |
| 7793 | } |
| 7794 | |
| 7795 | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
| 7796 | "__fspath__($self, /)\n" |
| 7797 | "--\n" |
| 7798 | "\n" |
| 7799 | "Returns the path for the entry."); |
| 7800 | |
| 7801 | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
| 7802 | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
| 7803 | |
| 7804 | static PyObject * |
| 7805 | os_DirEntry___fspath___impl(DirEntry *self); |
| 7806 | |
| 7807 | static PyObject * |
| 7808 | os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 7809 | { |
| 7810 | return os_DirEntry___fspath___impl(self); |
| 7811 | } |
| 7812 | |
| 7813 | PyDoc_STRVAR(os_scandir__doc__, |
| 7814 | "scandir($module, /, path=None)\n" |
| 7815 | "--\n" |
| 7816 | "\n" |
| 7817 | "Return an iterator of DirEntry objects for given path.\n" |
| 7818 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 7819 | "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] | 7820 | "is bytes, the names of yielded DirEntry objects will also be bytes; in\n" |
| 7821 | "all other circumstances they will be str.\n" |
| 7822 | "\n" |
| 7823 | "If path is None, uses the path=\'.\'."); |
| 7824 | |
| 7825 | #define OS_SCANDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7826 | {"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] | 7827 | |
| 7828 | static PyObject * |
| 7829 | os_scandir_impl(PyObject *module, path_t *path); |
| 7830 | |
| 7831 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7832 | 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] | 7833 | { |
| 7834 | PyObject *return_value = NULL; |
| 7835 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7836 | static _PyArg_Parser _parser = {NULL, _keywords, "scandir", 0}; |
| 7837 | PyObject *argsbuf[1]; |
| 7838 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | ea720fe | 2017-03-30 09:12:31 +0300 | [diff] [blame] | 7839 | path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR); |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7840 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7841 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 7842 | if (!args) { |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7843 | goto exit; |
| 7844 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7845 | if (!noptargs) { |
| 7846 | goto skip_optional_pos; |
| 7847 | } |
| 7848 | if (!path_converter(args[0], &path)) { |
| 7849 | goto exit; |
| 7850 | } |
| 7851 | skip_optional_pos: |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 7852 | return_value = os_scandir_impl(module, &path); |
| 7853 | |
| 7854 | exit: |
| 7855 | /* Cleanup for path */ |
| 7856 | path_cleanup(&path); |
| 7857 | |
| 7858 | return return_value; |
| 7859 | } |
| 7860 | |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 7861 | PyDoc_STRVAR(os_fspath__doc__, |
| 7862 | "fspath($module, /, path)\n" |
| 7863 | "--\n" |
| 7864 | "\n" |
| 7865 | "Return the file system path representation of the object.\n" |
| 7866 | "\n" |
Brett Cannon | b4f43e9 | 2016-06-09 14:32:08 -0700 | [diff] [blame] | 7867 | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
| 7868 | "object defines __fspath__(), then return the result of that method. All other\n" |
| 7869 | "types raise a TypeError."); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 7870 | |
| 7871 | #define OS_FSPATH_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7872 | {"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] | 7873 | |
| 7874 | static PyObject * |
Serhiy Storchaka | 2954f83 | 2016-07-07 18:20:03 +0300 | [diff] [blame] | 7875 | os_fspath_impl(PyObject *module, PyObject *path); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 7876 | |
| 7877 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7878 | 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] | 7879 | { |
| 7880 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 7881 | static const char * const _keywords[] = {"path", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7882 | static _PyArg_Parser _parser = {NULL, _keywords, "fspath", 0}; |
| 7883 | PyObject *argsbuf[1]; |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 7884 | PyObject *path; |
| 7885 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7886 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 7887 | if (!args) { |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 7888 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 7889 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7890 | path = args[0]; |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 7891 | return_value = os_fspath_impl(module, path); |
| 7892 | |
| 7893 | exit: |
| 7894 | return return_value; |
| 7895 | } |
| 7896 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 7897 | #if defined(HAVE_GETRANDOM_SYSCALL) |
| 7898 | |
| 7899 | PyDoc_STRVAR(os_getrandom__doc__, |
| 7900 | "getrandom($module, /, size, flags=0)\n" |
| 7901 | "--\n" |
| 7902 | "\n" |
| 7903 | "Obtain a series of random bytes."); |
| 7904 | |
| 7905 | #define OS_GETRANDOM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 7906 | {"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] | 7907 | |
| 7908 | static PyObject * |
| 7909 | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
| 7910 | |
| 7911 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 7912 | 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] | 7913 | { |
| 7914 | PyObject *return_value = NULL; |
| 7915 | static const char * const _keywords[] = {"size", "flags", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7916 | static _PyArg_Parser _parser = {NULL, _keywords, "getrandom", 0}; |
| 7917 | PyObject *argsbuf[2]; |
| 7918 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 7919 | Py_ssize_t size; |
| 7920 | int flags = 0; |
| 7921 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7922 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 7923 | if (!args) { |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 7924 | goto exit; |
| 7925 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 7926 | if (PyFloat_Check(args[0])) { |
| 7927 | PyErr_SetString(PyExc_TypeError, |
| 7928 | "integer argument expected, got float" ); |
| 7929 | goto exit; |
| 7930 | } |
| 7931 | { |
| 7932 | Py_ssize_t ival = -1; |
| 7933 | PyObject *iobj = PyNumber_Index(args[0]); |
| 7934 | if (iobj != NULL) { |
| 7935 | ival = PyLong_AsSsize_t(iobj); |
| 7936 | Py_DECREF(iobj); |
| 7937 | } |
| 7938 | if (ival == -1 && PyErr_Occurred()) { |
| 7939 | goto exit; |
| 7940 | } |
| 7941 | size = ival; |
| 7942 | } |
| 7943 | if (!noptargs) { |
| 7944 | goto skip_optional_pos; |
| 7945 | } |
| 7946 | if (PyFloat_Check(args[1])) { |
| 7947 | PyErr_SetString(PyExc_TypeError, |
| 7948 | "integer argument expected, got float" ); |
| 7949 | goto exit; |
| 7950 | } |
| 7951 | flags = _PyLong_AsInt(args[1]); |
| 7952 | if (flags == -1 && PyErr_Occurred()) { |
| 7953 | goto exit; |
| 7954 | } |
| 7955 | skip_optional_pos: |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 7956 | return_value = os_getrandom_impl(module, size, flags); |
| 7957 | |
| 7958 | exit: |
| 7959 | return return_value; |
| 7960 | } |
| 7961 | |
| 7962 | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
| 7963 | |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 7964 | #if defined(MS_WINDOWS) |
| 7965 | |
| 7966 | PyDoc_STRVAR(os__add_dll_directory__doc__, |
| 7967 | "_add_dll_directory($module, /, path)\n" |
| 7968 | "--\n" |
| 7969 | "\n" |
| 7970 | "Add a path to the DLL search path.\n" |
| 7971 | "\n" |
| 7972 | "This search path is used when resolving dependencies for imported\n" |
| 7973 | "extension modules (the module itself is resolved through sys.path),\n" |
| 7974 | "and also by ctypes.\n" |
| 7975 | "\n" |
| 7976 | "Returns an opaque value that may be passed to os.remove_dll_directory\n" |
| 7977 | "to remove this directory from the search path."); |
| 7978 | |
| 7979 | #define OS__ADD_DLL_DIRECTORY_METHODDEF \ |
| 7980 | {"_add_dll_directory", (PyCFunction)(void(*)(void))os__add_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__}, |
| 7981 | |
| 7982 | static PyObject * |
| 7983 | os__add_dll_directory_impl(PyObject *module, path_t *path); |
| 7984 | |
| 7985 | static PyObject * |
| 7986 | os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 7987 | { |
| 7988 | PyObject *return_value = NULL; |
| 7989 | static const char * const _keywords[] = {"path", NULL}; |
| 7990 | static _PyArg_Parser _parser = {NULL, _keywords, "_add_dll_directory", 0}; |
| 7991 | PyObject *argsbuf[1]; |
| 7992 | path_t path = PATH_T_INITIALIZE("_add_dll_directory", "path", 0, 0); |
| 7993 | |
| 7994 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 7995 | if (!args) { |
| 7996 | goto exit; |
| 7997 | } |
| 7998 | if (!path_converter(args[0], &path)) { |
| 7999 | goto exit; |
| 8000 | } |
| 8001 | return_value = os__add_dll_directory_impl(module, &path); |
| 8002 | |
| 8003 | exit: |
| 8004 | /* Cleanup for path */ |
| 8005 | path_cleanup(&path); |
| 8006 | |
| 8007 | return return_value; |
| 8008 | } |
| 8009 | |
| 8010 | #endif /* defined(MS_WINDOWS) */ |
| 8011 | |
| 8012 | #if defined(MS_WINDOWS) |
| 8013 | |
| 8014 | PyDoc_STRVAR(os__remove_dll_directory__doc__, |
| 8015 | "_remove_dll_directory($module, /, cookie)\n" |
| 8016 | "--\n" |
| 8017 | "\n" |
| 8018 | "Removes a path from the DLL search path.\n" |
| 8019 | "\n" |
| 8020 | "The parameter is an opaque value that was returned from\n" |
| 8021 | "os.add_dll_directory. You can only remove directories that you added\n" |
| 8022 | "yourself."); |
| 8023 | |
| 8024 | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \ |
| 8025 | {"_remove_dll_directory", (PyCFunction)(void(*)(void))os__remove_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__}, |
| 8026 | |
| 8027 | static PyObject * |
| 8028 | os__remove_dll_directory_impl(PyObject *module, PyObject *cookie); |
| 8029 | |
| 8030 | static PyObject * |
| 8031 | os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 8032 | { |
| 8033 | PyObject *return_value = NULL; |
| 8034 | static const char * const _keywords[] = {"cookie", NULL}; |
| 8035 | static _PyArg_Parser _parser = {NULL, _keywords, "_remove_dll_directory", 0}; |
| 8036 | PyObject *argsbuf[1]; |
| 8037 | PyObject *cookie; |
| 8038 | |
| 8039 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 8040 | if (!args) { |
| 8041 | goto exit; |
| 8042 | } |
| 8043 | cookie = args[0]; |
| 8044 | return_value = os__remove_dll_directory_impl(module, cookie); |
| 8045 | |
| 8046 | exit: |
| 8047 | return return_value; |
| 8048 | } |
| 8049 | |
| 8050 | #endif /* defined(MS_WINDOWS) */ |
| 8051 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8052 | #ifndef OS_TTYNAME_METHODDEF |
| 8053 | #define OS_TTYNAME_METHODDEF |
| 8054 | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
| 8055 | |
| 8056 | #ifndef OS_CTERMID_METHODDEF |
| 8057 | #define OS_CTERMID_METHODDEF |
| 8058 | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
| 8059 | |
| 8060 | #ifndef OS_FCHDIR_METHODDEF |
| 8061 | #define OS_FCHDIR_METHODDEF |
| 8062 | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
| 8063 | |
| 8064 | #ifndef OS_FCHMOD_METHODDEF |
| 8065 | #define OS_FCHMOD_METHODDEF |
| 8066 | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
| 8067 | |
| 8068 | #ifndef OS_LCHMOD_METHODDEF |
| 8069 | #define OS_LCHMOD_METHODDEF |
| 8070 | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
| 8071 | |
| 8072 | #ifndef OS_CHFLAGS_METHODDEF |
| 8073 | #define OS_CHFLAGS_METHODDEF |
| 8074 | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
| 8075 | |
| 8076 | #ifndef OS_LCHFLAGS_METHODDEF |
| 8077 | #define OS_LCHFLAGS_METHODDEF |
| 8078 | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
| 8079 | |
| 8080 | #ifndef OS_CHROOT_METHODDEF |
| 8081 | #define OS_CHROOT_METHODDEF |
| 8082 | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
| 8083 | |
| 8084 | #ifndef OS_FSYNC_METHODDEF |
| 8085 | #define OS_FSYNC_METHODDEF |
| 8086 | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
| 8087 | |
| 8088 | #ifndef OS_SYNC_METHODDEF |
| 8089 | #define OS_SYNC_METHODDEF |
| 8090 | #endif /* !defined(OS_SYNC_METHODDEF) */ |
| 8091 | |
| 8092 | #ifndef OS_FDATASYNC_METHODDEF |
| 8093 | #define OS_FDATASYNC_METHODDEF |
| 8094 | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
| 8095 | |
| 8096 | #ifndef OS_CHOWN_METHODDEF |
| 8097 | #define OS_CHOWN_METHODDEF |
| 8098 | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
| 8099 | |
| 8100 | #ifndef OS_FCHOWN_METHODDEF |
| 8101 | #define OS_FCHOWN_METHODDEF |
| 8102 | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
| 8103 | |
| 8104 | #ifndef OS_LCHOWN_METHODDEF |
| 8105 | #define OS_LCHOWN_METHODDEF |
| 8106 | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
| 8107 | |
| 8108 | #ifndef OS_LINK_METHODDEF |
| 8109 | #define OS_LINK_METHODDEF |
| 8110 | #endif /* !defined(OS_LINK_METHODDEF) */ |
| 8111 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 8112 | #ifndef OS__GETFULLPATHNAME_METHODDEF |
| 8113 | #define OS__GETFULLPATHNAME_METHODDEF |
| 8114 | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
| 8115 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8116 | #ifndef OS__GETFINALPATHNAME_METHODDEF |
| 8117 | #define OS__GETFINALPATHNAME_METHODDEF |
| 8118 | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
| 8119 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 8120 | #ifndef OS__ISDIR_METHODDEF |
| 8121 | #define OS__ISDIR_METHODDEF |
| 8122 | #endif /* !defined(OS__ISDIR_METHODDEF) */ |
| 8123 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8124 | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
| 8125 | #define OS__GETVOLUMEPATHNAME_METHODDEF |
| 8126 | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
| 8127 | |
| 8128 | #ifndef OS_NICE_METHODDEF |
| 8129 | #define OS_NICE_METHODDEF |
| 8130 | #endif /* !defined(OS_NICE_METHODDEF) */ |
| 8131 | |
| 8132 | #ifndef OS_GETPRIORITY_METHODDEF |
| 8133 | #define OS_GETPRIORITY_METHODDEF |
| 8134 | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
| 8135 | |
| 8136 | #ifndef OS_SETPRIORITY_METHODDEF |
| 8137 | #define OS_SETPRIORITY_METHODDEF |
| 8138 | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
| 8139 | |
| 8140 | #ifndef OS_SYSTEM_METHODDEF |
| 8141 | #define OS_SYSTEM_METHODDEF |
| 8142 | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
| 8143 | |
| 8144 | #ifndef OS_UNAME_METHODDEF |
| 8145 | #define OS_UNAME_METHODDEF |
| 8146 | #endif /* !defined(OS_UNAME_METHODDEF) */ |
| 8147 | |
| 8148 | #ifndef OS_EXECV_METHODDEF |
| 8149 | #define OS_EXECV_METHODDEF |
| 8150 | #endif /* !defined(OS_EXECV_METHODDEF) */ |
| 8151 | |
| 8152 | #ifndef OS_EXECVE_METHODDEF |
| 8153 | #define OS_EXECVE_METHODDEF |
| 8154 | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
| 8155 | |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 8156 | #ifndef OS_POSIX_SPAWN_METHODDEF |
| 8157 | #define OS_POSIX_SPAWN_METHODDEF |
| 8158 | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
| 8159 | |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 8160 | #ifndef OS_POSIX_SPAWNP_METHODDEF |
| 8161 | #define OS_POSIX_SPAWNP_METHODDEF |
| 8162 | #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */ |
| 8163 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8164 | #ifndef OS_SPAWNV_METHODDEF |
| 8165 | #define OS_SPAWNV_METHODDEF |
| 8166 | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
| 8167 | |
| 8168 | #ifndef OS_SPAWNVE_METHODDEF |
| 8169 | #define OS_SPAWNVE_METHODDEF |
| 8170 | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
| 8171 | |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 8172 | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
| 8173 | #define OS_REGISTER_AT_FORK_METHODDEF |
| 8174 | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
| 8175 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8176 | #ifndef OS_FORK1_METHODDEF |
| 8177 | #define OS_FORK1_METHODDEF |
| 8178 | #endif /* !defined(OS_FORK1_METHODDEF) */ |
| 8179 | |
| 8180 | #ifndef OS_FORK_METHODDEF |
| 8181 | #define OS_FORK_METHODDEF |
| 8182 | #endif /* !defined(OS_FORK_METHODDEF) */ |
| 8183 | |
| 8184 | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 8185 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 8186 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
| 8187 | |
| 8188 | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 8189 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 8190 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
| 8191 | |
| 8192 | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
| 8193 | #define OS_SCHED_GETSCHEDULER_METHODDEF |
| 8194 | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
| 8195 | |
| 8196 | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
| 8197 | #define OS_SCHED_SETSCHEDULER_METHODDEF |
| 8198 | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
| 8199 | |
| 8200 | #ifndef OS_SCHED_GETPARAM_METHODDEF |
| 8201 | #define OS_SCHED_GETPARAM_METHODDEF |
| 8202 | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
| 8203 | |
| 8204 | #ifndef OS_SCHED_SETPARAM_METHODDEF |
| 8205 | #define OS_SCHED_SETPARAM_METHODDEF |
| 8206 | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
| 8207 | |
| 8208 | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 8209 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 8210 | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
| 8211 | |
| 8212 | #ifndef OS_SCHED_YIELD_METHODDEF |
| 8213 | #define OS_SCHED_YIELD_METHODDEF |
| 8214 | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
| 8215 | |
| 8216 | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
| 8217 | #define OS_SCHED_SETAFFINITY_METHODDEF |
| 8218 | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
| 8219 | |
| 8220 | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
| 8221 | #define OS_SCHED_GETAFFINITY_METHODDEF |
| 8222 | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
| 8223 | |
| 8224 | #ifndef OS_OPENPTY_METHODDEF |
| 8225 | #define OS_OPENPTY_METHODDEF |
| 8226 | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
| 8227 | |
| 8228 | #ifndef OS_FORKPTY_METHODDEF |
| 8229 | #define OS_FORKPTY_METHODDEF |
| 8230 | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
| 8231 | |
| 8232 | #ifndef OS_GETEGID_METHODDEF |
| 8233 | #define OS_GETEGID_METHODDEF |
| 8234 | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
| 8235 | |
| 8236 | #ifndef OS_GETEUID_METHODDEF |
| 8237 | #define OS_GETEUID_METHODDEF |
| 8238 | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
| 8239 | |
| 8240 | #ifndef OS_GETGID_METHODDEF |
| 8241 | #define OS_GETGID_METHODDEF |
| 8242 | #endif /* !defined(OS_GETGID_METHODDEF) */ |
| 8243 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 8244 | #ifndef OS_GETPID_METHODDEF |
| 8245 | #define OS_GETPID_METHODDEF |
| 8246 | #endif /* !defined(OS_GETPID_METHODDEF) */ |
| 8247 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8248 | #ifndef OS_GETGROUPS_METHODDEF |
| 8249 | #define OS_GETGROUPS_METHODDEF |
| 8250 | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
| 8251 | |
| 8252 | #ifndef OS_GETPGID_METHODDEF |
| 8253 | #define OS_GETPGID_METHODDEF |
| 8254 | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
| 8255 | |
| 8256 | #ifndef OS_GETPGRP_METHODDEF |
| 8257 | #define OS_GETPGRP_METHODDEF |
| 8258 | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
| 8259 | |
| 8260 | #ifndef OS_SETPGRP_METHODDEF |
| 8261 | #define OS_SETPGRP_METHODDEF |
| 8262 | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
| 8263 | |
| 8264 | #ifndef OS_GETPPID_METHODDEF |
| 8265 | #define OS_GETPPID_METHODDEF |
| 8266 | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
| 8267 | |
| 8268 | #ifndef OS_GETLOGIN_METHODDEF |
| 8269 | #define OS_GETLOGIN_METHODDEF |
| 8270 | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
| 8271 | |
| 8272 | #ifndef OS_GETUID_METHODDEF |
| 8273 | #define OS_GETUID_METHODDEF |
| 8274 | #endif /* !defined(OS_GETUID_METHODDEF) */ |
| 8275 | |
| 8276 | #ifndef OS_KILL_METHODDEF |
| 8277 | #define OS_KILL_METHODDEF |
| 8278 | #endif /* !defined(OS_KILL_METHODDEF) */ |
| 8279 | |
| 8280 | #ifndef OS_KILLPG_METHODDEF |
| 8281 | #define OS_KILLPG_METHODDEF |
| 8282 | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
| 8283 | |
| 8284 | #ifndef OS_PLOCK_METHODDEF |
| 8285 | #define OS_PLOCK_METHODDEF |
| 8286 | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
| 8287 | |
| 8288 | #ifndef OS_SETUID_METHODDEF |
| 8289 | #define OS_SETUID_METHODDEF |
| 8290 | #endif /* !defined(OS_SETUID_METHODDEF) */ |
| 8291 | |
| 8292 | #ifndef OS_SETEUID_METHODDEF |
| 8293 | #define OS_SETEUID_METHODDEF |
| 8294 | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
| 8295 | |
| 8296 | #ifndef OS_SETEGID_METHODDEF |
| 8297 | #define OS_SETEGID_METHODDEF |
| 8298 | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
| 8299 | |
| 8300 | #ifndef OS_SETREUID_METHODDEF |
| 8301 | #define OS_SETREUID_METHODDEF |
| 8302 | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
| 8303 | |
| 8304 | #ifndef OS_SETREGID_METHODDEF |
| 8305 | #define OS_SETREGID_METHODDEF |
| 8306 | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
| 8307 | |
| 8308 | #ifndef OS_SETGID_METHODDEF |
| 8309 | #define OS_SETGID_METHODDEF |
| 8310 | #endif /* !defined(OS_SETGID_METHODDEF) */ |
| 8311 | |
| 8312 | #ifndef OS_SETGROUPS_METHODDEF |
| 8313 | #define OS_SETGROUPS_METHODDEF |
| 8314 | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
| 8315 | |
| 8316 | #ifndef OS_WAIT3_METHODDEF |
| 8317 | #define OS_WAIT3_METHODDEF |
| 8318 | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
| 8319 | |
| 8320 | #ifndef OS_WAIT4_METHODDEF |
| 8321 | #define OS_WAIT4_METHODDEF |
| 8322 | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
| 8323 | |
| 8324 | #ifndef OS_WAITID_METHODDEF |
| 8325 | #define OS_WAITID_METHODDEF |
| 8326 | #endif /* !defined(OS_WAITID_METHODDEF) */ |
| 8327 | |
| 8328 | #ifndef OS_WAITPID_METHODDEF |
| 8329 | #define OS_WAITPID_METHODDEF |
| 8330 | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
| 8331 | |
| 8332 | #ifndef OS_WAIT_METHODDEF |
| 8333 | #define OS_WAIT_METHODDEF |
| 8334 | #endif /* !defined(OS_WAIT_METHODDEF) */ |
| 8335 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 8336 | #ifndef OS_READLINK_METHODDEF |
| 8337 | #define OS_READLINK_METHODDEF |
| 8338 | #endif /* !defined(OS_READLINK_METHODDEF) */ |
| 8339 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8340 | #ifndef OS_SYMLINK_METHODDEF |
| 8341 | #define OS_SYMLINK_METHODDEF |
| 8342 | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
| 8343 | |
| 8344 | #ifndef OS_TIMES_METHODDEF |
| 8345 | #define OS_TIMES_METHODDEF |
| 8346 | #endif /* !defined(OS_TIMES_METHODDEF) */ |
| 8347 | |
| 8348 | #ifndef OS_GETSID_METHODDEF |
| 8349 | #define OS_GETSID_METHODDEF |
| 8350 | #endif /* !defined(OS_GETSID_METHODDEF) */ |
| 8351 | |
| 8352 | #ifndef OS_SETSID_METHODDEF |
| 8353 | #define OS_SETSID_METHODDEF |
| 8354 | #endif /* !defined(OS_SETSID_METHODDEF) */ |
| 8355 | |
| 8356 | #ifndef OS_SETPGID_METHODDEF |
| 8357 | #define OS_SETPGID_METHODDEF |
| 8358 | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
| 8359 | |
| 8360 | #ifndef OS_TCGETPGRP_METHODDEF |
| 8361 | #define OS_TCGETPGRP_METHODDEF |
| 8362 | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
| 8363 | |
| 8364 | #ifndef OS_TCSETPGRP_METHODDEF |
| 8365 | #define OS_TCSETPGRP_METHODDEF |
| 8366 | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
| 8367 | |
| 8368 | #ifndef OS_LOCKF_METHODDEF |
| 8369 | #define OS_LOCKF_METHODDEF |
| 8370 | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
| 8371 | |
| 8372 | #ifndef OS_READV_METHODDEF |
| 8373 | #define OS_READV_METHODDEF |
| 8374 | #endif /* !defined(OS_READV_METHODDEF) */ |
| 8375 | |
| 8376 | #ifndef OS_PREAD_METHODDEF |
| 8377 | #define OS_PREAD_METHODDEF |
| 8378 | #endif /* !defined(OS_PREAD_METHODDEF) */ |
| 8379 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 8380 | #ifndef OS_PREADV_METHODDEF |
| 8381 | #define OS_PREADV_METHODDEF |
| 8382 | #endif /* !defined(OS_PREADV_METHODDEF) */ |
| 8383 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 8384 | #ifndef OS__FCOPYFILE_METHODDEF |
| 8385 | #define OS__FCOPYFILE_METHODDEF |
| 8386 | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
| 8387 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8388 | #ifndef OS_PIPE_METHODDEF |
| 8389 | #define OS_PIPE_METHODDEF |
| 8390 | #endif /* !defined(OS_PIPE_METHODDEF) */ |
| 8391 | |
| 8392 | #ifndef OS_PIPE2_METHODDEF |
| 8393 | #define OS_PIPE2_METHODDEF |
| 8394 | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
| 8395 | |
| 8396 | #ifndef OS_WRITEV_METHODDEF |
| 8397 | #define OS_WRITEV_METHODDEF |
| 8398 | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
| 8399 | |
| 8400 | #ifndef OS_PWRITE_METHODDEF |
| 8401 | #define OS_PWRITE_METHODDEF |
| 8402 | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
| 8403 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 8404 | #ifndef OS_PWRITEV_METHODDEF |
| 8405 | #define OS_PWRITEV_METHODDEF |
| 8406 | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
| 8407 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8408 | #ifndef OS_MKFIFO_METHODDEF |
| 8409 | #define OS_MKFIFO_METHODDEF |
| 8410 | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
| 8411 | |
| 8412 | #ifndef OS_MKNOD_METHODDEF |
| 8413 | #define OS_MKNOD_METHODDEF |
| 8414 | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
| 8415 | |
| 8416 | #ifndef OS_MAJOR_METHODDEF |
| 8417 | #define OS_MAJOR_METHODDEF |
| 8418 | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
| 8419 | |
| 8420 | #ifndef OS_MINOR_METHODDEF |
| 8421 | #define OS_MINOR_METHODDEF |
| 8422 | #endif /* !defined(OS_MINOR_METHODDEF) */ |
| 8423 | |
| 8424 | #ifndef OS_MAKEDEV_METHODDEF |
| 8425 | #define OS_MAKEDEV_METHODDEF |
| 8426 | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
| 8427 | |
| 8428 | #ifndef OS_FTRUNCATE_METHODDEF |
| 8429 | #define OS_FTRUNCATE_METHODDEF |
| 8430 | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
| 8431 | |
| 8432 | #ifndef OS_TRUNCATE_METHODDEF |
| 8433 | #define OS_TRUNCATE_METHODDEF |
| 8434 | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
| 8435 | |
| 8436 | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
| 8437 | #define OS_POSIX_FALLOCATE_METHODDEF |
| 8438 | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
| 8439 | |
| 8440 | #ifndef OS_POSIX_FADVISE_METHODDEF |
| 8441 | #define OS_POSIX_FADVISE_METHODDEF |
| 8442 | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
| 8443 | |
| 8444 | #ifndef OS_PUTENV_METHODDEF |
| 8445 | #define OS_PUTENV_METHODDEF |
| 8446 | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
| 8447 | |
| 8448 | #ifndef OS_UNSETENV_METHODDEF |
| 8449 | #define OS_UNSETENV_METHODDEF |
| 8450 | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
| 8451 | |
| 8452 | #ifndef OS_WCOREDUMP_METHODDEF |
| 8453 | #define OS_WCOREDUMP_METHODDEF |
| 8454 | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
| 8455 | |
| 8456 | #ifndef OS_WIFCONTINUED_METHODDEF |
| 8457 | #define OS_WIFCONTINUED_METHODDEF |
| 8458 | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
| 8459 | |
| 8460 | #ifndef OS_WIFSTOPPED_METHODDEF |
| 8461 | #define OS_WIFSTOPPED_METHODDEF |
| 8462 | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
| 8463 | |
| 8464 | #ifndef OS_WIFSIGNALED_METHODDEF |
| 8465 | #define OS_WIFSIGNALED_METHODDEF |
| 8466 | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
| 8467 | |
| 8468 | #ifndef OS_WIFEXITED_METHODDEF |
| 8469 | #define OS_WIFEXITED_METHODDEF |
| 8470 | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
| 8471 | |
| 8472 | #ifndef OS_WEXITSTATUS_METHODDEF |
| 8473 | #define OS_WEXITSTATUS_METHODDEF |
| 8474 | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
| 8475 | |
| 8476 | #ifndef OS_WTERMSIG_METHODDEF |
| 8477 | #define OS_WTERMSIG_METHODDEF |
| 8478 | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
| 8479 | |
| 8480 | #ifndef OS_WSTOPSIG_METHODDEF |
| 8481 | #define OS_WSTOPSIG_METHODDEF |
| 8482 | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
| 8483 | |
| 8484 | #ifndef OS_FSTATVFS_METHODDEF |
| 8485 | #define OS_FSTATVFS_METHODDEF |
| 8486 | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
| 8487 | |
| 8488 | #ifndef OS_STATVFS_METHODDEF |
| 8489 | #define OS_STATVFS_METHODDEF |
| 8490 | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
| 8491 | |
| 8492 | #ifndef OS__GETDISKUSAGE_METHODDEF |
| 8493 | #define OS__GETDISKUSAGE_METHODDEF |
| 8494 | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
| 8495 | |
| 8496 | #ifndef OS_FPATHCONF_METHODDEF |
| 8497 | #define OS_FPATHCONF_METHODDEF |
| 8498 | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
| 8499 | |
| 8500 | #ifndef OS_PATHCONF_METHODDEF |
| 8501 | #define OS_PATHCONF_METHODDEF |
| 8502 | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
| 8503 | |
| 8504 | #ifndef OS_CONFSTR_METHODDEF |
| 8505 | #define OS_CONFSTR_METHODDEF |
| 8506 | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
| 8507 | |
| 8508 | #ifndef OS_SYSCONF_METHODDEF |
| 8509 | #define OS_SYSCONF_METHODDEF |
| 8510 | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
| 8511 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 8512 | #ifndef OS_STARTFILE_METHODDEF |
| 8513 | #define OS_STARTFILE_METHODDEF |
| 8514 | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
| 8515 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 8516 | #ifndef OS_GETLOADAVG_METHODDEF |
| 8517 | #define OS_GETLOADAVG_METHODDEF |
| 8518 | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
| 8519 | |
| 8520 | #ifndef OS_SETRESUID_METHODDEF |
| 8521 | #define OS_SETRESUID_METHODDEF |
| 8522 | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
| 8523 | |
| 8524 | #ifndef OS_SETRESGID_METHODDEF |
| 8525 | #define OS_SETRESGID_METHODDEF |
| 8526 | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
| 8527 | |
| 8528 | #ifndef OS_GETRESUID_METHODDEF |
| 8529 | #define OS_GETRESUID_METHODDEF |
| 8530 | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
| 8531 | |
| 8532 | #ifndef OS_GETRESGID_METHODDEF |
| 8533 | #define OS_GETRESGID_METHODDEF |
| 8534 | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
| 8535 | |
| 8536 | #ifndef OS_GETXATTR_METHODDEF |
| 8537 | #define OS_GETXATTR_METHODDEF |
| 8538 | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
| 8539 | |
| 8540 | #ifndef OS_SETXATTR_METHODDEF |
| 8541 | #define OS_SETXATTR_METHODDEF |
| 8542 | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
| 8543 | |
| 8544 | #ifndef OS_REMOVEXATTR_METHODDEF |
| 8545 | #define OS_REMOVEXATTR_METHODDEF |
| 8546 | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
| 8547 | |
| 8548 | #ifndef OS_LISTXATTR_METHODDEF |
| 8549 | #define OS_LISTXATTR_METHODDEF |
| 8550 | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
| 8551 | |
| 8552 | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 8553 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 8554 | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
| 8555 | |
| 8556 | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 8557 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 8558 | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 8559 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 8560 | #ifndef OS_GET_BLOCKING_METHODDEF |
| 8561 | #define OS_GET_BLOCKING_METHODDEF |
| 8562 | #endif /* !defined(OS_GET_BLOCKING_METHODDEF) */ |
| 8563 | |
| 8564 | #ifndef OS_SET_BLOCKING_METHODDEF |
| 8565 | #define OS_SET_BLOCKING_METHODDEF |
| 8566 | #endif /* !defined(OS_SET_BLOCKING_METHODDEF) */ |
| 8567 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 8568 | #ifndef OS_GETRANDOM_METHODDEF |
| 8569 | #define OS_GETRANDOM_METHODDEF |
| 8570 | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 8571 | |
| 8572 | #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF |
| 8573 | #define OS__ADD_DLL_DIRECTORY_METHODDEF |
| 8574 | #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */ |
| 8575 | |
| 8576 | #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF |
| 8577 | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF |
| 8578 | #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */ |
| 8579 | /*[clinic end generated code: output=ab36ec0376a422ae input=a9049054013a1b77]*/ |