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" |
Xiang Zhang | 4459e00 | 2017-01-22 13:04:17 +0800 | [diff] [blame] | 12 | " Path to be examined; can be string, bytes, path-like object or\n" |
| 13 | " open-file-descriptor int.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 14 | " dir_fd\n" |
| 15 | " If not None, it should be a file descriptor open to a directory,\n" |
| 16 | " and path should be a relative string; path will then be relative to\n" |
| 17 | " that directory.\n" |
| 18 | " follow_symlinks\n" |
| 19 | " If False, and the last element of the path is a symbolic link,\n" |
| 20 | " stat will examine the symbolic link itself instead of the file\n" |
| 21 | " the link points to.\n" |
| 22 | "\n" |
| 23 | "dir_fd and follow_symlinks may not be implemented\n" |
| 24 | " on your platform. If they are unavailable, using them will raise a\n" |
| 25 | " NotImplementedError.\n" |
| 26 | "\n" |
| 27 | "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 28 | " an open file descriptor."); |
| 29 | |
| 30 | #define OS_STAT_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 31 | {"stat", (PyCFunction)os_stat, METH_FASTCALL, os_stat__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 32 | |
| 33 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 34 | 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] | 35 | |
| 36 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 37 | os_stat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 38 | { |
| 39 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 40 | static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; |
| 41 | static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 42 | path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1); |
| 43 | int dir_fd = DEFAULT_DIR_FD; |
| 44 | int follow_symlinks = 1; |
| 45 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 46 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 47 | path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 48 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 49 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 50 | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
| 51 | |
| 52 | exit: |
| 53 | /* Cleanup for path */ |
| 54 | path_cleanup(&path); |
| 55 | |
| 56 | return return_value; |
| 57 | } |
| 58 | |
| 59 | PyDoc_STRVAR(os_lstat__doc__, |
| 60 | "lstat($module, /, path, *, dir_fd=None)\n" |
| 61 | "--\n" |
| 62 | "\n" |
| 63 | "Perform a stat system call on the given path, without following symbolic links.\n" |
| 64 | "\n" |
| 65 | "Like stat(), but do not follow symbolic links.\n" |
| 66 | "Equivalent to stat(path, follow_symlinks=False)."); |
| 67 | |
| 68 | #define OS_LSTAT_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 69 | {"lstat", (PyCFunction)os_lstat, METH_FASTCALL, os_lstat__doc__}, |
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_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 73 | |
| 74 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 75 | os_lstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 76 | { |
| 77 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 78 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 79 | static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 80 | path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0); |
| 81 | int dir_fd = DEFAULT_DIR_FD; |
| 82 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 83 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 84 | path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 85 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 86 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 87 | return_value = os_lstat_impl(module, &path, dir_fd); |
| 88 | |
| 89 | exit: |
| 90 | /* Cleanup for path */ |
| 91 | path_cleanup(&path); |
| 92 | |
| 93 | return return_value; |
| 94 | } |
| 95 | |
| 96 | PyDoc_STRVAR(os_access__doc__, |
| 97 | "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n" |
| 98 | " follow_symlinks=True)\n" |
| 99 | "--\n" |
| 100 | "\n" |
| 101 | "Use the real uid/gid to test for access to a path.\n" |
| 102 | "\n" |
| 103 | " path\n" |
Benjamin Peterson | 768f3b4 | 2016-09-05 15:29:33 -0700 | [diff] [blame] | 104 | " Path to be tested; can be string or bytes\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 105 | " mode\n" |
| 106 | " Operating-system mode bitfield. Can be F_OK to test existence,\n" |
| 107 | " or the inclusive-OR of R_OK, W_OK, and X_OK.\n" |
| 108 | " dir_fd\n" |
| 109 | " If not None, it should be a file descriptor open to a directory,\n" |
| 110 | " and path should be relative; path will then be relative to that\n" |
| 111 | " directory.\n" |
| 112 | " effective_ids\n" |
| 113 | " If True, access will use the effective uid/gid instead of\n" |
| 114 | " the real uid/gid.\n" |
| 115 | " follow_symlinks\n" |
| 116 | " If False, and the last element of the path is a symbolic link,\n" |
| 117 | " access will examine the symbolic link itself instead of the file\n" |
| 118 | " the link points to.\n" |
| 119 | "\n" |
| 120 | "dir_fd, effective_ids, and follow_symlinks may not be implemented\n" |
| 121 | " on your platform. If they are unavailable, using them will raise a\n" |
| 122 | " NotImplementedError.\n" |
| 123 | "\n" |
| 124 | "Note that most operations will use the effective uid/gid, therefore this\n" |
| 125 | " routine can be used in a suid/sgid environment to test if the invoking user\n" |
| 126 | " has the specified access to the path."); |
| 127 | |
| 128 | #define OS_ACCESS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 129 | {"access", (PyCFunction)os_access, METH_FASTCALL, os_access__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 130 | |
| 131 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 132 | 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] | 133 | int effective_ids, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 134 | |
| 135 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 136 | os_access(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 137 | { |
| 138 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 139 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL}; |
| 140 | static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0}; |
Benjamin Peterson | 768f3b4 | 2016-09-05 15:29:33 -0700 | [diff] [blame] | 141 | path_t path = PATH_T_INITIALIZE("access", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 142 | int mode; |
| 143 | int dir_fd = DEFAULT_DIR_FD; |
| 144 | int effective_ids = 0; |
| 145 | int follow_symlinks = 1; |
| 146 | int _return_value; |
| 147 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 148 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 149 | path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 150 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 151 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 152 | _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 153 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 154 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 155 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 156 | return_value = PyBool_FromLong((long)_return_value); |
| 157 | |
| 158 | exit: |
| 159 | /* Cleanup for path */ |
| 160 | path_cleanup(&path); |
| 161 | |
| 162 | return return_value; |
| 163 | } |
| 164 | |
| 165 | #if defined(HAVE_TTYNAME) |
| 166 | |
| 167 | PyDoc_STRVAR(os_ttyname__doc__, |
| 168 | "ttyname($module, fd, /)\n" |
| 169 | "--\n" |
| 170 | "\n" |
| 171 | "Return the name of the terminal device connected to \'fd\'.\n" |
| 172 | "\n" |
| 173 | " fd\n" |
| 174 | " Integer file descriptor handle."); |
| 175 | |
| 176 | #define OS_TTYNAME_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 177 | {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 178 | |
| 179 | static char * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 180 | os_ttyname_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 181 | |
| 182 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 183 | os_ttyname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 184 | { |
| 185 | PyObject *return_value = NULL; |
| 186 | int fd; |
| 187 | char *_return_value; |
| 188 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 189 | if (!PyArg_Parse(arg, "i:ttyname", &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 190 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 191 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 192 | _return_value = os_ttyname_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 193 | if (_return_value == NULL) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 194 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 195 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 196 | return_value = PyUnicode_DecodeFSDefault(_return_value); |
| 197 | |
| 198 | exit: |
| 199 | return return_value; |
| 200 | } |
| 201 | |
| 202 | #endif /* defined(HAVE_TTYNAME) */ |
| 203 | |
| 204 | #if defined(HAVE_CTERMID) |
| 205 | |
| 206 | PyDoc_STRVAR(os_ctermid__doc__, |
| 207 | "ctermid($module, /)\n" |
| 208 | "--\n" |
| 209 | "\n" |
| 210 | "Return the name of the controlling terminal for this process."); |
| 211 | |
| 212 | #define OS_CTERMID_METHODDEF \ |
| 213 | {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, |
| 214 | |
| 215 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 216 | os_ctermid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 217 | |
| 218 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 219 | os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 220 | { |
| 221 | return os_ctermid_impl(module); |
| 222 | } |
| 223 | |
| 224 | #endif /* defined(HAVE_CTERMID) */ |
| 225 | |
| 226 | PyDoc_STRVAR(os_chdir__doc__, |
| 227 | "chdir($module, /, path)\n" |
| 228 | "--\n" |
| 229 | "\n" |
| 230 | "Change the current working directory to the specified path.\n" |
| 231 | "\n" |
| 232 | "path may always be specified as a string.\n" |
| 233 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 234 | " If this functionality is unavailable, using it raises an exception."); |
| 235 | |
| 236 | #define OS_CHDIR_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 237 | {"chdir", (PyCFunction)os_chdir, METH_FASTCALL, os_chdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 238 | |
| 239 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 240 | os_chdir_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 241 | |
| 242 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 243 | os_chdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 244 | { |
| 245 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 246 | static const char * const _keywords[] = {"path", NULL}; |
| 247 | static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 248 | path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR); |
| 249 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 250 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 251 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 252 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 253 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 254 | return_value = os_chdir_impl(module, &path); |
| 255 | |
| 256 | exit: |
| 257 | /* Cleanup for path */ |
| 258 | path_cleanup(&path); |
| 259 | |
| 260 | return return_value; |
| 261 | } |
| 262 | |
| 263 | #if defined(HAVE_FCHDIR) |
| 264 | |
| 265 | PyDoc_STRVAR(os_fchdir__doc__, |
| 266 | "fchdir($module, /, fd)\n" |
| 267 | "--\n" |
| 268 | "\n" |
| 269 | "Change to the directory of the given file descriptor.\n" |
| 270 | "\n" |
| 271 | "fd must be opened on a directory, not a file.\n" |
| 272 | "Equivalent to os.chdir(fd)."); |
| 273 | |
| 274 | #define OS_FCHDIR_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 275 | {"fchdir", (PyCFunction)os_fchdir, METH_FASTCALL, os_fchdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 276 | |
| 277 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 278 | os_fchdir_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 279 | |
| 280 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 281 | os_fchdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 282 | { |
| 283 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 284 | static const char * const _keywords[] = {"fd", NULL}; |
| 285 | static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 286 | int fd; |
| 287 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 288 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 289 | fildes_converter, &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 290 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 291 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 292 | return_value = os_fchdir_impl(module, fd); |
| 293 | |
| 294 | exit: |
| 295 | return return_value; |
| 296 | } |
| 297 | |
| 298 | #endif /* defined(HAVE_FCHDIR) */ |
| 299 | |
| 300 | PyDoc_STRVAR(os_chmod__doc__, |
| 301 | "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n" |
| 302 | "--\n" |
| 303 | "\n" |
| 304 | "Change the access permissions of a file.\n" |
| 305 | "\n" |
| 306 | " path\n" |
| 307 | " Path to be modified. May always be specified as a str or bytes.\n" |
| 308 | " On some platforms, path may also be specified as an open file descriptor.\n" |
| 309 | " If this functionality is unavailable, using it raises an exception.\n" |
| 310 | " mode\n" |
| 311 | " Operating-system mode bitfield.\n" |
| 312 | " dir_fd\n" |
| 313 | " If not None, it should be a file descriptor open to a directory,\n" |
| 314 | " and path should be relative; path will then be relative to that\n" |
| 315 | " directory.\n" |
| 316 | " follow_symlinks\n" |
| 317 | " If False, and the last element of the path is a symbolic link,\n" |
| 318 | " chmod will modify the symbolic link itself instead of the file\n" |
| 319 | " the link points to.\n" |
| 320 | "\n" |
| 321 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 322 | " an open file descriptor.\n" |
| 323 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 324 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 325 | |
| 326 | #define OS_CHMOD_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 327 | {"chmod", (PyCFunction)os_chmod, METH_FASTCALL, os_chmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 328 | |
| 329 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 330 | 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] | 331 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 332 | |
| 333 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 334 | os_chmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 335 | { |
| 336 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 337 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL}; |
| 338 | static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 339 | path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD); |
| 340 | int mode; |
| 341 | int dir_fd = DEFAULT_DIR_FD; |
| 342 | int follow_symlinks = 1; |
| 343 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 344 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 345 | path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 346 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 347 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 348 | return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); |
| 349 | |
| 350 | exit: |
| 351 | /* Cleanup for path */ |
| 352 | path_cleanup(&path); |
| 353 | |
| 354 | return return_value; |
| 355 | } |
| 356 | |
| 357 | #if defined(HAVE_FCHMOD) |
| 358 | |
| 359 | PyDoc_STRVAR(os_fchmod__doc__, |
| 360 | "fchmod($module, /, fd, mode)\n" |
| 361 | "--\n" |
| 362 | "\n" |
| 363 | "Change the access permissions of the file given by file descriptor fd.\n" |
| 364 | "\n" |
| 365 | "Equivalent to os.chmod(fd, mode)."); |
| 366 | |
| 367 | #define OS_FCHMOD_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 368 | {"fchmod", (PyCFunction)os_fchmod, METH_FASTCALL, os_fchmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 369 | |
| 370 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 371 | os_fchmod_impl(PyObject *module, int fd, int mode); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 372 | |
| 373 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 374 | os_fchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 375 | { |
| 376 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 377 | static const char * const _keywords[] = {"fd", "mode", NULL}; |
| 378 | static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 379 | int fd; |
| 380 | int mode; |
| 381 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 382 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 383 | &fd, &mode)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 384 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 385 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 386 | return_value = os_fchmod_impl(module, fd, mode); |
| 387 | |
| 388 | exit: |
| 389 | return return_value; |
| 390 | } |
| 391 | |
| 392 | #endif /* defined(HAVE_FCHMOD) */ |
| 393 | |
| 394 | #if defined(HAVE_LCHMOD) |
| 395 | |
| 396 | PyDoc_STRVAR(os_lchmod__doc__, |
| 397 | "lchmod($module, /, path, mode)\n" |
| 398 | "--\n" |
| 399 | "\n" |
| 400 | "Change the access permissions of a file, without following symbolic links.\n" |
| 401 | "\n" |
| 402 | "If path is a symlink, this affects the link itself rather than the target.\n" |
| 403 | "Equivalent to chmod(path, mode, follow_symlinks=False).\""); |
| 404 | |
| 405 | #define OS_LCHMOD_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 406 | {"lchmod", (PyCFunction)os_lchmod, METH_FASTCALL, os_lchmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 407 | |
| 408 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 409 | os_lchmod_impl(PyObject *module, path_t *path, int mode); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 410 | |
| 411 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 412 | os_lchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 413 | { |
| 414 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 415 | static const char * const _keywords[] = {"path", "mode", NULL}; |
| 416 | static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 417 | path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0); |
| 418 | int mode; |
| 419 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 420 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 421 | path_converter, &path, &mode)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 422 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 423 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 424 | return_value = os_lchmod_impl(module, &path, mode); |
| 425 | |
| 426 | exit: |
| 427 | /* Cleanup for path */ |
| 428 | path_cleanup(&path); |
| 429 | |
| 430 | return return_value; |
| 431 | } |
| 432 | |
| 433 | #endif /* defined(HAVE_LCHMOD) */ |
| 434 | |
| 435 | #if defined(HAVE_CHFLAGS) |
| 436 | |
| 437 | PyDoc_STRVAR(os_chflags__doc__, |
| 438 | "chflags($module, /, path, flags, follow_symlinks=True)\n" |
| 439 | "--\n" |
| 440 | "\n" |
| 441 | "Set file flags.\n" |
| 442 | "\n" |
| 443 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 444 | " link, chflags will change flags on the symbolic link itself instead of the\n" |
| 445 | " file the link points to.\n" |
| 446 | "follow_symlinks may not be implemented on your platform. If it is\n" |
| 447 | "unavailable, using it will raise a NotImplementedError."); |
| 448 | |
| 449 | #define OS_CHFLAGS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 450 | {"chflags", (PyCFunction)os_chflags, METH_FASTCALL, os_chflags__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 451 | |
| 452 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 453 | os_chflags_impl(PyObject *module, path_t *path, unsigned long flags, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 454 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 455 | |
| 456 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 457 | os_chflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 458 | { |
| 459 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 460 | static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL}; |
| 461 | static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 462 | path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0); |
| 463 | unsigned long flags; |
| 464 | int follow_symlinks = 1; |
| 465 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 466 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 467 | path_converter, &path, &flags, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 468 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 469 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 470 | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
| 471 | |
| 472 | exit: |
| 473 | /* Cleanup for path */ |
| 474 | path_cleanup(&path); |
| 475 | |
| 476 | return return_value; |
| 477 | } |
| 478 | |
| 479 | #endif /* defined(HAVE_CHFLAGS) */ |
| 480 | |
| 481 | #if defined(HAVE_LCHFLAGS) |
| 482 | |
| 483 | PyDoc_STRVAR(os_lchflags__doc__, |
| 484 | "lchflags($module, /, path, flags)\n" |
| 485 | "--\n" |
| 486 | "\n" |
| 487 | "Set file flags.\n" |
| 488 | "\n" |
| 489 | "This function will not follow symbolic links.\n" |
| 490 | "Equivalent to chflags(path, flags, follow_symlinks=False)."); |
| 491 | |
| 492 | #define OS_LCHFLAGS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 493 | {"lchflags", (PyCFunction)os_lchflags, METH_FASTCALL, os_lchflags__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 494 | |
| 495 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 496 | os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 497 | |
| 498 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 499 | os_lchflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 500 | { |
| 501 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 502 | static const char * const _keywords[] = {"path", "flags", NULL}; |
| 503 | static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 504 | path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0); |
| 505 | unsigned long flags; |
| 506 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 507 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 508 | path_converter, &path, &flags)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 509 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 510 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 511 | return_value = os_lchflags_impl(module, &path, flags); |
| 512 | |
| 513 | exit: |
| 514 | /* Cleanup for path */ |
| 515 | path_cleanup(&path); |
| 516 | |
| 517 | return return_value; |
| 518 | } |
| 519 | |
| 520 | #endif /* defined(HAVE_LCHFLAGS) */ |
| 521 | |
| 522 | #if defined(HAVE_CHROOT) |
| 523 | |
| 524 | PyDoc_STRVAR(os_chroot__doc__, |
| 525 | "chroot($module, /, path)\n" |
| 526 | "--\n" |
| 527 | "\n" |
| 528 | "Change root directory to path."); |
| 529 | |
| 530 | #define OS_CHROOT_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 531 | {"chroot", (PyCFunction)os_chroot, METH_FASTCALL, os_chroot__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 532 | |
| 533 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 534 | os_chroot_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 535 | |
| 536 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 537 | os_chroot(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 538 | { |
| 539 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 540 | static const char * const _keywords[] = {"path", NULL}; |
| 541 | static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 542 | path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0); |
| 543 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 544 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 545 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 546 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 547 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 548 | return_value = os_chroot_impl(module, &path); |
| 549 | |
| 550 | exit: |
| 551 | /* Cleanup for path */ |
| 552 | path_cleanup(&path); |
| 553 | |
| 554 | return return_value; |
| 555 | } |
| 556 | |
| 557 | #endif /* defined(HAVE_CHROOT) */ |
| 558 | |
| 559 | #if defined(HAVE_FSYNC) |
| 560 | |
| 561 | PyDoc_STRVAR(os_fsync__doc__, |
| 562 | "fsync($module, /, fd)\n" |
| 563 | "--\n" |
| 564 | "\n" |
| 565 | "Force write of fd to disk."); |
| 566 | |
| 567 | #define OS_FSYNC_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 568 | {"fsync", (PyCFunction)os_fsync, METH_FASTCALL, os_fsync__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 569 | |
| 570 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 571 | os_fsync_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 572 | |
| 573 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 574 | os_fsync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 575 | { |
| 576 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 577 | static const char * const _keywords[] = {"fd", NULL}; |
| 578 | static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 579 | int fd; |
| 580 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 581 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 582 | fildes_converter, &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 583 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 584 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 585 | return_value = os_fsync_impl(module, fd); |
| 586 | |
| 587 | exit: |
| 588 | return return_value; |
| 589 | } |
| 590 | |
| 591 | #endif /* defined(HAVE_FSYNC) */ |
| 592 | |
| 593 | #if defined(HAVE_SYNC) |
| 594 | |
| 595 | PyDoc_STRVAR(os_sync__doc__, |
| 596 | "sync($module, /)\n" |
| 597 | "--\n" |
| 598 | "\n" |
| 599 | "Force write of everything to disk."); |
| 600 | |
| 601 | #define OS_SYNC_METHODDEF \ |
| 602 | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
| 603 | |
| 604 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 605 | os_sync_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 606 | |
| 607 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 608 | os_sync(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 609 | { |
| 610 | return os_sync_impl(module); |
| 611 | } |
| 612 | |
| 613 | #endif /* defined(HAVE_SYNC) */ |
| 614 | |
| 615 | #if defined(HAVE_FDATASYNC) |
| 616 | |
| 617 | PyDoc_STRVAR(os_fdatasync__doc__, |
| 618 | "fdatasync($module, /, fd)\n" |
| 619 | "--\n" |
| 620 | "\n" |
| 621 | "Force write of fd to disk without forcing update of metadata."); |
| 622 | |
| 623 | #define OS_FDATASYNC_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 624 | {"fdatasync", (PyCFunction)os_fdatasync, METH_FASTCALL, os_fdatasync__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 625 | |
| 626 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 627 | os_fdatasync_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 628 | |
| 629 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 630 | os_fdatasync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 631 | { |
| 632 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 633 | static const char * const _keywords[] = {"fd", NULL}; |
| 634 | static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 635 | int fd; |
| 636 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 637 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 638 | fildes_converter, &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 639 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 640 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 641 | return_value = os_fdatasync_impl(module, fd); |
| 642 | |
| 643 | exit: |
| 644 | return return_value; |
| 645 | } |
| 646 | |
| 647 | #endif /* defined(HAVE_FDATASYNC) */ |
| 648 | |
| 649 | #if defined(HAVE_CHOWN) |
| 650 | |
| 651 | PyDoc_STRVAR(os_chown__doc__, |
| 652 | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
| 653 | "--\n" |
| 654 | "\n" |
| 655 | "Change the owner and group id of path to the numeric uid and gid.\\\n" |
| 656 | "\n" |
| 657 | " path\n" |
| 658 | " Path to be examined; can be string, bytes, or open-file-descriptor int.\n" |
| 659 | " dir_fd\n" |
| 660 | " If not None, it should be a file descriptor open to a directory,\n" |
| 661 | " and path should be relative; path will then be relative to that\n" |
| 662 | " directory.\n" |
| 663 | " follow_symlinks\n" |
| 664 | " If False, and the last element of the path is a symbolic link,\n" |
| 665 | " stat will examine the symbolic link itself instead of the file\n" |
| 666 | " the link points to.\n" |
| 667 | "\n" |
| 668 | "path may always be specified as a string.\n" |
| 669 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 670 | " If this functionality is unavailable, using it raises an exception.\n" |
| 671 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 672 | " and path should be relative; path will then be relative to that directory.\n" |
| 673 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 674 | " link, chown will modify the symbolic link itself instead of the file the\n" |
| 675 | " link points to.\n" |
| 676 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 677 | " an open file descriptor.\n" |
| 678 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 679 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 680 | |
| 681 | #define OS_CHOWN_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 682 | {"chown", (PyCFunction)os_chown, METH_FASTCALL, os_chown__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 683 | |
| 684 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 685 | 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] | 686 | int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 687 | |
| 688 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 689 | os_chown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 690 | { |
| 691 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 692 | static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; |
| 693 | static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 694 | path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN); |
| 695 | uid_t uid; |
| 696 | gid_t gid; |
| 697 | int dir_fd = DEFAULT_DIR_FD; |
| 698 | int follow_symlinks = 1; |
| 699 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 700 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 701 | path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 702 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 703 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 704 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
| 705 | |
| 706 | exit: |
| 707 | /* Cleanup for path */ |
| 708 | path_cleanup(&path); |
| 709 | |
| 710 | return return_value; |
| 711 | } |
| 712 | |
| 713 | #endif /* defined(HAVE_CHOWN) */ |
| 714 | |
| 715 | #if defined(HAVE_FCHOWN) |
| 716 | |
| 717 | PyDoc_STRVAR(os_fchown__doc__, |
| 718 | "fchown($module, /, fd, uid, gid)\n" |
| 719 | "--\n" |
| 720 | "\n" |
| 721 | "Change the owner and group id of the file specified by file descriptor.\n" |
| 722 | "\n" |
| 723 | "Equivalent to os.chown(fd, uid, gid)."); |
| 724 | |
| 725 | #define OS_FCHOWN_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 726 | {"fchown", (PyCFunction)os_fchown, METH_FASTCALL, os_fchown__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 727 | |
| 728 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 729 | 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] | 730 | |
| 731 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 732 | os_fchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 733 | { |
| 734 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 735 | static const char * const _keywords[] = {"fd", "uid", "gid", NULL}; |
| 736 | static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 737 | int fd; |
| 738 | uid_t uid; |
| 739 | gid_t gid; |
| 740 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 741 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 742 | &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 743 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 744 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 745 | return_value = os_fchown_impl(module, fd, uid, gid); |
| 746 | |
| 747 | exit: |
| 748 | return return_value; |
| 749 | } |
| 750 | |
| 751 | #endif /* defined(HAVE_FCHOWN) */ |
| 752 | |
| 753 | #if defined(HAVE_LCHOWN) |
| 754 | |
| 755 | PyDoc_STRVAR(os_lchown__doc__, |
| 756 | "lchown($module, /, path, uid, gid)\n" |
| 757 | "--\n" |
| 758 | "\n" |
| 759 | "Change the owner and group id of path to the numeric uid and gid.\n" |
| 760 | "\n" |
| 761 | "This function will not follow symbolic links.\n" |
| 762 | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); |
| 763 | |
| 764 | #define OS_LCHOWN_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 765 | {"lchown", (PyCFunction)os_lchown, METH_FASTCALL, os_lchown__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 766 | |
| 767 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 768 | 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] | 769 | |
| 770 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 771 | os_lchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 772 | { |
| 773 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 774 | static const char * const _keywords[] = {"path", "uid", "gid", NULL}; |
| 775 | static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 776 | path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0); |
| 777 | uid_t uid; |
| 778 | gid_t gid; |
| 779 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 780 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 781 | path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 782 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 783 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 784 | return_value = os_lchown_impl(module, &path, uid, gid); |
| 785 | |
| 786 | exit: |
| 787 | /* Cleanup for path */ |
| 788 | path_cleanup(&path); |
| 789 | |
| 790 | return return_value; |
| 791 | } |
| 792 | |
| 793 | #endif /* defined(HAVE_LCHOWN) */ |
| 794 | |
| 795 | PyDoc_STRVAR(os_getcwd__doc__, |
| 796 | "getcwd($module, /)\n" |
| 797 | "--\n" |
| 798 | "\n" |
| 799 | "Return a unicode string representing the current working directory."); |
| 800 | |
| 801 | #define OS_GETCWD_METHODDEF \ |
| 802 | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
| 803 | |
| 804 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 805 | os_getcwd_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 806 | |
| 807 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 808 | os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 809 | { |
| 810 | return os_getcwd_impl(module); |
| 811 | } |
| 812 | |
| 813 | PyDoc_STRVAR(os_getcwdb__doc__, |
| 814 | "getcwdb($module, /)\n" |
| 815 | "--\n" |
| 816 | "\n" |
| 817 | "Return a bytes string representing the current working directory."); |
| 818 | |
| 819 | #define OS_GETCWDB_METHODDEF \ |
| 820 | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
| 821 | |
| 822 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 823 | os_getcwdb_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 824 | |
| 825 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 826 | os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 827 | { |
| 828 | return os_getcwdb_impl(module); |
| 829 | } |
| 830 | |
| 831 | #if defined(HAVE_LINK) |
| 832 | |
| 833 | PyDoc_STRVAR(os_link__doc__, |
| 834 | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
| 835 | " follow_symlinks=True)\n" |
| 836 | "--\n" |
| 837 | "\n" |
| 838 | "Create a hard link to a file.\n" |
| 839 | "\n" |
| 840 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 841 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 842 | " should be relative; the path will then be relative to that directory.\n" |
| 843 | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
| 844 | " link, link will create a link to the symbolic link itself instead of the\n" |
| 845 | " file the link points to.\n" |
| 846 | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" |
| 847 | " platform. If they are unavailable, using them will raise a\n" |
| 848 | " NotImplementedError."); |
| 849 | |
| 850 | #define OS_LINK_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 851 | {"link", (PyCFunction)os_link, METH_FASTCALL, os_link__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 852 | |
| 853 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 854 | 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] | 855 | int dst_dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 856 | |
| 857 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 858 | os_link(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 859 | { |
| 860 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 861 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; |
| 862 | static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 863 | path_t src = PATH_T_INITIALIZE("link", "src", 0, 0); |
| 864 | path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0); |
| 865 | int src_dir_fd = DEFAULT_DIR_FD; |
| 866 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 867 | int follow_symlinks = 1; |
| 868 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 869 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 870 | path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 871 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 872 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 873 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
| 874 | |
| 875 | exit: |
| 876 | /* Cleanup for src */ |
| 877 | path_cleanup(&src); |
| 878 | /* Cleanup for dst */ |
| 879 | path_cleanup(&dst); |
| 880 | |
| 881 | return return_value; |
| 882 | } |
| 883 | |
| 884 | #endif /* defined(HAVE_LINK) */ |
| 885 | |
| 886 | PyDoc_STRVAR(os_listdir__doc__, |
| 887 | "listdir($module, /, path=None)\n" |
| 888 | "--\n" |
| 889 | "\n" |
| 890 | "Return a list containing the names of the files in the directory.\n" |
| 891 | "\n" |
| 892 | "path can be specified as either str or bytes. If path is bytes,\n" |
| 893 | " the filenames returned will also be bytes; in all other circumstances\n" |
| 894 | " the filenames returned will be str.\n" |
| 895 | "If path is None, uses the path=\'.\'.\n" |
| 896 | "On some platforms, path may also be specified as an open file descriptor;\\\n" |
| 897 | " the file descriptor must refer to a directory.\n" |
| 898 | " If this functionality is unavailable, using it raises NotImplementedError.\n" |
| 899 | "\n" |
| 900 | "The list is in arbitrary order. It does not include the special\n" |
| 901 | "entries \'.\' and \'..\' even if they are present in the directory."); |
| 902 | |
| 903 | #define OS_LISTDIR_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 904 | {"listdir", (PyCFunction)os_listdir, METH_FASTCALL, os_listdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 905 | |
| 906 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 907 | os_listdir_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 908 | |
| 909 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 910 | os_listdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 911 | { |
| 912 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 913 | static const char * const _keywords[] = {"path", NULL}; |
| 914 | static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 915 | path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR); |
| 916 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 917 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 918 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 919 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 920 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 921 | return_value = os_listdir_impl(module, &path); |
| 922 | |
| 923 | exit: |
| 924 | /* Cleanup for path */ |
| 925 | path_cleanup(&path); |
| 926 | |
| 927 | return return_value; |
| 928 | } |
| 929 | |
| 930 | #if defined(MS_WINDOWS) |
| 931 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 932 | PyDoc_STRVAR(os__getfullpathname__doc__, |
| 933 | "_getfullpathname($module, path, /)\n" |
| 934 | "--\n" |
| 935 | "\n"); |
| 936 | |
| 937 | #define OS__GETFULLPATHNAME_METHODDEF \ |
| 938 | {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__}, |
| 939 | |
| 940 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 941 | os__getfullpathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 942 | |
| 943 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 944 | os__getfullpathname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 945 | { |
| 946 | PyObject *return_value = NULL; |
| 947 | path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0); |
| 948 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 949 | if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) { |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 950 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 951 | } |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 952 | return_value = os__getfullpathname_impl(module, &path); |
| 953 | |
| 954 | exit: |
| 955 | /* Cleanup for path */ |
| 956 | path_cleanup(&path); |
| 957 | |
| 958 | return return_value; |
| 959 | } |
| 960 | |
| 961 | #endif /* defined(MS_WINDOWS) */ |
| 962 | |
| 963 | #if defined(MS_WINDOWS) |
| 964 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 965 | PyDoc_STRVAR(os__getfinalpathname__doc__, |
| 966 | "_getfinalpathname($module, path, /)\n" |
| 967 | "--\n" |
| 968 | "\n" |
| 969 | "A helper function for samepath on windows."); |
| 970 | |
| 971 | #define OS__GETFINALPATHNAME_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 972 | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 973 | |
| 974 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 975 | os__getfinalpathname_impl(PyObject *module, PyObject *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 976 | |
| 977 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 978 | os__getfinalpathname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 979 | { |
| 980 | PyObject *return_value = NULL; |
| 981 | PyObject *path; |
| 982 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 983 | if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 984 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 985 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 986 | return_value = os__getfinalpathname_impl(module, path); |
| 987 | |
| 988 | exit: |
| 989 | return return_value; |
| 990 | } |
| 991 | |
| 992 | #endif /* defined(MS_WINDOWS) */ |
| 993 | |
| 994 | #if defined(MS_WINDOWS) |
| 995 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 996 | PyDoc_STRVAR(os__isdir__doc__, |
| 997 | "_isdir($module, path, /)\n" |
| 998 | "--\n" |
Serhiy Storchaka | 579f038 | 2016-11-08 20:21:22 +0200 | [diff] [blame] | 999 | "\n" |
| 1000 | "Return true if the pathname refers to an existing directory."); |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1001 | |
| 1002 | #define OS__ISDIR_METHODDEF \ |
| 1003 | {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__}, |
| 1004 | |
| 1005 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1006 | os__isdir_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1007 | |
| 1008 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1009 | os__isdir(PyObject *module, PyObject *arg) |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1010 | { |
| 1011 | PyObject *return_value = NULL; |
| 1012 | path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0); |
| 1013 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1014 | if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) { |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1015 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1016 | } |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1017 | return_value = os__isdir_impl(module, &path); |
| 1018 | |
| 1019 | exit: |
| 1020 | /* Cleanup for path */ |
| 1021 | path_cleanup(&path); |
| 1022 | |
| 1023 | return return_value; |
| 1024 | } |
| 1025 | |
| 1026 | #endif /* defined(MS_WINDOWS) */ |
| 1027 | |
| 1028 | #if defined(MS_WINDOWS) |
| 1029 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1030 | PyDoc_STRVAR(os__getvolumepathname__doc__, |
| 1031 | "_getvolumepathname($module, /, path)\n" |
| 1032 | "--\n" |
| 1033 | "\n" |
| 1034 | "A helper function for ismount on Win32."); |
| 1035 | |
| 1036 | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1037 | {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL, os__getvolumepathname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1038 | |
| 1039 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1040 | os__getvolumepathname_impl(PyObject *module, PyObject *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1041 | |
| 1042 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1043 | os__getvolumepathname(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1044 | { |
| 1045 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1046 | static const char * const _keywords[] = {"path", NULL}; |
| 1047 | static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1048 | PyObject *path; |
| 1049 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1050 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1051 | &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1052 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1053 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1054 | return_value = os__getvolumepathname_impl(module, path); |
| 1055 | |
| 1056 | exit: |
| 1057 | return return_value; |
| 1058 | } |
| 1059 | |
| 1060 | #endif /* defined(MS_WINDOWS) */ |
| 1061 | |
| 1062 | PyDoc_STRVAR(os_mkdir__doc__, |
| 1063 | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
| 1064 | "--\n" |
| 1065 | "\n" |
| 1066 | "Create a directory.\n" |
| 1067 | "\n" |
| 1068 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1069 | " and path should be relative; path will then be relative to that directory.\n" |
| 1070 | "dir_fd may not be implemented on your platform.\n" |
| 1071 | " If it is unavailable, using it will raise a NotImplementedError.\n" |
| 1072 | "\n" |
| 1073 | "The mode argument is ignored on Windows."); |
| 1074 | |
| 1075 | #define OS_MKDIR_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1076 | {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL, os_mkdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1077 | |
| 1078 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1079 | 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] | 1080 | |
| 1081 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1082 | os_mkdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1083 | { |
| 1084 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1085 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
| 1086 | static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1087 | path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0); |
| 1088 | int mode = 511; |
| 1089 | int dir_fd = DEFAULT_DIR_FD; |
| 1090 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1091 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1092 | path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1093 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1094 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1095 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
| 1096 | |
| 1097 | exit: |
| 1098 | /* Cleanup for path */ |
| 1099 | path_cleanup(&path); |
| 1100 | |
| 1101 | return return_value; |
| 1102 | } |
| 1103 | |
| 1104 | #if defined(HAVE_NICE) |
| 1105 | |
| 1106 | PyDoc_STRVAR(os_nice__doc__, |
| 1107 | "nice($module, increment, /)\n" |
| 1108 | "--\n" |
| 1109 | "\n" |
| 1110 | "Add increment to the priority of process and return the new priority."); |
| 1111 | |
| 1112 | #define OS_NICE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1113 | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1114 | |
| 1115 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1116 | os_nice_impl(PyObject *module, int increment); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1117 | |
| 1118 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1119 | os_nice(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1120 | { |
| 1121 | PyObject *return_value = NULL; |
| 1122 | int increment; |
| 1123 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1124 | if (!PyArg_Parse(arg, "i:nice", &increment)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1125 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1126 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1127 | return_value = os_nice_impl(module, increment); |
| 1128 | |
| 1129 | exit: |
| 1130 | return return_value; |
| 1131 | } |
| 1132 | |
| 1133 | #endif /* defined(HAVE_NICE) */ |
| 1134 | |
| 1135 | #if defined(HAVE_GETPRIORITY) |
| 1136 | |
| 1137 | PyDoc_STRVAR(os_getpriority__doc__, |
| 1138 | "getpriority($module, /, which, who)\n" |
| 1139 | "--\n" |
| 1140 | "\n" |
| 1141 | "Return program scheduling priority."); |
| 1142 | |
| 1143 | #define OS_GETPRIORITY_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1144 | {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL, os_getpriority__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1145 | |
| 1146 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1147 | os_getpriority_impl(PyObject *module, int which, int who); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1148 | |
| 1149 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1150 | os_getpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1151 | { |
| 1152 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1153 | static const char * const _keywords[] = {"which", "who", NULL}; |
| 1154 | static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1155 | int which; |
| 1156 | int who; |
| 1157 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1158 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1159 | &which, &who)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1160 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1161 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1162 | return_value = os_getpriority_impl(module, which, who); |
| 1163 | |
| 1164 | exit: |
| 1165 | return return_value; |
| 1166 | } |
| 1167 | |
| 1168 | #endif /* defined(HAVE_GETPRIORITY) */ |
| 1169 | |
| 1170 | #if defined(HAVE_SETPRIORITY) |
| 1171 | |
| 1172 | PyDoc_STRVAR(os_setpriority__doc__, |
| 1173 | "setpriority($module, /, which, who, priority)\n" |
| 1174 | "--\n" |
| 1175 | "\n" |
| 1176 | "Set program scheduling priority."); |
| 1177 | |
| 1178 | #define OS_SETPRIORITY_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1179 | {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL, os_setpriority__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1180 | |
| 1181 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1182 | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1183 | |
| 1184 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1185 | os_setpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1186 | { |
| 1187 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1188 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
| 1189 | static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1190 | int which; |
| 1191 | int who; |
| 1192 | int priority; |
| 1193 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1194 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1195 | &which, &who, &priority)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1196 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1197 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1198 | return_value = os_setpriority_impl(module, which, who, priority); |
| 1199 | |
| 1200 | exit: |
| 1201 | return return_value; |
| 1202 | } |
| 1203 | |
| 1204 | #endif /* defined(HAVE_SETPRIORITY) */ |
| 1205 | |
| 1206 | PyDoc_STRVAR(os_rename__doc__, |
| 1207 | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1208 | "--\n" |
| 1209 | "\n" |
| 1210 | "Rename a file or directory.\n" |
| 1211 | "\n" |
| 1212 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1213 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1214 | " should be relative; the path will then be relative to that directory.\n" |
| 1215 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1216 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1217 | |
| 1218 | #define OS_RENAME_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1219 | {"rename", (PyCFunction)os_rename, METH_FASTCALL, os_rename__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1220 | |
| 1221 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1222 | 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] | 1223 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1224 | |
| 1225 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1226 | os_rename(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1227 | { |
| 1228 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1229 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
| 1230 | static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1231 | path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0); |
| 1232 | path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0); |
| 1233 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1234 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1235 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1236 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1237 | path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1238 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1239 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1240 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1241 | |
| 1242 | exit: |
| 1243 | /* Cleanup for src */ |
| 1244 | path_cleanup(&src); |
| 1245 | /* Cleanup for dst */ |
| 1246 | path_cleanup(&dst); |
| 1247 | |
| 1248 | return return_value; |
| 1249 | } |
| 1250 | |
| 1251 | PyDoc_STRVAR(os_replace__doc__, |
| 1252 | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1253 | "--\n" |
| 1254 | "\n" |
| 1255 | "Rename a file or directory, overwriting the destination.\n" |
| 1256 | "\n" |
| 1257 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1258 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1259 | " should be relative; the path will then be relative to that directory.\n" |
| 1260 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1261 | " If they are unavailable, using them will raise a NotImplementedError.\""); |
| 1262 | |
| 1263 | #define OS_REPLACE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1264 | {"replace", (PyCFunction)os_replace, METH_FASTCALL, os_replace__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1265 | |
| 1266 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1267 | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
| 1268 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1269 | |
| 1270 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1271 | os_replace(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1272 | { |
| 1273 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1274 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
| 1275 | static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1276 | path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0); |
| 1277 | path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0); |
| 1278 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1279 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1280 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1281 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1282 | path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1283 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1284 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1285 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1286 | |
| 1287 | exit: |
| 1288 | /* Cleanup for src */ |
| 1289 | path_cleanup(&src); |
| 1290 | /* Cleanup for dst */ |
| 1291 | path_cleanup(&dst); |
| 1292 | |
| 1293 | return return_value; |
| 1294 | } |
| 1295 | |
| 1296 | PyDoc_STRVAR(os_rmdir__doc__, |
| 1297 | "rmdir($module, /, path, *, dir_fd=None)\n" |
| 1298 | "--\n" |
| 1299 | "\n" |
| 1300 | "Remove a directory.\n" |
| 1301 | "\n" |
| 1302 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1303 | " and path should be relative; path will then be relative to that directory.\n" |
| 1304 | "dir_fd may not be implemented on your platform.\n" |
| 1305 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1306 | |
| 1307 | #define OS_RMDIR_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1308 | {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL, os_rmdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1309 | |
| 1310 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1311 | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1312 | |
| 1313 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1314 | os_rmdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1315 | { |
| 1316 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1317 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 1318 | static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1319 | path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0); |
| 1320 | int dir_fd = DEFAULT_DIR_FD; |
| 1321 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1322 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1323 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1324 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1325 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1326 | return_value = os_rmdir_impl(module, &path, dir_fd); |
| 1327 | |
| 1328 | exit: |
| 1329 | /* Cleanup for path */ |
| 1330 | path_cleanup(&path); |
| 1331 | |
| 1332 | return return_value; |
| 1333 | } |
| 1334 | |
| 1335 | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
| 1336 | |
| 1337 | PyDoc_STRVAR(os_system__doc__, |
| 1338 | "system($module, /, command)\n" |
| 1339 | "--\n" |
| 1340 | "\n" |
| 1341 | "Execute the command in a subshell."); |
| 1342 | |
| 1343 | #define OS_SYSTEM_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1344 | {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1345 | |
| 1346 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1347 | os_system_impl(PyObject *module, Py_UNICODE *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1348 | |
| 1349 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1350 | os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1351 | { |
| 1352 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1353 | static const char * const _keywords[] = {"command", NULL}; |
| 1354 | static _PyArg_Parser _parser = {"u:system", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1355 | Py_UNICODE *command; |
| 1356 | long _return_value; |
| 1357 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1358 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1359 | &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1360 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1361 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1362 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1363 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1364 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1365 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1366 | return_value = PyLong_FromLong(_return_value); |
| 1367 | |
| 1368 | exit: |
| 1369 | return return_value; |
| 1370 | } |
| 1371 | |
| 1372 | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
| 1373 | |
| 1374 | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
| 1375 | |
| 1376 | PyDoc_STRVAR(os_system__doc__, |
| 1377 | "system($module, /, command)\n" |
| 1378 | "--\n" |
| 1379 | "\n" |
| 1380 | "Execute the command in a subshell."); |
| 1381 | |
| 1382 | #define OS_SYSTEM_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1383 | {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1384 | |
| 1385 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1386 | os_system_impl(PyObject *module, PyObject *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1387 | |
| 1388 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1389 | os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1390 | { |
| 1391 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1392 | static const char * const _keywords[] = {"command", NULL}; |
| 1393 | static _PyArg_Parser _parser = {"O&:system", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1394 | PyObject *command = NULL; |
| 1395 | long _return_value; |
| 1396 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1397 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1398 | PyUnicode_FSConverter, &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1399 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1400 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1401 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1402 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1403 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1404 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1405 | return_value = PyLong_FromLong(_return_value); |
| 1406 | |
| 1407 | exit: |
| 1408 | /* Cleanup for command */ |
| 1409 | Py_XDECREF(command); |
| 1410 | |
| 1411 | return return_value; |
| 1412 | } |
| 1413 | |
| 1414 | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
| 1415 | |
| 1416 | PyDoc_STRVAR(os_umask__doc__, |
| 1417 | "umask($module, mask, /)\n" |
| 1418 | "--\n" |
| 1419 | "\n" |
| 1420 | "Set the current numeric umask and return the previous umask."); |
| 1421 | |
| 1422 | #define OS_UMASK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1423 | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1424 | |
| 1425 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1426 | os_umask_impl(PyObject *module, int mask); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1427 | |
| 1428 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1429 | os_umask(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1430 | { |
| 1431 | PyObject *return_value = NULL; |
| 1432 | int mask; |
| 1433 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1434 | if (!PyArg_Parse(arg, "i:umask", &mask)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1435 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1436 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1437 | return_value = os_umask_impl(module, mask); |
| 1438 | |
| 1439 | exit: |
| 1440 | return return_value; |
| 1441 | } |
| 1442 | |
| 1443 | PyDoc_STRVAR(os_unlink__doc__, |
| 1444 | "unlink($module, /, path, *, dir_fd=None)\n" |
| 1445 | "--\n" |
| 1446 | "\n" |
| 1447 | "Remove a file (same as remove()).\n" |
| 1448 | "\n" |
| 1449 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1450 | " and path should be relative; path will then be relative to that directory.\n" |
| 1451 | "dir_fd may not be implemented on your platform.\n" |
| 1452 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1453 | |
| 1454 | #define OS_UNLINK_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1455 | {"unlink", (PyCFunction)os_unlink, METH_FASTCALL, os_unlink__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1456 | |
| 1457 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1458 | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1459 | |
| 1460 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1461 | os_unlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1462 | { |
| 1463 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1464 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 1465 | static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1466 | path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0); |
| 1467 | int dir_fd = DEFAULT_DIR_FD; |
| 1468 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1469 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1470 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1471 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1472 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1473 | return_value = os_unlink_impl(module, &path, dir_fd); |
| 1474 | |
| 1475 | exit: |
| 1476 | /* Cleanup for path */ |
| 1477 | path_cleanup(&path); |
| 1478 | |
| 1479 | return return_value; |
| 1480 | } |
| 1481 | |
| 1482 | PyDoc_STRVAR(os_remove__doc__, |
| 1483 | "remove($module, /, path, *, dir_fd=None)\n" |
| 1484 | "--\n" |
| 1485 | "\n" |
| 1486 | "Remove a file (same as unlink()).\n" |
| 1487 | "\n" |
| 1488 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1489 | " and path should be relative; path will then be relative to that directory.\n" |
| 1490 | "dir_fd may not be implemented on your platform.\n" |
| 1491 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1492 | |
| 1493 | #define OS_REMOVE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1494 | {"remove", (PyCFunction)os_remove, METH_FASTCALL, os_remove__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1495 | |
| 1496 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1497 | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1498 | |
| 1499 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1500 | os_remove(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1501 | { |
| 1502 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1503 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 1504 | static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1505 | path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0); |
| 1506 | int dir_fd = DEFAULT_DIR_FD; |
| 1507 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1508 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1509 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1510 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1511 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1512 | return_value = os_remove_impl(module, &path, dir_fd); |
| 1513 | |
| 1514 | exit: |
| 1515 | /* Cleanup for path */ |
| 1516 | path_cleanup(&path); |
| 1517 | |
| 1518 | return return_value; |
| 1519 | } |
| 1520 | |
| 1521 | #if defined(HAVE_UNAME) |
| 1522 | |
| 1523 | PyDoc_STRVAR(os_uname__doc__, |
| 1524 | "uname($module, /)\n" |
| 1525 | "--\n" |
| 1526 | "\n" |
| 1527 | "Return an object identifying the current operating system.\n" |
| 1528 | "\n" |
| 1529 | "The object behaves like a named tuple with the following fields:\n" |
| 1530 | " (sysname, nodename, release, version, machine)"); |
| 1531 | |
| 1532 | #define OS_UNAME_METHODDEF \ |
| 1533 | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
| 1534 | |
| 1535 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1536 | os_uname_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1537 | |
| 1538 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1539 | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1540 | { |
| 1541 | return os_uname_impl(module); |
| 1542 | } |
| 1543 | |
| 1544 | #endif /* defined(HAVE_UNAME) */ |
| 1545 | |
| 1546 | PyDoc_STRVAR(os_utime__doc__, |
| 1547 | "utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n" |
| 1548 | " follow_symlinks=True)\n" |
| 1549 | "--\n" |
| 1550 | "\n" |
| 1551 | "Set the access and modified time of path.\n" |
| 1552 | "\n" |
| 1553 | "path may always be specified as a string.\n" |
| 1554 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 1555 | " If this functionality is unavailable, using it raises an exception.\n" |
| 1556 | "\n" |
| 1557 | "If times is not None, it must be a tuple (atime, mtime);\n" |
| 1558 | " 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] | 1559 | "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] | 1560 | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
| 1561 | " since the epoch.\n" |
Martin Panter | 0ff8909 | 2015-09-09 01:56:53 +0000 | [diff] [blame] | 1562 | "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] | 1563 | "Specifying tuples for both times and ns is an error.\n" |
| 1564 | "\n" |
| 1565 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1566 | " and path should be relative; path will then be relative to that directory.\n" |
| 1567 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 1568 | " link, utime will modify the symbolic link itself instead of the file the\n" |
| 1569 | " link points to.\n" |
| 1570 | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
| 1571 | " as an open file descriptor.\n" |
| 1572 | "dir_fd and follow_symlinks may not be available on your platform.\n" |
| 1573 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1574 | |
| 1575 | #define OS_UTIME_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1576 | {"utime", (PyCFunction)os_utime, METH_FASTCALL, os_utime__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1577 | |
| 1578 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1579 | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
| 1580 | int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1581 | |
| 1582 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1583 | os_utime(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1584 | { |
| 1585 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1586 | static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
| 1587 | static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1588 | path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD); |
| 1589 | PyObject *times = NULL; |
| 1590 | PyObject *ns = NULL; |
| 1591 | int dir_fd = DEFAULT_DIR_FD; |
| 1592 | int follow_symlinks = 1; |
| 1593 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1594 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1595 | path_converter, &path, ×, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1596 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1597 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1598 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
| 1599 | |
| 1600 | exit: |
| 1601 | /* Cleanup for path */ |
| 1602 | path_cleanup(&path); |
| 1603 | |
| 1604 | return return_value; |
| 1605 | } |
| 1606 | |
| 1607 | PyDoc_STRVAR(os__exit__doc__, |
| 1608 | "_exit($module, /, status)\n" |
| 1609 | "--\n" |
| 1610 | "\n" |
| 1611 | "Exit to the system with specified status, without normal exit processing."); |
| 1612 | |
| 1613 | #define OS__EXIT_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1614 | {"_exit", (PyCFunction)os__exit, METH_FASTCALL, os__exit__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1615 | |
| 1616 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1617 | os__exit_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1618 | |
| 1619 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1620 | os__exit(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1621 | { |
| 1622 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1623 | static const char * const _keywords[] = {"status", NULL}; |
| 1624 | static _PyArg_Parser _parser = {"i:_exit", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1625 | int status; |
| 1626 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1627 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1628 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1629 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1630 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1631 | return_value = os__exit_impl(module, status); |
| 1632 | |
| 1633 | exit: |
| 1634 | return return_value; |
| 1635 | } |
| 1636 | |
| 1637 | #if defined(HAVE_EXECV) |
| 1638 | |
| 1639 | PyDoc_STRVAR(os_execv__doc__, |
| 1640 | "execv($module, path, argv, /)\n" |
| 1641 | "--\n" |
| 1642 | "\n" |
| 1643 | "Execute an executable path with arguments, replacing current process.\n" |
| 1644 | "\n" |
| 1645 | " path\n" |
| 1646 | " Path of executable file.\n" |
| 1647 | " argv\n" |
| 1648 | " Tuple or list of strings."); |
| 1649 | |
| 1650 | #define OS_EXECV_METHODDEF \ |
| 1651 | {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__}, |
| 1652 | |
| 1653 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1654 | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1655 | |
| 1656 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1657 | os_execv(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1658 | { |
| 1659 | PyObject *return_value = NULL; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1660 | path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1661 | PyObject *argv; |
| 1662 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 1663 | if (!PyArg_ParseTuple(args, "O&O:execv", |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1664 | path_converter, &path, &argv)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1665 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1666 | } |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1667 | return_value = os_execv_impl(module, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1668 | |
| 1669 | exit: |
| 1670 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1671 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1672 | |
| 1673 | return return_value; |
| 1674 | } |
| 1675 | |
| 1676 | #endif /* defined(HAVE_EXECV) */ |
| 1677 | |
| 1678 | #if defined(HAVE_EXECV) |
| 1679 | |
| 1680 | PyDoc_STRVAR(os_execve__doc__, |
| 1681 | "execve($module, /, path, argv, env)\n" |
| 1682 | "--\n" |
| 1683 | "\n" |
| 1684 | "Execute an executable path with arguments, replacing current process.\n" |
| 1685 | "\n" |
| 1686 | " path\n" |
| 1687 | " Path of executable file.\n" |
| 1688 | " argv\n" |
| 1689 | " Tuple or list of strings.\n" |
| 1690 | " env\n" |
| 1691 | " Dictionary of strings mapping to strings."); |
| 1692 | |
| 1693 | #define OS_EXECVE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1694 | {"execve", (PyCFunction)os_execve, METH_FASTCALL, os_execve__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1695 | |
| 1696 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1697 | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1698 | |
| 1699 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1700 | os_execve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1701 | { |
| 1702 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1703 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
| 1704 | static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1705 | path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE); |
| 1706 | PyObject *argv; |
| 1707 | PyObject *env; |
| 1708 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1709 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1710 | path_converter, &path, &argv, &env)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1711 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1712 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1713 | return_value = os_execve_impl(module, &path, argv, env); |
| 1714 | |
| 1715 | exit: |
| 1716 | /* Cleanup for path */ |
| 1717 | path_cleanup(&path); |
| 1718 | |
| 1719 | return return_value; |
| 1720 | } |
| 1721 | |
| 1722 | #endif /* defined(HAVE_EXECV) */ |
| 1723 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1724 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1725 | |
| 1726 | PyDoc_STRVAR(os_spawnv__doc__, |
| 1727 | "spawnv($module, mode, path, argv, /)\n" |
| 1728 | "--\n" |
| 1729 | "\n" |
| 1730 | "Execute the program specified by path in a new process.\n" |
| 1731 | "\n" |
| 1732 | " mode\n" |
| 1733 | " Mode of process creation.\n" |
| 1734 | " path\n" |
| 1735 | " Path of executable file.\n" |
| 1736 | " argv\n" |
| 1737 | " Tuple or list of strings."); |
| 1738 | |
| 1739 | #define OS_SPAWNV_METHODDEF \ |
| 1740 | {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__}, |
| 1741 | |
| 1742 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1743 | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1744 | |
| 1745 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1746 | os_spawnv(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1747 | { |
| 1748 | PyObject *return_value = NULL; |
| 1749 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1750 | path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1751 | PyObject *argv; |
| 1752 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 1753 | if (!PyArg_ParseTuple(args, "iO&O:spawnv", |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1754 | &mode, path_converter, &path, &argv)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1755 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1756 | } |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1757 | return_value = os_spawnv_impl(module, mode, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1758 | |
| 1759 | exit: |
| 1760 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1761 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1762 | |
| 1763 | return return_value; |
| 1764 | } |
| 1765 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1766 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1767 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1768 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1769 | |
| 1770 | PyDoc_STRVAR(os_spawnve__doc__, |
| 1771 | "spawnve($module, mode, path, argv, env, /)\n" |
| 1772 | "--\n" |
| 1773 | "\n" |
| 1774 | "Execute the program specified by path in a new process.\n" |
| 1775 | "\n" |
| 1776 | " mode\n" |
| 1777 | " Mode of process creation.\n" |
| 1778 | " path\n" |
| 1779 | " Path of executable file.\n" |
| 1780 | " argv\n" |
| 1781 | " Tuple or list of strings.\n" |
| 1782 | " env\n" |
| 1783 | " Dictionary of strings mapping to strings."); |
| 1784 | |
| 1785 | #define OS_SPAWNVE_METHODDEF \ |
| 1786 | {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__}, |
| 1787 | |
| 1788 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1789 | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1790 | PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1791 | |
| 1792 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1793 | os_spawnve(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1794 | { |
| 1795 | PyObject *return_value = NULL; |
| 1796 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1797 | path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1798 | PyObject *argv; |
| 1799 | PyObject *env; |
| 1800 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 1801 | if (!PyArg_ParseTuple(args, "iO&OO:spawnve", |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1802 | &mode, path_converter, &path, &argv, &env)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1803 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1804 | } |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1805 | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1806 | |
| 1807 | exit: |
| 1808 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1809 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1810 | |
| 1811 | return return_value; |
| 1812 | } |
| 1813 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1814 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1815 | |
| 1816 | #if defined(HAVE_FORK1) |
| 1817 | |
| 1818 | PyDoc_STRVAR(os_fork1__doc__, |
| 1819 | "fork1($module, /)\n" |
| 1820 | "--\n" |
| 1821 | "\n" |
| 1822 | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
| 1823 | "\n" |
| 1824 | "Return 0 to child process and PID of child to parent process."); |
| 1825 | |
| 1826 | #define OS_FORK1_METHODDEF \ |
| 1827 | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
| 1828 | |
| 1829 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1830 | os_fork1_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1831 | |
| 1832 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1833 | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1834 | { |
| 1835 | return os_fork1_impl(module); |
| 1836 | } |
| 1837 | |
| 1838 | #endif /* defined(HAVE_FORK1) */ |
| 1839 | |
| 1840 | #if defined(HAVE_FORK) |
| 1841 | |
| 1842 | PyDoc_STRVAR(os_fork__doc__, |
| 1843 | "fork($module, /)\n" |
| 1844 | "--\n" |
| 1845 | "\n" |
| 1846 | "Fork a child process.\n" |
| 1847 | "\n" |
| 1848 | "Return 0 to child process and PID of child to parent process."); |
| 1849 | |
| 1850 | #define OS_FORK_METHODDEF \ |
| 1851 | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
| 1852 | |
| 1853 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1854 | os_fork_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1855 | |
| 1856 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1857 | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1858 | { |
| 1859 | return os_fork_impl(module); |
| 1860 | } |
| 1861 | |
| 1862 | #endif /* defined(HAVE_FORK) */ |
| 1863 | |
| 1864 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 1865 | |
| 1866 | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
| 1867 | "sched_get_priority_max($module, /, policy)\n" |
| 1868 | "--\n" |
| 1869 | "\n" |
| 1870 | "Get the maximum scheduling priority for policy."); |
| 1871 | |
| 1872 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1873 | {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_FASTCALL, os_sched_get_priority_max__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1874 | |
| 1875 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1876 | os_sched_get_priority_max_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1877 | |
| 1878 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1879 | os_sched_get_priority_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1880 | { |
| 1881 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1882 | static const char * const _keywords[] = {"policy", NULL}; |
| 1883 | static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1884 | int policy; |
| 1885 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1886 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1887 | &policy)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1888 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1889 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1890 | return_value = os_sched_get_priority_max_impl(module, policy); |
| 1891 | |
| 1892 | exit: |
| 1893 | return return_value; |
| 1894 | } |
| 1895 | |
| 1896 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 1897 | |
| 1898 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 1899 | |
| 1900 | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
| 1901 | "sched_get_priority_min($module, /, policy)\n" |
| 1902 | "--\n" |
| 1903 | "\n" |
| 1904 | "Get the minimum scheduling priority for policy."); |
| 1905 | |
| 1906 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1907 | {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_FASTCALL, os_sched_get_priority_min__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1908 | |
| 1909 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1910 | os_sched_get_priority_min_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1911 | |
| 1912 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1913 | os_sched_get_priority_min(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1914 | { |
| 1915 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1916 | static const char * const _keywords[] = {"policy", NULL}; |
| 1917 | static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1918 | int policy; |
| 1919 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 1920 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1921 | &policy)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1922 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1923 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1924 | return_value = os_sched_get_priority_min_impl(module, policy); |
| 1925 | |
| 1926 | exit: |
| 1927 | return return_value; |
| 1928 | } |
| 1929 | |
| 1930 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 1931 | |
| 1932 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 1933 | |
| 1934 | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
| 1935 | "sched_getscheduler($module, pid, /)\n" |
| 1936 | "--\n" |
| 1937 | "\n" |
| 1938 | "Get the scheduling policy for the process identifiedy by pid.\n" |
| 1939 | "\n" |
| 1940 | "Passing 0 for pid returns the scheduling policy for the calling process."); |
| 1941 | |
| 1942 | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1943 | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1944 | |
| 1945 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1946 | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1947 | |
| 1948 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1949 | os_sched_getscheduler(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1950 | { |
| 1951 | PyObject *return_value = NULL; |
| 1952 | pid_t pid; |
| 1953 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1954 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1955 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1956 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1957 | return_value = os_sched_getscheduler_impl(module, pid); |
| 1958 | |
| 1959 | exit: |
| 1960 | return return_value; |
| 1961 | } |
| 1962 | |
| 1963 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 1964 | |
| 1965 | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) |
| 1966 | |
| 1967 | PyDoc_STRVAR(os_sched_param__doc__, |
| 1968 | "sched_param(sched_priority)\n" |
| 1969 | "--\n" |
| 1970 | "\n" |
| 1971 | "Current has only one field: sched_priority\");\n" |
| 1972 | "\n" |
| 1973 | " sched_priority\n" |
| 1974 | " A scheduling parameter."); |
| 1975 | |
| 1976 | static PyObject * |
| 1977 | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
| 1978 | |
| 1979 | static PyObject * |
| 1980 | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 1981 | { |
| 1982 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1983 | static const char * const _keywords[] = {"sched_priority", NULL}; |
| 1984 | static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1985 | PyObject *sched_priority; |
| 1986 | |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1987 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1988 | &sched_priority)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1989 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1990 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1991 | return_value = os_sched_param_impl(type, sched_priority); |
| 1992 | |
| 1993 | exit: |
| 1994 | return return_value; |
| 1995 | } |
| 1996 | |
| 1997 | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */ |
| 1998 | |
| 1999 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 2000 | |
| 2001 | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
| 2002 | "sched_setscheduler($module, pid, policy, param, /)\n" |
| 2003 | "--\n" |
| 2004 | "\n" |
| 2005 | "Set the scheduling policy for the process identified by pid.\n" |
| 2006 | "\n" |
| 2007 | "If pid is 0, the calling process is changed.\n" |
| 2008 | "param is an instance of sched_param."); |
| 2009 | |
| 2010 | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
| 2011 | {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__}, |
| 2012 | |
| 2013 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2014 | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2015 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2016 | |
| 2017 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2018 | os_sched_setscheduler(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2019 | { |
| 2020 | PyObject *return_value = NULL; |
| 2021 | pid_t pid; |
| 2022 | int policy; |
| 2023 | struct sched_param param; |
| 2024 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 2025 | if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO&:sched_setscheduler", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2026 | &pid, &policy, convert_sched_param, ¶m)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2027 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2028 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2029 | return_value = os_sched_setscheduler_impl(module, pid, policy, ¶m); |
| 2030 | |
| 2031 | exit: |
| 2032 | return return_value; |
| 2033 | } |
| 2034 | |
| 2035 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 2036 | |
| 2037 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2038 | |
| 2039 | PyDoc_STRVAR(os_sched_getparam__doc__, |
| 2040 | "sched_getparam($module, pid, /)\n" |
| 2041 | "--\n" |
| 2042 | "\n" |
| 2043 | "Returns scheduling parameters for the process identified by pid.\n" |
| 2044 | "\n" |
| 2045 | "If pid is 0, returns parameters for the calling process.\n" |
| 2046 | "Return value is an instance of sched_param."); |
| 2047 | |
| 2048 | #define OS_SCHED_GETPARAM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2049 | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2050 | |
| 2051 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2052 | os_sched_getparam_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2053 | |
| 2054 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2055 | os_sched_getparam(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2056 | { |
| 2057 | PyObject *return_value = NULL; |
| 2058 | pid_t pid; |
| 2059 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2060 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2061 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2062 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2063 | return_value = os_sched_getparam_impl(module, pid); |
| 2064 | |
| 2065 | exit: |
| 2066 | return return_value; |
| 2067 | } |
| 2068 | |
| 2069 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2070 | |
| 2071 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2072 | |
| 2073 | PyDoc_STRVAR(os_sched_setparam__doc__, |
| 2074 | "sched_setparam($module, pid, param, /)\n" |
| 2075 | "--\n" |
| 2076 | "\n" |
| 2077 | "Set scheduling parameters for the process identified by pid.\n" |
| 2078 | "\n" |
| 2079 | "If pid is 0, sets parameters for the calling process.\n" |
| 2080 | "param should be an instance of sched_param."); |
| 2081 | |
| 2082 | #define OS_SCHED_SETPARAM_METHODDEF \ |
| 2083 | {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__}, |
| 2084 | |
| 2085 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2086 | os_sched_setparam_impl(PyObject *module, pid_t pid, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2087 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2088 | |
| 2089 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2090 | os_sched_setparam(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2091 | { |
| 2092 | PyObject *return_value = NULL; |
| 2093 | pid_t pid; |
| 2094 | struct sched_param param; |
| 2095 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 2096 | if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O&:sched_setparam", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2097 | &pid, convert_sched_param, ¶m)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2098 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2099 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2100 | return_value = os_sched_setparam_impl(module, pid, ¶m); |
| 2101 | |
| 2102 | exit: |
| 2103 | return return_value; |
| 2104 | } |
| 2105 | |
| 2106 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2107 | |
| 2108 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
| 2109 | |
| 2110 | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
| 2111 | "sched_rr_get_interval($module, pid, /)\n" |
| 2112 | "--\n" |
| 2113 | "\n" |
| 2114 | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
| 2115 | "\n" |
| 2116 | "Value returned is a float."); |
| 2117 | |
| 2118 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2119 | {"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] | 2120 | |
| 2121 | static double |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2122 | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
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_rr_get_interval(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2126 | { |
| 2127 | PyObject *return_value = NULL; |
| 2128 | pid_t pid; |
| 2129 | double _return_value; |
| 2130 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2131 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2132 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2133 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2134 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2135 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2136 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2137 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2138 | return_value = PyFloat_FromDouble(_return_value); |
| 2139 | |
| 2140 | exit: |
| 2141 | return return_value; |
| 2142 | } |
| 2143 | |
| 2144 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
| 2145 | |
| 2146 | #if defined(HAVE_SCHED_H) |
| 2147 | |
| 2148 | PyDoc_STRVAR(os_sched_yield__doc__, |
| 2149 | "sched_yield($module, /)\n" |
| 2150 | "--\n" |
| 2151 | "\n" |
| 2152 | "Voluntarily relinquish the CPU."); |
| 2153 | |
| 2154 | #define OS_SCHED_YIELD_METHODDEF \ |
| 2155 | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
| 2156 | |
| 2157 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2158 | os_sched_yield_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_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2162 | { |
| 2163 | return os_sched_yield_impl(module); |
| 2164 | } |
| 2165 | |
| 2166 | #endif /* defined(HAVE_SCHED_H) */ |
| 2167 | |
| 2168 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 2169 | |
| 2170 | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
| 2171 | "sched_setaffinity($module, pid, mask, /)\n" |
| 2172 | "--\n" |
| 2173 | "\n" |
| 2174 | "Set the CPU affinity of the process identified by pid to mask.\n" |
| 2175 | "\n" |
| 2176 | "mask should be an iterable of integers identifying CPUs."); |
| 2177 | |
| 2178 | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
| 2179 | {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__}, |
| 2180 | |
| 2181 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2182 | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2183 | |
| 2184 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2185 | os_sched_setaffinity(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2186 | { |
| 2187 | PyObject *return_value = NULL; |
| 2188 | pid_t pid; |
| 2189 | PyObject *mask; |
| 2190 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 2191 | if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O:sched_setaffinity", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2192 | &pid, &mask)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2193 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2194 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2195 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
| 2196 | |
| 2197 | exit: |
| 2198 | return return_value; |
| 2199 | } |
| 2200 | |
| 2201 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 2202 | |
| 2203 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 2204 | |
| 2205 | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
| 2206 | "sched_getaffinity($module, pid, /)\n" |
| 2207 | "--\n" |
| 2208 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 2209 | "Return the affinity of the process identified by pid (or the current process if zero).\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2210 | "\n" |
| 2211 | "The affinity is returned as a set of CPU identifiers."); |
| 2212 | |
| 2213 | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2214 | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2215 | |
| 2216 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2217 | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2218 | |
| 2219 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2220 | os_sched_getaffinity(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2221 | { |
| 2222 | PyObject *return_value = NULL; |
| 2223 | pid_t pid; |
| 2224 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2225 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2226 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2227 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2228 | return_value = os_sched_getaffinity_impl(module, pid); |
| 2229 | |
| 2230 | exit: |
| 2231 | return return_value; |
| 2232 | } |
| 2233 | |
| 2234 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 2235 | |
| 2236 | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
| 2237 | |
| 2238 | PyDoc_STRVAR(os_openpty__doc__, |
| 2239 | "openpty($module, /)\n" |
| 2240 | "--\n" |
| 2241 | "\n" |
| 2242 | "Open a pseudo-terminal.\n" |
| 2243 | "\n" |
| 2244 | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
| 2245 | "for both the master and slave ends."); |
| 2246 | |
| 2247 | #define OS_OPENPTY_METHODDEF \ |
| 2248 | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
| 2249 | |
| 2250 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2251 | os_openpty_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_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2255 | { |
| 2256 | return os_openpty_impl(module); |
| 2257 | } |
| 2258 | |
| 2259 | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
| 2260 | |
| 2261 | #if defined(HAVE_FORKPTY) |
| 2262 | |
| 2263 | PyDoc_STRVAR(os_forkpty__doc__, |
| 2264 | "forkpty($module, /)\n" |
| 2265 | "--\n" |
| 2266 | "\n" |
| 2267 | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
| 2268 | "\n" |
| 2269 | "Returns a tuple of (pid, master_fd).\n" |
| 2270 | "Like fork(), return pid of 0 to the child process,\n" |
| 2271 | "and pid of child to the parent process.\n" |
| 2272 | "To both, return fd of newly opened pseudo-terminal."); |
| 2273 | |
| 2274 | #define OS_FORKPTY_METHODDEF \ |
| 2275 | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
| 2276 | |
| 2277 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2278 | os_forkpty_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2279 | |
| 2280 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2281 | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2282 | { |
| 2283 | return os_forkpty_impl(module); |
| 2284 | } |
| 2285 | |
| 2286 | #endif /* defined(HAVE_FORKPTY) */ |
| 2287 | |
| 2288 | #if defined(HAVE_GETEGID) |
| 2289 | |
| 2290 | PyDoc_STRVAR(os_getegid__doc__, |
| 2291 | "getegid($module, /)\n" |
| 2292 | "--\n" |
| 2293 | "\n" |
| 2294 | "Return the current process\'s effective group id."); |
| 2295 | |
| 2296 | #define OS_GETEGID_METHODDEF \ |
| 2297 | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
| 2298 | |
| 2299 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2300 | os_getegid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2301 | |
| 2302 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2303 | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2304 | { |
| 2305 | return os_getegid_impl(module); |
| 2306 | } |
| 2307 | |
| 2308 | #endif /* defined(HAVE_GETEGID) */ |
| 2309 | |
| 2310 | #if defined(HAVE_GETEUID) |
| 2311 | |
| 2312 | PyDoc_STRVAR(os_geteuid__doc__, |
| 2313 | "geteuid($module, /)\n" |
| 2314 | "--\n" |
| 2315 | "\n" |
| 2316 | "Return the current process\'s effective user id."); |
| 2317 | |
| 2318 | #define OS_GETEUID_METHODDEF \ |
| 2319 | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
| 2320 | |
| 2321 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2322 | os_geteuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2323 | |
| 2324 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2325 | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2326 | { |
| 2327 | return os_geteuid_impl(module); |
| 2328 | } |
| 2329 | |
| 2330 | #endif /* defined(HAVE_GETEUID) */ |
| 2331 | |
| 2332 | #if defined(HAVE_GETGID) |
| 2333 | |
| 2334 | PyDoc_STRVAR(os_getgid__doc__, |
| 2335 | "getgid($module, /)\n" |
| 2336 | "--\n" |
| 2337 | "\n" |
| 2338 | "Return the current process\'s group id."); |
| 2339 | |
| 2340 | #define OS_GETGID_METHODDEF \ |
| 2341 | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
| 2342 | |
| 2343 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2344 | os_getgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2345 | |
| 2346 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2347 | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2348 | { |
| 2349 | return os_getgid_impl(module); |
| 2350 | } |
| 2351 | |
| 2352 | #endif /* defined(HAVE_GETGID) */ |
| 2353 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 2354 | #if defined(HAVE_GETPID) |
| 2355 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2356 | PyDoc_STRVAR(os_getpid__doc__, |
| 2357 | "getpid($module, /)\n" |
| 2358 | "--\n" |
| 2359 | "\n" |
| 2360 | "Return the current process id."); |
| 2361 | |
| 2362 | #define OS_GETPID_METHODDEF \ |
| 2363 | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
| 2364 | |
| 2365 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2366 | os_getpid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2367 | |
| 2368 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2369 | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2370 | { |
| 2371 | return os_getpid_impl(module); |
| 2372 | } |
| 2373 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 2374 | #endif /* defined(HAVE_GETPID) */ |
| 2375 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2376 | #if defined(HAVE_GETGROUPS) |
| 2377 | |
| 2378 | PyDoc_STRVAR(os_getgroups__doc__, |
| 2379 | "getgroups($module, /)\n" |
| 2380 | "--\n" |
| 2381 | "\n" |
| 2382 | "Return list of supplemental group IDs for the process."); |
| 2383 | |
| 2384 | #define OS_GETGROUPS_METHODDEF \ |
| 2385 | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
| 2386 | |
| 2387 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2388 | os_getgroups_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2389 | |
| 2390 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2391 | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2392 | { |
| 2393 | return os_getgroups_impl(module); |
| 2394 | } |
| 2395 | |
| 2396 | #endif /* defined(HAVE_GETGROUPS) */ |
| 2397 | |
| 2398 | #if defined(HAVE_GETPGID) |
| 2399 | |
| 2400 | PyDoc_STRVAR(os_getpgid__doc__, |
| 2401 | "getpgid($module, /, pid)\n" |
| 2402 | "--\n" |
| 2403 | "\n" |
| 2404 | "Call the system call getpgid(), and return the result."); |
| 2405 | |
| 2406 | #define OS_GETPGID_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 2407 | {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL, os_getpgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2408 | |
| 2409 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2410 | os_getpgid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2411 | |
| 2412 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 2413 | os_getpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2414 | { |
| 2415 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2416 | static const char * const _keywords[] = {"pid", NULL}; |
| 2417 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2418 | pid_t pid; |
| 2419 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 2420 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2421 | &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2422 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2423 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2424 | return_value = os_getpgid_impl(module, pid); |
| 2425 | |
| 2426 | exit: |
| 2427 | return return_value; |
| 2428 | } |
| 2429 | |
| 2430 | #endif /* defined(HAVE_GETPGID) */ |
| 2431 | |
| 2432 | #if defined(HAVE_GETPGRP) |
| 2433 | |
| 2434 | PyDoc_STRVAR(os_getpgrp__doc__, |
| 2435 | "getpgrp($module, /)\n" |
| 2436 | "--\n" |
| 2437 | "\n" |
| 2438 | "Return the current process group id."); |
| 2439 | |
| 2440 | #define OS_GETPGRP_METHODDEF \ |
| 2441 | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
| 2442 | |
| 2443 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2444 | os_getpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2445 | |
| 2446 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2447 | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2448 | { |
| 2449 | return os_getpgrp_impl(module); |
| 2450 | } |
| 2451 | |
| 2452 | #endif /* defined(HAVE_GETPGRP) */ |
| 2453 | |
| 2454 | #if defined(HAVE_SETPGRP) |
| 2455 | |
| 2456 | PyDoc_STRVAR(os_setpgrp__doc__, |
| 2457 | "setpgrp($module, /)\n" |
| 2458 | "--\n" |
| 2459 | "\n" |
| 2460 | "Make the current process the leader of its process group."); |
| 2461 | |
| 2462 | #define OS_SETPGRP_METHODDEF \ |
| 2463 | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
| 2464 | |
| 2465 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2466 | os_setpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2467 | |
| 2468 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2469 | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2470 | { |
| 2471 | return os_setpgrp_impl(module); |
| 2472 | } |
| 2473 | |
| 2474 | #endif /* defined(HAVE_SETPGRP) */ |
| 2475 | |
| 2476 | #if defined(HAVE_GETPPID) |
| 2477 | |
| 2478 | PyDoc_STRVAR(os_getppid__doc__, |
| 2479 | "getppid($module, /)\n" |
| 2480 | "--\n" |
| 2481 | "\n" |
| 2482 | "Return the parent\'s process id.\n" |
| 2483 | "\n" |
| 2484 | "If the parent process has already exited, Windows machines will still\n" |
| 2485 | "return its id; others systems will return the id of the \'init\' process (1)."); |
| 2486 | |
| 2487 | #define OS_GETPPID_METHODDEF \ |
| 2488 | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
| 2489 | |
| 2490 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2491 | os_getppid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2492 | |
| 2493 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2494 | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2495 | { |
| 2496 | return os_getppid_impl(module); |
| 2497 | } |
| 2498 | |
| 2499 | #endif /* defined(HAVE_GETPPID) */ |
| 2500 | |
| 2501 | #if defined(HAVE_GETLOGIN) |
| 2502 | |
| 2503 | PyDoc_STRVAR(os_getlogin__doc__, |
| 2504 | "getlogin($module, /)\n" |
| 2505 | "--\n" |
| 2506 | "\n" |
| 2507 | "Return the actual login name."); |
| 2508 | |
| 2509 | #define OS_GETLOGIN_METHODDEF \ |
| 2510 | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
| 2511 | |
| 2512 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2513 | os_getlogin_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2514 | |
| 2515 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2516 | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2517 | { |
| 2518 | return os_getlogin_impl(module); |
| 2519 | } |
| 2520 | |
| 2521 | #endif /* defined(HAVE_GETLOGIN) */ |
| 2522 | |
| 2523 | #if defined(HAVE_GETUID) |
| 2524 | |
| 2525 | PyDoc_STRVAR(os_getuid__doc__, |
| 2526 | "getuid($module, /)\n" |
| 2527 | "--\n" |
| 2528 | "\n" |
| 2529 | "Return the current process\'s user id."); |
| 2530 | |
| 2531 | #define OS_GETUID_METHODDEF \ |
| 2532 | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
| 2533 | |
| 2534 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2535 | os_getuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2536 | |
| 2537 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2538 | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2539 | { |
| 2540 | return os_getuid_impl(module); |
| 2541 | } |
| 2542 | |
| 2543 | #endif /* defined(HAVE_GETUID) */ |
| 2544 | |
| 2545 | #if defined(HAVE_KILL) |
| 2546 | |
| 2547 | PyDoc_STRVAR(os_kill__doc__, |
| 2548 | "kill($module, pid, signal, /)\n" |
| 2549 | "--\n" |
| 2550 | "\n" |
| 2551 | "Kill a process with a signal."); |
| 2552 | |
| 2553 | #define OS_KILL_METHODDEF \ |
| 2554 | {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__}, |
| 2555 | |
| 2556 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2557 | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2558 | |
| 2559 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2560 | os_kill(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2561 | { |
| 2562 | PyObject *return_value = NULL; |
| 2563 | pid_t pid; |
| 2564 | Py_ssize_t signal; |
| 2565 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 2566 | if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "n:kill", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2567 | &pid, &signal)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2568 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2569 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2570 | return_value = os_kill_impl(module, pid, signal); |
| 2571 | |
| 2572 | exit: |
| 2573 | return return_value; |
| 2574 | } |
| 2575 | |
| 2576 | #endif /* defined(HAVE_KILL) */ |
| 2577 | |
| 2578 | #if defined(HAVE_KILLPG) |
| 2579 | |
| 2580 | PyDoc_STRVAR(os_killpg__doc__, |
| 2581 | "killpg($module, pgid, signal, /)\n" |
| 2582 | "--\n" |
| 2583 | "\n" |
| 2584 | "Kill a process group with a signal."); |
| 2585 | |
| 2586 | #define OS_KILLPG_METHODDEF \ |
| 2587 | {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__}, |
| 2588 | |
| 2589 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2590 | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2591 | |
| 2592 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2593 | os_killpg(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2594 | { |
| 2595 | PyObject *return_value = NULL; |
| 2596 | pid_t pgid; |
| 2597 | int signal; |
| 2598 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 2599 | if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:killpg", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2600 | &pgid, &signal)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2601 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2602 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2603 | return_value = os_killpg_impl(module, pgid, signal); |
| 2604 | |
| 2605 | exit: |
| 2606 | return return_value; |
| 2607 | } |
| 2608 | |
| 2609 | #endif /* defined(HAVE_KILLPG) */ |
| 2610 | |
| 2611 | #if defined(HAVE_PLOCK) |
| 2612 | |
| 2613 | PyDoc_STRVAR(os_plock__doc__, |
| 2614 | "plock($module, op, /)\n" |
| 2615 | "--\n" |
| 2616 | "\n" |
| 2617 | "Lock program segments into memory.\");"); |
| 2618 | |
| 2619 | #define OS_PLOCK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2620 | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2621 | |
| 2622 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2623 | os_plock_impl(PyObject *module, int op); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2624 | |
| 2625 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2626 | os_plock(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2627 | { |
| 2628 | PyObject *return_value = NULL; |
| 2629 | int op; |
| 2630 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2631 | if (!PyArg_Parse(arg, "i:plock", &op)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2632 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2633 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2634 | return_value = os_plock_impl(module, op); |
| 2635 | |
| 2636 | exit: |
| 2637 | return return_value; |
| 2638 | } |
| 2639 | |
| 2640 | #endif /* defined(HAVE_PLOCK) */ |
| 2641 | |
| 2642 | #if defined(HAVE_SETUID) |
| 2643 | |
| 2644 | PyDoc_STRVAR(os_setuid__doc__, |
| 2645 | "setuid($module, uid, /)\n" |
| 2646 | "--\n" |
| 2647 | "\n" |
| 2648 | "Set the current process\'s user id."); |
| 2649 | |
| 2650 | #define OS_SETUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2651 | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2652 | |
| 2653 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2654 | os_setuid_impl(PyObject *module, uid_t uid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2655 | |
| 2656 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2657 | os_setuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2658 | { |
| 2659 | PyObject *return_value = NULL; |
| 2660 | uid_t uid; |
| 2661 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2662 | if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2663 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2664 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2665 | return_value = os_setuid_impl(module, uid); |
| 2666 | |
| 2667 | exit: |
| 2668 | return return_value; |
| 2669 | } |
| 2670 | |
| 2671 | #endif /* defined(HAVE_SETUID) */ |
| 2672 | |
| 2673 | #if defined(HAVE_SETEUID) |
| 2674 | |
| 2675 | PyDoc_STRVAR(os_seteuid__doc__, |
| 2676 | "seteuid($module, euid, /)\n" |
| 2677 | "--\n" |
| 2678 | "\n" |
| 2679 | "Set the current process\'s effective user id."); |
| 2680 | |
| 2681 | #define OS_SETEUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2682 | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2683 | |
| 2684 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2685 | os_seteuid_impl(PyObject *module, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2686 | |
| 2687 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2688 | os_seteuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2689 | { |
| 2690 | PyObject *return_value = NULL; |
| 2691 | uid_t euid; |
| 2692 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2693 | if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2694 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2695 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2696 | return_value = os_seteuid_impl(module, euid); |
| 2697 | |
| 2698 | exit: |
| 2699 | return return_value; |
| 2700 | } |
| 2701 | |
| 2702 | #endif /* defined(HAVE_SETEUID) */ |
| 2703 | |
| 2704 | #if defined(HAVE_SETEGID) |
| 2705 | |
| 2706 | PyDoc_STRVAR(os_setegid__doc__, |
| 2707 | "setegid($module, egid, /)\n" |
| 2708 | "--\n" |
| 2709 | "\n" |
| 2710 | "Set the current process\'s effective group id."); |
| 2711 | |
| 2712 | #define OS_SETEGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2713 | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2714 | |
| 2715 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2716 | os_setegid_impl(PyObject *module, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2717 | |
| 2718 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2719 | os_setegid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2720 | { |
| 2721 | PyObject *return_value = NULL; |
| 2722 | gid_t egid; |
| 2723 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2724 | if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2725 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2726 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2727 | return_value = os_setegid_impl(module, egid); |
| 2728 | |
| 2729 | exit: |
| 2730 | return return_value; |
| 2731 | } |
| 2732 | |
| 2733 | #endif /* defined(HAVE_SETEGID) */ |
| 2734 | |
| 2735 | #if defined(HAVE_SETREUID) |
| 2736 | |
| 2737 | PyDoc_STRVAR(os_setreuid__doc__, |
| 2738 | "setreuid($module, ruid, euid, /)\n" |
| 2739 | "--\n" |
| 2740 | "\n" |
| 2741 | "Set the current process\'s real and effective user ids."); |
| 2742 | |
| 2743 | #define OS_SETREUID_METHODDEF \ |
| 2744 | {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__}, |
| 2745 | |
| 2746 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2747 | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2748 | |
| 2749 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2750 | os_setreuid(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2751 | { |
| 2752 | PyObject *return_value = NULL; |
| 2753 | uid_t ruid; |
| 2754 | uid_t euid; |
| 2755 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 2756 | if (!PyArg_ParseTuple(args, "O&O&:setreuid", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2757 | _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2758 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2759 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2760 | return_value = os_setreuid_impl(module, ruid, euid); |
| 2761 | |
| 2762 | exit: |
| 2763 | return return_value; |
| 2764 | } |
| 2765 | |
| 2766 | #endif /* defined(HAVE_SETREUID) */ |
| 2767 | |
| 2768 | #if defined(HAVE_SETREGID) |
| 2769 | |
| 2770 | PyDoc_STRVAR(os_setregid__doc__, |
| 2771 | "setregid($module, rgid, egid, /)\n" |
| 2772 | "--\n" |
| 2773 | "\n" |
| 2774 | "Set the current process\'s real and effective group ids."); |
| 2775 | |
| 2776 | #define OS_SETREGID_METHODDEF \ |
| 2777 | {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__}, |
| 2778 | |
| 2779 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2780 | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2781 | |
| 2782 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2783 | os_setregid(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2784 | { |
| 2785 | PyObject *return_value = NULL; |
| 2786 | gid_t rgid; |
| 2787 | gid_t egid; |
| 2788 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 2789 | if (!PyArg_ParseTuple(args, "O&O&:setregid", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2790 | _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2791 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2792 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2793 | return_value = os_setregid_impl(module, rgid, egid); |
| 2794 | |
| 2795 | exit: |
| 2796 | return return_value; |
| 2797 | } |
| 2798 | |
| 2799 | #endif /* defined(HAVE_SETREGID) */ |
| 2800 | |
| 2801 | #if defined(HAVE_SETGID) |
| 2802 | |
| 2803 | PyDoc_STRVAR(os_setgid__doc__, |
| 2804 | "setgid($module, gid, /)\n" |
| 2805 | "--\n" |
| 2806 | "\n" |
| 2807 | "Set the current process\'s group id."); |
| 2808 | |
| 2809 | #define OS_SETGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2810 | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2811 | |
| 2812 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2813 | os_setgid_impl(PyObject *module, gid_t gid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2814 | |
| 2815 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2816 | os_setgid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2817 | { |
| 2818 | PyObject *return_value = NULL; |
| 2819 | gid_t gid; |
| 2820 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2821 | if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2822 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2823 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2824 | return_value = os_setgid_impl(module, gid); |
| 2825 | |
| 2826 | exit: |
| 2827 | return return_value; |
| 2828 | } |
| 2829 | |
| 2830 | #endif /* defined(HAVE_SETGID) */ |
| 2831 | |
| 2832 | #if defined(HAVE_SETGROUPS) |
| 2833 | |
| 2834 | PyDoc_STRVAR(os_setgroups__doc__, |
| 2835 | "setgroups($module, groups, /)\n" |
| 2836 | "--\n" |
| 2837 | "\n" |
| 2838 | "Set the groups of the current process to list."); |
| 2839 | |
| 2840 | #define OS_SETGROUPS_METHODDEF \ |
| 2841 | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
| 2842 | |
| 2843 | #endif /* defined(HAVE_SETGROUPS) */ |
| 2844 | |
| 2845 | #if defined(HAVE_WAIT3) |
| 2846 | |
| 2847 | PyDoc_STRVAR(os_wait3__doc__, |
| 2848 | "wait3($module, /, options)\n" |
| 2849 | "--\n" |
| 2850 | "\n" |
| 2851 | "Wait for completion of a child process.\n" |
| 2852 | "\n" |
| 2853 | "Returns a tuple of information about the child process:\n" |
| 2854 | " (pid, status, rusage)"); |
| 2855 | |
| 2856 | #define OS_WAIT3_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 2857 | {"wait3", (PyCFunction)os_wait3, METH_FASTCALL, os_wait3__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2858 | |
| 2859 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2860 | os_wait3_impl(PyObject *module, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2861 | |
| 2862 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 2863 | os_wait3(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2864 | { |
| 2865 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2866 | static const char * const _keywords[] = {"options", NULL}; |
| 2867 | static _PyArg_Parser _parser = {"i:wait3", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2868 | int options; |
| 2869 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 2870 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2871 | &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2872 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2873 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2874 | return_value = os_wait3_impl(module, options); |
| 2875 | |
| 2876 | exit: |
| 2877 | return return_value; |
| 2878 | } |
| 2879 | |
| 2880 | #endif /* defined(HAVE_WAIT3) */ |
| 2881 | |
| 2882 | #if defined(HAVE_WAIT4) |
| 2883 | |
| 2884 | PyDoc_STRVAR(os_wait4__doc__, |
| 2885 | "wait4($module, /, pid, options)\n" |
| 2886 | "--\n" |
| 2887 | "\n" |
| 2888 | "Wait for completion of a specific child process.\n" |
| 2889 | "\n" |
| 2890 | "Returns a tuple of information about the child process:\n" |
| 2891 | " (pid, status, rusage)"); |
| 2892 | |
| 2893 | #define OS_WAIT4_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 2894 | {"wait4", (PyCFunction)os_wait4, METH_FASTCALL, os_wait4__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2895 | |
| 2896 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2897 | os_wait4_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2898 | |
| 2899 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 2900 | os_wait4(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2901 | { |
| 2902 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2903 | static const char * const _keywords[] = {"pid", "options", NULL}; |
| 2904 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2905 | pid_t pid; |
| 2906 | int options; |
| 2907 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 2908 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2909 | &pid, &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2910 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2911 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2912 | return_value = os_wait4_impl(module, pid, options); |
| 2913 | |
| 2914 | exit: |
| 2915 | return return_value; |
| 2916 | } |
| 2917 | |
| 2918 | #endif /* defined(HAVE_WAIT4) */ |
| 2919 | |
| 2920 | #if (defined(HAVE_WAITID) && !defined(__APPLE__)) |
| 2921 | |
| 2922 | PyDoc_STRVAR(os_waitid__doc__, |
| 2923 | "waitid($module, idtype, id, options, /)\n" |
| 2924 | "--\n" |
| 2925 | "\n" |
| 2926 | "Returns the result of waiting for a process or processes.\n" |
| 2927 | "\n" |
| 2928 | " idtype\n" |
| 2929 | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
| 2930 | " id\n" |
| 2931 | " The id to wait on.\n" |
| 2932 | " options\n" |
| 2933 | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
| 2934 | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
| 2935 | "\n" |
| 2936 | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
| 2937 | "no children in a waitable state."); |
| 2938 | |
| 2939 | #define OS_WAITID_METHODDEF \ |
| 2940 | {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__}, |
| 2941 | |
| 2942 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2943 | 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] | 2944 | |
| 2945 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2946 | os_waitid(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2947 | { |
| 2948 | PyObject *return_value = NULL; |
| 2949 | idtype_t idtype; |
| 2950 | id_t id; |
| 2951 | int options; |
| 2952 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 2953 | if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2954 | &idtype, &id, &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2955 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2956 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2957 | return_value = os_waitid_impl(module, idtype, id, options); |
| 2958 | |
| 2959 | exit: |
| 2960 | return return_value; |
| 2961 | } |
| 2962 | |
| 2963 | #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */ |
| 2964 | |
| 2965 | #if defined(HAVE_WAITPID) |
| 2966 | |
| 2967 | PyDoc_STRVAR(os_waitpid__doc__, |
| 2968 | "waitpid($module, pid, options, /)\n" |
| 2969 | "--\n" |
| 2970 | "\n" |
| 2971 | "Wait for completion of a given child process.\n" |
| 2972 | "\n" |
| 2973 | "Returns a tuple of information regarding the child process:\n" |
| 2974 | " (pid, status)\n" |
| 2975 | "\n" |
| 2976 | "The options argument is ignored on Windows."); |
| 2977 | |
| 2978 | #define OS_WAITPID_METHODDEF \ |
| 2979 | {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__}, |
| 2980 | |
| 2981 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2982 | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2983 | |
| 2984 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2985 | os_waitpid(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2986 | { |
| 2987 | PyObject *return_value = NULL; |
| 2988 | pid_t pid; |
| 2989 | int options; |
| 2990 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 2991 | if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:waitpid", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2992 | &pid, &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2993 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2994 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2995 | return_value = os_waitpid_impl(module, pid, options); |
| 2996 | |
| 2997 | exit: |
| 2998 | return return_value; |
| 2999 | } |
| 3000 | |
| 3001 | #endif /* defined(HAVE_WAITPID) */ |
| 3002 | |
| 3003 | #if defined(HAVE_CWAIT) |
| 3004 | |
| 3005 | PyDoc_STRVAR(os_waitpid__doc__, |
| 3006 | "waitpid($module, pid, options, /)\n" |
| 3007 | "--\n" |
| 3008 | "\n" |
| 3009 | "Wait for completion of a given process.\n" |
| 3010 | "\n" |
| 3011 | "Returns a tuple of information regarding the process:\n" |
| 3012 | " (pid, status << 8)\n" |
| 3013 | "\n" |
| 3014 | "The options argument is ignored on Windows."); |
| 3015 | |
| 3016 | #define OS_WAITPID_METHODDEF \ |
| 3017 | {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__}, |
| 3018 | |
| 3019 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3020 | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3021 | |
| 3022 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3023 | os_waitpid(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3024 | { |
| 3025 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3026 | intptr_t pid; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3027 | int options; |
| 3028 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3029 | if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "i:waitpid", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3030 | &pid, &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3031 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3032 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3033 | return_value = os_waitpid_impl(module, pid, options); |
| 3034 | |
| 3035 | exit: |
| 3036 | return return_value; |
| 3037 | } |
| 3038 | |
| 3039 | #endif /* defined(HAVE_CWAIT) */ |
| 3040 | |
| 3041 | #if defined(HAVE_WAIT) |
| 3042 | |
| 3043 | PyDoc_STRVAR(os_wait__doc__, |
| 3044 | "wait($module, /)\n" |
| 3045 | "--\n" |
| 3046 | "\n" |
| 3047 | "Wait for completion of a child process.\n" |
| 3048 | "\n" |
| 3049 | "Returns a tuple of information about the child process:\n" |
| 3050 | " (pid, status)"); |
| 3051 | |
| 3052 | #define OS_WAIT_METHODDEF \ |
| 3053 | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
| 3054 | |
| 3055 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3056 | os_wait_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3057 | |
| 3058 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3059 | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3060 | { |
| 3061 | return os_wait_impl(module); |
| 3062 | } |
| 3063 | |
| 3064 | #endif /* defined(HAVE_WAIT) */ |
| 3065 | |
| 3066 | #if defined(HAVE_SYMLINK) |
| 3067 | |
| 3068 | PyDoc_STRVAR(os_symlink__doc__, |
| 3069 | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
| 3070 | "--\n" |
| 3071 | "\n" |
| 3072 | "Create a symbolic link pointing to src named dst.\n" |
| 3073 | "\n" |
| 3074 | "target_is_directory is required on Windows if the target is to be\n" |
| 3075 | " interpreted as a directory. (On Windows, symlink requires\n" |
| 3076 | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
| 3077 | " target_is_directory is ignored on non-Windows platforms.\n" |
| 3078 | "\n" |
| 3079 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3080 | " and path should be relative; path will then be relative to that directory.\n" |
| 3081 | "dir_fd may not be implemented on your platform.\n" |
| 3082 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3083 | |
| 3084 | #define OS_SYMLINK_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3085 | {"symlink", (PyCFunction)os_symlink, METH_FASTCALL, os_symlink__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3086 | |
| 3087 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3088 | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 3089 | int target_is_directory, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3090 | |
| 3091 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3092 | os_symlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3093 | { |
| 3094 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3095 | static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
| 3096 | static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3097 | path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0); |
| 3098 | path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0); |
| 3099 | int target_is_directory = 0; |
| 3100 | int dir_fd = DEFAULT_DIR_FD; |
| 3101 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3102 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3103 | path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3104 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3105 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3106 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
| 3107 | |
| 3108 | exit: |
| 3109 | /* Cleanup for src */ |
| 3110 | path_cleanup(&src); |
| 3111 | /* Cleanup for dst */ |
| 3112 | path_cleanup(&dst); |
| 3113 | |
| 3114 | return return_value; |
| 3115 | } |
| 3116 | |
| 3117 | #endif /* defined(HAVE_SYMLINK) */ |
| 3118 | |
| 3119 | #if defined(HAVE_TIMES) |
| 3120 | |
| 3121 | PyDoc_STRVAR(os_times__doc__, |
| 3122 | "times($module, /)\n" |
| 3123 | "--\n" |
| 3124 | "\n" |
| 3125 | "Return a collection containing process timing information.\n" |
| 3126 | "\n" |
| 3127 | "The object returned behaves like a named tuple with these fields:\n" |
| 3128 | " (utime, stime, cutime, cstime, elapsed_time)\n" |
| 3129 | "All fields are floating point numbers."); |
| 3130 | |
| 3131 | #define OS_TIMES_METHODDEF \ |
| 3132 | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
| 3133 | |
| 3134 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3135 | os_times_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3136 | |
| 3137 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3138 | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3139 | { |
| 3140 | return os_times_impl(module); |
| 3141 | } |
| 3142 | |
| 3143 | #endif /* defined(HAVE_TIMES) */ |
| 3144 | |
| 3145 | #if defined(HAVE_GETSID) |
| 3146 | |
| 3147 | PyDoc_STRVAR(os_getsid__doc__, |
| 3148 | "getsid($module, pid, /)\n" |
| 3149 | "--\n" |
| 3150 | "\n" |
| 3151 | "Call the system call getsid(pid) and return the result."); |
| 3152 | |
| 3153 | #define OS_GETSID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3154 | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
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_getsid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3158 | |
| 3159 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3160 | os_getsid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3161 | { |
| 3162 | PyObject *return_value = NULL; |
| 3163 | pid_t pid; |
| 3164 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3165 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3166 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3167 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3168 | return_value = os_getsid_impl(module, pid); |
| 3169 | |
| 3170 | exit: |
| 3171 | return return_value; |
| 3172 | } |
| 3173 | |
| 3174 | #endif /* defined(HAVE_GETSID) */ |
| 3175 | |
| 3176 | #if defined(HAVE_SETSID) |
| 3177 | |
| 3178 | PyDoc_STRVAR(os_setsid__doc__, |
| 3179 | "setsid($module, /)\n" |
| 3180 | "--\n" |
| 3181 | "\n" |
| 3182 | "Call the system call setsid()."); |
| 3183 | |
| 3184 | #define OS_SETSID_METHODDEF \ |
| 3185 | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
| 3186 | |
| 3187 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3188 | os_setsid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3189 | |
| 3190 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3191 | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3192 | { |
| 3193 | return os_setsid_impl(module); |
| 3194 | } |
| 3195 | |
| 3196 | #endif /* defined(HAVE_SETSID) */ |
| 3197 | |
| 3198 | #if defined(HAVE_SETPGID) |
| 3199 | |
| 3200 | PyDoc_STRVAR(os_setpgid__doc__, |
| 3201 | "setpgid($module, pid, pgrp, /)\n" |
| 3202 | "--\n" |
| 3203 | "\n" |
| 3204 | "Call the system call setpgid(pid, pgrp)."); |
| 3205 | |
| 3206 | #define OS_SETPGID_METHODDEF \ |
| 3207 | {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__}, |
| 3208 | |
| 3209 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3210 | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3211 | |
| 3212 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3213 | os_setpgid(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3214 | { |
| 3215 | PyObject *return_value = NULL; |
| 3216 | pid_t pid; |
| 3217 | pid_t pgrp; |
| 3218 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3219 | if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3220 | &pid, &pgrp)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3221 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3222 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3223 | return_value = os_setpgid_impl(module, pid, pgrp); |
| 3224 | |
| 3225 | exit: |
| 3226 | return return_value; |
| 3227 | } |
| 3228 | |
| 3229 | #endif /* defined(HAVE_SETPGID) */ |
| 3230 | |
| 3231 | #if defined(HAVE_TCGETPGRP) |
| 3232 | |
| 3233 | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
| 3234 | "tcgetpgrp($module, fd, /)\n" |
| 3235 | "--\n" |
| 3236 | "\n" |
| 3237 | "Return the process group associated with the terminal specified by fd."); |
| 3238 | |
| 3239 | #define OS_TCGETPGRP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3240 | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3241 | |
| 3242 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3243 | os_tcgetpgrp_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3244 | |
| 3245 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3246 | os_tcgetpgrp(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3247 | { |
| 3248 | PyObject *return_value = NULL; |
| 3249 | int fd; |
| 3250 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3251 | if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3252 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3253 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3254 | return_value = os_tcgetpgrp_impl(module, fd); |
| 3255 | |
| 3256 | exit: |
| 3257 | return return_value; |
| 3258 | } |
| 3259 | |
| 3260 | #endif /* defined(HAVE_TCGETPGRP) */ |
| 3261 | |
| 3262 | #if defined(HAVE_TCSETPGRP) |
| 3263 | |
| 3264 | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
| 3265 | "tcsetpgrp($module, fd, pgid, /)\n" |
| 3266 | "--\n" |
| 3267 | "\n" |
| 3268 | "Set the process group associated with the terminal specified by fd."); |
| 3269 | |
| 3270 | #define OS_TCSETPGRP_METHODDEF \ |
| 3271 | {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__}, |
| 3272 | |
| 3273 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3274 | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3275 | |
| 3276 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3277 | os_tcsetpgrp(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3278 | { |
| 3279 | PyObject *return_value = NULL; |
| 3280 | int fd; |
| 3281 | pid_t pgid; |
| 3282 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3283 | if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID ":tcsetpgrp", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3284 | &fd, &pgid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3285 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3286 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3287 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
| 3288 | |
| 3289 | exit: |
| 3290 | return return_value; |
| 3291 | } |
| 3292 | |
| 3293 | #endif /* defined(HAVE_TCSETPGRP) */ |
| 3294 | |
| 3295 | PyDoc_STRVAR(os_open__doc__, |
| 3296 | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
| 3297 | "--\n" |
| 3298 | "\n" |
| 3299 | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
| 3300 | "\n" |
| 3301 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3302 | " and path should be relative; path will then be relative to that directory.\n" |
| 3303 | "dir_fd may not be implemented on your platform.\n" |
| 3304 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3305 | |
| 3306 | #define OS_OPEN_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3307 | {"open", (PyCFunction)os_open, METH_FASTCALL, os_open__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3308 | |
| 3309 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3310 | 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] | 3311 | |
| 3312 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3313 | os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3314 | { |
| 3315 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3316 | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
| 3317 | static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3318 | path_t path = PATH_T_INITIALIZE("open", "path", 0, 0); |
| 3319 | int flags; |
| 3320 | int mode = 511; |
| 3321 | int dir_fd = DEFAULT_DIR_FD; |
| 3322 | int _return_value; |
| 3323 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3324 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3325 | path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3326 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3327 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3328 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3329 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3330 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3331 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3332 | return_value = PyLong_FromLong((long)_return_value); |
| 3333 | |
| 3334 | exit: |
| 3335 | /* Cleanup for path */ |
| 3336 | path_cleanup(&path); |
| 3337 | |
| 3338 | return return_value; |
| 3339 | } |
| 3340 | |
| 3341 | PyDoc_STRVAR(os_close__doc__, |
| 3342 | "close($module, /, fd)\n" |
| 3343 | "--\n" |
| 3344 | "\n" |
| 3345 | "Close a file descriptor."); |
| 3346 | |
| 3347 | #define OS_CLOSE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3348 | {"close", (PyCFunction)os_close, METH_FASTCALL, os_close__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3349 | |
| 3350 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3351 | os_close_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3352 | |
| 3353 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3354 | os_close(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3355 | { |
| 3356 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3357 | static const char * const _keywords[] = {"fd", NULL}; |
| 3358 | static _PyArg_Parser _parser = {"i:close", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3359 | int fd; |
| 3360 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3361 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3362 | &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3363 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3364 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3365 | return_value = os_close_impl(module, fd); |
| 3366 | |
| 3367 | exit: |
| 3368 | return return_value; |
| 3369 | } |
| 3370 | |
| 3371 | PyDoc_STRVAR(os_closerange__doc__, |
| 3372 | "closerange($module, fd_low, fd_high, /)\n" |
| 3373 | "--\n" |
| 3374 | "\n" |
| 3375 | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
| 3376 | |
| 3377 | #define OS_CLOSERANGE_METHODDEF \ |
| 3378 | {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__}, |
| 3379 | |
| 3380 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3381 | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3382 | |
| 3383 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3384 | os_closerange(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3385 | { |
| 3386 | PyObject *return_value = NULL; |
| 3387 | int fd_low; |
| 3388 | int fd_high; |
| 3389 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3390 | if (!PyArg_ParseTuple(args, "ii:closerange", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3391 | &fd_low, &fd_high)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3392 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3393 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3394 | return_value = os_closerange_impl(module, fd_low, fd_high); |
| 3395 | |
| 3396 | exit: |
| 3397 | return return_value; |
| 3398 | } |
| 3399 | |
| 3400 | PyDoc_STRVAR(os_dup__doc__, |
| 3401 | "dup($module, fd, /)\n" |
| 3402 | "--\n" |
| 3403 | "\n" |
| 3404 | "Return a duplicate of a file descriptor."); |
| 3405 | |
| 3406 | #define OS_DUP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3407 | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3408 | |
| 3409 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3410 | os_dup_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3411 | |
| 3412 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3413 | os_dup(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3414 | { |
| 3415 | PyObject *return_value = NULL; |
| 3416 | int fd; |
| 3417 | int _return_value; |
| 3418 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3419 | if (!PyArg_Parse(arg, "i:dup", &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3420 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3421 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3422 | _return_value = os_dup_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3423 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3424 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3425 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3426 | return_value = PyLong_FromLong((long)_return_value); |
| 3427 | |
| 3428 | exit: |
| 3429 | return return_value; |
| 3430 | } |
| 3431 | |
| 3432 | PyDoc_STRVAR(os_dup2__doc__, |
| 3433 | "dup2($module, /, fd, fd2, inheritable=True)\n" |
| 3434 | "--\n" |
| 3435 | "\n" |
| 3436 | "Duplicate file descriptor."); |
| 3437 | |
| 3438 | #define OS_DUP2_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3439 | {"dup2", (PyCFunction)os_dup2, METH_FASTCALL, os_dup2__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3440 | |
| 3441 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3442 | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3443 | |
| 3444 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3445 | os_dup2(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3446 | { |
| 3447 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3448 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
| 3449 | static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3450 | int fd; |
| 3451 | int fd2; |
| 3452 | int inheritable = 1; |
| 3453 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3454 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3455 | &fd, &fd2, &inheritable)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3456 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3457 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3458 | return_value = os_dup2_impl(module, fd, fd2, inheritable); |
| 3459 | |
| 3460 | exit: |
| 3461 | return return_value; |
| 3462 | } |
| 3463 | |
| 3464 | #if defined(HAVE_LOCKF) |
| 3465 | |
| 3466 | PyDoc_STRVAR(os_lockf__doc__, |
| 3467 | "lockf($module, fd, command, length, /)\n" |
| 3468 | "--\n" |
| 3469 | "\n" |
| 3470 | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
| 3471 | "\n" |
| 3472 | " fd\n" |
| 3473 | " An open file descriptor.\n" |
| 3474 | " command\n" |
| 3475 | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
| 3476 | " length\n" |
| 3477 | " The number of bytes to lock, starting at the current position."); |
| 3478 | |
| 3479 | #define OS_LOCKF_METHODDEF \ |
| 3480 | {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__}, |
| 3481 | |
| 3482 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3483 | 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] | 3484 | |
| 3485 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3486 | os_lockf(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3487 | { |
| 3488 | PyObject *return_value = NULL; |
| 3489 | int fd; |
| 3490 | int command; |
| 3491 | Py_off_t length; |
| 3492 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3493 | if (!PyArg_ParseTuple(args, "iiO&:lockf", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3494 | &fd, &command, Py_off_t_converter, &length)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3495 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3496 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3497 | return_value = os_lockf_impl(module, fd, command, length); |
| 3498 | |
| 3499 | exit: |
| 3500 | return return_value; |
| 3501 | } |
| 3502 | |
| 3503 | #endif /* defined(HAVE_LOCKF) */ |
| 3504 | |
| 3505 | PyDoc_STRVAR(os_lseek__doc__, |
| 3506 | "lseek($module, fd, position, how, /)\n" |
| 3507 | "--\n" |
| 3508 | "\n" |
| 3509 | "Set the position of a file descriptor. Return the new position.\n" |
| 3510 | "\n" |
| 3511 | "Return the new cursor position in number of bytes\n" |
| 3512 | "relative to the beginning of the file."); |
| 3513 | |
| 3514 | #define OS_LSEEK_METHODDEF \ |
| 3515 | {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__}, |
| 3516 | |
| 3517 | static Py_off_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3518 | 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] | 3519 | |
| 3520 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3521 | os_lseek(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3522 | { |
| 3523 | PyObject *return_value = NULL; |
| 3524 | int fd; |
| 3525 | Py_off_t position; |
| 3526 | int how; |
| 3527 | Py_off_t _return_value; |
| 3528 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3529 | if (!PyArg_ParseTuple(args, "iO&i:lseek", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3530 | &fd, Py_off_t_converter, &position, &how)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3531 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3532 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3533 | _return_value = os_lseek_impl(module, fd, position, how); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3534 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3535 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3536 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3537 | return_value = PyLong_FromPy_off_t(_return_value); |
| 3538 | |
| 3539 | exit: |
| 3540 | return return_value; |
| 3541 | } |
| 3542 | |
| 3543 | PyDoc_STRVAR(os_read__doc__, |
| 3544 | "read($module, fd, length, /)\n" |
| 3545 | "--\n" |
| 3546 | "\n" |
| 3547 | "Read from a file descriptor. Returns a bytes object."); |
| 3548 | |
| 3549 | #define OS_READ_METHODDEF \ |
| 3550 | {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__}, |
| 3551 | |
| 3552 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3553 | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3554 | |
| 3555 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3556 | os_read(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3557 | { |
| 3558 | PyObject *return_value = NULL; |
| 3559 | int fd; |
| 3560 | Py_ssize_t length; |
| 3561 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3562 | if (!PyArg_ParseTuple(args, "in:read", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3563 | &fd, &length)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3564 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3565 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3566 | return_value = os_read_impl(module, fd, length); |
| 3567 | |
| 3568 | exit: |
| 3569 | return return_value; |
| 3570 | } |
| 3571 | |
| 3572 | #if defined(HAVE_READV) |
| 3573 | |
| 3574 | PyDoc_STRVAR(os_readv__doc__, |
| 3575 | "readv($module, fd, buffers, /)\n" |
| 3576 | "--\n" |
| 3577 | "\n" |
| 3578 | "Read from a file descriptor fd into an iterable of buffers.\n" |
| 3579 | "\n" |
| 3580 | "The buffers should be mutable buffers accepting bytes.\n" |
| 3581 | "readv will transfer data into each buffer until it is full\n" |
| 3582 | "and then move on to the next buffer in the sequence to hold\n" |
| 3583 | "the rest of the data.\n" |
| 3584 | "\n" |
| 3585 | "readv returns the total number of bytes read,\n" |
| 3586 | "which may be less than the total capacity of all the buffers."); |
| 3587 | |
| 3588 | #define OS_READV_METHODDEF \ |
| 3589 | {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__}, |
| 3590 | |
| 3591 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3592 | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3593 | |
| 3594 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3595 | os_readv(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3596 | { |
| 3597 | PyObject *return_value = NULL; |
| 3598 | int fd; |
| 3599 | PyObject *buffers; |
| 3600 | Py_ssize_t _return_value; |
| 3601 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3602 | if (!PyArg_ParseTuple(args, "iO:readv", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3603 | &fd, &buffers)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3604 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3605 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3606 | _return_value = os_readv_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3607 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3608 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3609 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3610 | return_value = PyLong_FromSsize_t(_return_value); |
| 3611 | |
| 3612 | exit: |
| 3613 | return return_value; |
| 3614 | } |
| 3615 | |
| 3616 | #endif /* defined(HAVE_READV) */ |
| 3617 | |
| 3618 | #if defined(HAVE_PREAD) |
| 3619 | |
| 3620 | PyDoc_STRVAR(os_pread__doc__, |
| 3621 | "pread($module, fd, length, offset, /)\n" |
| 3622 | "--\n" |
| 3623 | "\n" |
| 3624 | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
| 3625 | "\n" |
| 3626 | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
| 3627 | "the beginning of the file. The file offset remains unchanged."); |
| 3628 | |
| 3629 | #define OS_PREAD_METHODDEF \ |
| 3630 | {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__}, |
| 3631 | |
| 3632 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3633 | 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] | 3634 | |
| 3635 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3636 | os_pread(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3637 | { |
| 3638 | PyObject *return_value = NULL; |
| 3639 | int fd; |
| 3640 | int length; |
| 3641 | Py_off_t offset; |
| 3642 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3643 | if (!PyArg_ParseTuple(args, "iiO&:pread", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3644 | &fd, &length, Py_off_t_converter, &offset)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3645 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3646 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3647 | return_value = os_pread_impl(module, fd, length, offset); |
| 3648 | |
| 3649 | exit: |
| 3650 | return return_value; |
| 3651 | } |
| 3652 | |
| 3653 | #endif /* defined(HAVE_PREAD) */ |
| 3654 | |
| 3655 | PyDoc_STRVAR(os_write__doc__, |
| 3656 | "write($module, fd, data, /)\n" |
| 3657 | "--\n" |
| 3658 | "\n" |
| 3659 | "Write a bytes object to a file descriptor."); |
| 3660 | |
| 3661 | #define OS_WRITE_METHODDEF \ |
| 3662 | {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__}, |
| 3663 | |
| 3664 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3665 | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3666 | |
| 3667 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3668 | os_write(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3669 | { |
| 3670 | PyObject *return_value = NULL; |
| 3671 | int fd; |
| 3672 | Py_buffer data = {NULL, NULL}; |
| 3673 | Py_ssize_t _return_value; |
| 3674 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3675 | if (!PyArg_ParseTuple(args, "iy*:write", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3676 | &fd, &data)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3677 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3678 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3679 | _return_value = os_write_impl(module, fd, &data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3680 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3681 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3682 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3683 | return_value = PyLong_FromSsize_t(_return_value); |
| 3684 | |
| 3685 | exit: |
| 3686 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3687 | if (data.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3688 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3689 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3690 | |
| 3691 | return return_value; |
| 3692 | } |
| 3693 | |
| 3694 | PyDoc_STRVAR(os_fstat__doc__, |
| 3695 | "fstat($module, /, fd)\n" |
| 3696 | "--\n" |
| 3697 | "\n" |
| 3698 | "Perform a stat system call on the given file descriptor.\n" |
| 3699 | "\n" |
| 3700 | "Like stat(), but for an open file descriptor.\n" |
| 3701 | "Equivalent to os.stat(fd)."); |
| 3702 | |
| 3703 | #define OS_FSTAT_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3704 | {"fstat", (PyCFunction)os_fstat, METH_FASTCALL, os_fstat__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3705 | |
| 3706 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3707 | os_fstat_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3708 | |
| 3709 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3710 | os_fstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3711 | { |
| 3712 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3713 | static const char * const _keywords[] = {"fd", NULL}; |
| 3714 | static _PyArg_Parser _parser = {"i:fstat", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3715 | int fd; |
| 3716 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3717 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3718 | &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3719 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3720 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3721 | return_value = os_fstat_impl(module, fd); |
| 3722 | |
| 3723 | exit: |
| 3724 | return return_value; |
| 3725 | } |
| 3726 | |
| 3727 | PyDoc_STRVAR(os_isatty__doc__, |
| 3728 | "isatty($module, fd, /)\n" |
| 3729 | "--\n" |
| 3730 | "\n" |
| 3731 | "Return True if the fd is connected to a terminal.\n" |
| 3732 | "\n" |
| 3733 | "Return True if the file descriptor is an open file descriptor\n" |
| 3734 | "connected to the slave end of a terminal."); |
| 3735 | |
| 3736 | #define OS_ISATTY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3737 | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3738 | |
| 3739 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3740 | os_isatty_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3741 | |
| 3742 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3743 | os_isatty(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3744 | { |
| 3745 | PyObject *return_value = NULL; |
| 3746 | int fd; |
| 3747 | int _return_value; |
| 3748 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3749 | if (!PyArg_Parse(arg, "i:isatty", &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3750 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3751 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3752 | _return_value = os_isatty_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3753 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3754 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3755 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3756 | return_value = PyBool_FromLong((long)_return_value); |
| 3757 | |
| 3758 | exit: |
| 3759 | return return_value; |
| 3760 | } |
| 3761 | |
| 3762 | #if defined(HAVE_PIPE) |
| 3763 | |
| 3764 | PyDoc_STRVAR(os_pipe__doc__, |
| 3765 | "pipe($module, /)\n" |
| 3766 | "--\n" |
| 3767 | "\n" |
| 3768 | "Create a pipe.\n" |
| 3769 | "\n" |
| 3770 | "Returns a tuple of two file descriptors:\n" |
| 3771 | " (read_fd, write_fd)"); |
| 3772 | |
| 3773 | #define OS_PIPE_METHODDEF \ |
| 3774 | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
| 3775 | |
| 3776 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3777 | os_pipe_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3778 | |
| 3779 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3780 | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3781 | { |
| 3782 | return os_pipe_impl(module); |
| 3783 | } |
| 3784 | |
| 3785 | #endif /* defined(HAVE_PIPE) */ |
| 3786 | |
| 3787 | #if defined(HAVE_PIPE2) |
| 3788 | |
| 3789 | PyDoc_STRVAR(os_pipe2__doc__, |
| 3790 | "pipe2($module, flags, /)\n" |
| 3791 | "--\n" |
| 3792 | "\n" |
| 3793 | "Create a pipe with flags set atomically.\n" |
| 3794 | "\n" |
| 3795 | "Returns a tuple of two file descriptors:\n" |
| 3796 | " (read_fd, write_fd)\n" |
| 3797 | "\n" |
| 3798 | "flags can be constructed by ORing together one or more of these values:\n" |
| 3799 | "O_NONBLOCK, O_CLOEXEC."); |
| 3800 | |
| 3801 | #define OS_PIPE2_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3802 | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3803 | |
| 3804 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3805 | os_pipe2_impl(PyObject *module, int flags); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3806 | |
| 3807 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3808 | os_pipe2(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3809 | { |
| 3810 | PyObject *return_value = NULL; |
| 3811 | int flags; |
| 3812 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3813 | if (!PyArg_Parse(arg, "i:pipe2", &flags)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3814 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3815 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3816 | return_value = os_pipe2_impl(module, flags); |
| 3817 | |
| 3818 | exit: |
| 3819 | return return_value; |
| 3820 | } |
| 3821 | |
| 3822 | #endif /* defined(HAVE_PIPE2) */ |
| 3823 | |
| 3824 | #if defined(HAVE_WRITEV) |
| 3825 | |
| 3826 | PyDoc_STRVAR(os_writev__doc__, |
| 3827 | "writev($module, fd, buffers, /)\n" |
| 3828 | "--\n" |
| 3829 | "\n" |
| 3830 | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
| 3831 | "\n" |
| 3832 | "Returns the total number of bytes written.\n" |
| 3833 | "buffers must be a sequence of bytes-like objects."); |
| 3834 | |
| 3835 | #define OS_WRITEV_METHODDEF \ |
| 3836 | {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__}, |
| 3837 | |
| 3838 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3839 | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3840 | |
| 3841 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3842 | os_writev(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3843 | { |
| 3844 | PyObject *return_value = NULL; |
| 3845 | int fd; |
| 3846 | PyObject *buffers; |
| 3847 | Py_ssize_t _return_value; |
| 3848 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3849 | if (!PyArg_ParseTuple(args, "iO:writev", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3850 | &fd, &buffers)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3851 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3852 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3853 | _return_value = os_writev_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3854 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3855 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3856 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3857 | return_value = PyLong_FromSsize_t(_return_value); |
| 3858 | |
| 3859 | exit: |
| 3860 | return return_value; |
| 3861 | } |
| 3862 | |
| 3863 | #endif /* defined(HAVE_WRITEV) */ |
| 3864 | |
| 3865 | #if defined(HAVE_PWRITE) |
| 3866 | |
| 3867 | PyDoc_STRVAR(os_pwrite__doc__, |
| 3868 | "pwrite($module, fd, buffer, offset, /)\n" |
| 3869 | "--\n" |
| 3870 | "\n" |
| 3871 | "Write bytes to a file descriptor starting at a particular offset.\n" |
| 3872 | "\n" |
| 3873 | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
| 3874 | "the file. Returns the number of bytes writte. Does not change the\n" |
| 3875 | "current file offset."); |
| 3876 | |
| 3877 | #define OS_PWRITE_METHODDEF \ |
| 3878 | {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__}, |
| 3879 | |
| 3880 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3881 | 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] | 3882 | |
| 3883 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3884 | os_pwrite(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3885 | { |
| 3886 | PyObject *return_value = NULL; |
| 3887 | int fd; |
| 3888 | Py_buffer buffer = {NULL, NULL}; |
| 3889 | Py_off_t offset; |
| 3890 | Py_ssize_t _return_value; |
| 3891 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 3892 | if (!PyArg_ParseTuple(args, "iy*O&:pwrite", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3893 | &fd, &buffer, Py_off_t_converter, &offset)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3894 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3895 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3896 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3897 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3898 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3899 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3900 | return_value = PyLong_FromSsize_t(_return_value); |
| 3901 | |
| 3902 | exit: |
| 3903 | /* Cleanup for buffer */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3904 | if (buffer.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3905 | PyBuffer_Release(&buffer); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3906 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3907 | |
| 3908 | return return_value; |
| 3909 | } |
| 3910 | |
| 3911 | #endif /* defined(HAVE_PWRITE) */ |
| 3912 | |
| 3913 | #if defined(HAVE_MKFIFO) |
| 3914 | |
| 3915 | PyDoc_STRVAR(os_mkfifo__doc__, |
| 3916 | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
| 3917 | "--\n" |
| 3918 | "\n" |
| 3919 | "Create a \"fifo\" (a POSIX named pipe).\n" |
| 3920 | "\n" |
| 3921 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3922 | " and path should be relative; path will then be relative to that directory.\n" |
| 3923 | "dir_fd may not be implemented on your platform.\n" |
| 3924 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3925 | |
| 3926 | #define OS_MKFIFO_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3927 | {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL, os_mkfifo__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3928 | |
| 3929 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3930 | 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] | 3931 | |
| 3932 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3933 | os_mkfifo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3934 | { |
| 3935 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3936 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
| 3937 | static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3938 | path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0); |
| 3939 | int mode = 438; |
| 3940 | int dir_fd = DEFAULT_DIR_FD; |
| 3941 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3942 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3943 | path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3944 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3945 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3946 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
| 3947 | |
| 3948 | exit: |
| 3949 | /* Cleanup for path */ |
| 3950 | path_cleanup(&path); |
| 3951 | |
| 3952 | return return_value; |
| 3953 | } |
| 3954 | |
| 3955 | #endif /* defined(HAVE_MKFIFO) */ |
| 3956 | |
| 3957 | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
| 3958 | |
| 3959 | PyDoc_STRVAR(os_mknod__doc__, |
| 3960 | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
| 3961 | "--\n" |
| 3962 | "\n" |
| 3963 | "Create a node in the file system.\n" |
| 3964 | "\n" |
| 3965 | "Create a node in the file system (file, device special file or named pipe)\n" |
| 3966 | "at path. mode specifies both the permissions to use and the\n" |
| 3967 | "type of node to be created, being combined (bitwise OR) with one of\n" |
| 3968 | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
| 3969 | "device defines the newly created device special file (probably using\n" |
| 3970 | "os.makedev()). Otherwise device is ignored.\n" |
| 3971 | "\n" |
| 3972 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3973 | " and path should be relative; path will then be relative to that directory.\n" |
| 3974 | "dir_fd may not be implemented on your platform.\n" |
| 3975 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3976 | |
| 3977 | #define OS_MKNOD_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3978 | {"mknod", (PyCFunction)os_mknod, METH_FASTCALL, os_mknod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3979 | |
| 3980 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3981 | 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] | 3982 | int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3983 | |
| 3984 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3985 | os_mknod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3986 | { |
| 3987 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3988 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
| 3989 | static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3990 | path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0); |
| 3991 | int mode = 384; |
| 3992 | dev_t device = 0; |
| 3993 | int dir_fd = DEFAULT_DIR_FD; |
| 3994 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 3995 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3996 | path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3997 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3998 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3999 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
| 4000 | |
| 4001 | exit: |
| 4002 | /* Cleanup for path */ |
| 4003 | path_cleanup(&path); |
| 4004 | |
| 4005 | return return_value; |
| 4006 | } |
| 4007 | |
| 4008 | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
| 4009 | |
| 4010 | #if defined(HAVE_DEVICE_MACROS) |
| 4011 | |
| 4012 | PyDoc_STRVAR(os_major__doc__, |
| 4013 | "major($module, device, /)\n" |
| 4014 | "--\n" |
| 4015 | "\n" |
| 4016 | "Extracts a device major number from a raw device number."); |
| 4017 | |
| 4018 | #define OS_MAJOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4019 | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4020 | |
| 4021 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4022 | os_major_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4023 | |
| 4024 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4025 | os_major(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4026 | { |
| 4027 | PyObject *return_value = NULL; |
| 4028 | dev_t device; |
| 4029 | unsigned int _return_value; |
| 4030 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4031 | if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4032 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4033 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4034 | _return_value = os_major_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4035 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4036 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4037 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4038 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 4039 | |
| 4040 | exit: |
| 4041 | return return_value; |
| 4042 | } |
| 4043 | |
| 4044 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 4045 | |
| 4046 | #if defined(HAVE_DEVICE_MACROS) |
| 4047 | |
| 4048 | PyDoc_STRVAR(os_minor__doc__, |
| 4049 | "minor($module, device, /)\n" |
| 4050 | "--\n" |
| 4051 | "\n" |
| 4052 | "Extracts a device minor number from a raw device number."); |
| 4053 | |
| 4054 | #define OS_MINOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4055 | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4056 | |
| 4057 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4058 | os_minor_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4059 | |
| 4060 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4061 | os_minor(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4062 | { |
| 4063 | PyObject *return_value = NULL; |
| 4064 | dev_t device; |
| 4065 | unsigned int _return_value; |
| 4066 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4067 | if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4068 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4069 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4070 | _return_value = os_minor_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4071 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4072 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4073 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4074 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 4075 | |
| 4076 | exit: |
| 4077 | return return_value; |
| 4078 | } |
| 4079 | |
| 4080 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 4081 | |
| 4082 | #if defined(HAVE_DEVICE_MACROS) |
| 4083 | |
| 4084 | PyDoc_STRVAR(os_makedev__doc__, |
| 4085 | "makedev($module, major, minor, /)\n" |
| 4086 | "--\n" |
| 4087 | "\n" |
| 4088 | "Composes a raw device number from the major and minor device numbers."); |
| 4089 | |
| 4090 | #define OS_MAKEDEV_METHODDEF \ |
| 4091 | {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__}, |
| 4092 | |
| 4093 | static dev_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4094 | os_makedev_impl(PyObject *module, int major, int minor); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4095 | |
| 4096 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4097 | os_makedev(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4098 | { |
| 4099 | PyObject *return_value = NULL; |
| 4100 | int major; |
| 4101 | int minor; |
| 4102 | dev_t _return_value; |
| 4103 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 4104 | if (!PyArg_ParseTuple(args, "ii:makedev", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4105 | &major, &minor)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4106 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4107 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4108 | _return_value = os_makedev_impl(module, major, minor); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4109 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4110 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4111 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4112 | return_value = _PyLong_FromDev(_return_value); |
| 4113 | |
| 4114 | exit: |
| 4115 | return return_value; |
| 4116 | } |
| 4117 | |
| 4118 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 4119 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4120 | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4121 | |
| 4122 | PyDoc_STRVAR(os_ftruncate__doc__, |
| 4123 | "ftruncate($module, fd, length, /)\n" |
| 4124 | "--\n" |
| 4125 | "\n" |
| 4126 | "Truncate a file, specified by file descriptor, to a specific length."); |
| 4127 | |
| 4128 | #define OS_FTRUNCATE_METHODDEF \ |
| 4129 | {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__}, |
| 4130 | |
| 4131 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4132 | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4133 | |
| 4134 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4135 | os_ftruncate(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4136 | { |
| 4137 | PyObject *return_value = NULL; |
| 4138 | int fd; |
| 4139 | Py_off_t length; |
| 4140 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 4141 | if (!PyArg_ParseTuple(args, "iO&:ftruncate", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4142 | &fd, Py_off_t_converter, &length)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4143 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4144 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4145 | return_value = os_ftruncate_impl(module, fd, length); |
| 4146 | |
| 4147 | exit: |
| 4148 | return return_value; |
| 4149 | } |
| 4150 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4151 | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4152 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4153 | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4154 | |
| 4155 | PyDoc_STRVAR(os_truncate__doc__, |
| 4156 | "truncate($module, /, path, length)\n" |
| 4157 | "--\n" |
| 4158 | "\n" |
| 4159 | "Truncate a file, specified by path, to a specific length.\n" |
| 4160 | "\n" |
| 4161 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 4162 | " If this functionality is unavailable, using it raises an exception."); |
| 4163 | |
| 4164 | #define OS_TRUNCATE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4165 | {"truncate", (PyCFunction)os_truncate, METH_FASTCALL, os_truncate__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4166 | |
| 4167 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4168 | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4169 | |
| 4170 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4171 | os_truncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4172 | { |
| 4173 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4174 | static const char * const _keywords[] = {"path", "length", NULL}; |
| 4175 | static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4176 | path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE); |
| 4177 | Py_off_t length; |
| 4178 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4179 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4180 | path_converter, &path, Py_off_t_converter, &length)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4181 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4182 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4183 | return_value = os_truncate_impl(module, &path, length); |
| 4184 | |
| 4185 | exit: |
| 4186 | /* Cleanup for path */ |
| 4187 | path_cleanup(&path); |
| 4188 | |
| 4189 | return return_value; |
| 4190 | } |
| 4191 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4192 | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4193 | |
| 4194 | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 4195 | |
| 4196 | PyDoc_STRVAR(os_posix_fallocate__doc__, |
| 4197 | "posix_fallocate($module, fd, offset, length, /)\n" |
| 4198 | "--\n" |
| 4199 | "\n" |
| 4200 | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
| 4201 | "\n" |
| 4202 | "Ensure that the file specified by fd encompasses a range of bytes\n" |
| 4203 | "starting at offset bytes from the beginning and continuing for length bytes."); |
| 4204 | |
| 4205 | #define OS_POSIX_FALLOCATE_METHODDEF \ |
| 4206 | {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__}, |
| 4207 | |
| 4208 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4209 | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 4210 | Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4211 | |
| 4212 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4213 | os_posix_fallocate(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4214 | { |
| 4215 | PyObject *return_value = NULL; |
| 4216 | int fd; |
| 4217 | Py_off_t offset; |
| 4218 | Py_off_t length; |
| 4219 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 4220 | if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4221 | &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4222 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4223 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4224 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
| 4225 | |
| 4226 | exit: |
| 4227 | return return_value; |
| 4228 | } |
| 4229 | |
| 4230 | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 4231 | |
| 4232 | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 4233 | |
| 4234 | PyDoc_STRVAR(os_posix_fadvise__doc__, |
| 4235 | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
| 4236 | "--\n" |
| 4237 | "\n" |
| 4238 | "Announce an intention to access data in a specific pattern.\n" |
| 4239 | "\n" |
| 4240 | "Announce an intention to access data in a specific pattern, thus allowing\n" |
| 4241 | "the kernel to make optimizations.\n" |
| 4242 | "The advice applies to the region of the file specified by fd starting at\n" |
| 4243 | "offset and continuing for length bytes.\n" |
| 4244 | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
| 4245 | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
| 4246 | "POSIX_FADV_DONTNEED."); |
| 4247 | |
| 4248 | #define OS_POSIX_FADVISE_METHODDEF \ |
| 4249 | {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__}, |
| 4250 | |
| 4251 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4252 | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 4253 | Py_off_t length, int advice); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4254 | |
| 4255 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4256 | os_posix_fadvise(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4257 | { |
| 4258 | PyObject *return_value = NULL; |
| 4259 | int fd; |
| 4260 | Py_off_t offset; |
| 4261 | Py_off_t length; |
| 4262 | int advice; |
| 4263 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 4264 | if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4265 | &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4266 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4267 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4268 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
| 4269 | |
| 4270 | exit: |
| 4271 | return return_value; |
| 4272 | } |
| 4273 | |
| 4274 | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 4275 | |
| 4276 | #if defined(HAVE_PUTENV) && defined(MS_WINDOWS) |
| 4277 | |
| 4278 | PyDoc_STRVAR(os_putenv__doc__, |
| 4279 | "putenv($module, name, value, /)\n" |
| 4280 | "--\n" |
| 4281 | "\n" |
| 4282 | "Change or add an environment variable."); |
| 4283 | |
| 4284 | #define OS_PUTENV_METHODDEF \ |
| 4285 | {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__}, |
| 4286 | |
| 4287 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4288 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4289 | |
| 4290 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4291 | os_putenv(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4292 | { |
| 4293 | PyObject *return_value = NULL; |
| 4294 | PyObject *name; |
| 4295 | PyObject *value; |
| 4296 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 4297 | if (!PyArg_ParseTuple(args, "UU:putenv", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4298 | &name, &value)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4299 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4300 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4301 | return_value = os_putenv_impl(module, name, value); |
| 4302 | |
| 4303 | exit: |
| 4304 | return return_value; |
| 4305 | } |
| 4306 | |
| 4307 | #endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */ |
| 4308 | |
| 4309 | #if defined(HAVE_PUTENV) && !defined(MS_WINDOWS) |
| 4310 | |
| 4311 | PyDoc_STRVAR(os_putenv__doc__, |
| 4312 | "putenv($module, name, value, /)\n" |
| 4313 | "--\n" |
| 4314 | "\n" |
| 4315 | "Change or add an environment variable."); |
| 4316 | |
| 4317 | #define OS_PUTENV_METHODDEF \ |
| 4318 | {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__}, |
| 4319 | |
| 4320 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4321 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4322 | |
| 4323 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4324 | os_putenv(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4325 | { |
| 4326 | PyObject *return_value = NULL; |
| 4327 | PyObject *name = NULL; |
| 4328 | PyObject *value = NULL; |
| 4329 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 4330 | if (!PyArg_ParseTuple(args, "O&O&:putenv", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4331 | PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4332 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4333 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4334 | return_value = os_putenv_impl(module, name, value); |
| 4335 | |
| 4336 | exit: |
| 4337 | /* Cleanup for name */ |
| 4338 | Py_XDECREF(name); |
| 4339 | /* Cleanup for value */ |
| 4340 | Py_XDECREF(value); |
| 4341 | |
| 4342 | return return_value; |
| 4343 | } |
| 4344 | |
| 4345 | #endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */ |
| 4346 | |
| 4347 | #if defined(HAVE_UNSETENV) |
| 4348 | |
| 4349 | PyDoc_STRVAR(os_unsetenv__doc__, |
| 4350 | "unsetenv($module, name, /)\n" |
| 4351 | "--\n" |
| 4352 | "\n" |
| 4353 | "Delete an environment variable."); |
| 4354 | |
| 4355 | #define OS_UNSETENV_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4356 | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4357 | |
| 4358 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4359 | os_unsetenv_impl(PyObject *module, PyObject *name); |
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_unsetenv(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4363 | { |
| 4364 | PyObject *return_value = NULL; |
| 4365 | PyObject *name = NULL; |
| 4366 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4367 | if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4368 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4369 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4370 | return_value = os_unsetenv_impl(module, name); |
| 4371 | |
| 4372 | exit: |
| 4373 | /* Cleanup for name */ |
| 4374 | Py_XDECREF(name); |
| 4375 | |
| 4376 | return return_value; |
| 4377 | } |
| 4378 | |
| 4379 | #endif /* defined(HAVE_UNSETENV) */ |
| 4380 | |
| 4381 | PyDoc_STRVAR(os_strerror__doc__, |
| 4382 | "strerror($module, code, /)\n" |
| 4383 | "--\n" |
| 4384 | "\n" |
| 4385 | "Translate an error code to a message string."); |
| 4386 | |
| 4387 | #define OS_STRERROR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4388 | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4389 | |
| 4390 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4391 | os_strerror_impl(PyObject *module, int code); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4392 | |
| 4393 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4394 | os_strerror(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4395 | { |
| 4396 | PyObject *return_value = NULL; |
| 4397 | int code; |
| 4398 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4399 | if (!PyArg_Parse(arg, "i:strerror", &code)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4400 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4401 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4402 | return_value = os_strerror_impl(module, code); |
| 4403 | |
| 4404 | exit: |
| 4405 | return return_value; |
| 4406 | } |
| 4407 | |
| 4408 | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
| 4409 | |
| 4410 | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
| 4411 | "WCOREDUMP($module, status, /)\n" |
| 4412 | "--\n" |
| 4413 | "\n" |
| 4414 | "Return True if the process returning status was dumped to a core file."); |
| 4415 | |
| 4416 | #define OS_WCOREDUMP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4417 | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4418 | |
| 4419 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4420 | os_WCOREDUMP_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4421 | |
| 4422 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4423 | os_WCOREDUMP(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4424 | { |
| 4425 | PyObject *return_value = NULL; |
| 4426 | int status; |
| 4427 | int _return_value; |
| 4428 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4429 | if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4430 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4431 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4432 | _return_value = os_WCOREDUMP_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4433 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4434 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4435 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4436 | return_value = PyBool_FromLong((long)_return_value); |
| 4437 | |
| 4438 | exit: |
| 4439 | return return_value; |
| 4440 | } |
| 4441 | |
| 4442 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
| 4443 | |
| 4444 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
| 4445 | |
| 4446 | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
| 4447 | "WIFCONTINUED($module, /, status)\n" |
| 4448 | "--\n" |
| 4449 | "\n" |
| 4450 | "Return True if a particular process was continued from a job control stop.\n" |
| 4451 | "\n" |
| 4452 | "Return True if the process returning status was continued from a\n" |
| 4453 | "job control stop."); |
| 4454 | |
| 4455 | #define OS_WIFCONTINUED_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4456 | {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL, os_WIFCONTINUED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4457 | |
| 4458 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4459 | os_WIFCONTINUED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4460 | |
| 4461 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4462 | os_WIFCONTINUED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4463 | { |
| 4464 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4465 | static const char * const _keywords[] = {"status", NULL}; |
| 4466 | static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4467 | int status; |
| 4468 | int _return_value; |
| 4469 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4470 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4471 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4472 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4473 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4474 | _return_value = os_WIFCONTINUED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4475 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4476 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4477 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4478 | return_value = PyBool_FromLong((long)_return_value); |
| 4479 | |
| 4480 | exit: |
| 4481 | return return_value; |
| 4482 | } |
| 4483 | |
| 4484 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
| 4485 | |
| 4486 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
| 4487 | |
| 4488 | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
| 4489 | "WIFSTOPPED($module, /, status)\n" |
| 4490 | "--\n" |
| 4491 | "\n" |
| 4492 | "Return True if the process returning status was stopped."); |
| 4493 | |
| 4494 | #define OS_WIFSTOPPED_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4495 | {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL, os_WIFSTOPPED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4496 | |
| 4497 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4498 | os_WIFSTOPPED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4499 | |
| 4500 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4501 | os_WIFSTOPPED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4502 | { |
| 4503 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4504 | static const char * const _keywords[] = {"status", NULL}; |
| 4505 | static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4506 | int status; |
| 4507 | int _return_value; |
| 4508 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4509 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4510 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4511 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4512 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4513 | _return_value = os_WIFSTOPPED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4514 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4515 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4516 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4517 | return_value = PyBool_FromLong((long)_return_value); |
| 4518 | |
| 4519 | exit: |
| 4520 | return return_value; |
| 4521 | } |
| 4522 | |
| 4523 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
| 4524 | |
| 4525 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
| 4526 | |
| 4527 | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
| 4528 | "WIFSIGNALED($module, /, status)\n" |
| 4529 | "--\n" |
| 4530 | "\n" |
| 4531 | "Return True if the process returning status was terminated by a signal."); |
| 4532 | |
| 4533 | #define OS_WIFSIGNALED_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4534 | {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL, os_WIFSIGNALED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4535 | |
| 4536 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4537 | os_WIFSIGNALED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4538 | |
| 4539 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4540 | os_WIFSIGNALED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4541 | { |
| 4542 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4543 | static const char * const _keywords[] = {"status", NULL}; |
| 4544 | static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4545 | int status; |
| 4546 | int _return_value; |
| 4547 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4548 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4549 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4550 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4551 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4552 | _return_value = os_WIFSIGNALED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4553 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4554 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4555 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4556 | return_value = PyBool_FromLong((long)_return_value); |
| 4557 | |
| 4558 | exit: |
| 4559 | return return_value; |
| 4560 | } |
| 4561 | |
| 4562 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
| 4563 | |
| 4564 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
| 4565 | |
| 4566 | PyDoc_STRVAR(os_WIFEXITED__doc__, |
| 4567 | "WIFEXITED($module, /, status)\n" |
| 4568 | "--\n" |
| 4569 | "\n" |
| 4570 | "Return True if the process returning status exited via the exit() system call."); |
| 4571 | |
| 4572 | #define OS_WIFEXITED_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4573 | {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL, os_WIFEXITED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4574 | |
| 4575 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4576 | os_WIFEXITED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4577 | |
| 4578 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4579 | os_WIFEXITED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4580 | { |
| 4581 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4582 | static const char * const _keywords[] = {"status", NULL}; |
| 4583 | static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4584 | int status; |
| 4585 | int _return_value; |
| 4586 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4587 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4588 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4589 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4590 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4591 | _return_value = os_WIFEXITED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4592 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4593 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4594 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4595 | return_value = PyBool_FromLong((long)_return_value); |
| 4596 | |
| 4597 | exit: |
| 4598 | return return_value; |
| 4599 | } |
| 4600 | |
| 4601 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
| 4602 | |
| 4603 | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
| 4604 | |
| 4605 | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
| 4606 | "WEXITSTATUS($module, /, status)\n" |
| 4607 | "--\n" |
| 4608 | "\n" |
| 4609 | "Return the process return code from status."); |
| 4610 | |
| 4611 | #define OS_WEXITSTATUS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4612 | {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL, os_WEXITSTATUS__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4613 | |
| 4614 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4615 | os_WEXITSTATUS_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4616 | |
| 4617 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4618 | os_WEXITSTATUS(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4619 | { |
| 4620 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4621 | static const char * const _keywords[] = {"status", NULL}; |
| 4622 | static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4623 | int status; |
| 4624 | int _return_value; |
| 4625 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4626 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4627 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4628 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4629 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4630 | _return_value = os_WEXITSTATUS_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4631 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4632 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4633 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4634 | return_value = PyLong_FromLong((long)_return_value); |
| 4635 | |
| 4636 | exit: |
| 4637 | return return_value; |
| 4638 | } |
| 4639 | |
| 4640 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
| 4641 | |
| 4642 | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
| 4643 | |
| 4644 | PyDoc_STRVAR(os_WTERMSIG__doc__, |
| 4645 | "WTERMSIG($module, /, status)\n" |
| 4646 | "--\n" |
| 4647 | "\n" |
| 4648 | "Return the signal that terminated the process that provided the status value."); |
| 4649 | |
| 4650 | #define OS_WTERMSIG_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4651 | {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL, os_WTERMSIG__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4652 | |
| 4653 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4654 | os_WTERMSIG_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4655 | |
| 4656 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4657 | os_WTERMSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4658 | { |
| 4659 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4660 | static const char * const _keywords[] = {"status", NULL}; |
| 4661 | static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4662 | int status; |
| 4663 | int _return_value; |
| 4664 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4665 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4666 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4667 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4668 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4669 | _return_value = os_WTERMSIG_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4670 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4671 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4672 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4673 | return_value = PyLong_FromLong((long)_return_value); |
| 4674 | |
| 4675 | exit: |
| 4676 | return return_value; |
| 4677 | } |
| 4678 | |
| 4679 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
| 4680 | |
| 4681 | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
| 4682 | |
| 4683 | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
| 4684 | "WSTOPSIG($module, /, status)\n" |
| 4685 | "--\n" |
| 4686 | "\n" |
| 4687 | "Return the signal that stopped the process that provided the status value."); |
| 4688 | |
| 4689 | #define OS_WSTOPSIG_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4690 | {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL, os_WSTOPSIG__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4691 | |
| 4692 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4693 | os_WSTOPSIG_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4694 | |
| 4695 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4696 | os_WSTOPSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4697 | { |
| 4698 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4699 | static const char * const _keywords[] = {"status", NULL}; |
| 4700 | static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4701 | int status; |
| 4702 | int _return_value; |
| 4703 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4704 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4705 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4706 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4707 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4708 | _return_value = os_WSTOPSIG_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4709 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4710 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4711 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4712 | return_value = PyLong_FromLong((long)_return_value); |
| 4713 | |
| 4714 | exit: |
| 4715 | return return_value; |
| 4716 | } |
| 4717 | |
| 4718 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
| 4719 | |
| 4720 | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 4721 | |
| 4722 | PyDoc_STRVAR(os_fstatvfs__doc__, |
| 4723 | "fstatvfs($module, fd, /)\n" |
| 4724 | "--\n" |
| 4725 | "\n" |
| 4726 | "Perform an fstatvfs system call on the given fd.\n" |
| 4727 | "\n" |
| 4728 | "Equivalent to statvfs(fd)."); |
| 4729 | |
| 4730 | #define OS_FSTATVFS_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4731 | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4732 | |
| 4733 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4734 | os_fstatvfs_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4735 | |
| 4736 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4737 | os_fstatvfs(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4738 | { |
| 4739 | PyObject *return_value = NULL; |
| 4740 | int fd; |
| 4741 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4742 | if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4743 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4744 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4745 | return_value = os_fstatvfs_impl(module, fd); |
| 4746 | |
| 4747 | exit: |
| 4748 | return return_value; |
| 4749 | } |
| 4750 | |
| 4751 | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 4752 | |
| 4753 | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 4754 | |
| 4755 | PyDoc_STRVAR(os_statvfs__doc__, |
| 4756 | "statvfs($module, /, path)\n" |
| 4757 | "--\n" |
| 4758 | "\n" |
| 4759 | "Perform a statvfs system call on the given path.\n" |
| 4760 | "\n" |
| 4761 | "path may always be specified as a string.\n" |
| 4762 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 4763 | " If this functionality is unavailable, using it raises an exception."); |
| 4764 | |
| 4765 | #define OS_STATVFS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4766 | {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL, os_statvfs__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4767 | |
| 4768 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4769 | os_statvfs_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4770 | |
| 4771 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4772 | os_statvfs(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4773 | { |
| 4774 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4775 | static const char * const _keywords[] = {"path", NULL}; |
| 4776 | static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4777 | path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS); |
| 4778 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4779 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4780 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4781 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4782 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4783 | return_value = os_statvfs_impl(module, &path); |
| 4784 | |
| 4785 | exit: |
| 4786 | /* Cleanup for path */ |
| 4787 | path_cleanup(&path); |
| 4788 | |
| 4789 | return return_value; |
| 4790 | } |
| 4791 | |
| 4792 | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 4793 | |
| 4794 | #if defined(MS_WINDOWS) |
| 4795 | |
| 4796 | PyDoc_STRVAR(os__getdiskusage__doc__, |
| 4797 | "_getdiskusage($module, /, path)\n" |
| 4798 | "--\n" |
| 4799 | "\n" |
| 4800 | "Return disk usage statistics about the given path as a (total, free) tuple."); |
| 4801 | |
| 4802 | #define OS__GETDISKUSAGE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4803 | {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL, os__getdiskusage__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4804 | |
| 4805 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4806 | os__getdiskusage_impl(PyObject *module, Py_UNICODE *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4807 | |
| 4808 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4809 | os__getdiskusage(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4810 | { |
| 4811 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4812 | static const char * const _keywords[] = {"path", NULL}; |
| 4813 | static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4814 | Py_UNICODE *path; |
| 4815 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4816 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4817 | &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4818 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4819 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4820 | return_value = os__getdiskusage_impl(module, path); |
| 4821 | |
| 4822 | exit: |
| 4823 | return return_value; |
| 4824 | } |
| 4825 | |
| 4826 | #endif /* defined(MS_WINDOWS) */ |
| 4827 | |
| 4828 | #if defined(HAVE_FPATHCONF) |
| 4829 | |
| 4830 | PyDoc_STRVAR(os_fpathconf__doc__, |
| 4831 | "fpathconf($module, fd, name, /)\n" |
| 4832 | "--\n" |
| 4833 | "\n" |
| 4834 | "Return the configuration limit name for the file descriptor fd.\n" |
| 4835 | "\n" |
| 4836 | "If there is no limit, return -1."); |
| 4837 | |
| 4838 | #define OS_FPATHCONF_METHODDEF \ |
| 4839 | {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__}, |
| 4840 | |
| 4841 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4842 | os_fpathconf_impl(PyObject *module, int fd, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4843 | |
| 4844 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4845 | os_fpathconf(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4846 | { |
| 4847 | PyObject *return_value = NULL; |
| 4848 | int fd; |
| 4849 | int name; |
| 4850 | long _return_value; |
| 4851 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 4852 | if (!PyArg_ParseTuple(args, "iO&:fpathconf", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4853 | &fd, conv_path_confname, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4854 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4855 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4856 | _return_value = os_fpathconf_impl(module, fd, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4857 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4858 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4859 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4860 | return_value = PyLong_FromLong(_return_value); |
| 4861 | |
| 4862 | exit: |
| 4863 | return return_value; |
| 4864 | } |
| 4865 | |
| 4866 | #endif /* defined(HAVE_FPATHCONF) */ |
| 4867 | |
| 4868 | #if defined(HAVE_PATHCONF) |
| 4869 | |
| 4870 | PyDoc_STRVAR(os_pathconf__doc__, |
| 4871 | "pathconf($module, /, path, name)\n" |
| 4872 | "--\n" |
| 4873 | "\n" |
| 4874 | "Return the configuration limit name for the file or directory path.\n" |
| 4875 | "\n" |
| 4876 | "If there is no limit, return -1.\n" |
| 4877 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 4878 | " If this functionality is unavailable, using it raises an exception."); |
| 4879 | |
| 4880 | #define OS_PATHCONF_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4881 | {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL, os_pathconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4882 | |
| 4883 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4884 | os_pathconf_impl(PyObject *module, path_t *path, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4885 | |
| 4886 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4887 | os_pathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4888 | { |
| 4889 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4890 | static const char * const _keywords[] = {"path", "name", NULL}; |
| 4891 | static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4892 | path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF); |
| 4893 | int name; |
| 4894 | long _return_value; |
| 4895 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 4896 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4897 | path_converter, &path, conv_path_confname, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4898 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4899 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4900 | _return_value = os_pathconf_impl(module, &path, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4901 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4902 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4903 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4904 | return_value = PyLong_FromLong(_return_value); |
| 4905 | |
| 4906 | exit: |
| 4907 | /* Cleanup for path */ |
| 4908 | path_cleanup(&path); |
| 4909 | |
| 4910 | return return_value; |
| 4911 | } |
| 4912 | |
| 4913 | #endif /* defined(HAVE_PATHCONF) */ |
| 4914 | |
| 4915 | #if defined(HAVE_CONFSTR) |
| 4916 | |
| 4917 | PyDoc_STRVAR(os_confstr__doc__, |
| 4918 | "confstr($module, name, /)\n" |
| 4919 | "--\n" |
| 4920 | "\n" |
| 4921 | "Return a string-valued system configuration variable."); |
| 4922 | |
| 4923 | #define OS_CONFSTR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4924 | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4925 | |
| 4926 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4927 | os_confstr_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4928 | |
| 4929 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4930 | os_confstr(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4931 | { |
| 4932 | PyObject *return_value = NULL; |
| 4933 | int name; |
| 4934 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4935 | if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4936 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4937 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4938 | return_value = os_confstr_impl(module, name); |
| 4939 | |
| 4940 | exit: |
| 4941 | return return_value; |
| 4942 | } |
| 4943 | |
| 4944 | #endif /* defined(HAVE_CONFSTR) */ |
| 4945 | |
| 4946 | #if defined(HAVE_SYSCONF) |
| 4947 | |
| 4948 | PyDoc_STRVAR(os_sysconf__doc__, |
| 4949 | "sysconf($module, name, /)\n" |
| 4950 | "--\n" |
| 4951 | "\n" |
| 4952 | "Return an integer-valued system configuration variable."); |
| 4953 | |
| 4954 | #define OS_SYSCONF_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4955 | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4956 | |
| 4957 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4958 | os_sysconf_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4959 | |
| 4960 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4961 | os_sysconf(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4962 | { |
| 4963 | PyObject *return_value = NULL; |
| 4964 | int name; |
| 4965 | long _return_value; |
| 4966 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4967 | if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4968 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4969 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4970 | _return_value = os_sysconf_impl(module, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4971 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4972 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4973 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4974 | return_value = PyLong_FromLong(_return_value); |
| 4975 | |
| 4976 | exit: |
| 4977 | return return_value; |
| 4978 | } |
| 4979 | |
| 4980 | #endif /* defined(HAVE_SYSCONF) */ |
| 4981 | |
| 4982 | PyDoc_STRVAR(os_abort__doc__, |
| 4983 | "abort($module, /)\n" |
| 4984 | "--\n" |
| 4985 | "\n" |
| 4986 | "Abort the interpreter immediately.\n" |
| 4987 | "\n" |
| 4988 | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
| 4989 | "on the hosting operating system. This function never returns."); |
| 4990 | |
| 4991 | #define OS_ABORT_METHODDEF \ |
| 4992 | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
| 4993 | |
| 4994 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4995 | os_abort_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4996 | |
| 4997 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4998 | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4999 | { |
| 5000 | return os_abort_impl(module); |
| 5001 | } |
| 5002 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5003 | #if defined(MS_WINDOWS) |
| 5004 | |
| 5005 | PyDoc_STRVAR(os_startfile__doc__, |
| 5006 | "startfile($module, /, filepath, operation=None)\n" |
| 5007 | "--\n" |
| 5008 | "\n" |
| 5009 | "startfile(filepath [, operation])\n" |
| 5010 | "\n" |
| 5011 | "Start a file with its associated application.\n" |
| 5012 | "\n" |
| 5013 | "When \"operation\" is not specified or \"open\", this acts like\n" |
| 5014 | "double-clicking the file in Explorer, or giving the file name as an\n" |
| 5015 | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
| 5016 | "application (if any) its extension is associated.\n" |
| 5017 | "When another \"operation\" is given, it specifies what should be done with\n" |
| 5018 | "the file. A typical operation is \"print\".\n" |
| 5019 | "\n" |
| 5020 | "startfile returns as soon as the associated application is launched.\n" |
| 5021 | "There is no option to wait for the application to close, and no way\n" |
| 5022 | "to retrieve the application\'s exit status.\n" |
| 5023 | "\n" |
| 5024 | "The filepath is relative to the current directory. If you want to use\n" |
| 5025 | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
| 5026 | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
| 5027 | |
| 5028 | #define OS_STARTFILE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5029 | {"startfile", (PyCFunction)os_startfile, METH_FASTCALL, os_startfile__doc__}, |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5030 | |
| 5031 | static PyObject * |
| 5032 | os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation); |
| 5033 | |
| 5034 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5035 | os_startfile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5036 | { |
| 5037 | PyObject *return_value = NULL; |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5038 | static const char * const _keywords[] = {"filepath", "operation", NULL}; |
| 5039 | static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0}; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5040 | path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0); |
| 5041 | Py_UNICODE *operation = NULL; |
| 5042 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5043 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5044 | path_converter, &filepath, &operation)) { |
| 5045 | goto exit; |
| 5046 | } |
| 5047 | return_value = os_startfile_impl(module, &filepath, operation); |
| 5048 | |
| 5049 | exit: |
| 5050 | /* Cleanup for filepath */ |
| 5051 | path_cleanup(&filepath); |
| 5052 | |
| 5053 | return return_value; |
| 5054 | } |
| 5055 | |
| 5056 | #endif /* defined(MS_WINDOWS) */ |
| 5057 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5058 | #if defined(HAVE_GETLOADAVG) |
| 5059 | |
| 5060 | PyDoc_STRVAR(os_getloadavg__doc__, |
| 5061 | "getloadavg($module, /)\n" |
| 5062 | "--\n" |
| 5063 | "\n" |
| 5064 | "Return average recent system load information.\n" |
| 5065 | "\n" |
| 5066 | "Return the number of processes in the system run queue averaged over\n" |
| 5067 | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
| 5068 | "Raises OSError if the load average was unobtainable."); |
| 5069 | |
| 5070 | #define OS_GETLOADAVG_METHODDEF \ |
| 5071 | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
| 5072 | |
| 5073 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5074 | os_getloadavg_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5075 | |
| 5076 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5077 | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5078 | { |
| 5079 | return os_getloadavg_impl(module); |
| 5080 | } |
| 5081 | |
| 5082 | #endif /* defined(HAVE_GETLOADAVG) */ |
| 5083 | |
| 5084 | PyDoc_STRVAR(os_device_encoding__doc__, |
| 5085 | "device_encoding($module, /, fd)\n" |
| 5086 | "--\n" |
| 5087 | "\n" |
| 5088 | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
| 5089 | "\n" |
| 5090 | "The file descriptor must be attached to a terminal.\n" |
| 5091 | "If the device is not a terminal, return None."); |
| 5092 | |
| 5093 | #define OS_DEVICE_ENCODING_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5094 | {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL, os_device_encoding__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5095 | |
| 5096 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5097 | os_device_encoding_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5098 | |
| 5099 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5100 | os_device_encoding(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5101 | { |
| 5102 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5103 | static const char * const _keywords[] = {"fd", NULL}; |
| 5104 | static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5105 | int fd; |
| 5106 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5107 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5108 | &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5109 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5110 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5111 | return_value = os_device_encoding_impl(module, fd); |
| 5112 | |
| 5113 | exit: |
| 5114 | return return_value; |
| 5115 | } |
| 5116 | |
| 5117 | #if defined(HAVE_SETRESUID) |
| 5118 | |
| 5119 | PyDoc_STRVAR(os_setresuid__doc__, |
| 5120 | "setresuid($module, ruid, euid, suid, /)\n" |
| 5121 | "--\n" |
| 5122 | "\n" |
| 5123 | "Set the current process\'s real, effective, and saved user ids."); |
| 5124 | |
| 5125 | #define OS_SETRESUID_METHODDEF \ |
| 5126 | {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__}, |
| 5127 | |
| 5128 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5129 | 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] | 5130 | |
| 5131 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5132 | os_setresuid(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5133 | { |
| 5134 | PyObject *return_value = NULL; |
| 5135 | uid_t ruid; |
| 5136 | uid_t euid; |
| 5137 | uid_t suid; |
| 5138 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 5139 | if (!PyArg_ParseTuple(args, "O&O&O&:setresuid", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5140 | _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5141 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5142 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5143 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
| 5144 | |
| 5145 | exit: |
| 5146 | return return_value; |
| 5147 | } |
| 5148 | |
| 5149 | #endif /* defined(HAVE_SETRESUID) */ |
| 5150 | |
| 5151 | #if defined(HAVE_SETRESGID) |
| 5152 | |
| 5153 | PyDoc_STRVAR(os_setresgid__doc__, |
| 5154 | "setresgid($module, rgid, egid, sgid, /)\n" |
| 5155 | "--\n" |
| 5156 | "\n" |
| 5157 | "Set the current process\'s real, effective, and saved group ids."); |
| 5158 | |
| 5159 | #define OS_SETRESGID_METHODDEF \ |
| 5160 | {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__}, |
| 5161 | |
| 5162 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5163 | 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] | 5164 | |
| 5165 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5166 | os_setresgid(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5167 | { |
| 5168 | PyObject *return_value = NULL; |
| 5169 | gid_t rgid; |
| 5170 | gid_t egid; |
| 5171 | gid_t sgid; |
| 5172 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 5173 | if (!PyArg_ParseTuple(args, "O&O&O&:setresgid", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5174 | _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5175 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5176 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5177 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
| 5178 | |
| 5179 | exit: |
| 5180 | return return_value; |
| 5181 | } |
| 5182 | |
| 5183 | #endif /* defined(HAVE_SETRESGID) */ |
| 5184 | |
| 5185 | #if defined(HAVE_GETRESUID) |
| 5186 | |
| 5187 | PyDoc_STRVAR(os_getresuid__doc__, |
| 5188 | "getresuid($module, /)\n" |
| 5189 | "--\n" |
| 5190 | "\n" |
| 5191 | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
| 5192 | |
| 5193 | #define OS_GETRESUID_METHODDEF \ |
| 5194 | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
| 5195 | |
| 5196 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5197 | os_getresuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5198 | |
| 5199 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5200 | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5201 | { |
| 5202 | return os_getresuid_impl(module); |
| 5203 | } |
| 5204 | |
| 5205 | #endif /* defined(HAVE_GETRESUID) */ |
| 5206 | |
| 5207 | #if defined(HAVE_GETRESGID) |
| 5208 | |
| 5209 | PyDoc_STRVAR(os_getresgid__doc__, |
| 5210 | "getresgid($module, /)\n" |
| 5211 | "--\n" |
| 5212 | "\n" |
| 5213 | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
| 5214 | |
| 5215 | #define OS_GETRESGID_METHODDEF \ |
| 5216 | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
| 5217 | |
| 5218 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5219 | os_getresgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5220 | |
| 5221 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5222 | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5223 | { |
| 5224 | return os_getresgid_impl(module); |
| 5225 | } |
| 5226 | |
| 5227 | #endif /* defined(HAVE_GETRESGID) */ |
| 5228 | |
| 5229 | #if defined(USE_XATTRS) |
| 5230 | |
| 5231 | PyDoc_STRVAR(os_getxattr__doc__, |
| 5232 | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 5233 | "--\n" |
| 5234 | "\n" |
| 5235 | "Return the value of extended attribute attribute on path.\n" |
| 5236 | "\n" |
| 5237 | "path may be either a string or an open file descriptor.\n" |
| 5238 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 5239 | " link, getxattr will examine the symbolic link itself instead of the file\n" |
| 5240 | " the link points to."); |
| 5241 | |
| 5242 | #define OS_GETXATTR_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5243 | {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL, os_getxattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5244 | |
| 5245 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5246 | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 5247 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5248 | |
| 5249 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5250 | os_getxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5251 | { |
| 5252 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5253 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
| 5254 | static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5255 | path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1); |
| 5256 | path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0); |
| 5257 | int follow_symlinks = 1; |
| 5258 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5259 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5260 | path_converter, &path, path_converter, &attribute, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5261 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5262 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5263 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
| 5264 | |
| 5265 | exit: |
| 5266 | /* Cleanup for path */ |
| 5267 | path_cleanup(&path); |
| 5268 | /* Cleanup for attribute */ |
| 5269 | path_cleanup(&attribute); |
| 5270 | |
| 5271 | return return_value; |
| 5272 | } |
| 5273 | |
| 5274 | #endif /* defined(USE_XATTRS) */ |
| 5275 | |
| 5276 | #if defined(USE_XATTRS) |
| 5277 | |
| 5278 | PyDoc_STRVAR(os_setxattr__doc__, |
| 5279 | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
| 5280 | " follow_symlinks=True)\n" |
| 5281 | "--\n" |
| 5282 | "\n" |
| 5283 | "Set extended attribute attribute on path to value.\n" |
| 5284 | "\n" |
| 5285 | "path may be either a string or an open file descriptor.\n" |
| 5286 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 5287 | " link, setxattr will modify the symbolic link itself instead of the file\n" |
| 5288 | " the link points to."); |
| 5289 | |
| 5290 | #define OS_SETXATTR_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5291 | {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL, os_setxattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5292 | |
| 5293 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5294 | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 5295 | Py_buffer *value, int flags, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5296 | |
| 5297 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5298 | os_setxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5299 | { |
| 5300 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5301 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
| 5302 | static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5303 | path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1); |
| 5304 | path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0); |
| 5305 | Py_buffer value = {NULL, NULL}; |
| 5306 | int flags = 0; |
| 5307 | int follow_symlinks = 1; |
| 5308 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5309 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5310 | path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5311 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5312 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5313 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
| 5314 | |
| 5315 | exit: |
| 5316 | /* Cleanup for path */ |
| 5317 | path_cleanup(&path); |
| 5318 | /* Cleanup for attribute */ |
| 5319 | path_cleanup(&attribute); |
| 5320 | /* Cleanup for value */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5321 | if (value.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5322 | PyBuffer_Release(&value); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5323 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5324 | |
| 5325 | return return_value; |
| 5326 | } |
| 5327 | |
| 5328 | #endif /* defined(USE_XATTRS) */ |
| 5329 | |
| 5330 | #if defined(USE_XATTRS) |
| 5331 | |
| 5332 | PyDoc_STRVAR(os_removexattr__doc__, |
| 5333 | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 5334 | "--\n" |
| 5335 | "\n" |
| 5336 | "Remove extended attribute attribute on path.\n" |
| 5337 | "\n" |
| 5338 | "path may be either a string or an open file descriptor.\n" |
| 5339 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 5340 | " link, removexattr will modify the symbolic link itself instead of the file\n" |
| 5341 | " the link points to."); |
| 5342 | |
| 5343 | #define OS_REMOVEXATTR_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5344 | {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL, os_removexattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5345 | |
| 5346 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5347 | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 5348 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5349 | |
| 5350 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5351 | os_removexattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5352 | { |
| 5353 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5354 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
| 5355 | static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5356 | path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1); |
| 5357 | path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0); |
| 5358 | int follow_symlinks = 1; |
| 5359 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5360 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5361 | path_converter, &path, path_converter, &attribute, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5362 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5363 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5364 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
| 5365 | |
| 5366 | exit: |
| 5367 | /* Cleanup for path */ |
| 5368 | path_cleanup(&path); |
| 5369 | /* Cleanup for attribute */ |
| 5370 | path_cleanup(&attribute); |
| 5371 | |
| 5372 | return return_value; |
| 5373 | } |
| 5374 | |
| 5375 | #endif /* defined(USE_XATTRS) */ |
| 5376 | |
| 5377 | #if defined(USE_XATTRS) |
| 5378 | |
| 5379 | PyDoc_STRVAR(os_listxattr__doc__, |
| 5380 | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
| 5381 | "--\n" |
| 5382 | "\n" |
| 5383 | "Return a list of extended attributes on path.\n" |
| 5384 | "\n" |
| 5385 | "path may be either None, a string, or an open file descriptor.\n" |
| 5386 | "if path is None, listxattr will examine the current directory.\n" |
| 5387 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 5388 | " link, listxattr will examine the symbolic link itself instead of the file\n" |
| 5389 | " the link points to."); |
| 5390 | |
| 5391 | #define OS_LISTXATTR_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5392 | {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL, os_listxattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5393 | |
| 5394 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5395 | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5396 | |
| 5397 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5398 | os_listxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5399 | { |
| 5400 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5401 | static const char * const _keywords[] = {"path", "follow_symlinks", NULL}; |
| 5402 | static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5403 | path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1); |
| 5404 | int follow_symlinks = 1; |
| 5405 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5406 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5407 | path_converter, &path, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5408 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5409 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5410 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
| 5411 | |
| 5412 | exit: |
| 5413 | /* Cleanup for path */ |
| 5414 | path_cleanup(&path); |
| 5415 | |
| 5416 | return return_value; |
| 5417 | } |
| 5418 | |
| 5419 | #endif /* defined(USE_XATTRS) */ |
| 5420 | |
| 5421 | PyDoc_STRVAR(os_urandom__doc__, |
| 5422 | "urandom($module, size, /)\n" |
| 5423 | "--\n" |
| 5424 | "\n" |
| 5425 | "Return a bytes object containing random bytes suitable for cryptographic use."); |
| 5426 | |
| 5427 | #define OS_URANDOM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5428 | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5429 | |
| 5430 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5431 | os_urandom_impl(PyObject *module, Py_ssize_t size); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5432 | |
| 5433 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5434 | os_urandom(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5435 | { |
| 5436 | PyObject *return_value = NULL; |
| 5437 | Py_ssize_t size; |
| 5438 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5439 | if (!PyArg_Parse(arg, "n:urandom", &size)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5440 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5441 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5442 | return_value = os_urandom_impl(module, size); |
| 5443 | |
| 5444 | exit: |
| 5445 | return return_value; |
| 5446 | } |
| 5447 | |
| 5448 | PyDoc_STRVAR(os_cpu_count__doc__, |
| 5449 | "cpu_count($module, /)\n" |
| 5450 | "--\n" |
| 5451 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 5452 | "Return the number of CPUs in the system; return None if indeterminable.\n" |
| 5453 | "\n" |
| 5454 | "This number is not equivalent to the number of CPUs the current process can\n" |
| 5455 | "use. The number of usable CPUs can be obtained with\n" |
| 5456 | "``len(os.sched_getaffinity(0))``"); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5457 | |
| 5458 | #define OS_CPU_COUNT_METHODDEF \ |
| 5459 | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
| 5460 | |
| 5461 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5462 | os_cpu_count_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5463 | |
| 5464 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5465 | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5466 | { |
| 5467 | return os_cpu_count_impl(module); |
| 5468 | } |
| 5469 | |
| 5470 | PyDoc_STRVAR(os_get_inheritable__doc__, |
| 5471 | "get_inheritable($module, fd, /)\n" |
| 5472 | "--\n" |
| 5473 | "\n" |
| 5474 | "Get the close-on-exe flag of the specified file descriptor."); |
| 5475 | |
| 5476 | #define OS_GET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5477 | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5478 | |
| 5479 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5480 | os_get_inheritable_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5481 | |
| 5482 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5483 | os_get_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5484 | { |
| 5485 | PyObject *return_value = NULL; |
| 5486 | int fd; |
| 5487 | int _return_value; |
| 5488 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5489 | if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5490 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5491 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5492 | _return_value = os_get_inheritable_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5493 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5494 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5495 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5496 | return_value = PyBool_FromLong((long)_return_value); |
| 5497 | |
| 5498 | exit: |
| 5499 | return return_value; |
| 5500 | } |
| 5501 | |
| 5502 | PyDoc_STRVAR(os_set_inheritable__doc__, |
| 5503 | "set_inheritable($module, fd, inheritable, /)\n" |
| 5504 | "--\n" |
| 5505 | "\n" |
| 5506 | "Set the inheritable flag of the specified file descriptor."); |
| 5507 | |
| 5508 | #define OS_SET_INHERITABLE_METHODDEF \ |
| 5509 | {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__}, |
| 5510 | |
| 5511 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5512 | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5513 | |
| 5514 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5515 | os_set_inheritable(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5516 | { |
| 5517 | PyObject *return_value = NULL; |
| 5518 | int fd; |
| 5519 | int inheritable; |
| 5520 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 5521 | if (!PyArg_ParseTuple(args, "ii:set_inheritable", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5522 | &fd, &inheritable)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5523 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5524 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5525 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
| 5526 | |
| 5527 | exit: |
| 5528 | return return_value; |
| 5529 | } |
| 5530 | |
| 5531 | #if defined(MS_WINDOWS) |
| 5532 | |
| 5533 | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
| 5534 | "get_handle_inheritable($module, handle, /)\n" |
| 5535 | "--\n" |
| 5536 | "\n" |
| 5537 | "Get the close-on-exe flag of the specified file descriptor."); |
| 5538 | |
| 5539 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5540 | {"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] | 5541 | |
| 5542 | static int |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 5543 | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5544 | |
| 5545 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5546 | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5547 | { |
| 5548 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 5549 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5550 | int _return_value; |
| 5551 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5552 | if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5553 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5554 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5555 | _return_value = os_get_handle_inheritable_impl(module, handle); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5556 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5557 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5558 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5559 | return_value = PyBool_FromLong((long)_return_value); |
| 5560 | |
| 5561 | exit: |
| 5562 | return return_value; |
| 5563 | } |
| 5564 | |
| 5565 | #endif /* defined(MS_WINDOWS) */ |
| 5566 | |
| 5567 | #if defined(MS_WINDOWS) |
| 5568 | |
| 5569 | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
| 5570 | "set_handle_inheritable($module, handle, inheritable, /)\n" |
| 5571 | "--\n" |
| 5572 | "\n" |
| 5573 | "Set the inheritable flag of the specified handle."); |
| 5574 | |
| 5575 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
| 5576 | {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__}, |
| 5577 | |
| 5578 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 5579 | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 5580 | int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5581 | |
| 5582 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5583 | os_set_handle_inheritable(PyObject *module, PyObject *args) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5584 | { |
| 5585 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 5586 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5587 | int inheritable; |
| 5588 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 5589 | if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "p:set_handle_inheritable", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5590 | &handle, &inheritable)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5591 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5592 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5593 | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
| 5594 | |
| 5595 | exit: |
| 5596 | return return_value; |
| 5597 | } |
| 5598 | |
| 5599 | #endif /* defined(MS_WINDOWS) */ |
| 5600 | |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 5601 | PyDoc_STRVAR(os_fspath__doc__, |
| 5602 | "fspath($module, /, path)\n" |
| 5603 | "--\n" |
| 5604 | "\n" |
| 5605 | "Return the file system path representation of the object.\n" |
| 5606 | "\n" |
Brett Cannon | b4f43e9 | 2016-06-09 14:32:08 -0700 | [diff] [blame] | 5607 | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
| 5608 | "object defines __fspath__(), then return the result of that method. All other\n" |
| 5609 | "types raise a TypeError."); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 5610 | |
| 5611 | #define OS_FSPATH_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5612 | {"fspath", (PyCFunction)os_fspath, METH_FASTCALL, os_fspath__doc__}, |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 5613 | |
| 5614 | static PyObject * |
Serhiy Storchaka | 2954f83 | 2016-07-07 18:20:03 +0300 | [diff] [blame] | 5615 | os_fspath_impl(PyObject *module, PyObject *path); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 5616 | |
| 5617 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5618 | os_fspath(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 5619 | { |
| 5620 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5621 | static const char * const _keywords[] = {"path", NULL}; |
| 5622 | static _PyArg_Parser _parser = {"O:fspath", _keywords, 0}; |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 5623 | PyObject *path; |
| 5624 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5625 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5626 | &path)) { |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 5627 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5628 | } |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 5629 | return_value = os_fspath_impl(module, path); |
| 5630 | |
| 5631 | exit: |
| 5632 | return return_value; |
| 5633 | } |
| 5634 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 5635 | #if defined(HAVE_GETRANDOM_SYSCALL) |
| 5636 | |
| 5637 | PyDoc_STRVAR(os_getrandom__doc__, |
| 5638 | "getrandom($module, /, size, flags=0)\n" |
| 5639 | "--\n" |
| 5640 | "\n" |
| 5641 | "Obtain a series of random bytes."); |
| 5642 | |
| 5643 | #define OS_GETRANDOM_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5644 | {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL, os_getrandom__doc__}, |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 5645 | |
| 5646 | static PyObject * |
| 5647 | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
| 5648 | |
| 5649 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5650 | os_getrandom(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 5651 | { |
| 5652 | PyObject *return_value = NULL; |
| 5653 | static const char * const _keywords[] = {"size", "flags", NULL}; |
| 5654 | static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0}; |
| 5655 | Py_ssize_t size; |
| 5656 | int flags = 0; |
| 5657 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5658 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 5659 | &size, &flags)) { |
| 5660 | goto exit; |
| 5661 | } |
| 5662 | return_value = os_getrandom_impl(module, size, flags); |
| 5663 | |
| 5664 | exit: |
| 5665 | return return_value; |
| 5666 | } |
| 5667 | |
| 5668 | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
| 5669 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5670 | #ifndef OS_TTYNAME_METHODDEF |
| 5671 | #define OS_TTYNAME_METHODDEF |
| 5672 | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
| 5673 | |
| 5674 | #ifndef OS_CTERMID_METHODDEF |
| 5675 | #define OS_CTERMID_METHODDEF |
| 5676 | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
| 5677 | |
| 5678 | #ifndef OS_FCHDIR_METHODDEF |
| 5679 | #define OS_FCHDIR_METHODDEF |
| 5680 | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
| 5681 | |
| 5682 | #ifndef OS_FCHMOD_METHODDEF |
| 5683 | #define OS_FCHMOD_METHODDEF |
| 5684 | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
| 5685 | |
| 5686 | #ifndef OS_LCHMOD_METHODDEF |
| 5687 | #define OS_LCHMOD_METHODDEF |
| 5688 | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
| 5689 | |
| 5690 | #ifndef OS_CHFLAGS_METHODDEF |
| 5691 | #define OS_CHFLAGS_METHODDEF |
| 5692 | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
| 5693 | |
| 5694 | #ifndef OS_LCHFLAGS_METHODDEF |
| 5695 | #define OS_LCHFLAGS_METHODDEF |
| 5696 | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
| 5697 | |
| 5698 | #ifndef OS_CHROOT_METHODDEF |
| 5699 | #define OS_CHROOT_METHODDEF |
| 5700 | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
| 5701 | |
| 5702 | #ifndef OS_FSYNC_METHODDEF |
| 5703 | #define OS_FSYNC_METHODDEF |
| 5704 | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
| 5705 | |
| 5706 | #ifndef OS_SYNC_METHODDEF |
| 5707 | #define OS_SYNC_METHODDEF |
| 5708 | #endif /* !defined(OS_SYNC_METHODDEF) */ |
| 5709 | |
| 5710 | #ifndef OS_FDATASYNC_METHODDEF |
| 5711 | #define OS_FDATASYNC_METHODDEF |
| 5712 | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
| 5713 | |
| 5714 | #ifndef OS_CHOWN_METHODDEF |
| 5715 | #define OS_CHOWN_METHODDEF |
| 5716 | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
| 5717 | |
| 5718 | #ifndef OS_FCHOWN_METHODDEF |
| 5719 | #define OS_FCHOWN_METHODDEF |
| 5720 | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
| 5721 | |
| 5722 | #ifndef OS_LCHOWN_METHODDEF |
| 5723 | #define OS_LCHOWN_METHODDEF |
| 5724 | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
| 5725 | |
| 5726 | #ifndef OS_LINK_METHODDEF |
| 5727 | #define OS_LINK_METHODDEF |
| 5728 | #endif /* !defined(OS_LINK_METHODDEF) */ |
| 5729 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 5730 | #ifndef OS__GETFULLPATHNAME_METHODDEF |
| 5731 | #define OS__GETFULLPATHNAME_METHODDEF |
| 5732 | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
| 5733 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5734 | #ifndef OS__GETFINALPATHNAME_METHODDEF |
| 5735 | #define OS__GETFINALPATHNAME_METHODDEF |
| 5736 | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
| 5737 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 5738 | #ifndef OS__ISDIR_METHODDEF |
| 5739 | #define OS__ISDIR_METHODDEF |
| 5740 | #endif /* !defined(OS__ISDIR_METHODDEF) */ |
| 5741 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5742 | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
| 5743 | #define OS__GETVOLUMEPATHNAME_METHODDEF |
| 5744 | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
| 5745 | |
| 5746 | #ifndef OS_NICE_METHODDEF |
| 5747 | #define OS_NICE_METHODDEF |
| 5748 | #endif /* !defined(OS_NICE_METHODDEF) */ |
| 5749 | |
| 5750 | #ifndef OS_GETPRIORITY_METHODDEF |
| 5751 | #define OS_GETPRIORITY_METHODDEF |
| 5752 | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
| 5753 | |
| 5754 | #ifndef OS_SETPRIORITY_METHODDEF |
| 5755 | #define OS_SETPRIORITY_METHODDEF |
| 5756 | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
| 5757 | |
| 5758 | #ifndef OS_SYSTEM_METHODDEF |
| 5759 | #define OS_SYSTEM_METHODDEF |
| 5760 | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
| 5761 | |
| 5762 | #ifndef OS_UNAME_METHODDEF |
| 5763 | #define OS_UNAME_METHODDEF |
| 5764 | #endif /* !defined(OS_UNAME_METHODDEF) */ |
| 5765 | |
| 5766 | #ifndef OS_EXECV_METHODDEF |
| 5767 | #define OS_EXECV_METHODDEF |
| 5768 | #endif /* !defined(OS_EXECV_METHODDEF) */ |
| 5769 | |
| 5770 | #ifndef OS_EXECVE_METHODDEF |
| 5771 | #define OS_EXECVE_METHODDEF |
| 5772 | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
| 5773 | |
| 5774 | #ifndef OS_SPAWNV_METHODDEF |
| 5775 | #define OS_SPAWNV_METHODDEF |
| 5776 | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
| 5777 | |
| 5778 | #ifndef OS_SPAWNVE_METHODDEF |
| 5779 | #define OS_SPAWNVE_METHODDEF |
| 5780 | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
| 5781 | |
| 5782 | #ifndef OS_FORK1_METHODDEF |
| 5783 | #define OS_FORK1_METHODDEF |
| 5784 | #endif /* !defined(OS_FORK1_METHODDEF) */ |
| 5785 | |
| 5786 | #ifndef OS_FORK_METHODDEF |
| 5787 | #define OS_FORK_METHODDEF |
| 5788 | #endif /* !defined(OS_FORK_METHODDEF) */ |
| 5789 | |
| 5790 | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 5791 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 5792 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
| 5793 | |
| 5794 | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 5795 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 5796 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
| 5797 | |
| 5798 | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
| 5799 | #define OS_SCHED_GETSCHEDULER_METHODDEF |
| 5800 | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
| 5801 | |
| 5802 | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
| 5803 | #define OS_SCHED_SETSCHEDULER_METHODDEF |
| 5804 | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
| 5805 | |
| 5806 | #ifndef OS_SCHED_GETPARAM_METHODDEF |
| 5807 | #define OS_SCHED_GETPARAM_METHODDEF |
| 5808 | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
| 5809 | |
| 5810 | #ifndef OS_SCHED_SETPARAM_METHODDEF |
| 5811 | #define OS_SCHED_SETPARAM_METHODDEF |
| 5812 | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
| 5813 | |
| 5814 | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 5815 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 5816 | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
| 5817 | |
| 5818 | #ifndef OS_SCHED_YIELD_METHODDEF |
| 5819 | #define OS_SCHED_YIELD_METHODDEF |
| 5820 | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
| 5821 | |
| 5822 | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
| 5823 | #define OS_SCHED_SETAFFINITY_METHODDEF |
| 5824 | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
| 5825 | |
| 5826 | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
| 5827 | #define OS_SCHED_GETAFFINITY_METHODDEF |
| 5828 | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
| 5829 | |
| 5830 | #ifndef OS_OPENPTY_METHODDEF |
| 5831 | #define OS_OPENPTY_METHODDEF |
| 5832 | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
| 5833 | |
| 5834 | #ifndef OS_FORKPTY_METHODDEF |
| 5835 | #define OS_FORKPTY_METHODDEF |
| 5836 | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
| 5837 | |
| 5838 | #ifndef OS_GETEGID_METHODDEF |
| 5839 | #define OS_GETEGID_METHODDEF |
| 5840 | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
| 5841 | |
| 5842 | #ifndef OS_GETEUID_METHODDEF |
| 5843 | #define OS_GETEUID_METHODDEF |
| 5844 | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
| 5845 | |
| 5846 | #ifndef OS_GETGID_METHODDEF |
| 5847 | #define OS_GETGID_METHODDEF |
| 5848 | #endif /* !defined(OS_GETGID_METHODDEF) */ |
| 5849 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 5850 | #ifndef OS_GETPID_METHODDEF |
| 5851 | #define OS_GETPID_METHODDEF |
| 5852 | #endif /* !defined(OS_GETPID_METHODDEF) */ |
| 5853 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5854 | #ifndef OS_GETGROUPS_METHODDEF |
| 5855 | #define OS_GETGROUPS_METHODDEF |
| 5856 | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
| 5857 | |
| 5858 | #ifndef OS_GETPGID_METHODDEF |
| 5859 | #define OS_GETPGID_METHODDEF |
| 5860 | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
| 5861 | |
| 5862 | #ifndef OS_GETPGRP_METHODDEF |
| 5863 | #define OS_GETPGRP_METHODDEF |
| 5864 | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
| 5865 | |
| 5866 | #ifndef OS_SETPGRP_METHODDEF |
| 5867 | #define OS_SETPGRP_METHODDEF |
| 5868 | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
| 5869 | |
| 5870 | #ifndef OS_GETPPID_METHODDEF |
| 5871 | #define OS_GETPPID_METHODDEF |
| 5872 | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
| 5873 | |
| 5874 | #ifndef OS_GETLOGIN_METHODDEF |
| 5875 | #define OS_GETLOGIN_METHODDEF |
| 5876 | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
| 5877 | |
| 5878 | #ifndef OS_GETUID_METHODDEF |
| 5879 | #define OS_GETUID_METHODDEF |
| 5880 | #endif /* !defined(OS_GETUID_METHODDEF) */ |
| 5881 | |
| 5882 | #ifndef OS_KILL_METHODDEF |
| 5883 | #define OS_KILL_METHODDEF |
| 5884 | #endif /* !defined(OS_KILL_METHODDEF) */ |
| 5885 | |
| 5886 | #ifndef OS_KILLPG_METHODDEF |
| 5887 | #define OS_KILLPG_METHODDEF |
| 5888 | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
| 5889 | |
| 5890 | #ifndef OS_PLOCK_METHODDEF |
| 5891 | #define OS_PLOCK_METHODDEF |
| 5892 | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
| 5893 | |
| 5894 | #ifndef OS_SETUID_METHODDEF |
| 5895 | #define OS_SETUID_METHODDEF |
| 5896 | #endif /* !defined(OS_SETUID_METHODDEF) */ |
| 5897 | |
| 5898 | #ifndef OS_SETEUID_METHODDEF |
| 5899 | #define OS_SETEUID_METHODDEF |
| 5900 | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
| 5901 | |
| 5902 | #ifndef OS_SETEGID_METHODDEF |
| 5903 | #define OS_SETEGID_METHODDEF |
| 5904 | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
| 5905 | |
| 5906 | #ifndef OS_SETREUID_METHODDEF |
| 5907 | #define OS_SETREUID_METHODDEF |
| 5908 | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
| 5909 | |
| 5910 | #ifndef OS_SETREGID_METHODDEF |
| 5911 | #define OS_SETREGID_METHODDEF |
| 5912 | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
| 5913 | |
| 5914 | #ifndef OS_SETGID_METHODDEF |
| 5915 | #define OS_SETGID_METHODDEF |
| 5916 | #endif /* !defined(OS_SETGID_METHODDEF) */ |
| 5917 | |
| 5918 | #ifndef OS_SETGROUPS_METHODDEF |
| 5919 | #define OS_SETGROUPS_METHODDEF |
| 5920 | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
| 5921 | |
| 5922 | #ifndef OS_WAIT3_METHODDEF |
| 5923 | #define OS_WAIT3_METHODDEF |
| 5924 | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
| 5925 | |
| 5926 | #ifndef OS_WAIT4_METHODDEF |
| 5927 | #define OS_WAIT4_METHODDEF |
| 5928 | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
| 5929 | |
| 5930 | #ifndef OS_WAITID_METHODDEF |
| 5931 | #define OS_WAITID_METHODDEF |
| 5932 | #endif /* !defined(OS_WAITID_METHODDEF) */ |
| 5933 | |
| 5934 | #ifndef OS_WAITPID_METHODDEF |
| 5935 | #define OS_WAITPID_METHODDEF |
| 5936 | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
| 5937 | |
| 5938 | #ifndef OS_WAIT_METHODDEF |
| 5939 | #define OS_WAIT_METHODDEF |
| 5940 | #endif /* !defined(OS_WAIT_METHODDEF) */ |
| 5941 | |
| 5942 | #ifndef OS_SYMLINK_METHODDEF |
| 5943 | #define OS_SYMLINK_METHODDEF |
| 5944 | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
| 5945 | |
| 5946 | #ifndef OS_TIMES_METHODDEF |
| 5947 | #define OS_TIMES_METHODDEF |
| 5948 | #endif /* !defined(OS_TIMES_METHODDEF) */ |
| 5949 | |
| 5950 | #ifndef OS_GETSID_METHODDEF |
| 5951 | #define OS_GETSID_METHODDEF |
| 5952 | #endif /* !defined(OS_GETSID_METHODDEF) */ |
| 5953 | |
| 5954 | #ifndef OS_SETSID_METHODDEF |
| 5955 | #define OS_SETSID_METHODDEF |
| 5956 | #endif /* !defined(OS_SETSID_METHODDEF) */ |
| 5957 | |
| 5958 | #ifndef OS_SETPGID_METHODDEF |
| 5959 | #define OS_SETPGID_METHODDEF |
| 5960 | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
| 5961 | |
| 5962 | #ifndef OS_TCGETPGRP_METHODDEF |
| 5963 | #define OS_TCGETPGRP_METHODDEF |
| 5964 | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
| 5965 | |
| 5966 | #ifndef OS_TCSETPGRP_METHODDEF |
| 5967 | #define OS_TCSETPGRP_METHODDEF |
| 5968 | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
| 5969 | |
| 5970 | #ifndef OS_LOCKF_METHODDEF |
| 5971 | #define OS_LOCKF_METHODDEF |
| 5972 | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
| 5973 | |
| 5974 | #ifndef OS_READV_METHODDEF |
| 5975 | #define OS_READV_METHODDEF |
| 5976 | #endif /* !defined(OS_READV_METHODDEF) */ |
| 5977 | |
| 5978 | #ifndef OS_PREAD_METHODDEF |
| 5979 | #define OS_PREAD_METHODDEF |
| 5980 | #endif /* !defined(OS_PREAD_METHODDEF) */ |
| 5981 | |
| 5982 | #ifndef OS_PIPE_METHODDEF |
| 5983 | #define OS_PIPE_METHODDEF |
| 5984 | #endif /* !defined(OS_PIPE_METHODDEF) */ |
| 5985 | |
| 5986 | #ifndef OS_PIPE2_METHODDEF |
| 5987 | #define OS_PIPE2_METHODDEF |
| 5988 | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
| 5989 | |
| 5990 | #ifndef OS_WRITEV_METHODDEF |
| 5991 | #define OS_WRITEV_METHODDEF |
| 5992 | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
| 5993 | |
| 5994 | #ifndef OS_PWRITE_METHODDEF |
| 5995 | #define OS_PWRITE_METHODDEF |
| 5996 | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
| 5997 | |
| 5998 | #ifndef OS_MKFIFO_METHODDEF |
| 5999 | #define OS_MKFIFO_METHODDEF |
| 6000 | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
| 6001 | |
| 6002 | #ifndef OS_MKNOD_METHODDEF |
| 6003 | #define OS_MKNOD_METHODDEF |
| 6004 | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
| 6005 | |
| 6006 | #ifndef OS_MAJOR_METHODDEF |
| 6007 | #define OS_MAJOR_METHODDEF |
| 6008 | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
| 6009 | |
| 6010 | #ifndef OS_MINOR_METHODDEF |
| 6011 | #define OS_MINOR_METHODDEF |
| 6012 | #endif /* !defined(OS_MINOR_METHODDEF) */ |
| 6013 | |
| 6014 | #ifndef OS_MAKEDEV_METHODDEF |
| 6015 | #define OS_MAKEDEV_METHODDEF |
| 6016 | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
| 6017 | |
| 6018 | #ifndef OS_FTRUNCATE_METHODDEF |
| 6019 | #define OS_FTRUNCATE_METHODDEF |
| 6020 | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
| 6021 | |
| 6022 | #ifndef OS_TRUNCATE_METHODDEF |
| 6023 | #define OS_TRUNCATE_METHODDEF |
| 6024 | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
| 6025 | |
| 6026 | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
| 6027 | #define OS_POSIX_FALLOCATE_METHODDEF |
| 6028 | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
| 6029 | |
| 6030 | #ifndef OS_POSIX_FADVISE_METHODDEF |
| 6031 | #define OS_POSIX_FADVISE_METHODDEF |
| 6032 | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
| 6033 | |
| 6034 | #ifndef OS_PUTENV_METHODDEF |
| 6035 | #define OS_PUTENV_METHODDEF |
| 6036 | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
| 6037 | |
| 6038 | #ifndef OS_UNSETENV_METHODDEF |
| 6039 | #define OS_UNSETENV_METHODDEF |
| 6040 | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
| 6041 | |
| 6042 | #ifndef OS_WCOREDUMP_METHODDEF |
| 6043 | #define OS_WCOREDUMP_METHODDEF |
| 6044 | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
| 6045 | |
| 6046 | #ifndef OS_WIFCONTINUED_METHODDEF |
| 6047 | #define OS_WIFCONTINUED_METHODDEF |
| 6048 | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
| 6049 | |
| 6050 | #ifndef OS_WIFSTOPPED_METHODDEF |
| 6051 | #define OS_WIFSTOPPED_METHODDEF |
| 6052 | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
| 6053 | |
| 6054 | #ifndef OS_WIFSIGNALED_METHODDEF |
| 6055 | #define OS_WIFSIGNALED_METHODDEF |
| 6056 | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
| 6057 | |
| 6058 | #ifndef OS_WIFEXITED_METHODDEF |
| 6059 | #define OS_WIFEXITED_METHODDEF |
| 6060 | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
| 6061 | |
| 6062 | #ifndef OS_WEXITSTATUS_METHODDEF |
| 6063 | #define OS_WEXITSTATUS_METHODDEF |
| 6064 | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
| 6065 | |
| 6066 | #ifndef OS_WTERMSIG_METHODDEF |
| 6067 | #define OS_WTERMSIG_METHODDEF |
| 6068 | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
| 6069 | |
| 6070 | #ifndef OS_WSTOPSIG_METHODDEF |
| 6071 | #define OS_WSTOPSIG_METHODDEF |
| 6072 | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
| 6073 | |
| 6074 | #ifndef OS_FSTATVFS_METHODDEF |
| 6075 | #define OS_FSTATVFS_METHODDEF |
| 6076 | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
| 6077 | |
| 6078 | #ifndef OS_STATVFS_METHODDEF |
| 6079 | #define OS_STATVFS_METHODDEF |
| 6080 | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
| 6081 | |
| 6082 | #ifndef OS__GETDISKUSAGE_METHODDEF |
| 6083 | #define OS__GETDISKUSAGE_METHODDEF |
| 6084 | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
| 6085 | |
| 6086 | #ifndef OS_FPATHCONF_METHODDEF |
| 6087 | #define OS_FPATHCONF_METHODDEF |
| 6088 | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
| 6089 | |
| 6090 | #ifndef OS_PATHCONF_METHODDEF |
| 6091 | #define OS_PATHCONF_METHODDEF |
| 6092 | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
| 6093 | |
| 6094 | #ifndef OS_CONFSTR_METHODDEF |
| 6095 | #define OS_CONFSTR_METHODDEF |
| 6096 | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
| 6097 | |
| 6098 | #ifndef OS_SYSCONF_METHODDEF |
| 6099 | #define OS_SYSCONF_METHODDEF |
| 6100 | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
| 6101 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 6102 | #ifndef OS_STARTFILE_METHODDEF |
| 6103 | #define OS_STARTFILE_METHODDEF |
| 6104 | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
| 6105 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6106 | #ifndef OS_GETLOADAVG_METHODDEF |
| 6107 | #define OS_GETLOADAVG_METHODDEF |
| 6108 | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
| 6109 | |
| 6110 | #ifndef OS_SETRESUID_METHODDEF |
| 6111 | #define OS_SETRESUID_METHODDEF |
| 6112 | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
| 6113 | |
| 6114 | #ifndef OS_SETRESGID_METHODDEF |
| 6115 | #define OS_SETRESGID_METHODDEF |
| 6116 | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
| 6117 | |
| 6118 | #ifndef OS_GETRESUID_METHODDEF |
| 6119 | #define OS_GETRESUID_METHODDEF |
| 6120 | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
| 6121 | |
| 6122 | #ifndef OS_GETRESGID_METHODDEF |
| 6123 | #define OS_GETRESGID_METHODDEF |
| 6124 | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
| 6125 | |
| 6126 | #ifndef OS_GETXATTR_METHODDEF |
| 6127 | #define OS_GETXATTR_METHODDEF |
| 6128 | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
| 6129 | |
| 6130 | #ifndef OS_SETXATTR_METHODDEF |
| 6131 | #define OS_SETXATTR_METHODDEF |
| 6132 | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
| 6133 | |
| 6134 | #ifndef OS_REMOVEXATTR_METHODDEF |
| 6135 | #define OS_REMOVEXATTR_METHODDEF |
| 6136 | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
| 6137 | |
| 6138 | #ifndef OS_LISTXATTR_METHODDEF |
| 6139 | #define OS_LISTXATTR_METHODDEF |
| 6140 | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
| 6141 | |
| 6142 | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 6143 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 6144 | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
| 6145 | |
| 6146 | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 6147 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 6148 | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 6149 | |
| 6150 | #ifndef OS_GETRANDOM_METHODDEF |
| 6151 | #define OS_GETRANDOM_METHODDEF |
| 6152 | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
Xiang Zhang | 4459e00 | 2017-01-22 13:04:17 +0800 | [diff] [blame] | 6153 | /*[clinic end generated code: output=455def991740915a input=a9049054013a1b77]*/ |