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" |
| 12 | " Path to be examined; can be string, bytes, or open-file-descriptor int.\n" |
| 13 | " dir_fd\n" |
| 14 | " If not None, it should be a file descriptor open to a directory,\n" |
| 15 | " and path should be a relative string; path will then be relative to\n" |
| 16 | " that directory.\n" |
| 17 | " follow_symlinks\n" |
| 18 | " If False, and the last element of the path is a symbolic link,\n" |
| 19 | " stat will examine the symbolic link itself instead of the file\n" |
| 20 | " the link points to.\n" |
| 21 | "\n" |
| 22 | "dir_fd and follow_symlinks may not be implemented\n" |
| 23 | " on your platform. If they are unavailable, using them will raise a\n" |
| 24 | " NotImplementedError.\n" |
| 25 | "\n" |
| 26 | "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 27 | " an open file descriptor."); |
| 28 | |
| 29 | #define OS_STAT_METHODDEF \ |
| 30 | {"stat", (PyCFunction)os_stat, METH_VARARGS|METH_KEYWORDS, os_stat__doc__}, |
| 31 | |
| 32 | static PyObject * |
| 33 | os_stat_impl(PyModuleDef *module, path_t *path, int dir_fd, int follow_symlinks); |
| 34 | |
| 35 | static PyObject * |
| 36 | os_stat(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 37 | { |
| 38 | PyObject *return_value = NULL; |
| 39 | static char *_keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; |
| 40 | path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1); |
| 41 | int dir_fd = DEFAULT_DIR_FD; |
| 42 | int follow_symlinks = 1; |
| 43 | |
| 44 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 45 | "O&|$O&p:stat", _keywords, |
| 46 | path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) |
| 47 | goto exit; |
| 48 | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
| 49 | |
| 50 | exit: |
| 51 | /* Cleanup for path */ |
| 52 | path_cleanup(&path); |
| 53 | |
| 54 | return return_value; |
| 55 | } |
| 56 | |
| 57 | PyDoc_STRVAR(os_lstat__doc__, |
| 58 | "lstat($module, /, path, *, dir_fd=None)\n" |
| 59 | "--\n" |
| 60 | "\n" |
| 61 | "Perform a stat system call on the given path, without following symbolic links.\n" |
| 62 | "\n" |
| 63 | "Like stat(), but do not follow symbolic links.\n" |
| 64 | "Equivalent to stat(path, follow_symlinks=False)."); |
| 65 | |
| 66 | #define OS_LSTAT_METHODDEF \ |
| 67 | {"lstat", (PyCFunction)os_lstat, METH_VARARGS|METH_KEYWORDS, os_lstat__doc__}, |
| 68 | |
| 69 | static PyObject * |
| 70 | os_lstat_impl(PyModuleDef *module, path_t *path, int dir_fd); |
| 71 | |
| 72 | static PyObject * |
| 73 | os_lstat(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 74 | { |
| 75 | PyObject *return_value = NULL; |
| 76 | static char *_keywords[] = {"path", "dir_fd", NULL}; |
| 77 | path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0); |
| 78 | int dir_fd = DEFAULT_DIR_FD; |
| 79 | |
| 80 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 81 | "O&|$O&:lstat", _keywords, |
| 82 | path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) |
| 83 | goto exit; |
| 84 | return_value = os_lstat_impl(module, &path, dir_fd); |
| 85 | |
| 86 | exit: |
| 87 | /* Cleanup for path */ |
| 88 | path_cleanup(&path); |
| 89 | |
| 90 | return return_value; |
| 91 | } |
| 92 | |
| 93 | PyDoc_STRVAR(os_access__doc__, |
| 94 | "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n" |
| 95 | " follow_symlinks=True)\n" |
| 96 | "--\n" |
| 97 | "\n" |
| 98 | "Use the real uid/gid to test for access to a path.\n" |
| 99 | "\n" |
| 100 | " path\n" |
| 101 | " Path to be tested; can be string, bytes, or open-file-descriptor int.\n" |
| 102 | " mode\n" |
| 103 | " Operating-system mode bitfield. Can be F_OK to test existence,\n" |
| 104 | " or the inclusive-OR of R_OK, W_OK, and X_OK.\n" |
| 105 | " dir_fd\n" |
| 106 | " If not None, it should be a file descriptor open to a directory,\n" |
| 107 | " and path should be relative; path will then be relative to that\n" |
| 108 | " directory.\n" |
| 109 | " effective_ids\n" |
| 110 | " If True, access will use the effective uid/gid instead of\n" |
| 111 | " the real uid/gid.\n" |
| 112 | " follow_symlinks\n" |
| 113 | " If False, and the last element of the path is a symbolic link,\n" |
| 114 | " access will examine the symbolic link itself instead of the file\n" |
| 115 | " the link points to.\n" |
| 116 | "\n" |
| 117 | "dir_fd, effective_ids, and follow_symlinks may not be implemented\n" |
| 118 | " on your platform. If they are unavailable, using them will raise a\n" |
| 119 | " NotImplementedError.\n" |
| 120 | "\n" |
| 121 | "Note that most operations will use the effective uid/gid, therefore this\n" |
| 122 | " routine can be used in a suid/sgid environment to test if the invoking user\n" |
| 123 | " has the specified access to the path."); |
| 124 | |
| 125 | #define OS_ACCESS_METHODDEF \ |
| 126 | {"access", (PyCFunction)os_access, METH_VARARGS|METH_KEYWORDS, os_access__doc__}, |
| 127 | |
| 128 | static int |
| 129 | os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks); |
| 130 | |
| 131 | static PyObject * |
| 132 | os_access(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 133 | { |
| 134 | PyObject *return_value = NULL; |
| 135 | static char *_keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL}; |
| 136 | path_t path = PATH_T_INITIALIZE("access", "path", 0, 1); |
| 137 | int mode; |
| 138 | int dir_fd = DEFAULT_DIR_FD; |
| 139 | int effective_ids = 0; |
| 140 | int follow_symlinks = 1; |
| 141 | int _return_value; |
| 142 | |
| 143 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 144 | "O&i|$O&pp:access", _keywords, |
| 145 | path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) |
| 146 | goto exit; |
| 147 | _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks); |
| 148 | if ((_return_value == -1) && PyErr_Occurred()) |
| 149 | goto exit; |
| 150 | return_value = PyBool_FromLong((long)_return_value); |
| 151 | |
| 152 | exit: |
| 153 | /* Cleanup for path */ |
| 154 | path_cleanup(&path); |
| 155 | |
| 156 | return return_value; |
| 157 | } |
| 158 | |
| 159 | #if defined(HAVE_TTYNAME) |
| 160 | |
| 161 | PyDoc_STRVAR(os_ttyname__doc__, |
| 162 | "ttyname($module, fd, /)\n" |
| 163 | "--\n" |
| 164 | "\n" |
| 165 | "Return the name of the terminal device connected to \'fd\'.\n" |
| 166 | "\n" |
| 167 | " fd\n" |
| 168 | " Integer file descriptor handle."); |
| 169 | |
| 170 | #define OS_TTYNAME_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 171 | {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 172 | |
| 173 | static char * |
| 174 | os_ttyname_impl(PyModuleDef *module, int fd); |
| 175 | |
| 176 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 177 | os_ttyname(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 178 | { |
| 179 | PyObject *return_value = NULL; |
| 180 | int fd; |
| 181 | char *_return_value; |
| 182 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 183 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 184 | "i:ttyname", |
| 185 | &fd)) |
| 186 | goto exit; |
| 187 | _return_value = os_ttyname_impl(module, fd); |
| 188 | if (_return_value == NULL) |
| 189 | goto exit; |
| 190 | return_value = PyUnicode_DecodeFSDefault(_return_value); |
| 191 | |
| 192 | exit: |
| 193 | return return_value; |
| 194 | } |
| 195 | |
| 196 | #endif /* defined(HAVE_TTYNAME) */ |
| 197 | |
| 198 | #if defined(HAVE_CTERMID) |
| 199 | |
| 200 | PyDoc_STRVAR(os_ctermid__doc__, |
| 201 | "ctermid($module, /)\n" |
| 202 | "--\n" |
| 203 | "\n" |
| 204 | "Return the name of the controlling terminal for this process."); |
| 205 | |
| 206 | #define OS_CTERMID_METHODDEF \ |
| 207 | {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, |
| 208 | |
| 209 | static PyObject * |
| 210 | os_ctermid_impl(PyModuleDef *module); |
| 211 | |
| 212 | static PyObject * |
| 213 | os_ctermid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 214 | { |
| 215 | return os_ctermid_impl(module); |
| 216 | } |
| 217 | |
| 218 | #endif /* defined(HAVE_CTERMID) */ |
| 219 | |
| 220 | PyDoc_STRVAR(os_chdir__doc__, |
| 221 | "chdir($module, /, path)\n" |
| 222 | "--\n" |
| 223 | "\n" |
| 224 | "Change the current working directory to the specified path.\n" |
| 225 | "\n" |
| 226 | "path may always be specified as a string.\n" |
| 227 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 228 | " If this functionality is unavailable, using it raises an exception."); |
| 229 | |
| 230 | #define OS_CHDIR_METHODDEF \ |
| 231 | {"chdir", (PyCFunction)os_chdir, METH_VARARGS|METH_KEYWORDS, os_chdir__doc__}, |
| 232 | |
| 233 | static PyObject * |
| 234 | os_chdir_impl(PyModuleDef *module, path_t *path); |
| 235 | |
| 236 | static PyObject * |
| 237 | os_chdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 238 | { |
| 239 | PyObject *return_value = NULL; |
| 240 | static char *_keywords[] = {"path", NULL}; |
| 241 | path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR); |
| 242 | |
| 243 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 244 | "O&:chdir", _keywords, |
| 245 | path_converter, &path)) |
| 246 | goto exit; |
| 247 | return_value = os_chdir_impl(module, &path); |
| 248 | |
| 249 | exit: |
| 250 | /* Cleanup for path */ |
| 251 | path_cleanup(&path); |
| 252 | |
| 253 | return return_value; |
| 254 | } |
| 255 | |
| 256 | #if defined(HAVE_FCHDIR) |
| 257 | |
| 258 | PyDoc_STRVAR(os_fchdir__doc__, |
| 259 | "fchdir($module, /, fd)\n" |
| 260 | "--\n" |
| 261 | "\n" |
| 262 | "Change to the directory of the given file descriptor.\n" |
| 263 | "\n" |
| 264 | "fd must be opened on a directory, not a file.\n" |
| 265 | "Equivalent to os.chdir(fd)."); |
| 266 | |
| 267 | #define OS_FCHDIR_METHODDEF \ |
| 268 | {"fchdir", (PyCFunction)os_fchdir, METH_VARARGS|METH_KEYWORDS, os_fchdir__doc__}, |
| 269 | |
| 270 | static PyObject * |
| 271 | os_fchdir_impl(PyModuleDef *module, int fd); |
| 272 | |
| 273 | static PyObject * |
| 274 | os_fchdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 275 | { |
| 276 | PyObject *return_value = NULL; |
| 277 | static char *_keywords[] = {"fd", NULL}; |
| 278 | int fd; |
| 279 | |
| 280 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 281 | "O&:fchdir", _keywords, |
| 282 | fildes_converter, &fd)) |
| 283 | goto exit; |
| 284 | return_value = os_fchdir_impl(module, fd); |
| 285 | |
| 286 | exit: |
| 287 | return return_value; |
| 288 | } |
| 289 | |
| 290 | #endif /* defined(HAVE_FCHDIR) */ |
| 291 | |
| 292 | PyDoc_STRVAR(os_chmod__doc__, |
| 293 | "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n" |
| 294 | "--\n" |
| 295 | "\n" |
| 296 | "Change the access permissions of a file.\n" |
| 297 | "\n" |
| 298 | " path\n" |
| 299 | " Path to be modified. May always be specified as a str or bytes.\n" |
| 300 | " On some platforms, path may also be specified as an open file descriptor.\n" |
| 301 | " If this functionality is unavailable, using it raises an exception.\n" |
| 302 | " mode\n" |
| 303 | " Operating-system mode bitfield.\n" |
| 304 | " dir_fd\n" |
| 305 | " If not None, it should be a file descriptor open to a directory,\n" |
| 306 | " and path should be relative; path will then be relative to that\n" |
| 307 | " directory.\n" |
| 308 | " follow_symlinks\n" |
| 309 | " If False, and the last element of the path is a symbolic link,\n" |
| 310 | " chmod will modify the symbolic link itself instead of the file\n" |
| 311 | " the link points to.\n" |
| 312 | "\n" |
| 313 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 314 | " an open file descriptor.\n" |
| 315 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 316 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 317 | |
| 318 | #define OS_CHMOD_METHODDEF \ |
| 319 | {"chmod", (PyCFunction)os_chmod, METH_VARARGS|METH_KEYWORDS, os_chmod__doc__}, |
| 320 | |
| 321 | static PyObject * |
| 322 | os_chmod_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int follow_symlinks); |
| 323 | |
| 324 | static PyObject * |
| 325 | os_chmod(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 326 | { |
| 327 | PyObject *return_value = NULL; |
| 328 | static char *_keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL}; |
| 329 | path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD); |
| 330 | int mode; |
| 331 | int dir_fd = DEFAULT_DIR_FD; |
| 332 | int follow_symlinks = 1; |
| 333 | |
| 334 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 335 | "O&i|$O&p:chmod", _keywords, |
| 336 | path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) |
| 337 | goto exit; |
| 338 | return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); |
| 339 | |
| 340 | exit: |
| 341 | /* Cleanup for path */ |
| 342 | path_cleanup(&path); |
| 343 | |
| 344 | return return_value; |
| 345 | } |
| 346 | |
| 347 | #if defined(HAVE_FCHMOD) |
| 348 | |
| 349 | PyDoc_STRVAR(os_fchmod__doc__, |
| 350 | "fchmod($module, /, fd, mode)\n" |
| 351 | "--\n" |
| 352 | "\n" |
| 353 | "Change the access permissions of the file given by file descriptor fd.\n" |
| 354 | "\n" |
| 355 | "Equivalent to os.chmod(fd, mode)."); |
| 356 | |
| 357 | #define OS_FCHMOD_METHODDEF \ |
| 358 | {"fchmod", (PyCFunction)os_fchmod, METH_VARARGS|METH_KEYWORDS, os_fchmod__doc__}, |
| 359 | |
| 360 | static PyObject * |
| 361 | os_fchmod_impl(PyModuleDef *module, int fd, int mode); |
| 362 | |
| 363 | static PyObject * |
| 364 | os_fchmod(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 365 | { |
| 366 | PyObject *return_value = NULL; |
| 367 | static char *_keywords[] = {"fd", "mode", NULL}; |
| 368 | int fd; |
| 369 | int mode; |
| 370 | |
| 371 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 372 | "ii:fchmod", _keywords, |
| 373 | &fd, &mode)) |
| 374 | goto exit; |
| 375 | return_value = os_fchmod_impl(module, fd, mode); |
| 376 | |
| 377 | exit: |
| 378 | return return_value; |
| 379 | } |
| 380 | |
| 381 | #endif /* defined(HAVE_FCHMOD) */ |
| 382 | |
| 383 | #if defined(HAVE_LCHMOD) |
| 384 | |
| 385 | PyDoc_STRVAR(os_lchmod__doc__, |
| 386 | "lchmod($module, /, path, mode)\n" |
| 387 | "--\n" |
| 388 | "\n" |
| 389 | "Change the access permissions of a file, without following symbolic links.\n" |
| 390 | "\n" |
| 391 | "If path is a symlink, this affects the link itself rather than the target.\n" |
| 392 | "Equivalent to chmod(path, mode, follow_symlinks=False).\""); |
| 393 | |
| 394 | #define OS_LCHMOD_METHODDEF \ |
| 395 | {"lchmod", (PyCFunction)os_lchmod, METH_VARARGS|METH_KEYWORDS, os_lchmod__doc__}, |
| 396 | |
| 397 | static PyObject * |
| 398 | os_lchmod_impl(PyModuleDef *module, path_t *path, int mode); |
| 399 | |
| 400 | static PyObject * |
| 401 | os_lchmod(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 402 | { |
| 403 | PyObject *return_value = NULL; |
| 404 | static char *_keywords[] = {"path", "mode", NULL}; |
| 405 | path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0); |
| 406 | int mode; |
| 407 | |
| 408 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 409 | "O&i:lchmod", _keywords, |
| 410 | path_converter, &path, &mode)) |
| 411 | goto exit; |
| 412 | return_value = os_lchmod_impl(module, &path, mode); |
| 413 | |
| 414 | exit: |
| 415 | /* Cleanup for path */ |
| 416 | path_cleanup(&path); |
| 417 | |
| 418 | return return_value; |
| 419 | } |
| 420 | |
| 421 | #endif /* defined(HAVE_LCHMOD) */ |
| 422 | |
| 423 | #if defined(HAVE_CHFLAGS) |
| 424 | |
| 425 | PyDoc_STRVAR(os_chflags__doc__, |
| 426 | "chflags($module, /, path, flags, follow_symlinks=True)\n" |
| 427 | "--\n" |
| 428 | "\n" |
| 429 | "Set file flags.\n" |
| 430 | "\n" |
| 431 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 432 | " link, chflags will change flags on the symbolic link itself instead of the\n" |
| 433 | " file the link points to.\n" |
| 434 | "follow_symlinks may not be implemented on your platform. If it is\n" |
| 435 | "unavailable, using it will raise a NotImplementedError."); |
| 436 | |
| 437 | #define OS_CHFLAGS_METHODDEF \ |
| 438 | {"chflags", (PyCFunction)os_chflags, METH_VARARGS|METH_KEYWORDS, os_chflags__doc__}, |
| 439 | |
| 440 | static PyObject * |
| 441 | os_chflags_impl(PyModuleDef *module, path_t *path, unsigned long flags, int follow_symlinks); |
| 442 | |
| 443 | static PyObject * |
| 444 | os_chflags(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 445 | { |
| 446 | PyObject *return_value = NULL; |
| 447 | static char *_keywords[] = {"path", "flags", "follow_symlinks", NULL}; |
| 448 | path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0); |
| 449 | unsigned long flags; |
| 450 | int follow_symlinks = 1; |
| 451 | |
| 452 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 453 | "O&k|p:chflags", _keywords, |
| 454 | path_converter, &path, &flags, &follow_symlinks)) |
| 455 | goto exit; |
| 456 | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
| 457 | |
| 458 | exit: |
| 459 | /* Cleanup for path */ |
| 460 | path_cleanup(&path); |
| 461 | |
| 462 | return return_value; |
| 463 | } |
| 464 | |
| 465 | #endif /* defined(HAVE_CHFLAGS) */ |
| 466 | |
| 467 | #if defined(HAVE_LCHFLAGS) |
| 468 | |
| 469 | PyDoc_STRVAR(os_lchflags__doc__, |
| 470 | "lchflags($module, /, path, flags)\n" |
| 471 | "--\n" |
| 472 | "\n" |
| 473 | "Set file flags.\n" |
| 474 | "\n" |
| 475 | "This function will not follow symbolic links.\n" |
| 476 | "Equivalent to chflags(path, flags, follow_symlinks=False)."); |
| 477 | |
| 478 | #define OS_LCHFLAGS_METHODDEF \ |
| 479 | {"lchflags", (PyCFunction)os_lchflags, METH_VARARGS|METH_KEYWORDS, os_lchflags__doc__}, |
| 480 | |
| 481 | static PyObject * |
| 482 | os_lchflags_impl(PyModuleDef *module, path_t *path, unsigned long flags); |
| 483 | |
| 484 | static PyObject * |
| 485 | os_lchflags(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 486 | { |
| 487 | PyObject *return_value = NULL; |
| 488 | static char *_keywords[] = {"path", "flags", NULL}; |
| 489 | path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0); |
| 490 | unsigned long flags; |
| 491 | |
| 492 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 493 | "O&k:lchflags", _keywords, |
| 494 | path_converter, &path, &flags)) |
| 495 | goto exit; |
| 496 | return_value = os_lchflags_impl(module, &path, flags); |
| 497 | |
| 498 | exit: |
| 499 | /* Cleanup for path */ |
| 500 | path_cleanup(&path); |
| 501 | |
| 502 | return return_value; |
| 503 | } |
| 504 | |
| 505 | #endif /* defined(HAVE_LCHFLAGS) */ |
| 506 | |
| 507 | #if defined(HAVE_CHROOT) |
| 508 | |
| 509 | PyDoc_STRVAR(os_chroot__doc__, |
| 510 | "chroot($module, /, path)\n" |
| 511 | "--\n" |
| 512 | "\n" |
| 513 | "Change root directory to path."); |
| 514 | |
| 515 | #define OS_CHROOT_METHODDEF \ |
| 516 | {"chroot", (PyCFunction)os_chroot, METH_VARARGS|METH_KEYWORDS, os_chroot__doc__}, |
| 517 | |
| 518 | static PyObject * |
| 519 | os_chroot_impl(PyModuleDef *module, path_t *path); |
| 520 | |
| 521 | static PyObject * |
| 522 | os_chroot(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 523 | { |
| 524 | PyObject *return_value = NULL; |
| 525 | static char *_keywords[] = {"path", NULL}; |
| 526 | path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0); |
| 527 | |
| 528 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 529 | "O&:chroot", _keywords, |
| 530 | path_converter, &path)) |
| 531 | goto exit; |
| 532 | return_value = os_chroot_impl(module, &path); |
| 533 | |
| 534 | exit: |
| 535 | /* Cleanup for path */ |
| 536 | path_cleanup(&path); |
| 537 | |
| 538 | return return_value; |
| 539 | } |
| 540 | |
| 541 | #endif /* defined(HAVE_CHROOT) */ |
| 542 | |
| 543 | #if defined(HAVE_FSYNC) |
| 544 | |
| 545 | PyDoc_STRVAR(os_fsync__doc__, |
| 546 | "fsync($module, /, fd)\n" |
| 547 | "--\n" |
| 548 | "\n" |
| 549 | "Force write of fd to disk."); |
| 550 | |
| 551 | #define OS_FSYNC_METHODDEF \ |
| 552 | {"fsync", (PyCFunction)os_fsync, METH_VARARGS|METH_KEYWORDS, os_fsync__doc__}, |
| 553 | |
| 554 | static PyObject * |
| 555 | os_fsync_impl(PyModuleDef *module, int fd); |
| 556 | |
| 557 | static PyObject * |
| 558 | os_fsync(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 559 | { |
| 560 | PyObject *return_value = NULL; |
| 561 | static char *_keywords[] = {"fd", NULL}; |
| 562 | int fd; |
| 563 | |
| 564 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 565 | "O&:fsync", _keywords, |
| 566 | fildes_converter, &fd)) |
| 567 | goto exit; |
| 568 | return_value = os_fsync_impl(module, fd); |
| 569 | |
| 570 | exit: |
| 571 | return return_value; |
| 572 | } |
| 573 | |
| 574 | #endif /* defined(HAVE_FSYNC) */ |
| 575 | |
| 576 | #if defined(HAVE_SYNC) |
| 577 | |
| 578 | PyDoc_STRVAR(os_sync__doc__, |
| 579 | "sync($module, /)\n" |
| 580 | "--\n" |
| 581 | "\n" |
| 582 | "Force write of everything to disk."); |
| 583 | |
| 584 | #define OS_SYNC_METHODDEF \ |
| 585 | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
| 586 | |
| 587 | static PyObject * |
| 588 | os_sync_impl(PyModuleDef *module); |
| 589 | |
| 590 | static PyObject * |
| 591 | os_sync(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 592 | { |
| 593 | return os_sync_impl(module); |
| 594 | } |
| 595 | |
| 596 | #endif /* defined(HAVE_SYNC) */ |
| 597 | |
| 598 | #if defined(HAVE_FDATASYNC) |
| 599 | |
| 600 | PyDoc_STRVAR(os_fdatasync__doc__, |
| 601 | "fdatasync($module, /, fd)\n" |
| 602 | "--\n" |
| 603 | "\n" |
| 604 | "Force write of fd to disk without forcing update of metadata."); |
| 605 | |
| 606 | #define OS_FDATASYNC_METHODDEF \ |
| 607 | {"fdatasync", (PyCFunction)os_fdatasync, METH_VARARGS|METH_KEYWORDS, os_fdatasync__doc__}, |
| 608 | |
| 609 | static PyObject * |
| 610 | os_fdatasync_impl(PyModuleDef *module, int fd); |
| 611 | |
| 612 | static PyObject * |
| 613 | os_fdatasync(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 614 | { |
| 615 | PyObject *return_value = NULL; |
| 616 | static char *_keywords[] = {"fd", NULL}; |
| 617 | int fd; |
| 618 | |
| 619 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 620 | "O&:fdatasync", _keywords, |
| 621 | fildes_converter, &fd)) |
| 622 | goto exit; |
| 623 | return_value = os_fdatasync_impl(module, fd); |
| 624 | |
| 625 | exit: |
| 626 | return return_value; |
| 627 | } |
| 628 | |
| 629 | #endif /* defined(HAVE_FDATASYNC) */ |
| 630 | |
| 631 | #if defined(HAVE_CHOWN) |
| 632 | |
| 633 | PyDoc_STRVAR(os_chown__doc__, |
| 634 | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
| 635 | "--\n" |
| 636 | "\n" |
| 637 | "Change the owner and group id of path to the numeric uid and gid.\\\n" |
| 638 | "\n" |
| 639 | " path\n" |
| 640 | " Path to be examined; can be string, bytes, or open-file-descriptor int.\n" |
| 641 | " dir_fd\n" |
| 642 | " If not None, it should be a file descriptor open to a directory,\n" |
| 643 | " and path should be relative; path will then be relative to that\n" |
| 644 | " directory.\n" |
| 645 | " follow_symlinks\n" |
| 646 | " If False, and the last element of the path is a symbolic link,\n" |
| 647 | " stat will examine the symbolic link itself instead of the file\n" |
| 648 | " the link points to.\n" |
| 649 | "\n" |
| 650 | "path may always be specified as a string.\n" |
| 651 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 652 | " If this functionality is unavailable, using it raises an exception.\n" |
| 653 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 654 | " and path should be relative; path will then be relative to that directory.\n" |
| 655 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 656 | " link, chown will modify the symbolic link itself instead of the file the\n" |
| 657 | " link points to.\n" |
| 658 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 659 | " an open file descriptor.\n" |
| 660 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 661 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 662 | |
| 663 | #define OS_CHOWN_METHODDEF \ |
| 664 | {"chown", (PyCFunction)os_chown, METH_VARARGS|METH_KEYWORDS, os_chown__doc__}, |
| 665 | |
| 666 | static PyObject * |
| 667 | os_chown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid, int dir_fd, int follow_symlinks); |
| 668 | |
| 669 | static PyObject * |
| 670 | os_chown(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 671 | { |
| 672 | PyObject *return_value = NULL; |
| 673 | static char *_keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; |
| 674 | path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN); |
| 675 | uid_t uid; |
| 676 | gid_t gid; |
| 677 | int dir_fd = DEFAULT_DIR_FD; |
| 678 | int follow_symlinks = 1; |
| 679 | |
| 680 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 681 | "O&O&O&|$O&p:chown", _keywords, |
| 682 | path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) |
| 683 | goto exit; |
| 684 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
| 685 | |
| 686 | exit: |
| 687 | /* Cleanup for path */ |
| 688 | path_cleanup(&path); |
| 689 | |
| 690 | return return_value; |
| 691 | } |
| 692 | |
| 693 | #endif /* defined(HAVE_CHOWN) */ |
| 694 | |
| 695 | #if defined(HAVE_FCHOWN) |
| 696 | |
| 697 | PyDoc_STRVAR(os_fchown__doc__, |
| 698 | "fchown($module, /, fd, uid, gid)\n" |
| 699 | "--\n" |
| 700 | "\n" |
| 701 | "Change the owner and group id of the file specified by file descriptor.\n" |
| 702 | "\n" |
| 703 | "Equivalent to os.chown(fd, uid, gid)."); |
| 704 | |
| 705 | #define OS_FCHOWN_METHODDEF \ |
| 706 | {"fchown", (PyCFunction)os_fchown, METH_VARARGS|METH_KEYWORDS, os_fchown__doc__}, |
| 707 | |
| 708 | static PyObject * |
| 709 | os_fchown_impl(PyModuleDef *module, int fd, uid_t uid, gid_t gid); |
| 710 | |
| 711 | static PyObject * |
| 712 | os_fchown(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 713 | { |
| 714 | PyObject *return_value = NULL; |
| 715 | static char *_keywords[] = {"fd", "uid", "gid", NULL}; |
| 716 | int fd; |
| 717 | uid_t uid; |
| 718 | gid_t gid; |
| 719 | |
| 720 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 721 | "iO&O&:fchown", _keywords, |
| 722 | &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) |
| 723 | goto exit; |
| 724 | return_value = os_fchown_impl(module, fd, uid, gid); |
| 725 | |
| 726 | exit: |
| 727 | return return_value; |
| 728 | } |
| 729 | |
| 730 | #endif /* defined(HAVE_FCHOWN) */ |
| 731 | |
| 732 | #if defined(HAVE_LCHOWN) |
| 733 | |
| 734 | PyDoc_STRVAR(os_lchown__doc__, |
| 735 | "lchown($module, /, path, uid, gid)\n" |
| 736 | "--\n" |
| 737 | "\n" |
| 738 | "Change the owner and group id of path to the numeric uid and gid.\n" |
| 739 | "\n" |
| 740 | "This function will not follow symbolic links.\n" |
| 741 | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); |
| 742 | |
| 743 | #define OS_LCHOWN_METHODDEF \ |
| 744 | {"lchown", (PyCFunction)os_lchown, METH_VARARGS|METH_KEYWORDS, os_lchown__doc__}, |
| 745 | |
| 746 | static PyObject * |
| 747 | os_lchown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid); |
| 748 | |
| 749 | static PyObject * |
| 750 | os_lchown(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 751 | { |
| 752 | PyObject *return_value = NULL; |
| 753 | static char *_keywords[] = {"path", "uid", "gid", NULL}; |
| 754 | path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0); |
| 755 | uid_t uid; |
| 756 | gid_t gid; |
| 757 | |
| 758 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 759 | "O&O&O&:lchown", _keywords, |
| 760 | path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) |
| 761 | goto exit; |
| 762 | return_value = os_lchown_impl(module, &path, uid, gid); |
| 763 | |
| 764 | exit: |
| 765 | /* Cleanup for path */ |
| 766 | path_cleanup(&path); |
| 767 | |
| 768 | return return_value; |
| 769 | } |
| 770 | |
| 771 | #endif /* defined(HAVE_LCHOWN) */ |
| 772 | |
| 773 | PyDoc_STRVAR(os_getcwd__doc__, |
| 774 | "getcwd($module, /)\n" |
| 775 | "--\n" |
| 776 | "\n" |
| 777 | "Return a unicode string representing the current working directory."); |
| 778 | |
| 779 | #define OS_GETCWD_METHODDEF \ |
| 780 | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
| 781 | |
| 782 | static PyObject * |
| 783 | os_getcwd_impl(PyModuleDef *module); |
| 784 | |
| 785 | static PyObject * |
| 786 | os_getcwd(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 787 | { |
| 788 | return os_getcwd_impl(module); |
| 789 | } |
| 790 | |
| 791 | PyDoc_STRVAR(os_getcwdb__doc__, |
| 792 | "getcwdb($module, /)\n" |
| 793 | "--\n" |
| 794 | "\n" |
| 795 | "Return a bytes string representing the current working directory."); |
| 796 | |
| 797 | #define OS_GETCWDB_METHODDEF \ |
| 798 | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
| 799 | |
| 800 | static PyObject * |
| 801 | os_getcwdb_impl(PyModuleDef *module); |
| 802 | |
| 803 | static PyObject * |
| 804 | os_getcwdb(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 805 | { |
| 806 | return os_getcwdb_impl(module); |
| 807 | } |
| 808 | |
| 809 | #if defined(HAVE_LINK) |
| 810 | |
| 811 | PyDoc_STRVAR(os_link__doc__, |
| 812 | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
| 813 | " follow_symlinks=True)\n" |
| 814 | "--\n" |
| 815 | "\n" |
| 816 | "Create a hard link to a file.\n" |
| 817 | "\n" |
| 818 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 819 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 820 | " should be relative; the path will then be relative to that directory.\n" |
| 821 | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
| 822 | " link, link will create a link to the symbolic link itself instead of the\n" |
| 823 | " file the link points to.\n" |
| 824 | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" |
| 825 | " platform. If they are unavailable, using them will raise a\n" |
| 826 | " NotImplementedError."); |
| 827 | |
| 828 | #define OS_LINK_METHODDEF \ |
| 829 | {"link", (PyCFunction)os_link, METH_VARARGS|METH_KEYWORDS, os_link__doc__}, |
| 830 | |
| 831 | static PyObject * |
| 832 | os_link_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd, int follow_symlinks); |
| 833 | |
| 834 | static PyObject * |
| 835 | os_link(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 836 | { |
| 837 | PyObject *return_value = NULL; |
| 838 | static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; |
| 839 | path_t src = PATH_T_INITIALIZE("link", "src", 0, 0); |
| 840 | path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0); |
| 841 | int src_dir_fd = DEFAULT_DIR_FD; |
| 842 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 843 | int follow_symlinks = 1; |
| 844 | |
| 845 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 846 | "O&O&|$O&O&p:link", _keywords, |
| 847 | path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) |
| 848 | goto exit; |
| 849 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
| 850 | |
| 851 | exit: |
| 852 | /* Cleanup for src */ |
| 853 | path_cleanup(&src); |
| 854 | /* Cleanup for dst */ |
| 855 | path_cleanup(&dst); |
| 856 | |
| 857 | return return_value; |
| 858 | } |
| 859 | |
| 860 | #endif /* defined(HAVE_LINK) */ |
| 861 | |
| 862 | PyDoc_STRVAR(os_listdir__doc__, |
| 863 | "listdir($module, /, path=None)\n" |
| 864 | "--\n" |
| 865 | "\n" |
| 866 | "Return a list containing the names of the files in the directory.\n" |
| 867 | "\n" |
| 868 | "path can be specified as either str or bytes. If path is bytes,\n" |
| 869 | " the filenames returned will also be bytes; in all other circumstances\n" |
| 870 | " the filenames returned will be str.\n" |
| 871 | "If path is None, uses the path=\'.\'.\n" |
| 872 | "On some platforms, path may also be specified as an open file descriptor;\\\n" |
| 873 | " the file descriptor must refer to a directory.\n" |
| 874 | " If this functionality is unavailable, using it raises NotImplementedError.\n" |
| 875 | "\n" |
| 876 | "The list is in arbitrary order. It does not include the special\n" |
| 877 | "entries \'.\' and \'..\' even if they are present in the directory."); |
| 878 | |
| 879 | #define OS_LISTDIR_METHODDEF \ |
| 880 | {"listdir", (PyCFunction)os_listdir, METH_VARARGS|METH_KEYWORDS, os_listdir__doc__}, |
| 881 | |
| 882 | static PyObject * |
| 883 | os_listdir_impl(PyModuleDef *module, path_t *path); |
| 884 | |
| 885 | static PyObject * |
| 886 | os_listdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 887 | { |
| 888 | PyObject *return_value = NULL; |
| 889 | static char *_keywords[] = {"path", NULL}; |
| 890 | path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR); |
| 891 | |
| 892 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 893 | "|O&:listdir", _keywords, |
| 894 | path_converter, &path)) |
| 895 | goto exit; |
| 896 | return_value = os_listdir_impl(module, &path); |
| 897 | |
| 898 | exit: |
| 899 | /* Cleanup for path */ |
| 900 | path_cleanup(&path); |
| 901 | |
| 902 | return return_value; |
| 903 | } |
| 904 | |
| 905 | #if defined(MS_WINDOWS) |
| 906 | |
| 907 | PyDoc_STRVAR(os__getfinalpathname__doc__, |
| 908 | "_getfinalpathname($module, path, /)\n" |
| 909 | "--\n" |
| 910 | "\n" |
| 911 | "A helper function for samepath on windows."); |
| 912 | |
| 913 | #define OS__GETFINALPATHNAME_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 914 | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 915 | |
| 916 | static PyObject * |
| 917 | os__getfinalpathname_impl(PyModuleDef *module, PyObject *path); |
| 918 | |
| 919 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 920 | os__getfinalpathname(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 921 | { |
| 922 | PyObject *return_value = NULL; |
| 923 | PyObject *path; |
| 924 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 925 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 926 | "U:_getfinalpathname", |
| 927 | &path)) |
| 928 | goto exit; |
| 929 | return_value = os__getfinalpathname_impl(module, path); |
| 930 | |
| 931 | exit: |
| 932 | return return_value; |
| 933 | } |
| 934 | |
| 935 | #endif /* defined(MS_WINDOWS) */ |
| 936 | |
| 937 | #if defined(MS_WINDOWS) |
| 938 | |
| 939 | PyDoc_STRVAR(os__getvolumepathname__doc__, |
| 940 | "_getvolumepathname($module, /, path)\n" |
| 941 | "--\n" |
| 942 | "\n" |
| 943 | "A helper function for ismount on Win32."); |
| 944 | |
| 945 | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
| 946 | {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_VARARGS|METH_KEYWORDS, os__getvolumepathname__doc__}, |
| 947 | |
| 948 | static PyObject * |
| 949 | os__getvolumepathname_impl(PyModuleDef *module, PyObject *path); |
| 950 | |
| 951 | static PyObject * |
| 952 | os__getvolumepathname(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 953 | { |
| 954 | PyObject *return_value = NULL; |
| 955 | static char *_keywords[] = {"path", NULL}; |
| 956 | PyObject *path; |
| 957 | |
| 958 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 959 | "U:_getvolumepathname", _keywords, |
| 960 | &path)) |
| 961 | goto exit; |
| 962 | return_value = os__getvolumepathname_impl(module, path); |
| 963 | |
| 964 | exit: |
| 965 | return return_value; |
| 966 | } |
| 967 | |
| 968 | #endif /* defined(MS_WINDOWS) */ |
| 969 | |
| 970 | PyDoc_STRVAR(os_mkdir__doc__, |
| 971 | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
| 972 | "--\n" |
| 973 | "\n" |
| 974 | "Create a directory.\n" |
| 975 | "\n" |
| 976 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 977 | " and path should be relative; path will then be relative to that directory.\n" |
| 978 | "dir_fd may not be implemented on your platform.\n" |
| 979 | " If it is unavailable, using it will raise a NotImplementedError.\n" |
| 980 | "\n" |
| 981 | "The mode argument is ignored on Windows."); |
| 982 | |
| 983 | #define OS_MKDIR_METHODDEF \ |
| 984 | {"mkdir", (PyCFunction)os_mkdir, METH_VARARGS|METH_KEYWORDS, os_mkdir__doc__}, |
| 985 | |
| 986 | static PyObject * |
| 987 | os_mkdir_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd); |
| 988 | |
| 989 | static PyObject * |
| 990 | os_mkdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 991 | { |
| 992 | PyObject *return_value = NULL; |
| 993 | static char *_keywords[] = {"path", "mode", "dir_fd", NULL}; |
| 994 | path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0); |
| 995 | int mode = 511; |
| 996 | int dir_fd = DEFAULT_DIR_FD; |
| 997 | |
| 998 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 999 | "O&|i$O&:mkdir", _keywords, |
| 1000 | path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) |
| 1001 | goto exit; |
| 1002 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
| 1003 | |
| 1004 | exit: |
| 1005 | /* Cleanup for path */ |
| 1006 | path_cleanup(&path); |
| 1007 | |
| 1008 | return return_value; |
| 1009 | } |
| 1010 | |
| 1011 | #if defined(HAVE_NICE) |
| 1012 | |
| 1013 | PyDoc_STRVAR(os_nice__doc__, |
| 1014 | "nice($module, increment, /)\n" |
| 1015 | "--\n" |
| 1016 | "\n" |
| 1017 | "Add increment to the priority of process and return the new priority."); |
| 1018 | |
| 1019 | #define OS_NICE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1020 | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1021 | |
| 1022 | static PyObject * |
| 1023 | os_nice_impl(PyModuleDef *module, int increment); |
| 1024 | |
| 1025 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1026 | os_nice(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1027 | { |
| 1028 | PyObject *return_value = NULL; |
| 1029 | int increment; |
| 1030 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1031 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1032 | "i:nice", |
| 1033 | &increment)) |
| 1034 | goto exit; |
| 1035 | return_value = os_nice_impl(module, increment); |
| 1036 | |
| 1037 | exit: |
| 1038 | return return_value; |
| 1039 | } |
| 1040 | |
| 1041 | #endif /* defined(HAVE_NICE) */ |
| 1042 | |
| 1043 | #if defined(HAVE_GETPRIORITY) |
| 1044 | |
| 1045 | PyDoc_STRVAR(os_getpriority__doc__, |
| 1046 | "getpriority($module, /, which, who)\n" |
| 1047 | "--\n" |
| 1048 | "\n" |
| 1049 | "Return program scheduling priority."); |
| 1050 | |
| 1051 | #define OS_GETPRIORITY_METHODDEF \ |
| 1052 | {"getpriority", (PyCFunction)os_getpriority, METH_VARARGS|METH_KEYWORDS, os_getpriority__doc__}, |
| 1053 | |
| 1054 | static PyObject * |
| 1055 | os_getpriority_impl(PyModuleDef *module, int which, int who); |
| 1056 | |
| 1057 | static PyObject * |
| 1058 | os_getpriority(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1059 | { |
| 1060 | PyObject *return_value = NULL; |
| 1061 | static char *_keywords[] = {"which", "who", NULL}; |
| 1062 | int which; |
| 1063 | int who; |
| 1064 | |
| 1065 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1066 | "ii:getpriority", _keywords, |
| 1067 | &which, &who)) |
| 1068 | goto exit; |
| 1069 | return_value = os_getpriority_impl(module, which, who); |
| 1070 | |
| 1071 | exit: |
| 1072 | return return_value; |
| 1073 | } |
| 1074 | |
| 1075 | #endif /* defined(HAVE_GETPRIORITY) */ |
| 1076 | |
| 1077 | #if defined(HAVE_SETPRIORITY) |
| 1078 | |
| 1079 | PyDoc_STRVAR(os_setpriority__doc__, |
| 1080 | "setpriority($module, /, which, who, priority)\n" |
| 1081 | "--\n" |
| 1082 | "\n" |
| 1083 | "Set program scheduling priority."); |
| 1084 | |
| 1085 | #define OS_SETPRIORITY_METHODDEF \ |
| 1086 | {"setpriority", (PyCFunction)os_setpriority, METH_VARARGS|METH_KEYWORDS, os_setpriority__doc__}, |
| 1087 | |
| 1088 | static PyObject * |
| 1089 | os_setpriority_impl(PyModuleDef *module, int which, int who, int priority); |
| 1090 | |
| 1091 | static PyObject * |
| 1092 | os_setpriority(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1093 | { |
| 1094 | PyObject *return_value = NULL; |
| 1095 | static char *_keywords[] = {"which", "who", "priority", NULL}; |
| 1096 | int which; |
| 1097 | int who; |
| 1098 | int priority; |
| 1099 | |
| 1100 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1101 | "iii:setpriority", _keywords, |
| 1102 | &which, &who, &priority)) |
| 1103 | goto exit; |
| 1104 | return_value = os_setpriority_impl(module, which, who, priority); |
| 1105 | |
| 1106 | exit: |
| 1107 | return return_value; |
| 1108 | } |
| 1109 | |
| 1110 | #endif /* defined(HAVE_SETPRIORITY) */ |
| 1111 | |
| 1112 | PyDoc_STRVAR(os_rename__doc__, |
| 1113 | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1114 | "--\n" |
| 1115 | "\n" |
| 1116 | "Rename a file or directory.\n" |
| 1117 | "\n" |
| 1118 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1119 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1120 | " should be relative; the path will then be relative to that directory.\n" |
| 1121 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1122 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1123 | |
| 1124 | #define OS_RENAME_METHODDEF \ |
| 1125 | {"rename", (PyCFunction)os_rename, METH_VARARGS|METH_KEYWORDS, os_rename__doc__}, |
| 1126 | |
| 1127 | static PyObject * |
| 1128 | os_rename_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd); |
| 1129 | |
| 1130 | static PyObject * |
| 1131 | os_rename(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1132 | { |
| 1133 | PyObject *return_value = NULL; |
| 1134 | static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
| 1135 | path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0); |
| 1136 | path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0); |
| 1137 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1138 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1139 | |
| 1140 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1141 | "O&O&|$O&O&:rename", _keywords, |
| 1142 | path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) |
| 1143 | goto exit; |
| 1144 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1145 | |
| 1146 | exit: |
| 1147 | /* Cleanup for src */ |
| 1148 | path_cleanup(&src); |
| 1149 | /* Cleanup for dst */ |
| 1150 | path_cleanup(&dst); |
| 1151 | |
| 1152 | return return_value; |
| 1153 | } |
| 1154 | |
| 1155 | PyDoc_STRVAR(os_replace__doc__, |
| 1156 | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1157 | "--\n" |
| 1158 | "\n" |
| 1159 | "Rename a file or directory, overwriting the destination.\n" |
| 1160 | "\n" |
| 1161 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1162 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1163 | " should be relative; the path will then be relative to that directory.\n" |
| 1164 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1165 | " If they are unavailable, using them will raise a NotImplementedError.\""); |
| 1166 | |
| 1167 | #define OS_REPLACE_METHODDEF \ |
| 1168 | {"replace", (PyCFunction)os_replace, METH_VARARGS|METH_KEYWORDS, os_replace__doc__}, |
| 1169 | |
| 1170 | static PyObject * |
| 1171 | os_replace_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd); |
| 1172 | |
| 1173 | static PyObject * |
| 1174 | os_replace(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1175 | { |
| 1176 | PyObject *return_value = NULL; |
| 1177 | static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
| 1178 | path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0); |
| 1179 | path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0); |
| 1180 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1181 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1182 | |
| 1183 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1184 | "O&O&|$O&O&:replace", _keywords, |
| 1185 | path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) |
| 1186 | goto exit; |
| 1187 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1188 | |
| 1189 | exit: |
| 1190 | /* Cleanup for src */ |
| 1191 | path_cleanup(&src); |
| 1192 | /* Cleanup for dst */ |
| 1193 | path_cleanup(&dst); |
| 1194 | |
| 1195 | return return_value; |
| 1196 | } |
| 1197 | |
| 1198 | PyDoc_STRVAR(os_rmdir__doc__, |
| 1199 | "rmdir($module, /, path, *, dir_fd=None)\n" |
| 1200 | "--\n" |
| 1201 | "\n" |
| 1202 | "Remove a directory.\n" |
| 1203 | "\n" |
| 1204 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1205 | " and path should be relative; path will then be relative to that directory.\n" |
| 1206 | "dir_fd may not be implemented on your platform.\n" |
| 1207 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1208 | |
| 1209 | #define OS_RMDIR_METHODDEF \ |
| 1210 | {"rmdir", (PyCFunction)os_rmdir, METH_VARARGS|METH_KEYWORDS, os_rmdir__doc__}, |
| 1211 | |
| 1212 | static PyObject * |
| 1213 | os_rmdir_impl(PyModuleDef *module, path_t *path, int dir_fd); |
| 1214 | |
| 1215 | static PyObject * |
| 1216 | os_rmdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1217 | { |
| 1218 | PyObject *return_value = NULL; |
| 1219 | static char *_keywords[] = {"path", "dir_fd", NULL}; |
| 1220 | path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0); |
| 1221 | int dir_fd = DEFAULT_DIR_FD; |
| 1222 | |
| 1223 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1224 | "O&|$O&:rmdir", _keywords, |
| 1225 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) |
| 1226 | goto exit; |
| 1227 | return_value = os_rmdir_impl(module, &path, dir_fd); |
| 1228 | |
| 1229 | exit: |
| 1230 | /* Cleanup for path */ |
| 1231 | path_cleanup(&path); |
| 1232 | |
| 1233 | return return_value; |
| 1234 | } |
| 1235 | |
| 1236 | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
| 1237 | |
| 1238 | PyDoc_STRVAR(os_system__doc__, |
| 1239 | "system($module, /, command)\n" |
| 1240 | "--\n" |
| 1241 | "\n" |
| 1242 | "Execute the command in a subshell."); |
| 1243 | |
| 1244 | #define OS_SYSTEM_METHODDEF \ |
| 1245 | {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__}, |
| 1246 | |
| 1247 | static long |
| 1248 | os_system_impl(PyModuleDef *module, Py_UNICODE *command); |
| 1249 | |
| 1250 | static PyObject * |
| 1251 | os_system(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1252 | { |
| 1253 | PyObject *return_value = NULL; |
| 1254 | static char *_keywords[] = {"command", NULL}; |
| 1255 | Py_UNICODE *command; |
| 1256 | long _return_value; |
| 1257 | |
| 1258 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1259 | "u:system", _keywords, |
| 1260 | &command)) |
| 1261 | goto exit; |
| 1262 | _return_value = os_system_impl(module, command); |
| 1263 | if ((_return_value == -1) && PyErr_Occurred()) |
| 1264 | goto exit; |
| 1265 | return_value = PyLong_FromLong(_return_value); |
| 1266 | |
| 1267 | exit: |
| 1268 | return return_value; |
| 1269 | } |
| 1270 | |
| 1271 | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
| 1272 | |
| 1273 | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
| 1274 | |
| 1275 | PyDoc_STRVAR(os_system__doc__, |
| 1276 | "system($module, /, command)\n" |
| 1277 | "--\n" |
| 1278 | "\n" |
| 1279 | "Execute the command in a subshell."); |
| 1280 | |
| 1281 | #define OS_SYSTEM_METHODDEF \ |
| 1282 | {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__}, |
| 1283 | |
| 1284 | static long |
| 1285 | os_system_impl(PyModuleDef *module, PyObject *command); |
| 1286 | |
| 1287 | static PyObject * |
| 1288 | os_system(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1289 | { |
| 1290 | PyObject *return_value = NULL; |
| 1291 | static char *_keywords[] = {"command", NULL}; |
| 1292 | PyObject *command = NULL; |
| 1293 | long _return_value; |
| 1294 | |
| 1295 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1296 | "O&:system", _keywords, |
| 1297 | PyUnicode_FSConverter, &command)) |
| 1298 | goto exit; |
| 1299 | _return_value = os_system_impl(module, command); |
| 1300 | if ((_return_value == -1) && PyErr_Occurred()) |
| 1301 | goto exit; |
| 1302 | return_value = PyLong_FromLong(_return_value); |
| 1303 | |
| 1304 | exit: |
| 1305 | /* Cleanup for command */ |
| 1306 | Py_XDECREF(command); |
| 1307 | |
| 1308 | return return_value; |
| 1309 | } |
| 1310 | |
| 1311 | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
| 1312 | |
| 1313 | PyDoc_STRVAR(os_umask__doc__, |
| 1314 | "umask($module, mask, /)\n" |
| 1315 | "--\n" |
| 1316 | "\n" |
| 1317 | "Set the current numeric umask and return the previous umask."); |
| 1318 | |
| 1319 | #define OS_UMASK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1320 | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1321 | |
| 1322 | static PyObject * |
| 1323 | os_umask_impl(PyModuleDef *module, int mask); |
| 1324 | |
| 1325 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1326 | os_umask(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1327 | { |
| 1328 | PyObject *return_value = NULL; |
| 1329 | int mask; |
| 1330 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1331 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1332 | "i:umask", |
| 1333 | &mask)) |
| 1334 | goto exit; |
| 1335 | return_value = os_umask_impl(module, mask); |
| 1336 | |
| 1337 | exit: |
| 1338 | return return_value; |
| 1339 | } |
| 1340 | |
| 1341 | PyDoc_STRVAR(os_unlink__doc__, |
| 1342 | "unlink($module, /, path, *, dir_fd=None)\n" |
| 1343 | "--\n" |
| 1344 | "\n" |
| 1345 | "Remove a file (same as remove()).\n" |
| 1346 | "\n" |
| 1347 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1348 | " and path should be relative; path will then be relative to that directory.\n" |
| 1349 | "dir_fd may not be implemented on your platform.\n" |
| 1350 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1351 | |
| 1352 | #define OS_UNLINK_METHODDEF \ |
| 1353 | {"unlink", (PyCFunction)os_unlink, METH_VARARGS|METH_KEYWORDS, os_unlink__doc__}, |
| 1354 | |
| 1355 | static PyObject * |
| 1356 | os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd); |
| 1357 | |
| 1358 | static PyObject * |
| 1359 | os_unlink(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1360 | { |
| 1361 | PyObject *return_value = NULL; |
| 1362 | static char *_keywords[] = {"path", "dir_fd", NULL}; |
| 1363 | path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0); |
| 1364 | int dir_fd = DEFAULT_DIR_FD; |
| 1365 | |
| 1366 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1367 | "O&|$O&:unlink", _keywords, |
| 1368 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) |
| 1369 | goto exit; |
| 1370 | return_value = os_unlink_impl(module, &path, dir_fd); |
| 1371 | |
| 1372 | exit: |
| 1373 | /* Cleanup for path */ |
| 1374 | path_cleanup(&path); |
| 1375 | |
| 1376 | return return_value; |
| 1377 | } |
| 1378 | |
| 1379 | PyDoc_STRVAR(os_remove__doc__, |
| 1380 | "remove($module, /, path, *, dir_fd=None)\n" |
| 1381 | "--\n" |
| 1382 | "\n" |
| 1383 | "Remove a file (same as unlink()).\n" |
| 1384 | "\n" |
| 1385 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1386 | " and path should be relative; path will then be relative to that directory.\n" |
| 1387 | "dir_fd may not be implemented on your platform.\n" |
| 1388 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1389 | |
| 1390 | #define OS_REMOVE_METHODDEF \ |
| 1391 | {"remove", (PyCFunction)os_remove, METH_VARARGS|METH_KEYWORDS, os_remove__doc__}, |
| 1392 | |
| 1393 | static PyObject * |
| 1394 | os_remove_impl(PyModuleDef *module, path_t *path, int dir_fd); |
| 1395 | |
| 1396 | static PyObject * |
| 1397 | os_remove(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1398 | { |
| 1399 | PyObject *return_value = NULL; |
| 1400 | static char *_keywords[] = {"path", "dir_fd", NULL}; |
| 1401 | path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0); |
| 1402 | int dir_fd = DEFAULT_DIR_FD; |
| 1403 | |
| 1404 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1405 | "O&|$O&:remove", _keywords, |
| 1406 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) |
| 1407 | goto exit; |
| 1408 | return_value = os_remove_impl(module, &path, dir_fd); |
| 1409 | |
| 1410 | exit: |
| 1411 | /* Cleanup for path */ |
| 1412 | path_cleanup(&path); |
| 1413 | |
| 1414 | return return_value; |
| 1415 | } |
| 1416 | |
| 1417 | #if defined(HAVE_UNAME) |
| 1418 | |
| 1419 | PyDoc_STRVAR(os_uname__doc__, |
| 1420 | "uname($module, /)\n" |
| 1421 | "--\n" |
| 1422 | "\n" |
| 1423 | "Return an object identifying the current operating system.\n" |
| 1424 | "\n" |
| 1425 | "The object behaves like a named tuple with the following fields:\n" |
| 1426 | " (sysname, nodename, release, version, machine)"); |
| 1427 | |
| 1428 | #define OS_UNAME_METHODDEF \ |
| 1429 | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
| 1430 | |
| 1431 | static PyObject * |
| 1432 | os_uname_impl(PyModuleDef *module); |
| 1433 | |
| 1434 | static PyObject * |
| 1435 | os_uname(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 1436 | { |
| 1437 | return os_uname_impl(module); |
| 1438 | } |
| 1439 | |
| 1440 | #endif /* defined(HAVE_UNAME) */ |
| 1441 | |
| 1442 | PyDoc_STRVAR(os_utime__doc__, |
| 1443 | "utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n" |
| 1444 | " follow_symlinks=True)\n" |
| 1445 | "--\n" |
| 1446 | "\n" |
| 1447 | "Set the access and modified time of path.\n" |
| 1448 | "\n" |
| 1449 | "path may always be specified as a string.\n" |
| 1450 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 1451 | " If this functionality is unavailable, using it raises an exception.\n" |
| 1452 | "\n" |
| 1453 | "If times is not None, it must be a tuple (atime, mtime);\n" |
| 1454 | " atime and mtime should be expressed as float seconds since the epoch.\n" |
| 1455 | "If ns is not None, it must be a tuple (atime_ns, mtime_ns);\n" |
| 1456 | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
| 1457 | " since the epoch.\n" |
| 1458 | "If both times and ns are None, utime uses the current time.\n" |
| 1459 | "Specifying tuples for both times and ns is an error.\n" |
| 1460 | "\n" |
| 1461 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1462 | " and path should be relative; path will then be relative to that directory.\n" |
| 1463 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 1464 | " link, utime will modify the symbolic link itself instead of the file the\n" |
| 1465 | " link points to.\n" |
| 1466 | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
| 1467 | " as an open file descriptor.\n" |
| 1468 | "dir_fd and follow_symlinks may not be available on your platform.\n" |
| 1469 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1470 | |
| 1471 | #define OS_UTIME_METHODDEF \ |
| 1472 | {"utime", (PyCFunction)os_utime, METH_VARARGS|METH_KEYWORDS, os_utime__doc__}, |
| 1473 | |
| 1474 | static PyObject * |
| 1475 | os_utime_impl(PyModuleDef *module, path_t *path, PyObject *times, PyObject *ns, int dir_fd, int follow_symlinks); |
| 1476 | |
| 1477 | static PyObject * |
| 1478 | os_utime(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1479 | { |
| 1480 | PyObject *return_value = NULL; |
| 1481 | static char *_keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
| 1482 | path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD); |
| 1483 | PyObject *times = NULL; |
| 1484 | PyObject *ns = NULL; |
| 1485 | int dir_fd = DEFAULT_DIR_FD; |
| 1486 | int follow_symlinks = 1; |
| 1487 | |
| 1488 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1489 | "O&|O$OO&p:utime", _keywords, |
| 1490 | path_converter, &path, ×, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) |
| 1491 | goto exit; |
| 1492 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
| 1493 | |
| 1494 | exit: |
| 1495 | /* Cleanup for path */ |
| 1496 | path_cleanup(&path); |
| 1497 | |
| 1498 | return return_value; |
| 1499 | } |
| 1500 | |
| 1501 | PyDoc_STRVAR(os__exit__doc__, |
| 1502 | "_exit($module, /, status)\n" |
| 1503 | "--\n" |
| 1504 | "\n" |
| 1505 | "Exit to the system with specified status, without normal exit processing."); |
| 1506 | |
| 1507 | #define OS__EXIT_METHODDEF \ |
| 1508 | {"_exit", (PyCFunction)os__exit, METH_VARARGS|METH_KEYWORDS, os__exit__doc__}, |
| 1509 | |
| 1510 | static PyObject * |
| 1511 | os__exit_impl(PyModuleDef *module, int status); |
| 1512 | |
| 1513 | static PyObject * |
| 1514 | os__exit(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1515 | { |
| 1516 | PyObject *return_value = NULL; |
| 1517 | static char *_keywords[] = {"status", NULL}; |
| 1518 | int status; |
| 1519 | |
| 1520 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1521 | "i:_exit", _keywords, |
| 1522 | &status)) |
| 1523 | goto exit; |
| 1524 | return_value = os__exit_impl(module, status); |
| 1525 | |
| 1526 | exit: |
| 1527 | return return_value; |
| 1528 | } |
| 1529 | |
| 1530 | #if defined(HAVE_EXECV) |
| 1531 | |
| 1532 | PyDoc_STRVAR(os_execv__doc__, |
| 1533 | "execv($module, path, argv, /)\n" |
| 1534 | "--\n" |
| 1535 | "\n" |
| 1536 | "Execute an executable path with arguments, replacing current process.\n" |
| 1537 | "\n" |
| 1538 | " path\n" |
| 1539 | " Path of executable file.\n" |
| 1540 | " argv\n" |
| 1541 | " Tuple or list of strings."); |
| 1542 | |
| 1543 | #define OS_EXECV_METHODDEF \ |
| 1544 | {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__}, |
| 1545 | |
| 1546 | static PyObject * |
| 1547 | os_execv_impl(PyModuleDef *module, PyObject *path, PyObject *argv); |
| 1548 | |
| 1549 | static PyObject * |
| 1550 | os_execv(PyModuleDef *module, PyObject *args) |
| 1551 | { |
| 1552 | PyObject *return_value = NULL; |
| 1553 | PyObject *path = NULL; |
| 1554 | PyObject *argv; |
| 1555 | |
| 1556 | if (!PyArg_ParseTuple(args, |
| 1557 | "O&O:execv", |
| 1558 | PyUnicode_FSConverter, &path, &argv)) |
| 1559 | goto exit; |
| 1560 | return_value = os_execv_impl(module, path, argv); |
| 1561 | |
| 1562 | exit: |
| 1563 | /* Cleanup for path */ |
| 1564 | Py_XDECREF(path); |
| 1565 | |
| 1566 | return return_value; |
| 1567 | } |
| 1568 | |
| 1569 | #endif /* defined(HAVE_EXECV) */ |
| 1570 | |
| 1571 | #if defined(HAVE_EXECV) |
| 1572 | |
| 1573 | PyDoc_STRVAR(os_execve__doc__, |
| 1574 | "execve($module, /, path, argv, env)\n" |
| 1575 | "--\n" |
| 1576 | "\n" |
| 1577 | "Execute an executable path with arguments, replacing current process.\n" |
| 1578 | "\n" |
| 1579 | " path\n" |
| 1580 | " Path of executable file.\n" |
| 1581 | " argv\n" |
| 1582 | " Tuple or list of strings.\n" |
| 1583 | " env\n" |
| 1584 | " Dictionary of strings mapping to strings."); |
| 1585 | |
| 1586 | #define OS_EXECVE_METHODDEF \ |
| 1587 | {"execve", (PyCFunction)os_execve, METH_VARARGS|METH_KEYWORDS, os_execve__doc__}, |
| 1588 | |
| 1589 | static PyObject * |
| 1590 | os_execve_impl(PyModuleDef *module, path_t *path, PyObject *argv, PyObject *env); |
| 1591 | |
| 1592 | static PyObject * |
| 1593 | os_execve(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1594 | { |
| 1595 | PyObject *return_value = NULL; |
| 1596 | static char *_keywords[] = {"path", "argv", "env", NULL}; |
| 1597 | path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE); |
| 1598 | PyObject *argv; |
| 1599 | PyObject *env; |
| 1600 | |
| 1601 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1602 | "O&OO:execve", _keywords, |
| 1603 | path_converter, &path, &argv, &env)) |
| 1604 | goto exit; |
| 1605 | return_value = os_execve_impl(module, &path, argv, env); |
| 1606 | |
| 1607 | exit: |
| 1608 | /* Cleanup for path */ |
| 1609 | path_cleanup(&path); |
| 1610 | |
| 1611 | return return_value; |
| 1612 | } |
| 1613 | |
| 1614 | #endif /* defined(HAVE_EXECV) */ |
| 1615 | |
| 1616 | #if defined(HAVE_SPAWNV) |
| 1617 | |
| 1618 | PyDoc_STRVAR(os_spawnv__doc__, |
| 1619 | "spawnv($module, mode, path, argv, /)\n" |
| 1620 | "--\n" |
| 1621 | "\n" |
| 1622 | "Execute the program specified by path in a new process.\n" |
| 1623 | "\n" |
| 1624 | " mode\n" |
| 1625 | " Mode of process creation.\n" |
| 1626 | " path\n" |
| 1627 | " Path of executable file.\n" |
| 1628 | " argv\n" |
| 1629 | " Tuple or list of strings."); |
| 1630 | |
| 1631 | #define OS_SPAWNV_METHODDEF \ |
| 1632 | {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__}, |
| 1633 | |
| 1634 | static PyObject * |
| 1635 | os_spawnv_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv); |
| 1636 | |
| 1637 | static PyObject * |
| 1638 | os_spawnv(PyModuleDef *module, PyObject *args) |
| 1639 | { |
| 1640 | PyObject *return_value = NULL; |
| 1641 | int mode; |
| 1642 | PyObject *path = NULL; |
| 1643 | PyObject *argv; |
| 1644 | |
| 1645 | if (!PyArg_ParseTuple(args, |
| 1646 | "iO&O:spawnv", |
| 1647 | &mode, PyUnicode_FSConverter, &path, &argv)) |
| 1648 | goto exit; |
| 1649 | return_value = os_spawnv_impl(module, mode, path, argv); |
| 1650 | |
| 1651 | exit: |
| 1652 | /* Cleanup for path */ |
| 1653 | Py_XDECREF(path); |
| 1654 | |
| 1655 | return return_value; |
| 1656 | } |
| 1657 | |
| 1658 | #endif /* defined(HAVE_SPAWNV) */ |
| 1659 | |
| 1660 | #if defined(HAVE_SPAWNV) |
| 1661 | |
| 1662 | PyDoc_STRVAR(os_spawnve__doc__, |
| 1663 | "spawnve($module, mode, path, argv, env, /)\n" |
| 1664 | "--\n" |
| 1665 | "\n" |
| 1666 | "Execute the program specified by path in a new process.\n" |
| 1667 | "\n" |
| 1668 | " mode\n" |
| 1669 | " Mode of process creation.\n" |
| 1670 | " path\n" |
| 1671 | " Path of executable file.\n" |
| 1672 | " argv\n" |
| 1673 | " Tuple or list of strings.\n" |
| 1674 | " env\n" |
| 1675 | " Dictionary of strings mapping to strings."); |
| 1676 | |
| 1677 | #define OS_SPAWNVE_METHODDEF \ |
| 1678 | {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__}, |
| 1679 | |
| 1680 | static PyObject * |
| 1681 | os_spawnve_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv, PyObject *env); |
| 1682 | |
| 1683 | static PyObject * |
| 1684 | os_spawnve(PyModuleDef *module, PyObject *args) |
| 1685 | { |
| 1686 | PyObject *return_value = NULL; |
| 1687 | int mode; |
| 1688 | PyObject *path = NULL; |
| 1689 | PyObject *argv; |
| 1690 | PyObject *env; |
| 1691 | |
| 1692 | if (!PyArg_ParseTuple(args, |
| 1693 | "iO&OO:spawnve", |
| 1694 | &mode, PyUnicode_FSConverter, &path, &argv, &env)) |
| 1695 | goto exit; |
| 1696 | return_value = os_spawnve_impl(module, mode, path, argv, env); |
| 1697 | |
| 1698 | exit: |
| 1699 | /* Cleanup for path */ |
| 1700 | Py_XDECREF(path); |
| 1701 | |
| 1702 | return return_value; |
| 1703 | } |
| 1704 | |
| 1705 | #endif /* defined(HAVE_SPAWNV) */ |
| 1706 | |
| 1707 | #if defined(HAVE_FORK1) |
| 1708 | |
| 1709 | PyDoc_STRVAR(os_fork1__doc__, |
| 1710 | "fork1($module, /)\n" |
| 1711 | "--\n" |
| 1712 | "\n" |
| 1713 | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
| 1714 | "\n" |
| 1715 | "Return 0 to child process and PID of child to parent process."); |
| 1716 | |
| 1717 | #define OS_FORK1_METHODDEF \ |
| 1718 | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
| 1719 | |
| 1720 | static PyObject * |
| 1721 | os_fork1_impl(PyModuleDef *module); |
| 1722 | |
| 1723 | static PyObject * |
| 1724 | os_fork1(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 1725 | { |
| 1726 | return os_fork1_impl(module); |
| 1727 | } |
| 1728 | |
| 1729 | #endif /* defined(HAVE_FORK1) */ |
| 1730 | |
| 1731 | #if defined(HAVE_FORK) |
| 1732 | |
| 1733 | PyDoc_STRVAR(os_fork__doc__, |
| 1734 | "fork($module, /)\n" |
| 1735 | "--\n" |
| 1736 | "\n" |
| 1737 | "Fork a child process.\n" |
| 1738 | "\n" |
| 1739 | "Return 0 to child process and PID of child to parent process."); |
| 1740 | |
| 1741 | #define OS_FORK_METHODDEF \ |
| 1742 | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
| 1743 | |
| 1744 | static PyObject * |
| 1745 | os_fork_impl(PyModuleDef *module); |
| 1746 | |
| 1747 | static PyObject * |
| 1748 | os_fork(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 1749 | { |
| 1750 | return os_fork_impl(module); |
| 1751 | } |
| 1752 | |
| 1753 | #endif /* defined(HAVE_FORK) */ |
| 1754 | |
| 1755 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 1756 | |
| 1757 | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
| 1758 | "sched_get_priority_max($module, /, policy)\n" |
| 1759 | "--\n" |
| 1760 | "\n" |
| 1761 | "Get the maximum scheduling priority for policy."); |
| 1762 | |
| 1763 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
| 1764 | {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_max__doc__}, |
| 1765 | |
| 1766 | static PyObject * |
| 1767 | os_sched_get_priority_max_impl(PyModuleDef *module, int policy); |
| 1768 | |
| 1769 | static PyObject * |
| 1770 | os_sched_get_priority_max(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1771 | { |
| 1772 | PyObject *return_value = NULL; |
| 1773 | static char *_keywords[] = {"policy", NULL}; |
| 1774 | int policy; |
| 1775 | |
| 1776 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1777 | "i:sched_get_priority_max", _keywords, |
| 1778 | &policy)) |
| 1779 | goto exit; |
| 1780 | return_value = os_sched_get_priority_max_impl(module, policy); |
| 1781 | |
| 1782 | exit: |
| 1783 | return return_value; |
| 1784 | } |
| 1785 | |
| 1786 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 1787 | |
| 1788 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 1789 | |
| 1790 | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
| 1791 | "sched_get_priority_min($module, /, policy)\n" |
| 1792 | "--\n" |
| 1793 | "\n" |
| 1794 | "Get the minimum scheduling priority for policy."); |
| 1795 | |
| 1796 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
| 1797 | {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_min__doc__}, |
| 1798 | |
| 1799 | static PyObject * |
| 1800 | os_sched_get_priority_min_impl(PyModuleDef *module, int policy); |
| 1801 | |
| 1802 | static PyObject * |
| 1803 | os_sched_get_priority_min(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 1804 | { |
| 1805 | PyObject *return_value = NULL; |
| 1806 | static char *_keywords[] = {"policy", NULL}; |
| 1807 | int policy; |
| 1808 | |
| 1809 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1810 | "i:sched_get_priority_min", _keywords, |
| 1811 | &policy)) |
| 1812 | goto exit; |
| 1813 | return_value = os_sched_get_priority_min_impl(module, policy); |
| 1814 | |
| 1815 | exit: |
| 1816 | return return_value; |
| 1817 | } |
| 1818 | |
| 1819 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 1820 | |
| 1821 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 1822 | |
| 1823 | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
| 1824 | "sched_getscheduler($module, pid, /)\n" |
| 1825 | "--\n" |
| 1826 | "\n" |
| 1827 | "Get the scheduling policy for the process identifiedy by pid.\n" |
| 1828 | "\n" |
| 1829 | "Passing 0 for pid returns the scheduling policy for the calling process."); |
| 1830 | |
| 1831 | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1832 | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1833 | |
| 1834 | static PyObject * |
| 1835 | os_sched_getscheduler_impl(PyModuleDef *module, pid_t pid); |
| 1836 | |
| 1837 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1838 | os_sched_getscheduler(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1839 | { |
| 1840 | PyObject *return_value = NULL; |
| 1841 | pid_t pid; |
| 1842 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1843 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1844 | "" _Py_PARSE_PID ":sched_getscheduler", |
| 1845 | &pid)) |
| 1846 | goto exit; |
| 1847 | return_value = os_sched_getscheduler_impl(module, pid); |
| 1848 | |
| 1849 | exit: |
| 1850 | return return_value; |
| 1851 | } |
| 1852 | |
| 1853 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 1854 | |
| 1855 | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) |
| 1856 | |
| 1857 | PyDoc_STRVAR(os_sched_param__doc__, |
| 1858 | "sched_param(sched_priority)\n" |
| 1859 | "--\n" |
| 1860 | "\n" |
| 1861 | "Current has only one field: sched_priority\");\n" |
| 1862 | "\n" |
| 1863 | " sched_priority\n" |
| 1864 | " A scheduling parameter."); |
| 1865 | |
| 1866 | static PyObject * |
| 1867 | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
| 1868 | |
| 1869 | static PyObject * |
| 1870 | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 1871 | { |
| 1872 | PyObject *return_value = NULL; |
| 1873 | static char *_keywords[] = {"sched_priority", NULL}; |
| 1874 | PyObject *sched_priority; |
| 1875 | |
| 1876 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 1877 | "O:sched_param", _keywords, |
| 1878 | &sched_priority)) |
| 1879 | goto exit; |
| 1880 | return_value = os_sched_param_impl(type, sched_priority); |
| 1881 | |
| 1882 | exit: |
| 1883 | return return_value; |
| 1884 | } |
| 1885 | |
| 1886 | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */ |
| 1887 | |
| 1888 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 1889 | |
| 1890 | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
| 1891 | "sched_setscheduler($module, pid, policy, param, /)\n" |
| 1892 | "--\n" |
| 1893 | "\n" |
| 1894 | "Set the scheduling policy for the process identified by pid.\n" |
| 1895 | "\n" |
| 1896 | "If pid is 0, the calling process is changed.\n" |
| 1897 | "param is an instance of sched_param."); |
| 1898 | |
| 1899 | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
| 1900 | {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__}, |
| 1901 | |
| 1902 | static PyObject * |
| 1903 | os_sched_setscheduler_impl(PyModuleDef *module, pid_t pid, int policy, struct sched_param *param); |
| 1904 | |
| 1905 | static PyObject * |
| 1906 | os_sched_setscheduler(PyModuleDef *module, PyObject *args) |
| 1907 | { |
| 1908 | PyObject *return_value = NULL; |
| 1909 | pid_t pid; |
| 1910 | int policy; |
| 1911 | struct sched_param param; |
| 1912 | |
| 1913 | if (!PyArg_ParseTuple(args, |
| 1914 | "" _Py_PARSE_PID "iO&:sched_setscheduler", |
| 1915 | &pid, &policy, convert_sched_param, ¶m)) |
| 1916 | goto exit; |
| 1917 | return_value = os_sched_setscheduler_impl(module, pid, policy, ¶m); |
| 1918 | |
| 1919 | exit: |
| 1920 | return return_value; |
| 1921 | } |
| 1922 | |
| 1923 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 1924 | |
| 1925 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 1926 | |
| 1927 | PyDoc_STRVAR(os_sched_getparam__doc__, |
| 1928 | "sched_getparam($module, pid, /)\n" |
| 1929 | "--\n" |
| 1930 | "\n" |
| 1931 | "Returns scheduling parameters for the process identified by pid.\n" |
| 1932 | "\n" |
| 1933 | "If pid is 0, returns parameters for the calling process.\n" |
| 1934 | "Return value is an instance of sched_param."); |
| 1935 | |
| 1936 | #define OS_SCHED_GETPARAM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1937 | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1938 | |
| 1939 | static PyObject * |
| 1940 | os_sched_getparam_impl(PyModuleDef *module, pid_t pid); |
| 1941 | |
| 1942 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1943 | os_sched_getparam(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1944 | { |
| 1945 | PyObject *return_value = NULL; |
| 1946 | pid_t pid; |
| 1947 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 1948 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1949 | "" _Py_PARSE_PID ":sched_getparam", |
| 1950 | &pid)) |
| 1951 | goto exit; |
| 1952 | return_value = os_sched_getparam_impl(module, pid); |
| 1953 | |
| 1954 | exit: |
| 1955 | return return_value; |
| 1956 | } |
| 1957 | |
| 1958 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 1959 | |
| 1960 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 1961 | |
| 1962 | PyDoc_STRVAR(os_sched_setparam__doc__, |
| 1963 | "sched_setparam($module, pid, param, /)\n" |
| 1964 | "--\n" |
| 1965 | "\n" |
| 1966 | "Set scheduling parameters for the process identified by pid.\n" |
| 1967 | "\n" |
| 1968 | "If pid is 0, sets parameters for the calling process.\n" |
| 1969 | "param should be an instance of sched_param."); |
| 1970 | |
| 1971 | #define OS_SCHED_SETPARAM_METHODDEF \ |
| 1972 | {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__}, |
| 1973 | |
| 1974 | static PyObject * |
| 1975 | os_sched_setparam_impl(PyModuleDef *module, pid_t pid, struct sched_param *param); |
| 1976 | |
| 1977 | static PyObject * |
| 1978 | os_sched_setparam(PyModuleDef *module, PyObject *args) |
| 1979 | { |
| 1980 | PyObject *return_value = NULL; |
| 1981 | pid_t pid; |
| 1982 | struct sched_param param; |
| 1983 | |
| 1984 | if (!PyArg_ParseTuple(args, |
| 1985 | "" _Py_PARSE_PID "O&:sched_setparam", |
| 1986 | &pid, convert_sched_param, ¶m)) |
| 1987 | goto exit; |
| 1988 | return_value = os_sched_setparam_impl(module, pid, ¶m); |
| 1989 | |
| 1990 | exit: |
| 1991 | return return_value; |
| 1992 | } |
| 1993 | |
| 1994 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 1995 | |
| 1996 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
| 1997 | |
| 1998 | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
| 1999 | "sched_rr_get_interval($module, pid, /)\n" |
| 2000 | "--\n" |
| 2001 | "\n" |
| 2002 | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
| 2003 | "\n" |
| 2004 | "Value returned is a float."); |
| 2005 | |
| 2006 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2007 | {"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] | 2008 | |
| 2009 | static double |
| 2010 | os_sched_rr_get_interval_impl(PyModuleDef *module, pid_t pid); |
| 2011 | |
| 2012 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2013 | os_sched_rr_get_interval(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2014 | { |
| 2015 | PyObject *return_value = NULL; |
| 2016 | pid_t pid; |
| 2017 | double _return_value; |
| 2018 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2019 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2020 | "" _Py_PARSE_PID ":sched_rr_get_interval", |
| 2021 | &pid)) |
| 2022 | goto exit; |
| 2023 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
| 2024 | if ((_return_value == -1.0) && PyErr_Occurred()) |
| 2025 | goto exit; |
| 2026 | return_value = PyFloat_FromDouble(_return_value); |
| 2027 | |
| 2028 | exit: |
| 2029 | return return_value; |
| 2030 | } |
| 2031 | |
| 2032 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
| 2033 | |
| 2034 | #if defined(HAVE_SCHED_H) |
| 2035 | |
| 2036 | PyDoc_STRVAR(os_sched_yield__doc__, |
| 2037 | "sched_yield($module, /)\n" |
| 2038 | "--\n" |
| 2039 | "\n" |
| 2040 | "Voluntarily relinquish the CPU."); |
| 2041 | |
| 2042 | #define OS_SCHED_YIELD_METHODDEF \ |
| 2043 | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
| 2044 | |
| 2045 | static PyObject * |
| 2046 | os_sched_yield_impl(PyModuleDef *module); |
| 2047 | |
| 2048 | static PyObject * |
| 2049 | os_sched_yield(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2050 | { |
| 2051 | return os_sched_yield_impl(module); |
| 2052 | } |
| 2053 | |
| 2054 | #endif /* defined(HAVE_SCHED_H) */ |
| 2055 | |
| 2056 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 2057 | |
| 2058 | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
| 2059 | "sched_setaffinity($module, pid, mask, /)\n" |
| 2060 | "--\n" |
| 2061 | "\n" |
| 2062 | "Set the CPU affinity of the process identified by pid to mask.\n" |
| 2063 | "\n" |
| 2064 | "mask should be an iterable of integers identifying CPUs."); |
| 2065 | |
| 2066 | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
| 2067 | {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__}, |
| 2068 | |
| 2069 | static PyObject * |
| 2070 | os_sched_setaffinity_impl(PyModuleDef *module, pid_t pid, PyObject *mask); |
| 2071 | |
| 2072 | static PyObject * |
| 2073 | os_sched_setaffinity(PyModuleDef *module, PyObject *args) |
| 2074 | { |
| 2075 | PyObject *return_value = NULL; |
| 2076 | pid_t pid; |
| 2077 | PyObject *mask; |
| 2078 | |
| 2079 | if (!PyArg_ParseTuple(args, |
| 2080 | "" _Py_PARSE_PID "O:sched_setaffinity", |
| 2081 | &pid, &mask)) |
| 2082 | goto exit; |
| 2083 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
| 2084 | |
| 2085 | exit: |
| 2086 | return return_value; |
| 2087 | } |
| 2088 | |
| 2089 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 2090 | |
| 2091 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 2092 | |
| 2093 | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
| 2094 | "sched_getaffinity($module, pid, /)\n" |
| 2095 | "--\n" |
| 2096 | "\n" |
| 2097 | "Return the affinity of the process identified by pid.\n" |
| 2098 | "\n" |
| 2099 | "The affinity is returned as a set of CPU identifiers."); |
| 2100 | |
| 2101 | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2102 | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2103 | |
| 2104 | static PyObject * |
| 2105 | os_sched_getaffinity_impl(PyModuleDef *module, pid_t pid); |
| 2106 | |
| 2107 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2108 | os_sched_getaffinity(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2109 | { |
| 2110 | PyObject *return_value = NULL; |
| 2111 | pid_t pid; |
| 2112 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2113 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2114 | "" _Py_PARSE_PID ":sched_getaffinity", |
| 2115 | &pid)) |
| 2116 | goto exit; |
| 2117 | return_value = os_sched_getaffinity_impl(module, pid); |
| 2118 | |
| 2119 | exit: |
| 2120 | return return_value; |
| 2121 | } |
| 2122 | |
| 2123 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 2124 | |
| 2125 | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
| 2126 | |
| 2127 | PyDoc_STRVAR(os_openpty__doc__, |
| 2128 | "openpty($module, /)\n" |
| 2129 | "--\n" |
| 2130 | "\n" |
| 2131 | "Open a pseudo-terminal.\n" |
| 2132 | "\n" |
| 2133 | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
| 2134 | "for both the master and slave ends."); |
| 2135 | |
| 2136 | #define OS_OPENPTY_METHODDEF \ |
| 2137 | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
| 2138 | |
| 2139 | static PyObject * |
| 2140 | os_openpty_impl(PyModuleDef *module); |
| 2141 | |
| 2142 | static PyObject * |
| 2143 | os_openpty(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2144 | { |
| 2145 | return os_openpty_impl(module); |
| 2146 | } |
| 2147 | |
| 2148 | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
| 2149 | |
| 2150 | #if defined(HAVE_FORKPTY) |
| 2151 | |
| 2152 | PyDoc_STRVAR(os_forkpty__doc__, |
| 2153 | "forkpty($module, /)\n" |
| 2154 | "--\n" |
| 2155 | "\n" |
| 2156 | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
| 2157 | "\n" |
| 2158 | "Returns a tuple of (pid, master_fd).\n" |
| 2159 | "Like fork(), return pid of 0 to the child process,\n" |
| 2160 | "and pid of child to the parent process.\n" |
| 2161 | "To both, return fd of newly opened pseudo-terminal."); |
| 2162 | |
| 2163 | #define OS_FORKPTY_METHODDEF \ |
| 2164 | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
| 2165 | |
| 2166 | static PyObject * |
| 2167 | os_forkpty_impl(PyModuleDef *module); |
| 2168 | |
| 2169 | static PyObject * |
| 2170 | os_forkpty(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2171 | { |
| 2172 | return os_forkpty_impl(module); |
| 2173 | } |
| 2174 | |
| 2175 | #endif /* defined(HAVE_FORKPTY) */ |
| 2176 | |
| 2177 | #if defined(HAVE_GETEGID) |
| 2178 | |
| 2179 | PyDoc_STRVAR(os_getegid__doc__, |
| 2180 | "getegid($module, /)\n" |
| 2181 | "--\n" |
| 2182 | "\n" |
| 2183 | "Return the current process\'s effective group id."); |
| 2184 | |
| 2185 | #define OS_GETEGID_METHODDEF \ |
| 2186 | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
| 2187 | |
| 2188 | static PyObject * |
| 2189 | os_getegid_impl(PyModuleDef *module); |
| 2190 | |
| 2191 | static PyObject * |
| 2192 | os_getegid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2193 | { |
| 2194 | return os_getegid_impl(module); |
| 2195 | } |
| 2196 | |
| 2197 | #endif /* defined(HAVE_GETEGID) */ |
| 2198 | |
| 2199 | #if defined(HAVE_GETEUID) |
| 2200 | |
| 2201 | PyDoc_STRVAR(os_geteuid__doc__, |
| 2202 | "geteuid($module, /)\n" |
| 2203 | "--\n" |
| 2204 | "\n" |
| 2205 | "Return the current process\'s effective user id."); |
| 2206 | |
| 2207 | #define OS_GETEUID_METHODDEF \ |
| 2208 | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
| 2209 | |
| 2210 | static PyObject * |
| 2211 | os_geteuid_impl(PyModuleDef *module); |
| 2212 | |
| 2213 | static PyObject * |
| 2214 | os_geteuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2215 | { |
| 2216 | return os_geteuid_impl(module); |
| 2217 | } |
| 2218 | |
| 2219 | #endif /* defined(HAVE_GETEUID) */ |
| 2220 | |
| 2221 | #if defined(HAVE_GETGID) |
| 2222 | |
| 2223 | PyDoc_STRVAR(os_getgid__doc__, |
| 2224 | "getgid($module, /)\n" |
| 2225 | "--\n" |
| 2226 | "\n" |
| 2227 | "Return the current process\'s group id."); |
| 2228 | |
| 2229 | #define OS_GETGID_METHODDEF \ |
| 2230 | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
| 2231 | |
| 2232 | static PyObject * |
| 2233 | os_getgid_impl(PyModuleDef *module); |
| 2234 | |
| 2235 | static PyObject * |
| 2236 | os_getgid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2237 | { |
| 2238 | return os_getgid_impl(module); |
| 2239 | } |
| 2240 | |
| 2241 | #endif /* defined(HAVE_GETGID) */ |
| 2242 | |
| 2243 | PyDoc_STRVAR(os_getpid__doc__, |
| 2244 | "getpid($module, /)\n" |
| 2245 | "--\n" |
| 2246 | "\n" |
| 2247 | "Return the current process id."); |
| 2248 | |
| 2249 | #define OS_GETPID_METHODDEF \ |
| 2250 | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
| 2251 | |
| 2252 | static PyObject * |
| 2253 | os_getpid_impl(PyModuleDef *module); |
| 2254 | |
| 2255 | static PyObject * |
| 2256 | os_getpid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2257 | { |
| 2258 | return os_getpid_impl(module); |
| 2259 | } |
| 2260 | |
| 2261 | #if defined(HAVE_GETGROUPS) |
| 2262 | |
| 2263 | PyDoc_STRVAR(os_getgroups__doc__, |
| 2264 | "getgroups($module, /)\n" |
| 2265 | "--\n" |
| 2266 | "\n" |
| 2267 | "Return list of supplemental group IDs for the process."); |
| 2268 | |
| 2269 | #define OS_GETGROUPS_METHODDEF \ |
| 2270 | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
| 2271 | |
| 2272 | static PyObject * |
| 2273 | os_getgroups_impl(PyModuleDef *module); |
| 2274 | |
| 2275 | static PyObject * |
| 2276 | os_getgroups(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2277 | { |
| 2278 | return os_getgroups_impl(module); |
| 2279 | } |
| 2280 | |
| 2281 | #endif /* defined(HAVE_GETGROUPS) */ |
| 2282 | |
| 2283 | #if defined(HAVE_GETPGID) |
| 2284 | |
| 2285 | PyDoc_STRVAR(os_getpgid__doc__, |
| 2286 | "getpgid($module, /, pid)\n" |
| 2287 | "--\n" |
| 2288 | "\n" |
| 2289 | "Call the system call getpgid(), and return the result."); |
| 2290 | |
| 2291 | #define OS_GETPGID_METHODDEF \ |
| 2292 | {"getpgid", (PyCFunction)os_getpgid, METH_VARARGS|METH_KEYWORDS, os_getpgid__doc__}, |
| 2293 | |
| 2294 | static PyObject * |
| 2295 | os_getpgid_impl(PyModuleDef *module, pid_t pid); |
| 2296 | |
| 2297 | static PyObject * |
| 2298 | os_getpgid(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 2299 | { |
| 2300 | PyObject *return_value = NULL; |
| 2301 | static char *_keywords[] = {"pid", NULL}; |
| 2302 | pid_t pid; |
| 2303 | |
| 2304 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 2305 | "" _Py_PARSE_PID ":getpgid", _keywords, |
| 2306 | &pid)) |
| 2307 | goto exit; |
| 2308 | return_value = os_getpgid_impl(module, pid); |
| 2309 | |
| 2310 | exit: |
| 2311 | return return_value; |
| 2312 | } |
| 2313 | |
| 2314 | #endif /* defined(HAVE_GETPGID) */ |
| 2315 | |
| 2316 | #if defined(HAVE_GETPGRP) |
| 2317 | |
| 2318 | PyDoc_STRVAR(os_getpgrp__doc__, |
| 2319 | "getpgrp($module, /)\n" |
| 2320 | "--\n" |
| 2321 | "\n" |
| 2322 | "Return the current process group id."); |
| 2323 | |
| 2324 | #define OS_GETPGRP_METHODDEF \ |
| 2325 | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
| 2326 | |
| 2327 | static PyObject * |
| 2328 | os_getpgrp_impl(PyModuleDef *module); |
| 2329 | |
| 2330 | static PyObject * |
| 2331 | os_getpgrp(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2332 | { |
| 2333 | return os_getpgrp_impl(module); |
| 2334 | } |
| 2335 | |
| 2336 | #endif /* defined(HAVE_GETPGRP) */ |
| 2337 | |
| 2338 | #if defined(HAVE_SETPGRP) |
| 2339 | |
| 2340 | PyDoc_STRVAR(os_setpgrp__doc__, |
| 2341 | "setpgrp($module, /)\n" |
| 2342 | "--\n" |
| 2343 | "\n" |
| 2344 | "Make the current process the leader of its process group."); |
| 2345 | |
| 2346 | #define OS_SETPGRP_METHODDEF \ |
| 2347 | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
| 2348 | |
| 2349 | static PyObject * |
| 2350 | os_setpgrp_impl(PyModuleDef *module); |
| 2351 | |
| 2352 | static PyObject * |
| 2353 | os_setpgrp(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2354 | { |
| 2355 | return os_setpgrp_impl(module); |
| 2356 | } |
| 2357 | |
| 2358 | #endif /* defined(HAVE_SETPGRP) */ |
| 2359 | |
| 2360 | #if defined(HAVE_GETPPID) |
| 2361 | |
| 2362 | PyDoc_STRVAR(os_getppid__doc__, |
| 2363 | "getppid($module, /)\n" |
| 2364 | "--\n" |
| 2365 | "\n" |
| 2366 | "Return the parent\'s process id.\n" |
| 2367 | "\n" |
| 2368 | "If the parent process has already exited, Windows machines will still\n" |
| 2369 | "return its id; others systems will return the id of the \'init\' process (1)."); |
| 2370 | |
| 2371 | #define OS_GETPPID_METHODDEF \ |
| 2372 | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
| 2373 | |
| 2374 | static PyObject * |
| 2375 | os_getppid_impl(PyModuleDef *module); |
| 2376 | |
| 2377 | static PyObject * |
| 2378 | os_getppid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2379 | { |
| 2380 | return os_getppid_impl(module); |
| 2381 | } |
| 2382 | |
| 2383 | #endif /* defined(HAVE_GETPPID) */ |
| 2384 | |
| 2385 | #if defined(HAVE_GETLOGIN) |
| 2386 | |
| 2387 | PyDoc_STRVAR(os_getlogin__doc__, |
| 2388 | "getlogin($module, /)\n" |
| 2389 | "--\n" |
| 2390 | "\n" |
| 2391 | "Return the actual login name."); |
| 2392 | |
| 2393 | #define OS_GETLOGIN_METHODDEF \ |
| 2394 | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
| 2395 | |
| 2396 | static PyObject * |
| 2397 | os_getlogin_impl(PyModuleDef *module); |
| 2398 | |
| 2399 | static PyObject * |
| 2400 | os_getlogin(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2401 | { |
| 2402 | return os_getlogin_impl(module); |
| 2403 | } |
| 2404 | |
| 2405 | #endif /* defined(HAVE_GETLOGIN) */ |
| 2406 | |
| 2407 | #if defined(HAVE_GETUID) |
| 2408 | |
| 2409 | PyDoc_STRVAR(os_getuid__doc__, |
| 2410 | "getuid($module, /)\n" |
| 2411 | "--\n" |
| 2412 | "\n" |
| 2413 | "Return the current process\'s user id."); |
| 2414 | |
| 2415 | #define OS_GETUID_METHODDEF \ |
| 2416 | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
| 2417 | |
| 2418 | static PyObject * |
| 2419 | os_getuid_impl(PyModuleDef *module); |
| 2420 | |
| 2421 | static PyObject * |
| 2422 | os_getuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2423 | { |
| 2424 | return os_getuid_impl(module); |
| 2425 | } |
| 2426 | |
| 2427 | #endif /* defined(HAVE_GETUID) */ |
| 2428 | |
| 2429 | #if defined(HAVE_KILL) |
| 2430 | |
| 2431 | PyDoc_STRVAR(os_kill__doc__, |
| 2432 | "kill($module, pid, signal, /)\n" |
| 2433 | "--\n" |
| 2434 | "\n" |
| 2435 | "Kill a process with a signal."); |
| 2436 | |
| 2437 | #define OS_KILL_METHODDEF \ |
| 2438 | {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__}, |
| 2439 | |
| 2440 | static PyObject * |
| 2441 | os_kill_impl(PyModuleDef *module, pid_t pid, Py_ssize_t signal); |
| 2442 | |
| 2443 | static PyObject * |
| 2444 | os_kill(PyModuleDef *module, PyObject *args) |
| 2445 | { |
| 2446 | PyObject *return_value = NULL; |
| 2447 | pid_t pid; |
| 2448 | Py_ssize_t signal; |
| 2449 | |
| 2450 | if (!PyArg_ParseTuple(args, |
| 2451 | "" _Py_PARSE_PID "n:kill", |
| 2452 | &pid, &signal)) |
| 2453 | goto exit; |
| 2454 | return_value = os_kill_impl(module, pid, signal); |
| 2455 | |
| 2456 | exit: |
| 2457 | return return_value; |
| 2458 | } |
| 2459 | |
| 2460 | #endif /* defined(HAVE_KILL) */ |
| 2461 | |
| 2462 | #if defined(HAVE_KILLPG) |
| 2463 | |
| 2464 | PyDoc_STRVAR(os_killpg__doc__, |
| 2465 | "killpg($module, pgid, signal, /)\n" |
| 2466 | "--\n" |
| 2467 | "\n" |
| 2468 | "Kill a process group with a signal."); |
| 2469 | |
| 2470 | #define OS_KILLPG_METHODDEF \ |
| 2471 | {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__}, |
| 2472 | |
| 2473 | static PyObject * |
| 2474 | os_killpg_impl(PyModuleDef *module, pid_t pgid, int signal); |
| 2475 | |
| 2476 | static PyObject * |
| 2477 | os_killpg(PyModuleDef *module, PyObject *args) |
| 2478 | { |
| 2479 | PyObject *return_value = NULL; |
| 2480 | pid_t pgid; |
| 2481 | int signal; |
| 2482 | |
| 2483 | if (!PyArg_ParseTuple(args, |
| 2484 | "" _Py_PARSE_PID "i:killpg", |
| 2485 | &pgid, &signal)) |
| 2486 | goto exit; |
| 2487 | return_value = os_killpg_impl(module, pgid, signal); |
| 2488 | |
| 2489 | exit: |
| 2490 | return return_value; |
| 2491 | } |
| 2492 | |
| 2493 | #endif /* defined(HAVE_KILLPG) */ |
| 2494 | |
| 2495 | #if defined(HAVE_PLOCK) |
| 2496 | |
| 2497 | PyDoc_STRVAR(os_plock__doc__, |
| 2498 | "plock($module, op, /)\n" |
| 2499 | "--\n" |
| 2500 | "\n" |
| 2501 | "Lock program segments into memory.\");"); |
| 2502 | |
| 2503 | #define OS_PLOCK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2504 | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2505 | |
| 2506 | static PyObject * |
| 2507 | os_plock_impl(PyModuleDef *module, int op); |
| 2508 | |
| 2509 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2510 | os_plock(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2511 | { |
| 2512 | PyObject *return_value = NULL; |
| 2513 | int op; |
| 2514 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2515 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2516 | "i:plock", |
| 2517 | &op)) |
| 2518 | goto exit; |
| 2519 | return_value = os_plock_impl(module, op); |
| 2520 | |
| 2521 | exit: |
| 2522 | return return_value; |
| 2523 | } |
| 2524 | |
| 2525 | #endif /* defined(HAVE_PLOCK) */ |
| 2526 | |
| 2527 | #if defined(HAVE_SETUID) |
| 2528 | |
| 2529 | PyDoc_STRVAR(os_setuid__doc__, |
| 2530 | "setuid($module, uid, /)\n" |
| 2531 | "--\n" |
| 2532 | "\n" |
| 2533 | "Set the current process\'s user id."); |
| 2534 | |
| 2535 | #define OS_SETUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2536 | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2537 | |
| 2538 | static PyObject * |
| 2539 | os_setuid_impl(PyModuleDef *module, uid_t uid); |
| 2540 | |
| 2541 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2542 | os_setuid(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2543 | { |
| 2544 | PyObject *return_value = NULL; |
| 2545 | uid_t uid; |
| 2546 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2547 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2548 | "O&:setuid", |
| 2549 | _Py_Uid_Converter, &uid)) |
| 2550 | goto exit; |
| 2551 | return_value = os_setuid_impl(module, uid); |
| 2552 | |
| 2553 | exit: |
| 2554 | return return_value; |
| 2555 | } |
| 2556 | |
| 2557 | #endif /* defined(HAVE_SETUID) */ |
| 2558 | |
| 2559 | #if defined(HAVE_SETEUID) |
| 2560 | |
| 2561 | PyDoc_STRVAR(os_seteuid__doc__, |
| 2562 | "seteuid($module, euid, /)\n" |
| 2563 | "--\n" |
| 2564 | "\n" |
| 2565 | "Set the current process\'s effective user id."); |
| 2566 | |
| 2567 | #define OS_SETEUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2568 | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2569 | |
| 2570 | static PyObject * |
| 2571 | os_seteuid_impl(PyModuleDef *module, uid_t euid); |
| 2572 | |
| 2573 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2574 | os_seteuid(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2575 | { |
| 2576 | PyObject *return_value = NULL; |
| 2577 | uid_t euid; |
| 2578 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2579 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2580 | "O&:seteuid", |
| 2581 | _Py_Uid_Converter, &euid)) |
| 2582 | goto exit; |
| 2583 | return_value = os_seteuid_impl(module, euid); |
| 2584 | |
| 2585 | exit: |
| 2586 | return return_value; |
| 2587 | } |
| 2588 | |
| 2589 | #endif /* defined(HAVE_SETEUID) */ |
| 2590 | |
| 2591 | #if defined(HAVE_SETEGID) |
| 2592 | |
| 2593 | PyDoc_STRVAR(os_setegid__doc__, |
| 2594 | "setegid($module, egid, /)\n" |
| 2595 | "--\n" |
| 2596 | "\n" |
| 2597 | "Set the current process\'s effective group id."); |
| 2598 | |
| 2599 | #define OS_SETEGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2600 | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2601 | |
| 2602 | static PyObject * |
| 2603 | os_setegid_impl(PyModuleDef *module, gid_t egid); |
| 2604 | |
| 2605 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2606 | os_setegid(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2607 | { |
| 2608 | PyObject *return_value = NULL; |
| 2609 | gid_t egid; |
| 2610 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2611 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2612 | "O&:setegid", |
| 2613 | _Py_Gid_Converter, &egid)) |
| 2614 | goto exit; |
| 2615 | return_value = os_setegid_impl(module, egid); |
| 2616 | |
| 2617 | exit: |
| 2618 | return return_value; |
| 2619 | } |
| 2620 | |
| 2621 | #endif /* defined(HAVE_SETEGID) */ |
| 2622 | |
| 2623 | #if defined(HAVE_SETREUID) |
| 2624 | |
| 2625 | PyDoc_STRVAR(os_setreuid__doc__, |
| 2626 | "setreuid($module, ruid, euid, /)\n" |
| 2627 | "--\n" |
| 2628 | "\n" |
| 2629 | "Set the current process\'s real and effective user ids."); |
| 2630 | |
| 2631 | #define OS_SETREUID_METHODDEF \ |
| 2632 | {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__}, |
| 2633 | |
| 2634 | static PyObject * |
| 2635 | os_setreuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid); |
| 2636 | |
| 2637 | static PyObject * |
| 2638 | os_setreuid(PyModuleDef *module, PyObject *args) |
| 2639 | { |
| 2640 | PyObject *return_value = NULL; |
| 2641 | uid_t ruid; |
| 2642 | uid_t euid; |
| 2643 | |
| 2644 | if (!PyArg_ParseTuple(args, |
| 2645 | "O&O&:setreuid", |
| 2646 | _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) |
| 2647 | goto exit; |
| 2648 | return_value = os_setreuid_impl(module, ruid, euid); |
| 2649 | |
| 2650 | exit: |
| 2651 | return return_value; |
| 2652 | } |
| 2653 | |
| 2654 | #endif /* defined(HAVE_SETREUID) */ |
| 2655 | |
| 2656 | #if defined(HAVE_SETREGID) |
| 2657 | |
| 2658 | PyDoc_STRVAR(os_setregid__doc__, |
| 2659 | "setregid($module, rgid, egid, /)\n" |
| 2660 | "--\n" |
| 2661 | "\n" |
| 2662 | "Set the current process\'s real and effective group ids."); |
| 2663 | |
| 2664 | #define OS_SETREGID_METHODDEF \ |
| 2665 | {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__}, |
| 2666 | |
| 2667 | static PyObject * |
| 2668 | os_setregid_impl(PyModuleDef *module, gid_t rgid, gid_t egid); |
| 2669 | |
| 2670 | static PyObject * |
| 2671 | os_setregid(PyModuleDef *module, PyObject *args) |
| 2672 | { |
| 2673 | PyObject *return_value = NULL; |
| 2674 | gid_t rgid; |
| 2675 | gid_t egid; |
| 2676 | |
| 2677 | if (!PyArg_ParseTuple(args, |
| 2678 | "O&O&:setregid", |
| 2679 | _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) |
| 2680 | goto exit; |
| 2681 | return_value = os_setregid_impl(module, rgid, egid); |
| 2682 | |
| 2683 | exit: |
| 2684 | return return_value; |
| 2685 | } |
| 2686 | |
| 2687 | #endif /* defined(HAVE_SETREGID) */ |
| 2688 | |
| 2689 | #if defined(HAVE_SETGID) |
| 2690 | |
| 2691 | PyDoc_STRVAR(os_setgid__doc__, |
| 2692 | "setgid($module, gid, /)\n" |
| 2693 | "--\n" |
| 2694 | "\n" |
| 2695 | "Set the current process\'s group id."); |
| 2696 | |
| 2697 | #define OS_SETGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2698 | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2699 | |
| 2700 | static PyObject * |
| 2701 | os_setgid_impl(PyModuleDef *module, gid_t gid); |
| 2702 | |
| 2703 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2704 | os_setgid(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2705 | { |
| 2706 | PyObject *return_value = NULL; |
| 2707 | gid_t gid; |
| 2708 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 2709 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2710 | "O&:setgid", |
| 2711 | _Py_Gid_Converter, &gid)) |
| 2712 | goto exit; |
| 2713 | return_value = os_setgid_impl(module, gid); |
| 2714 | |
| 2715 | exit: |
| 2716 | return return_value; |
| 2717 | } |
| 2718 | |
| 2719 | #endif /* defined(HAVE_SETGID) */ |
| 2720 | |
| 2721 | #if defined(HAVE_SETGROUPS) |
| 2722 | |
| 2723 | PyDoc_STRVAR(os_setgroups__doc__, |
| 2724 | "setgroups($module, groups, /)\n" |
| 2725 | "--\n" |
| 2726 | "\n" |
| 2727 | "Set the groups of the current process to list."); |
| 2728 | |
| 2729 | #define OS_SETGROUPS_METHODDEF \ |
| 2730 | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
| 2731 | |
| 2732 | #endif /* defined(HAVE_SETGROUPS) */ |
| 2733 | |
| 2734 | #if defined(HAVE_WAIT3) |
| 2735 | |
| 2736 | PyDoc_STRVAR(os_wait3__doc__, |
| 2737 | "wait3($module, /, options)\n" |
| 2738 | "--\n" |
| 2739 | "\n" |
| 2740 | "Wait for completion of a child process.\n" |
| 2741 | "\n" |
| 2742 | "Returns a tuple of information about the child process:\n" |
| 2743 | " (pid, status, rusage)"); |
| 2744 | |
| 2745 | #define OS_WAIT3_METHODDEF \ |
| 2746 | {"wait3", (PyCFunction)os_wait3, METH_VARARGS|METH_KEYWORDS, os_wait3__doc__}, |
| 2747 | |
| 2748 | static PyObject * |
| 2749 | os_wait3_impl(PyModuleDef *module, int options); |
| 2750 | |
| 2751 | static PyObject * |
| 2752 | os_wait3(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 2753 | { |
| 2754 | PyObject *return_value = NULL; |
| 2755 | static char *_keywords[] = {"options", NULL}; |
| 2756 | int options; |
| 2757 | |
| 2758 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 2759 | "i:wait3", _keywords, |
| 2760 | &options)) |
| 2761 | goto exit; |
| 2762 | return_value = os_wait3_impl(module, options); |
| 2763 | |
| 2764 | exit: |
| 2765 | return return_value; |
| 2766 | } |
| 2767 | |
| 2768 | #endif /* defined(HAVE_WAIT3) */ |
| 2769 | |
| 2770 | #if defined(HAVE_WAIT4) |
| 2771 | |
| 2772 | PyDoc_STRVAR(os_wait4__doc__, |
| 2773 | "wait4($module, /, pid, options)\n" |
| 2774 | "--\n" |
| 2775 | "\n" |
| 2776 | "Wait for completion of a specific child process.\n" |
| 2777 | "\n" |
| 2778 | "Returns a tuple of information about the child process:\n" |
| 2779 | " (pid, status, rusage)"); |
| 2780 | |
| 2781 | #define OS_WAIT4_METHODDEF \ |
| 2782 | {"wait4", (PyCFunction)os_wait4, METH_VARARGS|METH_KEYWORDS, os_wait4__doc__}, |
| 2783 | |
| 2784 | static PyObject * |
| 2785 | os_wait4_impl(PyModuleDef *module, pid_t pid, int options); |
| 2786 | |
| 2787 | static PyObject * |
| 2788 | os_wait4(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 2789 | { |
| 2790 | PyObject *return_value = NULL; |
| 2791 | static char *_keywords[] = {"pid", "options", NULL}; |
| 2792 | pid_t pid; |
| 2793 | int options; |
| 2794 | |
| 2795 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 2796 | "" _Py_PARSE_PID "i:wait4", _keywords, |
| 2797 | &pid, &options)) |
| 2798 | goto exit; |
| 2799 | return_value = os_wait4_impl(module, pid, options); |
| 2800 | |
| 2801 | exit: |
| 2802 | return return_value; |
| 2803 | } |
| 2804 | |
| 2805 | #endif /* defined(HAVE_WAIT4) */ |
| 2806 | |
| 2807 | #if (defined(HAVE_WAITID) && !defined(__APPLE__)) |
| 2808 | |
| 2809 | PyDoc_STRVAR(os_waitid__doc__, |
| 2810 | "waitid($module, idtype, id, options, /)\n" |
| 2811 | "--\n" |
| 2812 | "\n" |
| 2813 | "Returns the result of waiting for a process or processes.\n" |
| 2814 | "\n" |
| 2815 | " idtype\n" |
| 2816 | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
| 2817 | " id\n" |
| 2818 | " The id to wait on.\n" |
| 2819 | " options\n" |
| 2820 | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
| 2821 | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
| 2822 | "\n" |
| 2823 | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
| 2824 | "no children in a waitable state."); |
| 2825 | |
| 2826 | #define OS_WAITID_METHODDEF \ |
| 2827 | {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__}, |
| 2828 | |
| 2829 | static PyObject * |
| 2830 | os_waitid_impl(PyModuleDef *module, idtype_t idtype, id_t id, int options); |
| 2831 | |
| 2832 | static PyObject * |
| 2833 | os_waitid(PyModuleDef *module, PyObject *args) |
| 2834 | { |
| 2835 | PyObject *return_value = NULL; |
| 2836 | idtype_t idtype; |
| 2837 | id_t id; |
| 2838 | int options; |
| 2839 | |
| 2840 | if (!PyArg_ParseTuple(args, |
| 2841 | "i" _Py_PARSE_PID "i:waitid", |
| 2842 | &idtype, &id, &options)) |
| 2843 | goto exit; |
| 2844 | return_value = os_waitid_impl(module, idtype, id, options); |
| 2845 | |
| 2846 | exit: |
| 2847 | return return_value; |
| 2848 | } |
| 2849 | |
| 2850 | #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */ |
| 2851 | |
| 2852 | #if defined(HAVE_WAITPID) |
| 2853 | |
| 2854 | PyDoc_STRVAR(os_waitpid__doc__, |
| 2855 | "waitpid($module, pid, options, /)\n" |
| 2856 | "--\n" |
| 2857 | "\n" |
| 2858 | "Wait for completion of a given child process.\n" |
| 2859 | "\n" |
| 2860 | "Returns a tuple of information regarding the child process:\n" |
| 2861 | " (pid, status)\n" |
| 2862 | "\n" |
| 2863 | "The options argument is ignored on Windows."); |
| 2864 | |
| 2865 | #define OS_WAITPID_METHODDEF \ |
| 2866 | {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__}, |
| 2867 | |
| 2868 | static PyObject * |
| 2869 | os_waitpid_impl(PyModuleDef *module, pid_t pid, int options); |
| 2870 | |
| 2871 | static PyObject * |
| 2872 | os_waitpid(PyModuleDef *module, PyObject *args) |
| 2873 | { |
| 2874 | PyObject *return_value = NULL; |
| 2875 | pid_t pid; |
| 2876 | int options; |
| 2877 | |
| 2878 | if (!PyArg_ParseTuple(args, |
| 2879 | "" _Py_PARSE_PID "i:waitpid", |
| 2880 | &pid, &options)) |
| 2881 | goto exit; |
| 2882 | return_value = os_waitpid_impl(module, pid, options); |
| 2883 | |
| 2884 | exit: |
| 2885 | return return_value; |
| 2886 | } |
| 2887 | |
| 2888 | #endif /* defined(HAVE_WAITPID) */ |
| 2889 | |
| 2890 | #if defined(HAVE_CWAIT) |
| 2891 | |
| 2892 | PyDoc_STRVAR(os_waitpid__doc__, |
| 2893 | "waitpid($module, pid, options, /)\n" |
| 2894 | "--\n" |
| 2895 | "\n" |
| 2896 | "Wait for completion of a given process.\n" |
| 2897 | "\n" |
| 2898 | "Returns a tuple of information regarding the process:\n" |
| 2899 | " (pid, status << 8)\n" |
| 2900 | "\n" |
| 2901 | "The options argument is ignored on Windows."); |
| 2902 | |
| 2903 | #define OS_WAITPID_METHODDEF \ |
| 2904 | {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__}, |
| 2905 | |
| 2906 | static PyObject * |
| 2907 | os_waitpid_impl(PyModuleDef *module, Py_intptr_t pid, int options); |
| 2908 | |
| 2909 | static PyObject * |
| 2910 | os_waitpid(PyModuleDef *module, PyObject *args) |
| 2911 | { |
| 2912 | PyObject *return_value = NULL; |
| 2913 | Py_intptr_t pid; |
| 2914 | int options; |
| 2915 | |
| 2916 | if (!PyArg_ParseTuple(args, |
| 2917 | "" _Py_PARSE_INTPTR "i:waitpid", |
| 2918 | &pid, &options)) |
| 2919 | goto exit; |
| 2920 | return_value = os_waitpid_impl(module, pid, options); |
| 2921 | |
| 2922 | exit: |
| 2923 | return return_value; |
| 2924 | } |
| 2925 | |
| 2926 | #endif /* defined(HAVE_CWAIT) */ |
| 2927 | |
| 2928 | #if defined(HAVE_WAIT) |
| 2929 | |
| 2930 | PyDoc_STRVAR(os_wait__doc__, |
| 2931 | "wait($module, /)\n" |
| 2932 | "--\n" |
| 2933 | "\n" |
| 2934 | "Wait for completion of a child process.\n" |
| 2935 | "\n" |
| 2936 | "Returns a tuple of information about the child process:\n" |
| 2937 | " (pid, status)"); |
| 2938 | |
| 2939 | #define OS_WAIT_METHODDEF \ |
| 2940 | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
| 2941 | |
| 2942 | static PyObject * |
| 2943 | os_wait_impl(PyModuleDef *module); |
| 2944 | |
| 2945 | static PyObject * |
| 2946 | os_wait(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 2947 | { |
| 2948 | return os_wait_impl(module); |
| 2949 | } |
| 2950 | |
| 2951 | #endif /* defined(HAVE_WAIT) */ |
| 2952 | |
| 2953 | #if defined(HAVE_SYMLINK) |
| 2954 | |
| 2955 | PyDoc_STRVAR(os_symlink__doc__, |
| 2956 | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
| 2957 | "--\n" |
| 2958 | "\n" |
| 2959 | "Create a symbolic link pointing to src named dst.\n" |
| 2960 | "\n" |
| 2961 | "target_is_directory is required on Windows if the target is to be\n" |
| 2962 | " interpreted as a directory. (On Windows, symlink requires\n" |
| 2963 | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
| 2964 | " target_is_directory is ignored on non-Windows platforms.\n" |
| 2965 | "\n" |
| 2966 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 2967 | " and path should be relative; path will then be relative to that directory.\n" |
| 2968 | "dir_fd may not be implemented on your platform.\n" |
| 2969 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 2970 | |
| 2971 | #define OS_SYMLINK_METHODDEF \ |
| 2972 | {"symlink", (PyCFunction)os_symlink, METH_VARARGS|METH_KEYWORDS, os_symlink__doc__}, |
| 2973 | |
| 2974 | static PyObject * |
| 2975 | os_symlink_impl(PyModuleDef *module, path_t *src, path_t *dst, int target_is_directory, int dir_fd); |
| 2976 | |
| 2977 | static PyObject * |
| 2978 | os_symlink(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 2979 | { |
| 2980 | PyObject *return_value = NULL; |
| 2981 | static char *_keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
| 2982 | path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0); |
| 2983 | path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0); |
| 2984 | int target_is_directory = 0; |
| 2985 | int dir_fd = DEFAULT_DIR_FD; |
| 2986 | |
| 2987 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 2988 | "O&O&|p$O&:symlink", _keywords, |
| 2989 | path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) |
| 2990 | goto exit; |
| 2991 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
| 2992 | |
| 2993 | exit: |
| 2994 | /* Cleanup for src */ |
| 2995 | path_cleanup(&src); |
| 2996 | /* Cleanup for dst */ |
| 2997 | path_cleanup(&dst); |
| 2998 | |
| 2999 | return return_value; |
| 3000 | } |
| 3001 | |
| 3002 | #endif /* defined(HAVE_SYMLINK) */ |
| 3003 | |
| 3004 | #if defined(HAVE_TIMES) |
| 3005 | |
| 3006 | PyDoc_STRVAR(os_times__doc__, |
| 3007 | "times($module, /)\n" |
| 3008 | "--\n" |
| 3009 | "\n" |
| 3010 | "Return a collection containing process timing information.\n" |
| 3011 | "\n" |
| 3012 | "The object returned behaves like a named tuple with these fields:\n" |
| 3013 | " (utime, stime, cutime, cstime, elapsed_time)\n" |
| 3014 | "All fields are floating point numbers."); |
| 3015 | |
| 3016 | #define OS_TIMES_METHODDEF \ |
| 3017 | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
| 3018 | |
| 3019 | static PyObject * |
| 3020 | os_times_impl(PyModuleDef *module); |
| 3021 | |
| 3022 | static PyObject * |
| 3023 | os_times(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 3024 | { |
| 3025 | return os_times_impl(module); |
| 3026 | } |
| 3027 | |
| 3028 | #endif /* defined(HAVE_TIMES) */ |
| 3029 | |
| 3030 | #if defined(HAVE_GETSID) |
| 3031 | |
| 3032 | PyDoc_STRVAR(os_getsid__doc__, |
| 3033 | "getsid($module, pid, /)\n" |
| 3034 | "--\n" |
| 3035 | "\n" |
| 3036 | "Call the system call getsid(pid) and return the result."); |
| 3037 | |
| 3038 | #define OS_GETSID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3039 | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3040 | |
| 3041 | static PyObject * |
| 3042 | os_getsid_impl(PyModuleDef *module, pid_t pid); |
| 3043 | |
| 3044 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3045 | os_getsid(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3046 | { |
| 3047 | PyObject *return_value = NULL; |
| 3048 | pid_t pid; |
| 3049 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3050 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3051 | "" _Py_PARSE_PID ":getsid", |
| 3052 | &pid)) |
| 3053 | goto exit; |
| 3054 | return_value = os_getsid_impl(module, pid); |
| 3055 | |
| 3056 | exit: |
| 3057 | return return_value; |
| 3058 | } |
| 3059 | |
| 3060 | #endif /* defined(HAVE_GETSID) */ |
| 3061 | |
| 3062 | #if defined(HAVE_SETSID) |
| 3063 | |
| 3064 | PyDoc_STRVAR(os_setsid__doc__, |
| 3065 | "setsid($module, /)\n" |
| 3066 | "--\n" |
| 3067 | "\n" |
| 3068 | "Call the system call setsid()."); |
| 3069 | |
| 3070 | #define OS_SETSID_METHODDEF \ |
| 3071 | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
| 3072 | |
| 3073 | static PyObject * |
| 3074 | os_setsid_impl(PyModuleDef *module); |
| 3075 | |
| 3076 | static PyObject * |
| 3077 | os_setsid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 3078 | { |
| 3079 | return os_setsid_impl(module); |
| 3080 | } |
| 3081 | |
| 3082 | #endif /* defined(HAVE_SETSID) */ |
| 3083 | |
| 3084 | #if defined(HAVE_SETPGID) |
| 3085 | |
| 3086 | PyDoc_STRVAR(os_setpgid__doc__, |
| 3087 | "setpgid($module, pid, pgrp, /)\n" |
| 3088 | "--\n" |
| 3089 | "\n" |
| 3090 | "Call the system call setpgid(pid, pgrp)."); |
| 3091 | |
| 3092 | #define OS_SETPGID_METHODDEF \ |
| 3093 | {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__}, |
| 3094 | |
| 3095 | static PyObject * |
| 3096 | os_setpgid_impl(PyModuleDef *module, pid_t pid, pid_t pgrp); |
| 3097 | |
| 3098 | static PyObject * |
| 3099 | os_setpgid(PyModuleDef *module, PyObject *args) |
| 3100 | { |
| 3101 | PyObject *return_value = NULL; |
| 3102 | pid_t pid; |
| 3103 | pid_t pgrp; |
| 3104 | |
| 3105 | if (!PyArg_ParseTuple(args, |
| 3106 | "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid", |
| 3107 | &pid, &pgrp)) |
| 3108 | goto exit; |
| 3109 | return_value = os_setpgid_impl(module, pid, pgrp); |
| 3110 | |
| 3111 | exit: |
| 3112 | return return_value; |
| 3113 | } |
| 3114 | |
| 3115 | #endif /* defined(HAVE_SETPGID) */ |
| 3116 | |
| 3117 | #if defined(HAVE_TCGETPGRP) |
| 3118 | |
| 3119 | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
| 3120 | "tcgetpgrp($module, fd, /)\n" |
| 3121 | "--\n" |
| 3122 | "\n" |
| 3123 | "Return the process group associated with the terminal specified by fd."); |
| 3124 | |
| 3125 | #define OS_TCGETPGRP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3126 | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3127 | |
| 3128 | static PyObject * |
| 3129 | os_tcgetpgrp_impl(PyModuleDef *module, int fd); |
| 3130 | |
| 3131 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3132 | os_tcgetpgrp(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3133 | { |
| 3134 | PyObject *return_value = NULL; |
| 3135 | int fd; |
| 3136 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3137 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3138 | "i:tcgetpgrp", |
| 3139 | &fd)) |
| 3140 | goto exit; |
| 3141 | return_value = os_tcgetpgrp_impl(module, fd); |
| 3142 | |
| 3143 | exit: |
| 3144 | return return_value; |
| 3145 | } |
| 3146 | |
| 3147 | #endif /* defined(HAVE_TCGETPGRP) */ |
| 3148 | |
| 3149 | #if defined(HAVE_TCSETPGRP) |
| 3150 | |
| 3151 | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
| 3152 | "tcsetpgrp($module, fd, pgid, /)\n" |
| 3153 | "--\n" |
| 3154 | "\n" |
| 3155 | "Set the process group associated with the terminal specified by fd."); |
| 3156 | |
| 3157 | #define OS_TCSETPGRP_METHODDEF \ |
| 3158 | {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__}, |
| 3159 | |
| 3160 | static PyObject * |
| 3161 | os_tcsetpgrp_impl(PyModuleDef *module, int fd, pid_t pgid); |
| 3162 | |
| 3163 | static PyObject * |
| 3164 | os_tcsetpgrp(PyModuleDef *module, PyObject *args) |
| 3165 | { |
| 3166 | PyObject *return_value = NULL; |
| 3167 | int fd; |
| 3168 | pid_t pgid; |
| 3169 | |
| 3170 | if (!PyArg_ParseTuple(args, |
| 3171 | "i" _Py_PARSE_PID ":tcsetpgrp", |
| 3172 | &fd, &pgid)) |
| 3173 | goto exit; |
| 3174 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
| 3175 | |
| 3176 | exit: |
| 3177 | return return_value; |
| 3178 | } |
| 3179 | |
| 3180 | #endif /* defined(HAVE_TCSETPGRP) */ |
| 3181 | |
| 3182 | PyDoc_STRVAR(os_open__doc__, |
| 3183 | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
| 3184 | "--\n" |
| 3185 | "\n" |
| 3186 | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
| 3187 | "\n" |
| 3188 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3189 | " and path should be relative; path will then be relative to that directory.\n" |
| 3190 | "dir_fd may not be implemented on your platform.\n" |
| 3191 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3192 | |
| 3193 | #define OS_OPEN_METHODDEF \ |
| 3194 | {"open", (PyCFunction)os_open, METH_VARARGS|METH_KEYWORDS, os_open__doc__}, |
| 3195 | |
| 3196 | static int |
| 3197 | os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd); |
| 3198 | |
| 3199 | static PyObject * |
| 3200 | os_open(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 3201 | { |
| 3202 | PyObject *return_value = NULL; |
| 3203 | static char *_keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
| 3204 | path_t path = PATH_T_INITIALIZE("open", "path", 0, 0); |
| 3205 | int flags; |
| 3206 | int mode = 511; |
| 3207 | int dir_fd = DEFAULT_DIR_FD; |
| 3208 | int _return_value; |
| 3209 | |
| 3210 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 3211 | "O&i|i$O&:open", _keywords, |
| 3212 | path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) |
| 3213 | goto exit; |
| 3214 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
| 3215 | if ((_return_value == -1) && PyErr_Occurred()) |
| 3216 | goto exit; |
| 3217 | return_value = PyLong_FromLong((long)_return_value); |
| 3218 | |
| 3219 | exit: |
| 3220 | /* Cleanup for path */ |
| 3221 | path_cleanup(&path); |
| 3222 | |
| 3223 | return return_value; |
| 3224 | } |
| 3225 | |
| 3226 | PyDoc_STRVAR(os_close__doc__, |
| 3227 | "close($module, /, fd)\n" |
| 3228 | "--\n" |
| 3229 | "\n" |
| 3230 | "Close a file descriptor."); |
| 3231 | |
| 3232 | #define OS_CLOSE_METHODDEF \ |
| 3233 | {"close", (PyCFunction)os_close, METH_VARARGS|METH_KEYWORDS, os_close__doc__}, |
| 3234 | |
| 3235 | static PyObject * |
| 3236 | os_close_impl(PyModuleDef *module, int fd); |
| 3237 | |
| 3238 | static PyObject * |
| 3239 | os_close(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 3240 | { |
| 3241 | PyObject *return_value = NULL; |
| 3242 | static char *_keywords[] = {"fd", NULL}; |
| 3243 | int fd; |
| 3244 | |
| 3245 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 3246 | "i:close", _keywords, |
| 3247 | &fd)) |
| 3248 | goto exit; |
| 3249 | return_value = os_close_impl(module, fd); |
| 3250 | |
| 3251 | exit: |
| 3252 | return return_value; |
| 3253 | } |
| 3254 | |
| 3255 | PyDoc_STRVAR(os_closerange__doc__, |
| 3256 | "closerange($module, fd_low, fd_high, /)\n" |
| 3257 | "--\n" |
| 3258 | "\n" |
| 3259 | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
| 3260 | |
| 3261 | #define OS_CLOSERANGE_METHODDEF \ |
| 3262 | {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__}, |
| 3263 | |
| 3264 | static PyObject * |
| 3265 | os_closerange_impl(PyModuleDef *module, int fd_low, int fd_high); |
| 3266 | |
| 3267 | static PyObject * |
| 3268 | os_closerange(PyModuleDef *module, PyObject *args) |
| 3269 | { |
| 3270 | PyObject *return_value = NULL; |
| 3271 | int fd_low; |
| 3272 | int fd_high; |
| 3273 | |
| 3274 | if (!PyArg_ParseTuple(args, |
| 3275 | "ii:closerange", |
| 3276 | &fd_low, &fd_high)) |
| 3277 | goto exit; |
| 3278 | return_value = os_closerange_impl(module, fd_low, fd_high); |
| 3279 | |
| 3280 | exit: |
| 3281 | return return_value; |
| 3282 | } |
| 3283 | |
| 3284 | PyDoc_STRVAR(os_dup__doc__, |
| 3285 | "dup($module, fd, /)\n" |
| 3286 | "--\n" |
| 3287 | "\n" |
| 3288 | "Return a duplicate of a file descriptor."); |
| 3289 | |
| 3290 | #define OS_DUP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3291 | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3292 | |
| 3293 | static int |
| 3294 | os_dup_impl(PyModuleDef *module, int fd); |
| 3295 | |
| 3296 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3297 | os_dup(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3298 | { |
| 3299 | PyObject *return_value = NULL; |
| 3300 | int fd; |
| 3301 | int _return_value; |
| 3302 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3303 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3304 | "i:dup", |
| 3305 | &fd)) |
| 3306 | goto exit; |
| 3307 | _return_value = os_dup_impl(module, fd); |
| 3308 | if ((_return_value == -1) && PyErr_Occurred()) |
| 3309 | goto exit; |
| 3310 | return_value = PyLong_FromLong((long)_return_value); |
| 3311 | |
| 3312 | exit: |
| 3313 | return return_value; |
| 3314 | } |
| 3315 | |
| 3316 | PyDoc_STRVAR(os_dup2__doc__, |
| 3317 | "dup2($module, /, fd, fd2, inheritable=True)\n" |
| 3318 | "--\n" |
| 3319 | "\n" |
| 3320 | "Duplicate file descriptor."); |
| 3321 | |
| 3322 | #define OS_DUP2_METHODDEF \ |
| 3323 | {"dup2", (PyCFunction)os_dup2, METH_VARARGS|METH_KEYWORDS, os_dup2__doc__}, |
| 3324 | |
| 3325 | static PyObject * |
| 3326 | os_dup2_impl(PyModuleDef *module, int fd, int fd2, int inheritable); |
| 3327 | |
| 3328 | static PyObject * |
| 3329 | os_dup2(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 3330 | { |
| 3331 | PyObject *return_value = NULL; |
| 3332 | static char *_keywords[] = {"fd", "fd2", "inheritable", NULL}; |
| 3333 | int fd; |
| 3334 | int fd2; |
| 3335 | int inheritable = 1; |
| 3336 | |
| 3337 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 3338 | "ii|p:dup2", _keywords, |
| 3339 | &fd, &fd2, &inheritable)) |
| 3340 | goto exit; |
| 3341 | return_value = os_dup2_impl(module, fd, fd2, inheritable); |
| 3342 | |
| 3343 | exit: |
| 3344 | return return_value; |
| 3345 | } |
| 3346 | |
| 3347 | #if defined(HAVE_LOCKF) |
| 3348 | |
| 3349 | PyDoc_STRVAR(os_lockf__doc__, |
| 3350 | "lockf($module, fd, command, length, /)\n" |
| 3351 | "--\n" |
| 3352 | "\n" |
| 3353 | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
| 3354 | "\n" |
| 3355 | " fd\n" |
| 3356 | " An open file descriptor.\n" |
| 3357 | " command\n" |
| 3358 | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
| 3359 | " length\n" |
| 3360 | " The number of bytes to lock, starting at the current position."); |
| 3361 | |
| 3362 | #define OS_LOCKF_METHODDEF \ |
| 3363 | {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__}, |
| 3364 | |
| 3365 | static PyObject * |
| 3366 | os_lockf_impl(PyModuleDef *module, int fd, int command, Py_off_t length); |
| 3367 | |
| 3368 | static PyObject * |
| 3369 | os_lockf(PyModuleDef *module, PyObject *args) |
| 3370 | { |
| 3371 | PyObject *return_value = NULL; |
| 3372 | int fd; |
| 3373 | int command; |
| 3374 | Py_off_t length; |
| 3375 | |
| 3376 | if (!PyArg_ParseTuple(args, |
| 3377 | "iiO&:lockf", |
| 3378 | &fd, &command, Py_off_t_converter, &length)) |
| 3379 | goto exit; |
| 3380 | return_value = os_lockf_impl(module, fd, command, length); |
| 3381 | |
| 3382 | exit: |
| 3383 | return return_value; |
| 3384 | } |
| 3385 | |
| 3386 | #endif /* defined(HAVE_LOCKF) */ |
| 3387 | |
| 3388 | PyDoc_STRVAR(os_lseek__doc__, |
| 3389 | "lseek($module, fd, position, how, /)\n" |
| 3390 | "--\n" |
| 3391 | "\n" |
| 3392 | "Set the position of a file descriptor. Return the new position.\n" |
| 3393 | "\n" |
| 3394 | "Return the new cursor position in number of bytes\n" |
| 3395 | "relative to the beginning of the file."); |
| 3396 | |
| 3397 | #define OS_LSEEK_METHODDEF \ |
| 3398 | {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__}, |
| 3399 | |
| 3400 | static Py_off_t |
| 3401 | os_lseek_impl(PyModuleDef *module, int fd, Py_off_t position, int how); |
| 3402 | |
| 3403 | static PyObject * |
| 3404 | os_lseek(PyModuleDef *module, PyObject *args) |
| 3405 | { |
| 3406 | PyObject *return_value = NULL; |
| 3407 | int fd; |
| 3408 | Py_off_t position; |
| 3409 | int how; |
| 3410 | Py_off_t _return_value; |
| 3411 | |
| 3412 | if (!PyArg_ParseTuple(args, |
| 3413 | "iO&i:lseek", |
| 3414 | &fd, Py_off_t_converter, &position, &how)) |
| 3415 | goto exit; |
| 3416 | _return_value = os_lseek_impl(module, fd, position, how); |
| 3417 | if ((_return_value == -1) && PyErr_Occurred()) |
| 3418 | goto exit; |
| 3419 | return_value = PyLong_FromPy_off_t(_return_value); |
| 3420 | |
| 3421 | exit: |
| 3422 | return return_value; |
| 3423 | } |
| 3424 | |
| 3425 | PyDoc_STRVAR(os_read__doc__, |
| 3426 | "read($module, fd, length, /)\n" |
| 3427 | "--\n" |
| 3428 | "\n" |
| 3429 | "Read from a file descriptor. Returns a bytes object."); |
| 3430 | |
| 3431 | #define OS_READ_METHODDEF \ |
| 3432 | {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__}, |
| 3433 | |
| 3434 | static PyObject * |
| 3435 | os_read_impl(PyModuleDef *module, int fd, Py_ssize_t length); |
| 3436 | |
| 3437 | static PyObject * |
| 3438 | os_read(PyModuleDef *module, PyObject *args) |
| 3439 | { |
| 3440 | PyObject *return_value = NULL; |
| 3441 | int fd; |
| 3442 | Py_ssize_t length; |
| 3443 | |
| 3444 | if (!PyArg_ParseTuple(args, |
| 3445 | "in:read", |
| 3446 | &fd, &length)) |
| 3447 | goto exit; |
| 3448 | return_value = os_read_impl(module, fd, length); |
| 3449 | |
| 3450 | exit: |
| 3451 | return return_value; |
| 3452 | } |
| 3453 | |
| 3454 | #if defined(HAVE_READV) |
| 3455 | |
| 3456 | PyDoc_STRVAR(os_readv__doc__, |
| 3457 | "readv($module, fd, buffers, /)\n" |
| 3458 | "--\n" |
| 3459 | "\n" |
| 3460 | "Read from a file descriptor fd into an iterable of buffers.\n" |
| 3461 | "\n" |
| 3462 | "The buffers should be mutable buffers accepting bytes.\n" |
| 3463 | "readv will transfer data into each buffer until it is full\n" |
| 3464 | "and then move on to the next buffer in the sequence to hold\n" |
| 3465 | "the rest of the data.\n" |
| 3466 | "\n" |
| 3467 | "readv returns the total number of bytes read,\n" |
| 3468 | "which may be less than the total capacity of all the buffers."); |
| 3469 | |
| 3470 | #define OS_READV_METHODDEF \ |
| 3471 | {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__}, |
| 3472 | |
| 3473 | static Py_ssize_t |
| 3474 | os_readv_impl(PyModuleDef *module, int fd, PyObject *buffers); |
| 3475 | |
| 3476 | static PyObject * |
| 3477 | os_readv(PyModuleDef *module, PyObject *args) |
| 3478 | { |
| 3479 | PyObject *return_value = NULL; |
| 3480 | int fd; |
| 3481 | PyObject *buffers; |
| 3482 | Py_ssize_t _return_value; |
| 3483 | |
| 3484 | if (!PyArg_ParseTuple(args, |
| 3485 | "iO:readv", |
| 3486 | &fd, &buffers)) |
| 3487 | goto exit; |
| 3488 | _return_value = os_readv_impl(module, fd, buffers); |
| 3489 | if ((_return_value == -1) && PyErr_Occurred()) |
| 3490 | goto exit; |
| 3491 | return_value = PyLong_FromSsize_t(_return_value); |
| 3492 | |
| 3493 | exit: |
| 3494 | return return_value; |
| 3495 | } |
| 3496 | |
| 3497 | #endif /* defined(HAVE_READV) */ |
| 3498 | |
| 3499 | #if defined(HAVE_PREAD) |
| 3500 | |
| 3501 | PyDoc_STRVAR(os_pread__doc__, |
| 3502 | "pread($module, fd, length, offset, /)\n" |
| 3503 | "--\n" |
| 3504 | "\n" |
| 3505 | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
| 3506 | "\n" |
| 3507 | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
| 3508 | "the beginning of the file. The file offset remains unchanged."); |
| 3509 | |
| 3510 | #define OS_PREAD_METHODDEF \ |
| 3511 | {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__}, |
| 3512 | |
| 3513 | static PyObject * |
| 3514 | os_pread_impl(PyModuleDef *module, int fd, int length, Py_off_t offset); |
| 3515 | |
| 3516 | static PyObject * |
| 3517 | os_pread(PyModuleDef *module, PyObject *args) |
| 3518 | { |
| 3519 | PyObject *return_value = NULL; |
| 3520 | int fd; |
| 3521 | int length; |
| 3522 | Py_off_t offset; |
| 3523 | |
| 3524 | if (!PyArg_ParseTuple(args, |
| 3525 | "iiO&:pread", |
| 3526 | &fd, &length, Py_off_t_converter, &offset)) |
| 3527 | goto exit; |
| 3528 | return_value = os_pread_impl(module, fd, length, offset); |
| 3529 | |
| 3530 | exit: |
| 3531 | return return_value; |
| 3532 | } |
| 3533 | |
| 3534 | #endif /* defined(HAVE_PREAD) */ |
| 3535 | |
| 3536 | PyDoc_STRVAR(os_write__doc__, |
| 3537 | "write($module, fd, data, /)\n" |
| 3538 | "--\n" |
| 3539 | "\n" |
| 3540 | "Write a bytes object to a file descriptor."); |
| 3541 | |
| 3542 | #define OS_WRITE_METHODDEF \ |
| 3543 | {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__}, |
| 3544 | |
| 3545 | static Py_ssize_t |
| 3546 | os_write_impl(PyModuleDef *module, int fd, Py_buffer *data); |
| 3547 | |
| 3548 | static PyObject * |
| 3549 | os_write(PyModuleDef *module, PyObject *args) |
| 3550 | { |
| 3551 | PyObject *return_value = NULL; |
| 3552 | int fd; |
| 3553 | Py_buffer data = {NULL, NULL}; |
| 3554 | Py_ssize_t _return_value; |
| 3555 | |
| 3556 | if (!PyArg_ParseTuple(args, |
| 3557 | "iy*:write", |
| 3558 | &fd, &data)) |
| 3559 | goto exit; |
| 3560 | _return_value = os_write_impl(module, fd, &data); |
| 3561 | if ((_return_value == -1) && PyErr_Occurred()) |
| 3562 | goto exit; |
| 3563 | return_value = PyLong_FromSsize_t(_return_value); |
| 3564 | |
| 3565 | exit: |
| 3566 | /* Cleanup for data */ |
| 3567 | if (data.obj) |
| 3568 | PyBuffer_Release(&data); |
| 3569 | |
| 3570 | return return_value; |
| 3571 | } |
| 3572 | |
| 3573 | PyDoc_STRVAR(os_fstat__doc__, |
| 3574 | "fstat($module, /, fd)\n" |
| 3575 | "--\n" |
| 3576 | "\n" |
| 3577 | "Perform a stat system call on the given file descriptor.\n" |
| 3578 | "\n" |
| 3579 | "Like stat(), but for an open file descriptor.\n" |
| 3580 | "Equivalent to os.stat(fd)."); |
| 3581 | |
| 3582 | #define OS_FSTAT_METHODDEF \ |
| 3583 | {"fstat", (PyCFunction)os_fstat, METH_VARARGS|METH_KEYWORDS, os_fstat__doc__}, |
| 3584 | |
| 3585 | static PyObject * |
| 3586 | os_fstat_impl(PyModuleDef *module, int fd); |
| 3587 | |
| 3588 | static PyObject * |
| 3589 | os_fstat(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 3590 | { |
| 3591 | PyObject *return_value = NULL; |
| 3592 | static char *_keywords[] = {"fd", NULL}; |
| 3593 | int fd; |
| 3594 | |
| 3595 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 3596 | "i:fstat", _keywords, |
| 3597 | &fd)) |
| 3598 | goto exit; |
| 3599 | return_value = os_fstat_impl(module, fd); |
| 3600 | |
| 3601 | exit: |
| 3602 | return return_value; |
| 3603 | } |
| 3604 | |
| 3605 | PyDoc_STRVAR(os_isatty__doc__, |
| 3606 | "isatty($module, fd, /)\n" |
| 3607 | "--\n" |
| 3608 | "\n" |
| 3609 | "Return True if the fd is connected to a terminal.\n" |
| 3610 | "\n" |
| 3611 | "Return True if the file descriptor is an open file descriptor\n" |
| 3612 | "connected to the slave end of a terminal."); |
| 3613 | |
| 3614 | #define OS_ISATTY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3615 | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3616 | |
| 3617 | static int |
| 3618 | os_isatty_impl(PyModuleDef *module, int fd); |
| 3619 | |
| 3620 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3621 | os_isatty(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3622 | { |
| 3623 | PyObject *return_value = NULL; |
| 3624 | int fd; |
| 3625 | int _return_value; |
| 3626 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3627 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3628 | "i:isatty", |
| 3629 | &fd)) |
| 3630 | goto exit; |
| 3631 | _return_value = os_isatty_impl(module, fd); |
| 3632 | if ((_return_value == -1) && PyErr_Occurred()) |
| 3633 | goto exit; |
| 3634 | return_value = PyBool_FromLong((long)_return_value); |
| 3635 | |
| 3636 | exit: |
| 3637 | return return_value; |
| 3638 | } |
| 3639 | |
| 3640 | #if defined(HAVE_PIPE) |
| 3641 | |
| 3642 | PyDoc_STRVAR(os_pipe__doc__, |
| 3643 | "pipe($module, /)\n" |
| 3644 | "--\n" |
| 3645 | "\n" |
| 3646 | "Create a pipe.\n" |
| 3647 | "\n" |
| 3648 | "Returns a tuple of two file descriptors:\n" |
| 3649 | " (read_fd, write_fd)"); |
| 3650 | |
| 3651 | #define OS_PIPE_METHODDEF \ |
| 3652 | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
| 3653 | |
| 3654 | static PyObject * |
| 3655 | os_pipe_impl(PyModuleDef *module); |
| 3656 | |
| 3657 | static PyObject * |
| 3658 | os_pipe(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 3659 | { |
| 3660 | return os_pipe_impl(module); |
| 3661 | } |
| 3662 | |
| 3663 | #endif /* defined(HAVE_PIPE) */ |
| 3664 | |
| 3665 | #if defined(HAVE_PIPE2) |
| 3666 | |
| 3667 | PyDoc_STRVAR(os_pipe2__doc__, |
| 3668 | "pipe2($module, flags, /)\n" |
| 3669 | "--\n" |
| 3670 | "\n" |
| 3671 | "Create a pipe with flags set atomically.\n" |
| 3672 | "\n" |
| 3673 | "Returns a tuple of two file descriptors:\n" |
| 3674 | " (read_fd, write_fd)\n" |
| 3675 | "\n" |
| 3676 | "flags can be constructed by ORing together one or more of these values:\n" |
| 3677 | "O_NONBLOCK, O_CLOEXEC."); |
| 3678 | |
| 3679 | #define OS_PIPE2_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3680 | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3681 | |
| 3682 | static PyObject * |
| 3683 | os_pipe2_impl(PyModuleDef *module, int flags); |
| 3684 | |
| 3685 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3686 | os_pipe2(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3687 | { |
| 3688 | PyObject *return_value = NULL; |
| 3689 | int flags; |
| 3690 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3691 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3692 | "i:pipe2", |
| 3693 | &flags)) |
| 3694 | goto exit; |
| 3695 | return_value = os_pipe2_impl(module, flags); |
| 3696 | |
| 3697 | exit: |
| 3698 | return return_value; |
| 3699 | } |
| 3700 | |
| 3701 | #endif /* defined(HAVE_PIPE2) */ |
| 3702 | |
| 3703 | #if defined(HAVE_WRITEV) |
| 3704 | |
| 3705 | PyDoc_STRVAR(os_writev__doc__, |
| 3706 | "writev($module, fd, buffers, /)\n" |
| 3707 | "--\n" |
| 3708 | "\n" |
| 3709 | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
| 3710 | "\n" |
| 3711 | "Returns the total number of bytes written.\n" |
| 3712 | "buffers must be a sequence of bytes-like objects."); |
| 3713 | |
| 3714 | #define OS_WRITEV_METHODDEF \ |
| 3715 | {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__}, |
| 3716 | |
| 3717 | static Py_ssize_t |
| 3718 | os_writev_impl(PyModuleDef *module, int fd, PyObject *buffers); |
| 3719 | |
| 3720 | static PyObject * |
| 3721 | os_writev(PyModuleDef *module, PyObject *args) |
| 3722 | { |
| 3723 | PyObject *return_value = NULL; |
| 3724 | int fd; |
| 3725 | PyObject *buffers; |
| 3726 | Py_ssize_t _return_value; |
| 3727 | |
| 3728 | if (!PyArg_ParseTuple(args, |
| 3729 | "iO:writev", |
| 3730 | &fd, &buffers)) |
| 3731 | goto exit; |
| 3732 | _return_value = os_writev_impl(module, fd, buffers); |
| 3733 | if ((_return_value == -1) && PyErr_Occurred()) |
| 3734 | goto exit; |
| 3735 | return_value = PyLong_FromSsize_t(_return_value); |
| 3736 | |
| 3737 | exit: |
| 3738 | return return_value; |
| 3739 | } |
| 3740 | |
| 3741 | #endif /* defined(HAVE_WRITEV) */ |
| 3742 | |
| 3743 | #if defined(HAVE_PWRITE) |
| 3744 | |
| 3745 | PyDoc_STRVAR(os_pwrite__doc__, |
| 3746 | "pwrite($module, fd, buffer, offset, /)\n" |
| 3747 | "--\n" |
| 3748 | "\n" |
| 3749 | "Write bytes to a file descriptor starting at a particular offset.\n" |
| 3750 | "\n" |
| 3751 | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
| 3752 | "the file. Returns the number of bytes writte. Does not change the\n" |
| 3753 | "current file offset."); |
| 3754 | |
| 3755 | #define OS_PWRITE_METHODDEF \ |
| 3756 | {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__}, |
| 3757 | |
| 3758 | static Py_ssize_t |
| 3759 | os_pwrite_impl(PyModuleDef *module, int fd, Py_buffer *buffer, Py_off_t offset); |
| 3760 | |
| 3761 | static PyObject * |
| 3762 | os_pwrite(PyModuleDef *module, PyObject *args) |
| 3763 | { |
| 3764 | PyObject *return_value = NULL; |
| 3765 | int fd; |
| 3766 | Py_buffer buffer = {NULL, NULL}; |
| 3767 | Py_off_t offset; |
| 3768 | Py_ssize_t _return_value; |
| 3769 | |
| 3770 | if (!PyArg_ParseTuple(args, |
| 3771 | "iy*O&:pwrite", |
| 3772 | &fd, &buffer, Py_off_t_converter, &offset)) |
| 3773 | goto exit; |
| 3774 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
| 3775 | if ((_return_value == -1) && PyErr_Occurred()) |
| 3776 | goto exit; |
| 3777 | return_value = PyLong_FromSsize_t(_return_value); |
| 3778 | |
| 3779 | exit: |
| 3780 | /* Cleanup for buffer */ |
| 3781 | if (buffer.obj) |
| 3782 | PyBuffer_Release(&buffer); |
| 3783 | |
| 3784 | return return_value; |
| 3785 | } |
| 3786 | |
| 3787 | #endif /* defined(HAVE_PWRITE) */ |
| 3788 | |
| 3789 | #if defined(HAVE_MKFIFO) |
| 3790 | |
| 3791 | PyDoc_STRVAR(os_mkfifo__doc__, |
| 3792 | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
| 3793 | "--\n" |
| 3794 | "\n" |
| 3795 | "Create a \"fifo\" (a POSIX named pipe).\n" |
| 3796 | "\n" |
| 3797 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3798 | " and path should be relative; path will then be relative to that directory.\n" |
| 3799 | "dir_fd may not be implemented on your platform.\n" |
| 3800 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3801 | |
| 3802 | #define OS_MKFIFO_METHODDEF \ |
| 3803 | {"mkfifo", (PyCFunction)os_mkfifo, METH_VARARGS|METH_KEYWORDS, os_mkfifo__doc__}, |
| 3804 | |
| 3805 | static PyObject * |
| 3806 | os_mkfifo_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd); |
| 3807 | |
| 3808 | static PyObject * |
| 3809 | os_mkfifo(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 3810 | { |
| 3811 | PyObject *return_value = NULL; |
| 3812 | static char *_keywords[] = {"path", "mode", "dir_fd", NULL}; |
| 3813 | path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0); |
| 3814 | int mode = 438; |
| 3815 | int dir_fd = DEFAULT_DIR_FD; |
| 3816 | |
| 3817 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 3818 | "O&|i$O&:mkfifo", _keywords, |
| 3819 | path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) |
| 3820 | goto exit; |
| 3821 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
| 3822 | |
| 3823 | exit: |
| 3824 | /* Cleanup for path */ |
| 3825 | path_cleanup(&path); |
| 3826 | |
| 3827 | return return_value; |
| 3828 | } |
| 3829 | |
| 3830 | #endif /* defined(HAVE_MKFIFO) */ |
| 3831 | |
| 3832 | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
| 3833 | |
| 3834 | PyDoc_STRVAR(os_mknod__doc__, |
| 3835 | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
| 3836 | "--\n" |
| 3837 | "\n" |
| 3838 | "Create a node in the file system.\n" |
| 3839 | "\n" |
| 3840 | "Create a node in the file system (file, device special file or named pipe)\n" |
| 3841 | "at path. mode specifies both the permissions to use and the\n" |
| 3842 | "type of node to be created, being combined (bitwise OR) with one of\n" |
| 3843 | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
| 3844 | "device defines the newly created device special file (probably using\n" |
| 3845 | "os.makedev()). Otherwise device is ignored.\n" |
| 3846 | "\n" |
| 3847 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3848 | " and path should be relative; path will then be relative to that directory.\n" |
| 3849 | "dir_fd may not be implemented on your platform.\n" |
| 3850 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3851 | |
| 3852 | #define OS_MKNOD_METHODDEF \ |
| 3853 | {"mknod", (PyCFunction)os_mknod, METH_VARARGS|METH_KEYWORDS, os_mknod__doc__}, |
| 3854 | |
| 3855 | static PyObject * |
| 3856 | os_mknod_impl(PyModuleDef *module, path_t *path, int mode, dev_t device, int dir_fd); |
| 3857 | |
| 3858 | static PyObject * |
| 3859 | os_mknod(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 3860 | { |
| 3861 | PyObject *return_value = NULL; |
| 3862 | static char *_keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
| 3863 | path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0); |
| 3864 | int mode = 384; |
| 3865 | dev_t device = 0; |
| 3866 | int dir_fd = DEFAULT_DIR_FD; |
| 3867 | |
| 3868 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 3869 | "O&|iO&$O&:mknod", _keywords, |
| 3870 | path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) |
| 3871 | goto exit; |
| 3872 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
| 3873 | |
| 3874 | exit: |
| 3875 | /* Cleanup for path */ |
| 3876 | path_cleanup(&path); |
| 3877 | |
| 3878 | return return_value; |
| 3879 | } |
| 3880 | |
| 3881 | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
| 3882 | |
| 3883 | #if defined(HAVE_DEVICE_MACROS) |
| 3884 | |
| 3885 | PyDoc_STRVAR(os_major__doc__, |
| 3886 | "major($module, device, /)\n" |
| 3887 | "--\n" |
| 3888 | "\n" |
| 3889 | "Extracts a device major number from a raw device number."); |
| 3890 | |
| 3891 | #define OS_MAJOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3892 | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3893 | |
| 3894 | static unsigned int |
| 3895 | os_major_impl(PyModuleDef *module, dev_t device); |
| 3896 | |
| 3897 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3898 | os_major(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3899 | { |
| 3900 | PyObject *return_value = NULL; |
| 3901 | dev_t device; |
| 3902 | unsigned int _return_value; |
| 3903 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3904 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3905 | "O&:major", |
| 3906 | _Py_Dev_Converter, &device)) |
| 3907 | goto exit; |
| 3908 | _return_value = os_major_impl(module, device); |
| 3909 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) |
| 3910 | goto exit; |
| 3911 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 3912 | |
| 3913 | exit: |
| 3914 | return return_value; |
| 3915 | } |
| 3916 | |
| 3917 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 3918 | |
| 3919 | #if defined(HAVE_DEVICE_MACROS) |
| 3920 | |
| 3921 | PyDoc_STRVAR(os_minor__doc__, |
| 3922 | "minor($module, device, /)\n" |
| 3923 | "--\n" |
| 3924 | "\n" |
| 3925 | "Extracts a device minor number from a raw device number."); |
| 3926 | |
| 3927 | #define OS_MINOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3928 | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3929 | |
| 3930 | static unsigned int |
| 3931 | os_minor_impl(PyModuleDef *module, dev_t device); |
| 3932 | |
| 3933 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3934 | os_minor(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3935 | { |
| 3936 | PyObject *return_value = NULL; |
| 3937 | dev_t device; |
| 3938 | unsigned int _return_value; |
| 3939 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 3940 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3941 | "O&:minor", |
| 3942 | _Py_Dev_Converter, &device)) |
| 3943 | goto exit; |
| 3944 | _return_value = os_minor_impl(module, device); |
| 3945 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) |
| 3946 | goto exit; |
| 3947 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 3948 | |
| 3949 | exit: |
| 3950 | return return_value; |
| 3951 | } |
| 3952 | |
| 3953 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 3954 | |
| 3955 | #if defined(HAVE_DEVICE_MACROS) |
| 3956 | |
| 3957 | PyDoc_STRVAR(os_makedev__doc__, |
| 3958 | "makedev($module, major, minor, /)\n" |
| 3959 | "--\n" |
| 3960 | "\n" |
| 3961 | "Composes a raw device number from the major and minor device numbers."); |
| 3962 | |
| 3963 | #define OS_MAKEDEV_METHODDEF \ |
| 3964 | {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__}, |
| 3965 | |
| 3966 | static dev_t |
| 3967 | os_makedev_impl(PyModuleDef *module, int major, int minor); |
| 3968 | |
| 3969 | static PyObject * |
| 3970 | os_makedev(PyModuleDef *module, PyObject *args) |
| 3971 | { |
| 3972 | PyObject *return_value = NULL; |
| 3973 | int major; |
| 3974 | int minor; |
| 3975 | dev_t _return_value; |
| 3976 | |
| 3977 | if (!PyArg_ParseTuple(args, |
| 3978 | "ii:makedev", |
| 3979 | &major, &minor)) |
| 3980 | goto exit; |
| 3981 | _return_value = os_makedev_impl(module, major, minor); |
| 3982 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) |
| 3983 | goto exit; |
| 3984 | return_value = _PyLong_FromDev(_return_value); |
| 3985 | |
| 3986 | exit: |
| 3987 | return return_value; |
| 3988 | } |
| 3989 | |
| 3990 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 3991 | |
| 3992 | #if defined(HAVE_FTRUNCATE) |
| 3993 | |
| 3994 | PyDoc_STRVAR(os_ftruncate__doc__, |
| 3995 | "ftruncate($module, fd, length, /)\n" |
| 3996 | "--\n" |
| 3997 | "\n" |
| 3998 | "Truncate a file, specified by file descriptor, to a specific length."); |
| 3999 | |
| 4000 | #define OS_FTRUNCATE_METHODDEF \ |
| 4001 | {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__}, |
| 4002 | |
| 4003 | static PyObject * |
| 4004 | os_ftruncate_impl(PyModuleDef *module, int fd, Py_off_t length); |
| 4005 | |
| 4006 | static PyObject * |
| 4007 | os_ftruncate(PyModuleDef *module, PyObject *args) |
| 4008 | { |
| 4009 | PyObject *return_value = NULL; |
| 4010 | int fd; |
| 4011 | Py_off_t length; |
| 4012 | |
| 4013 | if (!PyArg_ParseTuple(args, |
| 4014 | "iO&:ftruncate", |
| 4015 | &fd, Py_off_t_converter, &length)) |
| 4016 | goto exit; |
| 4017 | return_value = os_ftruncate_impl(module, fd, length); |
| 4018 | |
| 4019 | exit: |
| 4020 | return return_value; |
| 4021 | } |
| 4022 | |
| 4023 | #endif /* defined(HAVE_FTRUNCATE) */ |
| 4024 | |
| 4025 | #if defined(HAVE_TRUNCATE) |
| 4026 | |
| 4027 | PyDoc_STRVAR(os_truncate__doc__, |
| 4028 | "truncate($module, /, path, length)\n" |
| 4029 | "--\n" |
| 4030 | "\n" |
| 4031 | "Truncate a file, specified by path, to a specific length.\n" |
| 4032 | "\n" |
| 4033 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 4034 | " If this functionality is unavailable, using it raises an exception."); |
| 4035 | |
| 4036 | #define OS_TRUNCATE_METHODDEF \ |
| 4037 | {"truncate", (PyCFunction)os_truncate, METH_VARARGS|METH_KEYWORDS, os_truncate__doc__}, |
| 4038 | |
| 4039 | static PyObject * |
| 4040 | os_truncate_impl(PyModuleDef *module, path_t *path, Py_off_t length); |
| 4041 | |
| 4042 | static PyObject * |
| 4043 | os_truncate(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4044 | { |
| 4045 | PyObject *return_value = NULL; |
| 4046 | static char *_keywords[] = {"path", "length", NULL}; |
| 4047 | path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE); |
| 4048 | Py_off_t length; |
| 4049 | |
| 4050 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4051 | "O&O&:truncate", _keywords, |
| 4052 | path_converter, &path, Py_off_t_converter, &length)) |
| 4053 | goto exit; |
| 4054 | return_value = os_truncate_impl(module, &path, length); |
| 4055 | |
| 4056 | exit: |
| 4057 | /* Cleanup for path */ |
| 4058 | path_cleanup(&path); |
| 4059 | |
| 4060 | return return_value; |
| 4061 | } |
| 4062 | |
| 4063 | #endif /* defined(HAVE_TRUNCATE) */ |
| 4064 | |
| 4065 | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 4066 | |
| 4067 | PyDoc_STRVAR(os_posix_fallocate__doc__, |
| 4068 | "posix_fallocate($module, fd, offset, length, /)\n" |
| 4069 | "--\n" |
| 4070 | "\n" |
| 4071 | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
| 4072 | "\n" |
| 4073 | "Ensure that the file specified by fd encompasses a range of bytes\n" |
| 4074 | "starting at offset bytes from the beginning and continuing for length bytes."); |
| 4075 | |
| 4076 | #define OS_POSIX_FALLOCATE_METHODDEF \ |
| 4077 | {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__}, |
| 4078 | |
| 4079 | static PyObject * |
| 4080 | os_posix_fallocate_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length); |
| 4081 | |
| 4082 | static PyObject * |
| 4083 | os_posix_fallocate(PyModuleDef *module, PyObject *args) |
| 4084 | { |
| 4085 | PyObject *return_value = NULL; |
| 4086 | int fd; |
| 4087 | Py_off_t offset; |
| 4088 | Py_off_t length; |
| 4089 | |
| 4090 | if (!PyArg_ParseTuple(args, |
| 4091 | "iO&O&:posix_fallocate", |
| 4092 | &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) |
| 4093 | goto exit; |
| 4094 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
| 4095 | |
| 4096 | exit: |
| 4097 | return return_value; |
| 4098 | } |
| 4099 | |
| 4100 | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 4101 | |
| 4102 | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 4103 | |
| 4104 | PyDoc_STRVAR(os_posix_fadvise__doc__, |
| 4105 | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
| 4106 | "--\n" |
| 4107 | "\n" |
| 4108 | "Announce an intention to access data in a specific pattern.\n" |
| 4109 | "\n" |
| 4110 | "Announce an intention to access data in a specific pattern, thus allowing\n" |
| 4111 | "the kernel to make optimizations.\n" |
| 4112 | "The advice applies to the region of the file specified by fd starting at\n" |
| 4113 | "offset and continuing for length bytes.\n" |
| 4114 | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
| 4115 | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
| 4116 | "POSIX_FADV_DONTNEED."); |
| 4117 | |
| 4118 | #define OS_POSIX_FADVISE_METHODDEF \ |
| 4119 | {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__}, |
| 4120 | |
| 4121 | static PyObject * |
| 4122 | os_posix_fadvise_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length, int advice); |
| 4123 | |
| 4124 | static PyObject * |
| 4125 | os_posix_fadvise(PyModuleDef *module, PyObject *args) |
| 4126 | { |
| 4127 | PyObject *return_value = NULL; |
| 4128 | int fd; |
| 4129 | Py_off_t offset; |
| 4130 | Py_off_t length; |
| 4131 | int advice; |
| 4132 | |
| 4133 | if (!PyArg_ParseTuple(args, |
| 4134 | "iO&O&i:posix_fadvise", |
| 4135 | &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) |
| 4136 | goto exit; |
| 4137 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
| 4138 | |
| 4139 | exit: |
| 4140 | return return_value; |
| 4141 | } |
| 4142 | |
| 4143 | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 4144 | |
| 4145 | #if defined(HAVE_PUTENV) && defined(MS_WINDOWS) |
| 4146 | |
| 4147 | PyDoc_STRVAR(os_putenv__doc__, |
| 4148 | "putenv($module, name, value, /)\n" |
| 4149 | "--\n" |
| 4150 | "\n" |
| 4151 | "Change or add an environment variable."); |
| 4152 | |
| 4153 | #define OS_PUTENV_METHODDEF \ |
| 4154 | {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__}, |
| 4155 | |
| 4156 | static PyObject * |
| 4157 | os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value); |
| 4158 | |
| 4159 | static PyObject * |
| 4160 | os_putenv(PyModuleDef *module, PyObject *args) |
| 4161 | { |
| 4162 | PyObject *return_value = NULL; |
| 4163 | PyObject *name; |
| 4164 | PyObject *value; |
| 4165 | |
| 4166 | if (!PyArg_ParseTuple(args, |
| 4167 | "UU:putenv", |
| 4168 | &name, &value)) |
| 4169 | goto exit; |
| 4170 | return_value = os_putenv_impl(module, name, value); |
| 4171 | |
| 4172 | exit: |
| 4173 | return return_value; |
| 4174 | } |
| 4175 | |
| 4176 | #endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */ |
| 4177 | |
| 4178 | #if defined(HAVE_PUTENV) && !defined(MS_WINDOWS) |
| 4179 | |
| 4180 | PyDoc_STRVAR(os_putenv__doc__, |
| 4181 | "putenv($module, name, value, /)\n" |
| 4182 | "--\n" |
| 4183 | "\n" |
| 4184 | "Change or add an environment variable."); |
| 4185 | |
| 4186 | #define OS_PUTENV_METHODDEF \ |
| 4187 | {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__}, |
| 4188 | |
| 4189 | static PyObject * |
| 4190 | os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value); |
| 4191 | |
| 4192 | static PyObject * |
| 4193 | os_putenv(PyModuleDef *module, PyObject *args) |
| 4194 | { |
| 4195 | PyObject *return_value = NULL; |
| 4196 | PyObject *name = NULL; |
| 4197 | PyObject *value = NULL; |
| 4198 | |
| 4199 | if (!PyArg_ParseTuple(args, |
| 4200 | "O&O&:putenv", |
| 4201 | PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) |
| 4202 | goto exit; |
| 4203 | return_value = os_putenv_impl(module, name, value); |
| 4204 | |
| 4205 | exit: |
| 4206 | /* Cleanup for name */ |
| 4207 | Py_XDECREF(name); |
| 4208 | /* Cleanup for value */ |
| 4209 | Py_XDECREF(value); |
| 4210 | |
| 4211 | return return_value; |
| 4212 | } |
| 4213 | |
| 4214 | #endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */ |
| 4215 | |
| 4216 | #if defined(HAVE_UNSETENV) |
| 4217 | |
| 4218 | PyDoc_STRVAR(os_unsetenv__doc__, |
| 4219 | "unsetenv($module, name, /)\n" |
| 4220 | "--\n" |
| 4221 | "\n" |
| 4222 | "Delete an environment variable."); |
| 4223 | |
| 4224 | #define OS_UNSETENV_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4225 | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4226 | |
| 4227 | static PyObject * |
| 4228 | os_unsetenv_impl(PyModuleDef *module, PyObject *name); |
| 4229 | |
| 4230 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4231 | os_unsetenv(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4232 | { |
| 4233 | PyObject *return_value = NULL; |
| 4234 | PyObject *name = NULL; |
| 4235 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4236 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4237 | "O&:unsetenv", |
| 4238 | PyUnicode_FSConverter, &name)) |
| 4239 | goto exit; |
| 4240 | return_value = os_unsetenv_impl(module, name); |
| 4241 | |
| 4242 | exit: |
| 4243 | /* Cleanup for name */ |
| 4244 | Py_XDECREF(name); |
| 4245 | |
| 4246 | return return_value; |
| 4247 | } |
| 4248 | |
| 4249 | #endif /* defined(HAVE_UNSETENV) */ |
| 4250 | |
| 4251 | PyDoc_STRVAR(os_strerror__doc__, |
| 4252 | "strerror($module, code, /)\n" |
| 4253 | "--\n" |
| 4254 | "\n" |
| 4255 | "Translate an error code to a message string."); |
| 4256 | |
| 4257 | #define OS_STRERROR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4258 | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4259 | |
| 4260 | static PyObject * |
| 4261 | os_strerror_impl(PyModuleDef *module, int code); |
| 4262 | |
| 4263 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4264 | os_strerror(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4265 | { |
| 4266 | PyObject *return_value = NULL; |
| 4267 | int code; |
| 4268 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4269 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4270 | "i:strerror", |
| 4271 | &code)) |
| 4272 | goto exit; |
| 4273 | return_value = os_strerror_impl(module, code); |
| 4274 | |
| 4275 | exit: |
| 4276 | return return_value; |
| 4277 | } |
| 4278 | |
| 4279 | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
| 4280 | |
| 4281 | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
| 4282 | "WCOREDUMP($module, status, /)\n" |
| 4283 | "--\n" |
| 4284 | "\n" |
| 4285 | "Return True if the process returning status was dumped to a core file."); |
| 4286 | |
| 4287 | #define OS_WCOREDUMP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4288 | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4289 | |
| 4290 | static int |
| 4291 | os_WCOREDUMP_impl(PyModuleDef *module, int status); |
| 4292 | |
| 4293 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4294 | os_WCOREDUMP(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4295 | { |
| 4296 | PyObject *return_value = NULL; |
| 4297 | int status; |
| 4298 | int _return_value; |
| 4299 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4300 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4301 | "i:WCOREDUMP", |
| 4302 | &status)) |
| 4303 | goto exit; |
| 4304 | _return_value = os_WCOREDUMP_impl(module, status); |
| 4305 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4306 | goto exit; |
| 4307 | return_value = PyBool_FromLong((long)_return_value); |
| 4308 | |
| 4309 | exit: |
| 4310 | return return_value; |
| 4311 | } |
| 4312 | |
| 4313 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
| 4314 | |
| 4315 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
| 4316 | |
| 4317 | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
| 4318 | "WIFCONTINUED($module, /, status)\n" |
| 4319 | "--\n" |
| 4320 | "\n" |
| 4321 | "Return True if a particular process was continued from a job control stop.\n" |
| 4322 | "\n" |
| 4323 | "Return True if the process returning status was continued from a\n" |
| 4324 | "job control stop."); |
| 4325 | |
| 4326 | #define OS_WIFCONTINUED_METHODDEF \ |
| 4327 | {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_VARARGS|METH_KEYWORDS, os_WIFCONTINUED__doc__}, |
| 4328 | |
| 4329 | static int |
| 4330 | os_WIFCONTINUED_impl(PyModuleDef *module, int status); |
| 4331 | |
| 4332 | static PyObject * |
| 4333 | os_WIFCONTINUED(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4334 | { |
| 4335 | PyObject *return_value = NULL; |
| 4336 | static char *_keywords[] = {"status", NULL}; |
| 4337 | int status; |
| 4338 | int _return_value; |
| 4339 | |
| 4340 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4341 | "i:WIFCONTINUED", _keywords, |
| 4342 | &status)) |
| 4343 | goto exit; |
| 4344 | _return_value = os_WIFCONTINUED_impl(module, status); |
| 4345 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4346 | goto exit; |
| 4347 | return_value = PyBool_FromLong((long)_return_value); |
| 4348 | |
| 4349 | exit: |
| 4350 | return return_value; |
| 4351 | } |
| 4352 | |
| 4353 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
| 4354 | |
| 4355 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
| 4356 | |
| 4357 | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
| 4358 | "WIFSTOPPED($module, /, status)\n" |
| 4359 | "--\n" |
| 4360 | "\n" |
| 4361 | "Return True if the process returning status was stopped."); |
| 4362 | |
| 4363 | #define OS_WIFSTOPPED_METHODDEF \ |
| 4364 | {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_VARARGS|METH_KEYWORDS, os_WIFSTOPPED__doc__}, |
| 4365 | |
| 4366 | static int |
| 4367 | os_WIFSTOPPED_impl(PyModuleDef *module, int status); |
| 4368 | |
| 4369 | static PyObject * |
| 4370 | os_WIFSTOPPED(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4371 | { |
| 4372 | PyObject *return_value = NULL; |
| 4373 | static char *_keywords[] = {"status", NULL}; |
| 4374 | int status; |
| 4375 | int _return_value; |
| 4376 | |
| 4377 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4378 | "i:WIFSTOPPED", _keywords, |
| 4379 | &status)) |
| 4380 | goto exit; |
| 4381 | _return_value = os_WIFSTOPPED_impl(module, status); |
| 4382 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4383 | goto exit; |
| 4384 | return_value = PyBool_FromLong((long)_return_value); |
| 4385 | |
| 4386 | exit: |
| 4387 | return return_value; |
| 4388 | } |
| 4389 | |
| 4390 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
| 4391 | |
| 4392 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
| 4393 | |
| 4394 | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
| 4395 | "WIFSIGNALED($module, /, status)\n" |
| 4396 | "--\n" |
| 4397 | "\n" |
| 4398 | "Return True if the process returning status was terminated by a signal."); |
| 4399 | |
| 4400 | #define OS_WIFSIGNALED_METHODDEF \ |
| 4401 | {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_VARARGS|METH_KEYWORDS, os_WIFSIGNALED__doc__}, |
| 4402 | |
| 4403 | static int |
| 4404 | os_WIFSIGNALED_impl(PyModuleDef *module, int status); |
| 4405 | |
| 4406 | static PyObject * |
| 4407 | os_WIFSIGNALED(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4408 | { |
| 4409 | PyObject *return_value = NULL; |
| 4410 | static char *_keywords[] = {"status", NULL}; |
| 4411 | int status; |
| 4412 | int _return_value; |
| 4413 | |
| 4414 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4415 | "i:WIFSIGNALED", _keywords, |
| 4416 | &status)) |
| 4417 | goto exit; |
| 4418 | _return_value = os_WIFSIGNALED_impl(module, status); |
| 4419 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4420 | goto exit; |
| 4421 | return_value = PyBool_FromLong((long)_return_value); |
| 4422 | |
| 4423 | exit: |
| 4424 | return return_value; |
| 4425 | } |
| 4426 | |
| 4427 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
| 4428 | |
| 4429 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
| 4430 | |
| 4431 | PyDoc_STRVAR(os_WIFEXITED__doc__, |
| 4432 | "WIFEXITED($module, /, status)\n" |
| 4433 | "--\n" |
| 4434 | "\n" |
| 4435 | "Return True if the process returning status exited via the exit() system call."); |
| 4436 | |
| 4437 | #define OS_WIFEXITED_METHODDEF \ |
| 4438 | {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_VARARGS|METH_KEYWORDS, os_WIFEXITED__doc__}, |
| 4439 | |
| 4440 | static int |
| 4441 | os_WIFEXITED_impl(PyModuleDef *module, int status); |
| 4442 | |
| 4443 | static PyObject * |
| 4444 | os_WIFEXITED(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4445 | { |
| 4446 | PyObject *return_value = NULL; |
| 4447 | static char *_keywords[] = {"status", NULL}; |
| 4448 | int status; |
| 4449 | int _return_value; |
| 4450 | |
| 4451 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4452 | "i:WIFEXITED", _keywords, |
| 4453 | &status)) |
| 4454 | goto exit; |
| 4455 | _return_value = os_WIFEXITED_impl(module, status); |
| 4456 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4457 | goto exit; |
| 4458 | return_value = PyBool_FromLong((long)_return_value); |
| 4459 | |
| 4460 | exit: |
| 4461 | return return_value; |
| 4462 | } |
| 4463 | |
| 4464 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
| 4465 | |
| 4466 | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
| 4467 | |
| 4468 | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
| 4469 | "WEXITSTATUS($module, /, status)\n" |
| 4470 | "--\n" |
| 4471 | "\n" |
| 4472 | "Return the process return code from status."); |
| 4473 | |
| 4474 | #define OS_WEXITSTATUS_METHODDEF \ |
| 4475 | {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_VARARGS|METH_KEYWORDS, os_WEXITSTATUS__doc__}, |
| 4476 | |
| 4477 | static int |
| 4478 | os_WEXITSTATUS_impl(PyModuleDef *module, int status); |
| 4479 | |
| 4480 | static PyObject * |
| 4481 | os_WEXITSTATUS(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4482 | { |
| 4483 | PyObject *return_value = NULL; |
| 4484 | static char *_keywords[] = {"status", NULL}; |
| 4485 | int status; |
| 4486 | int _return_value; |
| 4487 | |
| 4488 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4489 | "i:WEXITSTATUS", _keywords, |
| 4490 | &status)) |
| 4491 | goto exit; |
| 4492 | _return_value = os_WEXITSTATUS_impl(module, status); |
| 4493 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4494 | goto exit; |
| 4495 | return_value = PyLong_FromLong((long)_return_value); |
| 4496 | |
| 4497 | exit: |
| 4498 | return return_value; |
| 4499 | } |
| 4500 | |
| 4501 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
| 4502 | |
| 4503 | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
| 4504 | |
| 4505 | PyDoc_STRVAR(os_WTERMSIG__doc__, |
| 4506 | "WTERMSIG($module, /, status)\n" |
| 4507 | "--\n" |
| 4508 | "\n" |
| 4509 | "Return the signal that terminated the process that provided the status value."); |
| 4510 | |
| 4511 | #define OS_WTERMSIG_METHODDEF \ |
| 4512 | {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_VARARGS|METH_KEYWORDS, os_WTERMSIG__doc__}, |
| 4513 | |
| 4514 | static int |
| 4515 | os_WTERMSIG_impl(PyModuleDef *module, int status); |
| 4516 | |
| 4517 | static PyObject * |
| 4518 | os_WTERMSIG(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4519 | { |
| 4520 | PyObject *return_value = NULL; |
| 4521 | static char *_keywords[] = {"status", NULL}; |
| 4522 | int status; |
| 4523 | int _return_value; |
| 4524 | |
| 4525 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4526 | "i:WTERMSIG", _keywords, |
| 4527 | &status)) |
| 4528 | goto exit; |
| 4529 | _return_value = os_WTERMSIG_impl(module, status); |
| 4530 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4531 | goto exit; |
| 4532 | return_value = PyLong_FromLong((long)_return_value); |
| 4533 | |
| 4534 | exit: |
| 4535 | return return_value; |
| 4536 | } |
| 4537 | |
| 4538 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
| 4539 | |
| 4540 | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
| 4541 | |
| 4542 | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
| 4543 | "WSTOPSIG($module, /, status)\n" |
| 4544 | "--\n" |
| 4545 | "\n" |
| 4546 | "Return the signal that stopped the process that provided the status value."); |
| 4547 | |
| 4548 | #define OS_WSTOPSIG_METHODDEF \ |
| 4549 | {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_VARARGS|METH_KEYWORDS, os_WSTOPSIG__doc__}, |
| 4550 | |
| 4551 | static int |
| 4552 | os_WSTOPSIG_impl(PyModuleDef *module, int status); |
| 4553 | |
| 4554 | static PyObject * |
| 4555 | os_WSTOPSIG(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4556 | { |
| 4557 | PyObject *return_value = NULL; |
| 4558 | static char *_keywords[] = {"status", NULL}; |
| 4559 | int status; |
| 4560 | int _return_value; |
| 4561 | |
| 4562 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4563 | "i:WSTOPSIG", _keywords, |
| 4564 | &status)) |
| 4565 | goto exit; |
| 4566 | _return_value = os_WSTOPSIG_impl(module, status); |
| 4567 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4568 | goto exit; |
| 4569 | return_value = PyLong_FromLong((long)_return_value); |
| 4570 | |
| 4571 | exit: |
| 4572 | return return_value; |
| 4573 | } |
| 4574 | |
| 4575 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
| 4576 | |
| 4577 | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 4578 | |
| 4579 | PyDoc_STRVAR(os_fstatvfs__doc__, |
| 4580 | "fstatvfs($module, fd, /)\n" |
| 4581 | "--\n" |
| 4582 | "\n" |
| 4583 | "Perform an fstatvfs system call on the given fd.\n" |
| 4584 | "\n" |
| 4585 | "Equivalent to statvfs(fd)."); |
| 4586 | |
| 4587 | #define OS_FSTATVFS_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4588 | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4589 | |
| 4590 | static PyObject * |
| 4591 | os_fstatvfs_impl(PyModuleDef *module, int fd); |
| 4592 | |
| 4593 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4594 | os_fstatvfs(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4595 | { |
| 4596 | PyObject *return_value = NULL; |
| 4597 | int fd; |
| 4598 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4599 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4600 | "i:fstatvfs", |
| 4601 | &fd)) |
| 4602 | goto exit; |
| 4603 | return_value = os_fstatvfs_impl(module, fd); |
| 4604 | |
| 4605 | exit: |
| 4606 | return return_value; |
| 4607 | } |
| 4608 | |
| 4609 | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 4610 | |
| 4611 | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 4612 | |
| 4613 | PyDoc_STRVAR(os_statvfs__doc__, |
| 4614 | "statvfs($module, /, path)\n" |
| 4615 | "--\n" |
| 4616 | "\n" |
| 4617 | "Perform a statvfs system call on the given path.\n" |
| 4618 | "\n" |
| 4619 | "path may always be specified as a string.\n" |
| 4620 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 4621 | " If this functionality is unavailable, using it raises an exception."); |
| 4622 | |
| 4623 | #define OS_STATVFS_METHODDEF \ |
| 4624 | {"statvfs", (PyCFunction)os_statvfs, METH_VARARGS|METH_KEYWORDS, os_statvfs__doc__}, |
| 4625 | |
| 4626 | static PyObject * |
| 4627 | os_statvfs_impl(PyModuleDef *module, path_t *path); |
| 4628 | |
| 4629 | static PyObject * |
| 4630 | os_statvfs(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4631 | { |
| 4632 | PyObject *return_value = NULL; |
| 4633 | static char *_keywords[] = {"path", NULL}; |
| 4634 | path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS); |
| 4635 | |
| 4636 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4637 | "O&:statvfs", _keywords, |
| 4638 | path_converter, &path)) |
| 4639 | goto exit; |
| 4640 | return_value = os_statvfs_impl(module, &path); |
| 4641 | |
| 4642 | exit: |
| 4643 | /* Cleanup for path */ |
| 4644 | path_cleanup(&path); |
| 4645 | |
| 4646 | return return_value; |
| 4647 | } |
| 4648 | |
| 4649 | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 4650 | |
| 4651 | #if defined(MS_WINDOWS) |
| 4652 | |
| 4653 | PyDoc_STRVAR(os__getdiskusage__doc__, |
| 4654 | "_getdiskusage($module, /, path)\n" |
| 4655 | "--\n" |
| 4656 | "\n" |
| 4657 | "Return disk usage statistics about the given path as a (total, free) tuple."); |
| 4658 | |
| 4659 | #define OS__GETDISKUSAGE_METHODDEF \ |
| 4660 | {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_VARARGS|METH_KEYWORDS, os__getdiskusage__doc__}, |
| 4661 | |
| 4662 | static PyObject * |
| 4663 | os__getdiskusage_impl(PyModuleDef *module, Py_UNICODE *path); |
| 4664 | |
| 4665 | static PyObject * |
| 4666 | os__getdiskusage(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4667 | { |
| 4668 | PyObject *return_value = NULL; |
| 4669 | static char *_keywords[] = {"path", NULL}; |
| 4670 | Py_UNICODE *path; |
| 4671 | |
| 4672 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4673 | "u:_getdiskusage", _keywords, |
| 4674 | &path)) |
| 4675 | goto exit; |
| 4676 | return_value = os__getdiskusage_impl(module, path); |
| 4677 | |
| 4678 | exit: |
| 4679 | return return_value; |
| 4680 | } |
| 4681 | |
| 4682 | #endif /* defined(MS_WINDOWS) */ |
| 4683 | |
| 4684 | #if defined(HAVE_FPATHCONF) |
| 4685 | |
| 4686 | PyDoc_STRVAR(os_fpathconf__doc__, |
| 4687 | "fpathconf($module, fd, name, /)\n" |
| 4688 | "--\n" |
| 4689 | "\n" |
| 4690 | "Return the configuration limit name for the file descriptor fd.\n" |
| 4691 | "\n" |
| 4692 | "If there is no limit, return -1."); |
| 4693 | |
| 4694 | #define OS_FPATHCONF_METHODDEF \ |
| 4695 | {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__}, |
| 4696 | |
| 4697 | static long |
| 4698 | os_fpathconf_impl(PyModuleDef *module, int fd, int name); |
| 4699 | |
| 4700 | static PyObject * |
| 4701 | os_fpathconf(PyModuleDef *module, PyObject *args) |
| 4702 | { |
| 4703 | PyObject *return_value = NULL; |
| 4704 | int fd; |
| 4705 | int name; |
| 4706 | long _return_value; |
| 4707 | |
| 4708 | if (!PyArg_ParseTuple(args, |
| 4709 | "iO&:fpathconf", |
| 4710 | &fd, conv_path_confname, &name)) |
| 4711 | goto exit; |
| 4712 | _return_value = os_fpathconf_impl(module, fd, name); |
| 4713 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4714 | goto exit; |
| 4715 | return_value = PyLong_FromLong(_return_value); |
| 4716 | |
| 4717 | exit: |
| 4718 | return return_value; |
| 4719 | } |
| 4720 | |
| 4721 | #endif /* defined(HAVE_FPATHCONF) */ |
| 4722 | |
| 4723 | #if defined(HAVE_PATHCONF) |
| 4724 | |
| 4725 | PyDoc_STRVAR(os_pathconf__doc__, |
| 4726 | "pathconf($module, /, path, name)\n" |
| 4727 | "--\n" |
| 4728 | "\n" |
| 4729 | "Return the configuration limit name for the file or directory path.\n" |
| 4730 | "\n" |
| 4731 | "If there is no limit, return -1.\n" |
| 4732 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 4733 | " If this functionality is unavailable, using it raises an exception."); |
| 4734 | |
| 4735 | #define OS_PATHCONF_METHODDEF \ |
| 4736 | {"pathconf", (PyCFunction)os_pathconf, METH_VARARGS|METH_KEYWORDS, os_pathconf__doc__}, |
| 4737 | |
| 4738 | static long |
| 4739 | os_pathconf_impl(PyModuleDef *module, path_t *path, int name); |
| 4740 | |
| 4741 | static PyObject * |
| 4742 | os_pathconf(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4743 | { |
| 4744 | PyObject *return_value = NULL; |
| 4745 | static char *_keywords[] = {"path", "name", NULL}; |
| 4746 | path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF); |
| 4747 | int name; |
| 4748 | long _return_value; |
| 4749 | |
| 4750 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4751 | "O&O&:pathconf", _keywords, |
| 4752 | path_converter, &path, conv_path_confname, &name)) |
| 4753 | goto exit; |
| 4754 | _return_value = os_pathconf_impl(module, &path, name); |
| 4755 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4756 | goto exit; |
| 4757 | return_value = PyLong_FromLong(_return_value); |
| 4758 | |
| 4759 | exit: |
| 4760 | /* Cleanup for path */ |
| 4761 | path_cleanup(&path); |
| 4762 | |
| 4763 | return return_value; |
| 4764 | } |
| 4765 | |
| 4766 | #endif /* defined(HAVE_PATHCONF) */ |
| 4767 | |
| 4768 | #if defined(HAVE_CONFSTR) |
| 4769 | |
| 4770 | PyDoc_STRVAR(os_confstr__doc__, |
| 4771 | "confstr($module, name, /)\n" |
| 4772 | "--\n" |
| 4773 | "\n" |
| 4774 | "Return a string-valued system configuration variable."); |
| 4775 | |
| 4776 | #define OS_CONFSTR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4777 | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4778 | |
| 4779 | static PyObject * |
| 4780 | os_confstr_impl(PyModuleDef *module, int name); |
| 4781 | |
| 4782 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4783 | os_confstr(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4784 | { |
| 4785 | PyObject *return_value = NULL; |
| 4786 | int name; |
| 4787 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4788 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4789 | "O&:confstr", |
| 4790 | conv_confstr_confname, &name)) |
| 4791 | goto exit; |
| 4792 | return_value = os_confstr_impl(module, name); |
| 4793 | |
| 4794 | exit: |
| 4795 | return return_value; |
| 4796 | } |
| 4797 | |
| 4798 | #endif /* defined(HAVE_CONFSTR) */ |
| 4799 | |
| 4800 | #if defined(HAVE_SYSCONF) |
| 4801 | |
| 4802 | PyDoc_STRVAR(os_sysconf__doc__, |
| 4803 | "sysconf($module, name, /)\n" |
| 4804 | "--\n" |
| 4805 | "\n" |
| 4806 | "Return an integer-valued system configuration variable."); |
| 4807 | |
| 4808 | #define OS_SYSCONF_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4809 | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4810 | |
| 4811 | static long |
| 4812 | os_sysconf_impl(PyModuleDef *module, int name); |
| 4813 | |
| 4814 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4815 | os_sysconf(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4816 | { |
| 4817 | PyObject *return_value = NULL; |
| 4818 | int name; |
| 4819 | long _return_value; |
| 4820 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 4821 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4822 | "O&:sysconf", |
| 4823 | conv_sysconf_confname, &name)) |
| 4824 | goto exit; |
| 4825 | _return_value = os_sysconf_impl(module, name); |
| 4826 | if ((_return_value == -1) && PyErr_Occurred()) |
| 4827 | goto exit; |
| 4828 | return_value = PyLong_FromLong(_return_value); |
| 4829 | |
| 4830 | exit: |
| 4831 | return return_value; |
| 4832 | } |
| 4833 | |
| 4834 | #endif /* defined(HAVE_SYSCONF) */ |
| 4835 | |
| 4836 | PyDoc_STRVAR(os_abort__doc__, |
| 4837 | "abort($module, /)\n" |
| 4838 | "--\n" |
| 4839 | "\n" |
| 4840 | "Abort the interpreter immediately.\n" |
| 4841 | "\n" |
| 4842 | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
| 4843 | "on the hosting operating system. This function never returns."); |
| 4844 | |
| 4845 | #define OS_ABORT_METHODDEF \ |
| 4846 | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
| 4847 | |
| 4848 | static PyObject * |
| 4849 | os_abort_impl(PyModuleDef *module); |
| 4850 | |
| 4851 | static PyObject * |
| 4852 | os_abort(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 4853 | { |
| 4854 | return os_abort_impl(module); |
| 4855 | } |
| 4856 | |
| 4857 | #if defined(HAVE_GETLOADAVG) |
| 4858 | |
| 4859 | PyDoc_STRVAR(os_getloadavg__doc__, |
| 4860 | "getloadavg($module, /)\n" |
| 4861 | "--\n" |
| 4862 | "\n" |
| 4863 | "Return average recent system load information.\n" |
| 4864 | "\n" |
| 4865 | "Return the number of processes in the system run queue averaged over\n" |
| 4866 | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
| 4867 | "Raises OSError if the load average was unobtainable."); |
| 4868 | |
| 4869 | #define OS_GETLOADAVG_METHODDEF \ |
| 4870 | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
| 4871 | |
| 4872 | static PyObject * |
| 4873 | os_getloadavg_impl(PyModuleDef *module); |
| 4874 | |
| 4875 | static PyObject * |
| 4876 | os_getloadavg(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 4877 | { |
| 4878 | return os_getloadavg_impl(module); |
| 4879 | } |
| 4880 | |
| 4881 | #endif /* defined(HAVE_GETLOADAVG) */ |
| 4882 | |
| 4883 | PyDoc_STRVAR(os_device_encoding__doc__, |
| 4884 | "device_encoding($module, /, fd)\n" |
| 4885 | "--\n" |
| 4886 | "\n" |
| 4887 | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
| 4888 | "\n" |
| 4889 | "The file descriptor must be attached to a terminal.\n" |
| 4890 | "If the device is not a terminal, return None."); |
| 4891 | |
| 4892 | #define OS_DEVICE_ENCODING_METHODDEF \ |
| 4893 | {"device_encoding", (PyCFunction)os_device_encoding, METH_VARARGS|METH_KEYWORDS, os_device_encoding__doc__}, |
| 4894 | |
| 4895 | static PyObject * |
| 4896 | os_device_encoding_impl(PyModuleDef *module, int fd); |
| 4897 | |
| 4898 | static PyObject * |
| 4899 | os_device_encoding(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 4900 | { |
| 4901 | PyObject *return_value = NULL; |
| 4902 | static char *_keywords[] = {"fd", NULL}; |
| 4903 | int fd; |
| 4904 | |
| 4905 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 4906 | "i:device_encoding", _keywords, |
| 4907 | &fd)) |
| 4908 | goto exit; |
| 4909 | return_value = os_device_encoding_impl(module, fd); |
| 4910 | |
| 4911 | exit: |
| 4912 | return return_value; |
| 4913 | } |
| 4914 | |
| 4915 | #if defined(HAVE_SETRESUID) |
| 4916 | |
| 4917 | PyDoc_STRVAR(os_setresuid__doc__, |
| 4918 | "setresuid($module, ruid, euid, suid, /)\n" |
| 4919 | "--\n" |
| 4920 | "\n" |
| 4921 | "Set the current process\'s real, effective, and saved user ids."); |
| 4922 | |
| 4923 | #define OS_SETRESUID_METHODDEF \ |
| 4924 | {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__}, |
| 4925 | |
| 4926 | static PyObject * |
| 4927 | os_setresuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid, uid_t suid); |
| 4928 | |
| 4929 | static PyObject * |
| 4930 | os_setresuid(PyModuleDef *module, PyObject *args) |
| 4931 | { |
| 4932 | PyObject *return_value = NULL; |
| 4933 | uid_t ruid; |
| 4934 | uid_t euid; |
| 4935 | uid_t suid; |
| 4936 | |
| 4937 | if (!PyArg_ParseTuple(args, |
| 4938 | "O&O&O&:setresuid", |
| 4939 | _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) |
| 4940 | goto exit; |
| 4941 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
| 4942 | |
| 4943 | exit: |
| 4944 | return return_value; |
| 4945 | } |
| 4946 | |
| 4947 | #endif /* defined(HAVE_SETRESUID) */ |
| 4948 | |
| 4949 | #if defined(HAVE_SETRESGID) |
| 4950 | |
| 4951 | PyDoc_STRVAR(os_setresgid__doc__, |
| 4952 | "setresgid($module, rgid, egid, sgid, /)\n" |
| 4953 | "--\n" |
| 4954 | "\n" |
| 4955 | "Set the current process\'s real, effective, and saved group ids."); |
| 4956 | |
| 4957 | #define OS_SETRESGID_METHODDEF \ |
| 4958 | {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__}, |
| 4959 | |
| 4960 | static PyObject * |
| 4961 | os_setresgid_impl(PyModuleDef *module, gid_t rgid, gid_t egid, gid_t sgid); |
| 4962 | |
| 4963 | static PyObject * |
| 4964 | os_setresgid(PyModuleDef *module, PyObject *args) |
| 4965 | { |
| 4966 | PyObject *return_value = NULL; |
| 4967 | gid_t rgid; |
| 4968 | gid_t egid; |
| 4969 | gid_t sgid; |
| 4970 | |
| 4971 | if (!PyArg_ParseTuple(args, |
| 4972 | "O&O&O&:setresgid", |
| 4973 | _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) |
| 4974 | goto exit; |
| 4975 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
| 4976 | |
| 4977 | exit: |
| 4978 | return return_value; |
| 4979 | } |
| 4980 | |
| 4981 | #endif /* defined(HAVE_SETRESGID) */ |
| 4982 | |
| 4983 | #if defined(HAVE_GETRESUID) |
| 4984 | |
| 4985 | PyDoc_STRVAR(os_getresuid__doc__, |
| 4986 | "getresuid($module, /)\n" |
| 4987 | "--\n" |
| 4988 | "\n" |
| 4989 | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
| 4990 | |
| 4991 | #define OS_GETRESUID_METHODDEF \ |
| 4992 | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
| 4993 | |
| 4994 | static PyObject * |
| 4995 | os_getresuid_impl(PyModuleDef *module); |
| 4996 | |
| 4997 | static PyObject * |
| 4998 | os_getresuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 4999 | { |
| 5000 | return os_getresuid_impl(module); |
| 5001 | } |
| 5002 | |
| 5003 | #endif /* defined(HAVE_GETRESUID) */ |
| 5004 | |
| 5005 | #if defined(HAVE_GETRESGID) |
| 5006 | |
| 5007 | PyDoc_STRVAR(os_getresgid__doc__, |
| 5008 | "getresgid($module, /)\n" |
| 5009 | "--\n" |
| 5010 | "\n" |
| 5011 | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
| 5012 | |
| 5013 | #define OS_GETRESGID_METHODDEF \ |
| 5014 | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
| 5015 | |
| 5016 | static PyObject * |
| 5017 | os_getresgid_impl(PyModuleDef *module); |
| 5018 | |
| 5019 | static PyObject * |
| 5020 | os_getresgid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 5021 | { |
| 5022 | return os_getresgid_impl(module); |
| 5023 | } |
| 5024 | |
| 5025 | #endif /* defined(HAVE_GETRESGID) */ |
| 5026 | |
| 5027 | #if defined(USE_XATTRS) |
| 5028 | |
| 5029 | PyDoc_STRVAR(os_getxattr__doc__, |
| 5030 | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 5031 | "--\n" |
| 5032 | "\n" |
| 5033 | "Return the value of extended attribute attribute on path.\n" |
| 5034 | "\n" |
| 5035 | "path may be either a string or an open file descriptor.\n" |
| 5036 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 5037 | " link, getxattr will examine the symbolic link itself instead of the file\n" |
| 5038 | " the link points to."); |
| 5039 | |
| 5040 | #define OS_GETXATTR_METHODDEF \ |
| 5041 | {"getxattr", (PyCFunction)os_getxattr, METH_VARARGS|METH_KEYWORDS, os_getxattr__doc__}, |
| 5042 | |
| 5043 | static PyObject * |
| 5044 | os_getxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks); |
| 5045 | |
| 5046 | static PyObject * |
| 5047 | os_getxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 5048 | { |
| 5049 | PyObject *return_value = NULL; |
| 5050 | static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
| 5051 | path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1); |
| 5052 | path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0); |
| 5053 | int follow_symlinks = 1; |
| 5054 | |
| 5055 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 5056 | "O&O&|$p:getxattr", _keywords, |
| 5057 | path_converter, &path, path_converter, &attribute, &follow_symlinks)) |
| 5058 | goto exit; |
| 5059 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
| 5060 | |
| 5061 | exit: |
| 5062 | /* Cleanup for path */ |
| 5063 | path_cleanup(&path); |
| 5064 | /* Cleanup for attribute */ |
| 5065 | path_cleanup(&attribute); |
| 5066 | |
| 5067 | return return_value; |
| 5068 | } |
| 5069 | |
| 5070 | #endif /* defined(USE_XATTRS) */ |
| 5071 | |
| 5072 | #if defined(USE_XATTRS) |
| 5073 | |
| 5074 | PyDoc_STRVAR(os_setxattr__doc__, |
| 5075 | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
| 5076 | " follow_symlinks=True)\n" |
| 5077 | "--\n" |
| 5078 | "\n" |
| 5079 | "Set extended attribute attribute on path to value.\n" |
| 5080 | "\n" |
| 5081 | "path may be either a string or an open file descriptor.\n" |
| 5082 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 5083 | " link, setxattr will modify the symbolic link itself instead of the file\n" |
| 5084 | " the link points to."); |
| 5085 | |
| 5086 | #define OS_SETXATTR_METHODDEF \ |
| 5087 | {"setxattr", (PyCFunction)os_setxattr, METH_VARARGS|METH_KEYWORDS, os_setxattr__doc__}, |
| 5088 | |
| 5089 | static PyObject * |
| 5090 | os_setxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, Py_buffer *value, int flags, int follow_symlinks); |
| 5091 | |
| 5092 | static PyObject * |
| 5093 | os_setxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 5094 | { |
| 5095 | PyObject *return_value = NULL; |
| 5096 | static char *_keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
| 5097 | path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1); |
| 5098 | path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0); |
| 5099 | Py_buffer value = {NULL, NULL}; |
| 5100 | int flags = 0; |
| 5101 | int follow_symlinks = 1; |
| 5102 | |
| 5103 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 5104 | "O&O&y*|i$p:setxattr", _keywords, |
| 5105 | path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) |
| 5106 | goto exit; |
| 5107 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
| 5108 | |
| 5109 | exit: |
| 5110 | /* Cleanup for path */ |
| 5111 | path_cleanup(&path); |
| 5112 | /* Cleanup for attribute */ |
| 5113 | path_cleanup(&attribute); |
| 5114 | /* Cleanup for value */ |
| 5115 | if (value.obj) |
| 5116 | PyBuffer_Release(&value); |
| 5117 | |
| 5118 | return return_value; |
| 5119 | } |
| 5120 | |
| 5121 | #endif /* defined(USE_XATTRS) */ |
| 5122 | |
| 5123 | #if defined(USE_XATTRS) |
| 5124 | |
| 5125 | PyDoc_STRVAR(os_removexattr__doc__, |
| 5126 | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 5127 | "--\n" |
| 5128 | "\n" |
| 5129 | "Remove extended attribute attribute on path.\n" |
| 5130 | "\n" |
| 5131 | "path may be either a string or an open file descriptor.\n" |
| 5132 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 5133 | " link, removexattr will modify the symbolic link itself instead of the file\n" |
| 5134 | " the link points to."); |
| 5135 | |
| 5136 | #define OS_REMOVEXATTR_METHODDEF \ |
| 5137 | {"removexattr", (PyCFunction)os_removexattr, METH_VARARGS|METH_KEYWORDS, os_removexattr__doc__}, |
| 5138 | |
| 5139 | static PyObject * |
| 5140 | os_removexattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks); |
| 5141 | |
| 5142 | static PyObject * |
| 5143 | os_removexattr(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 5144 | { |
| 5145 | PyObject *return_value = NULL; |
| 5146 | static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
| 5147 | path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1); |
| 5148 | path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0); |
| 5149 | int follow_symlinks = 1; |
| 5150 | |
| 5151 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 5152 | "O&O&|$p:removexattr", _keywords, |
| 5153 | path_converter, &path, path_converter, &attribute, &follow_symlinks)) |
| 5154 | goto exit; |
| 5155 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
| 5156 | |
| 5157 | exit: |
| 5158 | /* Cleanup for path */ |
| 5159 | path_cleanup(&path); |
| 5160 | /* Cleanup for attribute */ |
| 5161 | path_cleanup(&attribute); |
| 5162 | |
| 5163 | return return_value; |
| 5164 | } |
| 5165 | |
| 5166 | #endif /* defined(USE_XATTRS) */ |
| 5167 | |
| 5168 | #if defined(USE_XATTRS) |
| 5169 | |
| 5170 | PyDoc_STRVAR(os_listxattr__doc__, |
| 5171 | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
| 5172 | "--\n" |
| 5173 | "\n" |
| 5174 | "Return a list of extended attributes on path.\n" |
| 5175 | "\n" |
| 5176 | "path may be either None, a string, or an open file descriptor.\n" |
| 5177 | "if path is None, listxattr will examine the current directory.\n" |
| 5178 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 5179 | " link, listxattr will examine the symbolic link itself instead of the file\n" |
| 5180 | " the link points to."); |
| 5181 | |
| 5182 | #define OS_LISTXATTR_METHODDEF \ |
| 5183 | {"listxattr", (PyCFunction)os_listxattr, METH_VARARGS|METH_KEYWORDS, os_listxattr__doc__}, |
| 5184 | |
| 5185 | static PyObject * |
| 5186 | os_listxattr_impl(PyModuleDef *module, path_t *path, int follow_symlinks); |
| 5187 | |
| 5188 | static PyObject * |
| 5189 | os_listxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 5190 | { |
| 5191 | PyObject *return_value = NULL; |
| 5192 | static char *_keywords[] = {"path", "follow_symlinks", NULL}; |
| 5193 | path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1); |
| 5194 | int follow_symlinks = 1; |
| 5195 | |
| 5196 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 5197 | "|O&$p:listxattr", _keywords, |
| 5198 | path_converter, &path, &follow_symlinks)) |
| 5199 | goto exit; |
| 5200 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
| 5201 | |
| 5202 | exit: |
| 5203 | /* Cleanup for path */ |
| 5204 | path_cleanup(&path); |
| 5205 | |
| 5206 | return return_value; |
| 5207 | } |
| 5208 | |
| 5209 | #endif /* defined(USE_XATTRS) */ |
| 5210 | |
| 5211 | PyDoc_STRVAR(os_urandom__doc__, |
| 5212 | "urandom($module, size, /)\n" |
| 5213 | "--\n" |
| 5214 | "\n" |
| 5215 | "Return a bytes object containing random bytes suitable for cryptographic use."); |
| 5216 | |
| 5217 | #define OS_URANDOM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5218 | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5219 | |
| 5220 | static PyObject * |
| 5221 | os_urandom_impl(PyModuleDef *module, Py_ssize_t size); |
| 5222 | |
| 5223 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5224 | os_urandom(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5225 | { |
| 5226 | PyObject *return_value = NULL; |
| 5227 | Py_ssize_t size; |
| 5228 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5229 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5230 | "n:urandom", |
| 5231 | &size)) |
| 5232 | goto exit; |
| 5233 | return_value = os_urandom_impl(module, size); |
| 5234 | |
| 5235 | exit: |
| 5236 | return return_value; |
| 5237 | } |
| 5238 | |
| 5239 | PyDoc_STRVAR(os_cpu_count__doc__, |
| 5240 | "cpu_count($module, /)\n" |
| 5241 | "--\n" |
| 5242 | "\n" |
| 5243 | "Return the number of CPUs in the system; return None if indeterminable."); |
| 5244 | |
| 5245 | #define OS_CPU_COUNT_METHODDEF \ |
| 5246 | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
| 5247 | |
| 5248 | static PyObject * |
| 5249 | os_cpu_count_impl(PyModuleDef *module); |
| 5250 | |
| 5251 | static PyObject * |
| 5252 | os_cpu_count(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 5253 | { |
| 5254 | return os_cpu_count_impl(module); |
| 5255 | } |
| 5256 | |
| 5257 | PyDoc_STRVAR(os_get_inheritable__doc__, |
| 5258 | "get_inheritable($module, fd, /)\n" |
| 5259 | "--\n" |
| 5260 | "\n" |
| 5261 | "Get the close-on-exe flag of the specified file descriptor."); |
| 5262 | |
| 5263 | #define OS_GET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5264 | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5265 | |
| 5266 | static int |
| 5267 | os_get_inheritable_impl(PyModuleDef *module, int fd); |
| 5268 | |
| 5269 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5270 | os_get_inheritable(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5271 | { |
| 5272 | PyObject *return_value = NULL; |
| 5273 | int fd; |
| 5274 | int _return_value; |
| 5275 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5276 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5277 | "i:get_inheritable", |
| 5278 | &fd)) |
| 5279 | goto exit; |
| 5280 | _return_value = os_get_inheritable_impl(module, fd); |
| 5281 | if ((_return_value == -1) && PyErr_Occurred()) |
| 5282 | goto exit; |
| 5283 | return_value = PyBool_FromLong((long)_return_value); |
| 5284 | |
| 5285 | exit: |
| 5286 | return return_value; |
| 5287 | } |
| 5288 | |
| 5289 | PyDoc_STRVAR(os_set_inheritable__doc__, |
| 5290 | "set_inheritable($module, fd, inheritable, /)\n" |
| 5291 | "--\n" |
| 5292 | "\n" |
| 5293 | "Set the inheritable flag of the specified file descriptor."); |
| 5294 | |
| 5295 | #define OS_SET_INHERITABLE_METHODDEF \ |
| 5296 | {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__}, |
| 5297 | |
| 5298 | static PyObject * |
| 5299 | os_set_inheritable_impl(PyModuleDef *module, int fd, int inheritable); |
| 5300 | |
| 5301 | static PyObject * |
| 5302 | os_set_inheritable(PyModuleDef *module, PyObject *args) |
| 5303 | { |
| 5304 | PyObject *return_value = NULL; |
| 5305 | int fd; |
| 5306 | int inheritable; |
| 5307 | |
| 5308 | if (!PyArg_ParseTuple(args, |
| 5309 | "ii:set_inheritable", |
| 5310 | &fd, &inheritable)) |
| 5311 | goto exit; |
| 5312 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
| 5313 | |
| 5314 | exit: |
| 5315 | return return_value; |
| 5316 | } |
| 5317 | |
| 5318 | #if defined(MS_WINDOWS) |
| 5319 | |
| 5320 | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
| 5321 | "get_handle_inheritable($module, handle, /)\n" |
| 5322 | "--\n" |
| 5323 | "\n" |
| 5324 | "Get the close-on-exe flag of the specified file descriptor."); |
| 5325 | |
| 5326 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5327 | {"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] | 5328 | |
| 5329 | static int |
| 5330 | os_get_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle); |
| 5331 | |
| 5332 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5333 | os_get_handle_inheritable(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5334 | { |
| 5335 | PyObject *return_value = NULL; |
| 5336 | Py_intptr_t handle; |
| 5337 | int _return_value; |
| 5338 | |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5339 | if (!PyArg_Parse(arg, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5340 | "" _Py_PARSE_INTPTR ":get_handle_inheritable", |
| 5341 | &handle)) |
| 5342 | goto exit; |
| 5343 | _return_value = os_get_handle_inheritable_impl(module, handle); |
| 5344 | if ((_return_value == -1) && PyErr_Occurred()) |
| 5345 | goto exit; |
| 5346 | return_value = PyBool_FromLong((long)_return_value); |
| 5347 | |
| 5348 | exit: |
| 5349 | return return_value; |
| 5350 | } |
| 5351 | |
| 5352 | #endif /* defined(MS_WINDOWS) */ |
| 5353 | |
| 5354 | #if defined(MS_WINDOWS) |
| 5355 | |
| 5356 | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
| 5357 | "set_handle_inheritable($module, handle, inheritable, /)\n" |
| 5358 | "--\n" |
| 5359 | "\n" |
| 5360 | "Set the inheritable flag of the specified handle."); |
| 5361 | |
| 5362 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
| 5363 | {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__}, |
| 5364 | |
| 5365 | static PyObject * |
| 5366 | os_set_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle, int inheritable); |
| 5367 | |
| 5368 | static PyObject * |
| 5369 | os_set_handle_inheritable(PyModuleDef *module, PyObject *args) |
| 5370 | { |
| 5371 | PyObject *return_value = NULL; |
| 5372 | Py_intptr_t handle; |
| 5373 | int inheritable; |
| 5374 | |
| 5375 | if (!PyArg_ParseTuple(args, |
| 5376 | "" _Py_PARSE_INTPTR "p:set_handle_inheritable", |
| 5377 | &handle, &inheritable)) |
| 5378 | goto exit; |
| 5379 | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
| 5380 | |
| 5381 | exit: |
| 5382 | return return_value; |
| 5383 | } |
| 5384 | |
| 5385 | #endif /* defined(MS_WINDOWS) */ |
| 5386 | |
| 5387 | #ifndef OS_TTYNAME_METHODDEF |
| 5388 | #define OS_TTYNAME_METHODDEF |
| 5389 | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
| 5390 | |
| 5391 | #ifndef OS_CTERMID_METHODDEF |
| 5392 | #define OS_CTERMID_METHODDEF |
| 5393 | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
| 5394 | |
| 5395 | #ifndef OS_FCHDIR_METHODDEF |
| 5396 | #define OS_FCHDIR_METHODDEF |
| 5397 | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
| 5398 | |
| 5399 | #ifndef OS_FCHMOD_METHODDEF |
| 5400 | #define OS_FCHMOD_METHODDEF |
| 5401 | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
| 5402 | |
| 5403 | #ifndef OS_LCHMOD_METHODDEF |
| 5404 | #define OS_LCHMOD_METHODDEF |
| 5405 | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
| 5406 | |
| 5407 | #ifndef OS_CHFLAGS_METHODDEF |
| 5408 | #define OS_CHFLAGS_METHODDEF |
| 5409 | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
| 5410 | |
| 5411 | #ifndef OS_LCHFLAGS_METHODDEF |
| 5412 | #define OS_LCHFLAGS_METHODDEF |
| 5413 | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
| 5414 | |
| 5415 | #ifndef OS_CHROOT_METHODDEF |
| 5416 | #define OS_CHROOT_METHODDEF |
| 5417 | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
| 5418 | |
| 5419 | #ifndef OS_FSYNC_METHODDEF |
| 5420 | #define OS_FSYNC_METHODDEF |
| 5421 | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
| 5422 | |
| 5423 | #ifndef OS_SYNC_METHODDEF |
| 5424 | #define OS_SYNC_METHODDEF |
| 5425 | #endif /* !defined(OS_SYNC_METHODDEF) */ |
| 5426 | |
| 5427 | #ifndef OS_FDATASYNC_METHODDEF |
| 5428 | #define OS_FDATASYNC_METHODDEF |
| 5429 | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
| 5430 | |
| 5431 | #ifndef OS_CHOWN_METHODDEF |
| 5432 | #define OS_CHOWN_METHODDEF |
| 5433 | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
| 5434 | |
| 5435 | #ifndef OS_FCHOWN_METHODDEF |
| 5436 | #define OS_FCHOWN_METHODDEF |
| 5437 | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
| 5438 | |
| 5439 | #ifndef OS_LCHOWN_METHODDEF |
| 5440 | #define OS_LCHOWN_METHODDEF |
| 5441 | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
| 5442 | |
| 5443 | #ifndef OS_LINK_METHODDEF |
| 5444 | #define OS_LINK_METHODDEF |
| 5445 | #endif /* !defined(OS_LINK_METHODDEF) */ |
| 5446 | |
| 5447 | #ifndef OS__GETFINALPATHNAME_METHODDEF |
| 5448 | #define OS__GETFINALPATHNAME_METHODDEF |
| 5449 | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
| 5450 | |
| 5451 | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
| 5452 | #define OS__GETVOLUMEPATHNAME_METHODDEF |
| 5453 | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
| 5454 | |
| 5455 | #ifndef OS_NICE_METHODDEF |
| 5456 | #define OS_NICE_METHODDEF |
| 5457 | #endif /* !defined(OS_NICE_METHODDEF) */ |
| 5458 | |
| 5459 | #ifndef OS_GETPRIORITY_METHODDEF |
| 5460 | #define OS_GETPRIORITY_METHODDEF |
| 5461 | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
| 5462 | |
| 5463 | #ifndef OS_SETPRIORITY_METHODDEF |
| 5464 | #define OS_SETPRIORITY_METHODDEF |
| 5465 | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
| 5466 | |
| 5467 | #ifndef OS_SYSTEM_METHODDEF |
| 5468 | #define OS_SYSTEM_METHODDEF |
| 5469 | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
| 5470 | |
| 5471 | #ifndef OS_UNAME_METHODDEF |
| 5472 | #define OS_UNAME_METHODDEF |
| 5473 | #endif /* !defined(OS_UNAME_METHODDEF) */ |
| 5474 | |
| 5475 | #ifndef OS_EXECV_METHODDEF |
| 5476 | #define OS_EXECV_METHODDEF |
| 5477 | #endif /* !defined(OS_EXECV_METHODDEF) */ |
| 5478 | |
| 5479 | #ifndef OS_EXECVE_METHODDEF |
| 5480 | #define OS_EXECVE_METHODDEF |
| 5481 | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
| 5482 | |
| 5483 | #ifndef OS_SPAWNV_METHODDEF |
| 5484 | #define OS_SPAWNV_METHODDEF |
| 5485 | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
| 5486 | |
| 5487 | #ifndef OS_SPAWNVE_METHODDEF |
| 5488 | #define OS_SPAWNVE_METHODDEF |
| 5489 | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
| 5490 | |
| 5491 | #ifndef OS_FORK1_METHODDEF |
| 5492 | #define OS_FORK1_METHODDEF |
| 5493 | #endif /* !defined(OS_FORK1_METHODDEF) */ |
| 5494 | |
| 5495 | #ifndef OS_FORK_METHODDEF |
| 5496 | #define OS_FORK_METHODDEF |
| 5497 | #endif /* !defined(OS_FORK_METHODDEF) */ |
| 5498 | |
| 5499 | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 5500 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 5501 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
| 5502 | |
| 5503 | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 5504 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 5505 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
| 5506 | |
| 5507 | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
| 5508 | #define OS_SCHED_GETSCHEDULER_METHODDEF |
| 5509 | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
| 5510 | |
| 5511 | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
| 5512 | #define OS_SCHED_SETSCHEDULER_METHODDEF |
| 5513 | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
| 5514 | |
| 5515 | #ifndef OS_SCHED_GETPARAM_METHODDEF |
| 5516 | #define OS_SCHED_GETPARAM_METHODDEF |
| 5517 | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
| 5518 | |
| 5519 | #ifndef OS_SCHED_SETPARAM_METHODDEF |
| 5520 | #define OS_SCHED_SETPARAM_METHODDEF |
| 5521 | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
| 5522 | |
| 5523 | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 5524 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 5525 | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
| 5526 | |
| 5527 | #ifndef OS_SCHED_YIELD_METHODDEF |
| 5528 | #define OS_SCHED_YIELD_METHODDEF |
| 5529 | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
| 5530 | |
| 5531 | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
| 5532 | #define OS_SCHED_SETAFFINITY_METHODDEF |
| 5533 | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
| 5534 | |
| 5535 | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
| 5536 | #define OS_SCHED_GETAFFINITY_METHODDEF |
| 5537 | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
| 5538 | |
| 5539 | #ifndef OS_OPENPTY_METHODDEF |
| 5540 | #define OS_OPENPTY_METHODDEF |
| 5541 | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
| 5542 | |
| 5543 | #ifndef OS_FORKPTY_METHODDEF |
| 5544 | #define OS_FORKPTY_METHODDEF |
| 5545 | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
| 5546 | |
| 5547 | #ifndef OS_GETEGID_METHODDEF |
| 5548 | #define OS_GETEGID_METHODDEF |
| 5549 | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
| 5550 | |
| 5551 | #ifndef OS_GETEUID_METHODDEF |
| 5552 | #define OS_GETEUID_METHODDEF |
| 5553 | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
| 5554 | |
| 5555 | #ifndef OS_GETGID_METHODDEF |
| 5556 | #define OS_GETGID_METHODDEF |
| 5557 | #endif /* !defined(OS_GETGID_METHODDEF) */ |
| 5558 | |
| 5559 | #ifndef OS_GETGROUPS_METHODDEF |
| 5560 | #define OS_GETGROUPS_METHODDEF |
| 5561 | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
| 5562 | |
| 5563 | #ifndef OS_GETPGID_METHODDEF |
| 5564 | #define OS_GETPGID_METHODDEF |
| 5565 | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
| 5566 | |
| 5567 | #ifndef OS_GETPGRP_METHODDEF |
| 5568 | #define OS_GETPGRP_METHODDEF |
| 5569 | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
| 5570 | |
| 5571 | #ifndef OS_SETPGRP_METHODDEF |
| 5572 | #define OS_SETPGRP_METHODDEF |
| 5573 | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
| 5574 | |
| 5575 | #ifndef OS_GETPPID_METHODDEF |
| 5576 | #define OS_GETPPID_METHODDEF |
| 5577 | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
| 5578 | |
| 5579 | #ifndef OS_GETLOGIN_METHODDEF |
| 5580 | #define OS_GETLOGIN_METHODDEF |
| 5581 | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
| 5582 | |
| 5583 | #ifndef OS_GETUID_METHODDEF |
| 5584 | #define OS_GETUID_METHODDEF |
| 5585 | #endif /* !defined(OS_GETUID_METHODDEF) */ |
| 5586 | |
| 5587 | #ifndef OS_KILL_METHODDEF |
| 5588 | #define OS_KILL_METHODDEF |
| 5589 | #endif /* !defined(OS_KILL_METHODDEF) */ |
| 5590 | |
| 5591 | #ifndef OS_KILLPG_METHODDEF |
| 5592 | #define OS_KILLPG_METHODDEF |
| 5593 | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
| 5594 | |
| 5595 | #ifndef OS_PLOCK_METHODDEF |
| 5596 | #define OS_PLOCK_METHODDEF |
| 5597 | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
| 5598 | |
| 5599 | #ifndef OS_SETUID_METHODDEF |
| 5600 | #define OS_SETUID_METHODDEF |
| 5601 | #endif /* !defined(OS_SETUID_METHODDEF) */ |
| 5602 | |
| 5603 | #ifndef OS_SETEUID_METHODDEF |
| 5604 | #define OS_SETEUID_METHODDEF |
| 5605 | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
| 5606 | |
| 5607 | #ifndef OS_SETEGID_METHODDEF |
| 5608 | #define OS_SETEGID_METHODDEF |
| 5609 | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
| 5610 | |
| 5611 | #ifndef OS_SETREUID_METHODDEF |
| 5612 | #define OS_SETREUID_METHODDEF |
| 5613 | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
| 5614 | |
| 5615 | #ifndef OS_SETREGID_METHODDEF |
| 5616 | #define OS_SETREGID_METHODDEF |
| 5617 | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
| 5618 | |
| 5619 | #ifndef OS_SETGID_METHODDEF |
| 5620 | #define OS_SETGID_METHODDEF |
| 5621 | #endif /* !defined(OS_SETGID_METHODDEF) */ |
| 5622 | |
| 5623 | #ifndef OS_SETGROUPS_METHODDEF |
| 5624 | #define OS_SETGROUPS_METHODDEF |
| 5625 | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
| 5626 | |
| 5627 | #ifndef OS_WAIT3_METHODDEF |
| 5628 | #define OS_WAIT3_METHODDEF |
| 5629 | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
| 5630 | |
| 5631 | #ifndef OS_WAIT4_METHODDEF |
| 5632 | #define OS_WAIT4_METHODDEF |
| 5633 | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
| 5634 | |
| 5635 | #ifndef OS_WAITID_METHODDEF |
| 5636 | #define OS_WAITID_METHODDEF |
| 5637 | #endif /* !defined(OS_WAITID_METHODDEF) */ |
| 5638 | |
| 5639 | #ifndef OS_WAITPID_METHODDEF |
| 5640 | #define OS_WAITPID_METHODDEF |
| 5641 | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
| 5642 | |
| 5643 | #ifndef OS_WAIT_METHODDEF |
| 5644 | #define OS_WAIT_METHODDEF |
| 5645 | #endif /* !defined(OS_WAIT_METHODDEF) */ |
| 5646 | |
| 5647 | #ifndef OS_SYMLINK_METHODDEF |
| 5648 | #define OS_SYMLINK_METHODDEF |
| 5649 | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
| 5650 | |
| 5651 | #ifndef OS_TIMES_METHODDEF |
| 5652 | #define OS_TIMES_METHODDEF |
| 5653 | #endif /* !defined(OS_TIMES_METHODDEF) */ |
| 5654 | |
| 5655 | #ifndef OS_GETSID_METHODDEF |
| 5656 | #define OS_GETSID_METHODDEF |
| 5657 | #endif /* !defined(OS_GETSID_METHODDEF) */ |
| 5658 | |
| 5659 | #ifndef OS_SETSID_METHODDEF |
| 5660 | #define OS_SETSID_METHODDEF |
| 5661 | #endif /* !defined(OS_SETSID_METHODDEF) */ |
| 5662 | |
| 5663 | #ifndef OS_SETPGID_METHODDEF |
| 5664 | #define OS_SETPGID_METHODDEF |
| 5665 | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
| 5666 | |
| 5667 | #ifndef OS_TCGETPGRP_METHODDEF |
| 5668 | #define OS_TCGETPGRP_METHODDEF |
| 5669 | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
| 5670 | |
| 5671 | #ifndef OS_TCSETPGRP_METHODDEF |
| 5672 | #define OS_TCSETPGRP_METHODDEF |
| 5673 | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
| 5674 | |
| 5675 | #ifndef OS_LOCKF_METHODDEF |
| 5676 | #define OS_LOCKF_METHODDEF |
| 5677 | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
| 5678 | |
| 5679 | #ifndef OS_READV_METHODDEF |
| 5680 | #define OS_READV_METHODDEF |
| 5681 | #endif /* !defined(OS_READV_METHODDEF) */ |
| 5682 | |
| 5683 | #ifndef OS_PREAD_METHODDEF |
| 5684 | #define OS_PREAD_METHODDEF |
| 5685 | #endif /* !defined(OS_PREAD_METHODDEF) */ |
| 5686 | |
| 5687 | #ifndef OS_PIPE_METHODDEF |
| 5688 | #define OS_PIPE_METHODDEF |
| 5689 | #endif /* !defined(OS_PIPE_METHODDEF) */ |
| 5690 | |
| 5691 | #ifndef OS_PIPE2_METHODDEF |
| 5692 | #define OS_PIPE2_METHODDEF |
| 5693 | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
| 5694 | |
| 5695 | #ifndef OS_WRITEV_METHODDEF |
| 5696 | #define OS_WRITEV_METHODDEF |
| 5697 | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
| 5698 | |
| 5699 | #ifndef OS_PWRITE_METHODDEF |
| 5700 | #define OS_PWRITE_METHODDEF |
| 5701 | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
| 5702 | |
| 5703 | #ifndef OS_MKFIFO_METHODDEF |
| 5704 | #define OS_MKFIFO_METHODDEF |
| 5705 | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
| 5706 | |
| 5707 | #ifndef OS_MKNOD_METHODDEF |
| 5708 | #define OS_MKNOD_METHODDEF |
| 5709 | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
| 5710 | |
| 5711 | #ifndef OS_MAJOR_METHODDEF |
| 5712 | #define OS_MAJOR_METHODDEF |
| 5713 | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
| 5714 | |
| 5715 | #ifndef OS_MINOR_METHODDEF |
| 5716 | #define OS_MINOR_METHODDEF |
| 5717 | #endif /* !defined(OS_MINOR_METHODDEF) */ |
| 5718 | |
| 5719 | #ifndef OS_MAKEDEV_METHODDEF |
| 5720 | #define OS_MAKEDEV_METHODDEF |
| 5721 | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
| 5722 | |
| 5723 | #ifndef OS_FTRUNCATE_METHODDEF |
| 5724 | #define OS_FTRUNCATE_METHODDEF |
| 5725 | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
| 5726 | |
| 5727 | #ifndef OS_TRUNCATE_METHODDEF |
| 5728 | #define OS_TRUNCATE_METHODDEF |
| 5729 | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
| 5730 | |
| 5731 | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
| 5732 | #define OS_POSIX_FALLOCATE_METHODDEF |
| 5733 | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
| 5734 | |
| 5735 | #ifndef OS_POSIX_FADVISE_METHODDEF |
| 5736 | #define OS_POSIX_FADVISE_METHODDEF |
| 5737 | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
| 5738 | |
| 5739 | #ifndef OS_PUTENV_METHODDEF |
| 5740 | #define OS_PUTENV_METHODDEF |
| 5741 | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
| 5742 | |
| 5743 | #ifndef OS_UNSETENV_METHODDEF |
| 5744 | #define OS_UNSETENV_METHODDEF |
| 5745 | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
| 5746 | |
| 5747 | #ifndef OS_WCOREDUMP_METHODDEF |
| 5748 | #define OS_WCOREDUMP_METHODDEF |
| 5749 | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
| 5750 | |
| 5751 | #ifndef OS_WIFCONTINUED_METHODDEF |
| 5752 | #define OS_WIFCONTINUED_METHODDEF |
| 5753 | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
| 5754 | |
| 5755 | #ifndef OS_WIFSTOPPED_METHODDEF |
| 5756 | #define OS_WIFSTOPPED_METHODDEF |
| 5757 | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
| 5758 | |
| 5759 | #ifndef OS_WIFSIGNALED_METHODDEF |
| 5760 | #define OS_WIFSIGNALED_METHODDEF |
| 5761 | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
| 5762 | |
| 5763 | #ifndef OS_WIFEXITED_METHODDEF |
| 5764 | #define OS_WIFEXITED_METHODDEF |
| 5765 | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
| 5766 | |
| 5767 | #ifndef OS_WEXITSTATUS_METHODDEF |
| 5768 | #define OS_WEXITSTATUS_METHODDEF |
| 5769 | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
| 5770 | |
| 5771 | #ifndef OS_WTERMSIG_METHODDEF |
| 5772 | #define OS_WTERMSIG_METHODDEF |
| 5773 | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
| 5774 | |
| 5775 | #ifndef OS_WSTOPSIG_METHODDEF |
| 5776 | #define OS_WSTOPSIG_METHODDEF |
| 5777 | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
| 5778 | |
| 5779 | #ifndef OS_FSTATVFS_METHODDEF |
| 5780 | #define OS_FSTATVFS_METHODDEF |
| 5781 | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
| 5782 | |
| 5783 | #ifndef OS_STATVFS_METHODDEF |
| 5784 | #define OS_STATVFS_METHODDEF |
| 5785 | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
| 5786 | |
| 5787 | #ifndef OS__GETDISKUSAGE_METHODDEF |
| 5788 | #define OS__GETDISKUSAGE_METHODDEF |
| 5789 | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
| 5790 | |
| 5791 | #ifndef OS_FPATHCONF_METHODDEF |
| 5792 | #define OS_FPATHCONF_METHODDEF |
| 5793 | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
| 5794 | |
| 5795 | #ifndef OS_PATHCONF_METHODDEF |
| 5796 | #define OS_PATHCONF_METHODDEF |
| 5797 | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
| 5798 | |
| 5799 | #ifndef OS_CONFSTR_METHODDEF |
| 5800 | #define OS_CONFSTR_METHODDEF |
| 5801 | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
| 5802 | |
| 5803 | #ifndef OS_SYSCONF_METHODDEF |
| 5804 | #define OS_SYSCONF_METHODDEF |
| 5805 | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
| 5806 | |
| 5807 | #ifndef OS_GETLOADAVG_METHODDEF |
| 5808 | #define OS_GETLOADAVG_METHODDEF |
| 5809 | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
| 5810 | |
| 5811 | #ifndef OS_SETRESUID_METHODDEF |
| 5812 | #define OS_SETRESUID_METHODDEF |
| 5813 | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
| 5814 | |
| 5815 | #ifndef OS_SETRESGID_METHODDEF |
| 5816 | #define OS_SETRESGID_METHODDEF |
| 5817 | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
| 5818 | |
| 5819 | #ifndef OS_GETRESUID_METHODDEF |
| 5820 | #define OS_GETRESUID_METHODDEF |
| 5821 | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
| 5822 | |
| 5823 | #ifndef OS_GETRESGID_METHODDEF |
| 5824 | #define OS_GETRESGID_METHODDEF |
| 5825 | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
| 5826 | |
| 5827 | #ifndef OS_GETXATTR_METHODDEF |
| 5828 | #define OS_GETXATTR_METHODDEF |
| 5829 | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
| 5830 | |
| 5831 | #ifndef OS_SETXATTR_METHODDEF |
| 5832 | #define OS_SETXATTR_METHODDEF |
| 5833 | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
| 5834 | |
| 5835 | #ifndef OS_REMOVEXATTR_METHODDEF |
| 5836 | #define OS_REMOVEXATTR_METHODDEF |
| 5837 | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
| 5838 | |
| 5839 | #ifndef OS_LISTXATTR_METHODDEF |
| 5840 | #define OS_LISTXATTR_METHODDEF |
| 5841 | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
| 5842 | |
| 5843 | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 5844 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 5845 | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
| 5846 | |
| 5847 | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 5848 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 5849 | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame^] | 5850 | /*[clinic end generated code: output=b15ceac3a8ff0eae input=a9049054013a1b77]*/ |