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