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