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