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" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 12 | " Path to be examined; can be string, bytes, a path-like object or\n" |
Xiang Zhang | 4459e00 | 2017-01-22 13:04:17 +0800 | [diff] [blame] | 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 \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 31 | {"stat", (PyCFunction)(void(*)(void))os_stat, METH_FASTCALL|METH_KEYWORDS, 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 * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 37 | os_stat(PyObject *module, PyObject *const *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 | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 46 | if (!_PyArg_ParseStackAndKeywords(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 \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 69 | {"lstat", (PyCFunction)(void(*)(void))os_lstat, METH_FASTCALL|METH_KEYWORDS, 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 * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 75 | os_lstat(PyObject *module, PyObject *const *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 | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 83 | if (!_PyArg_ParseStackAndKeywords(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" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 104 | " Path to be tested; can be string, bytes, or a path-like object.\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 \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 129 | {"access", (PyCFunction)(void(*)(void))os_access, METH_FASTCALL|METH_KEYWORDS, 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 * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 136 | os_access(PyObject *module, PyObject *const *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 | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 148 | if (!_PyArg_ParseStackAndKeywords(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 | |
Serhiy Storchaka | 4db62e1 | 2018-12-17 16:47:45 +0200 | [diff] [blame] | 179 | static PyObject * |
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; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 187 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 188 | if (PyFloat_Check(arg)) { |
| 189 | PyErr_SetString(PyExc_TypeError, |
| 190 | "integer argument expected, got float" ); |
| 191 | goto exit; |
| 192 | } |
| 193 | fd = _PyLong_AsInt(arg); |
| 194 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 195 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 196 | } |
Serhiy Storchaka | 4db62e1 | 2018-12-17 16:47:45 +0200 | [diff] [blame] | 197 | return_value = os_ttyname_impl(module, fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 198 | |
| 199 | exit: |
| 200 | return return_value; |
| 201 | } |
| 202 | |
| 203 | #endif /* defined(HAVE_TTYNAME) */ |
| 204 | |
| 205 | #if defined(HAVE_CTERMID) |
| 206 | |
| 207 | PyDoc_STRVAR(os_ctermid__doc__, |
| 208 | "ctermid($module, /)\n" |
| 209 | "--\n" |
| 210 | "\n" |
| 211 | "Return the name of the controlling terminal for this process."); |
| 212 | |
| 213 | #define OS_CTERMID_METHODDEF \ |
| 214 | {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, |
| 215 | |
| 216 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 217 | os_ctermid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 218 | |
| 219 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 220 | os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 221 | { |
| 222 | return os_ctermid_impl(module); |
| 223 | } |
| 224 | |
| 225 | #endif /* defined(HAVE_CTERMID) */ |
| 226 | |
| 227 | PyDoc_STRVAR(os_chdir__doc__, |
| 228 | "chdir($module, /, path)\n" |
| 229 | "--\n" |
| 230 | "\n" |
| 231 | "Change the current working directory to the specified path.\n" |
| 232 | "\n" |
| 233 | "path may always be specified as a string.\n" |
| 234 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 235 | " If this functionality is unavailable, using it raises an exception."); |
| 236 | |
| 237 | #define OS_CHDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 238 | {"chdir", (PyCFunction)(void(*)(void))os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 239 | |
| 240 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 241 | os_chdir_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 242 | |
| 243 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 244 | os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 245 | { |
| 246 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 247 | static const char * const _keywords[] = {"path", NULL}; |
| 248 | static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 249 | path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR); |
| 250 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 251 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 252 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 253 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 254 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 255 | return_value = os_chdir_impl(module, &path); |
| 256 | |
| 257 | exit: |
| 258 | /* Cleanup for path */ |
| 259 | path_cleanup(&path); |
| 260 | |
| 261 | return return_value; |
| 262 | } |
| 263 | |
| 264 | #if defined(HAVE_FCHDIR) |
| 265 | |
| 266 | PyDoc_STRVAR(os_fchdir__doc__, |
| 267 | "fchdir($module, /, fd)\n" |
| 268 | "--\n" |
| 269 | "\n" |
| 270 | "Change to the directory of the given file descriptor.\n" |
| 271 | "\n" |
| 272 | "fd must be opened on a directory, not a file.\n" |
| 273 | "Equivalent to os.chdir(fd)."); |
| 274 | |
| 275 | #define OS_FCHDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 276 | {"fchdir", (PyCFunction)(void(*)(void))os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 277 | |
| 278 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 279 | os_fchdir_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 280 | |
| 281 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 282 | os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 283 | { |
| 284 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 285 | static const char * const _keywords[] = {"fd", NULL}; |
| 286 | static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 287 | int fd; |
| 288 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 289 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 290 | fildes_converter, &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 291 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 292 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 293 | return_value = os_fchdir_impl(module, fd); |
| 294 | |
| 295 | exit: |
| 296 | return return_value; |
| 297 | } |
| 298 | |
| 299 | #endif /* defined(HAVE_FCHDIR) */ |
| 300 | |
| 301 | PyDoc_STRVAR(os_chmod__doc__, |
| 302 | "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n" |
| 303 | "--\n" |
| 304 | "\n" |
| 305 | "Change the access permissions of a file.\n" |
| 306 | "\n" |
| 307 | " path\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 308 | " Path to be modified. May always be specified as a str, bytes, or a path-like object.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 309 | " On some platforms, path may also be specified as an open file descriptor.\n" |
| 310 | " If this functionality is unavailable, using it raises an exception.\n" |
| 311 | " mode\n" |
| 312 | " Operating-system mode bitfield.\n" |
| 313 | " dir_fd\n" |
| 314 | " If not None, it should be a file descriptor open to a directory,\n" |
| 315 | " and path should be relative; path will then be relative to that\n" |
| 316 | " directory.\n" |
| 317 | " follow_symlinks\n" |
| 318 | " If False, and the last element of the path is a symbolic link,\n" |
| 319 | " chmod will modify the symbolic link itself instead of the file\n" |
| 320 | " the link points to.\n" |
| 321 | "\n" |
| 322 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 323 | " an open file descriptor.\n" |
| 324 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 325 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 326 | |
| 327 | #define OS_CHMOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 328 | {"chmod", (PyCFunction)(void(*)(void))os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 329 | |
| 330 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 331 | 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] | 332 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 333 | |
| 334 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 335 | os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 336 | { |
| 337 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 338 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL}; |
| 339 | static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 340 | path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD); |
| 341 | int mode; |
| 342 | int dir_fd = DEFAULT_DIR_FD; |
| 343 | int follow_symlinks = 1; |
| 344 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 345 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 346 | path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 347 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 348 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 349 | return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); |
| 350 | |
| 351 | exit: |
| 352 | /* Cleanup for path */ |
| 353 | path_cleanup(&path); |
| 354 | |
| 355 | return return_value; |
| 356 | } |
| 357 | |
| 358 | #if defined(HAVE_FCHMOD) |
| 359 | |
| 360 | PyDoc_STRVAR(os_fchmod__doc__, |
| 361 | "fchmod($module, /, fd, mode)\n" |
| 362 | "--\n" |
| 363 | "\n" |
| 364 | "Change the access permissions of the file given by file descriptor fd.\n" |
| 365 | "\n" |
| 366 | "Equivalent to os.chmod(fd, mode)."); |
| 367 | |
| 368 | #define OS_FCHMOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 369 | {"fchmod", (PyCFunction)(void(*)(void))os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 370 | |
| 371 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 372 | os_fchmod_impl(PyObject *module, int fd, int mode); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 373 | |
| 374 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 375 | os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 376 | { |
| 377 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 378 | static const char * const _keywords[] = {"fd", "mode", NULL}; |
| 379 | static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 380 | int fd; |
| 381 | int mode; |
| 382 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 383 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 384 | &fd, &mode)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 385 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 386 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 387 | return_value = os_fchmod_impl(module, fd, mode); |
| 388 | |
| 389 | exit: |
| 390 | return return_value; |
| 391 | } |
| 392 | |
| 393 | #endif /* defined(HAVE_FCHMOD) */ |
| 394 | |
| 395 | #if defined(HAVE_LCHMOD) |
| 396 | |
| 397 | PyDoc_STRVAR(os_lchmod__doc__, |
| 398 | "lchmod($module, /, path, mode)\n" |
| 399 | "--\n" |
| 400 | "\n" |
| 401 | "Change the access permissions of a file, without following symbolic links.\n" |
| 402 | "\n" |
| 403 | "If path is a symlink, this affects the link itself rather than the target.\n" |
| 404 | "Equivalent to chmod(path, mode, follow_symlinks=False).\""); |
| 405 | |
| 406 | #define OS_LCHMOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 407 | {"lchmod", (PyCFunction)(void(*)(void))os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 408 | |
| 409 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 410 | os_lchmod_impl(PyObject *module, path_t *path, int mode); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 411 | |
| 412 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 413 | os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 414 | { |
| 415 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 416 | static const char * const _keywords[] = {"path", "mode", NULL}; |
| 417 | static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 418 | path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0); |
| 419 | int mode; |
| 420 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 421 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 422 | path_converter, &path, &mode)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 423 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 424 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 425 | return_value = os_lchmod_impl(module, &path, mode); |
| 426 | |
| 427 | exit: |
| 428 | /* Cleanup for path */ |
| 429 | path_cleanup(&path); |
| 430 | |
| 431 | return return_value; |
| 432 | } |
| 433 | |
| 434 | #endif /* defined(HAVE_LCHMOD) */ |
| 435 | |
| 436 | #if defined(HAVE_CHFLAGS) |
| 437 | |
| 438 | PyDoc_STRVAR(os_chflags__doc__, |
| 439 | "chflags($module, /, path, flags, follow_symlinks=True)\n" |
| 440 | "--\n" |
| 441 | "\n" |
| 442 | "Set file flags.\n" |
| 443 | "\n" |
| 444 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 445 | " link, chflags will change flags on the symbolic link itself instead of the\n" |
| 446 | " file the link points to.\n" |
| 447 | "follow_symlinks may not be implemented on your platform. If it is\n" |
| 448 | "unavailable, using it will raise a NotImplementedError."); |
| 449 | |
| 450 | #define OS_CHFLAGS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 451 | {"chflags", (PyCFunction)(void(*)(void))os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 452 | |
| 453 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 454 | os_chflags_impl(PyObject *module, path_t *path, unsigned long flags, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 455 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 456 | |
| 457 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 458 | os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 459 | { |
| 460 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 461 | static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL}; |
| 462 | static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 463 | path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0); |
| 464 | unsigned long flags; |
| 465 | int follow_symlinks = 1; |
| 466 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 467 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 468 | path_converter, &path, &flags, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 469 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 470 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 471 | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
| 472 | |
| 473 | exit: |
| 474 | /* Cleanup for path */ |
| 475 | path_cleanup(&path); |
| 476 | |
| 477 | return return_value; |
| 478 | } |
| 479 | |
| 480 | #endif /* defined(HAVE_CHFLAGS) */ |
| 481 | |
| 482 | #if defined(HAVE_LCHFLAGS) |
| 483 | |
| 484 | PyDoc_STRVAR(os_lchflags__doc__, |
| 485 | "lchflags($module, /, path, flags)\n" |
| 486 | "--\n" |
| 487 | "\n" |
| 488 | "Set file flags.\n" |
| 489 | "\n" |
| 490 | "This function will not follow symbolic links.\n" |
| 491 | "Equivalent to chflags(path, flags, follow_symlinks=False)."); |
| 492 | |
| 493 | #define OS_LCHFLAGS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 494 | {"lchflags", (PyCFunction)(void(*)(void))os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 495 | |
| 496 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 497 | os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 498 | |
| 499 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 500 | os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 501 | { |
| 502 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 503 | static const char * const _keywords[] = {"path", "flags", NULL}; |
| 504 | static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 505 | path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0); |
| 506 | unsigned long flags; |
| 507 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 508 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 509 | path_converter, &path, &flags)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 510 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 511 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 512 | return_value = os_lchflags_impl(module, &path, flags); |
| 513 | |
| 514 | exit: |
| 515 | /* Cleanup for path */ |
| 516 | path_cleanup(&path); |
| 517 | |
| 518 | return return_value; |
| 519 | } |
| 520 | |
| 521 | #endif /* defined(HAVE_LCHFLAGS) */ |
| 522 | |
| 523 | #if defined(HAVE_CHROOT) |
| 524 | |
| 525 | PyDoc_STRVAR(os_chroot__doc__, |
| 526 | "chroot($module, /, path)\n" |
| 527 | "--\n" |
| 528 | "\n" |
| 529 | "Change root directory to path."); |
| 530 | |
| 531 | #define OS_CHROOT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 532 | {"chroot", (PyCFunction)(void(*)(void))os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 533 | |
| 534 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 535 | os_chroot_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 536 | |
| 537 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 538 | os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 539 | { |
| 540 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 541 | static const char * const _keywords[] = {"path", NULL}; |
| 542 | static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 543 | path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0); |
| 544 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 545 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 546 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 547 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 548 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 549 | return_value = os_chroot_impl(module, &path); |
| 550 | |
| 551 | exit: |
| 552 | /* Cleanup for path */ |
| 553 | path_cleanup(&path); |
| 554 | |
| 555 | return return_value; |
| 556 | } |
| 557 | |
| 558 | #endif /* defined(HAVE_CHROOT) */ |
| 559 | |
| 560 | #if defined(HAVE_FSYNC) |
| 561 | |
| 562 | PyDoc_STRVAR(os_fsync__doc__, |
| 563 | "fsync($module, /, fd)\n" |
| 564 | "--\n" |
| 565 | "\n" |
| 566 | "Force write of fd to disk."); |
| 567 | |
| 568 | #define OS_FSYNC_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 569 | {"fsync", (PyCFunction)(void(*)(void))os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 570 | |
| 571 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 572 | os_fsync_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 573 | |
| 574 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 575 | os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 576 | { |
| 577 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 578 | static const char * const _keywords[] = {"fd", NULL}; |
| 579 | static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 580 | int fd; |
| 581 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 582 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 583 | fildes_converter, &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 584 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 585 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 586 | return_value = os_fsync_impl(module, fd); |
| 587 | |
| 588 | exit: |
| 589 | return return_value; |
| 590 | } |
| 591 | |
| 592 | #endif /* defined(HAVE_FSYNC) */ |
| 593 | |
| 594 | #if defined(HAVE_SYNC) |
| 595 | |
| 596 | PyDoc_STRVAR(os_sync__doc__, |
| 597 | "sync($module, /)\n" |
| 598 | "--\n" |
| 599 | "\n" |
| 600 | "Force write of everything to disk."); |
| 601 | |
| 602 | #define OS_SYNC_METHODDEF \ |
| 603 | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
| 604 | |
| 605 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 606 | os_sync_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 607 | |
| 608 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 609 | os_sync(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 610 | { |
| 611 | return os_sync_impl(module); |
| 612 | } |
| 613 | |
| 614 | #endif /* defined(HAVE_SYNC) */ |
| 615 | |
| 616 | #if defined(HAVE_FDATASYNC) |
| 617 | |
| 618 | PyDoc_STRVAR(os_fdatasync__doc__, |
| 619 | "fdatasync($module, /, fd)\n" |
| 620 | "--\n" |
| 621 | "\n" |
| 622 | "Force write of fd to disk without forcing update of metadata."); |
| 623 | |
| 624 | #define OS_FDATASYNC_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 625 | {"fdatasync", (PyCFunction)(void(*)(void))os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 626 | |
| 627 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 628 | os_fdatasync_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 629 | |
| 630 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 631 | os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 632 | { |
| 633 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 634 | static const char * const _keywords[] = {"fd", NULL}; |
| 635 | static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 636 | int fd; |
| 637 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 638 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 639 | fildes_converter, &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 640 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 641 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 642 | return_value = os_fdatasync_impl(module, fd); |
| 643 | |
| 644 | exit: |
| 645 | return return_value; |
| 646 | } |
| 647 | |
| 648 | #endif /* defined(HAVE_FDATASYNC) */ |
| 649 | |
| 650 | #if defined(HAVE_CHOWN) |
| 651 | |
| 652 | PyDoc_STRVAR(os_chown__doc__, |
| 653 | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
| 654 | "--\n" |
| 655 | "\n" |
| 656 | "Change the owner and group id of path to the numeric uid and gid.\\\n" |
| 657 | "\n" |
| 658 | " path\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 659 | " Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 660 | " dir_fd\n" |
| 661 | " If not None, it should be a file descriptor open to a directory,\n" |
| 662 | " and path should be relative; path will then be relative to that\n" |
| 663 | " directory.\n" |
| 664 | " follow_symlinks\n" |
| 665 | " If False, and the last element of the path is a symbolic link,\n" |
| 666 | " stat will examine the symbolic link itself instead of the file\n" |
| 667 | " the link points to.\n" |
| 668 | "\n" |
| 669 | "path may always be specified as a string.\n" |
| 670 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 671 | " If this functionality is unavailable, using it raises an exception.\n" |
| 672 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 673 | " and path should be relative; path will then be relative to that directory.\n" |
| 674 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 675 | " link, chown will modify the symbolic link itself instead of the file the\n" |
| 676 | " link points to.\n" |
| 677 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
| 678 | " an open file descriptor.\n" |
| 679 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
| 680 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 681 | |
| 682 | #define OS_CHOWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 683 | {"chown", (PyCFunction)(void(*)(void))os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 684 | |
| 685 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 686 | 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] | 687 | int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 688 | |
| 689 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 690 | os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 691 | { |
| 692 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 693 | static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; |
| 694 | static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 695 | path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN); |
| 696 | uid_t uid; |
| 697 | gid_t gid; |
| 698 | int dir_fd = DEFAULT_DIR_FD; |
| 699 | int follow_symlinks = 1; |
| 700 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 701 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 702 | 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] | 703 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 704 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 705 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
| 706 | |
| 707 | exit: |
| 708 | /* Cleanup for path */ |
| 709 | path_cleanup(&path); |
| 710 | |
| 711 | return return_value; |
| 712 | } |
| 713 | |
| 714 | #endif /* defined(HAVE_CHOWN) */ |
| 715 | |
| 716 | #if defined(HAVE_FCHOWN) |
| 717 | |
| 718 | PyDoc_STRVAR(os_fchown__doc__, |
| 719 | "fchown($module, /, fd, uid, gid)\n" |
| 720 | "--\n" |
| 721 | "\n" |
| 722 | "Change the owner and group id of the file specified by file descriptor.\n" |
| 723 | "\n" |
| 724 | "Equivalent to os.chown(fd, uid, gid)."); |
| 725 | |
| 726 | #define OS_FCHOWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 727 | {"fchown", (PyCFunction)(void(*)(void))os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 728 | |
| 729 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 730 | 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] | 731 | |
| 732 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 733 | os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 734 | { |
| 735 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 736 | static const char * const _keywords[] = {"fd", "uid", "gid", NULL}; |
| 737 | static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 738 | int fd; |
| 739 | uid_t uid; |
| 740 | gid_t gid; |
| 741 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 742 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 743 | &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 744 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 745 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 746 | return_value = os_fchown_impl(module, fd, uid, gid); |
| 747 | |
| 748 | exit: |
| 749 | return return_value; |
| 750 | } |
| 751 | |
| 752 | #endif /* defined(HAVE_FCHOWN) */ |
| 753 | |
| 754 | #if defined(HAVE_LCHOWN) |
| 755 | |
| 756 | PyDoc_STRVAR(os_lchown__doc__, |
| 757 | "lchown($module, /, path, uid, gid)\n" |
| 758 | "--\n" |
| 759 | "\n" |
| 760 | "Change the owner and group id of path to the numeric uid and gid.\n" |
| 761 | "\n" |
| 762 | "This function will not follow symbolic links.\n" |
| 763 | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); |
| 764 | |
| 765 | #define OS_LCHOWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 766 | {"lchown", (PyCFunction)(void(*)(void))os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 767 | |
| 768 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 769 | 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] | 770 | |
| 771 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 772 | os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 773 | { |
| 774 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 775 | static const char * const _keywords[] = {"path", "uid", "gid", NULL}; |
| 776 | static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 777 | path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0); |
| 778 | uid_t uid; |
| 779 | gid_t gid; |
| 780 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 781 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 782 | path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 783 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 784 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 785 | return_value = os_lchown_impl(module, &path, uid, gid); |
| 786 | |
| 787 | exit: |
| 788 | /* Cleanup for path */ |
| 789 | path_cleanup(&path); |
| 790 | |
| 791 | return return_value; |
| 792 | } |
| 793 | |
| 794 | #endif /* defined(HAVE_LCHOWN) */ |
| 795 | |
| 796 | PyDoc_STRVAR(os_getcwd__doc__, |
| 797 | "getcwd($module, /)\n" |
| 798 | "--\n" |
| 799 | "\n" |
| 800 | "Return a unicode string representing the current working directory."); |
| 801 | |
| 802 | #define OS_GETCWD_METHODDEF \ |
| 803 | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
| 804 | |
| 805 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 806 | os_getcwd_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 807 | |
| 808 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 809 | os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 810 | { |
| 811 | return os_getcwd_impl(module); |
| 812 | } |
| 813 | |
| 814 | PyDoc_STRVAR(os_getcwdb__doc__, |
| 815 | "getcwdb($module, /)\n" |
| 816 | "--\n" |
| 817 | "\n" |
| 818 | "Return a bytes string representing the current working directory."); |
| 819 | |
| 820 | #define OS_GETCWDB_METHODDEF \ |
| 821 | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
| 822 | |
| 823 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 824 | os_getcwdb_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 825 | |
| 826 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 827 | os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 828 | { |
| 829 | return os_getcwdb_impl(module); |
| 830 | } |
| 831 | |
| 832 | #if defined(HAVE_LINK) |
| 833 | |
| 834 | PyDoc_STRVAR(os_link__doc__, |
| 835 | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
| 836 | " follow_symlinks=True)\n" |
| 837 | "--\n" |
| 838 | "\n" |
| 839 | "Create a hard link to a file.\n" |
| 840 | "\n" |
| 841 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 842 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 843 | " should be relative; the path will then be relative to that directory.\n" |
| 844 | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
| 845 | " link, link will create a link to the symbolic link itself instead of the\n" |
| 846 | " file the link points to.\n" |
| 847 | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" |
| 848 | " platform. If they are unavailable, using them will raise a\n" |
| 849 | " NotImplementedError."); |
| 850 | |
| 851 | #define OS_LINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 852 | {"link", (PyCFunction)(void(*)(void))os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 853 | |
| 854 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 855 | 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] | 856 | int dst_dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 857 | |
| 858 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 859 | os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 860 | { |
| 861 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 862 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; |
| 863 | static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 864 | path_t src = PATH_T_INITIALIZE("link", "src", 0, 0); |
| 865 | path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0); |
| 866 | int src_dir_fd = DEFAULT_DIR_FD; |
| 867 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 868 | int follow_symlinks = 1; |
| 869 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 870 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 871 | 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] | 872 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 873 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 874 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
| 875 | |
| 876 | exit: |
| 877 | /* Cleanup for src */ |
| 878 | path_cleanup(&src); |
| 879 | /* Cleanup for dst */ |
| 880 | path_cleanup(&dst); |
| 881 | |
| 882 | return return_value; |
| 883 | } |
| 884 | |
| 885 | #endif /* defined(HAVE_LINK) */ |
| 886 | |
| 887 | PyDoc_STRVAR(os_listdir__doc__, |
| 888 | "listdir($module, /, path=None)\n" |
| 889 | "--\n" |
| 890 | "\n" |
| 891 | "Return a list containing the names of the files in the directory.\n" |
| 892 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 893 | "path can be specified as either str, bytes, or a path-like object. If path is bytes,\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 894 | " the filenames returned will also be bytes; in all other circumstances\n" |
| 895 | " the filenames returned will be str.\n" |
| 896 | "If path is None, uses the path=\'.\'.\n" |
| 897 | "On some platforms, path may also be specified as an open file descriptor;\\\n" |
| 898 | " the file descriptor must refer to a directory.\n" |
| 899 | " If this functionality is unavailable, using it raises NotImplementedError.\n" |
| 900 | "\n" |
| 901 | "The list is in arbitrary order. It does not include the special\n" |
| 902 | "entries \'.\' and \'..\' even if they are present in the directory."); |
| 903 | |
| 904 | #define OS_LISTDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 905 | {"listdir", (PyCFunction)(void(*)(void))os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 906 | |
| 907 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 908 | os_listdir_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 909 | |
| 910 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 911 | os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 912 | { |
| 913 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 914 | static const char * const _keywords[] = {"path", NULL}; |
| 915 | static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 916 | path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR); |
| 917 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 918 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 919 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 920 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 921 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 922 | return_value = os_listdir_impl(module, &path); |
| 923 | |
| 924 | exit: |
| 925 | /* Cleanup for path */ |
| 926 | path_cleanup(&path); |
| 927 | |
| 928 | return return_value; |
| 929 | } |
| 930 | |
| 931 | #if defined(MS_WINDOWS) |
| 932 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 933 | PyDoc_STRVAR(os__getfullpathname__doc__, |
| 934 | "_getfullpathname($module, path, /)\n" |
| 935 | "--\n" |
| 936 | "\n"); |
| 937 | |
| 938 | #define OS__GETFULLPATHNAME_METHODDEF \ |
| 939 | {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__}, |
| 940 | |
| 941 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 942 | os__getfullpathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 943 | |
| 944 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 945 | os__getfullpathname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 946 | { |
| 947 | PyObject *return_value = NULL; |
| 948 | path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0); |
| 949 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 950 | if (!path_converter(arg, &path)) { |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 951 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 952 | } |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 953 | return_value = os__getfullpathname_impl(module, &path); |
| 954 | |
| 955 | exit: |
| 956 | /* Cleanup for path */ |
| 957 | path_cleanup(&path); |
| 958 | |
| 959 | return return_value; |
| 960 | } |
| 961 | |
| 962 | #endif /* defined(MS_WINDOWS) */ |
| 963 | |
| 964 | #if defined(MS_WINDOWS) |
| 965 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 966 | PyDoc_STRVAR(os__getfinalpathname__doc__, |
| 967 | "_getfinalpathname($module, path, /)\n" |
| 968 | "--\n" |
| 969 | "\n" |
| 970 | "A helper function for samepath on windows."); |
| 971 | |
| 972 | #define OS__GETFINALPATHNAME_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 973 | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 974 | |
| 975 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 976 | os__getfinalpathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 977 | |
| 978 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 979 | os__getfinalpathname(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 980 | { |
| 981 | PyObject *return_value = NULL; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 982 | path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 983 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 984 | if (!path_converter(arg, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 985 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 986 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 987 | return_value = os__getfinalpathname_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 988 | |
| 989 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 990 | /* Cleanup for path */ |
| 991 | path_cleanup(&path); |
| 992 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 993 | return return_value; |
| 994 | } |
| 995 | |
| 996 | #endif /* defined(MS_WINDOWS) */ |
| 997 | |
| 998 | #if defined(MS_WINDOWS) |
| 999 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1000 | PyDoc_STRVAR(os__isdir__doc__, |
| 1001 | "_isdir($module, path, /)\n" |
| 1002 | "--\n" |
Serhiy Storchaka | 579f038 | 2016-11-08 20:21:22 +0200 | [diff] [blame] | 1003 | "\n" |
| 1004 | "Return true if the pathname refers to an existing directory."); |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1005 | |
| 1006 | #define OS__ISDIR_METHODDEF \ |
| 1007 | {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__}, |
| 1008 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 1009 | #endif /* defined(MS_WINDOWS) */ |
| 1010 | |
| 1011 | #if defined(MS_WINDOWS) |
| 1012 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1013 | PyDoc_STRVAR(os__getvolumepathname__doc__, |
| 1014 | "_getvolumepathname($module, /, path)\n" |
| 1015 | "--\n" |
| 1016 | "\n" |
| 1017 | "A helper function for ismount on Win32."); |
| 1018 | |
| 1019 | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1020 | {"_getvolumepathname", (PyCFunction)(void(*)(void))os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1021 | |
| 1022 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1023 | os__getvolumepathname_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1024 | |
| 1025 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1026 | os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1027 | { |
| 1028 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1029 | static const char * const _keywords[] = {"path", NULL}; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1030 | static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0}; |
| 1031 | path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1032 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1033 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1034 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1035 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1036 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1037 | return_value = os__getvolumepathname_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1038 | |
| 1039 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 1040 | /* Cleanup for path */ |
| 1041 | path_cleanup(&path); |
| 1042 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1043 | return return_value; |
| 1044 | } |
| 1045 | |
| 1046 | #endif /* defined(MS_WINDOWS) */ |
| 1047 | |
| 1048 | PyDoc_STRVAR(os_mkdir__doc__, |
| 1049 | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
| 1050 | "--\n" |
| 1051 | "\n" |
| 1052 | "Create a directory.\n" |
| 1053 | "\n" |
| 1054 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1055 | " and path should be relative; path will then be relative to that directory.\n" |
| 1056 | "dir_fd may not be implemented on your platform.\n" |
| 1057 | " If it is unavailable, using it will raise a NotImplementedError.\n" |
| 1058 | "\n" |
| 1059 | "The mode argument is ignored on Windows."); |
| 1060 | |
| 1061 | #define OS_MKDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1062 | {"mkdir", (PyCFunction)(void(*)(void))os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1063 | |
| 1064 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1065 | 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] | 1066 | |
| 1067 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1068 | os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1069 | { |
| 1070 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1071 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
| 1072 | static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1073 | path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0); |
| 1074 | int mode = 511; |
| 1075 | int dir_fd = DEFAULT_DIR_FD; |
| 1076 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1077 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1078 | path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1079 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1080 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1081 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
| 1082 | |
| 1083 | exit: |
| 1084 | /* Cleanup for path */ |
| 1085 | path_cleanup(&path); |
| 1086 | |
| 1087 | return return_value; |
| 1088 | } |
| 1089 | |
| 1090 | #if defined(HAVE_NICE) |
| 1091 | |
| 1092 | PyDoc_STRVAR(os_nice__doc__, |
| 1093 | "nice($module, increment, /)\n" |
| 1094 | "--\n" |
| 1095 | "\n" |
| 1096 | "Add increment to the priority of process and return the new priority."); |
| 1097 | |
| 1098 | #define OS_NICE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1099 | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1100 | |
| 1101 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1102 | os_nice_impl(PyObject *module, int increment); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1103 | |
| 1104 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1105 | os_nice(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1106 | { |
| 1107 | PyObject *return_value = NULL; |
| 1108 | int increment; |
| 1109 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1110 | if (PyFloat_Check(arg)) { |
| 1111 | PyErr_SetString(PyExc_TypeError, |
| 1112 | "integer argument expected, got float" ); |
| 1113 | goto exit; |
| 1114 | } |
| 1115 | increment = _PyLong_AsInt(arg); |
| 1116 | if (increment == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1117 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1118 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1119 | return_value = os_nice_impl(module, increment); |
| 1120 | |
| 1121 | exit: |
| 1122 | return return_value; |
| 1123 | } |
| 1124 | |
| 1125 | #endif /* defined(HAVE_NICE) */ |
| 1126 | |
| 1127 | #if defined(HAVE_GETPRIORITY) |
| 1128 | |
| 1129 | PyDoc_STRVAR(os_getpriority__doc__, |
| 1130 | "getpriority($module, /, which, who)\n" |
| 1131 | "--\n" |
| 1132 | "\n" |
| 1133 | "Return program scheduling priority."); |
| 1134 | |
| 1135 | #define OS_GETPRIORITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1136 | {"getpriority", (PyCFunction)(void(*)(void))os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1137 | |
| 1138 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1139 | os_getpriority_impl(PyObject *module, int which, int who); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1140 | |
| 1141 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1142 | os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1143 | { |
| 1144 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1145 | static const char * const _keywords[] = {"which", "who", NULL}; |
| 1146 | static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1147 | int which; |
| 1148 | int who; |
| 1149 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1150 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1151 | &which, &who)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1152 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1153 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1154 | return_value = os_getpriority_impl(module, which, who); |
| 1155 | |
| 1156 | exit: |
| 1157 | return return_value; |
| 1158 | } |
| 1159 | |
| 1160 | #endif /* defined(HAVE_GETPRIORITY) */ |
| 1161 | |
| 1162 | #if defined(HAVE_SETPRIORITY) |
| 1163 | |
| 1164 | PyDoc_STRVAR(os_setpriority__doc__, |
| 1165 | "setpriority($module, /, which, who, priority)\n" |
| 1166 | "--\n" |
| 1167 | "\n" |
| 1168 | "Set program scheduling priority."); |
| 1169 | |
| 1170 | #define OS_SETPRIORITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1171 | {"setpriority", (PyCFunction)(void(*)(void))os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1172 | |
| 1173 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1174 | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1175 | |
| 1176 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1177 | os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1178 | { |
| 1179 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1180 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
| 1181 | static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1182 | int which; |
| 1183 | int who; |
| 1184 | int priority; |
| 1185 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1186 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1187 | &which, &who, &priority)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1188 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1189 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1190 | return_value = os_setpriority_impl(module, which, who, priority); |
| 1191 | |
| 1192 | exit: |
| 1193 | return return_value; |
| 1194 | } |
| 1195 | |
| 1196 | #endif /* defined(HAVE_SETPRIORITY) */ |
| 1197 | |
| 1198 | PyDoc_STRVAR(os_rename__doc__, |
| 1199 | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1200 | "--\n" |
| 1201 | "\n" |
| 1202 | "Rename a file or directory.\n" |
| 1203 | "\n" |
| 1204 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1205 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1206 | " should be relative; the path will then be relative to that directory.\n" |
| 1207 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1208 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1209 | |
| 1210 | #define OS_RENAME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1211 | {"rename", (PyCFunction)(void(*)(void))os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1212 | |
| 1213 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1214 | 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] | 1215 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1216 | |
| 1217 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1218 | os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1219 | { |
| 1220 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1221 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
| 1222 | static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1223 | path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0); |
| 1224 | path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0); |
| 1225 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1226 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1227 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1228 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1229 | 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] | 1230 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1231 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1232 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1233 | |
| 1234 | exit: |
| 1235 | /* Cleanup for src */ |
| 1236 | path_cleanup(&src); |
| 1237 | /* Cleanup for dst */ |
| 1238 | path_cleanup(&dst); |
| 1239 | |
| 1240 | return return_value; |
| 1241 | } |
| 1242 | |
| 1243 | PyDoc_STRVAR(os_replace__doc__, |
| 1244 | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
| 1245 | "--\n" |
| 1246 | "\n" |
| 1247 | "Rename a file or directory, overwriting the destination.\n" |
| 1248 | "\n" |
| 1249 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
| 1250 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
| 1251 | " should be relative; the path will then be relative to that directory.\n" |
| 1252 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
| 1253 | " If they are unavailable, using them will raise a NotImplementedError.\""); |
| 1254 | |
| 1255 | #define OS_REPLACE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1256 | {"replace", (PyCFunction)(void(*)(void))os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1257 | |
| 1258 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1259 | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
| 1260 | int dst_dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1261 | |
| 1262 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1263 | os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1264 | { |
| 1265 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1266 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
| 1267 | static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1268 | path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0); |
| 1269 | path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0); |
| 1270 | int src_dir_fd = DEFAULT_DIR_FD; |
| 1271 | int dst_dir_fd = DEFAULT_DIR_FD; |
| 1272 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1273 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1274 | 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] | 1275 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1276 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1277 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
| 1278 | |
| 1279 | exit: |
| 1280 | /* Cleanup for src */ |
| 1281 | path_cleanup(&src); |
| 1282 | /* Cleanup for dst */ |
| 1283 | path_cleanup(&dst); |
| 1284 | |
| 1285 | return return_value; |
| 1286 | } |
| 1287 | |
| 1288 | PyDoc_STRVAR(os_rmdir__doc__, |
| 1289 | "rmdir($module, /, path, *, dir_fd=None)\n" |
| 1290 | "--\n" |
| 1291 | "\n" |
| 1292 | "Remove a directory.\n" |
| 1293 | "\n" |
| 1294 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1295 | " and path should be relative; path will then be relative to that directory.\n" |
| 1296 | "dir_fd may not be implemented on your platform.\n" |
| 1297 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1298 | |
| 1299 | #define OS_RMDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1300 | {"rmdir", (PyCFunction)(void(*)(void))os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1301 | |
| 1302 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1303 | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1304 | |
| 1305 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1306 | os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1307 | { |
| 1308 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1309 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 1310 | static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1311 | path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0); |
| 1312 | int dir_fd = DEFAULT_DIR_FD; |
| 1313 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1314 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1315 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1316 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1317 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1318 | return_value = os_rmdir_impl(module, &path, dir_fd); |
| 1319 | |
| 1320 | exit: |
| 1321 | /* Cleanup for path */ |
| 1322 | path_cleanup(&path); |
| 1323 | |
| 1324 | return return_value; |
| 1325 | } |
| 1326 | |
| 1327 | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
| 1328 | |
| 1329 | PyDoc_STRVAR(os_system__doc__, |
| 1330 | "system($module, /, command)\n" |
| 1331 | "--\n" |
| 1332 | "\n" |
| 1333 | "Execute the command in a subshell."); |
| 1334 | |
| 1335 | #define OS_SYSTEM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1336 | {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1337 | |
| 1338 | static long |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 1339 | os_system_impl(PyObject *module, const Py_UNICODE *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1340 | |
| 1341 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1342 | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1343 | { |
| 1344 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1345 | static const char * const _keywords[] = {"command", NULL}; |
| 1346 | static _PyArg_Parser _parser = {"u:system", _keywords, 0}; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 1347 | const Py_UNICODE *command; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1348 | long _return_value; |
| 1349 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1350 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1351 | &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1352 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1353 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1354 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1355 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1356 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1357 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1358 | return_value = PyLong_FromLong(_return_value); |
| 1359 | |
| 1360 | exit: |
| 1361 | return return_value; |
| 1362 | } |
| 1363 | |
| 1364 | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
| 1365 | |
| 1366 | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
| 1367 | |
| 1368 | PyDoc_STRVAR(os_system__doc__, |
| 1369 | "system($module, /, command)\n" |
| 1370 | "--\n" |
| 1371 | "\n" |
| 1372 | "Execute the command in a subshell."); |
| 1373 | |
| 1374 | #define OS_SYSTEM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1375 | {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1376 | |
| 1377 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1378 | os_system_impl(PyObject *module, PyObject *command); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1379 | |
| 1380 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1381 | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1382 | { |
| 1383 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1384 | static const char * const _keywords[] = {"command", NULL}; |
| 1385 | static _PyArg_Parser _parser = {"O&:system", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1386 | PyObject *command = NULL; |
| 1387 | long _return_value; |
| 1388 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1389 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1390 | PyUnicode_FSConverter, &command)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1391 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1392 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1393 | _return_value = os_system_impl(module, command); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1394 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1395 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1396 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1397 | return_value = PyLong_FromLong(_return_value); |
| 1398 | |
| 1399 | exit: |
| 1400 | /* Cleanup for command */ |
| 1401 | Py_XDECREF(command); |
| 1402 | |
| 1403 | return return_value; |
| 1404 | } |
| 1405 | |
| 1406 | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
| 1407 | |
| 1408 | PyDoc_STRVAR(os_umask__doc__, |
| 1409 | "umask($module, mask, /)\n" |
| 1410 | "--\n" |
| 1411 | "\n" |
| 1412 | "Set the current numeric umask and return the previous umask."); |
| 1413 | |
| 1414 | #define OS_UMASK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 1415 | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1416 | |
| 1417 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1418 | os_umask_impl(PyObject *module, int mask); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1419 | |
| 1420 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1421 | os_umask(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1422 | { |
| 1423 | PyObject *return_value = NULL; |
| 1424 | int mask; |
| 1425 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1426 | if (PyFloat_Check(arg)) { |
| 1427 | PyErr_SetString(PyExc_TypeError, |
| 1428 | "integer argument expected, got float" ); |
| 1429 | goto exit; |
| 1430 | } |
| 1431 | mask = _PyLong_AsInt(arg); |
| 1432 | if (mask == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1433 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1434 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1435 | return_value = os_umask_impl(module, mask); |
| 1436 | |
| 1437 | exit: |
| 1438 | return return_value; |
| 1439 | } |
| 1440 | |
| 1441 | PyDoc_STRVAR(os_unlink__doc__, |
| 1442 | "unlink($module, /, path, *, dir_fd=None)\n" |
| 1443 | "--\n" |
| 1444 | "\n" |
| 1445 | "Remove a file (same as remove()).\n" |
| 1446 | "\n" |
| 1447 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1448 | " and path should be relative; path will then be relative to that directory.\n" |
| 1449 | "dir_fd may not be implemented on your platform.\n" |
| 1450 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1451 | |
| 1452 | #define OS_UNLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1453 | {"unlink", (PyCFunction)(void(*)(void))os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1454 | |
| 1455 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1456 | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1457 | |
| 1458 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1459 | os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1460 | { |
| 1461 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1462 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 1463 | static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1464 | path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0); |
| 1465 | int dir_fd = DEFAULT_DIR_FD; |
| 1466 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1467 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1468 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1469 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1470 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1471 | return_value = os_unlink_impl(module, &path, dir_fd); |
| 1472 | |
| 1473 | exit: |
| 1474 | /* Cleanup for path */ |
| 1475 | path_cleanup(&path); |
| 1476 | |
| 1477 | return return_value; |
| 1478 | } |
| 1479 | |
| 1480 | PyDoc_STRVAR(os_remove__doc__, |
| 1481 | "remove($module, /, path, *, dir_fd=None)\n" |
| 1482 | "--\n" |
| 1483 | "\n" |
| 1484 | "Remove a file (same as unlink()).\n" |
| 1485 | "\n" |
| 1486 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1487 | " and path should be relative; path will then be relative to that directory.\n" |
| 1488 | "dir_fd may not be implemented on your platform.\n" |
| 1489 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 1490 | |
| 1491 | #define OS_REMOVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1492 | {"remove", (PyCFunction)(void(*)(void))os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1493 | |
| 1494 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1495 | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1496 | |
| 1497 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1498 | os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1499 | { |
| 1500 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1501 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 1502 | static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1503 | path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0); |
| 1504 | int dir_fd = DEFAULT_DIR_FD; |
| 1505 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1506 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1507 | path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1508 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1509 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1510 | return_value = os_remove_impl(module, &path, dir_fd); |
| 1511 | |
| 1512 | exit: |
| 1513 | /* Cleanup for path */ |
| 1514 | path_cleanup(&path); |
| 1515 | |
| 1516 | return return_value; |
| 1517 | } |
| 1518 | |
| 1519 | #if defined(HAVE_UNAME) |
| 1520 | |
| 1521 | PyDoc_STRVAR(os_uname__doc__, |
| 1522 | "uname($module, /)\n" |
| 1523 | "--\n" |
| 1524 | "\n" |
| 1525 | "Return an object identifying the current operating system.\n" |
| 1526 | "\n" |
| 1527 | "The object behaves like a named tuple with the following fields:\n" |
| 1528 | " (sysname, nodename, release, version, machine)"); |
| 1529 | |
| 1530 | #define OS_UNAME_METHODDEF \ |
| 1531 | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
| 1532 | |
| 1533 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1534 | os_uname_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1535 | |
| 1536 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1537 | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1538 | { |
| 1539 | return os_uname_impl(module); |
| 1540 | } |
| 1541 | |
| 1542 | #endif /* defined(HAVE_UNAME) */ |
| 1543 | |
| 1544 | PyDoc_STRVAR(os_utime__doc__, |
| 1545 | "utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n" |
| 1546 | " follow_symlinks=True)\n" |
| 1547 | "--\n" |
| 1548 | "\n" |
| 1549 | "Set the access and modified time of path.\n" |
| 1550 | "\n" |
| 1551 | "path may always be specified as a string.\n" |
| 1552 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 1553 | " If this functionality is unavailable, using it raises an exception.\n" |
| 1554 | "\n" |
| 1555 | "If times is not None, it must be a tuple (atime, mtime);\n" |
| 1556 | " 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] | 1557 | "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] | 1558 | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
| 1559 | " since the epoch.\n" |
Martin Panter | 0ff8909 | 2015-09-09 01:56:53 +0000 | [diff] [blame] | 1560 | "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] | 1561 | "Specifying tuples for both times and ns is an error.\n" |
| 1562 | "\n" |
| 1563 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 1564 | " and path should be relative; path will then be relative to that directory.\n" |
| 1565 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 1566 | " link, utime will modify the symbolic link itself instead of the file the\n" |
| 1567 | " link points to.\n" |
| 1568 | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
| 1569 | " as an open file descriptor.\n" |
| 1570 | "dir_fd and follow_symlinks may not be available on your platform.\n" |
| 1571 | " If they are unavailable, using them will raise a NotImplementedError."); |
| 1572 | |
| 1573 | #define OS_UTIME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1574 | {"utime", (PyCFunction)(void(*)(void))os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1575 | |
| 1576 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1577 | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
| 1578 | int dir_fd, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1579 | |
| 1580 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1581 | os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1582 | { |
| 1583 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1584 | static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
| 1585 | static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1586 | path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD); |
| 1587 | PyObject *times = NULL; |
| 1588 | PyObject *ns = NULL; |
| 1589 | int dir_fd = DEFAULT_DIR_FD; |
| 1590 | int follow_symlinks = 1; |
| 1591 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1592 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1593 | path_converter, &path, ×, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1594 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1595 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1596 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
| 1597 | |
| 1598 | exit: |
| 1599 | /* Cleanup for path */ |
| 1600 | path_cleanup(&path); |
| 1601 | |
| 1602 | return return_value; |
| 1603 | } |
| 1604 | |
| 1605 | PyDoc_STRVAR(os__exit__doc__, |
| 1606 | "_exit($module, /, status)\n" |
| 1607 | "--\n" |
| 1608 | "\n" |
| 1609 | "Exit to the system with specified status, without normal exit processing."); |
| 1610 | |
| 1611 | #define OS__EXIT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1612 | {"_exit", (PyCFunction)(void(*)(void))os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1613 | |
| 1614 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1615 | os__exit_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1616 | |
| 1617 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1618 | os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1619 | { |
| 1620 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1621 | static const char * const _keywords[] = {"status", NULL}; |
| 1622 | static _PyArg_Parser _parser = {"i:_exit", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1623 | int status; |
| 1624 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1625 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1626 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1627 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1628 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1629 | return_value = os__exit_impl(module, status); |
| 1630 | |
| 1631 | exit: |
| 1632 | return return_value; |
| 1633 | } |
| 1634 | |
| 1635 | #if defined(HAVE_EXECV) |
| 1636 | |
| 1637 | PyDoc_STRVAR(os_execv__doc__, |
| 1638 | "execv($module, path, argv, /)\n" |
| 1639 | "--\n" |
| 1640 | "\n" |
| 1641 | "Execute an executable path with arguments, replacing current process.\n" |
| 1642 | "\n" |
| 1643 | " path\n" |
| 1644 | " Path of executable file.\n" |
| 1645 | " argv\n" |
| 1646 | " Tuple or list of strings."); |
| 1647 | |
| 1648 | #define OS_EXECV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1649 | {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1650 | |
| 1651 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1652 | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1653 | |
| 1654 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1655 | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1656 | { |
| 1657 | PyObject *return_value = NULL; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1658 | path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1659 | PyObject *argv; |
| 1660 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1661 | if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1662 | goto exit; |
| 1663 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1664 | if (!path_converter(args[0], &path)) { |
| 1665 | goto exit; |
| 1666 | } |
| 1667 | argv = args[1]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1668 | return_value = os_execv_impl(module, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1669 | |
| 1670 | exit: |
| 1671 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1672 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1673 | |
| 1674 | return return_value; |
| 1675 | } |
| 1676 | |
| 1677 | #endif /* defined(HAVE_EXECV) */ |
| 1678 | |
| 1679 | #if defined(HAVE_EXECV) |
| 1680 | |
| 1681 | PyDoc_STRVAR(os_execve__doc__, |
| 1682 | "execve($module, /, path, argv, env)\n" |
| 1683 | "--\n" |
| 1684 | "\n" |
| 1685 | "Execute an executable path with arguments, replacing current process.\n" |
| 1686 | "\n" |
| 1687 | " path\n" |
| 1688 | " Path of executable file.\n" |
| 1689 | " argv\n" |
| 1690 | " Tuple or list of strings.\n" |
| 1691 | " env\n" |
| 1692 | " Dictionary of strings mapping to strings."); |
| 1693 | |
| 1694 | #define OS_EXECVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1695 | {"execve", (PyCFunction)(void(*)(void))os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1696 | |
| 1697 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1698 | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1699 | |
| 1700 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1701 | os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1702 | { |
| 1703 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1704 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
| 1705 | static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1706 | path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE); |
| 1707 | PyObject *argv; |
| 1708 | PyObject *env; |
| 1709 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 1710 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1711 | path_converter, &path, &argv, &env)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1712 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1713 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1714 | return_value = os_execve_impl(module, &path, argv, env); |
| 1715 | |
| 1716 | exit: |
| 1717 | /* Cleanup for path */ |
| 1718 | path_cleanup(&path); |
| 1719 | |
| 1720 | return return_value; |
| 1721 | } |
| 1722 | |
| 1723 | #endif /* defined(HAVE_EXECV) */ |
| 1724 | |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1725 | #if defined(HAVE_POSIX_SPAWN) |
| 1726 | |
| 1727 | PyDoc_STRVAR(os_posix_spawn__doc__, |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 1728 | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1729 | " setpgroup=None, resetids=False, setsigmask=(),\n" |
| 1730 | " setsigdef=(), scheduler=None)\n" |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1731 | "--\n" |
| 1732 | "\n" |
| 1733 | "Execute the program specified by path in a new process.\n" |
| 1734 | "\n" |
| 1735 | " path\n" |
| 1736 | " Path of executable file.\n" |
| 1737 | " argv\n" |
| 1738 | " Tuple or list of strings.\n" |
| 1739 | " env\n" |
| 1740 | " Dictionary of strings mapping to strings.\n" |
| 1741 | " file_actions\n" |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1742 | " A sequence of file action tuples.\n" |
| 1743 | " setpgroup\n" |
| 1744 | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
| 1745 | " resetids\n" |
| 1746 | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
| 1747 | " setsigmask\n" |
| 1748 | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
| 1749 | " setsigdef\n" |
| 1750 | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
| 1751 | " scheduler\n" |
| 1752 | " A tuple with the scheduler policy (optional) and parameters."); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1753 | |
| 1754 | #define OS_POSIX_SPAWN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1755 | {"posix_spawn", (PyCFunction)(void(*)(void))os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__}, |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1756 | |
| 1757 | static PyObject * |
| 1758 | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1759 | PyObject *env, PyObject *file_actions, |
| 1760 | PyObject *setpgroup, int resetids, PyObject *setsigmask, |
| 1761 | PyObject *setsigdef, PyObject *scheduler); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1762 | |
| 1763 | static PyObject * |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1764 | os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1765 | { |
| 1766 | PyObject *return_value = NULL; |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 1767 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL}; |
| 1768 | static _PyArg_Parser _parser = {"O&OO|$OOiOOO:posix_spawn", _keywords, 0}; |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1769 | path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0); |
| 1770 | PyObject *argv; |
| 1771 | PyObject *env; |
Serhiy Storchaka | d700f97 | 2018-09-08 14:48:18 +0300 | [diff] [blame] | 1772 | PyObject *file_actions = NULL; |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1773 | PyObject *setpgroup = NULL; |
| 1774 | int resetids = 0; |
| 1775 | PyObject *setsigmask = NULL; |
| 1776 | PyObject *setsigdef = NULL; |
| 1777 | PyObject *scheduler = NULL; |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1778 | |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1779 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 1780 | path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsigmask, &setsigdef, &scheduler)) { |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1781 | goto exit; |
| 1782 | } |
Pablo Galindo | 254a466 | 2018-09-07 16:44:24 +0100 | [diff] [blame] | 1783 | return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsigmask, setsigdef, scheduler); |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 1784 | |
| 1785 | exit: |
| 1786 | /* Cleanup for path */ |
| 1787 | path_cleanup(&path); |
| 1788 | |
| 1789 | return return_value; |
| 1790 | } |
| 1791 | |
| 1792 | #endif /* defined(HAVE_POSIX_SPAWN) */ |
| 1793 | |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 1794 | #if defined(HAVE_POSIX_SPAWNP) |
| 1795 | |
| 1796 | PyDoc_STRVAR(os_posix_spawnp__doc__, |
| 1797 | "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n" |
| 1798 | " setpgroup=None, resetids=False, setsigmask=(),\n" |
| 1799 | " setsigdef=(), scheduler=None)\n" |
| 1800 | "--\n" |
| 1801 | "\n" |
| 1802 | "Execute the program specified by path in a new process.\n" |
| 1803 | "\n" |
| 1804 | " path\n" |
| 1805 | " Path of executable file.\n" |
| 1806 | " argv\n" |
| 1807 | " Tuple or list of strings.\n" |
| 1808 | " env\n" |
| 1809 | " Dictionary of strings mapping to strings.\n" |
| 1810 | " file_actions\n" |
| 1811 | " A sequence of file action tuples.\n" |
| 1812 | " setpgroup\n" |
| 1813 | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
| 1814 | " resetids\n" |
| 1815 | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
| 1816 | " setsigmask\n" |
| 1817 | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
| 1818 | " setsigdef\n" |
| 1819 | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
| 1820 | " scheduler\n" |
| 1821 | " A tuple with the scheduler policy (optional) and parameters."); |
| 1822 | |
| 1823 | #define OS_POSIX_SPAWNP_METHODDEF \ |
| 1824 | {"posix_spawnp", (PyCFunction)(void(*)(void))os_posix_spawnp, METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__}, |
| 1825 | |
| 1826 | static PyObject * |
| 1827 | os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv, |
| 1828 | PyObject *env, PyObject *file_actions, |
| 1829 | PyObject *setpgroup, int resetids, PyObject *setsigmask, |
| 1830 | PyObject *setsigdef, PyObject *scheduler); |
| 1831 | |
| 1832 | static PyObject * |
| 1833 | os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1834 | { |
| 1835 | PyObject *return_value = NULL; |
| 1836 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL}; |
| 1837 | static _PyArg_Parser _parser = {"O&OO|$OOiOOO:posix_spawnp", _keywords, 0}; |
| 1838 | path_t path = PATH_T_INITIALIZE("posix_spawnp", "path", 0, 0); |
| 1839 | PyObject *argv; |
| 1840 | PyObject *env; |
| 1841 | PyObject *file_actions = NULL; |
| 1842 | PyObject *setpgroup = NULL; |
| 1843 | int resetids = 0; |
| 1844 | PyObject *setsigmask = NULL; |
| 1845 | PyObject *setsigdef = NULL; |
| 1846 | PyObject *scheduler = NULL; |
| 1847 | |
| 1848 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 1849 | path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsigmask, &setsigdef, &scheduler)) { |
| 1850 | goto exit; |
| 1851 | } |
| 1852 | return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsigmask, setsigdef, scheduler); |
| 1853 | |
| 1854 | exit: |
| 1855 | /* Cleanup for path */ |
| 1856 | path_cleanup(&path); |
| 1857 | |
| 1858 | return return_value; |
| 1859 | } |
| 1860 | |
| 1861 | #endif /* defined(HAVE_POSIX_SPAWNP) */ |
| 1862 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1863 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1864 | |
| 1865 | PyDoc_STRVAR(os_spawnv__doc__, |
| 1866 | "spawnv($module, mode, path, argv, /)\n" |
| 1867 | "--\n" |
| 1868 | "\n" |
| 1869 | "Execute the program specified by path in a new process.\n" |
| 1870 | "\n" |
| 1871 | " mode\n" |
| 1872 | " Mode of process creation.\n" |
| 1873 | " path\n" |
| 1874 | " Path of executable file.\n" |
| 1875 | " argv\n" |
| 1876 | " Tuple or list of strings."); |
| 1877 | |
| 1878 | #define OS_SPAWNV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1879 | {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1880 | |
| 1881 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1882 | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1883 | |
| 1884 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1885 | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1886 | { |
| 1887 | PyObject *return_value = NULL; |
| 1888 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1889 | path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1890 | PyObject *argv; |
| 1891 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1892 | if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1893 | goto exit; |
| 1894 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1895 | if (PyFloat_Check(args[0])) { |
| 1896 | PyErr_SetString(PyExc_TypeError, |
| 1897 | "integer argument expected, got float" ); |
| 1898 | goto exit; |
| 1899 | } |
| 1900 | mode = _PyLong_AsInt(args[0]); |
| 1901 | if (mode == -1 && PyErr_Occurred()) { |
| 1902 | goto exit; |
| 1903 | } |
| 1904 | if (!path_converter(args[1], &path)) { |
| 1905 | goto exit; |
| 1906 | } |
| 1907 | argv = args[2]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1908 | return_value = os_spawnv_impl(module, mode, &path, argv); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1909 | |
| 1910 | exit: |
| 1911 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1912 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1913 | |
| 1914 | return return_value; |
| 1915 | } |
| 1916 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1917 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1918 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1919 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1920 | |
| 1921 | PyDoc_STRVAR(os_spawnve__doc__, |
| 1922 | "spawnve($module, mode, path, argv, env, /)\n" |
| 1923 | "--\n" |
| 1924 | "\n" |
| 1925 | "Execute the program specified by path in a new process.\n" |
| 1926 | "\n" |
| 1927 | " mode\n" |
| 1928 | " Mode of process creation.\n" |
| 1929 | " path\n" |
| 1930 | " Path of executable file.\n" |
| 1931 | " argv\n" |
| 1932 | " Tuple or list of strings.\n" |
| 1933 | " env\n" |
| 1934 | " Dictionary of strings mapping to strings."); |
| 1935 | |
| 1936 | #define OS_SPAWNVE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1937 | {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1938 | |
| 1939 | static PyObject * |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1940 | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1941 | PyObject *env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1942 | |
| 1943 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1944 | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1945 | { |
| 1946 | PyObject *return_value = NULL; |
| 1947 | int mode; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1948 | path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1949 | PyObject *argv; |
| 1950 | PyObject *env; |
| 1951 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1952 | if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1953 | goto exit; |
| 1954 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1955 | if (PyFloat_Check(args[0])) { |
| 1956 | PyErr_SetString(PyExc_TypeError, |
| 1957 | "integer argument expected, got float" ); |
| 1958 | goto exit; |
| 1959 | } |
| 1960 | mode = _PyLong_AsInt(args[0]); |
| 1961 | if (mode == -1 && PyErr_Occurred()) { |
| 1962 | goto exit; |
| 1963 | } |
| 1964 | if (!path_converter(args[1], &path)) { |
| 1965 | goto exit; |
| 1966 | } |
| 1967 | argv = args[2]; |
| 1968 | env = args[3]; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1969 | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1970 | |
| 1971 | exit: |
| 1972 | /* Cleanup for path */ |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1973 | path_cleanup(&path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1974 | |
| 1975 | return return_value; |
| 1976 | } |
| 1977 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 1978 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1979 | |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1980 | #if defined(HAVE_FORK) |
| 1981 | |
| 1982 | PyDoc_STRVAR(os_register_at_fork__doc__, |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1983 | "register_at_fork($module, /, *, before=None, after_in_child=None,\n" |
| 1984 | " after_in_parent=None)\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1985 | "--\n" |
| 1986 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1987 | "Register callables to be called when forking a new process.\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1988 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1989 | " before\n" |
| 1990 | " A callable to be called in the parent before the fork() syscall.\n" |
| 1991 | " after_in_child\n" |
| 1992 | " A callable to be called in the child after fork().\n" |
| 1993 | " after_in_parent\n" |
| 1994 | " A callable to be called in the parent after fork().\n" |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1995 | "\n" |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 1996 | "\'before\' callbacks are called in reverse order.\n" |
| 1997 | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order."); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 1998 | |
| 1999 | #define OS_REGISTER_AT_FORK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2000 | {"register_at_fork", (PyCFunction)(void(*)(void))os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__}, |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2001 | |
| 2002 | static PyObject * |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2003 | os_register_at_fork_impl(PyObject *module, PyObject *before, |
| 2004 | PyObject *after_in_child, PyObject *after_in_parent); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2005 | |
| 2006 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2007 | os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2008 | { |
| 2009 | PyObject *return_value = NULL; |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2010 | static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL}; |
| 2011 | static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0}; |
| 2012 | PyObject *before = NULL; |
| 2013 | PyObject *after_in_child = NULL; |
| 2014 | PyObject *after_in_parent = NULL; |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2015 | |
| 2016 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2017 | &before, &after_in_child, &after_in_parent)) { |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2018 | goto exit; |
| 2019 | } |
Gregory P. Smith | 163468a | 2017-05-29 10:03:41 -0700 | [diff] [blame] | 2020 | return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent); |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 2021 | |
| 2022 | exit: |
| 2023 | return return_value; |
| 2024 | } |
| 2025 | |
| 2026 | #endif /* defined(HAVE_FORK) */ |
| 2027 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2028 | #if defined(HAVE_FORK1) |
| 2029 | |
| 2030 | PyDoc_STRVAR(os_fork1__doc__, |
| 2031 | "fork1($module, /)\n" |
| 2032 | "--\n" |
| 2033 | "\n" |
| 2034 | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
| 2035 | "\n" |
| 2036 | "Return 0 to child process and PID of child to parent process."); |
| 2037 | |
| 2038 | #define OS_FORK1_METHODDEF \ |
| 2039 | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
| 2040 | |
| 2041 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2042 | os_fork1_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2043 | |
| 2044 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2045 | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2046 | { |
| 2047 | return os_fork1_impl(module); |
| 2048 | } |
| 2049 | |
| 2050 | #endif /* defined(HAVE_FORK1) */ |
| 2051 | |
| 2052 | #if defined(HAVE_FORK) |
| 2053 | |
| 2054 | PyDoc_STRVAR(os_fork__doc__, |
| 2055 | "fork($module, /)\n" |
| 2056 | "--\n" |
| 2057 | "\n" |
| 2058 | "Fork a child process.\n" |
| 2059 | "\n" |
| 2060 | "Return 0 to child process and PID of child to parent process."); |
| 2061 | |
| 2062 | #define OS_FORK_METHODDEF \ |
| 2063 | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
| 2064 | |
| 2065 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2066 | os_fork_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2067 | |
| 2068 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2069 | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2070 | { |
| 2071 | return os_fork_impl(module); |
| 2072 | } |
| 2073 | |
| 2074 | #endif /* defined(HAVE_FORK) */ |
| 2075 | |
| 2076 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 2077 | |
| 2078 | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
| 2079 | "sched_get_priority_max($module, /, policy)\n" |
| 2080 | "--\n" |
| 2081 | "\n" |
| 2082 | "Get the maximum scheduling priority for policy."); |
| 2083 | |
| 2084 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2085 | {"sched_get_priority_max", (PyCFunction)(void(*)(void))os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2086 | |
| 2087 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2088 | os_sched_get_priority_max_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2089 | |
| 2090 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2091 | os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2092 | { |
| 2093 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2094 | static const char * const _keywords[] = {"policy", NULL}; |
| 2095 | static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2096 | int policy; |
| 2097 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 2098 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2099 | &policy)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2100 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2101 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2102 | return_value = os_sched_get_priority_max_impl(module, policy); |
| 2103 | |
| 2104 | exit: |
| 2105 | return return_value; |
| 2106 | } |
| 2107 | |
| 2108 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 2109 | |
| 2110 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
| 2111 | |
| 2112 | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
| 2113 | "sched_get_priority_min($module, /, policy)\n" |
| 2114 | "--\n" |
| 2115 | "\n" |
| 2116 | "Get the minimum scheduling priority for policy."); |
| 2117 | |
| 2118 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2119 | {"sched_get_priority_min", (PyCFunction)(void(*)(void))os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2120 | |
| 2121 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2122 | os_sched_get_priority_min_impl(PyObject *module, int policy); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2123 | |
| 2124 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2125 | os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2126 | { |
| 2127 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2128 | static const char * const _keywords[] = {"policy", NULL}; |
| 2129 | static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2130 | int policy; |
| 2131 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 2132 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2133 | &policy)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2134 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2135 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2136 | return_value = os_sched_get_priority_min_impl(module, policy); |
| 2137 | |
| 2138 | exit: |
| 2139 | return return_value; |
| 2140 | } |
| 2141 | |
| 2142 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
| 2143 | |
| 2144 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 2145 | |
| 2146 | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
| 2147 | "sched_getscheduler($module, pid, /)\n" |
| 2148 | "--\n" |
| 2149 | "\n" |
| 2150 | "Get the scheduling policy for the process identifiedy by pid.\n" |
| 2151 | "\n" |
| 2152 | "Passing 0 for pid returns the scheduling policy for the calling process."); |
| 2153 | |
| 2154 | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2155 | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2156 | |
| 2157 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2158 | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
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_getscheduler(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2162 | { |
| 2163 | PyObject *return_value = NULL; |
| 2164 | pid_t pid; |
| 2165 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2166 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2167 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2168 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2169 | return_value = os_sched_getscheduler_impl(module, pid); |
| 2170 | |
| 2171 | exit: |
| 2172 | return return_value; |
| 2173 | } |
| 2174 | |
| 2175 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 2176 | |
William Orr | 81574b8 | 2018-10-01 22:19:56 -0700 | [diff] [blame] | 2177 | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2178 | |
| 2179 | PyDoc_STRVAR(os_sched_param__doc__, |
| 2180 | "sched_param(sched_priority)\n" |
| 2181 | "--\n" |
| 2182 | "\n" |
| 2183 | "Current has only one field: sched_priority\");\n" |
| 2184 | "\n" |
| 2185 | " sched_priority\n" |
| 2186 | " A scheduling parameter."); |
| 2187 | |
| 2188 | static PyObject * |
| 2189 | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
| 2190 | |
| 2191 | static PyObject * |
| 2192 | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 2193 | { |
| 2194 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2195 | static const char * const _keywords[] = {"sched_priority", NULL}; |
| 2196 | static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2197 | PyObject *sched_priority; |
| 2198 | |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2199 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2200 | &sched_priority)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2201 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2202 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2203 | return_value = os_sched_param_impl(type, sched_priority); |
| 2204 | |
| 2205 | exit: |
| 2206 | return return_value; |
| 2207 | } |
| 2208 | |
William Orr | 81574b8 | 2018-10-01 22:19:56 -0700 | [diff] [blame] | 2209 | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2210 | |
| 2211 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
| 2212 | |
| 2213 | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
| 2214 | "sched_setscheduler($module, pid, policy, param, /)\n" |
| 2215 | "--\n" |
| 2216 | "\n" |
| 2217 | "Set the scheduling policy for the process identified by pid.\n" |
| 2218 | "\n" |
| 2219 | "If pid is 0, the calling process is changed.\n" |
| 2220 | "param is an instance of sched_param."); |
| 2221 | |
| 2222 | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2223 | {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2224 | |
| 2225 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2226 | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2227 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2228 | |
| 2229 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2230 | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2231 | { |
| 2232 | PyObject *return_value = NULL; |
| 2233 | pid_t pid; |
| 2234 | int policy; |
| 2235 | struct sched_param param; |
| 2236 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2237 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler", |
| 2238 | &pid, &policy, convert_sched_param, ¶m)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2239 | goto exit; |
| 2240 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2241 | return_value = os_sched_setscheduler_impl(module, pid, policy, ¶m); |
| 2242 | |
| 2243 | exit: |
| 2244 | return return_value; |
| 2245 | } |
| 2246 | |
| 2247 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
| 2248 | |
| 2249 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2250 | |
| 2251 | PyDoc_STRVAR(os_sched_getparam__doc__, |
| 2252 | "sched_getparam($module, pid, /)\n" |
| 2253 | "--\n" |
| 2254 | "\n" |
| 2255 | "Returns scheduling parameters for the process identified by pid.\n" |
| 2256 | "\n" |
| 2257 | "If pid is 0, returns parameters for the calling process.\n" |
| 2258 | "Return value is an instance of sched_param."); |
| 2259 | |
| 2260 | #define OS_SCHED_GETPARAM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2261 | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2262 | |
| 2263 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2264 | os_sched_getparam_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2265 | |
| 2266 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2267 | os_sched_getparam(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2268 | { |
| 2269 | PyObject *return_value = NULL; |
| 2270 | pid_t pid; |
| 2271 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2272 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2273 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2274 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2275 | return_value = os_sched_getparam_impl(module, pid); |
| 2276 | |
| 2277 | exit: |
| 2278 | return return_value; |
| 2279 | } |
| 2280 | |
| 2281 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2282 | |
| 2283 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
| 2284 | |
| 2285 | PyDoc_STRVAR(os_sched_setparam__doc__, |
| 2286 | "sched_setparam($module, pid, param, /)\n" |
| 2287 | "--\n" |
| 2288 | "\n" |
| 2289 | "Set scheduling parameters for the process identified by pid.\n" |
| 2290 | "\n" |
| 2291 | "If pid is 0, sets parameters for the calling process.\n" |
| 2292 | "param should be an instance of sched_param."); |
| 2293 | |
| 2294 | #define OS_SCHED_SETPARAM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2295 | {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2296 | |
| 2297 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2298 | os_sched_setparam_impl(PyObject *module, pid_t pid, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 2299 | struct sched_param *param); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2300 | |
| 2301 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2302 | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2303 | { |
| 2304 | PyObject *return_value = NULL; |
| 2305 | pid_t pid; |
| 2306 | struct sched_param param; |
| 2307 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2308 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam", |
| 2309 | &pid, convert_sched_param, ¶m)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2310 | goto exit; |
| 2311 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2312 | return_value = os_sched_setparam_impl(module, pid, ¶m); |
| 2313 | |
| 2314 | exit: |
| 2315 | return return_value; |
| 2316 | } |
| 2317 | |
| 2318 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
| 2319 | |
| 2320 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
| 2321 | |
| 2322 | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
| 2323 | "sched_rr_get_interval($module, pid, /)\n" |
| 2324 | "--\n" |
| 2325 | "\n" |
| 2326 | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
| 2327 | "\n" |
| 2328 | "Value returned is a float."); |
| 2329 | |
| 2330 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2331 | {"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] | 2332 | |
| 2333 | static double |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2334 | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2335 | |
| 2336 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2337 | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2338 | { |
| 2339 | PyObject *return_value = NULL; |
| 2340 | pid_t pid; |
| 2341 | double _return_value; |
| 2342 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2343 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2344 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2345 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2346 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2347 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2348 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2349 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2350 | return_value = PyFloat_FromDouble(_return_value); |
| 2351 | |
| 2352 | exit: |
| 2353 | return return_value; |
| 2354 | } |
| 2355 | |
| 2356 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
| 2357 | |
| 2358 | #if defined(HAVE_SCHED_H) |
| 2359 | |
| 2360 | PyDoc_STRVAR(os_sched_yield__doc__, |
| 2361 | "sched_yield($module, /)\n" |
| 2362 | "--\n" |
| 2363 | "\n" |
| 2364 | "Voluntarily relinquish the CPU."); |
| 2365 | |
| 2366 | #define OS_SCHED_YIELD_METHODDEF \ |
| 2367 | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
| 2368 | |
| 2369 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2370 | os_sched_yield_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2371 | |
| 2372 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2373 | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2374 | { |
| 2375 | return os_sched_yield_impl(module); |
| 2376 | } |
| 2377 | |
| 2378 | #endif /* defined(HAVE_SCHED_H) */ |
| 2379 | |
| 2380 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 2381 | |
| 2382 | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
| 2383 | "sched_setaffinity($module, pid, mask, /)\n" |
| 2384 | "--\n" |
| 2385 | "\n" |
| 2386 | "Set the CPU affinity of the process identified by pid to mask.\n" |
| 2387 | "\n" |
| 2388 | "mask should be an iterable of integers identifying CPUs."); |
| 2389 | |
| 2390 | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2391 | {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2392 | |
| 2393 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2394 | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2395 | |
| 2396 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2397 | os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2398 | { |
| 2399 | PyObject *return_value = NULL; |
| 2400 | pid_t pid; |
| 2401 | PyObject *mask; |
| 2402 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2403 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity", |
| 2404 | &pid, &mask)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2405 | goto exit; |
| 2406 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2407 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
| 2408 | |
| 2409 | exit: |
| 2410 | return return_value; |
| 2411 | } |
| 2412 | |
| 2413 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 2414 | |
| 2415 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
| 2416 | |
| 2417 | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
| 2418 | "sched_getaffinity($module, pid, /)\n" |
| 2419 | "--\n" |
| 2420 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 2421 | "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] | 2422 | "\n" |
| 2423 | "The affinity is returned as a set of CPU identifiers."); |
| 2424 | |
| 2425 | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2426 | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2427 | |
| 2428 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2429 | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2430 | |
| 2431 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2432 | os_sched_getaffinity(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2433 | { |
| 2434 | PyObject *return_value = NULL; |
| 2435 | pid_t pid; |
| 2436 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2437 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2438 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2439 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2440 | return_value = os_sched_getaffinity_impl(module, pid); |
| 2441 | |
| 2442 | exit: |
| 2443 | return return_value; |
| 2444 | } |
| 2445 | |
| 2446 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
| 2447 | |
| 2448 | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
| 2449 | |
| 2450 | PyDoc_STRVAR(os_openpty__doc__, |
| 2451 | "openpty($module, /)\n" |
| 2452 | "--\n" |
| 2453 | "\n" |
| 2454 | "Open a pseudo-terminal.\n" |
| 2455 | "\n" |
| 2456 | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
| 2457 | "for both the master and slave ends."); |
| 2458 | |
| 2459 | #define OS_OPENPTY_METHODDEF \ |
| 2460 | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
| 2461 | |
| 2462 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2463 | os_openpty_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2464 | |
| 2465 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2466 | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2467 | { |
| 2468 | return os_openpty_impl(module); |
| 2469 | } |
| 2470 | |
| 2471 | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
| 2472 | |
| 2473 | #if defined(HAVE_FORKPTY) |
| 2474 | |
| 2475 | PyDoc_STRVAR(os_forkpty__doc__, |
| 2476 | "forkpty($module, /)\n" |
| 2477 | "--\n" |
| 2478 | "\n" |
| 2479 | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
| 2480 | "\n" |
| 2481 | "Returns a tuple of (pid, master_fd).\n" |
| 2482 | "Like fork(), return pid of 0 to the child process,\n" |
| 2483 | "and pid of child to the parent process.\n" |
| 2484 | "To both, return fd of newly opened pseudo-terminal."); |
| 2485 | |
| 2486 | #define OS_FORKPTY_METHODDEF \ |
| 2487 | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
| 2488 | |
| 2489 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2490 | os_forkpty_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2491 | |
| 2492 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2493 | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2494 | { |
| 2495 | return os_forkpty_impl(module); |
| 2496 | } |
| 2497 | |
| 2498 | #endif /* defined(HAVE_FORKPTY) */ |
| 2499 | |
| 2500 | #if defined(HAVE_GETEGID) |
| 2501 | |
| 2502 | PyDoc_STRVAR(os_getegid__doc__, |
| 2503 | "getegid($module, /)\n" |
| 2504 | "--\n" |
| 2505 | "\n" |
| 2506 | "Return the current process\'s effective group id."); |
| 2507 | |
| 2508 | #define OS_GETEGID_METHODDEF \ |
| 2509 | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
| 2510 | |
| 2511 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2512 | os_getegid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2513 | |
| 2514 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2515 | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2516 | { |
| 2517 | return os_getegid_impl(module); |
| 2518 | } |
| 2519 | |
| 2520 | #endif /* defined(HAVE_GETEGID) */ |
| 2521 | |
| 2522 | #if defined(HAVE_GETEUID) |
| 2523 | |
| 2524 | PyDoc_STRVAR(os_geteuid__doc__, |
| 2525 | "geteuid($module, /)\n" |
| 2526 | "--\n" |
| 2527 | "\n" |
| 2528 | "Return the current process\'s effective user id."); |
| 2529 | |
| 2530 | #define OS_GETEUID_METHODDEF \ |
| 2531 | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
| 2532 | |
| 2533 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2534 | os_geteuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2535 | |
| 2536 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2537 | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2538 | { |
| 2539 | return os_geteuid_impl(module); |
| 2540 | } |
| 2541 | |
| 2542 | #endif /* defined(HAVE_GETEUID) */ |
| 2543 | |
| 2544 | #if defined(HAVE_GETGID) |
| 2545 | |
| 2546 | PyDoc_STRVAR(os_getgid__doc__, |
| 2547 | "getgid($module, /)\n" |
| 2548 | "--\n" |
| 2549 | "\n" |
| 2550 | "Return the current process\'s group id."); |
| 2551 | |
| 2552 | #define OS_GETGID_METHODDEF \ |
| 2553 | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
| 2554 | |
| 2555 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2556 | os_getgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2557 | |
| 2558 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2559 | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2560 | { |
| 2561 | return os_getgid_impl(module); |
| 2562 | } |
| 2563 | |
| 2564 | #endif /* defined(HAVE_GETGID) */ |
| 2565 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 2566 | #if defined(HAVE_GETPID) |
| 2567 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2568 | PyDoc_STRVAR(os_getpid__doc__, |
| 2569 | "getpid($module, /)\n" |
| 2570 | "--\n" |
| 2571 | "\n" |
| 2572 | "Return the current process id."); |
| 2573 | |
| 2574 | #define OS_GETPID_METHODDEF \ |
| 2575 | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
| 2576 | |
| 2577 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2578 | os_getpid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2579 | |
| 2580 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2581 | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2582 | { |
| 2583 | return os_getpid_impl(module); |
| 2584 | } |
| 2585 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 2586 | #endif /* defined(HAVE_GETPID) */ |
| 2587 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2588 | #if defined(HAVE_GETGROUPS) |
| 2589 | |
| 2590 | PyDoc_STRVAR(os_getgroups__doc__, |
| 2591 | "getgroups($module, /)\n" |
| 2592 | "--\n" |
| 2593 | "\n" |
| 2594 | "Return list of supplemental group IDs for the process."); |
| 2595 | |
| 2596 | #define OS_GETGROUPS_METHODDEF \ |
| 2597 | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
| 2598 | |
| 2599 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2600 | os_getgroups_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2601 | |
| 2602 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2603 | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2604 | { |
| 2605 | return os_getgroups_impl(module); |
| 2606 | } |
| 2607 | |
| 2608 | #endif /* defined(HAVE_GETGROUPS) */ |
| 2609 | |
| 2610 | #if defined(HAVE_GETPGID) |
| 2611 | |
| 2612 | PyDoc_STRVAR(os_getpgid__doc__, |
| 2613 | "getpgid($module, /, pid)\n" |
| 2614 | "--\n" |
| 2615 | "\n" |
| 2616 | "Call the system call getpgid(), and return the result."); |
| 2617 | |
| 2618 | #define OS_GETPGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2619 | {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2620 | |
| 2621 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2622 | os_getpgid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2623 | |
| 2624 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2625 | os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2626 | { |
| 2627 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 2628 | static const char * const _keywords[] = {"pid", NULL}; |
| 2629 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2630 | pid_t pid; |
| 2631 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 2632 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2633 | &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2634 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2635 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2636 | return_value = os_getpgid_impl(module, pid); |
| 2637 | |
| 2638 | exit: |
| 2639 | return return_value; |
| 2640 | } |
| 2641 | |
| 2642 | #endif /* defined(HAVE_GETPGID) */ |
| 2643 | |
| 2644 | #if defined(HAVE_GETPGRP) |
| 2645 | |
| 2646 | PyDoc_STRVAR(os_getpgrp__doc__, |
| 2647 | "getpgrp($module, /)\n" |
| 2648 | "--\n" |
| 2649 | "\n" |
| 2650 | "Return the current process group id."); |
| 2651 | |
| 2652 | #define OS_GETPGRP_METHODDEF \ |
| 2653 | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
| 2654 | |
| 2655 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2656 | os_getpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2657 | |
| 2658 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2659 | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2660 | { |
| 2661 | return os_getpgrp_impl(module); |
| 2662 | } |
| 2663 | |
| 2664 | #endif /* defined(HAVE_GETPGRP) */ |
| 2665 | |
| 2666 | #if defined(HAVE_SETPGRP) |
| 2667 | |
| 2668 | PyDoc_STRVAR(os_setpgrp__doc__, |
| 2669 | "setpgrp($module, /)\n" |
| 2670 | "--\n" |
| 2671 | "\n" |
| 2672 | "Make the current process the leader of its process group."); |
| 2673 | |
| 2674 | #define OS_SETPGRP_METHODDEF \ |
| 2675 | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
| 2676 | |
| 2677 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2678 | os_setpgrp_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2679 | |
| 2680 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2681 | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2682 | { |
| 2683 | return os_setpgrp_impl(module); |
| 2684 | } |
| 2685 | |
| 2686 | #endif /* defined(HAVE_SETPGRP) */ |
| 2687 | |
| 2688 | #if defined(HAVE_GETPPID) |
| 2689 | |
| 2690 | PyDoc_STRVAR(os_getppid__doc__, |
| 2691 | "getppid($module, /)\n" |
| 2692 | "--\n" |
| 2693 | "\n" |
| 2694 | "Return the parent\'s process id.\n" |
| 2695 | "\n" |
| 2696 | "If the parent process has already exited, Windows machines will still\n" |
| 2697 | "return its id; others systems will return the id of the \'init\' process (1)."); |
| 2698 | |
| 2699 | #define OS_GETPPID_METHODDEF \ |
| 2700 | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
| 2701 | |
| 2702 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2703 | os_getppid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2704 | |
| 2705 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2706 | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2707 | { |
| 2708 | return os_getppid_impl(module); |
| 2709 | } |
| 2710 | |
| 2711 | #endif /* defined(HAVE_GETPPID) */ |
| 2712 | |
| 2713 | #if defined(HAVE_GETLOGIN) |
| 2714 | |
| 2715 | PyDoc_STRVAR(os_getlogin__doc__, |
| 2716 | "getlogin($module, /)\n" |
| 2717 | "--\n" |
| 2718 | "\n" |
| 2719 | "Return the actual login name."); |
| 2720 | |
| 2721 | #define OS_GETLOGIN_METHODDEF \ |
| 2722 | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
| 2723 | |
| 2724 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2725 | os_getlogin_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2726 | |
| 2727 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2728 | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2729 | { |
| 2730 | return os_getlogin_impl(module); |
| 2731 | } |
| 2732 | |
| 2733 | #endif /* defined(HAVE_GETLOGIN) */ |
| 2734 | |
| 2735 | #if defined(HAVE_GETUID) |
| 2736 | |
| 2737 | PyDoc_STRVAR(os_getuid__doc__, |
| 2738 | "getuid($module, /)\n" |
| 2739 | "--\n" |
| 2740 | "\n" |
| 2741 | "Return the current process\'s user id."); |
| 2742 | |
| 2743 | #define OS_GETUID_METHODDEF \ |
| 2744 | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
| 2745 | |
| 2746 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2747 | os_getuid_impl(PyObject *module); |
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_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2751 | { |
| 2752 | return os_getuid_impl(module); |
| 2753 | } |
| 2754 | |
| 2755 | #endif /* defined(HAVE_GETUID) */ |
| 2756 | |
| 2757 | #if defined(HAVE_KILL) |
| 2758 | |
| 2759 | PyDoc_STRVAR(os_kill__doc__, |
| 2760 | "kill($module, pid, signal, /)\n" |
| 2761 | "--\n" |
| 2762 | "\n" |
| 2763 | "Kill a process with a signal."); |
| 2764 | |
| 2765 | #define OS_KILL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2766 | {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2767 | |
| 2768 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2769 | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2770 | |
| 2771 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2772 | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2773 | { |
| 2774 | PyObject *return_value = NULL; |
| 2775 | pid_t pid; |
| 2776 | Py_ssize_t signal; |
| 2777 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2778 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill", |
| 2779 | &pid, &signal)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2780 | goto exit; |
| 2781 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2782 | return_value = os_kill_impl(module, pid, signal); |
| 2783 | |
| 2784 | exit: |
| 2785 | return return_value; |
| 2786 | } |
| 2787 | |
| 2788 | #endif /* defined(HAVE_KILL) */ |
| 2789 | |
| 2790 | #if defined(HAVE_KILLPG) |
| 2791 | |
| 2792 | PyDoc_STRVAR(os_killpg__doc__, |
| 2793 | "killpg($module, pgid, signal, /)\n" |
| 2794 | "--\n" |
| 2795 | "\n" |
| 2796 | "Kill a process group with a signal."); |
| 2797 | |
| 2798 | #define OS_KILLPG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2799 | {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2800 | |
| 2801 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2802 | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2803 | |
| 2804 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2805 | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2806 | { |
| 2807 | PyObject *return_value = NULL; |
| 2808 | pid_t pgid; |
| 2809 | int signal; |
| 2810 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 2811 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg", |
| 2812 | &pgid, &signal)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2813 | goto exit; |
| 2814 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2815 | return_value = os_killpg_impl(module, pgid, signal); |
| 2816 | |
| 2817 | exit: |
| 2818 | return return_value; |
| 2819 | } |
| 2820 | |
| 2821 | #endif /* defined(HAVE_KILLPG) */ |
| 2822 | |
| 2823 | #if defined(HAVE_PLOCK) |
| 2824 | |
| 2825 | PyDoc_STRVAR(os_plock__doc__, |
| 2826 | "plock($module, op, /)\n" |
| 2827 | "--\n" |
| 2828 | "\n" |
| 2829 | "Lock program segments into memory.\");"); |
| 2830 | |
| 2831 | #define OS_PLOCK_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2832 | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2833 | |
| 2834 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2835 | os_plock_impl(PyObject *module, int op); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2836 | |
| 2837 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2838 | os_plock(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2839 | { |
| 2840 | PyObject *return_value = NULL; |
| 2841 | int op; |
| 2842 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 2843 | if (PyFloat_Check(arg)) { |
| 2844 | PyErr_SetString(PyExc_TypeError, |
| 2845 | "integer argument expected, got float" ); |
| 2846 | goto exit; |
| 2847 | } |
| 2848 | op = _PyLong_AsInt(arg); |
| 2849 | if (op == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2850 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2851 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2852 | return_value = os_plock_impl(module, op); |
| 2853 | |
| 2854 | exit: |
| 2855 | return return_value; |
| 2856 | } |
| 2857 | |
| 2858 | #endif /* defined(HAVE_PLOCK) */ |
| 2859 | |
| 2860 | #if defined(HAVE_SETUID) |
| 2861 | |
| 2862 | PyDoc_STRVAR(os_setuid__doc__, |
| 2863 | "setuid($module, uid, /)\n" |
| 2864 | "--\n" |
| 2865 | "\n" |
| 2866 | "Set the current process\'s user id."); |
| 2867 | |
| 2868 | #define OS_SETUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2869 | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2870 | |
| 2871 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2872 | os_setuid_impl(PyObject *module, uid_t uid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2873 | |
| 2874 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2875 | os_setuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2876 | { |
| 2877 | PyObject *return_value = NULL; |
| 2878 | uid_t uid; |
| 2879 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 2880 | if (!_Py_Uid_Converter(arg, &uid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2881 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2882 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2883 | return_value = os_setuid_impl(module, uid); |
| 2884 | |
| 2885 | exit: |
| 2886 | return return_value; |
| 2887 | } |
| 2888 | |
| 2889 | #endif /* defined(HAVE_SETUID) */ |
| 2890 | |
| 2891 | #if defined(HAVE_SETEUID) |
| 2892 | |
| 2893 | PyDoc_STRVAR(os_seteuid__doc__, |
| 2894 | "seteuid($module, euid, /)\n" |
| 2895 | "--\n" |
| 2896 | "\n" |
| 2897 | "Set the current process\'s effective user id."); |
| 2898 | |
| 2899 | #define OS_SETEUID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2900 | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2901 | |
| 2902 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2903 | os_seteuid_impl(PyObject *module, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2904 | |
| 2905 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2906 | os_seteuid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2907 | { |
| 2908 | PyObject *return_value = NULL; |
| 2909 | uid_t euid; |
| 2910 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 2911 | if (!_Py_Uid_Converter(arg, &euid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2912 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2913 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2914 | return_value = os_seteuid_impl(module, euid); |
| 2915 | |
| 2916 | exit: |
| 2917 | return return_value; |
| 2918 | } |
| 2919 | |
| 2920 | #endif /* defined(HAVE_SETEUID) */ |
| 2921 | |
| 2922 | #if defined(HAVE_SETEGID) |
| 2923 | |
| 2924 | PyDoc_STRVAR(os_setegid__doc__, |
| 2925 | "setegid($module, egid, /)\n" |
| 2926 | "--\n" |
| 2927 | "\n" |
| 2928 | "Set the current process\'s effective group id."); |
| 2929 | |
| 2930 | #define OS_SETEGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 2931 | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2932 | |
| 2933 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2934 | os_setegid_impl(PyObject *module, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2935 | |
| 2936 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2937 | os_setegid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2938 | { |
| 2939 | PyObject *return_value = NULL; |
| 2940 | gid_t egid; |
| 2941 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 2942 | if (!_Py_Gid_Converter(arg, &egid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2943 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 2944 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2945 | return_value = os_setegid_impl(module, egid); |
| 2946 | |
| 2947 | exit: |
| 2948 | return return_value; |
| 2949 | } |
| 2950 | |
| 2951 | #endif /* defined(HAVE_SETEGID) */ |
| 2952 | |
| 2953 | #if defined(HAVE_SETREUID) |
| 2954 | |
| 2955 | PyDoc_STRVAR(os_setreuid__doc__, |
| 2956 | "setreuid($module, ruid, euid, /)\n" |
| 2957 | "--\n" |
| 2958 | "\n" |
| 2959 | "Set the current process\'s real and effective user ids."); |
| 2960 | |
| 2961 | #define OS_SETREUID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 2962 | {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2963 | |
| 2964 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 2965 | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2966 | |
| 2967 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 2968 | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2969 | { |
| 2970 | PyObject *return_value = NULL; |
| 2971 | uid_t ruid; |
| 2972 | uid_t euid; |
| 2973 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 2974 | if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { |
| 2975 | goto exit; |
| 2976 | } |
| 2977 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
| 2978 | goto exit; |
| 2979 | } |
| 2980 | if (!_Py_Uid_Converter(args[1], &euid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 2981 | goto exit; |
| 2982 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 2983 | return_value = os_setreuid_impl(module, ruid, euid); |
| 2984 | |
| 2985 | exit: |
| 2986 | return return_value; |
| 2987 | } |
| 2988 | |
| 2989 | #endif /* defined(HAVE_SETREUID) */ |
| 2990 | |
| 2991 | #if defined(HAVE_SETREGID) |
| 2992 | |
| 2993 | PyDoc_STRVAR(os_setregid__doc__, |
| 2994 | "setregid($module, rgid, egid, /)\n" |
| 2995 | "--\n" |
| 2996 | "\n" |
| 2997 | "Set the current process\'s real and effective group ids."); |
| 2998 | |
| 2999 | #define OS_SETREGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3000 | {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3001 | |
| 3002 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3003 | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3004 | |
| 3005 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3006 | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3007 | { |
| 3008 | PyObject *return_value = NULL; |
| 3009 | gid_t rgid; |
| 3010 | gid_t egid; |
| 3011 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3012 | if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { |
| 3013 | goto exit; |
| 3014 | } |
| 3015 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
| 3016 | goto exit; |
| 3017 | } |
| 3018 | if (!_Py_Gid_Converter(args[1], &egid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3019 | goto exit; |
| 3020 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3021 | return_value = os_setregid_impl(module, rgid, egid); |
| 3022 | |
| 3023 | exit: |
| 3024 | return return_value; |
| 3025 | } |
| 3026 | |
| 3027 | #endif /* defined(HAVE_SETREGID) */ |
| 3028 | |
| 3029 | #if defined(HAVE_SETGID) |
| 3030 | |
| 3031 | PyDoc_STRVAR(os_setgid__doc__, |
| 3032 | "setgid($module, gid, /)\n" |
| 3033 | "--\n" |
| 3034 | "\n" |
| 3035 | "Set the current process\'s group id."); |
| 3036 | |
| 3037 | #define OS_SETGID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3038 | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3039 | |
| 3040 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3041 | os_setgid_impl(PyObject *module, gid_t gid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3042 | |
| 3043 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3044 | os_setgid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3045 | { |
| 3046 | PyObject *return_value = NULL; |
| 3047 | gid_t gid; |
| 3048 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3049 | if (!_Py_Gid_Converter(arg, &gid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3050 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3051 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3052 | return_value = os_setgid_impl(module, gid); |
| 3053 | |
| 3054 | exit: |
| 3055 | return return_value; |
| 3056 | } |
| 3057 | |
| 3058 | #endif /* defined(HAVE_SETGID) */ |
| 3059 | |
| 3060 | #if defined(HAVE_SETGROUPS) |
| 3061 | |
| 3062 | PyDoc_STRVAR(os_setgroups__doc__, |
| 3063 | "setgroups($module, groups, /)\n" |
| 3064 | "--\n" |
| 3065 | "\n" |
| 3066 | "Set the groups of the current process to list."); |
| 3067 | |
| 3068 | #define OS_SETGROUPS_METHODDEF \ |
| 3069 | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
| 3070 | |
| 3071 | #endif /* defined(HAVE_SETGROUPS) */ |
| 3072 | |
| 3073 | #if defined(HAVE_WAIT3) |
| 3074 | |
| 3075 | PyDoc_STRVAR(os_wait3__doc__, |
| 3076 | "wait3($module, /, options)\n" |
| 3077 | "--\n" |
| 3078 | "\n" |
| 3079 | "Wait for completion of a child process.\n" |
| 3080 | "\n" |
| 3081 | "Returns a tuple of information about the child process:\n" |
| 3082 | " (pid, status, rusage)"); |
| 3083 | |
| 3084 | #define OS_WAIT3_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3085 | {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__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_wait3_impl(PyObject *module, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3089 | |
| 3090 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3091 | os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3092 | { |
| 3093 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3094 | static const char * const _keywords[] = {"options", NULL}; |
| 3095 | static _PyArg_Parser _parser = {"i:wait3", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3096 | int options; |
| 3097 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3098 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3099 | &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3100 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3101 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3102 | return_value = os_wait3_impl(module, options); |
| 3103 | |
| 3104 | exit: |
| 3105 | return return_value; |
| 3106 | } |
| 3107 | |
| 3108 | #endif /* defined(HAVE_WAIT3) */ |
| 3109 | |
| 3110 | #if defined(HAVE_WAIT4) |
| 3111 | |
| 3112 | PyDoc_STRVAR(os_wait4__doc__, |
| 3113 | "wait4($module, /, pid, options)\n" |
| 3114 | "--\n" |
| 3115 | "\n" |
| 3116 | "Wait for completion of a specific child process.\n" |
| 3117 | "\n" |
| 3118 | "Returns a tuple of information about the child process:\n" |
| 3119 | " (pid, status, rusage)"); |
| 3120 | |
| 3121 | #define OS_WAIT4_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3122 | {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3123 | |
| 3124 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3125 | os_wait4_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3126 | |
| 3127 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3128 | os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3129 | { |
| 3130 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3131 | static const char * const _keywords[] = {"pid", "options", NULL}; |
| 3132 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3133 | pid_t pid; |
| 3134 | int options; |
| 3135 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3136 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3137 | &pid, &options)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3138 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3139 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3140 | return_value = os_wait4_impl(module, pid, options); |
| 3141 | |
| 3142 | exit: |
| 3143 | return return_value; |
| 3144 | } |
| 3145 | |
| 3146 | #endif /* defined(HAVE_WAIT4) */ |
| 3147 | |
| 3148 | #if (defined(HAVE_WAITID) && !defined(__APPLE__)) |
| 3149 | |
| 3150 | PyDoc_STRVAR(os_waitid__doc__, |
| 3151 | "waitid($module, idtype, id, options, /)\n" |
| 3152 | "--\n" |
| 3153 | "\n" |
| 3154 | "Returns the result of waiting for a process or processes.\n" |
| 3155 | "\n" |
| 3156 | " idtype\n" |
| 3157 | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
| 3158 | " id\n" |
| 3159 | " The id to wait on.\n" |
| 3160 | " options\n" |
| 3161 | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
| 3162 | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
| 3163 | "\n" |
| 3164 | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
| 3165 | "no children in a waitable state."); |
| 3166 | |
| 3167 | #define OS_WAITID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3168 | {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3169 | |
| 3170 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3171 | 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] | 3172 | |
| 3173 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3174 | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3175 | { |
| 3176 | PyObject *return_value = NULL; |
| 3177 | idtype_t idtype; |
| 3178 | id_t id; |
| 3179 | int options; |
| 3180 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3181 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid", |
| 3182 | &idtype, &id, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3183 | goto exit; |
| 3184 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3185 | return_value = os_waitid_impl(module, idtype, id, options); |
| 3186 | |
| 3187 | exit: |
| 3188 | return return_value; |
| 3189 | } |
| 3190 | |
| 3191 | #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */ |
| 3192 | |
| 3193 | #if defined(HAVE_WAITPID) |
| 3194 | |
| 3195 | PyDoc_STRVAR(os_waitpid__doc__, |
| 3196 | "waitpid($module, pid, options, /)\n" |
| 3197 | "--\n" |
| 3198 | "\n" |
| 3199 | "Wait for completion of a given child process.\n" |
| 3200 | "\n" |
| 3201 | "Returns a tuple of information regarding the child process:\n" |
| 3202 | " (pid, status)\n" |
| 3203 | "\n" |
| 3204 | "The options argument is ignored on Windows."); |
| 3205 | |
| 3206 | #define OS_WAITPID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3207 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3208 | |
| 3209 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3210 | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3211 | |
| 3212 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3213 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3214 | { |
| 3215 | PyObject *return_value = NULL; |
| 3216 | pid_t pid; |
| 3217 | int options; |
| 3218 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3219 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid", |
| 3220 | &pid, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3221 | goto exit; |
| 3222 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3223 | return_value = os_waitpid_impl(module, pid, options); |
| 3224 | |
| 3225 | exit: |
| 3226 | return return_value; |
| 3227 | } |
| 3228 | |
| 3229 | #endif /* defined(HAVE_WAITPID) */ |
| 3230 | |
| 3231 | #if defined(HAVE_CWAIT) |
| 3232 | |
| 3233 | PyDoc_STRVAR(os_waitpid__doc__, |
| 3234 | "waitpid($module, pid, options, /)\n" |
| 3235 | "--\n" |
| 3236 | "\n" |
| 3237 | "Wait for completion of a given process.\n" |
| 3238 | "\n" |
| 3239 | "Returns a tuple of information regarding the process:\n" |
| 3240 | " (pid, status << 8)\n" |
| 3241 | "\n" |
| 3242 | "The options argument is ignored on Windows."); |
| 3243 | |
| 3244 | #define OS_WAITPID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3245 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3246 | |
| 3247 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3248 | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3249 | |
| 3250 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3251 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3252 | { |
| 3253 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 3254 | intptr_t pid; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3255 | int options; |
| 3256 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3257 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid", |
| 3258 | &pid, &options)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3259 | goto exit; |
| 3260 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3261 | return_value = os_waitpid_impl(module, pid, options); |
| 3262 | |
| 3263 | exit: |
| 3264 | return return_value; |
| 3265 | } |
| 3266 | |
| 3267 | #endif /* defined(HAVE_CWAIT) */ |
| 3268 | |
| 3269 | #if defined(HAVE_WAIT) |
| 3270 | |
| 3271 | PyDoc_STRVAR(os_wait__doc__, |
| 3272 | "wait($module, /)\n" |
| 3273 | "--\n" |
| 3274 | "\n" |
| 3275 | "Wait for completion of a child process.\n" |
| 3276 | "\n" |
| 3277 | "Returns a tuple of information about the child process:\n" |
| 3278 | " (pid, status)"); |
| 3279 | |
| 3280 | #define OS_WAIT_METHODDEF \ |
| 3281 | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
| 3282 | |
| 3283 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3284 | os_wait_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3285 | |
| 3286 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3287 | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3288 | { |
| 3289 | return os_wait_impl(module); |
| 3290 | } |
| 3291 | |
| 3292 | #endif /* defined(HAVE_WAIT) */ |
| 3293 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 3294 | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
| 3295 | |
| 3296 | PyDoc_STRVAR(os_readlink__doc__, |
| 3297 | "readlink($module, /, path, *, dir_fd=None)\n" |
| 3298 | "--\n" |
| 3299 | "\n" |
| 3300 | "Return a string representing the path to which the symbolic link points.\n" |
| 3301 | "\n" |
| 3302 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3303 | "and path should be relative; path will then be relative to that directory.\n" |
| 3304 | "\n" |
| 3305 | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
| 3306 | "using it will raise a NotImplementedError."); |
| 3307 | |
| 3308 | #define OS_READLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3309 | {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__}, |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 3310 | |
| 3311 | static PyObject * |
| 3312 | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
| 3313 | |
| 3314 | static PyObject * |
| 3315 | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 3316 | { |
| 3317 | PyObject *return_value = NULL; |
| 3318 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
| 3319 | static _PyArg_Parser _parser = {"O&|$O&:readlink", _keywords, 0}; |
| 3320 | path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0); |
| 3321 | int dir_fd = DEFAULT_DIR_FD; |
| 3322 | |
| 3323 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 3324 | path_converter, &path, READLINKAT_DIR_FD_CONVERTER, &dir_fd)) { |
| 3325 | goto exit; |
| 3326 | } |
| 3327 | return_value = os_readlink_impl(module, &path, dir_fd); |
| 3328 | |
| 3329 | exit: |
| 3330 | /* Cleanup for path */ |
| 3331 | path_cleanup(&path); |
| 3332 | |
| 3333 | return return_value; |
| 3334 | } |
| 3335 | |
| 3336 | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
| 3337 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3338 | #if defined(HAVE_SYMLINK) |
| 3339 | |
| 3340 | PyDoc_STRVAR(os_symlink__doc__, |
| 3341 | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
| 3342 | "--\n" |
| 3343 | "\n" |
| 3344 | "Create a symbolic link pointing to src named dst.\n" |
| 3345 | "\n" |
| 3346 | "target_is_directory is required on Windows if the target is to be\n" |
| 3347 | " interpreted as a directory. (On Windows, symlink requires\n" |
| 3348 | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
| 3349 | " target_is_directory is ignored on non-Windows platforms.\n" |
| 3350 | "\n" |
| 3351 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3352 | " and path should be relative; path will then be relative to that directory.\n" |
| 3353 | "dir_fd may not be implemented on your platform.\n" |
| 3354 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3355 | |
| 3356 | #define OS_SYMLINK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3357 | {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3358 | |
| 3359 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3360 | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 3361 | int target_is_directory, int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3362 | |
| 3363 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3364 | os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3365 | { |
| 3366 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3367 | static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
| 3368 | static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3369 | path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0); |
| 3370 | path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0); |
| 3371 | int target_is_directory = 0; |
| 3372 | int dir_fd = DEFAULT_DIR_FD; |
| 3373 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3374 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3375 | 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] | 3376 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3377 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3378 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
| 3379 | |
| 3380 | exit: |
| 3381 | /* Cleanup for src */ |
| 3382 | path_cleanup(&src); |
| 3383 | /* Cleanup for dst */ |
| 3384 | path_cleanup(&dst); |
| 3385 | |
| 3386 | return return_value; |
| 3387 | } |
| 3388 | |
| 3389 | #endif /* defined(HAVE_SYMLINK) */ |
| 3390 | |
| 3391 | #if defined(HAVE_TIMES) |
| 3392 | |
| 3393 | PyDoc_STRVAR(os_times__doc__, |
| 3394 | "times($module, /)\n" |
| 3395 | "--\n" |
| 3396 | "\n" |
| 3397 | "Return a collection containing process timing information.\n" |
| 3398 | "\n" |
| 3399 | "The object returned behaves like a named tuple with these fields:\n" |
| 3400 | " (utime, stime, cutime, cstime, elapsed_time)\n" |
| 3401 | "All fields are floating point numbers."); |
| 3402 | |
| 3403 | #define OS_TIMES_METHODDEF \ |
| 3404 | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
| 3405 | |
| 3406 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3407 | os_times_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3408 | |
| 3409 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3410 | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3411 | { |
| 3412 | return os_times_impl(module); |
| 3413 | } |
| 3414 | |
| 3415 | #endif /* defined(HAVE_TIMES) */ |
| 3416 | |
| 3417 | #if defined(HAVE_GETSID) |
| 3418 | |
| 3419 | PyDoc_STRVAR(os_getsid__doc__, |
| 3420 | "getsid($module, pid, /)\n" |
| 3421 | "--\n" |
| 3422 | "\n" |
| 3423 | "Call the system call getsid(pid) and return the result."); |
| 3424 | |
| 3425 | #define OS_GETSID_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3426 | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3427 | |
| 3428 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3429 | os_getsid_impl(PyObject *module, pid_t pid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3430 | |
| 3431 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3432 | os_getsid(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3433 | { |
| 3434 | PyObject *return_value = NULL; |
| 3435 | pid_t pid; |
| 3436 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3437 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3438 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3439 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3440 | return_value = os_getsid_impl(module, pid); |
| 3441 | |
| 3442 | exit: |
| 3443 | return return_value; |
| 3444 | } |
| 3445 | |
| 3446 | #endif /* defined(HAVE_GETSID) */ |
| 3447 | |
| 3448 | #if defined(HAVE_SETSID) |
| 3449 | |
| 3450 | PyDoc_STRVAR(os_setsid__doc__, |
| 3451 | "setsid($module, /)\n" |
| 3452 | "--\n" |
| 3453 | "\n" |
| 3454 | "Call the system call setsid()."); |
| 3455 | |
| 3456 | #define OS_SETSID_METHODDEF \ |
| 3457 | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
| 3458 | |
| 3459 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3460 | os_setsid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3461 | |
| 3462 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3463 | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3464 | { |
| 3465 | return os_setsid_impl(module); |
| 3466 | } |
| 3467 | |
| 3468 | #endif /* defined(HAVE_SETSID) */ |
| 3469 | |
| 3470 | #if defined(HAVE_SETPGID) |
| 3471 | |
| 3472 | PyDoc_STRVAR(os_setpgid__doc__, |
| 3473 | "setpgid($module, pid, pgrp, /)\n" |
| 3474 | "--\n" |
| 3475 | "\n" |
| 3476 | "Call the system call setpgid(pid, pgrp)."); |
| 3477 | |
| 3478 | #define OS_SETPGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3479 | {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3480 | |
| 3481 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3482 | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3483 | |
| 3484 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3485 | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3486 | { |
| 3487 | PyObject *return_value = NULL; |
| 3488 | pid_t pid; |
| 3489 | pid_t pgrp; |
| 3490 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3491 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid", |
| 3492 | &pid, &pgrp)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3493 | goto exit; |
| 3494 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3495 | return_value = os_setpgid_impl(module, pid, pgrp); |
| 3496 | |
| 3497 | exit: |
| 3498 | return return_value; |
| 3499 | } |
| 3500 | |
| 3501 | #endif /* defined(HAVE_SETPGID) */ |
| 3502 | |
| 3503 | #if defined(HAVE_TCGETPGRP) |
| 3504 | |
| 3505 | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
| 3506 | "tcgetpgrp($module, fd, /)\n" |
| 3507 | "--\n" |
| 3508 | "\n" |
| 3509 | "Return the process group associated with the terminal specified by fd."); |
| 3510 | |
| 3511 | #define OS_TCGETPGRP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3512 | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3513 | |
| 3514 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3515 | os_tcgetpgrp_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3516 | |
| 3517 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3518 | os_tcgetpgrp(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3519 | { |
| 3520 | PyObject *return_value = NULL; |
| 3521 | int fd; |
| 3522 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3523 | if (PyFloat_Check(arg)) { |
| 3524 | PyErr_SetString(PyExc_TypeError, |
| 3525 | "integer argument expected, got float" ); |
| 3526 | goto exit; |
| 3527 | } |
| 3528 | fd = _PyLong_AsInt(arg); |
| 3529 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3530 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3531 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3532 | return_value = os_tcgetpgrp_impl(module, fd); |
| 3533 | |
| 3534 | exit: |
| 3535 | return return_value; |
| 3536 | } |
| 3537 | |
| 3538 | #endif /* defined(HAVE_TCGETPGRP) */ |
| 3539 | |
| 3540 | #if defined(HAVE_TCSETPGRP) |
| 3541 | |
| 3542 | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
| 3543 | "tcsetpgrp($module, fd, pgid, /)\n" |
| 3544 | "--\n" |
| 3545 | "\n" |
| 3546 | "Set the process group associated with the terminal specified by fd."); |
| 3547 | |
| 3548 | #define OS_TCSETPGRP_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3549 | {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3550 | |
| 3551 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3552 | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3553 | |
| 3554 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3555 | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3556 | { |
| 3557 | PyObject *return_value = NULL; |
| 3558 | int fd; |
| 3559 | pid_t pgid; |
| 3560 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 3561 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp", |
| 3562 | &fd, &pgid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3563 | goto exit; |
| 3564 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3565 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
| 3566 | |
| 3567 | exit: |
| 3568 | return return_value; |
| 3569 | } |
| 3570 | |
| 3571 | #endif /* defined(HAVE_TCSETPGRP) */ |
| 3572 | |
| 3573 | PyDoc_STRVAR(os_open__doc__, |
| 3574 | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
| 3575 | "--\n" |
| 3576 | "\n" |
| 3577 | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
| 3578 | "\n" |
| 3579 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 3580 | " and path should be relative; path will then be relative to that directory.\n" |
| 3581 | "dir_fd may not be implemented on your platform.\n" |
| 3582 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 3583 | |
| 3584 | #define OS_OPEN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3585 | {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3586 | |
| 3587 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3588 | 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] | 3589 | |
| 3590 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3591 | os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3592 | { |
| 3593 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3594 | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
| 3595 | static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3596 | path_t path = PATH_T_INITIALIZE("open", "path", 0, 0); |
| 3597 | int flags; |
| 3598 | int mode = 511; |
| 3599 | int dir_fd = DEFAULT_DIR_FD; |
| 3600 | int _return_value; |
| 3601 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3602 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3603 | path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) { |
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_open_impl(module, &path, flags, mode, dir_fd); |
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_FromLong((long)_return_value); |
| 3611 | |
| 3612 | exit: |
| 3613 | /* Cleanup for path */ |
| 3614 | path_cleanup(&path); |
| 3615 | |
| 3616 | return return_value; |
| 3617 | } |
| 3618 | |
| 3619 | PyDoc_STRVAR(os_close__doc__, |
| 3620 | "close($module, /, fd)\n" |
| 3621 | "--\n" |
| 3622 | "\n" |
| 3623 | "Close a file descriptor."); |
| 3624 | |
| 3625 | #define OS_CLOSE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3626 | {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3627 | |
| 3628 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3629 | os_close_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3630 | |
| 3631 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3632 | os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3633 | { |
| 3634 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3635 | static const char * const _keywords[] = {"fd", NULL}; |
| 3636 | static _PyArg_Parser _parser = {"i:close", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3637 | int fd; |
| 3638 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3639 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3640 | &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3641 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3642 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3643 | return_value = os_close_impl(module, fd); |
| 3644 | |
| 3645 | exit: |
| 3646 | return return_value; |
| 3647 | } |
| 3648 | |
| 3649 | PyDoc_STRVAR(os_closerange__doc__, |
| 3650 | "closerange($module, fd_low, fd_high, /)\n" |
| 3651 | "--\n" |
| 3652 | "\n" |
| 3653 | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
| 3654 | |
| 3655 | #define OS_CLOSERANGE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3656 | {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3657 | |
| 3658 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3659 | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3660 | |
| 3661 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3662 | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3663 | { |
| 3664 | PyObject *return_value = NULL; |
| 3665 | int fd_low; |
| 3666 | int fd_high; |
| 3667 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3668 | if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { |
| 3669 | goto exit; |
| 3670 | } |
| 3671 | if (PyFloat_Check(args[0])) { |
| 3672 | PyErr_SetString(PyExc_TypeError, |
| 3673 | "integer argument expected, got float" ); |
| 3674 | goto exit; |
| 3675 | } |
| 3676 | fd_low = _PyLong_AsInt(args[0]); |
| 3677 | if (fd_low == -1 && PyErr_Occurred()) { |
| 3678 | goto exit; |
| 3679 | } |
| 3680 | if (PyFloat_Check(args[1])) { |
| 3681 | PyErr_SetString(PyExc_TypeError, |
| 3682 | "integer argument expected, got float" ); |
| 3683 | goto exit; |
| 3684 | } |
| 3685 | fd_high = _PyLong_AsInt(args[1]); |
| 3686 | if (fd_high == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3687 | goto exit; |
| 3688 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3689 | return_value = os_closerange_impl(module, fd_low, fd_high); |
| 3690 | |
| 3691 | exit: |
| 3692 | return return_value; |
| 3693 | } |
| 3694 | |
| 3695 | PyDoc_STRVAR(os_dup__doc__, |
| 3696 | "dup($module, fd, /)\n" |
| 3697 | "--\n" |
| 3698 | "\n" |
| 3699 | "Return a duplicate of a file descriptor."); |
| 3700 | |
| 3701 | #define OS_DUP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 3702 | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3703 | |
| 3704 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3705 | os_dup_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3706 | |
| 3707 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3708 | os_dup(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3709 | { |
| 3710 | PyObject *return_value = NULL; |
| 3711 | int fd; |
| 3712 | int _return_value; |
| 3713 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 3714 | if (PyFloat_Check(arg)) { |
| 3715 | PyErr_SetString(PyExc_TypeError, |
| 3716 | "integer argument expected, got float" ); |
| 3717 | goto exit; |
| 3718 | } |
| 3719 | fd = _PyLong_AsInt(arg); |
| 3720 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3721 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3722 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3723 | _return_value = os_dup_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3724 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3725 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3726 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3727 | return_value = PyLong_FromLong((long)_return_value); |
| 3728 | |
| 3729 | exit: |
| 3730 | return return_value; |
| 3731 | } |
| 3732 | |
| 3733 | PyDoc_STRVAR(os_dup2__doc__, |
| 3734 | "dup2($module, /, fd, fd2, inheritable=True)\n" |
| 3735 | "--\n" |
| 3736 | "\n" |
| 3737 | "Duplicate file descriptor."); |
| 3738 | |
| 3739 | #define OS_DUP2_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3740 | {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3741 | |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 3742 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3743 | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3744 | |
| 3745 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3746 | os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3747 | { |
| 3748 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 3749 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
| 3750 | static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3751 | int fd; |
| 3752 | int fd2; |
| 3753 | int inheritable = 1; |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 3754 | int _return_value; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3755 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 3756 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3757 | &fd, &fd2, &inheritable)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3758 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3759 | } |
Benjamin Peterson | bbdb17d | 2017-12-29 13:13:06 -0800 | [diff] [blame] | 3760 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
| 3761 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 3762 | goto exit; |
| 3763 | } |
| 3764 | return_value = PyLong_FromLong((long)_return_value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3765 | |
| 3766 | exit: |
| 3767 | return return_value; |
| 3768 | } |
| 3769 | |
| 3770 | #if defined(HAVE_LOCKF) |
| 3771 | |
| 3772 | PyDoc_STRVAR(os_lockf__doc__, |
| 3773 | "lockf($module, fd, command, length, /)\n" |
| 3774 | "--\n" |
| 3775 | "\n" |
| 3776 | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
| 3777 | "\n" |
| 3778 | " fd\n" |
| 3779 | " An open file descriptor.\n" |
| 3780 | " command\n" |
| 3781 | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
| 3782 | " length\n" |
| 3783 | " The number of bytes to lock, starting at the current position."); |
| 3784 | |
| 3785 | #define OS_LOCKF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3786 | {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3787 | |
| 3788 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3789 | 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] | 3790 | |
| 3791 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3792 | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3793 | { |
| 3794 | PyObject *return_value = NULL; |
| 3795 | int fd; |
| 3796 | int command; |
| 3797 | Py_off_t length; |
| 3798 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3799 | if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { |
| 3800 | goto exit; |
| 3801 | } |
| 3802 | if (PyFloat_Check(args[0])) { |
| 3803 | PyErr_SetString(PyExc_TypeError, |
| 3804 | "integer argument expected, got float" ); |
| 3805 | goto exit; |
| 3806 | } |
| 3807 | fd = _PyLong_AsInt(args[0]); |
| 3808 | if (fd == -1 && PyErr_Occurred()) { |
| 3809 | goto exit; |
| 3810 | } |
| 3811 | if (PyFloat_Check(args[1])) { |
| 3812 | PyErr_SetString(PyExc_TypeError, |
| 3813 | "integer argument expected, got float" ); |
| 3814 | goto exit; |
| 3815 | } |
| 3816 | command = _PyLong_AsInt(args[1]); |
| 3817 | if (command == -1 && PyErr_Occurred()) { |
| 3818 | goto exit; |
| 3819 | } |
| 3820 | if (!Py_off_t_converter(args[2], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3821 | goto exit; |
| 3822 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3823 | return_value = os_lockf_impl(module, fd, command, length); |
| 3824 | |
| 3825 | exit: |
| 3826 | return return_value; |
| 3827 | } |
| 3828 | |
| 3829 | #endif /* defined(HAVE_LOCKF) */ |
| 3830 | |
| 3831 | PyDoc_STRVAR(os_lseek__doc__, |
| 3832 | "lseek($module, fd, position, how, /)\n" |
| 3833 | "--\n" |
| 3834 | "\n" |
| 3835 | "Set the position of a file descriptor. Return the new position.\n" |
| 3836 | "\n" |
| 3837 | "Return the new cursor position in number of bytes\n" |
| 3838 | "relative to the beginning of the file."); |
| 3839 | |
| 3840 | #define OS_LSEEK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3841 | {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3842 | |
| 3843 | static Py_off_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3844 | 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] | 3845 | |
| 3846 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3847 | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3848 | { |
| 3849 | PyObject *return_value = NULL; |
| 3850 | int fd; |
| 3851 | Py_off_t position; |
| 3852 | int how; |
| 3853 | Py_off_t _return_value; |
| 3854 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3855 | if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { |
| 3856 | goto exit; |
| 3857 | } |
| 3858 | if (PyFloat_Check(args[0])) { |
| 3859 | PyErr_SetString(PyExc_TypeError, |
| 3860 | "integer argument expected, got float" ); |
| 3861 | goto exit; |
| 3862 | } |
| 3863 | fd = _PyLong_AsInt(args[0]); |
| 3864 | if (fd == -1 && PyErr_Occurred()) { |
| 3865 | goto exit; |
| 3866 | } |
| 3867 | if (!Py_off_t_converter(args[1], &position)) { |
| 3868 | goto exit; |
| 3869 | } |
| 3870 | if (PyFloat_Check(args[2])) { |
| 3871 | PyErr_SetString(PyExc_TypeError, |
| 3872 | "integer argument expected, got float" ); |
| 3873 | goto exit; |
| 3874 | } |
| 3875 | how = _PyLong_AsInt(args[2]); |
| 3876 | if (how == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3877 | goto exit; |
| 3878 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3879 | _return_value = os_lseek_impl(module, fd, position, how); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3880 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3881 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3882 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3883 | return_value = PyLong_FromPy_off_t(_return_value); |
| 3884 | |
| 3885 | exit: |
| 3886 | return return_value; |
| 3887 | } |
| 3888 | |
| 3889 | PyDoc_STRVAR(os_read__doc__, |
| 3890 | "read($module, fd, length, /)\n" |
| 3891 | "--\n" |
| 3892 | "\n" |
| 3893 | "Read from a file descriptor. Returns a bytes object."); |
| 3894 | |
| 3895 | #define OS_READ_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3896 | {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3897 | |
| 3898 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3899 | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3900 | |
| 3901 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3902 | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3903 | { |
| 3904 | PyObject *return_value = NULL; |
| 3905 | int fd; |
| 3906 | Py_ssize_t length; |
| 3907 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3908 | if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3909 | goto exit; |
| 3910 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3911 | if (PyFloat_Check(args[0])) { |
| 3912 | PyErr_SetString(PyExc_TypeError, |
| 3913 | "integer argument expected, got float" ); |
| 3914 | goto exit; |
| 3915 | } |
| 3916 | fd = _PyLong_AsInt(args[0]); |
| 3917 | if (fd == -1 && PyErr_Occurred()) { |
| 3918 | goto exit; |
| 3919 | } |
| 3920 | if (PyFloat_Check(args[1])) { |
| 3921 | PyErr_SetString(PyExc_TypeError, |
| 3922 | "integer argument expected, got float" ); |
| 3923 | goto exit; |
| 3924 | } |
| 3925 | { |
| 3926 | Py_ssize_t ival = -1; |
| 3927 | PyObject *iobj = PyNumber_Index(args[1]); |
| 3928 | if (iobj != NULL) { |
| 3929 | ival = PyLong_AsSsize_t(iobj); |
| 3930 | Py_DECREF(iobj); |
| 3931 | } |
| 3932 | if (ival == -1 && PyErr_Occurred()) { |
| 3933 | goto exit; |
| 3934 | } |
| 3935 | length = ival; |
| 3936 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3937 | return_value = os_read_impl(module, fd, length); |
| 3938 | |
| 3939 | exit: |
| 3940 | return return_value; |
| 3941 | } |
| 3942 | |
| 3943 | #if defined(HAVE_READV) |
| 3944 | |
| 3945 | PyDoc_STRVAR(os_readv__doc__, |
| 3946 | "readv($module, fd, buffers, /)\n" |
| 3947 | "--\n" |
| 3948 | "\n" |
| 3949 | "Read from a file descriptor fd into an iterable of buffers.\n" |
| 3950 | "\n" |
| 3951 | "The buffers should be mutable buffers accepting bytes.\n" |
| 3952 | "readv will transfer data into each buffer until it is full\n" |
| 3953 | "and then move on to the next buffer in the sequence to hold\n" |
| 3954 | "the rest of the data.\n" |
| 3955 | "\n" |
| 3956 | "readv returns the total number of bytes read,\n" |
| 3957 | "which may be less than the total capacity of all the buffers."); |
| 3958 | |
| 3959 | #define OS_READV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 3960 | {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3961 | |
| 3962 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 3963 | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3964 | |
| 3965 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 3966 | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3967 | { |
| 3968 | PyObject *return_value = NULL; |
| 3969 | int fd; |
| 3970 | PyObject *buffers; |
| 3971 | Py_ssize_t _return_value; |
| 3972 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3973 | if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 3974 | goto exit; |
| 3975 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 3976 | if (PyFloat_Check(args[0])) { |
| 3977 | PyErr_SetString(PyExc_TypeError, |
| 3978 | "integer argument expected, got float" ); |
| 3979 | goto exit; |
| 3980 | } |
| 3981 | fd = _PyLong_AsInt(args[0]); |
| 3982 | if (fd == -1 && PyErr_Occurred()) { |
| 3983 | goto exit; |
| 3984 | } |
| 3985 | buffers = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3986 | _return_value = os_readv_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3987 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3988 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 3989 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 3990 | return_value = PyLong_FromSsize_t(_return_value); |
| 3991 | |
| 3992 | exit: |
| 3993 | return return_value; |
| 3994 | } |
| 3995 | |
| 3996 | #endif /* defined(HAVE_READV) */ |
| 3997 | |
| 3998 | #if defined(HAVE_PREAD) |
| 3999 | |
| 4000 | PyDoc_STRVAR(os_pread__doc__, |
| 4001 | "pread($module, fd, length, offset, /)\n" |
| 4002 | "--\n" |
| 4003 | "\n" |
| 4004 | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
| 4005 | "\n" |
| 4006 | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
| 4007 | "the beginning of the file. The file offset remains unchanged."); |
| 4008 | |
| 4009 | #define OS_PREAD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4010 | {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4011 | |
| 4012 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4013 | 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] | 4014 | |
| 4015 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4016 | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4017 | { |
| 4018 | PyObject *return_value = NULL; |
| 4019 | int fd; |
| 4020 | int length; |
| 4021 | Py_off_t offset; |
| 4022 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4023 | if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { |
| 4024 | goto exit; |
| 4025 | } |
| 4026 | if (PyFloat_Check(args[0])) { |
| 4027 | PyErr_SetString(PyExc_TypeError, |
| 4028 | "integer argument expected, got float" ); |
| 4029 | goto exit; |
| 4030 | } |
| 4031 | fd = _PyLong_AsInt(args[0]); |
| 4032 | if (fd == -1 && PyErr_Occurred()) { |
| 4033 | goto exit; |
| 4034 | } |
| 4035 | if (PyFloat_Check(args[1])) { |
| 4036 | PyErr_SetString(PyExc_TypeError, |
| 4037 | "integer argument expected, got float" ); |
| 4038 | goto exit; |
| 4039 | } |
| 4040 | length = _PyLong_AsInt(args[1]); |
| 4041 | if (length == -1 && PyErr_Occurred()) { |
| 4042 | goto exit; |
| 4043 | } |
| 4044 | if (!Py_off_t_converter(args[2], &offset)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4045 | goto exit; |
| 4046 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4047 | return_value = os_pread_impl(module, fd, length, offset); |
| 4048 | |
| 4049 | exit: |
| 4050 | return return_value; |
| 4051 | } |
| 4052 | |
| 4053 | #endif /* defined(HAVE_PREAD) */ |
| 4054 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4055 | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
| 4056 | |
| 4057 | PyDoc_STRVAR(os_preadv__doc__, |
| 4058 | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
| 4059 | "--\n" |
| 4060 | "\n" |
| 4061 | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
| 4062 | "\n" |
| 4063 | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
| 4064 | "transfer data into each buffer until it is full and then move on to the next\n" |
| 4065 | "buffer in the sequence to hold the rest of the data. Its fourth argument,\n" |
| 4066 | "specifies the file offset at which the input operation is to be performed. It\n" |
| 4067 | "will return the total number of bytes read (which can be less than the total\n" |
| 4068 | "capacity of all the objects).\n" |
| 4069 | "\n" |
| 4070 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
| 4071 | "\n" |
| 4072 | "- RWF_HIPRI\n" |
| 4073 | "- RWF_NOWAIT\n" |
| 4074 | "\n" |
| 4075 | "Using non-zero flags requires Linux 4.6 or newer."); |
| 4076 | |
| 4077 | #define OS_PREADV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4078 | {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__}, |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4079 | |
| 4080 | static Py_ssize_t |
| 4081 | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
| 4082 | int flags); |
| 4083 | |
| 4084 | static PyObject * |
| 4085 | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 4086 | { |
| 4087 | PyObject *return_value = NULL; |
| 4088 | int fd; |
| 4089 | PyObject *buffers; |
| 4090 | Py_off_t offset; |
| 4091 | int flags = 0; |
| 4092 | Py_ssize_t _return_value; |
| 4093 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4094 | if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4095 | goto exit; |
| 4096 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4097 | if (PyFloat_Check(args[0])) { |
| 4098 | PyErr_SetString(PyExc_TypeError, |
| 4099 | "integer argument expected, got float" ); |
| 4100 | goto exit; |
| 4101 | } |
| 4102 | fd = _PyLong_AsInt(args[0]); |
| 4103 | if (fd == -1 && PyErr_Occurred()) { |
| 4104 | goto exit; |
| 4105 | } |
| 4106 | buffers = args[1]; |
| 4107 | if (!Py_off_t_converter(args[2], &offset)) { |
| 4108 | goto exit; |
| 4109 | } |
| 4110 | if (nargs < 4) { |
| 4111 | goto skip_optional; |
| 4112 | } |
| 4113 | if (PyFloat_Check(args[3])) { |
| 4114 | PyErr_SetString(PyExc_TypeError, |
| 4115 | "integer argument expected, got float" ); |
| 4116 | goto exit; |
| 4117 | } |
| 4118 | flags = _PyLong_AsInt(args[3]); |
| 4119 | if (flags == -1 && PyErr_Occurred()) { |
| 4120 | goto exit; |
| 4121 | } |
| 4122 | skip_optional: |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4123 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
| 4124 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 4125 | goto exit; |
| 4126 | } |
| 4127 | return_value = PyLong_FromSsize_t(_return_value); |
| 4128 | |
| 4129 | exit: |
| 4130 | return return_value; |
| 4131 | } |
| 4132 | |
| 4133 | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
| 4134 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4135 | PyDoc_STRVAR(os_write__doc__, |
| 4136 | "write($module, fd, data, /)\n" |
| 4137 | "--\n" |
| 4138 | "\n" |
| 4139 | "Write a bytes object to a file descriptor."); |
| 4140 | |
| 4141 | #define OS_WRITE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4142 | {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4143 | |
| 4144 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4145 | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4146 | |
| 4147 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4148 | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4149 | { |
| 4150 | PyObject *return_value = NULL; |
| 4151 | int fd; |
| 4152 | Py_buffer data = {NULL, NULL}; |
| 4153 | Py_ssize_t _return_value; |
| 4154 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4155 | if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { |
| 4156 | goto exit; |
| 4157 | } |
| 4158 | if (PyFloat_Check(args[0])) { |
| 4159 | PyErr_SetString(PyExc_TypeError, |
| 4160 | "integer argument expected, got float" ); |
| 4161 | goto exit; |
| 4162 | } |
| 4163 | fd = _PyLong_AsInt(args[0]); |
| 4164 | if (fd == -1 && PyErr_Occurred()) { |
| 4165 | goto exit; |
| 4166 | } |
| 4167 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
| 4168 | goto exit; |
| 4169 | } |
| 4170 | if (!PyBuffer_IsContiguous(&data, 'C')) { |
| 4171 | _PyArg_BadArgument("write", 2, "contiguous buffer", args[1]); |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4172 | goto exit; |
| 4173 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4174 | _return_value = os_write_impl(module, fd, &data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4175 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4176 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4177 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4178 | return_value = PyLong_FromSsize_t(_return_value); |
| 4179 | |
| 4180 | exit: |
| 4181 | /* Cleanup for data */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4182 | if (data.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4183 | PyBuffer_Release(&data); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4184 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4185 | |
| 4186 | return return_value; |
| 4187 | } |
| 4188 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4189 | #if defined(__APPLE__) |
| 4190 | |
| 4191 | PyDoc_STRVAR(os__fcopyfile__doc__, |
| 4192 | "_fcopyfile($module, infd, outfd, flags, /)\n" |
| 4193 | "--\n" |
| 4194 | "\n" |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 4195 | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4196 | |
| 4197 | #define OS__FCOPYFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4198 | {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__}, |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4199 | |
| 4200 | static PyObject * |
| 4201 | os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags); |
| 4202 | |
| 4203 | static PyObject * |
| 4204 | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 4205 | { |
| 4206 | PyObject *return_value = NULL; |
| 4207 | int infd; |
| 4208 | int outfd; |
| 4209 | int flags; |
| 4210 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4211 | if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { |
| 4212 | goto exit; |
| 4213 | } |
| 4214 | if (PyFloat_Check(args[0])) { |
| 4215 | PyErr_SetString(PyExc_TypeError, |
| 4216 | "integer argument expected, got float" ); |
| 4217 | goto exit; |
| 4218 | } |
| 4219 | infd = _PyLong_AsInt(args[0]); |
| 4220 | if (infd == -1 && PyErr_Occurred()) { |
| 4221 | goto exit; |
| 4222 | } |
| 4223 | if (PyFloat_Check(args[1])) { |
| 4224 | PyErr_SetString(PyExc_TypeError, |
| 4225 | "integer argument expected, got float" ); |
| 4226 | goto exit; |
| 4227 | } |
| 4228 | outfd = _PyLong_AsInt(args[1]); |
| 4229 | if (outfd == -1 && PyErr_Occurred()) { |
| 4230 | goto exit; |
| 4231 | } |
| 4232 | if (PyFloat_Check(args[2])) { |
| 4233 | PyErr_SetString(PyExc_TypeError, |
| 4234 | "integer argument expected, got float" ); |
| 4235 | goto exit; |
| 4236 | } |
| 4237 | flags = _PyLong_AsInt(args[2]); |
| 4238 | if (flags == -1 && PyErr_Occurred()) { |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 4239 | goto exit; |
| 4240 | } |
| 4241 | return_value = os__fcopyfile_impl(module, infd, outfd, flags); |
| 4242 | |
| 4243 | exit: |
| 4244 | return return_value; |
| 4245 | } |
| 4246 | |
| 4247 | #endif /* defined(__APPLE__) */ |
| 4248 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4249 | PyDoc_STRVAR(os_fstat__doc__, |
| 4250 | "fstat($module, /, fd)\n" |
| 4251 | "--\n" |
| 4252 | "\n" |
| 4253 | "Perform a stat system call on the given file descriptor.\n" |
| 4254 | "\n" |
| 4255 | "Like stat(), but for an open file descriptor.\n" |
| 4256 | "Equivalent to os.stat(fd)."); |
| 4257 | |
| 4258 | #define OS_FSTAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4259 | {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4260 | |
| 4261 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4262 | os_fstat_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4263 | |
| 4264 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4265 | os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4266 | { |
| 4267 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4268 | static const char * const _keywords[] = {"fd", NULL}; |
| 4269 | static _PyArg_Parser _parser = {"i:fstat", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4270 | int fd; |
| 4271 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 4272 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4273 | &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4274 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4275 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4276 | return_value = os_fstat_impl(module, fd); |
| 4277 | |
| 4278 | exit: |
| 4279 | return return_value; |
| 4280 | } |
| 4281 | |
| 4282 | PyDoc_STRVAR(os_isatty__doc__, |
| 4283 | "isatty($module, fd, /)\n" |
| 4284 | "--\n" |
| 4285 | "\n" |
| 4286 | "Return True if the fd is connected to a terminal.\n" |
| 4287 | "\n" |
| 4288 | "Return True if the file descriptor is an open file descriptor\n" |
| 4289 | "connected to the slave end of a terminal."); |
| 4290 | |
| 4291 | #define OS_ISATTY_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4292 | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4293 | |
| 4294 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4295 | os_isatty_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4296 | |
| 4297 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4298 | os_isatty(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4299 | { |
| 4300 | PyObject *return_value = NULL; |
| 4301 | int fd; |
| 4302 | int _return_value; |
| 4303 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4304 | if (PyFloat_Check(arg)) { |
| 4305 | PyErr_SetString(PyExc_TypeError, |
| 4306 | "integer argument expected, got float" ); |
| 4307 | goto exit; |
| 4308 | } |
| 4309 | fd = _PyLong_AsInt(arg); |
| 4310 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4311 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4312 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4313 | _return_value = os_isatty_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4314 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4315 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4316 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4317 | return_value = PyBool_FromLong((long)_return_value); |
| 4318 | |
| 4319 | exit: |
| 4320 | return return_value; |
| 4321 | } |
| 4322 | |
| 4323 | #if defined(HAVE_PIPE) |
| 4324 | |
| 4325 | PyDoc_STRVAR(os_pipe__doc__, |
| 4326 | "pipe($module, /)\n" |
| 4327 | "--\n" |
| 4328 | "\n" |
| 4329 | "Create a pipe.\n" |
| 4330 | "\n" |
| 4331 | "Returns a tuple of two file descriptors:\n" |
| 4332 | " (read_fd, write_fd)"); |
| 4333 | |
| 4334 | #define OS_PIPE_METHODDEF \ |
| 4335 | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
| 4336 | |
| 4337 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4338 | os_pipe_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4339 | |
| 4340 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4341 | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4342 | { |
| 4343 | return os_pipe_impl(module); |
| 4344 | } |
| 4345 | |
| 4346 | #endif /* defined(HAVE_PIPE) */ |
| 4347 | |
| 4348 | #if defined(HAVE_PIPE2) |
| 4349 | |
| 4350 | PyDoc_STRVAR(os_pipe2__doc__, |
| 4351 | "pipe2($module, flags, /)\n" |
| 4352 | "--\n" |
| 4353 | "\n" |
| 4354 | "Create a pipe with flags set atomically.\n" |
| 4355 | "\n" |
| 4356 | "Returns a tuple of two file descriptors:\n" |
| 4357 | " (read_fd, write_fd)\n" |
| 4358 | "\n" |
| 4359 | "flags can be constructed by ORing together one or more of these values:\n" |
| 4360 | "O_NONBLOCK, O_CLOEXEC."); |
| 4361 | |
| 4362 | #define OS_PIPE2_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4363 | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4364 | |
| 4365 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4366 | os_pipe2_impl(PyObject *module, int flags); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4367 | |
| 4368 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4369 | os_pipe2(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4370 | { |
| 4371 | PyObject *return_value = NULL; |
| 4372 | int flags; |
| 4373 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4374 | if (PyFloat_Check(arg)) { |
| 4375 | PyErr_SetString(PyExc_TypeError, |
| 4376 | "integer argument expected, got float" ); |
| 4377 | goto exit; |
| 4378 | } |
| 4379 | flags = _PyLong_AsInt(arg); |
| 4380 | if (flags == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4381 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4382 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4383 | return_value = os_pipe2_impl(module, flags); |
| 4384 | |
| 4385 | exit: |
| 4386 | return return_value; |
| 4387 | } |
| 4388 | |
| 4389 | #endif /* defined(HAVE_PIPE2) */ |
| 4390 | |
| 4391 | #if defined(HAVE_WRITEV) |
| 4392 | |
| 4393 | PyDoc_STRVAR(os_writev__doc__, |
| 4394 | "writev($module, fd, buffers, /)\n" |
| 4395 | "--\n" |
| 4396 | "\n" |
| 4397 | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
| 4398 | "\n" |
| 4399 | "Returns the total number of bytes written.\n" |
| 4400 | "buffers must be a sequence of bytes-like objects."); |
| 4401 | |
| 4402 | #define OS_WRITEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4403 | {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4404 | |
| 4405 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4406 | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4407 | |
| 4408 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4409 | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4410 | { |
| 4411 | PyObject *return_value = NULL; |
| 4412 | int fd; |
| 4413 | PyObject *buffers; |
| 4414 | Py_ssize_t _return_value; |
| 4415 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4416 | if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4417 | goto exit; |
| 4418 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4419 | if (PyFloat_Check(args[0])) { |
| 4420 | PyErr_SetString(PyExc_TypeError, |
| 4421 | "integer argument expected, got float" ); |
| 4422 | goto exit; |
| 4423 | } |
| 4424 | fd = _PyLong_AsInt(args[0]); |
| 4425 | if (fd == -1 && PyErr_Occurred()) { |
| 4426 | goto exit; |
| 4427 | } |
| 4428 | buffers = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4429 | _return_value = os_writev_impl(module, fd, buffers); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4430 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4431 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4432 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4433 | return_value = PyLong_FromSsize_t(_return_value); |
| 4434 | |
| 4435 | exit: |
| 4436 | return return_value; |
| 4437 | } |
| 4438 | |
| 4439 | #endif /* defined(HAVE_WRITEV) */ |
| 4440 | |
| 4441 | #if defined(HAVE_PWRITE) |
| 4442 | |
| 4443 | PyDoc_STRVAR(os_pwrite__doc__, |
| 4444 | "pwrite($module, fd, buffer, offset, /)\n" |
| 4445 | "--\n" |
| 4446 | "\n" |
| 4447 | "Write bytes to a file descriptor starting at a particular offset.\n" |
| 4448 | "\n" |
| 4449 | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
| 4450 | "the file. Returns the number of bytes writte. Does not change the\n" |
| 4451 | "current file offset."); |
| 4452 | |
| 4453 | #define OS_PWRITE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4454 | {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4455 | |
| 4456 | static Py_ssize_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4457 | 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] | 4458 | |
| 4459 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4460 | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4461 | { |
| 4462 | PyObject *return_value = NULL; |
| 4463 | int fd; |
| 4464 | Py_buffer buffer = {NULL, NULL}; |
| 4465 | Py_off_t offset; |
| 4466 | Py_ssize_t _return_value; |
| 4467 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4468 | if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { |
| 4469 | goto exit; |
| 4470 | } |
| 4471 | if (PyFloat_Check(args[0])) { |
| 4472 | PyErr_SetString(PyExc_TypeError, |
| 4473 | "integer argument expected, got float" ); |
| 4474 | goto exit; |
| 4475 | } |
| 4476 | fd = _PyLong_AsInt(args[0]); |
| 4477 | if (fd == -1 && PyErr_Occurred()) { |
| 4478 | goto exit; |
| 4479 | } |
| 4480 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
| 4481 | goto exit; |
| 4482 | } |
| 4483 | if (!PyBuffer_IsContiguous(&buffer, 'C')) { |
| 4484 | _PyArg_BadArgument("pwrite", 2, "contiguous buffer", args[1]); |
| 4485 | goto exit; |
| 4486 | } |
| 4487 | if (!Py_off_t_converter(args[2], &offset)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4488 | goto exit; |
| 4489 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4490 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4491 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4492 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4493 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4494 | return_value = PyLong_FromSsize_t(_return_value); |
| 4495 | |
| 4496 | exit: |
| 4497 | /* Cleanup for buffer */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4498 | if (buffer.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4499 | PyBuffer_Release(&buffer); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4500 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4501 | |
| 4502 | return return_value; |
| 4503 | } |
| 4504 | |
| 4505 | #endif /* defined(HAVE_PWRITE) */ |
| 4506 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4507 | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
| 4508 | |
| 4509 | PyDoc_STRVAR(os_pwritev__doc__, |
| 4510 | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
| 4511 | "--\n" |
| 4512 | "\n" |
| 4513 | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
| 4514 | "\n" |
| 4515 | "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n" |
| 4516 | "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n" |
| 4517 | "buffer is written before proceeding to second, and so on. The operating system may\n" |
| 4518 | "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n" |
| 4519 | "This function writes the contents of each object to the file descriptor and returns\n" |
| 4520 | "the total number of bytes written.\n" |
| 4521 | "\n" |
| 4522 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
| 4523 | "\n" |
| 4524 | "- RWF_DSYNC\n" |
| 4525 | "- RWF_SYNC\n" |
| 4526 | "\n" |
| 4527 | "Using non-zero flags requires Linux 4.7 or newer."); |
| 4528 | |
| 4529 | #define OS_PWRITEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4530 | {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__}, |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4531 | |
| 4532 | static Py_ssize_t |
| 4533 | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
| 4534 | int flags); |
| 4535 | |
| 4536 | static PyObject * |
| 4537 | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 4538 | { |
| 4539 | PyObject *return_value = NULL; |
| 4540 | int fd; |
| 4541 | PyObject *buffers; |
| 4542 | Py_off_t offset; |
| 4543 | int flags = 0; |
| 4544 | Py_ssize_t _return_value; |
| 4545 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4546 | if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4547 | goto exit; |
| 4548 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4549 | if (PyFloat_Check(args[0])) { |
| 4550 | PyErr_SetString(PyExc_TypeError, |
| 4551 | "integer argument expected, got float" ); |
| 4552 | goto exit; |
| 4553 | } |
| 4554 | fd = _PyLong_AsInt(args[0]); |
| 4555 | if (fd == -1 && PyErr_Occurred()) { |
| 4556 | goto exit; |
| 4557 | } |
| 4558 | buffers = args[1]; |
| 4559 | if (!Py_off_t_converter(args[2], &offset)) { |
| 4560 | goto exit; |
| 4561 | } |
| 4562 | if (nargs < 4) { |
| 4563 | goto skip_optional; |
| 4564 | } |
| 4565 | if (PyFloat_Check(args[3])) { |
| 4566 | PyErr_SetString(PyExc_TypeError, |
| 4567 | "integer argument expected, got float" ); |
| 4568 | goto exit; |
| 4569 | } |
| 4570 | flags = _PyLong_AsInt(args[3]); |
| 4571 | if (flags == -1 && PyErr_Occurred()) { |
| 4572 | goto exit; |
| 4573 | } |
| 4574 | skip_optional: |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 4575 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
| 4576 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 4577 | goto exit; |
| 4578 | } |
| 4579 | return_value = PyLong_FromSsize_t(_return_value); |
| 4580 | |
| 4581 | exit: |
| 4582 | return return_value; |
| 4583 | } |
| 4584 | |
| 4585 | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
| 4586 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4587 | #if defined(HAVE_MKFIFO) |
| 4588 | |
| 4589 | PyDoc_STRVAR(os_mkfifo__doc__, |
| 4590 | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
| 4591 | "--\n" |
| 4592 | "\n" |
| 4593 | "Create a \"fifo\" (a POSIX named pipe).\n" |
| 4594 | "\n" |
| 4595 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 4596 | " and path should be relative; path will then be relative to that directory.\n" |
| 4597 | "dir_fd may not be implemented on your platform.\n" |
| 4598 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 4599 | |
| 4600 | #define OS_MKFIFO_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4601 | {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4602 | |
| 4603 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4604 | 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] | 4605 | |
| 4606 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4607 | os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4608 | { |
| 4609 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4610 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
| 4611 | static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4612 | path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0); |
| 4613 | int mode = 438; |
| 4614 | int dir_fd = DEFAULT_DIR_FD; |
| 4615 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 4616 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4617 | path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4618 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4619 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4620 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
| 4621 | |
| 4622 | exit: |
| 4623 | /* Cleanup for path */ |
| 4624 | path_cleanup(&path); |
| 4625 | |
| 4626 | return return_value; |
| 4627 | } |
| 4628 | |
| 4629 | #endif /* defined(HAVE_MKFIFO) */ |
| 4630 | |
| 4631 | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
| 4632 | |
| 4633 | PyDoc_STRVAR(os_mknod__doc__, |
| 4634 | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
| 4635 | "--\n" |
| 4636 | "\n" |
| 4637 | "Create a node in the file system.\n" |
| 4638 | "\n" |
| 4639 | "Create a node in the file system (file, device special file or named pipe)\n" |
| 4640 | "at path. mode specifies both the permissions to use and the\n" |
| 4641 | "type of node to be created, being combined (bitwise OR) with one of\n" |
| 4642 | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
| 4643 | "device defines the newly created device special file (probably using\n" |
| 4644 | "os.makedev()). Otherwise device is ignored.\n" |
| 4645 | "\n" |
| 4646 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
| 4647 | " and path should be relative; path will then be relative to that directory.\n" |
| 4648 | "dir_fd may not be implemented on your platform.\n" |
| 4649 | " If it is unavailable, using it will raise a NotImplementedError."); |
| 4650 | |
| 4651 | #define OS_MKNOD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4652 | {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4653 | |
| 4654 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4655 | 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] | 4656 | int dir_fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4657 | |
| 4658 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4659 | os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4660 | { |
| 4661 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4662 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
| 4663 | static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4664 | path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0); |
| 4665 | int mode = 384; |
| 4666 | dev_t device = 0; |
| 4667 | int dir_fd = DEFAULT_DIR_FD; |
| 4668 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 4669 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4670 | 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] | 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 = os_mknod_impl(module, &path, mode, device, dir_fd); |
| 4674 | |
| 4675 | exit: |
| 4676 | /* Cleanup for path */ |
| 4677 | path_cleanup(&path); |
| 4678 | |
| 4679 | return return_value; |
| 4680 | } |
| 4681 | |
| 4682 | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
| 4683 | |
| 4684 | #if defined(HAVE_DEVICE_MACROS) |
| 4685 | |
| 4686 | PyDoc_STRVAR(os_major__doc__, |
| 4687 | "major($module, device, /)\n" |
| 4688 | "--\n" |
| 4689 | "\n" |
| 4690 | "Extracts a device major number from a raw device number."); |
| 4691 | |
| 4692 | #define OS_MAJOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4693 | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4694 | |
| 4695 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4696 | os_major_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4697 | |
| 4698 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4699 | os_major(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4700 | { |
| 4701 | PyObject *return_value = NULL; |
| 4702 | dev_t device; |
| 4703 | unsigned int _return_value; |
| 4704 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4705 | if (!_Py_Dev_Converter(arg, &device)) { |
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_major_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4709 | if ((_return_value == (unsigned int)-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_FromUnsignedLong((unsigned long)_return_value); |
| 4713 | |
| 4714 | exit: |
| 4715 | return return_value; |
| 4716 | } |
| 4717 | |
| 4718 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 4719 | |
| 4720 | #if defined(HAVE_DEVICE_MACROS) |
| 4721 | |
| 4722 | PyDoc_STRVAR(os_minor__doc__, |
| 4723 | "minor($module, device, /)\n" |
| 4724 | "--\n" |
| 4725 | "\n" |
| 4726 | "Extracts a device minor number from a raw device number."); |
| 4727 | |
| 4728 | #define OS_MINOR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 4729 | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4730 | |
| 4731 | static unsigned int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4732 | os_minor_impl(PyObject *module, dev_t device); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4733 | |
| 4734 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4735 | os_minor(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4736 | { |
| 4737 | PyObject *return_value = NULL; |
| 4738 | dev_t device; |
| 4739 | unsigned int _return_value; |
| 4740 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 4741 | if (!_Py_Dev_Converter(arg, &device)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4742 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4743 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4744 | _return_value = os_minor_impl(module, device); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4745 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4746 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4747 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4748 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
| 4749 | |
| 4750 | exit: |
| 4751 | return return_value; |
| 4752 | } |
| 4753 | |
| 4754 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 4755 | |
| 4756 | #if defined(HAVE_DEVICE_MACROS) |
| 4757 | |
| 4758 | PyDoc_STRVAR(os_makedev__doc__, |
| 4759 | "makedev($module, major, minor, /)\n" |
| 4760 | "--\n" |
| 4761 | "\n" |
| 4762 | "Composes a raw device number from the major and minor device numbers."); |
| 4763 | |
| 4764 | #define OS_MAKEDEV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4765 | {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4766 | |
| 4767 | static dev_t |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4768 | os_makedev_impl(PyObject *module, int major, int minor); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4769 | |
| 4770 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4771 | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4772 | { |
| 4773 | PyObject *return_value = NULL; |
| 4774 | int major; |
| 4775 | int minor; |
| 4776 | dev_t _return_value; |
| 4777 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4778 | if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { |
| 4779 | goto exit; |
| 4780 | } |
| 4781 | if (PyFloat_Check(args[0])) { |
| 4782 | PyErr_SetString(PyExc_TypeError, |
| 4783 | "integer argument expected, got float" ); |
| 4784 | goto exit; |
| 4785 | } |
| 4786 | major = _PyLong_AsInt(args[0]); |
| 4787 | if (major == -1 && PyErr_Occurred()) { |
| 4788 | goto exit; |
| 4789 | } |
| 4790 | if (PyFloat_Check(args[1])) { |
| 4791 | PyErr_SetString(PyExc_TypeError, |
| 4792 | "integer argument expected, got float" ); |
| 4793 | goto exit; |
| 4794 | } |
| 4795 | minor = _PyLong_AsInt(args[1]); |
| 4796 | if (minor == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4797 | goto exit; |
| 4798 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4799 | _return_value = os_makedev_impl(module, major, minor); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4800 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4801 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4802 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4803 | return_value = _PyLong_FromDev(_return_value); |
| 4804 | |
| 4805 | exit: |
| 4806 | return return_value; |
| 4807 | } |
| 4808 | |
| 4809 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
| 4810 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4811 | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4812 | |
| 4813 | PyDoc_STRVAR(os_ftruncate__doc__, |
| 4814 | "ftruncate($module, fd, length, /)\n" |
| 4815 | "--\n" |
| 4816 | "\n" |
| 4817 | "Truncate a file, specified by file descriptor, to a specific length."); |
| 4818 | |
| 4819 | #define OS_FTRUNCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4820 | {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4821 | |
| 4822 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4823 | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4824 | |
| 4825 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4826 | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4827 | { |
| 4828 | PyObject *return_value = NULL; |
| 4829 | int fd; |
| 4830 | Py_off_t length; |
| 4831 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4832 | if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { |
| 4833 | goto exit; |
| 4834 | } |
| 4835 | if (PyFloat_Check(args[0])) { |
| 4836 | PyErr_SetString(PyExc_TypeError, |
| 4837 | "integer argument expected, got float" ); |
| 4838 | goto exit; |
| 4839 | } |
| 4840 | fd = _PyLong_AsInt(args[0]); |
| 4841 | if (fd == -1 && PyErr_Occurred()) { |
| 4842 | goto exit; |
| 4843 | } |
| 4844 | if (!Py_off_t_converter(args[1], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4845 | goto exit; |
| 4846 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4847 | return_value = os_ftruncate_impl(module, fd, length); |
| 4848 | |
| 4849 | exit: |
| 4850 | return return_value; |
| 4851 | } |
| 4852 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4853 | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4854 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4855 | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4856 | |
| 4857 | PyDoc_STRVAR(os_truncate__doc__, |
| 4858 | "truncate($module, /, path, length)\n" |
| 4859 | "--\n" |
| 4860 | "\n" |
| 4861 | "Truncate a file, specified by path, to a specific length.\n" |
| 4862 | "\n" |
| 4863 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 4864 | " If this functionality is unavailable, using it raises an exception."); |
| 4865 | |
| 4866 | #define OS_TRUNCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4867 | {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4868 | |
| 4869 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4870 | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4871 | |
| 4872 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4873 | os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4874 | { |
| 4875 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 4876 | static const char * const _keywords[] = {"path", "length", NULL}; |
| 4877 | static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4878 | path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE); |
| 4879 | Py_off_t length; |
| 4880 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 4881 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4882 | path_converter, &path, Py_off_t_converter, &length)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4883 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 4884 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4885 | return_value = os_truncate_impl(module, &path, length); |
| 4886 | |
| 4887 | exit: |
| 4888 | /* Cleanup for path */ |
| 4889 | path_cleanup(&path); |
| 4890 | |
| 4891 | return return_value; |
| 4892 | } |
| 4893 | |
Steve Dower | f737703 | 2015-04-12 15:44:54 -0400 | [diff] [blame] | 4894 | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4895 | |
| 4896 | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 4897 | |
| 4898 | PyDoc_STRVAR(os_posix_fallocate__doc__, |
| 4899 | "posix_fallocate($module, fd, offset, length, /)\n" |
| 4900 | "--\n" |
| 4901 | "\n" |
| 4902 | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
| 4903 | "\n" |
| 4904 | "Ensure that the file specified by fd encompasses a range of bytes\n" |
| 4905 | "starting at offset bytes from the beginning and continuing for length bytes."); |
| 4906 | |
| 4907 | #define OS_POSIX_FALLOCATE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4908 | {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4909 | |
| 4910 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4911 | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 4912 | Py_off_t length); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4913 | |
| 4914 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4915 | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4916 | { |
| 4917 | PyObject *return_value = NULL; |
| 4918 | int fd; |
| 4919 | Py_off_t offset; |
| 4920 | Py_off_t length; |
| 4921 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4922 | if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { |
| 4923 | goto exit; |
| 4924 | } |
| 4925 | if (PyFloat_Check(args[0])) { |
| 4926 | PyErr_SetString(PyExc_TypeError, |
| 4927 | "integer argument expected, got float" ); |
| 4928 | goto exit; |
| 4929 | } |
| 4930 | fd = _PyLong_AsInt(args[0]); |
| 4931 | if (fd == -1 && PyErr_Occurred()) { |
| 4932 | goto exit; |
| 4933 | } |
| 4934 | if (!Py_off_t_converter(args[1], &offset)) { |
| 4935 | goto exit; |
| 4936 | } |
| 4937 | if (!Py_off_t_converter(args[2], &length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 4938 | goto exit; |
| 4939 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4940 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
| 4941 | |
| 4942 | exit: |
| 4943 | return return_value; |
| 4944 | } |
| 4945 | |
| 4946 | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 4947 | |
| 4948 | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
| 4949 | |
| 4950 | PyDoc_STRVAR(os_posix_fadvise__doc__, |
| 4951 | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
| 4952 | "--\n" |
| 4953 | "\n" |
| 4954 | "Announce an intention to access data in a specific pattern.\n" |
| 4955 | "\n" |
| 4956 | "Announce an intention to access data in a specific pattern, thus allowing\n" |
| 4957 | "the kernel to make optimizations.\n" |
| 4958 | "The advice applies to the region of the file specified by fd starting at\n" |
| 4959 | "offset and continuing for length bytes.\n" |
| 4960 | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
| 4961 | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
| 4962 | "POSIX_FADV_DONTNEED."); |
| 4963 | |
| 4964 | #define OS_POSIX_FADVISE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 4965 | {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4966 | |
| 4967 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 4968 | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 4969 | Py_off_t length, int advice); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4970 | |
| 4971 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 4972 | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 4973 | { |
| 4974 | PyObject *return_value = NULL; |
| 4975 | int fd; |
| 4976 | Py_off_t offset; |
| 4977 | Py_off_t length; |
| 4978 | int advice; |
| 4979 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 4980 | if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { |
| 4981 | goto exit; |
| 4982 | } |
| 4983 | if (PyFloat_Check(args[0])) { |
| 4984 | PyErr_SetString(PyExc_TypeError, |
| 4985 | "integer argument expected, got float" ); |
| 4986 | goto exit; |
| 4987 | } |
| 4988 | fd = _PyLong_AsInt(args[0]); |
| 4989 | if (fd == -1 && PyErr_Occurred()) { |
| 4990 | goto exit; |
| 4991 | } |
| 4992 | if (!Py_off_t_converter(args[1], &offset)) { |
| 4993 | goto exit; |
| 4994 | } |
| 4995 | if (!Py_off_t_converter(args[2], &length)) { |
| 4996 | goto exit; |
| 4997 | } |
| 4998 | if (PyFloat_Check(args[3])) { |
| 4999 | PyErr_SetString(PyExc_TypeError, |
| 5000 | "integer argument expected, got float" ); |
| 5001 | goto exit; |
| 5002 | } |
| 5003 | advice = _PyLong_AsInt(args[3]); |
| 5004 | if (advice == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5005 | goto exit; |
| 5006 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5007 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
| 5008 | |
| 5009 | exit: |
| 5010 | return return_value; |
| 5011 | } |
| 5012 | |
| 5013 | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
| 5014 | |
| 5015 | #if defined(HAVE_PUTENV) && defined(MS_WINDOWS) |
| 5016 | |
| 5017 | PyDoc_STRVAR(os_putenv__doc__, |
| 5018 | "putenv($module, name, value, /)\n" |
| 5019 | "--\n" |
| 5020 | "\n" |
| 5021 | "Change or add an environment variable."); |
| 5022 | |
| 5023 | #define OS_PUTENV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5024 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5025 | |
| 5026 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5027 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5028 | |
| 5029 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5030 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5031 | { |
| 5032 | PyObject *return_value = NULL; |
| 5033 | PyObject *name; |
| 5034 | PyObject *value; |
| 5035 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5036 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5037 | goto exit; |
| 5038 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5039 | if (!PyUnicode_Check(args[0])) { |
| 5040 | _PyArg_BadArgument("putenv", 1, "str", args[0]); |
| 5041 | goto exit; |
| 5042 | } |
| 5043 | if (PyUnicode_READY(args[0]) == -1) { |
| 5044 | goto exit; |
| 5045 | } |
| 5046 | name = args[0]; |
| 5047 | if (!PyUnicode_Check(args[1])) { |
| 5048 | _PyArg_BadArgument("putenv", 2, "str", args[1]); |
| 5049 | goto exit; |
| 5050 | } |
| 5051 | if (PyUnicode_READY(args[1]) == -1) { |
| 5052 | goto exit; |
| 5053 | } |
| 5054 | value = args[1]; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5055 | return_value = os_putenv_impl(module, name, value); |
| 5056 | |
| 5057 | exit: |
| 5058 | return return_value; |
| 5059 | } |
| 5060 | |
| 5061 | #endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */ |
| 5062 | |
| 5063 | #if defined(HAVE_PUTENV) && !defined(MS_WINDOWS) |
| 5064 | |
| 5065 | PyDoc_STRVAR(os_putenv__doc__, |
| 5066 | "putenv($module, name, value, /)\n" |
| 5067 | "--\n" |
| 5068 | "\n" |
| 5069 | "Change or add an environment variable."); |
| 5070 | |
| 5071 | #define OS_PUTENV_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5072 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5073 | |
| 5074 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5075 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5076 | |
| 5077 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5078 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5079 | { |
| 5080 | PyObject *return_value = NULL; |
| 5081 | PyObject *name = NULL; |
| 5082 | PyObject *value = NULL; |
| 5083 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5084 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
| 5085 | goto exit; |
| 5086 | } |
| 5087 | if (!PyUnicode_FSConverter(args[0], &name)) { |
| 5088 | goto exit; |
| 5089 | } |
| 5090 | if (!PyUnicode_FSConverter(args[1], &value)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5091 | goto exit; |
| 5092 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5093 | return_value = os_putenv_impl(module, name, value); |
| 5094 | |
| 5095 | exit: |
| 5096 | /* Cleanup for name */ |
| 5097 | Py_XDECREF(name); |
| 5098 | /* Cleanup for value */ |
| 5099 | Py_XDECREF(value); |
| 5100 | |
| 5101 | return return_value; |
| 5102 | } |
| 5103 | |
| 5104 | #endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */ |
| 5105 | |
| 5106 | #if defined(HAVE_UNSETENV) |
| 5107 | |
| 5108 | PyDoc_STRVAR(os_unsetenv__doc__, |
| 5109 | "unsetenv($module, name, /)\n" |
| 5110 | "--\n" |
| 5111 | "\n" |
| 5112 | "Delete an environment variable."); |
| 5113 | |
| 5114 | #define OS_UNSETENV_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5115 | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5116 | |
| 5117 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5118 | os_unsetenv_impl(PyObject *module, PyObject *name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5119 | |
| 5120 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5121 | os_unsetenv(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5122 | { |
| 5123 | PyObject *return_value = NULL; |
| 5124 | PyObject *name = NULL; |
| 5125 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5126 | if (!PyUnicode_FSConverter(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5127 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5128 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5129 | return_value = os_unsetenv_impl(module, name); |
| 5130 | |
| 5131 | exit: |
| 5132 | /* Cleanup for name */ |
| 5133 | Py_XDECREF(name); |
| 5134 | |
| 5135 | return return_value; |
| 5136 | } |
| 5137 | |
| 5138 | #endif /* defined(HAVE_UNSETENV) */ |
| 5139 | |
| 5140 | PyDoc_STRVAR(os_strerror__doc__, |
| 5141 | "strerror($module, code, /)\n" |
| 5142 | "--\n" |
| 5143 | "\n" |
| 5144 | "Translate an error code to a message string."); |
| 5145 | |
| 5146 | #define OS_STRERROR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5147 | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5148 | |
| 5149 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5150 | os_strerror_impl(PyObject *module, int code); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5151 | |
| 5152 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5153 | os_strerror(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5154 | { |
| 5155 | PyObject *return_value = NULL; |
| 5156 | int code; |
| 5157 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5158 | if (PyFloat_Check(arg)) { |
| 5159 | PyErr_SetString(PyExc_TypeError, |
| 5160 | "integer argument expected, got float" ); |
| 5161 | goto exit; |
| 5162 | } |
| 5163 | code = _PyLong_AsInt(arg); |
| 5164 | if (code == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5165 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5166 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5167 | return_value = os_strerror_impl(module, code); |
| 5168 | |
| 5169 | exit: |
| 5170 | return return_value; |
| 5171 | } |
| 5172 | |
| 5173 | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
| 5174 | |
| 5175 | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
| 5176 | "WCOREDUMP($module, status, /)\n" |
| 5177 | "--\n" |
| 5178 | "\n" |
| 5179 | "Return True if the process returning status was dumped to a core file."); |
| 5180 | |
| 5181 | #define OS_WCOREDUMP_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5182 | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5183 | |
| 5184 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5185 | os_WCOREDUMP_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5186 | |
| 5187 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5188 | os_WCOREDUMP(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5189 | { |
| 5190 | PyObject *return_value = NULL; |
| 5191 | int status; |
| 5192 | int _return_value; |
| 5193 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5194 | if (PyFloat_Check(arg)) { |
| 5195 | PyErr_SetString(PyExc_TypeError, |
| 5196 | "integer argument expected, got float" ); |
| 5197 | goto exit; |
| 5198 | } |
| 5199 | status = _PyLong_AsInt(arg); |
| 5200 | if (status == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5201 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5202 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5203 | _return_value = os_WCOREDUMP_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5204 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5205 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5206 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5207 | return_value = PyBool_FromLong((long)_return_value); |
| 5208 | |
| 5209 | exit: |
| 5210 | return return_value; |
| 5211 | } |
| 5212 | |
| 5213 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
| 5214 | |
| 5215 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
| 5216 | |
| 5217 | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
| 5218 | "WIFCONTINUED($module, /, status)\n" |
| 5219 | "--\n" |
| 5220 | "\n" |
| 5221 | "Return True if a particular process was continued from a job control stop.\n" |
| 5222 | "\n" |
| 5223 | "Return True if the process returning status was continued from a\n" |
| 5224 | "job control stop."); |
| 5225 | |
| 5226 | #define OS_WIFCONTINUED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5227 | {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5228 | |
| 5229 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5230 | os_WIFCONTINUED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5231 | |
| 5232 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5233 | os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5234 | { |
| 5235 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5236 | static const char * const _keywords[] = {"status", NULL}; |
| 5237 | static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5238 | int status; |
| 5239 | int _return_value; |
| 5240 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5241 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5242 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5243 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5244 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5245 | _return_value = os_WIFCONTINUED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5246 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5247 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5248 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5249 | return_value = PyBool_FromLong((long)_return_value); |
| 5250 | |
| 5251 | exit: |
| 5252 | return return_value; |
| 5253 | } |
| 5254 | |
| 5255 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
| 5256 | |
| 5257 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
| 5258 | |
| 5259 | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
| 5260 | "WIFSTOPPED($module, /, status)\n" |
| 5261 | "--\n" |
| 5262 | "\n" |
| 5263 | "Return True if the process returning status was stopped."); |
| 5264 | |
| 5265 | #define OS_WIFSTOPPED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5266 | {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5267 | |
| 5268 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5269 | os_WIFSTOPPED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5270 | |
| 5271 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5272 | os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5273 | { |
| 5274 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5275 | static const char * const _keywords[] = {"status", NULL}; |
| 5276 | static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5277 | int status; |
| 5278 | int _return_value; |
| 5279 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5280 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5281 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5282 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5283 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5284 | _return_value = os_WIFSTOPPED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5285 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5286 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5287 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5288 | return_value = PyBool_FromLong((long)_return_value); |
| 5289 | |
| 5290 | exit: |
| 5291 | return return_value; |
| 5292 | } |
| 5293 | |
| 5294 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
| 5295 | |
| 5296 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
| 5297 | |
| 5298 | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
| 5299 | "WIFSIGNALED($module, /, status)\n" |
| 5300 | "--\n" |
| 5301 | "\n" |
| 5302 | "Return True if the process returning status was terminated by a signal."); |
| 5303 | |
| 5304 | #define OS_WIFSIGNALED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5305 | {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5306 | |
| 5307 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5308 | os_WIFSIGNALED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5309 | |
| 5310 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5311 | os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5312 | { |
| 5313 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5314 | static const char * const _keywords[] = {"status", NULL}; |
| 5315 | static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5316 | int status; |
| 5317 | int _return_value; |
| 5318 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5319 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5320 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5321 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5322 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5323 | _return_value = os_WIFSIGNALED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5324 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5325 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5326 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5327 | return_value = PyBool_FromLong((long)_return_value); |
| 5328 | |
| 5329 | exit: |
| 5330 | return return_value; |
| 5331 | } |
| 5332 | |
| 5333 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
| 5334 | |
| 5335 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
| 5336 | |
| 5337 | PyDoc_STRVAR(os_WIFEXITED__doc__, |
| 5338 | "WIFEXITED($module, /, status)\n" |
| 5339 | "--\n" |
| 5340 | "\n" |
| 5341 | "Return True if the process returning status exited via the exit() system call."); |
| 5342 | |
| 5343 | #define OS_WIFEXITED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5344 | {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5345 | |
| 5346 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5347 | os_WIFEXITED_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5348 | |
| 5349 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5350 | os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5351 | { |
| 5352 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5353 | static const char * const _keywords[] = {"status", NULL}; |
| 5354 | static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5355 | int status; |
| 5356 | int _return_value; |
| 5357 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5358 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5359 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5360 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5361 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5362 | _return_value = os_WIFEXITED_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5363 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5364 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5365 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5366 | return_value = PyBool_FromLong((long)_return_value); |
| 5367 | |
| 5368 | exit: |
| 5369 | return return_value; |
| 5370 | } |
| 5371 | |
| 5372 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
| 5373 | |
| 5374 | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
| 5375 | |
| 5376 | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
| 5377 | "WEXITSTATUS($module, /, status)\n" |
| 5378 | "--\n" |
| 5379 | "\n" |
| 5380 | "Return the process return code from status."); |
| 5381 | |
| 5382 | #define OS_WEXITSTATUS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5383 | {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5384 | |
| 5385 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5386 | os_WEXITSTATUS_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5387 | |
| 5388 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5389 | os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5390 | { |
| 5391 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5392 | static const char * const _keywords[] = {"status", NULL}; |
| 5393 | static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5394 | int status; |
| 5395 | int _return_value; |
| 5396 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5397 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5398 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5399 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5400 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5401 | _return_value = os_WEXITSTATUS_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5402 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5403 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5404 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5405 | return_value = PyLong_FromLong((long)_return_value); |
| 5406 | |
| 5407 | exit: |
| 5408 | return return_value; |
| 5409 | } |
| 5410 | |
| 5411 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
| 5412 | |
| 5413 | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
| 5414 | |
| 5415 | PyDoc_STRVAR(os_WTERMSIG__doc__, |
| 5416 | "WTERMSIG($module, /, status)\n" |
| 5417 | "--\n" |
| 5418 | "\n" |
| 5419 | "Return the signal that terminated the process that provided the status value."); |
| 5420 | |
| 5421 | #define OS_WTERMSIG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5422 | {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5423 | |
| 5424 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5425 | os_WTERMSIG_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5426 | |
| 5427 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5428 | os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5429 | { |
| 5430 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5431 | static const char * const _keywords[] = {"status", NULL}; |
| 5432 | static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5433 | int status; |
| 5434 | int _return_value; |
| 5435 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5436 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5437 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5438 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5439 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5440 | _return_value = os_WTERMSIG_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5441 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5442 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5443 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5444 | return_value = PyLong_FromLong((long)_return_value); |
| 5445 | |
| 5446 | exit: |
| 5447 | return return_value; |
| 5448 | } |
| 5449 | |
| 5450 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
| 5451 | |
| 5452 | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
| 5453 | |
| 5454 | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
| 5455 | "WSTOPSIG($module, /, status)\n" |
| 5456 | "--\n" |
| 5457 | "\n" |
| 5458 | "Return the signal that stopped the process that provided the status value."); |
| 5459 | |
| 5460 | #define OS_WSTOPSIG_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5461 | {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5462 | |
| 5463 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5464 | os_WSTOPSIG_impl(PyObject *module, int status); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5465 | |
| 5466 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5467 | os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5468 | { |
| 5469 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5470 | static const char * const _keywords[] = {"status", NULL}; |
| 5471 | static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5472 | int status; |
| 5473 | int _return_value; |
| 5474 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5475 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5476 | &status)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5477 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5478 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5479 | _return_value = os_WSTOPSIG_impl(module, status); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5480 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5481 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5482 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5483 | return_value = PyLong_FromLong((long)_return_value); |
| 5484 | |
| 5485 | exit: |
| 5486 | return return_value; |
| 5487 | } |
| 5488 | |
| 5489 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
| 5490 | |
| 5491 | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 5492 | |
| 5493 | PyDoc_STRVAR(os_fstatvfs__doc__, |
| 5494 | "fstatvfs($module, fd, /)\n" |
| 5495 | "--\n" |
| 5496 | "\n" |
| 5497 | "Perform an fstatvfs system call on the given fd.\n" |
| 5498 | "\n" |
| 5499 | "Equivalent to statvfs(fd)."); |
| 5500 | |
| 5501 | #define OS_FSTATVFS_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5502 | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5503 | |
| 5504 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5505 | os_fstatvfs_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5506 | |
| 5507 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5508 | os_fstatvfs(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5509 | { |
| 5510 | PyObject *return_value = NULL; |
| 5511 | int fd; |
| 5512 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5513 | if (PyFloat_Check(arg)) { |
| 5514 | PyErr_SetString(PyExc_TypeError, |
| 5515 | "integer argument expected, got float" ); |
| 5516 | goto exit; |
| 5517 | } |
| 5518 | fd = _PyLong_AsInt(arg); |
| 5519 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5520 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5521 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5522 | return_value = os_fstatvfs_impl(module, fd); |
| 5523 | |
| 5524 | exit: |
| 5525 | return return_value; |
| 5526 | } |
| 5527 | |
| 5528 | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 5529 | |
| 5530 | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
| 5531 | |
| 5532 | PyDoc_STRVAR(os_statvfs__doc__, |
| 5533 | "statvfs($module, /, path)\n" |
| 5534 | "--\n" |
| 5535 | "\n" |
| 5536 | "Perform a statvfs system call on the given path.\n" |
| 5537 | "\n" |
| 5538 | "path may always be specified as a string.\n" |
| 5539 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 5540 | " If this functionality is unavailable, using it raises an exception."); |
| 5541 | |
| 5542 | #define OS_STATVFS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5543 | {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__}, |
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_statvfs_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5547 | |
| 5548 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5549 | os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5550 | { |
| 5551 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5552 | static const char * const _keywords[] = {"path", NULL}; |
| 5553 | static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5554 | path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS); |
| 5555 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5556 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5557 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5558 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5559 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5560 | return_value = os_statvfs_impl(module, &path); |
| 5561 | |
| 5562 | exit: |
| 5563 | /* Cleanup for path */ |
| 5564 | path_cleanup(&path); |
| 5565 | |
| 5566 | return return_value; |
| 5567 | } |
| 5568 | |
| 5569 | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
| 5570 | |
| 5571 | #if defined(MS_WINDOWS) |
| 5572 | |
| 5573 | PyDoc_STRVAR(os__getdiskusage__doc__, |
| 5574 | "_getdiskusage($module, /, path)\n" |
| 5575 | "--\n" |
| 5576 | "\n" |
| 5577 | "Return disk usage statistics about the given path as a (total, free) tuple."); |
| 5578 | |
| 5579 | #define OS__GETDISKUSAGE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5580 | {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5581 | |
| 5582 | static PyObject * |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5583 | os__getdiskusage_impl(PyObject *module, path_t *path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5584 | |
| 5585 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5586 | os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5587 | { |
| 5588 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5589 | static const char * const _keywords[] = {"path", NULL}; |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5590 | static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0}; |
| 5591 | path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5592 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5593 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5594 | path_converter, &path)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5595 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5596 | } |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5597 | return_value = os__getdiskusage_impl(module, &path); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5598 | |
| 5599 | exit: |
Steve Dower | 23ad6d0 | 2018-02-22 10:39:10 -0800 | [diff] [blame] | 5600 | /* Cleanup for path */ |
| 5601 | path_cleanup(&path); |
| 5602 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5603 | return return_value; |
| 5604 | } |
| 5605 | |
| 5606 | #endif /* defined(MS_WINDOWS) */ |
| 5607 | |
| 5608 | #if defined(HAVE_FPATHCONF) |
| 5609 | |
| 5610 | PyDoc_STRVAR(os_fpathconf__doc__, |
| 5611 | "fpathconf($module, fd, name, /)\n" |
| 5612 | "--\n" |
| 5613 | "\n" |
| 5614 | "Return the configuration limit name for the file descriptor fd.\n" |
| 5615 | "\n" |
| 5616 | "If there is no limit, return -1."); |
| 5617 | |
| 5618 | #define OS_FPATHCONF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5619 | {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5620 | |
| 5621 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5622 | os_fpathconf_impl(PyObject *module, int fd, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5623 | |
| 5624 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5625 | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5626 | { |
| 5627 | PyObject *return_value = NULL; |
| 5628 | int fd; |
| 5629 | int name; |
| 5630 | long _return_value; |
| 5631 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5632 | if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { |
| 5633 | goto exit; |
| 5634 | } |
| 5635 | if (PyFloat_Check(args[0])) { |
| 5636 | PyErr_SetString(PyExc_TypeError, |
| 5637 | "integer argument expected, got float" ); |
| 5638 | goto exit; |
| 5639 | } |
| 5640 | fd = _PyLong_AsInt(args[0]); |
| 5641 | if (fd == -1 && PyErr_Occurred()) { |
| 5642 | goto exit; |
| 5643 | } |
| 5644 | if (!conv_path_confname(args[1], &name)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5645 | goto exit; |
| 5646 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5647 | _return_value = os_fpathconf_impl(module, fd, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5648 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5649 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5650 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5651 | return_value = PyLong_FromLong(_return_value); |
| 5652 | |
| 5653 | exit: |
| 5654 | return return_value; |
| 5655 | } |
| 5656 | |
| 5657 | #endif /* defined(HAVE_FPATHCONF) */ |
| 5658 | |
| 5659 | #if defined(HAVE_PATHCONF) |
| 5660 | |
| 5661 | PyDoc_STRVAR(os_pathconf__doc__, |
| 5662 | "pathconf($module, /, path, name)\n" |
| 5663 | "--\n" |
| 5664 | "\n" |
| 5665 | "Return the configuration limit name for the file or directory path.\n" |
| 5666 | "\n" |
| 5667 | "If there is no limit, return -1.\n" |
| 5668 | "On some platforms, path may also be specified as an open file descriptor.\n" |
| 5669 | " If this functionality is unavailable, using it raises an exception."); |
| 5670 | |
| 5671 | #define OS_PATHCONF_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5672 | {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5673 | |
| 5674 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5675 | os_pathconf_impl(PyObject *module, path_t *path, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5676 | |
| 5677 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5678 | os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5679 | { |
| 5680 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5681 | static const char * const _keywords[] = {"path", "name", NULL}; |
| 5682 | static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5683 | path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF); |
| 5684 | int name; |
| 5685 | long _return_value; |
| 5686 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5687 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5688 | path_converter, &path, conv_path_confname, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5689 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5690 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5691 | _return_value = os_pathconf_impl(module, &path, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5692 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5693 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5694 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5695 | return_value = PyLong_FromLong(_return_value); |
| 5696 | |
| 5697 | exit: |
| 5698 | /* Cleanup for path */ |
| 5699 | path_cleanup(&path); |
| 5700 | |
| 5701 | return return_value; |
| 5702 | } |
| 5703 | |
| 5704 | #endif /* defined(HAVE_PATHCONF) */ |
| 5705 | |
| 5706 | #if defined(HAVE_CONFSTR) |
| 5707 | |
| 5708 | PyDoc_STRVAR(os_confstr__doc__, |
| 5709 | "confstr($module, name, /)\n" |
| 5710 | "--\n" |
| 5711 | "\n" |
| 5712 | "Return a string-valued system configuration variable."); |
| 5713 | |
| 5714 | #define OS_CONFSTR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5715 | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5716 | |
| 5717 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5718 | os_confstr_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5719 | |
| 5720 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5721 | os_confstr(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5722 | { |
| 5723 | PyObject *return_value = NULL; |
| 5724 | int name; |
| 5725 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5726 | if (!conv_confstr_confname(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5727 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5728 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5729 | return_value = os_confstr_impl(module, name); |
| 5730 | |
| 5731 | exit: |
| 5732 | return return_value; |
| 5733 | } |
| 5734 | |
| 5735 | #endif /* defined(HAVE_CONFSTR) */ |
| 5736 | |
| 5737 | #if defined(HAVE_SYSCONF) |
| 5738 | |
| 5739 | PyDoc_STRVAR(os_sysconf__doc__, |
| 5740 | "sysconf($module, name, /)\n" |
| 5741 | "--\n" |
| 5742 | "\n" |
| 5743 | "Return an integer-valued system configuration variable."); |
| 5744 | |
| 5745 | #define OS_SYSCONF_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 5746 | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5747 | |
| 5748 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5749 | os_sysconf_impl(PyObject *module, int name); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5750 | |
| 5751 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5752 | os_sysconf(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5753 | { |
| 5754 | PyObject *return_value = NULL; |
| 5755 | int name; |
| 5756 | long _return_value; |
| 5757 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 5758 | if (!conv_sysconf_confname(arg, &name)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5759 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5760 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5761 | _return_value = os_sysconf_impl(module, name); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5762 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5763 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5764 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5765 | return_value = PyLong_FromLong(_return_value); |
| 5766 | |
| 5767 | exit: |
| 5768 | return return_value; |
| 5769 | } |
| 5770 | |
| 5771 | #endif /* defined(HAVE_SYSCONF) */ |
| 5772 | |
| 5773 | PyDoc_STRVAR(os_abort__doc__, |
| 5774 | "abort($module, /)\n" |
| 5775 | "--\n" |
| 5776 | "\n" |
| 5777 | "Abort the interpreter immediately.\n" |
| 5778 | "\n" |
| 5779 | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
| 5780 | "on the hosting operating system. This function never returns."); |
| 5781 | |
| 5782 | #define OS_ABORT_METHODDEF \ |
| 5783 | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
| 5784 | |
| 5785 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5786 | os_abort_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5787 | |
| 5788 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5789 | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5790 | { |
| 5791 | return os_abort_impl(module); |
| 5792 | } |
| 5793 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5794 | #if defined(MS_WINDOWS) |
| 5795 | |
| 5796 | PyDoc_STRVAR(os_startfile__doc__, |
| 5797 | "startfile($module, /, filepath, operation=None)\n" |
| 5798 | "--\n" |
| 5799 | "\n" |
| 5800 | "startfile(filepath [, operation])\n" |
| 5801 | "\n" |
| 5802 | "Start a file with its associated application.\n" |
| 5803 | "\n" |
| 5804 | "When \"operation\" is not specified or \"open\", this acts like\n" |
| 5805 | "double-clicking the file in Explorer, or giving the file name as an\n" |
| 5806 | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
| 5807 | "application (if any) its extension is associated.\n" |
| 5808 | "When another \"operation\" is given, it specifies what should be done with\n" |
| 5809 | "the file. A typical operation is \"print\".\n" |
| 5810 | "\n" |
| 5811 | "startfile returns as soon as the associated application is launched.\n" |
| 5812 | "There is no option to wait for the application to close, and no way\n" |
| 5813 | "to retrieve the application\'s exit status.\n" |
| 5814 | "\n" |
| 5815 | "The filepath is relative to the current directory. If you want to use\n" |
| 5816 | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
| 5817 | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
| 5818 | |
| 5819 | #define OS_STARTFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5820 | {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__}, |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5821 | |
| 5822 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 5823 | os_startfile_impl(PyObject *module, path_t *filepath, |
| 5824 | const Py_UNICODE *operation); |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5825 | |
| 5826 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5827 | os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5828 | { |
| 5829 | PyObject *return_value = NULL; |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 5830 | static const char * const _keywords[] = {"filepath", "operation", NULL}; |
| 5831 | static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0}; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5832 | path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0); |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 5833 | const Py_UNICODE *operation = NULL; |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5834 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5835 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 5836 | path_converter, &filepath, &operation)) { |
| 5837 | goto exit; |
| 5838 | } |
| 5839 | return_value = os_startfile_impl(module, &filepath, operation); |
| 5840 | |
| 5841 | exit: |
| 5842 | /* Cleanup for filepath */ |
| 5843 | path_cleanup(&filepath); |
| 5844 | |
| 5845 | return return_value; |
| 5846 | } |
| 5847 | |
| 5848 | #endif /* defined(MS_WINDOWS) */ |
| 5849 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5850 | #if defined(HAVE_GETLOADAVG) |
| 5851 | |
| 5852 | PyDoc_STRVAR(os_getloadavg__doc__, |
| 5853 | "getloadavg($module, /)\n" |
| 5854 | "--\n" |
| 5855 | "\n" |
| 5856 | "Return average recent system load information.\n" |
| 5857 | "\n" |
| 5858 | "Return the number of processes in the system run queue averaged over\n" |
| 5859 | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
| 5860 | "Raises OSError if the load average was unobtainable."); |
| 5861 | |
| 5862 | #define OS_GETLOADAVG_METHODDEF \ |
| 5863 | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
| 5864 | |
| 5865 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5866 | os_getloadavg_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5867 | |
| 5868 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5869 | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5870 | { |
| 5871 | return os_getloadavg_impl(module); |
| 5872 | } |
| 5873 | |
| 5874 | #endif /* defined(HAVE_GETLOADAVG) */ |
| 5875 | |
| 5876 | PyDoc_STRVAR(os_device_encoding__doc__, |
| 5877 | "device_encoding($module, /, fd)\n" |
| 5878 | "--\n" |
| 5879 | "\n" |
| 5880 | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
| 5881 | "\n" |
| 5882 | "The file descriptor must be attached to a terminal.\n" |
| 5883 | "If the device is not a terminal, return None."); |
| 5884 | |
| 5885 | #define OS_DEVICE_ENCODING_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5886 | {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5887 | |
| 5888 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5889 | os_device_encoding_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5890 | |
| 5891 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5892 | os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5893 | { |
| 5894 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 5895 | static const char * const _keywords[] = {"fd", NULL}; |
| 5896 | static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5897 | int fd; |
| 5898 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 5899 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5900 | &fd)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5901 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 5902 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5903 | return_value = os_device_encoding_impl(module, fd); |
| 5904 | |
| 5905 | exit: |
| 5906 | return return_value; |
| 5907 | } |
| 5908 | |
| 5909 | #if defined(HAVE_SETRESUID) |
| 5910 | |
| 5911 | PyDoc_STRVAR(os_setresuid__doc__, |
| 5912 | "setresuid($module, ruid, euid, suid, /)\n" |
| 5913 | "--\n" |
| 5914 | "\n" |
| 5915 | "Set the current process\'s real, effective, and saved user ids."); |
| 5916 | |
| 5917 | #define OS_SETRESUID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5918 | {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5919 | |
| 5920 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5921 | 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] | 5922 | |
| 5923 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5924 | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5925 | { |
| 5926 | PyObject *return_value = NULL; |
| 5927 | uid_t ruid; |
| 5928 | uid_t euid; |
| 5929 | uid_t suid; |
| 5930 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5931 | if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { |
| 5932 | goto exit; |
| 5933 | } |
| 5934 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
| 5935 | goto exit; |
| 5936 | } |
| 5937 | if (!_Py_Uid_Converter(args[1], &euid)) { |
| 5938 | goto exit; |
| 5939 | } |
| 5940 | if (!_Py_Uid_Converter(args[2], &suid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5941 | goto exit; |
| 5942 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5943 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
| 5944 | |
| 5945 | exit: |
| 5946 | return return_value; |
| 5947 | } |
| 5948 | |
| 5949 | #endif /* defined(HAVE_SETRESUID) */ |
| 5950 | |
| 5951 | #if defined(HAVE_SETRESGID) |
| 5952 | |
| 5953 | PyDoc_STRVAR(os_setresgid__doc__, |
| 5954 | "setresgid($module, rgid, egid, sgid, /)\n" |
| 5955 | "--\n" |
| 5956 | "\n" |
| 5957 | "Set the current process\'s real, effective, and saved group ids."); |
| 5958 | |
| 5959 | #define OS_SETRESGID_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 5960 | {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5961 | |
| 5962 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 5963 | 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] | 5964 | |
| 5965 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 5966 | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5967 | { |
| 5968 | PyObject *return_value = NULL; |
| 5969 | gid_t rgid; |
| 5970 | gid_t egid; |
| 5971 | gid_t sgid; |
| 5972 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 5973 | if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { |
| 5974 | goto exit; |
| 5975 | } |
| 5976 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
| 5977 | goto exit; |
| 5978 | } |
| 5979 | if (!_Py_Gid_Converter(args[1], &egid)) { |
| 5980 | goto exit; |
| 5981 | } |
| 5982 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 5983 | goto exit; |
| 5984 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 5985 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
| 5986 | |
| 5987 | exit: |
| 5988 | return return_value; |
| 5989 | } |
| 5990 | |
| 5991 | #endif /* defined(HAVE_SETRESGID) */ |
| 5992 | |
| 5993 | #if defined(HAVE_GETRESUID) |
| 5994 | |
| 5995 | PyDoc_STRVAR(os_getresuid__doc__, |
| 5996 | "getresuid($module, /)\n" |
| 5997 | "--\n" |
| 5998 | "\n" |
| 5999 | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
| 6000 | |
| 6001 | #define OS_GETRESUID_METHODDEF \ |
| 6002 | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
| 6003 | |
| 6004 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6005 | os_getresuid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6006 | |
| 6007 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6008 | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6009 | { |
| 6010 | return os_getresuid_impl(module); |
| 6011 | } |
| 6012 | |
| 6013 | #endif /* defined(HAVE_GETRESUID) */ |
| 6014 | |
| 6015 | #if defined(HAVE_GETRESGID) |
| 6016 | |
| 6017 | PyDoc_STRVAR(os_getresgid__doc__, |
| 6018 | "getresgid($module, /)\n" |
| 6019 | "--\n" |
| 6020 | "\n" |
| 6021 | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
| 6022 | |
| 6023 | #define OS_GETRESGID_METHODDEF \ |
| 6024 | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
| 6025 | |
| 6026 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6027 | os_getresgid_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6028 | |
| 6029 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6030 | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6031 | { |
| 6032 | return os_getresgid_impl(module); |
| 6033 | } |
| 6034 | |
| 6035 | #endif /* defined(HAVE_GETRESGID) */ |
| 6036 | |
| 6037 | #if defined(USE_XATTRS) |
| 6038 | |
| 6039 | PyDoc_STRVAR(os_getxattr__doc__, |
| 6040 | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 6041 | "--\n" |
| 6042 | "\n" |
| 6043 | "Return the value of extended attribute attribute on path.\n" |
| 6044 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 6045 | "path may be either a string, a path-like object, or an open file descriptor.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6046 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 6047 | " link, getxattr will examine the symbolic link itself instead of the file\n" |
| 6048 | " the link points to."); |
| 6049 | |
| 6050 | #define OS_GETXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6051 | {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6052 | |
| 6053 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6054 | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 6055 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6056 | |
| 6057 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6058 | os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6059 | { |
| 6060 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6061 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
| 6062 | static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6063 | path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1); |
| 6064 | path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0); |
| 6065 | int follow_symlinks = 1; |
| 6066 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6067 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6068 | path_converter, &path, path_converter, &attribute, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6069 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6070 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6071 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
| 6072 | |
| 6073 | exit: |
| 6074 | /* Cleanup for path */ |
| 6075 | path_cleanup(&path); |
| 6076 | /* Cleanup for attribute */ |
| 6077 | path_cleanup(&attribute); |
| 6078 | |
| 6079 | return return_value; |
| 6080 | } |
| 6081 | |
| 6082 | #endif /* defined(USE_XATTRS) */ |
| 6083 | |
| 6084 | #if defined(USE_XATTRS) |
| 6085 | |
| 6086 | PyDoc_STRVAR(os_setxattr__doc__, |
| 6087 | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
| 6088 | " follow_symlinks=True)\n" |
| 6089 | "--\n" |
| 6090 | "\n" |
| 6091 | "Set extended attribute attribute on path to value.\n" |
| 6092 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 6093 | "path may be either a string, a path-like object, or an open file descriptor.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6094 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 6095 | " link, setxattr will modify the symbolic link itself instead of the file\n" |
| 6096 | " the link points to."); |
| 6097 | |
| 6098 | #define OS_SETXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6099 | {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6100 | |
| 6101 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6102 | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 6103 | Py_buffer *value, int flags, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6104 | |
| 6105 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6106 | os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6107 | { |
| 6108 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6109 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
| 6110 | static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6111 | path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1); |
| 6112 | path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0); |
| 6113 | Py_buffer value = {NULL, NULL}; |
| 6114 | int flags = 0; |
| 6115 | int follow_symlinks = 1; |
| 6116 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6117 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6118 | path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6119 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6120 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6121 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
| 6122 | |
| 6123 | exit: |
| 6124 | /* Cleanup for path */ |
| 6125 | path_cleanup(&path); |
| 6126 | /* Cleanup for attribute */ |
| 6127 | path_cleanup(&attribute); |
| 6128 | /* Cleanup for value */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6129 | if (value.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6130 | PyBuffer_Release(&value); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6131 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6132 | |
| 6133 | return return_value; |
| 6134 | } |
| 6135 | |
| 6136 | #endif /* defined(USE_XATTRS) */ |
| 6137 | |
| 6138 | #if defined(USE_XATTRS) |
| 6139 | |
| 6140 | PyDoc_STRVAR(os_removexattr__doc__, |
| 6141 | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
| 6142 | "--\n" |
| 6143 | "\n" |
| 6144 | "Remove extended attribute attribute on path.\n" |
| 6145 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 6146 | "path may be either a string, a path-like object, or an open file descriptor.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6147 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 6148 | " link, removexattr will modify the symbolic link itself instead of the file\n" |
| 6149 | " the link points to."); |
| 6150 | |
| 6151 | #define OS_REMOVEXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6152 | {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6153 | |
| 6154 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6155 | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 6156 | int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6157 | |
| 6158 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6159 | os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6160 | { |
| 6161 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6162 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
| 6163 | static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6164 | path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1); |
| 6165 | path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0); |
| 6166 | int follow_symlinks = 1; |
| 6167 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6168 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6169 | path_converter, &path, path_converter, &attribute, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6170 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6171 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6172 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
| 6173 | |
| 6174 | exit: |
| 6175 | /* Cleanup for path */ |
| 6176 | path_cleanup(&path); |
| 6177 | /* Cleanup for attribute */ |
| 6178 | path_cleanup(&attribute); |
| 6179 | |
| 6180 | return return_value; |
| 6181 | } |
| 6182 | |
| 6183 | #endif /* defined(USE_XATTRS) */ |
| 6184 | |
| 6185 | #if defined(USE_XATTRS) |
| 6186 | |
| 6187 | PyDoc_STRVAR(os_listxattr__doc__, |
| 6188 | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
| 6189 | "--\n" |
| 6190 | "\n" |
| 6191 | "Return a list of extended attributes on path.\n" |
| 6192 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 6193 | "path may be either None, a string, a path-like object, or an open file descriptor.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6194 | "if path is None, listxattr will examine the current directory.\n" |
| 6195 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
| 6196 | " link, listxattr will examine the symbolic link itself instead of the file\n" |
| 6197 | " the link points to."); |
| 6198 | |
| 6199 | #define OS_LISTXATTR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6200 | {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6201 | |
| 6202 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6203 | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6204 | |
| 6205 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6206 | os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6207 | { |
| 6208 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6209 | static const char * const _keywords[] = {"path", "follow_symlinks", NULL}; |
| 6210 | static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6211 | path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1); |
| 6212 | int follow_symlinks = 1; |
| 6213 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6214 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6215 | path_converter, &path, &follow_symlinks)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6216 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6217 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6218 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
| 6219 | |
| 6220 | exit: |
| 6221 | /* Cleanup for path */ |
| 6222 | path_cleanup(&path); |
| 6223 | |
| 6224 | return return_value; |
| 6225 | } |
| 6226 | |
| 6227 | #endif /* defined(USE_XATTRS) */ |
| 6228 | |
| 6229 | PyDoc_STRVAR(os_urandom__doc__, |
| 6230 | "urandom($module, size, /)\n" |
| 6231 | "--\n" |
| 6232 | "\n" |
| 6233 | "Return a bytes object containing random bytes suitable for cryptographic use."); |
| 6234 | |
| 6235 | #define OS_URANDOM_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6236 | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6237 | |
| 6238 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6239 | os_urandom_impl(PyObject *module, Py_ssize_t size); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6240 | |
| 6241 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6242 | os_urandom(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6243 | { |
| 6244 | PyObject *return_value = NULL; |
| 6245 | Py_ssize_t size; |
| 6246 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6247 | if (PyFloat_Check(arg)) { |
| 6248 | PyErr_SetString(PyExc_TypeError, |
| 6249 | "integer argument expected, got float" ); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6250 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6251 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6252 | { |
| 6253 | Py_ssize_t ival = -1; |
| 6254 | PyObject *iobj = PyNumber_Index(arg); |
| 6255 | if (iobj != NULL) { |
| 6256 | ival = PyLong_AsSsize_t(iobj); |
| 6257 | Py_DECREF(iobj); |
| 6258 | } |
| 6259 | if (ival == -1 && PyErr_Occurred()) { |
| 6260 | goto exit; |
| 6261 | } |
| 6262 | size = ival; |
| 6263 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6264 | return_value = os_urandom_impl(module, size); |
| 6265 | |
| 6266 | exit: |
| 6267 | return return_value; |
| 6268 | } |
| 6269 | |
| 6270 | PyDoc_STRVAR(os_cpu_count__doc__, |
| 6271 | "cpu_count($module, /)\n" |
| 6272 | "--\n" |
| 6273 | "\n" |
Charles-François Natali | 80d62e6 | 2015-08-13 20:37:08 +0100 | [diff] [blame] | 6274 | "Return the number of CPUs in the system; return None if indeterminable.\n" |
| 6275 | "\n" |
| 6276 | "This number is not equivalent to the number of CPUs the current process can\n" |
| 6277 | "use. The number of usable CPUs can be obtained with\n" |
| 6278 | "``len(os.sched_getaffinity(0))``"); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6279 | |
| 6280 | #define OS_CPU_COUNT_METHODDEF \ |
| 6281 | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
| 6282 | |
| 6283 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6284 | os_cpu_count_impl(PyObject *module); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6285 | |
| 6286 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6287 | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6288 | { |
| 6289 | return os_cpu_count_impl(module); |
| 6290 | } |
| 6291 | |
| 6292 | PyDoc_STRVAR(os_get_inheritable__doc__, |
| 6293 | "get_inheritable($module, fd, /)\n" |
| 6294 | "--\n" |
| 6295 | "\n" |
| 6296 | "Get the close-on-exe flag of the specified file descriptor."); |
| 6297 | |
| 6298 | #define OS_GET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6299 | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6300 | |
| 6301 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6302 | os_get_inheritable_impl(PyObject *module, int fd); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6303 | |
| 6304 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6305 | os_get_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6306 | { |
| 6307 | PyObject *return_value = NULL; |
| 6308 | int fd; |
| 6309 | int _return_value; |
| 6310 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6311 | if (PyFloat_Check(arg)) { |
| 6312 | PyErr_SetString(PyExc_TypeError, |
| 6313 | "integer argument expected, got float" ); |
| 6314 | goto exit; |
| 6315 | } |
| 6316 | fd = _PyLong_AsInt(arg); |
| 6317 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6318 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6319 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6320 | _return_value = os_get_inheritable_impl(module, fd); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6321 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6322 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6323 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6324 | return_value = PyBool_FromLong((long)_return_value); |
| 6325 | |
| 6326 | exit: |
| 6327 | return return_value; |
| 6328 | } |
| 6329 | |
| 6330 | PyDoc_STRVAR(os_set_inheritable__doc__, |
| 6331 | "set_inheritable($module, fd, inheritable, /)\n" |
| 6332 | "--\n" |
| 6333 | "\n" |
| 6334 | "Set the inheritable flag of the specified file descriptor."); |
| 6335 | |
| 6336 | #define OS_SET_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6337 | {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6338 | |
| 6339 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6340 | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6341 | |
| 6342 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6343 | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6344 | { |
| 6345 | PyObject *return_value = NULL; |
| 6346 | int fd; |
| 6347 | int inheritable; |
| 6348 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6349 | if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { |
| 6350 | goto exit; |
| 6351 | } |
| 6352 | if (PyFloat_Check(args[0])) { |
| 6353 | PyErr_SetString(PyExc_TypeError, |
| 6354 | "integer argument expected, got float" ); |
| 6355 | goto exit; |
| 6356 | } |
| 6357 | fd = _PyLong_AsInt(args[0]); |
| 6358 | if (fd == -1 && PyErr_Occurred()) { |
| 6359 | goto exit; |
| 6360 | } |
| 6361 | if (PyFloat_Check(args[1])) { |
| 6362 | PyErr_SetString(PyExc_TypeError, |
| 6363 | "integer argument expected, got float" ); |
| 6364 | goto exit; |
| 6365 | } |
| 6366 | inheritable = _PyLong_AsInt(args[1]); |
| 6367 | if (inheritable == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6368 | goto exit; |
| 6369 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6370 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
| 6371 | |
| 6372 | exit: |
| 6373 | return return_value; |
| 6374 | } |
| 6375 | |
| 6376 | #if defined(MS_WINDOWS) |
| 6377 | |
| 6378 | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
| 6379 | "get_handle_inheritable($module, handle, /)\n" |
| 6380 | "--\n" |
| 6381 | "\n" |
| 6382 | "Get the close-on-exe flag of the specified file descriptor."); |
| 6383 | |
| 6384 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 6385 | {"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] | 6386 | |
| 6387 | static int |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 6388 | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6389 | |
| 6390 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 6391 | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6392 | { |
| 6393 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 6394 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6395 | int _return_value; |
| 6396 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6397 | if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6398 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6399 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6400 | _return_value = os_get_handle_inheritable_impl(module, handle); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6401 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6402 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6403 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6404 | return_value = PyBool_FromLong((long)_return_value); |
| 6405 | |
| 6406 | exit: |
| 6407 | return return_value; |
| 6408 | } |
| 6409 | |
| 6410 | #endif /* defined(MS_WINDOWS) */ |
| 6411 | |
| 6412 | #if defined(MS_WINDOWS) |
| 6413 | |
| 6414 | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
| 6415 | "set_handle_inheritable($module, handle, inheritable, /)\n" |
| 6416 | "--\n" |
| 6417 | "\n" |
| 6418 | "Set the inheritable flag of the specified handle."); |
| 6419 | |
| 6420 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6421 | {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6422 | |
| 6423 | static PyObject * |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 6424 | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 6425 | int inheritable); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6426 | |
| 6427 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6428 | os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6429 | { |
| 6430 | PyObject *return_value = NULL; |
Victor Stinner | 581139c | 2016-09-06 15:54:20 -0700 | [diff] [blame] | 6431 | intptr_t handle; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6432 | int inheritable; |
| 6433 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 6434 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable", |
| 6435 | &handle, &inheritable)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 6436 | goto exit; |
| 6437 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6438 | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
| 6439 | |
| 6440 | exit: |
| 6441 | return return_value; |
| 6442 | } |
| 6443 | |
| 6444 | #endif /* defined(MS_WINDOWS) */ |
| 6445 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 6446 | #if !defined(MS_WINDOWS) |
| 6447 | |
| 6448 | PyDoc_STRVAR(os_get_blocking__doc__, |
| 6449 | "get_blocking($module, fd, /)\n" |
| 6450 | "--\n" |
| 6451 | "\n" |
| 6452 | "Get the blocking mode of the file descriptor.\n" |
| 6453 | "\n" |
| 6454 | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared."); |
| 6455 | |
| 6456 | #define OS_GET_BLOCKING_METHODDEF \ |
| 6457 | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
| 6458 | |
| 6459 | static int |
| 6460 | os_get_blocking_impl(PyObject *module, int fd); |
| 6461 | |
| 6462 | static PyObject * |
| 6463 | os_get_blocking(PyObject *module, PyObject *arg) |
| 6464 | { |
| 6465 | PyObject *return_value = NULL; |
| 6466 | int fd; |
| 6467 | int _return_value; |
| 6468 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 6469 | if (PyFloat_Check(arg)) { |
| 6470 | PyErr_SetString(PyExc_TypeError, |
| 6471 | "integer argument expected, got float" ); |
| 6472 | goto exit; |
| 6473 | } |
| 6474 | fd = _PyLong_AsInt(arg); |
| 6475 | if (fd == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 6476 | goto exit; |
| 6477 | } |
| 6478 | _return_value = os_get_blocking_impl(module, fd); |
| 6479 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 6480 | goto exit; |
| 6481 | } |
| 6482 | return_value = PyBool_FromLong((long)_return_value); |
| 6483 | |
| 6484 | exit: |
| 6485 | return return_value; |
| 6486 | } |
| 6487 | |
| 6488 | #endif /* !defined(MS_WINDOWS) */ |
| 6489 | |
| 6490 | #if !defined(MS_WINDOWS) |
| 6491 | |
| 6492 | PyDoc_STRVAR(os_set_blocking__doc__, |
| 6493 | "set_blocking($module, fd, blocking, /)\n" |
| 6494 | "--\n" |
| 6495 | "\n" |
| 6496 | "Set the blocking mode of the specified file descriptor.\n" |
| 6497 | "\n" |
| 6498 | "Set the O_NONBLOCK flag if blocking is False,\n" |
| 6499 | "clear the O_NONBLOCK flag otherwise."); |
| 6500 | |
| 6501 | #define OS_SET_BLOCKING_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6502 | {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__}, |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 6503 | |
| 6504 | static PyObject * |
| 6505 | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
| 6506 | |
| 6507 | static PyObject * |
| 6508 | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 6509 | { |
| 6510 | PyObject *return_value = NULL; |
| 6511 | int fd; |
| 6512 | int blocking; |
| 6513 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 6514 | if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { |
| 6515 | goto exit; |
| 6516 | } |
| 6517 | if (PyFloat_Check(args[0])) { |
| 6518 | PyErr_SetString(PyExc_TypeError, |
| 6519 | "integer argument expected, got float" ); |
| 6520 | goto exit; |
| 6521 | } |
| 6522 | fd = _PyLong_AsInt(args[0]); |
| 6523 | if (fd == -1 && PyErr_Occurred()) { |
| 6524 | goto exit; |
| 6525 | } |
| 6526 | if (PyFloat_Check(args[1])) { |
| 6527 | PyErr_SetString(PyExc_TypeError, |
| 6528 | "integer argument expected, got float" ); |
| 6529 | goto exit; |
| 6530 | } |
| 6531 | blocking = _PyLong_AsInt(args[1]); |
| 6532 | if (blocking == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 6533 | goto exit; |
| 6534 | } |
| 6535 | return_value = os_set_blocking_impl(module, fd, blocking); |
| 6536 | |
| 6537 | exit: |
| 6538 | return return_value; |
| 6539 | } |
| 6540 | |
| 6541 | #endif /* !defined(MS_WINDOWS) */ |
| 6542 | |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6543 | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
| 6544 | "is_symlink($self, /)\n" |
| 6545 | "--\n" |
| 6546 | "\n" |
| 6547 | "Return True if the entry is a symbolic link; cached per entry."); |
| 6548 | |
| 6549 | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
| 6550 | {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__}, |
| 6551 | |
| 6552 | static int |
| 6553 | os_DirEntry_is_symlink_impl(DirEntry *self); |
| 6554 | |
| 6555 | static PyObject * |
| 6556 | os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 6557 | { |
| 6558 | PyObject *return_value = NULL; |
| 6559 | int _return_value; |
| 6560 | |
| 6561 | _return_value = os_DirEntry_is_symlink_impl(self); |
| 6562 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 6563 | goto exit; |
| 6564 | } |
| 6565 | return_value = PyBool_FromLong((long)_return_value); |
| 6566 | |
| 6567 | exit: |
| 6568 | return return_value; |
| 6569 | } |
| 6570 | |
| 6571 | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
| 6572 | "stat($self, /, *, follow_symlinks=True)\n" |
| 6573 | "--\n" |
| 6574 | "\n" |
| 6575 | "Return stat_result object for the entry; cached per entry."); |
| 6576 | |
| 6577 | #define OS_DIRENTRY_STAT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6578 | {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__}, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6579 | |
| 6580 | static PyObject * |
| 6581 | os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks); |
| 6582 | |
| 6583 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6584 | os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6585 | { |
| 6586 | PyObject *return_value = NULL; |
| 6587 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
| 6588 | static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0}; |
| 6589 | int follow_symlinks = 1; |
| 6590 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6591 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6592 | &follow_symlinks)) { |
| 6593 | goto exit; |
| 6594 | } |
| 6595 | return_value = os_DirEntry_stat_impl(self, follow_symlinks); |
| 6596 | |
| 6597 | exit: |
| 6598 | return return_value; |
| 6599 | } |
| 6600 | |
| 6601 | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
| 6602 | "is_dir($self, /, *, follow_symlinks=True)\n" |
| 6603 | "--\n" |
| 6604 | "\n" |
| 6605 | "Return True if the entry is a directory; cached per entry."); |
| 6606 | |
| 6607 | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6608 | {"is_dir", (PyCFunction)(void(*)(void))os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__}, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6609 | |
| 6610 | static int |
| 6611 | os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks); |
| 6612 | |
| 6613 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6614 | os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6615 | { |
| 6616 | PyObject *return_value = NULL; |
| 6617 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
| 6618 | static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0}; |
| 6619 | int follow_symlinks = 1; |
| 6620 | int _return_value; |
| 6621 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6622 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6623 | &follow_symlinks)) { |
| 6624 | goto exit; |
| 6625 | } |
| 6626 | _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks); |
| 6627 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 6628 | goto exit; |
| 6629 | } |
| 6630 | return_value = PyBool_FromLong((long)_return_value); |
| 6631 | |
| 6632 | exit: |
| 6633 | return return_value; |
| 6634 | } |
| 6635 | |
| 6636 | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
| 6637 | "is_file($self, /, *, follow_symlinks=True)\n" |
| 6638 | "--\n" |
| 6639 | "\n" |
| 6640 | "Return True if the entry is a file; cached per entry."); |
| 6641 | |
| 6642 | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6643 | {"is_file", (PyCFunction)(void(*)(void))os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__}, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6644 | |
| 6645 | static int |
| 6646 | os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks); |
| 6647 | |
| 6648 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6649 | os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6650 | { |
| 6651 | PyObject *return_value = NULL; |
| 6652 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
| 6653 | static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0}; |
| 6654 | int follow_symlinks = 1; |
| 6655 | int _return_value; |
| 6656 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6657 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6658 | &follow_symlinks)) { |
| 6659 | goto exit; |
| 6660 | } |
| 6661 | _return_value = os_DirEntry_is_file_impl(self, follow_symlinks); |
| 6662 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 6663 | goto exit; |
| 6664 | } |
| 6665 | return_value = PyBool_FromLong((long)_return_value); |
| 6666 | |
| 6667 | exit: |
| 6668 | return return_value; |
| 6669 | } |
| 6670 | |
| 6671 | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
| 6672 | "inode($self, /)\n" |
| 6673 | "--\n" |
| 6674 | "\n" |
| 6675 | "Return inode of the entry; cached per entry."); |
| 6676 | |
| 6677 | #define OS_DIRENTRY_INODE_METHODDEF \ |
| 6678 | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
| 6679 | |
| 6680 | static PyObject * |
| 6681 | os_DirEntry_inode_impl(DirEntry *self); |
| 6682 | |
| 6683 | static PyObject * |
| 6684 | os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 6685 | { |
| 6686 | return os_DirEntry_inode_impl(self); |
| 6687 | } |
| 6688 | |
| 6689 | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
| 6690 | "__fspath__($self, /)\n" |
| 6691 | "--\n" |
| 6692 | "\n" |
| 6693 | "Returns the path for the entry."); |
| 6694 | |
| 6695 | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
| 6696 | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
| 6697 | |
| 6698 | static PyObject * |
| 6699 | os_DirEntry___fspath___impl(DirEntry *self); |
| 6700 | |
| 6701 | static PyObject * |
| 6702 | os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
| 6703 | { |
| 6704 | return os_DirEntry___fspath___impl(self); |
| 6705 | } |
| 6706 | |
| 6707 | PyDoc_STRVAR(os_scandir__doc__, |
| 6708 | "scandir($module, /, path=None)\n" |
| 6709 | "--\n" |
| 6710 | "\n" |
| 6711 | "Return an iterator of DirEntry objects for given path.\n" |
| 6712 | "\n" |
BNMetrics | b942707 | 2018-11-02 15:20:19 +0000 | [diff] [blame] | 6713 | "path can be specified as either str, bytes, or a path-like object. If path\n" |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6714 | "is bytes, the names of yielded DirEntry objects will also be bytes; in\n" |
| 6715 | "all other circumstances they will be str.\n" |
| 6716 | "\n" |
| 6717 | "If path is None, uses the path=\'.\'."); |
| 6718 | |
| 6719 | #define OS_SCANDIR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6720 | {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__}, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6721 | |
| 6722 | static PyObject * |
| 6723 | os_scandir_impl(PyObject *module, path_t *path); |
| 6724 | |
| 6725 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6726 | os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6727 | { |
| 6728 | PyObject *return_value = NULL; |
| 6729 | static const char * const _keywords[] = {"path", NULL}; |
| 6730 | static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0}; |
Serhiy Storchaka | ea720fe | 2017-03-30 09:12:31 +0300 | [diff] [blame] | 6731 | path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR); |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6732 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6733 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 49d02d1 | 2016-11-06 13:45:33 +0200 | [diff] [blame] | 6734 | path_converter, &path)) { |
| 6735 | goto exit; |
| 6736 | } |
| 6737 | return_value = os_scandir_impl(module, &path); |
| 6738 | |
| 6739 | exit: |
| 6740 | /* Cleanup for path */ |
| 6741 | path_cleanup(&path); |
| 6742 | |
| 6743 | return return_value; |
| 6744 | } |
| 6745 | |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6746 | PyDoc_STRVAR(os_fspath__doc__, |
| 6747 | "fspath($module, /, path)\n" |
| 6748 | "--\n" |
| 6749 | "\n" |
| 6750 | "Return the file system path representation of the object.\n" |
| 6751 | "\n" |
Brett Cannon | b4f43e9 | 2016-06-09 14:32:08 -0700 | [diff] [blame] | 6752 | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
| 6753 | "object defines __fspath__(), then return the result of that method. All other\n" |
| 6754 | "types raise a TypeError."); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6755 | |
| 6756 | #define OS_FSPATH_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6757 | {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__}, |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6758 | |
| 6759 | static PyObject * |
Serhiy Storchaka | 2954f83 | 2016-07-07 18:20:03 +0300 | [diff] [blame] | 6760 | os_fspath_impl(PyObject *module, PyObject *path); |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6761 | |
| 6762 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6763 | os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6764 | { |
| 6765 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 6766 | static const char * const _keywords[] = {"path", NULL}; |
| 6767 | static _PyArg_Parser _parser = {"O:fspath", _keywords, 0}; |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6768 | PyObject *path; |
| 6769 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6770 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6771 | &path)) { |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6772 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 6773 | } |
Ethan Furman | 410ef8e | 2016-06-04 12:06:26 -0700 | [diff] [blame] | 6774 | return_value = os_fspath_impl(module, path); |
| 6775 | |
| 6776 | exit: |
| 6777 | return return_value; |
| 6778 | } |
| 6779 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 6780 | #if defined(HAVE_GETRANDOM_SYSCALL) |
| 6781 | |
| 6782 | PyDoc_STRVAR(os_getrandom__doc__, |
| 6783 | "getrandom($module, /, size, flags=0)\n" |
| 6784 | "--\n" |
| 6785 | "\n" |
| 6786 | "Obtain a series of random bytes."); |
| 6787 | |
| 6788 | #define OS_GETRANDOM_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 6789 | {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__}, |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 6790 | |
| 6791 | static PyObject * |
| 6792 | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
| 6793 | |
| 6794 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 6795 | os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 6796 | { |
| 6797 | PyObject *return_value = NULL; |
| 6798 | static const char * const _keywords[] = {"size", "flags", NULL}; |
| 6799 | static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0}; |
| 6800 | Py_ssize_t size; |
| 6801 | int flags = 0; |
| 6802 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 6803 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 6804 | &size, &flags)) { |
| 6805 | goto exit; |
| 6806 | } |
| 6807 | return_value = os_getrandom_impl(module, size, flags); |
| 6808 | |
| 6809 | exit: |
| 6810 | return return_value; |
| 6811 | } |
| 6812 | |
| 6813 | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
| 6814 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6815 | #ifndef OS_TTYNAME_METHODDEF |
| 6816 | #define OS_TTYNAME_METHODDEF |
| 6817 | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
| 6818 | |
| 6819 | #ifndef OS_CTERMID_METHODDEF |
| 6820 | #define OS_CTERMID_METHODDEF |
| 6821 | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
| 6822 | |
| 6823 | #ifndef OS_FCHDIR_METHODDEF |
| 6824 | #define OS_FCHDIR_METHODDEF |
| 6825 | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
| 6826 | |
| 6827 | #ifndef OS_FCHMOD_METHODDEF |
| 6828 | #define OS_FCHMOD_METHODDEF |
| 6829 | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
| 6830 | |
| 6831 | #ifndef OS_LCHMOD_METHODDEF |
| 6832 | #define OS_LCHMOD_METHODDEF |
| 6833 | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
| 6834 | |
| 6835 | #ifndef OS_CHFLAGS_METHODDEF |
| 6836 | #define OS_CHFLAGS_METHODDEF |
| 6837 | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
| 6838 | |
| 6839 | #ifndef OS_LCHFLAGS_METHODDEF |
| 6840 | #define OS_LCHFLAGS_METHODDEF |
| 6841 | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
| 6842 | |
| 6843 | #ifndef OS_CHROOT_METHODDEF |
| 6844 | #define OS_CHROOT_METHODDEF |
| 6845 | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
| 6846 | |
| 6847 | #ifndef OS_FSYNC_METHODDEF |
| 6848 | #define OS_FSYNC_METHODDEF |
| 6849 | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
| 6850 | |
| 6851 | #ifndef OS_SYNC_METHODDEF |
| 6852 | #define OS_SYNC_METHODDEF |
| 6853 | #endif /* !defined(OS_SYNC_METHODDEF) */ |
| 6854 | |
| 6855 | #ifndef OS_FDATASYNC_METHODDEF |
| 6856 | #define OS_FDATASYNC_METHODDEF |
| 6857 | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
| 6858 | |
| 6859 | #ifndef OS_CHOWN_METHODDEF |
| 6860 | #define OS_CHOWN_METHODDEF |
| 6861 | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
| 6862 | |
| 6863 | #ifndef OS_FCHOWN_METHODDEF |
| 6864 | #define OS_FCHOWN_METHODDEF |
| 6865 | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
| 6866 | |
| 6867 | #ifndef OS_LCHOWN_METHODDEF |
| 6868 | #define OS_LCHOWN_METHODDEF |
| 6869 | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
| 6870 | |
| 6871 | #ifndef OS_LINK_METHODDEF |
| 6872 | #define OS_LINK_METHODDEF |
| 6873 | #endif /* !defined(OS_LINK_METHODDEF) */ |
| 6874 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 6875 | #ifndef OS__GETFULLPATHNAME_METHODDEF |
| 6876 | #define OS__GETFULLPATHNAME_METHODDEF |
| 6877 | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
| 6878 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6879 | #ifndef OS__GETFINALPATHNAME_METHODDEF |
| 6880 | #define OS__GETFINALPATHNAME_METHODDEF |
| 6881 | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
| 6882 | |
Serhiy Storchaka | f0b5015 | 2015-05-13 00:52:39 +0300 | [diff] [blame] | 6883 | #ifndef OS__ISDIR_METHODDEF |
| 6884 | #define OS__ISDIR_METHODDEF |
| 6885 | #endif /* !defined(OS__ISDIR_METHODDEF) */ |
| 6886 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6887 | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
| 6888 | #define OS__GETVOLUMEPATHNAME_METHODDEF |
| 6889 | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
| 6890 | |
| 6891 | #ifndef OS_NICE_METHODDEF |
| 6892 | #define OS_NICE_METHODDEF |
| 6893 | #endif /* !defined(OS_NICE_METHODDEF) */ |
| 6894 | |
| 6895 | #ifndef OS_GETPRIORITY_METHODDEF |
| 6896 | #define OS_GETPRIORITY_METHODDEF |
| 6897 | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
| 6898 | |
| 6899 | #ifndef OS_SETPRIORITY_METHODDEF |
| 6900 | #define OS_SETPRIORITY_METHODDEF |
| 6901 | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
| 6902 | |
| 6903 | #ifndef OS_SYSTEM_METHODDEF |
| 6904 | #define OS_SYSTEM_METHODDEF |
| 6905 | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
| 6906 | |
| 6907 | #ifndef OS_UNAME_METHODDEF |
| 6908 | #define OS_UNAME_METHODDEF |
| 6909 | #endif /* !defined(OS_UNAME_METHODDEF) */ |
| 6910 | |
| 6911 | #ifndef OS_EXECV_METHODDEF |
| 6912 | #define OS_EXECV_METHODDEF |
| 6913 | #endif /* !defined(OS_EXECV_METHODDEF) */ |
| 6914 | |
| 6915 | #ifndef OS_EXECVE_METHODDEF |
| 6916 | #define OS_EXECVE_METHODDEF |
| 6917 | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
| 6918 | |
Pablo Galindo | 6c6ddf9 | 2018-01-29 01:56:10 +0000 | [diff] [blame] | 6919 | #ifndef OS_POSIX_SPAWN_METHODDEF |
| 6920 | #define OS_POSIX_SPAWN_METHODDEF |
| 6921 | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
| 6922 | |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 6923 | #ifndef OS_POSIX_SPAWNP_METHODDEF |
| 6924 | #define OS_POSIX_SPAWNP_METHODDEF |
| 6925 | #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */ |
| 6926 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6927 | #ifndef OS_SPAWNV_METHODDEF |
| 6928 | #define OS_SPAWNV_METHODDEF |
| 6929 | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
| 6930 | |
| 6931 | #ifndef OS_SPAWNVE_METHODDEF |
| 6932 | #define OS_SPAWNVE_METHODDEF |
| 6933 | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
| 6934 | |
Antoine Pitrou | 346cbd3 | 2017-05-27 17:50:54 +0200 | [diff] [blame] | 6935 | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
| 6936 | #define OS_REGISTER_AT_FORK_METHODDEF |
| 6937 | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
| 6938 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 6939 | #ifndef OS_FORK1_METHODDEF |
| 6940 | #define OS_FORK1_METHODDEF |
| 6941 | #endif /* !defined(OS_FORK1_METHODDEF) */ |
| 6942 | |
| 6943 | #ifndef OS_FORK_METHODDEF |
| 6944 | #define OS_FORK_METHODDEF |
| 6945 | #endif /* !defined(OS_FORK_METHODDEF) */ |
| 6946 | |
| 6947 | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 6948 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
| 6949 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
| 6950 | |
| 6951 | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 6952 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
| 6953 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
| 6954 | |
| 6955 | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
| 6956 | #define OS_SCHED_GETSCHEDULER_METHODDEF |
| 6957 | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
| 6958 | |
| 6959 | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
| 6960 | #define OS_SCHED_SETSCHEDULER_METHODDEF |
| 6961 | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
| 6962 | |
| 6963 | #ifndef OS_SCHED_GETPARAM_METHODDEF |
| 6964 | #define OS_SCHED_GETPARAM_METHODDEF |
| 6965 | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
| 6966 | |
| 6967 | #ifndef OS_SCHED_SETPARAM_METHODDEF |
| 6968 | #define OS_SCHED_SETPARAM_METHODDEF |
| 6969 | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
| 6970 | |
| 6971 | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 6972 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
| 6973 | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
| 6974 | |
| 6975 | #ifndef OS_SCHED_YIELD_METHODDEF |
| 6976 | #define OS_SCHED_YIELD_METHODDEF |
| 6977 | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
| 6978 | |
| 6979 | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
| 6980 | #define OS_SCHED_SETAFFINITY_METHODDEF |
| 6981 | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
| 6982 | |
| 6983 | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
| 6984 | #define OS_SCHED_GETAFFINITY_METHODDEF |
| 6985 | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
| 6986 | |
| 6987 | #ifndef OS_OPENPTY_METHODDEF |
| 6988 | #define OS_OPENPTY_METHODDEF |
| 6989 | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
| 6990 | |
| 6991 | #ifndef OS_FORKPTY_METHODDEF |
| 6992 | #define OS_FORKPTY_METHODDEF |
| 6993 | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
| 6994 | |
| 6995 | #ifndef OS_GETEGID_METHODDEF |
| 6996 | #define OS_GETEGID_METHODDEF |
| 6997 | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
| 6998 | |
| 6999 | #ifndef OS_GETEUID_METHODDEF |
| 7000 | #define OS_GETEUID_METHODDEF |
| 7001 | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
| 7002 | |
| 7003 | #ifndef OS_GETGID_METHODDEF |
| 7004 | #define OS_GETGID_METHODDEF |
| 7005 | #endif /* !defined(OS_GETGID_METHODDEF) */ |
| 7006 | |
Berker Peksag | 3940499 | 2016-09-15 20:45:16 +0300 | [diff] [blame] | 7007 | #ifndef OS_GETPID_METHODDEF |
| 7008 | #define OS_GETPID_METHODDEF |
| 7009 | #endif /* !defined(OS_GETPID_METHODDEF) */ |
| 7010 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7011 | #ifndef OS_GETGROUPS_METHODDEF |
| 7012 | #define OS_GETGROUPS_METHODDEF |
| 7013 | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
| 7014 | |
| 7015 | #ifndef OS_GETPGID_METHODDEF |
| 7016 | #define OS_GETPGID_METHODDEF |
| 7017 | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
| 7018 | |
| 7019 | #ifndef OS_GETPGRP_METHODDEF |
| 7020 | #define OS_GETPGRP_METHODDEF |
| 7021 | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
| 7022 | |
| 7023 | #ifndef OS_SETPGRP_METHODDEF |
| 7024 | #define OS_SETPGRP_METHODDEF |
| 7025 | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
| 7026 | |
| 7027 | #ifndef OS_GETPPID_METHODDEF |
| 7028 | #define OS_GETPPID_METHODDEF |
| 7029 | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
| 7030 | |
| 7031 | #ifndef OS_GETLOGIN_METHODDEF |
| 7032 | #define OS_GETLOGIN_METHODDEF |
| 7033 | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
| 7034 | |
| 7035 | #ifndef OS_GETUID_METHODDEF |
| 7036 | #define OS_GETUID_METHODDEF |
| 7037 | #endif /* !defined(OS_GETUID_METHODDEF) */ |
| 7038 | |
| 7039 | #ifndef OS_KILL_METHODDEF |
| 7040 | #define OS_KILL_METHODDEF |
| 7041 | #endif /* !defined(OS_KILL_METHODDEF) */ |
| 7042 | |
| 7043 | #ifndef OS_KILLPG_METHODDEF |
| 7044 | #define OS_KILLPG_METHODDEF |
| 7045 | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
| 7046 | |
| 7047 | #ifndef OS_PLOCK_METHODDEF |
| 7048 | #define OS_PLOCK_METHODDEF |
| 7049 | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
| 7050 | |
| 7051 | #ifndef OS_SETUID_METHODDEF |
| 7052 | #define OS_SETUID_METHODDEF |
| 7053 | #endif /* !defined(OS_SETUID_METHODDEF) */ |
| 7054 | |
| 7055 | #ifndef OS_SETEUID_METHODDEF |
| 7056 | #define OS_SETEUID_METHODDEF |
| 7057 | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
| 7058 | |
| 7059 | #ifndef OS_SETEGID_METHODDEF |
| 7060 | #define OS_SETEGID_METHODDEF |
| 7061 | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
| 7062 | |
| 7063 | #ifndef OS_SETREUID_METHODDEF |
| 7064 | #define OS_SETREUID_METHODDEF |
| 7065 | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
| 7066 | |
| 7067 | #ifndef OS_SETREGID_METHODDEF |
| 7068 | #define OS_SETREGID_METHODDEF |
| 7069 | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
| 7070 | |
| 7071 | #ifndef OS_SETGID_METHODDEF |
| 7072 | #define OS_SETGID_METHODDEF |
| 7073 | #endif /* !defined(OS_SETGID_METHODDEF) */ |
| 7074 | |
| 7075 | #ifndef OS_SETGROUPS_METHODDEF |
| 7076 | #define OS_SETGROUPS_METHODDEF |
| 7077 | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
| 7078 | |
| 7079 | #ifndef OS_WAIT3_METHODDEF |
| 7080 | #define OS_WAIT3_METHODDEF |
| 7081 | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
| 7082 | |
| 7083 | #ifndef OS_WAIT4_METHODDEF |
| 7084 | #define OS_WAIT4_METHODDEF |
| 7085 | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
| 7086 | |
| 7087 | #ifndef OS_WAITID_METHODDEF |
| 7088 | #define OS_WAITID_METHODDEF |
| 7089 | #endif /* !defined(OS_WAITID_METHODDEF) */ |
| 7090 | |
| 7091 | #ifndef OS_WAITPID_METHODDEF |
| 7092 | #define OS_WAITPID_METHODDEF |
| 7093 | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
| 7094 | |
| 7095 | #ifndef OS_WAIT_METHODDEF |
| 7096 | #define OS_WAIT_METHODDEF |
| 7097 | #endif /* !defined(OS_WAIT_METHODDEF) */ |
| 7098 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7099 | #ifndef OS_READLINK_METHODDEF |
| 7100 | #define OS_READLINK_METHODDEF |
| 7101 | #endif /* !defined(OS_READLINK_METHODDEF) */ |
| 7102 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7103 | #ifndef OS_SYMLINK_METHODDEF |
| 7104 | #define OS_SYMLINK_METHODDEF |
| 7105 | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
| 7106 | |
| 7107 | #ifndef OS_TIMES_METHODDEF |
| 7108 | #define OS_TIMES_METHODDEF |
| 7109 | #endif /* !defined(OS_TIMES_METHODDEF) */ |
| 7110 | |
| 7111 | #ifndef OS_GETSID_METHODDEF |
| 7112 | #define OS_GETSID_METHODDEF |
| 7113 | #endif /* !defined(OS_GETSID_METHODDEF) */ |
| 7114 | |
| 7115 | #ifndef OS_SETSID_METHODDEF |
| 7116 | #define OS_SETSID_METHODDEF |
| 7117 | #endif /* !defined(OS_SETSID_METHODDEF) */ |
| 7118 | |
| 7119 | #ifndef OS_SETPGID_METHODDEF |
| 7120 | #define OS_SETPGID_METHODDEF |
| 7121 | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
| 7122 | |
| 7123 | #ifndef OS_TCGETPGRP_METHODDEF |
| 7124 | #define OS_TCGETPGRP_METHODDEF |
| 7125 | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
| 7126 | |
| 7127 | #ifndef OS_TCSETPGRP_METHODDEF |
| 7128 | #define OS_TCSETPGRP_METHODDEF |
| 7129 | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
| 7130 | |
| 7131 | #ifndef OS_LOCKF_METHODDEF |
| 7132 | #define OS_LOCKF_METHODDEF |
| 7133 | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
| 7134 | |
| 7135 | #ifndef OS_READV_METHODDEF |
| 7136 | #define OS_READV_METHODDEF |
| 7137 | #endif /* !defined(OS_READV_METHODDEF) */ |
| 7138 | |
| 7139 | #ifndef OS_PREAD_METHODDEF |
| 7140 | #define OS_PREAD_METHODDEF |
| 7141 | #endif /* !defined(OS_PREAD_METHODDEF) */ |
| 7142 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 7143 | #ifndef OS_PREADV_METHODDEF |
| 7144 | #define OS_PREADV_METHODDEF |
| 7145 | #endif /* !defined(OS_PREADV_METHODDEF) */ |
| 7146 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 7147 | #ifndef OS__FCOPYFILE_METHODDEF |
| 7148 | #define OS__FCOPYFILE_METHODDEF |
| 7149 | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
| 7150 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7151 | #ifndef OS_PIPE_METHODDEF |
| 7152 | #define OS_PIPE_METHODDEF |
| 7153 | #endif /* !defined(OS_PIPE_METHODDEF) */ |
| 7154 | |
| 7155 | #ifndef OS_PIPE2_METHODDEF |
| 7156 | #define OS_PIPE2_METHODDEF |
| 7157 | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
| 7158 | |
| 7159 | #ifndef OS_WRITEV_METHODDEF |
| 7160 | #define OS_WRITEV_METHODDEF |
| 7161 | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
| 7162 | |
| 7163 | #ifndef OS_PWRITE_METHODDEF |
| 7164 | #define OS_PWRITE_METHODDEF |
| 7165 | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
| 7166 | |
Pablo Galindo | 4defba3 | 2018-01-27 16:16:37 +0000 | [diff] [blame] | 7167 | #ifndef OS_PWRITEV_METHODDEF |
| 7168 | #define OS_PWRITEV_METHODDEF |
| 7169 | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
| 7170 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7171 | #ifndef OS_MKFIFO_METHODDEF |
| 7172 | #define OS_MKFIFO_METHODDEF |
| 7173 | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
| 7174 | |
| 7175 | #ifndef OS_MKNOD_METHODDEF |
| 7176 | #define OS_MKNOD_METHODDEF |
| 7177 | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
| 7178 | |
| 7179 | #ifndef OS_MAJOR_METHODDEF |
| 7180 | #define OS_MAJOR_METHODDEF |
| 7181 | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
| 7182 | |
| 7183 | #ifndef OS_MINOR_METHODDEF |
| 7184 | #define OS_MINOR_METHODDEF |
| 7185 | #endif /* !defined(OS_MINOR_METHODDEF) */ |
| 7186 | |
| 7187 | #ifndef OS_MAKEDEV_METHODDEF |
| 7188 | #define OS_MAKEDEV_METHODDEF |
| 7189 | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
| 7190 | |
| 7191 | #ifndef OS_FTRUNCATE_METHODDEF |
| 7192 | #define OS_FTRUNCATE_METHODDEF |
| 7193 | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
| 7194 | |
| 7195 | #ifndef OS_TRUNCATE_METHODDEF |
| 7196 | #define OS_TRUNCATE_METHODDEF |
| 7197 | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
| 7198 | |
| 7199 | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
| 7200 | #define OS_POSIX_FALLOCATE_METHODDEF |
| 7201 | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
| 7202 | |
| 7203 | #ifndef OS_POSIX_FADVISE_METHODDEF |
| 7204 | #define OS_POSIX_FADVISE_METHODDEF |
| 7205 | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
| 7206 | |
| 7207 | #ifndef OS_PUTENV_METHODDEF |
| 7208 | #define OS_PUTENV_METHODDEF |
| 7209 | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
| 7210 | |
| 7211 | #ifndef OS_UNSETENV_METHODDEF |
| 7212 | #define OS_UNSETENV_METHODDEF |
| 7213 | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
| 7214 | |
| 7215 | #ifndef OS_WCOREDUMP_METHODDEF |
| 7216 | #define OS_WCOREDUMP_METHODDEF |
| 7217 | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
| 7218 | |
| 7219 | #ifndef OS_WIFCONTINUED_METHODDEF |
| 7220 | #define OS_WIFCONTINUED_METHODDEF |
| 7221 | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
| 7222 | |
| 7223 | #ifndef OS_WIFSTOPPED_METHODDEF |
| 7224 | #define OS_WIFSTOPPED_METHODDEF |
| 7225 | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
| 7226 | |
| 7227 | #ifndef OS_WIFSIGNALED_METHODDEF |
| 7228 | #define OS_WIFSIGNALED_METHODDEF |
| 7229 | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
| 7230 | |
| 7231 | #ifndef OS_WIFEXITED_METHODDEF |
| 7232 | #define OS_WIFEXITED_METHODDEF |
| 7233 | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
| 7234 | |
| 7235 | #ifndef OS_WEXITSTATUS_METHODDEF |
| 7236 | #define OS_WEXITSTATUS_METHODDEF |
| 7237 | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
| 7238 | |
| 7239 | #ifndef OS_WTERMSIG_METHODDEF |
| 7240 | #define OS_WTERMSIG_METHODDEF |
| 7241 | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
| 7242 | |
| 7243 | #ifndef OS_WSTOPSIG_METHODDEF |
| 7244 | #define OS_WSTOPSIG_METHODDEF |
| 7245 | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
| 7246 | |
| 7247 | #ifndef OS_FSTATVFS_METHODDEF |
| 7248 | #define OS_FSTATVFS_METHODDEF |
| 7249 | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
| 7250 | |
| 7251 | #ifndef OS_STATVFS_METHODDEF |
| 7252 | #define OS_STATVFS_METHODDEF |
| 7253 | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
| 7254 | |
| 7255 | #ifndef OS__GETDISKUSAGE_METHODDEF |
| 7256 | #define OS__GETDISKUSAGE_METHODDEF |
| 7257 | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
| 7258 | |
| 7259 | #ifndef OS_FPATHCONF_METHODDEF |
| 7260 | #define OS_FPATHCONF_METHODDEF |
| 7261 | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
| 7262 | |
| 7263 | #ifndef OS_PATHCONF_METHODDEF |
| 7264 | #define OS_PATHCONF_METHODDEF |
| 7265 | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
| 7266 | |
| 7267 | #ifndef OS_CONFSTR_METHODDEF |
| 7268 | #define OS_CONFSTR_METHODDEF |
| 7269 | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
| 7270 | |
| 7271 | #ifndef OS_SYSCONF_METHODDEF |
| 7272 | #define OS_SYSCONF_METHODDEF |
| 7273 | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
| 7274 | |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 7275 | #ifndef OS_STARTFILE_METHODDEF |
| 7276 | #define OS_STARTFILE_METHODDEF |
| 7277 | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
| 7278 | |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7279 | #ifndef OS_GETLOADAVG_METHODDEF |
| 7280 | #define OS_GETLOADAVG_METHODDEF |
| 7281 | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
| 7282 | |
| 7283 | #ifndef OS_SETRESUID_METHODDEF |
| 7284 | #define OS_SETRESUID_METHODDEF |
| 7285 | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
| 7286 | |
| 7287 | #ifndef OS_SETRESGID_METHODDEF |
| 7288 | #define OS_SETRESGID_METHODDEF |
| 7289 | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
| 7290 | |
| 7291 | #ifndef OS_GETRESUID_METHODDEF |
| 7292 | #define OS_GETRESUID_METHODDEF |
| 7293 | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
| 7294 | |
| 7295 | #ifndef OS_GETRESGID_METHODDEF |
| 7296 | #define OS_GETRESGID_METHODDEF |
| 7297 | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
| 7298 | |
| 7299 | #ifndef OS_GETXATTR_METHODDEF |
| 7300 | #define OS_GETXATTR_METHODDEF |
| 7301 | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
| 7302 | |
| 7303 | #ifndef OS_SETXATTR_METHODDEF |
| 7304 | #define OS_SETXATTR_METHODDEF |
| 7305 | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
| 7306 | |
| 7307 | #ifndef OS_REMOVEXATTR_METHODDEF |
| 7308 | #define OS_REMOVEXATTR_METHODDEF |
| 7309 | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
| 7310 | |
| 7311 | #ifndef OS_LISTXATTR_METHODDEF |
| 7312 | #define OS_LISTXATTR_METHODDEF |
| 7313 | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
| 7314 | |
| 7315 | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 7316 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
| 7317 | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
| 7318 | |
| 7319 | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 7320 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
| 7321 | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 7322 | |
Serhiy Storchaka | 12a69db | 2018-09-17 15:38:27 +0300 | [diff] [blame] | 7323 | #ifndef OS_GET_BLOCKING_METHODDEF |
| 7324 | #define OS_GET_BLOCKING_METHODDEF |
| 7325 | #endif /* !defined(OS_GET_BLOCKING_METHODDEF) */ |
| 7326 | |
| 7327 | #ifndef OS_SET_BLOCKING_METHODDEF |
| 7328 | #define OS_SET_BLOCKING_METHODDEF |
| 7329 | #endif /* !defined(OS_SET_BLOCKING_METHODDEF) */ |
| 7330 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 7331 | #ifndef OS_GETRANDOM_METHODDEF |
| 7332 | #define OS_GETRANDOM_METHODDEF |
| 7333 | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
Joannah Nanjekye | 92b8322 | 2019-01-16 16:29:26 +0300 | [diff] [blame] | 7334 | /*[clinic end generated code: output=dabd0fa27bf87044 input=a9049054013a1b77]*/ |