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