blob: 56010f408ccfe4daccd8dd9309f9752082932b2e [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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"
BNMetricsb9427072018-11-02 15:20:19 +000012" Path to be examined; can be string, bytes, a path-like object or\n"
Xiang Zhang4459e002017-01-22 13:04:17 +080013" open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030014" 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 Storchaka6969eaf2017-07-03 21:20:15 +030031 {"stat", (PyCFunction)os_stat, METH_FASTCALL|METH_KEYWORDS, os_stat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030032
33static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030034os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030035
36static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020037os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030038{
39 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030040 static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
41 static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030042 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
43 int dir_fd = DEFAULT_DIR_FD;
44 int follow_symlinks = 1;
45
Victor Stinner3e1fad62017-01-17 01:29:01 +010046 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030047 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030048 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030049 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030050 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
51
52exit:
53 /* Cleanup for path */
54 path_cleanup(&path);
55
56 return return_value;
57}
58
59PyDoc_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 Storchaka6969eaf2017-07-03 21:20:15 +030069 {"lstat", (PyCFunction)os_lstat, METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030070
71static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030072os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030073
74static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020075os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030076{
77 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030078 static const char * const _keywords[] = {"path", "dir_fd", NULL};
79 static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030080 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
81 int dir_fd = DEFAULT_DIR_FD;
82
Victor Stinner3e1fad62017-01-17 01:29:01 +010083 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030084 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030087 return_value = os_lstat_impl(module, &path, dir_fd);
88
89exit:
90 /* Cleanup for path */
91 path_cleanup(&path);
92
93 return return_value;
94}
95
96PyDoc_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"
BNMetricsb9427072018-11-02 15:20:19 +0000104" Path to be tested; can be string, bytes, or a path-like object.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300105" 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 Storchaka6969eaf2017-07-03 21:20:15 +0300129 {"access", (PyCFunction)os_access, METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130
131static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300132os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400133 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300134
135static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200136os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300137{
138 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300139 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 Peterson768f3b42016-09-05 15:29:33 -0700141 path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300142 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 Stinner3e1fad62017-01-17 01:29:01 +0100148 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300149 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300150 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300151 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300152 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300153 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300154 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300155 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300156 return_value = PyBool_FromLong((long)_return_value);
157
158exit:
159 /* Cleanup for path */
160 path_cleanup(&path);
161
162 return return_value;
163}
164
165#if defined(HAVE_TTYNAME)
166
167PyDoc_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 Storchaka92e8af62015-04-04 00:12:11 +0300177 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300178
179static char *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300180os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300181
182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300183os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300184{
185 PyObject *return_value = NULL;
186 int fd;
187 char *_return_value;
188
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300189 if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300190 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300191 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300192 _return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300193 if (_return_value == NULL) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300194 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300195 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300196 return_value = PyUnicode_DecodeFSDefault(_return_value);
197
198exit:
199 return return_value;
200}
201
202#endif /* defined(HAVE_TTYNAME) */
203
204#if defined(HAVE_CTERMID)
205
206PyDoc_STRVAR(os_ctermid__doc__,
207"ctermid($module, /)\n"
208"--\n"
209"\n"
210"Return the name of the controlling terminal for this process.");
211
212#define OS_CTERMID_METHODDEF \
213 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
214
215static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300216os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300217
218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300219os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300220{
221 return os_ctermid_impl(module);
222}
223
224#endif /* defined(HAVE_CTERMID) */
225
226PyDoc_STRVAR(os_chdir__doc__,
227"chdir($module, /, path)\n"
228"--\n"
229"\n"
230"Change the current working directory to the specified path.\n"
231"\n"
232"path may always be specified as a string.\n"
233"On some platforms, path may also be specified as an open file descriptor.\n"
234" If this functionality is unavailable, using it raises an exception.");
235
236#define OS_CHDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300237 {"chdir", (PyCFunction)os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300238
239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300240os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300241
242static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200243os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300244{
245 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300246 static const char * const _keywords[] = {"path", NULL};
247 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300248 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
249
Victor Stinner3e1fad62017-01-17 01:29:01 +0100250 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300251 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300252 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300253 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300254 return_value = os_chdir_impl(module, &path);
255
256exit:
257 /* Cleanup for path */
258 path_cleanup(&path);
259
260 return return_value;
261}
262
263#if defined(HAVE_FCHDIR)
264
265PyDoc_STRVAR(os_fchdir__doc__,
266"fchdir($module, /, fd)\n"
267"--\n"
268"\n"
269"Change to the directory of the given file descriptor.\n"
270"\n"
271"fd must be opened on a directory, not a file.\n"
272"Equivalent to os.chdir(fd).");
273
274#define OS_FCHDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300275 {"fchdir", (PyCFunction)os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300276
277static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300278os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300279
280static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200281os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300282{
283 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300284 static const char * const _keywords[] = {"fd", NULL};
285 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300286 int fd;
287
Victor Stinner3e1fad62017-01-17 01:29:01 +0100288 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300289 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300290 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300291 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300292 return_value = os_fchdir_impl(module, fd);
293
294exit:
295 return return_value;
296}
297
298#endif /* defined(HAVE_FCHDIR) */
299
300PyDoc_STRVAR(os_chmod__doc__,
301"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
302"--\n"
303"\n"
304"Change the access permissions of a file.\n"
305"\n"
306" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000307" Path to be modified. May always be specified as a str, bytes, or a path-like object.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300308" On some platforms, path may also be specified as an open file descriptor.\n"
309" If this functionality is unavailable, using it raises an exception.\n"
310" mode\n"
311" Operating-system mode bitfield.\n"
312" dir_fd\n"
313" If not None, it should be a file descriptor open to a directory,\n"
314" and path should be relative; path will then be relative to that\n"
315" directory.\n"
316" follow_symlinks\n"
317" If False, and the last element of the path is a symbolic link,\n"
318" chmod will modify the symbolic link itself instead of the file\n"
319" the link points to.\n"
320"\n"
321"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
322" an open file descriptor.\n"
323"dir_fd and follow_symlinks may not be implemented on your platform.\n"
324" If they are unavailable, using them will raise a NotImplementedError.");
325
326#define OS_CHMOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300327 {"chmod", (PyCFunction)os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300328
329static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300330os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400331 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300332
333static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200334os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300335{
336 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300337 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
338 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300339 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
340 int mode;
341 int dir_fd = DEFAULT_DIR_FD;
342 int follow_symlinks = 1;
343
Victor Stinner3e1fad62017-01-17 01:29:01 +0100344 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300345 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300346 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300347 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300348 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
349
350exit:
351 /* Cleanup for path */
352 path_cleanup(&path);
353
354 return return_value;
355}
356
357#if defined(HAVE_FCHMOD)
358
359PyDoc_STRVAR(os_fchmod__doc__,
360"fchmod($module, /, fd, mode)\n"
361"--\n"
362"\n"
363"Change the access permissions of the file given by file descriptor fd.\n"
364"\n"
365"Equivalent to os.chmod(fd, mode).");
366
367#define OS_FCHMOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300368 {"fchmod", (PyCFunction)os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300369
370static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300371os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300372
373static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200374os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300375{
376 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300377 static const char * const _keywords[] = {"fd", "mode", NULL};
378 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300379 int fd;
380 int mode;
381
Victor Stinner3e1fad62017-01-17 01:29:01 +0100382 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300383 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300386 return_value = os_fchmod_impl(module, fd, mode);
387
388exit:
389 return return_value;
390}
391
392#endif /* defined(HAVE_FCHMOD) */
393
394#if defined(HAVE_LCHMOD)
395
396PyDoc_STRVAR(os_lchmod__doc__,
397"lchmod($module, /, path, mode)\n"
398"--\n"
399"\n"
400"Change the access permissions of a file, without following symbolic links.\n"
401"\n"
402"If path is a symlink, this affects the link itself rather than the target.\n"
403"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
404
405#define OS_LCHMOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300406 {"lchmod", (PyCFunction)os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300407
408static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300409os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300410
411static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200412os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300413{
414 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300415 static const char * const _keywords[] = {"path", "mode", NULL};
416 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300417 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
418 int mode;
419
Victor Stinner3e1fad62017-01-17 01:29:01 +0100420 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300421 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300424 return_value = os_lchmod_impl(module, &path, mode);
425
426exit:
427 /* Cleanup for path */
428 path_cleanup(&path);
429
430 return return_value;
431}
432
433#endif /* defined(HAVE_LCHMOD) */
434
435#if defined(HAVE_CHFLAGS)
436
437PyDoc_STRVAR(os_chflags__doc__,
438"chflags($module, /, path, flags, follow_symlinks=True)\n"
439"--\n"
440"\n"
441"Set file flags.\n"
442"\n"
443"If follow_symlinks is False, and the last element of the path is a symbolic\n"
444" link, chflags will change flags on the symbolic link itself instead of the\n"
445" file the link points to.\n"
446"follow_symlinks may not be implemented on your platform. If it is\n"
447"unavailable, using it will raise a NotImplementedError.");
448
449#define OS_CHFLAGS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300450 {"chflags", (PyCFunction)os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300451
452static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300453os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400454 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300455
456static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200457os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300458{
459 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300460 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
461 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300462 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
463 unsigned long flags;
464 int follow_symlinks = 1;
465
Victor Stinner3e1fad62017-01-17 01:29:01 +0100466 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300467 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300468 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300469 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300470 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
471
472exit:
473 /* Cleanup for path */
474 path_cleanup(&path);
475
476 return return_value;
477}
478
479#endif /* defined(HAVE_CHFLAGS) */
480
481#if defined(HAVE_LCHFLAGS)
482
483PyDoc_STRVAR(os_lchflags__doc__,
484"lchflags($module, /, path, flags)\n"
485"--\n"
486"\n"
487"Set file flags.\n"
488"\n"
489"This function will not follow symbolic links.\n"
490"Equivalent to chflags(path, flags, follow_symlinks=False).");
491
492#define OS_LCHFLAGS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300493 {"lchflags", (PyCFunction)os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300494
495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300496os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300497
498static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200499os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300500{
501 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300502 static const char * const _keywords[] = {"path", "flags", NULL};
503 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
505 unsigned long flags;
506
Victor Stinner3e1fad62017-01-17 01:29:01 +0100507 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300508 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300511 return_value = os_lchflags_impl(module, &path, flags);
512
513exit:
514 /* Cleanup for path */
515 path_cleanup(&path);
516
517 return return_value;
518}
519
520#endif /* defined(HAVE_LCHFLAGS) */
521
522#if defined(HAVE_CHROOT)
523
524PyDoc_STRVAR(os_chroot__doc__,
525"chroot($module, /, path)\n"
526"--\n"
527"\n"
528"Change root directory to path.");
529
530#define OS_CHROOT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300531 {"chroot", (PyCFunction)os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300532
533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300534os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300535
536static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200537os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300538{
539 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300540 static const char * const _keywords[] = {"path", NULL};
541 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300542 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
543
Victor Stinner3e1fad62017-01-17 01:29:01 +0100544 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300545 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300546 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300547 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300548 return_value = os_chroot_impl(module, &path);
549
550exit:
551 /* Cleanup for path */
552 path_cleanup(&path);
553
554 return return_value;
555}
556
557#endif /* defined(HAVE_CHROOT) */
558
559#if defined(HAVE_FSYNC)
560
561PyDoc_STRVAR(os_fsync__doc__,
562"fsync($module, /, fd)\n"
563"--\n"
564"\n"
565"Force write of fd to disk.");
566
567#define OS_FSYNC_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300568 {"fsync", (PyCFunction)os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300569
570static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300571os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300572
573static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200574os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300575{
576 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300577 static const char * const _keywords[] = {"fd", NULL};
578 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300579 int fd;
580
Victor Stinner3e1fad62017-01-17 01:29:01 +0100581 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300582 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300583 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300584 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300585 return_value = os_fsync_impl(module, fd);
586
587exit:
588 return return_value;
589}
590
591#endif /* defined(HAVE_FSYNC) */
592
593#if defined(HAVE_SYNC)
594
595PyDoc_STRVAR(os_sync__doc__,
596"sync($module, /)\n"
597"--\n"
598"\n"
599"Force write of everything to disk.");
600
601#define OS_SYNC_METHODDEF \
602 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
603
604static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300605os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300606
607static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300608os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300609{
610 return os_sync_impl(module);
611}
612
613#endif /* defined(HAVE_SYNC) */
614
615#if defined(HAVE_FDATASYNC)
616
617PyDoc_STRVAR(os_fdatasync__doc__,
618"fdatasync($module, /, fd)\n"
619"--\n"
620"\n"
621"Force write of fd to disk without forcing update of metadata.");
622
623#define OS_FDATASYNC_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300624 {"fdatasync", (PyCFunction)os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300625
626static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300627os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300628
629static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200630os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300631{
632 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300633 static const char * const _keywords[] = {"fd", NULL};
634 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300635 int fd;
636
Victor Stinner3e1fad62017-01-17 01:29:01 +0100637 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300638 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300639 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300640 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300641 return_value = os_fdatasync_impl(module, fd);
642
643exit:
644 return return_value;
645}
646
647#endif /* defined(HAVE_FDATASYNC) */
648
649#if defined(HAVE_CHOWN)
650
651PyDoc_STRVAR(os_chown__doc__,
652"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
653"--\n"
654"\n"
655"Change the owner and group id of path to the numeric uid and gid.\\\n"
656"\n"
657" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000658" Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300659" dir_fd\n"
660" If not None, it should be a file descriptor open to a directory,\n"
661" and path should be relative; path will then be relative to that\n"
662" directory.\n"
663" follow_symlinks\n"
664" If False, and the last element of the path is a symbolic link,\n"
665" stat will examine the symbolic link itself instead of the file\n"
666" the link points to.\n"
667"\n"
668"path may always be specified as a string.\n"
669"On some platforms, path may also be specified as an open file descriptor.\n"
670" If this functionality is unavailable, using it raises an exception.\n"
671"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
672" and path should be relative; path will then be relative to that directory.\n"
673"If follow_symlinks is False, and the last element of the path is a symbolic\n"
674" link, chown will modify the symbolic link itself instead of the file the\n"
675" link points to.\n"
676"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
677" an open file descriptor.\n"
678"dir_fd and follow_symlinks may not be implemented on your platform.\n"
679" If they are unavailable, using them will raise a NotImplementedError.");
680
681#define OS_CHOWN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300682 {"chown", (PyCFunction)os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300683
684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300685os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400686 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300687
688static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200689os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300690{
691 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300692 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
693 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300694 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
695 uid_t uid;
696 gid_t gid;
697 int dir_fd = DEFAULT_DIR_FD;
698 int follow_symlinks = 1;
699
Victor Stinner3e1fad62017-01-17 01:29:01 +0100700 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300701 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300702 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300703 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300704 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
705
706exit:
707 /* Cleanup for path */
708 path_cleanup(&path);
709
710 return return_value;
711}
712
713#endif /* defined(HAVE_CHOWN) */
714
715#if defined(HAVE_FCHOWN)
716
717PyDoc_STRVAR(os_fchown__doc__,
718"fchown($module, /, fd, uid, gid)\n"
719"--\n"
720"\n"
721"Change the owner and group id of the file specified by file descriptor.\n"
722"\n"
723"Equivalent to os.chown(fd, uid, gid).");
724
725#define OS_FCHOWN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300726 {"fchown", (PyCFunction)os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300727
728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300729os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300730
731static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200732os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300733{
734 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300735 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
736 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300737 int fd;
738 uid_t uid;
739 gid_t gid;
740
Victor Stinner3e1fad62017-01-17 01:29:01 +0100741 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300742 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300743 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300744 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300745 return_value = os_fchown_impl(module, fd, uid, gid);
746
747exit:
748 return return_value;
749}
750
751#endif /* defined(HAVE_FCHOWN) */
752
753#if defined(HAVE_LCHOWN)
754
755PyDoc_STRVAR(os_lchown__doc__,
756"lchown($module, /, path, uid, gid)\n"
757"--\n"
758"\n"
759"Change the owner and group id of path to the numeric uid and gid.\n"
760"\n"
761"This function will not follow symbolic links.\n"
762"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
763
764#define OS_LCHOWN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300765 {"lchown", (PyCFunction)os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300766
767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300768os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300769
770static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200771os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300772{
773 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300774 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
775 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300776 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
777 uid_t uid;
778 gid_t gid;
779
Victor Stinner3e1fad62017-01-17 01:29:01 +0100780 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300781 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300782 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300783 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300784 return_value = os_lchown_impl(module, &path, uid, gid);
785
786exit:
787 /* Cleanup for path */
788 path_cleanup(&path);
789
790 return return_value;
791}
792
793#endif /* defined(HAVE_LCHOWN) */
794
795PyDoc_STRVAR(os_getcwd__doc__,
796"getcwd($module, /)\n"
797"--\n"
798"\n"
799"Return a unicode string representing the current working directory.");
800
801#define OS_GETCWD_METHODDEF \
802 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
803
804static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300805os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300806
807static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300808os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300809{
810 return os_getcwd_impl(module);
811}
812
813PyDoc_STRVAR(os_getcwdb__doc__,
814"getcwdb($module, /)\n"
815"--\n"
816"\n"
817"Return a bytes string representing the current working directory.");
818
819#define OS_GETCWDB_METHODDEF \
820 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
821
822static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300823os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300824
825static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300826os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300827{
828 return os_getcwdb_impl(module);
829}
830
831#if defined(HAVE_LINK)
832
833PyDoc_STRVAR(os_link__doc__,
834"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
835" follow_symlinks=True)\n"
836"--\n"
837"\n"
838"Create a hard link to a file.\n"
839"\n"
840"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
841" descriptor open to a directory, and the respective path string (src or dst)\n"
842" should be relative; the path will then be relative to that directory.\n"
843"If follow_symlinks is False, and the last element of src is a symbolic\n"
844" link, link will create a link to the symbolic link itself instead of the\n"
845" file the link points to.\n"
846"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
847" platform. If they are unavailable, using them will raise a\n"
848" NotImplementedError.");
849
850#define OS_LINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300851 {"link", (PyCFunction)os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300852
853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300854os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400855 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300856
857static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200858os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300859{
860 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300861 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
862 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300863 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
864 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
865 int src_dir_fd = DEFAULT_DIR_FD;
866 int dst_dir_fd = DEFAULT_DIR_FD;
867 int follow_symlinks = 1;
868
Victor Stinner3e1fad62017-01-17 01:29:01 +0100869 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300870 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300871 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300872 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300873 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
874
875exit:
876 /* Cleanup for src */
877 path_cleanup(&src);
878 /* Cleanup for dst */
879 path_cleanup(&dst);
880
881 return return_value;
882}
883
884#endif /* defined(HAVE_LINK) */
885
886PyDoc_STRVAR(os_listdir__doc__,
887"listdir($module, /, path=None)\n"
888"--\n"
889"\n"
890"Return a list containing the names of the files in the directory.\n"
891"\n"
BNMetricsb9427072018-11-02 15:20:19 +0000892"path can be specified as either str, bytes, or a path-like object. If path is bytes,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300893" the filenames returned will also be bytes; in all other circumstances\n"
894" the filenames returned will be str.\n"
895"If path is None, uses the path=\'.\'.\n"
896"On some platforms, path may also be specified as an open file descriptor;\\\n"
897" the file descriptor must refer to a directory.\n"
898" If this functionality is unavailable, using it raises NotImplementedError.\n"
899"\n"
900"The list is in arbitrary order. It does not include the special\n"
901"entries \'.\' and \'..\' even if they are present in the directory.");
902
903#define OS_LISTDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300904 {"listdir", (PyCFunction)os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300905
906static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300907os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300908
909static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200910os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300911{
912 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300913 static const char * const _keywords[] = {"path", NULL};
914 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300915 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
916
Victor Stinner3e1fad62017-01-17 01:29:01 +0100917 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300918 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300919 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300920 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300921 return_value = os_listdir_impl(module, &path);
922
923exit:
924 /* Cleanup for path */
925 path_cleanup(&path);
926
927 return return_value;
928}
929
930#if defined(MS_WINDOWS)
931
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300932PyDoc_STRVAR(os__getfullpathname__doc__,
933"_getfullpathname($module, path, /)\n"
934"--\n"
935"\n");
936
937#define OS__GETFULLPATHNAME_METHODDEF \
938 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
939
940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300941os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300942
943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300944os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300945{
946 PyObject *return_value = NULL;
947 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
948
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300949 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300951 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300952 return_value = os__getfullpathname_impl(module, &path);
953
954exit:
955 /* Cleanup for path */
956 path_cleanup(&path);
957
958 return return_value;
959}
960
961#endif /* defined(MS_WINDOWS) */
962
963#if defined(MS_WINDOWS)
964
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300965PyDoc_STRVAR(os__getfinalpathname__doc__,
966"_getfinalpathname($module, path, /)\n"
967"--\n"
968"\n"
969"A helper function for samepath on windows.");
970
971#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300972 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300973
974static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -0800975os__getfinalpathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300976
977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300978os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300979{
980 PyObject *return_value = NULL;
Steve Dower23ad6d02018-02-22 10:39:10 -0800981 path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300982
Steve Dower23ad6d02018-02-22 10:39:10 -0800983 if (!PyArg_Parse(arg, "O&:_getfinalpathname", path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300985 }
Steve Dower23ad6d02018-02-22 10:39:10 -0800986 return_value = os__getfinalpathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300987
988exit:
Steve Dower23ad6d02018-02-22 10:39:10 -0800989 /* Cleanup for path */
990 path_cleanup(&path);
991
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300992 return return_value;
993}
994
995#endif /* defined(MS_WINDOWS) */
996
997#if defined(MS_WINDOWS)
998
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300999PyDoc_STRVAR(os__isdir__doc__,
1000"_isdir($module, path, /)\n"
1001"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +02001002"\n"
1003"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001004
1005#define OS__ISDIR_METHODDEF \
1006 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1007
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001008#endif /* defined(MS_WINDOWS) */
1009
1010#if defined(MS_WINDOWS)
1011
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001012PyDoc_STRVAR(os__getvolumepathname__doc__,
1013"_getvolumepathname($module, /, path)\n"
1014"--\n"
1015"\n"
1016"A helper function for ismount on Win32.");
1017
1018#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001019 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001020
1021static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08001022os__getvolumepathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001023
1024static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001025os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001026{
1027 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001028 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08001029 static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0};
1030 path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001031
Victor Stinner3e1fad62017-01-17 01:29:01 +01001032 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08001033 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001034 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001035 }
Steve Dower23ad6d02018-02-22 10:39:10 -08001036 return_value = os__getvolumepathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001037
1038exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08001039 /* Cleanup for path */
1040 path_cleanup(&path);
1041
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001042 return return_value;
1043}
1044
1045#endif /* defined(MS_WINDOWS) */
1046
1047PyDoc_STRVAR(os_mkdir__doc__,
1048"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1049"--\n"
1050"\n"
1051"Create a directory.\n"
1052"\n"
1053"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1054" and path should be relative; path will then be relative to that directory.\n"
1055"dir_fd may not be implemented on your platform.\n"
1056" If it is unavailable, using it will raise a NotImplementedError.\n"
1057"\n"
1058"The mode argument is ignored on Windows.");
1059
1060#define OS_MKDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001061 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001062
1063static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001064os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001065
1066static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001067os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001068{
1069 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001070 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1071 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001072 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1073 int mode = 511;
1074 int dir_fd = DEFAULT_DIR_FD;
1075
Victor Stinner3e1fad62017-01-17 01:29:01 +01001076 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001077 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001078 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001079 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001080 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1081
1082exit:
1083 /* Cleanup for path */
1084 path_cleanup(&path);
1085
1086 return return_value;
1087}
1088
1089#if defined(HAVE_NICE)
1090
1091PyDoc_STRVAR(os_nice__doc__,
1092"nice($module, increment, /)\n"
1093"--\n"
1094"\n"
1095"Add increment to the priority of process and return the new priority.");
1096
1097#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001098 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001099
1100static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001101os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001102
1103static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001104os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001105{
1106 PyObject *return_value = NULL;
1107 int increment;
1108
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001109 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001110 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001111 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001112 return_value = os_nice_impl(module, increment);
1113
1114exit:
1115 return return_value;
1116}
1117
1118#endif /* defined(HAVE_NICE) */
1119
1120#if defined(HAVE_GETPRIORITY)
1121
1122PyDoc_STRVAR(os_getpriority__doc__,
1123"getpriority($module, /, which, who)\n"
1124"--\n"
1125"\n"
1126"Return program scheduling priority.");
1127
1128#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001129 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001130
1131static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001132os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001133
1134static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001135os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001136{
1137 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001138 static const char * const _keywords[] = {"which", "who", NULL};
1139 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001140 int which;
1141 int who;
1142
Victor Stinner3e1fad62017-01-17 01:29:01 +01001143 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001144 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001145 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001146 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001147 return_value = os_getpriority_impl(module, which, who);
1148
1149exit:
1150 return return_value;
1151}
1152
1153#endif /* defined(HAVE_GETPRIORITY) */
1154
1155#if defined(HAVE_SETPRIORITY)
1156
1157PyDoc_STRVAR(os_setpriority__doc__,
1158"setpriority($module, /, which, who, priority)\n"
1159"--\n"
1160"\n"
1161"Set program scheduling priority.");
1162
1163#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001164 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001165
1166static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001167os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001168
1169static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001170os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001171{
1172 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001173 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1174 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001175 int which;
1176 int who;
1177 int priority;
1178
Victor Stinner3e1fad62017-01-17 01:29:01 +01001179 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001180 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001181 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001182 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001183 return_value = os_setpriority_impl(module, which, who, priority);
1184
1185exit:
1186 return return_value;
1187}
1188
1189#endif /* defined(HAVE_SETPRIORITY) */
1190
1191PyDoc_STRVAR(os_rename__doc__,
1192"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1193"--\n"
1194"\n"
1195"Rename a file or directory.\n"
1196"\n"
1197"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1198" descriptor open to a directory, and the respective path string (src or dst)\n"
1199" should be relative; the path will then be relative to that directory.\n"
1200"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1201" If they are unavailable, using them will raise a NotImplementedError.");
1202
1203#define OS_RENAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001204 {"rename", (PyCFunction)os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001205
1206static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001207os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001208 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001209
1210static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001211os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001212{
1213 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001214 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1215 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001216 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1217 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1218 int src_dir_fd = DEFAULT_DIR_FD;
1219 int dst_dir_fd = DEFAULT_DIR_FD;
1220
Victor Stinner3e1fad62017-01-17 01:29:01 +01001221 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001222 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001223 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001224 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001225 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1226
1227exit:
1228 /* Cleanup for src */
1229 path_cleanup(&src);
1230 /* Cleanup for dst */
1231 path_cleanup(&dst);
1232
1233 return return_value;
1234}
1235
1236PyDoc_STRVAR(os_replace__doc__,
1237"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1238"--\n"
1239"\n"
1240"Rename a file or directory, overwriting the destination.\n"
1241"\n"
1242"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1243" descriptor open to a directory, and the respective path string (src or dst)\n"
1244" should be relative; the path will then be relative to that directory.\n"
1245"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1246" If they are unavailable, using them will raise a NotImplementedError.\"");
1247
1248#define OS_REPLACE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001249 {"replace", (PyCFunction)os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001250
1251static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001252os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1253 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001254
1255static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001256os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001257{
1258 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001259 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1260 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001261 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1262 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1263 int src_dir_fd = DEFAULT_DIR_FD;
1264 int dst_dir_fd = DEFAULT_DIR_FD;
1265
Victor Stinner3e1fad62017-01-17 01:29:01 +01001266 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001267 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001268 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001269 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001270 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1271
1272exit:
1273 /* Cleanup for src */
1274 path_cleanup(&src);
1275 /* Cleanup for dst */
1276 path_cleanup(&dst);
1277
1278 return return_value;
1279}
1280
1281PyDoc_STRVAR(os_rmdir__doc__,
1282"rmdir($module, /, path, *, dir_fd=None)\n"
1283"--\n"
1284"\n"
1285"Remove a directory.\n"
1286"\n"
1287"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1288" and path should be relative; path will then be relative to that directory.\n"
1289"dir_fd may not be implemented on your platform.\n"
1290" If it is unavailable, using it will raise a NotImplementedError.");
1291
1292#define OS_RMDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001293 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001294
1295static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001296os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001297
1298static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001299os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001300{
1301 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001302 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1303 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001304 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1305 int dir_fd = DEFAULT_DIR_FD;
1306
Victor Stinner3e1fad62017-01-17 01:29:01 +01001307 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001308 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001309 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001310 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001311 return_value = os_rmdir_impl(module, &path, dir_fd);
1312
1313exit:
1314 /* Cleanup for path */
1315 path_cleanup(&path);
1316
1317 return return_value;
1318}
1319
1320#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1321
1322PyDoc_STRVAR(os_system__doc__,
1323"system($module, /, command)\n"
1324"--\n"
1325"\n"
1326"Execute the command in a subshell.");
1327
1328#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001329 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001330
1331static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001332os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001333
1334static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001335os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001336{
1337 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001338 static const char * const _keywords[] = {"command", NULL};
1339 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001340 Py_UNICODE *command;
1341 long _return_value;
1342
Victor Stinner3e1fad62017-01-17 01:29:01 +01001343 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001344 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001345 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001346 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001347 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001348 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001349 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001350 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001351 return_value = PyLong_FromLong(_return_value);
1352
1353exit:
1354 return return_value;
1355}
1356
1357#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1358
1359#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1360
1361PyDoc_STRVAR(os_system__doc__,
1362"system($module, /, command)\n"
1363"--\n"
1364"\n"
1365"Execute the command in a subshell.");
1366
1367#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001368 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001369
1370static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001371os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001372
1373static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001374os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001375{
1376 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001377 static const char * const _keywords[] = {"command", NULL};
1378 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001379 PyObject *command = NULL;
1380 long _return_value;
1381
Victor Stinner3e1fad62017-01-17 01:29:01 +01001382 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001383 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001386 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001387 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001388 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001389 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390 return_value = PyLong_FromLong(_return_value);
1391
1392exit:
1393 /* Cleanup for command */
1394 Py_XDECREF(command);
1395
1396 return return_value;
1397}
1398
1399#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1400
1401PyDoc_STRVAR(os_umask__doc__,
1402"umask($module, mask, /)\n"
1403"--\n"
1404"\n"
1405"Set the current numeric umask and return the previous umask.");
1406
1407#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001408 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001409
1410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001411os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001412
1413static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001414os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001415{
1416 PyObject *return_value = NULL;
1417 int mask;
1418
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001419 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001420 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001421 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001422 return_value = os_umask_impl(module, mask);
1423
1424exit:
1425 return return_value;
1426}
1427
1428PyDoc_STRVAR(os_unlink__doc__,
1429"unlink($module, /, path, *, dir_fd=None)\n"
1430"--\n"
1431"\n"
1432"Remove a file (same as remove()).\n"
1433"\n"
1434"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1435" and path should be relative; path will then be relative to that directory.\n"
1436"dir_fd may not be implemented on your platform.\n"
1437" If it is unavailable, using it will raise a NotImplementedError.");
1438
1439#define OS_UNLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001440 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001441
1442static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001443os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001444
1445static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001446os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001447{
1448 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001449 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1450 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001451 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1452 int dir_fd = DEFAULT_DIR_FD;
1453
Victor Stinner3e1fad62017-01-17 01:29:01 +01001454 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001455 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001456 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001457 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001458 return_value = os_unlink_impl(module, &path, dir_fd);
1459
1460exit:
1461 /* Cleanup for path */
1462 path_cleanup(&path);
1463
1464 return return_value;
1465}
1466
1467PyDoc_STRVAR(os_remove__doc__,
1468"remove($module, /, path, *, dir_fd=None)\n"
1469"--\n"
1470"\n"
1471"Remove a file (same as unlink()).\n"
1472"\n"
1473"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1474" and path should be relative; path will then be relative to that directory.\n"
1475"dir_fd may not be implemented on your platform.\n"
1476" If it is unavailable, using it will raise a NotImplementedError.");
1477
1478#define OS_REMOVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001479 {"remove", (PyCFunction)os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001480
1481static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001482os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001483
1484static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001485os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001486{
1487 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001488 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1489 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001490 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1491 int dir_fd = DEFAULT_DIR_FD;
1492
Victor Stinner3e1fad62017-01-17 01:29:01 +01001493 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001494 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001495 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001496 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001497 return_value = os_remove_impl(module, &path, dir_fd);
1498
1499exit:
1500 /* Cleanup for path */
1501 path_cleanup(&path);
1502
1503 return return_value;
1504}
1505
1506#if defined(HAVE_UNAME)
1507
1508PyDoc_STRVAR(os_uname__doc__,
1509"uname($module, /)\n"
1510"--\n"
1511"\n"
1512"Return an object identifying the current operating system.\n"
1513"\n"
1514"The object behaves like a named tuple with the following fields:\n"
1515" (sysname, nodename, release, version, machine)");
1516
1517#define OS_UNAME_METHODDEF \
1518 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1519
1520static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001521os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001522
1523static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001524os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001525{
1526 return os_uname_impl(module);
1527}
1528
1529#endif /* defined(HAVE_UNAME) */
1530
1531PyDoc_STRVAR(os_utime__doc__,
1532"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1533" follow_symlinks=True)\n"
1534"--\n"
1535"\n"
1536"Set the access and modified time of path.\n"
1537"\n"
1538"path may always be specified as a string.\n"
1539"On some platforms, path may also be specified as an open file descriptor.\n"
1540" If this functionality is unavailable, using it raises an exception.\n"
1541"\n"
1542"If times is not None, it must be a tuple (atime, mtime);\n"
1543" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001544"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001545" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1546" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001547"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001548"Specifying tuples for both times and ns is an error.\n"
1549"\n"
1550"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1551" and path should be relative; path will then be relative to that directory.\n"
1552"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1553" link, utime will modify the symbolic link itself instead of the file the\n"
1554" link points to.\n"
1555"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1556" as an open file descriptor.\n"
1557"dir_fd and follow_symlinks may not be available on your platform.\n"
1558" If they are unavailable, using them will raise a NotImplementedError.");
1559
1560#define OS_UTIME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001561 {"utime", (PyCFunction)os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001562
1563static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001564os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1565 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001566
1567static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001568os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001569{
1570 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001571 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1572 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001573 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1574 PyObject *times = NULL;
1575 PyObject *ns = NULL;
1576 int dir_fd = DEFAULT_DIR_FD;
1577 int follow_symlinks = 1;
1578
Victor Stinner3e1fad62017-01-17 01:29:01 +01001579 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001580 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001581 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001582 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001583 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1584
1585exit:
1586 /* Cleanup for path */
1587 path_cleanup(&path);
1588
1589 return return_value;
1590}
1591
1592PyDoc_STRVAR(os__exit__doc__,
1593"_exit($module, /, status)\n"
1594"--\n"
1595"\n"
1596"Exit to the system with specified status, without normal exit processing.");
1597
1598#define OS__EXIT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001599 {"_exit", (PyCFunction)os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001600
1601static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001602os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001603
1604static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001605os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001606{
1607 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001608 static const char * const _keywords[] = {"status", NULL};
1609 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001610 int status;
1611
Victor Stinner3e1fad62017-01-17 01:29:01 +01001612 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001613 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001614 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001615 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001616 return_value = os__exit_impl(module, status);
1617
1618exit:
1619 return return_value;
1620}
1621
1622#if defined(HAVE_EXECV)
1623
1624PyDoc_STRVAR(os_execv__doc__,
1625"execv($module, path, argv, /)\n"
1626"--\n"
1627"\n"
1628"Execute an executable path with arguments, replacing current process.\n"
1629"\n"
1630" path\n"
1631" Path of executable file.\n"
1632" argv\n"
1633" Tuple or list of strings.");
1634
1635#define OS_EXECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001636 {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001637
1638static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001639os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001640
1641static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001642os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001643{
1644 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001645 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001646 PyObject *argv;
1647
Sylvain74453812017-06-10 06:51:48 +02001648 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
1649 path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001650 goto exit;
1651 }
Steve Dowercc16be82016-09-08 10:35:16 -07001652 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001653
1654exit:
1655 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001656 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001657
1658 return return_value;
1659}
1660
1661#endif /* defined(HAVE_EXECV) */
1662
1663#if defined(HAVE_EXECV)
1664
1665PyDoc_STRVAR(os_execve__doc__,
1666"execve($module, /, path, argv, env)\n"
1667"--\n"
1668"\n"
1669"Execute an executable path with arguments, replacing current process.\n"
1670"\n"
1671" path\n"
1672" Path of executable file.\n"
1673" argv\n"
1674" Tuple or list of strings.\n"
1675" env\n"
1676" Dictionary of strings mapping to strings.");
1677
1678#define OS_EXECVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001679 {"execve", (PyCFunction)os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001680
1681static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001682os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001683
1684static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001685os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001686{
1687 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001688 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1689 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001690 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1691 PyObject *argv;
1692 PyObject *env;
1693
Victor Stinner3e1fad62017-01-17 01:29:01 +01001694 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001695 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001696 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001697 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001698 return_value = os_execve_impl(module, &path, argv, env);
1699
1700exit:
1701 /* Cleanup for path */
1702 path_cleanup(&path);
1703
1704 return return_value;
1705}
1706
1707#endif /* defined(HAVE_EXECV) */
1708
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001709#if defined(HAVE_POSIX_SPAWN)
1710
1711PyDoc_STRVAR(os_posix_spawn__doc__,
Serhiy Storchakad700f972018-09-08 14:48:18 +03001712"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001713" setpgroup=None, resetids=False, setsigmask=(),\n"
1714" setsigdef=(), scheduler=None)\n"
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001715"--\n"
1716"\n"
1717"Execute the program specified by path in a new process.\n"
1718"\n"
1719" path\n"
1720" Path of executable file.\n"
1721" argv\n"
1722" Tuple or list of strings.\n"
1723" env\n"
1724" Dictionary of strings mapping to strings.\n"
1725" file_actions\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001726" A sequence of file action tuples.\n"
1727" setpgroup\n"
1728" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
1729" resetids\n"
1730" If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
1731" setsigmask\n"
1732" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
1733" setsigdef\n"
1734" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
1735" scheduler\n"
1736" A tuple with the scheduler policy (optional) and parameters.");
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001737
1738#define OS_POSIX_SPAWN_METHODDEF \
Pablo Galindo254a4662018-09-07 16:44:24 +01001739 {"posix_spawn", (PyCFunction)os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001740
1741static PyObject *
1742os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
Pablo Galindo254a4662018-09-07 16:44:24 +01001743 PyObject *env, PyObject *file_actions,
1744 PyObject *setpgroup, int resetids, PyObject *setsigmask,
1745 PyObject *setsigdef, PyObject *scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001746
1747static PyObject *
Pablo Galindo254a4662018-09-07 16:44:24 +01001748os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001749{
1750 PyObject *return_value = NULL;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001751 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL};
1752 static _PyArg_Parser _parser = {"O&OO|$OOiOOO:posix_spawn", _keywords, 0};
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001753 path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
1754 PyObject *argv;
1755 PyObject *env;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001756 PyObject *file_actions = NULL;
Pablo Galindo254a4662018-09-07 16:44:24 +01001757 PyObject *setpgroup = NULL;
1758 int resetids = 0;
1759 PyObject *setsigmask = NULL;
1760 PyObject *setsigdef = NULL;
1761 PyObject *scheduler = NULL;
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001762
Pablo Galindo254a4662018-09-07 16:44:24 +01001763 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1764 path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsigmask, &setsigdef, &scheduler)) {
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001765 goto exit;
1766 }
Pablo Galindo254a4662018-09-07 16:44:24 +01001767 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsigmask, setsigdef, scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001768
1769exit:
1770 /* Cleanup for path */
1771 path_cleanup(&path);
1772
1773 return return_value;
1774}
1775
1776#endif /* defined(HAVE_POSIX_SPAWN) */
1777
Steve Dowercc16be82016-09-08 10:35:16 -07001778#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001779
1780PyDoc_STRVAR(os_spawnv__doc__,
1781"spawnv($module, mode, path, argv, /)\n"
1782"--\n"
1783"\n"
1784"Execute the program specified by path in a new process.\n"
1785"\n"
1786" mode\n"
1787" Mode of process creation.\n"
1788" path\n"
1789" Path of executable file.\n"
1790" argv\n"
1791" Tuple or list of strings.");
1792
1793#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001794 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001795
1796static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001797os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001798
1799static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001800os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001801{
1802 PyObject *return_value = NULL;
1803 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001804 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001805 PyObject *argv;
1806
Sylvain74453812017-06-10 06:51:48 +02001807 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1808 &mode, path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001809 goto exit;
1810 }
Steve Dowercc16be82016-09-08 10:35:16 -07001811 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001812
1813exit:
1814 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001815 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001816
1817 return return_value;
1818}
1819
Steve Dowercc16be82016-09-08 10:35:16 -07001820#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001821
Steve Dowercc16be82016-09-08 10:35:16 -07001822#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001823
1824PyDoc_STRVAR(os_spawnve__doc__,
1825"spawnve($module, mode, path, argv, env, /)\n"
1826"--\n"
1827"\n"
1828"Execute the program specified by path in a new process.\n"
1829"\n"
1830" mode\n"
1831" Mode of process creation.\n"
1832" path\n"
1833" Path of executable file.\n"
1834" argv\n"
1835" Tuple or list of strings.\n"
1836" env\n"
1837" Dictionary of strings mapping to strings.");
1838
1839#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001840 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001841
1842static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001843os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001844 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001845
1846static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001847os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001848{
1849 PyObject *return_value = NULL;
1850 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001851 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001852 PyObject *argv;
1853 PyObject *env;
1854
Sylvain74453812017-06-10 06:51:48 +02001855 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1856 &mode, path_converter, &path, &argv, &env)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001857 goto exit;
1858 }
Steve Dowercc16be82016-09-08 10:35:16 -07001859 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001860
1861exit:
1862 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001863 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001864
1865 return return_value;
1866}
1867
Steve Dowercc16be82016-09-08 10:35:16 -07001868#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001869
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001870#if defined(HAVE_FORK)
1871
1872PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001873"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1874" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001875"--\n"
1876"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001877"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001878"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001879" before\n"
1880" A callable to be called in the parent before the fork() syscall.\n"
1881" after_in_child\n"
1882" A callable to be called in the child after fork().\n"
1883" after_in_parent\n"
1884" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001885"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001886"\'before\' callbacks are called in reverse order.\n"
1887"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001888
1889#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001890 {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001891
1892static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001893os_register_at_fork_impl(PyObject *module, PyObject *before,
1894 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001895
1896static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001897os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001898{
1899 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001900 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1901 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1902 PyObject *before = NULL;
1903 PyObject *after_in_child = NULL;
1904 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001905
1906 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001907 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001908 goto exit;
1909 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001910 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001911
1912exit:
1913 return return_value;
1914}
1915
1916#endif /* defined(HAVE_FORK) */
1917
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001918#if defined(HAVE_FORK1)
1919
1920PyDoc_STRVAR(os_fork1__doc__,
1921"fork1($module, /)\n"
1922"--\n"
1923"\n"
1924"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1925"\n"
1926"Return 0 to child process and PID of child to parent process.");
1927
1928#define OS_FORK1_METHODDEF \
1929 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1930
1931static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001932os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001933
1934static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001935os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001936{
1937 return os_fork1_impl(module);
1938}
1939
1940#endif /* defined(HAVE_FORK1) */
1941
1942#if defined(HAVE_FORK)
1943
1944PyDoc_STRVAR(os_fork__doc__,
1945"fork($module, /)\n"
1946"--\n"
1947"\n"
1948"Fork a child process.\n"
1949"\n"
1950"Return 0 to child process and PID of child to parent process.");
1951
1952#define OS_FORK_METHODDEF \
1953 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1954
1955static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001956os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001957
1958static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001959os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001960{
1961 return os_fork_impl(module);
1962}
1963
1964#endif /* defined(HAVE_FORK) */
1965
1966#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1967
1968PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1969"sched_get_priority_max($module, /, policy)\n"
1970"--\n"
1971"\n"
1972"Get the maximum scheduling priority for policy.");
1973
1974#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001975 {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001976
1977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001978os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001979
1980static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001981os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001982{
1983 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001984 static const char * const _keywords[] = {"policy", NULL};
1985 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001986 int policy;
1987
Victor Stinner3e1fad62017-01-17 01:29:01 +01001988 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001989 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001990 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001991 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001992 return_value = os_sched_get_priority_max_impl(module, policy);
1993
1994exit:
1995 return return_value;
1996}
1997
1998#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1999
2000#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2001
2002PyDoc_STRVAR(os_sched_get_priority_min__doc__,
2003"sched_get_priority_min($module, /, policy)\n"
2004"--\n"
2005"\n"
2006"Get the minimum scheduling priority for policy.");
2007
2008#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002009 {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002010
2011static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002012os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002013
2014static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002015os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002016{
2017 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002018 static const char * const _keywords[] = {"policy", NULL};
2019 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002020 int policy;
2021
Victor Stinner3e1fad62017-01-17 01:29:01 +01002022 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002023 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002024 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002025 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002026 return_value = os_sched_get_priority_min_impl(module, policy);
2027
2028exit:
2029 return return_value;
2030}
2031
2032#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2033
2034#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2035
2036PyDoc_STRVAR(os_sched_getscheduler__doc__,
2037"sched_getscheduler($module, pid, /)\n"
2038"--\n"
2039"\n"
2040"Get the scheduling policy for the process identifiedy by pid.\n"
2041"\n"
2042"Passing 0 for pid returns the scheduling policy for the calling process.");
2043
2044#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002045 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002046
2047static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002048os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002049
2050static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002051os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002052{
2053 PyObject *return_value = NULL;
2054 pid_t pid;
2055
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002056 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002057 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002058 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002059 return_value = os_sched_getscheduler_impl(module, pid);
2060
2061exit:
2062 return return_value;
2063}
2064
2065#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2066
William Orr81574b82018-10-01 22:19:56 -07002067#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002068
2069PyDoc_STRVAR(os_sched_param__doc__,
2070"sched_param(sched_priority)\n"
2071"--\n"
2072"\n"
2073"Current has only one field: sched_priority\");\n"
2074"\n"
2075" sched_priority\n"
2076" A scheduling parameter.");
2077
2078static PyObject *
2079os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2080
2081static PyObject *
2082os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2083{
2084 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002085 static const char * const _keywords[] = {"sched_priority", NULL};
2086 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002087 PyObject *sched_priority;
2088
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002089 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002090 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002091 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002092 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002093 return_value = os_sched_param_impl(type, sched_priority);
2094
2095exit:
2096 return return_value;
2097}
2098
William Orr81574b82018-10-01 22:19:56 -07002099#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002100
2101#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2102
2103PyDoc_STRVAR(os_sched_setscheduler__doc__,
2104"sched_setscheduler($module, pid, policy, param, /)\n"
2105"--\n"
2106"\n"
2107"Set the scheduling policy for the process identified by pid.\n"
2108"\n"
2109"If pid is 0, the calling process is changed.\n"
2110"param is an instance of sched_param.");
2111
2112#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002113 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002114
2115static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002116os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002117 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002118
2119static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002120os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002121{
2122 PyObject *return_value = NULL;
2123 pid_t pid;
2124 int policy;
2125 struct sched_param param;
2126
Sylvain74453812017-06-10 06:51:48 +02002127 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2128 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002129 goto exit;
2130 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002131 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2132
2133exit:
2134 return return_value;
2135}
2136
2137#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2138
2139#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2140
2141PyDoc_STRVAR(os_sched_getparam__doc__,
2142"sched_getparam($module, pid, /)\n"
2143"--\n"
2144"\n"
2145"Returns scheduling parameters for the process identified by pid.\n"
2146"\n"
2147"If pid is 0, returns parameters for the calling process.\n"
2148"Return value is an instance of sched_param.");
2149
2150#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002151 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002152
2153static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002154os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002155
2156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002157os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002158{
2159 PyObject *return_value = NULL;
2160 pid_t pid;
2161
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002162 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002163 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002164 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002165 return_value = os_sched_getparam_impl(module, pid);
2166
2167exit:
2168 return return_value;
2169}
2170
2171#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2172
2173#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2174
2175PyDoc_STRVAR(os_sched_setparam__doc__,
2176"sched_setparam($module, pid, param, /)\n"
2177"--\n"
2178"\n"
2179"Set scheduling parameters for the process identified by pid.\n"
2180"\n"
2181"If pid is 0, sets parameters for the calling process.\n"
2182"param should be an instance of sched_param.");
2183
2184#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002185 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002186
2187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002188os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002189 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002190
2191static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002192os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002193{
2194 PyObject *return_value = NULL;
2195 pid_t pid;
2196 struct sched_param param;
2197
Sylvain74453812017-06-10 06:51:48 +02002198 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2199 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002200 goto exit;
2201 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002202 return_value = os_sched_setparam_impl(module, pid, &param);
2203
2204exit:
2205 return return_value;
2206}
2207
2208#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2209
2210#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2211
2212PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2213"sched_rr_get_interval($module, pid, /)\n"
2214"--\n"
2215"\n"
2216"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2217"\n"
2218"Value returned is a float.");
2219
2220#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002221 {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002222
2223static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002224os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002225
2226static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002227os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002228{
2229 PyObject *return_value = NULL;
2230 pid_t pid;
2231 double _return_value;
2232
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002233 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002234 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002235 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002236 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002237 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002238 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002239 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002240 return_value = PyFloat_FromDouble(_return_value);
2241
2242exit:
2243 return return_value;
2244}
2245
2246#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2247
2248#if defined(HAVE_SCHED_H)
2249
2250PyDoc_STRVAR(os_sched_yield__doc__,
2251"sched_yield($module, /)\n"
2252"--\n"
2253"\n"
2254"Voluntarily relinquish the CPU.");
2255
2256#define OS_SCHED_YIELD_METHODDEF \
2257 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2258
2259static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002260os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002261
2262static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002263os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002264{
2265 return os_sched_yield_impl(module);
2266}
2267
2268#endif /* defined(HAVE_SCHED_H) */
2269
2270#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2271
2272PyDoc_STRVAR(os_sched_setaffinity__doc__,
2273"sched_setaffinity($module, pid, mask, /)\n"
2274"--\n"
2275"\n"
2276"Set the CPU affinity of the process identified by pid to mask.\n"
2277"\n"
2278"mask should be an iterable of integers identifying CPUs.");
2279
2280#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002281 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002282
2283static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002284os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002285
2286static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002287os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002288{
2289 PyObject *return_value = NULL;
2290 pid_t pid;
2291 PyObject *mask;
2292
Sylvain74453812017-06-10 06:51:48 +02002293 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2294 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002295 goto exit;
2296 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002297 return_value = os_sched_setaffinity_impl(module, pid, mask);
2298
2299exit:
2300 return return_value;
2301}
2302
2303#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2304
2305#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2306
2307PyDoc_STRVAR(os_sched_getaffinity__doc__,
2308"sched_getaffinity($module, pid, /)\n"
2309"--\n"
2310"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002311"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002312"\n"
2313"The affinity is returned as a set of CPU identifiers.");
2314
2315#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002316 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002317
2318static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002319os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002320
2321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002322os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002323{
2324 PyObject *return_value = NULL;
2325 pid_t pid;
2326
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002327 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002328 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002329 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002330 return_value = os_sched_getaffinity_impl(module, pid);
2331
2332exit:
2333 return return_value;
2334}
2335
2336#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2337
2338#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2339
2340PyDoc_STRVAR(os_openpty__doc__,
2341"openpty($module, /)\n"
2342"--\n"
2343"\n"
2344"Open a pseudo-terminal.\n"
2345"\n"
2346"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2347"for both the master and slave ends.");
2348
2349#define OS_OPENPTY_METHODDEF \
2350 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2351
2352static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002353os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002354
2355static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002356os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002357{
2358 return os_openpty_impl(module);
2359}
2360
2361#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2362
2363#if defined(HAVE_FORKPTY)
2364
2365PyDoc_STRVAR(os_forkpty__doc__,
2366"forkpty($module, /)\n"
2367"--\n"
2368"\n"
2369"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2370"\n"
2371"Returns a tuple of (pid, master_fd).\n"
2372"Like fork(), return pid of 0 to the child process,\n"
2373"and pid of child to the parent process.\n"
2374"To both, return fd of newly opened pseudo-terminal.");
2375
2376#define OS_FORKPTY_METHODDEF \
2377 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2378
2379static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002380os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002381
2382static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002383os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002384{
2385 return os_forkpty_impl(module);
2386}
2387
2388#endif /* defined(HAVE_FORKPTY) */
2389
2390#if defined(HAVE_GETEGID)
2391
2392PyDoc_STRVAR(os_getegid__doc__,
2393"getegid($module, /)\n"
2394"--\n"
2395"\n"
2396"Return the current process\'s effective group id.");
2397
2398#define OS_GETEGID_METHODDEF \
2399 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2400
2401static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002402os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002403
2404static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002405os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002406{
2407 return os_getegid_impl(module);
2408}
2409
2410#endif /* defined(HAVE_GETEGID) */
2411
2412#if defined(HAVE_GETEUID)
2413
2414PyDoc_STRVAR(os_geteuid__doc__,
2415"geteuid($module, /)\n"
2416"--\n"
2417"\n"
2418"Return the current process\'s effective user id.");
2419
2420#define OS_GETEUID_METHODDEF \
2421 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2422
2423static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002424os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002425
2426static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002427os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002428{
2429 return os_geteuid_impl(module);
2430}
2431
2432#endif /* defined(HAVE_GETEUID) */
2433
2434#if defined(HAVE_GETGID)
2435
2436PyDoc_STRVAR(os_getgid__doc__,
2437"getgid($module, /)\n"
2438"--\n"
2439"\n"
2440"Return the current process\'s group id.");
2441
2442#define OS_GETGID_METHODDEF \
2443 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2444
2445static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002446os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002447
2448static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002449os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002450{
2451 return os_getgid_impl(module);
2452}
2453
2454#endif /* defined(HAVE_GETGID) */
2455
Berker Peksag39404992016-09-15 20:45:16 +03002456#if defined(HAVE_GETPID)
2457
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002458PyDoc_STRVAR(os_getpid__doc__,
2459"getpid($module, /)\n"
2460"--\n"
2461"\n"
2462"Return the current process id.");
2463
2464#define OS_GETPID_METHODDEF \
2465 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2466
2467static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002468os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002469
2470static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002471os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002472{
2473 return os_getpid_impl(module);
2474}
2475
Berker Peksag39404992016-09-15 20:45:16 +03002476#endif /* defined(HAVE_GETPID) */
2477
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002478#if defined(HAVE_GETGROUPS)
2479
2480PyDoc_STRVAR(os_getgroups__doc__,
2481"getgroups($module, /)\n"
2482"--\n"
2483"\n"
2484"Return list of supplemental group IDs for the process.");
2485
2486#define OS_GETGROUPS_METHODDEF \
2487 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2488
2489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002490os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002491
2492static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002493os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002494{
2495 return os_getgroups_impl(module);
2496}
2497
2498#endif /* defined(HAVE_GETGROUPS) */
2499
2500#if defined(HAVE_GETPGID)
2501
2502PyDoc_STRVAR(os_getpgid__doc__,
2503"getpgid($module, /, pid)\n"
2504"--\n"
2505"\n"
2506"Call the system call getpgid(), and return the result.");
2507
2508#define OS_GETPGID_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002509 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002510
2511static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002512os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002513
2514static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002515os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002516{
2517 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002518 static const char * const _keywords[] = {"pid", NULL};
2519 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002520 pid_t pid;
2521
Victor Stinner3e1fad62017-01-17 01:29:01 +01002522 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002523 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002524 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002525 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002526 return_value = os_getpgid_impl(module, pid);
2527
2528exit:
2529 return return_value;
2530}
2531
2532#endif /* defined(HAVE_GETPGID) */
2533
2534#if defined(HAVE_GETPGRP)
2535
2536PyDoc_STRVAR(os_getpgrp__doc__,
2537"getpgrp($module, /)\n"
2538"--\n"
2539"\n"
2540"Return the current process group id.");
2541
2542#define OS_GETPGRP_METHODDEF \
2543 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2544
2545static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002546os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002547
2548static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002549os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002550{
2551 return os_getpgrp_impl(module);
2552}
2553
2554#endif /* defined(HAVE_GETPGRP) */
2555
2556#if defined(HAVE_SETPGRP)
2557
2558PyDoc_STRVAR(os_setpgrp__doc__,
2559"setpgrp($module, /)\n"
2560"--\n"
2561"\n"
2562"Make the current process the leader of its process group.");
2563
2564#define OS_SETPGRP_METHODDEF \
2565 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2566
2567static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002568os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002569
2570static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002571os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002572{
2573 return os_setpgrp_impl(module);
2574}
2575
2576#endif /* defined(HAVE_SETPGRP) */
2577
2578#if defined(HAVE_GETPPID)
2579
2580PyDoc_STRVAR(os_getppid__doc__,
2581"getppid($module, /)\n"
2582"--\n"
2583"\n"
2584"Return the parent\'s process id.\n"
2585"\n"
2586"If the parent process has already exited, Windows machines will still\n"
2587"return its id; others systems will return the id of the \'init\' process (1).");
2588
2589#define OS_GETPPID_METHODDEF \
2590 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2591
2592static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002593os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002594
2595static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002596os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002597{
2598 return os_getppid_impl(module);
2599}
2600
2601#endif /* defined(HAVE_GETPPID) */
2602
2603#if defined(HAVE_GETLOGIN)
2604
2605PyDoc_STRVAR(os_getlogin__doc__,
2606"getlogin($module, /)\n"
2607"--\n"
2608"\n"
2609"Return the actual login name.");
2610
2611#define OS_GETLOGIN_METHODDEF \
2612 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2613
2614static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002615os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002616
2617static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002618os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002619{
2620 return os_getlogin_impl(module);
2621}
2622
2623#endif /* defined(HAVE_GETLOGIN) */
2624
2625#if defined(HAVE_GETUID)
2626
2627PyDoc_STRVAR(os_getuid__doc__,
2628"getuid($module, /)\n"
2629"--\n"
2630"\n"
2631"Return the current process\'s user id.");
2632
2633#define OS_GETUID_METHODDEF \
2634 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2635
2636static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002637os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002638
2639static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002640os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002641{
2642 return os_getuid_impl(module);
2643}
2644
2645#endif /* defined(HAVE_GETUID) */
2646
2647#if defined(HAVE_KILL)
2648
2649PyDoc_STRVAR(os_kill__doc__,
2650"kill($module, pid, signal, /)\n"
2651"--\n"
2652"\n"
2653"Kill a process with a signal.");
2654
2655#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002656 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002657
2658static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002659os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002660
2661static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002662os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002663{
2664 PyObject *return_value = NULL;
2665 pid_t pid;
2666 Py_ssize_t signal;
2667
Sylvain74453812017-06-10 06:51:48 +02002668 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2669 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002670 goto exit;
2671 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002672 return_value = os_kill_impl(module, pid, signal);
2673
2674exit:
2675 return return_value;
2676}
2677
2678#endif /* defined(HAVE_KILL) */
2679
2680#if defined(HAVE_KILLPG)
2681
2682PyDoc_STRVAR(os_killpg__doc__,
2683"killpg($module, pgid, signal, /)\n"
2684"--\n"
2685"\n"
2686"Kill a process group with a signal.");
2687
2688#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002689 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002690
2691static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002692os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002693
2694static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002695os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002696{
2697 PyObject *return_value = NULL;
2698 pid_t pgid;
2699 int signal;
2700
Sylvain74453812017-06-10 06:51:48 +02002701 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2702 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002703 goto exit;
2704 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002705 return_value = os_killpg_impl(module, pgid, signal);
2706
2707exit:
2708 return return_value;
2709}
2710
2711#endif /* defined(HAVE_KILLPG) */
2712
2713#if defined(HAVE_PLOCK)
2714
2715PyDoc_STRVAR(os_plock__doc__,
2716"plock($module, op, /)\n"
2717"--\n"
2718"\n"
2719"Lock program segments into memory.\");");
2720
2721#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002722 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002723
2724static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002725os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002726
2727static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002728os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002729{
2730 PyObject *return_value = NULL;
2731 int op;
2732
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002733 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002734 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002735 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002736 return_value = os_plock_impl(module, op);
2737
2738exit:
2739 return return_value;
2740}
2741
2742#endif /* defined(HAVE_PLOCK) */
2743
2744#if defined(HAVE_SETUID)
2745
2746PyDoc_STRVAR(os_setuid__doc__,
2747"setuid($module, uid, /)\n"
2748"--\n"
2749"\n"
2750"Set the current process\'s user id.");
2751
2752#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002753 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002754
2755static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002756os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002757
2758static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002759os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002760{
2761 PyObject *return_value = NULL;
2762 uid_t uid;
2763
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002764 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002765 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002766 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002767 return_value = os_setuid_impl(module, uid);
2768
2769exit:
2770 return return_value;
2771}
2772
2773#endif /* defined(HAVE_SETUID) */
2774
2775#if defined(HAVE_SETEUID)
2776
2777PyDoc_STRVAR(os_seteuid__doc__,
2778"seteuid($module, euid, /)\n"
2779"--\n"
2780"\n"
2781"Set the current process\'s effective user id.");
2782
2783#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002784 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002785
2786static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002787os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002788
2789static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002790os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002791{
2792 PyObject *return_value = NULL;
2793 uid_t euid;
2794
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002795 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002796 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002797 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002798 return_value = os_seteuid_impl(module, euid);
2799
2800exit:
2801 return return_value;
2802}
2803
2804#endif /* defined(HAVE_SETEUID) */
2805
2806#if defined(HAVE_SETEGID)
2807
2808PyDoc_STRVAR(os_setegid__doc__,
2809"setegid($module, egid, /)\n"
2810"--\n"
2811"\n"
2812"Set the current process\'s effective group id.");
2813
2814#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002815 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002816
2817static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002818os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002819
2820static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002821os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002822{
2823 PyObject *return_value = NULL;
2824 gid_t egid;
2825
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002826 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002827 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002828 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002829 return_value = os_setegid_impl(module, egid);
2830
2831exit:
2832 return return_value;
2833}
2834
2835#endif /* defined(HAVE_SETEGID) */
2836
2837#if defined(HAVE_SETREUID)
2838
2839PyDoc_STRVAR(os_setreuid__doc__,
2840"setreuid($module, ruid, euid, /)\n"
2841"--\n"
2842"\n"
2843"Set the current process\'s real and effective user ids.");
2844
2845#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002846 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002847
2848static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002849os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002850
2851static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002852os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002853{
2854 PyObject *return_value = NULL;
2855 uid_t ruid;
2856 uid_t euid;
2857
Sylvain74453812017-06-10 06:51:48 +02002858 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2859 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002860 goto exit;
2861 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002862 return_value = os_setreuid_impl(module, ruid, euid);
2863
2864exit:
2865 return return_value;
2866}
2867
2868#endif /* defined(HAVE_SETREUID) */
2869
2870#if defined(HAVE_SETREGID)
2871
2872PyDoc_STRVAR(os_setregid__doc__,
2873"setregid($module, rgid, egid, /)\n"
2874"--\n"
2875"\n"
2876"Set the current process\'s real and effective group ids.");
2877
2878#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002879 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002880
2881static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002882os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002883
2884static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002885os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002886{
2887 PyObject *return_value = NULL;
2888 gid_t rgid;
2889 gid_t egid;
2890
Sylvain74453812017-06-10 06:51:48 +02002891 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2892 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002893 goto exit;
2894 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002895 return_value = os_setregid_impl(module, rgid, egid);
2896
2897exit:
2898 return return_value;
2899}
2900
2901#endif /* defined(HAVE_SETREGID) */
2902
2903#if defined(HAVE_SETGID)
2904
2905PyDoc_STRVAR(os_setgid__doc__,
2906"setgid($module, gid, /)\n"
2907"--\n"
2908"\n"
2909"Set the current process\'s group id.");
2910
2911#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002912 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002913
2914static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002915os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002916
2917static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002918os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002919{
2920 PyObject *return_value = NULL;
2921 gid_t gid;
2922
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002923 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002924 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002925 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002926 return_value = os_setgid_impl(module, gid);
2927
2928exit:
2929 return return_value;
2930}
2931
2932#endif /* defined(HAVE_SETGID) */
2933
2934#if defined(HAVE_SETGROUPS)
2935
2936PyDoc_STRVAR(os_setgroups__doc__,
2937"setgroups($module, groups, /)\n"
2938"--\n"
2939"\n"
2940"Set the groups of the current process to list.");
2941
2942#define OS_SETGROUPS_METHODDEF \
2943 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2944
2945#endif /* defined(HAVE_SETGROUPS) */
2946
2947#if defined(HAVE_WAIT3)
2948
2949PyDoc_STRVAR(os_wait3__doc__,
2950"wait3($module, /, options)\n"
2951"--\n"
2952"\n"
2953"Wait for completion of a child process.\n"
2954"\n"
2955"Returns a tuple of information about the child process:\n"
2956" (pid, status, rusage)");
2957
2958#define OS_WAIT3_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002959 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002960
2961static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002962os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002963
2964static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002965os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002966{
2967 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002968 static const char * const _keywords[] = {"options", NULL};
2969 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002970 int options;
2971
Victor Stinner3e1fad62017-01-17 01:29:01 +01002972 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002973 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002974 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002975 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002976 return_value = os_wait3_impl(module, options);
2977
2978exit:
2979 return return_value;
2980}
2981
2982#endif /* defined(HAVE_WAIT3) */
2983
2984#if defined(HAVE_WAIT4)
2985
2986PyDoc_STRVAR(os_wait4__doc__,
2987"wait4($module, /, pid, options)\n"
2988"--\n"
2989"\n"
2990"Wait for completion of a specific child process.\n"
2991"\n"
2992"Returns a tuple of information about the child process:\n"
2993" (pid, status, rusage)");
2994
2995#define OS_WAIT4_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002996 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002997
2998static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002999os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003000
3001static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003002os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003003{
3004 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003005 static const char * const _keywords[] = {"pid", "options", NULL};
3006 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003007 pid_t pid;
3008 int options;
3009
Victor Stinner3e1fad62017-01-17 01:29:01 +01003010 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003011 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003012 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003013 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003014 return_value = os_wait4_impl(module, pid, options);
3015
3016exit:
3017 return return_value;
3018}
3019
3020#endif /* defined(HAVE_WAIT4) */
3021
3022#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3023
3024PyDoc_STRVAR(os_waitid__doc__,
3025"waitid($module, idtype, id, options, /)\n"
3026"--\n"
3027"\n"
3028"Returns the result of waiting for a process or processes.\n"
3029"\n"
3030" idtype\n"
3031" Must be one of be P_PID, P_PGID or P_ALL.\n"
3032" id\n"
3033" The id to wait on.\n"
3034" options\n"
3035" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3036" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3037"\n"
3038"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3039"no children in a waitable state.");
3040
3041#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003042 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003043
3044static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003045os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003046
3047static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003048os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003049{
3050 PyObject *return_value = NULL;
3051 idtype_t idtype;
3052 id_t id;
3053 int options;
3054
Sylvain74453812017-06-10 06:51:48 +02003055 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3056 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003057 goto exit;
3058 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003059 return_value = os_waitid_impl(module, idtype, id, options);
3060
3061exit:
3062 return return_value;
3063}
3064
3065#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3066
3067#if defined(HAVE_WAITPID)
3068
3069PyDoc_STRVAR(os_waitpid__doc__,
3070"waitpid($module, pid, options, /)\n"
3071"--\n"
3072"\n"
3073"Wait for completion of a given child process.\n"
3074"\n"
3075"Returns a tuple of information regarding the child process:\n"
3076" (pid, status)\n"
3077"\n"
3078"The options argument is ignored on Windows.");
3079
3080#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003081 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003082
3083static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003084os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003085
3086static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003087os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003088{
3089 PyObject *return_value = NULL;
3090 pid_t pid;
3091 int options;
3092
Sylvain74453812017-06-10 06:51:48 +02003093 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3094 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003095 goto exit;
3096 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003097 return_value = os_waitpid_impl(module, pid, options);
3098
3099exit:
3100 return return_value;
3101}
3102
3103#endif /* defined(HAVE_WAITPID) */
3104
3105#if defined(HAVE_CWAIT)
3106
3107PyDoc_STRVAR(os_waitpid__doc__,
3108"waitpid($module, pid, options, /)\n"
3109"--\n"
3110"\n"
3111"Wait for completion of a given process.\n"
3112"\n"
3113"Returns a tuple of information regarding the process:\n"
3114" (pid, status << 8)\n"
3115"\n"
3116"The options argument is ignored on Windows.");
3117
3118#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003119 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003120
3121static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003122os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003123
3124static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003125os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003126{
3127 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003128 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003129 int options;
3130
Sylvain74453812017-06-10 06:51:48 +02003131 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3132 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003133 goto exit;
3134 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003135 return_value = os_waitpid_impl(module, pid, options);
3136
3137exit:
3138 return return_value;
3139}
3140
3141#endif /* defined(HAVE_CWAIT) */
3142
3143#if defined(HAVE_WAIT)
3144
3145PyDoc_STRVAR(os_wait__doc__,
3146"wait($module, /)\n"
3147"--\n"
3148"\n"
3149"Wait for completion of a child process.\n"
3150"\n"
3151"Returns a tuple of information about the child process:\n"
3152" (pid, status)");
3153
3154#define OS_WAIT_METHODDEF \
3155 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3156
3157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003158os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003159
3160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003161os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003162{
3163 return os_wait_impl(module);
3164}
3165
3166#endif /* defined(HAVE_WAIT) */
3167
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003168#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
3169
3170PyDoc_STRVAR(os_readlink__doc__,
3171"readlink($module, /, path, *, dir_fd=None)\n"
3172"--\n"
3173"\n"
3174"Return a string representing the path to which the symbolic link points.\n"
3175"\n"
3176"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3177"and path should be relative; path will then be relative to that directory.\n"
3178"\n"
3179"dir_fd may not be implemented on your platform. If it is unavailable,\n"
3180"using it will raise a NotImplementedError.");
3181
3182#define OS_READLINK_METHODDEF \
3183 {"readlink", (PyCFunction)os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
3184
3185static PyObject *
3186os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
3187
3188static PyObject *
3189os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3190{
3191 PyObject *return_value = NULL;
3192 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3193 static _PyArg_Parser _parser = {"O&|$O&:readlink", _keywords, 0};
3194 path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
3195 int dir_fd = DEFAULT_DIR_FD;
3196
3197 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3198 path_converter, &path, READLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
3199 goto exit;
3200 }
3201 return_value = os_readlink_impl(module, &path, dir_fd);
3202
3203exit:
3204 /* Cleanup for path */
3205 path_cleanup(&path);
3206
3207 return return_value;
3208}
3209
3210#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
3211
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003212#if defined(HAVE_SYMLINK)
3213
3214PyDoc_STRVAR(os_symlink__doc__,
3215"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3216"--\n"
3217"\n"
3218"Create a symbolic link pointing to src named dst.\n"
3219"\n"
3220"target_is_directory is required on Windows if the target is to be\n"
3221" interpreted as a directory. (On Windows, symlink requires\n"
3222" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3223" target_is_directory is ignored on non-Windows platforms.\n"
3224"\n"
3225"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3226" and path should be relative; path will then be relative to that directory.\n"
3227"dir_fd may not be implemented on your platform.\n"
3228" If it is unavailable, using it will raise a NotImplementedError.");
3229
3230#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003231 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003232
3233static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003234os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003235 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003236
3237static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003238os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003239{
3240 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003241 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3242 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003243 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3244 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3245 int target_is_directory = 0;
3246 int dir_fd = DEFAULT_DIR_FD;
3247
Victor Stinner3e1fad62017-01-17 01:29:01 +01003248 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003249 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003250 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003251 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003252 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3253
3254exit:
3255 /* Cleanup for src */
3256 path_cleanup(&src);
3257 /* Cleanup for dst */
3258 path_cleanup(&dst);
3259
3260 return return_value;
3261}
3262
3263#endif /* defined(HAVE_SYMLINK) */
3264
3265#if defined(HAVE_TIMES)
3266
3267PyDoc_STRVAR(os_times__doc__,
3268"times($module, /)\n"
3269"--\n"
3270"\n"
3271"Return a collection containing process timing information.\n"
3272"\n"
3273"The object returned behaves like a named tuple with these fields:\n"
3274" (utime, stime, cutime, cstime, elapsed_time)\n"
3275"All fields are floating point numbers.");
3276
3277#define OS_TIMES_METHODDEF \
3278 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3279
3280static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003281os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003282
3283static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003284os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003285{
3286 return os_times_impl(module);
3287}
3288
3289#endif /* defined(HAVE_TIMES) */
3290
3291#if defined(HAVE_GETSID)
3292
3293PyDoc_STRVAR(os_getsid__doc__,
3294"getsid($module, pid, /)\n"
3295"--\n"
3296"\n"
3297"Call the system call getsid(pid) and return the result.");
3298
3299#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003300 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003301
3302static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003303os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003304
3305static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003306os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003307{
3308 PyObject *return_value = NULL;
3309 pid_t pid;
3310
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003311 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003312 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003313 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003314 return_value = os_getsid_impl(module, pid);
3315
3316exit:
3317 return return_value;
3318}
3319
3320#endif /* defined(HAVE_GETSID) */
3321
3322#if defined(HAVE_SETSID)
3323
3324PyDoc_STRVAR(os_setsid__doc__,
3325"setsid($module, /)\n"
3326"--\n"
3327"\n"
3328"Call the system call setsid().");
3329
3330#define OS_SETSID_METHODDEF \
3331 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3332
3333static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003334os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003335
3336static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003337os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003338{
3339 return os_setsid_impl(module);
3340}
3341
3342#endif /* defined(HAVE_SETSID) */
3343
3344#if defined(HAVE_SETPGID)
3345
3346PyDoc_STRVAR(os_setpgid__doc__,
3347"setpgid($module, pid, pgrp, /)\n"
3348"--\n"
3349"\n"
3350"Call the system call setpgid(pid, pgrp).");
3351
3352#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003353 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003354
3355static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003356os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003357
3358static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003359os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003360{
3361 PyObject *return_value = NULL;
3362 pid_t pid;
3363 pid_t pgrp;
3364
Sylvain74453812017-06-10 06:51:48 +02003365 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3366 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003367 goto exit;
3368 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003369 return_value = os_setpgid_impl(module, pid, pgrp);
3370
3371exit:
3372 return return_value;
3373}
3374
3375#endif /* defined(HAVE_SETPGID) */
3376
3377#if defined(HAVE_TCGETPGRP)
3378
3379PyDoc_STRVAR(os_tcgetpgrp__doc__,
3380"tcgetpgrp($module, fd, /)\n"
3381"--\n"
3382"\n"
3383"Return the process group associated with the terminal specified by fd.");
3384
3385#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003386 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003387
3388static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003389os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003390
3391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003392os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003393{
3394 PyObject *return_value = NULL;
3395 int fd;
3396
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003397 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003398 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003399 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003400 return_value = os_tcgetpgrp_impl(module, fd);
3401
3402exit:
3403 return return_value;
3404}
3405
3406#endif /* defined(HAVE_TCGETPGRP) */
3407
3408#if defined(HAVE_TCSETPGRP)
3409
3410PyDoc_STRVAR(os_tcsetpgrp__doc__,
3411"tcsetpgrp($module, fd, pgid, /)\n"
3412"--\n"
3413"\n"
3414"Set the process group associated with the terminal specified by fd.");
3415
3416#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003417 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003418
3419static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003420os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003421
3422static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003423os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003424{
3425 PyObject *return_value = NULL;
3426 int fd;
3427 pid_t pgid;
3428
Sylvain74453812017-06-10 06:51:48 +02003429 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3430 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003431 goto exit;
3432 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003433 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3434
3435exit:
3436 return return_value;
3437}
3438
3439#endif /* defined(HAVE_TCSETPGRP) */
3440
3441PyDoc_STRVAR(os_open__doc__,
3442"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3443"--\n"
3444"\n"
3445"Open a file for low level IO. Returns a file descriptor (integer).\n"
3446"\n"
3447"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3448" and path should be relative; path will then be relative to that directory.\n"
3449"dir_fd may not be implemented on your platform.\n"
3450" If it is unavailable, using it will raise a NotImplementedError.");
3451
3452#define OS_OPEN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003453 {"open", (PyCFunction)os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003454
3455static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003456os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003457
3458static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003459os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003460{
3461 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003462 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3463 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003464 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3465 int flags;
3466 int mode = 511;
3467 int dir_fd = DEFAULT_DIR_FD;
3468 int _return_value;
3469
Victor Stinner3e1fad62017-01-17 01:29:01 +01003470 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003471 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003472 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003473 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003474 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003475 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003476 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003477 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003478 return_value = PyLong_FromLong((long)_return_value);
3479
3480exit:
3481 /* Cleanup for path */
3482 path_cleanup(&path);
3483
3484 return return_value;
3485}
3486
3487PyDoc_STRVAR(os_close__doc__,
3488"close($module, /, fd)\n"
3489"--\n"
3490"\n"
3491"Close a file descriptor.");
3492
3493#define OS_CLOSE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003494 {"close", (PyCFunction)os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003495
3496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003497os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003498
3499static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003500os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003501{
3502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003503 static const char * const _keywords[] = {"fd", NULL};
3504 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003505 int fd;
3506
Victor Stinner3e1fad62017-01-17 01:29:01 +01003507 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003508 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003511 return_value = os_close_impl(module, fd);
3512
3513exit:
3514 return return_value;
3515}
3516
3517PyDoc_STRVAR(os_closerange__doc__,
3518"closerange($module, fd_low, fd_high, /)\n"
3519"--\n"
3520"\n"
3521"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3522
3523#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003524 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003525
3526static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003527os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003528
3529static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003530os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003531{
3532 PyObject *return_value = NULL;
3533 int fd_low;
3534 int fd_high;
3535
Sylvain74453812017-06-10 06:51:48 +02003536 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3537 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003538 goto exit;
3539 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003540 return_value = os_closerange_impl(module, fd_low, fd_high);
3541
3542exit:
3543 return return_value;
3544}
3545
3546PyDoc_STRVAR(os_dup__doc__,
3547"dup($module, fd, /)\n"
3548"--\n"
3549"\n"
3550"Return a duplicate of a file descriptor.");
3551
3552#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003553 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003554
3555static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003556os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003557
3558static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003559os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003560{
3561 PyObject *return_value = NULL;
3562 int fd;
3563 int _return_value;
3564
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003565 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003566 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003567 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003568 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003569 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003570 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003571 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003572 return_value = PyLong_FromLong((long)_return_value);
3573
3574exit:
3575 return return_value;
3576}
3577
3578PyDoc_STRVAR(os_dup2__doc__,
3579"dup2($module, /, fd, fd2, inheritable=True)\n"
3580"--\n"
3581"\n"
3582"Duplicate file descriptor.");
3583
3584#define OS_DUP2_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003585 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003586
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003587static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003588os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003589
3590static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003591os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003592{
3593 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003594 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3595 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003596 int fd;
3597 int fd2;
3598 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003599 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003600
Victor Stinner3e1fad62017-01-17 01:29:01 +01003601 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003602 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003603 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003604 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003605 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3606 if ((_return_value == -1) && PyErr_Occurred()) {
3607 goto exit;
3608 }
3609 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003610
3611exit:
3612 return return_value;
3613}
3614
3615#if defined(HAVE_LOCKF)
3616
3617PyDoc_STRVAR(os_lockf__doc__,
3618"lockf($module, fd, command, length, /)\n"
3619"--\n"
3620"\n"
3621"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3622"\n"
3623" fd\n"
3624" An open file descriptor.\n"
3625" command\n"
3626" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3627" length\n"
3628" The number of bytes to lock, starting at the current position.");
3629
3630#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003631 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003632
3633static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003634os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003635
3636static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003637os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003638{
3639 PyObject *return_value = NULL;
3640 int fd;
3641 int command;
3642 Py_off_t length;
3643
Sylvain74453812017-06-10 06:51:48 +02003644 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3645 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003646 goto exit;
3647 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003648 return_value = os_lockf_impl(module, fd, command, length);
3649
3650exit:
3651 return return_value;
3652}
3653
3654#endif /* defined(HAVE_LOCKF) */
3655
3656PyDoc_STRVAR(os_lseek__doc__,
3657"lseek($module, fd, position, how, /)\n"
3658"--\n"
3659"\n"
3660"Set the position of a file descriptor. Return the new position.\n"
3661"\n"
3662"Return the new cursor position in number of bytes\n"
3663"relative to the beginning of the file.");
3664
3665#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003666 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003667
3668static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003669os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003670
3671static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003672os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003673{
3674 PyObject *return_value = NULL;
3675 int fd;
3676 Py_off_t position;
3677 int how;
3678 Py_off_t _return_value;
3679
Sylvain74453812017-06-10 06:51:48 +02003680 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3681 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003682 goto exit;
3683 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003684 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003685 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003686 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003687 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003688 return_value = PyLong_FromPy_off_t(_return_value);
3689
3690exit:
3691 return return_value;
3692}
3693
3694PyDoc_STRVAR(os_read__doc__,
3695"read($module, fd, length, /)\n"
3696"--\n"
3697"\n"
3698"Read from a file descriptor. Returns a bytes object.");
3699
3700#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003701 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003702
3703static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003704os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003705
3706static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003707os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003708{
3709 PyObject *return_value = NULL;
3710 int fd;
3711 Py_ssize_t length;
3712
Sylvain74453812017-06-10 06:51:48 +02003713 if (!_PyArg_ParseStack(args, nargs, "in:read",
3714 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003715 goto exit;
3716 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003717 return_value = os_read_impl(module, fd, length);
3718
3719exit:
3720 return return_value;
3721}
3722
3723#if defined(HAVE_READV)
3724
3725PyDoc_STRVAR(os_readv__doc__,
3726"readv($module, fd, buffers, /)\n"
3727"--\n"
3728"\n"
3729"Read from a file descriptor fd into an iterable of buffers.\n"
3730"\n"
3731"The buffers should be mutable buffers accepting bytes.\n"
3732"readv will transfer data into each buffer until it is full\n"
3733"and then move on to the next buffer in the sequence to hold\n"
3734"the rest of the data.\n"
3735"\n"
3736"readv returns the total number of bytes read,\n"
3737"which may be less than the total capacity of all the buffers.");
3738
3739#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003740 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003741
3742static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003743os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003744
3745static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003746os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003747{
3748 PyObject *return_value = NULL;
3749 int fd;
3750 PyObject *buffers;
3751 Py_ssize_t _return_value;
3752
Sylvain74453812017-06-10 06:51:48 +02003753 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3754 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003755 goto exit;
3756 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003757 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003758 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003759 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003760 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003761 return_value = PyLong_FromSsize_t(_return_value);
3762
3763exit:
3764 return return_value;
3765}
3766
3767#endif /* defined(HAVE_READV) */
3768
3769#if defined(HAVE_PREAD)
3770
3771PyDoc_STRVAR(os_pread__doc__,
3772"pread($module, fd, length, offset, /)\n"
3773"--\n"
3774"\n"
3775"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3776"\n"
3777"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3778"the beginning of the file. The file offset remains unchanged.");
3779
3780#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003781 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003782
3783static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003784os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003785
3786static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003787os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003788{
3789 PyObject *return_value = NULL;
3790 int fd;
3791 int length;
3792 Py_off_t offset;
3793
Sylvain74453812017-06-10 06:51:48 +02003794 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3795 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003796 goto exit;
3797 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003798 return_value = os_pread_impl(module, fd, length, offset);
3799
3800exit:
3801 return return_value;
3802}
3803
3804#endif /* defined(HAVE_PREAD) */
3805
Pablo Galindo4defba32018-01-27 16:16:37 +00003806#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3807
3808PyDoc_STRVAR(os_preadv__doc__,
3809"preadv($module, fd, buffers, offset, flags=0, /)\n"
3810"--\n"
3811"\n"
3812"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3813"\n"
3814"Combines the functionality of readv() and pread(). As readv(), it will\n"
3815"transfer data into each buffer until it is full and then move on to the next\n"
3816"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3817"specifies the file offset at which the input operation is to be performed. It\n"
3818"will return the total number of bytes read (which can be less than the total\n"
3819"capacity of all the objects).\n"
3820"\n"
3821"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3822"\n"
3823"- RWF_HIPRI\n"
3824"- RWF_NOWAIT\n"
3825"\n"
3826"Using non-zero flags requires Linux 4.6 or newer.");
3827
3828#define OS_PREADV_METHODDEF \
3829 {"preadv", (PyCFunction)os_preadv, METH_FASTCALL, os_preadv__doc__},
3830
3831static Py_ssize_t
3832os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
3833 int flags);
3834
3835static PyObject *
3836os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3837{
3838 PyObject *return_value = NULL;
3839 int fd;
3840 PyObject *buffers;
3841 Py_off_t offset;
3842 int flags = 0;
3843 Py_ssize_t _return_value;
3844
3845 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",
3846 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
3847 goto exit;
3848 }
3849 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
3850 if ((_return_value == -1) && PyErr_Occurred()) {
3851 goto exit;
3852 }
3853 return_value = PyLong_FromSsize_t(_return_value);
3854
3855exit:
3856 return return_value;
3857}
3858
3859#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
3860
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003861PyDoc_STRVAR(os_write__doc__,
3862"write($module, fd, data, /)\n"
3863"--\n"
3864"\n"
3865"Write a bytes object to a file descriptor.");
3866
3867#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003868 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003869
3870static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003871os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003872
3873static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003874os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003875{
3876 PyObject *return_value = NULL;
3877 int fd;
3878 Py_buffer data = {NULL, NULL};
3879 Py_ssize_t _return_value;
3880
Sylvain74453812017-06-10 06:51:48 +02003881 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3882 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003883 goto exit;
3884 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003885 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003886 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003887 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003888 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003889 return_value = PyLong_FromSsize_t(_return_value);
3890
3891exit:
3892 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003893 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003894 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003895 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003896
3897 return return_value;
3898}
3899
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003900#if defined(__APPLE__)
3901
3902PyDoc_STRVAR(os__fcopyfile__doc__,
3903"_fcopyfile($module, infd, outfd, flags, /)\n"
3904"--\n"
3905"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07003906"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003907
3908#define OS__FCOPYFILE_METHODDEF \
3909 {"_fcopyfile", (PyCFunction)os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
3910
3911static PyObject *
3912os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
3913
3914static PyObject *
3915os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3916{
3917 PyObject *return_value = NULL;
3918 int infd;
3919 int outfd;
3920 int flags;
3921
3922 if (!_PyArg_ParseStack(args, nargs, "iii:_fcopyfile",
3923 &infd, &outfd, &flags)) {
3924 goto exit;
3925 }
3926 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
3927
3928exit:
3929 return return_value;
3930}
3931
3932#endif /* defined(__APPLE__) */
3933
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003934PyDoc_STRVAR(os_fstat__doc__,
3935"fstat($module, /, fd)\n"
3936"--\n"
3937"\n"
3938"Perform a stat system call on the given file descriptor.\n"
3939"\n"
3940"Like stat(), but for an open file descriptor.\n"
3941"Equivalent to os.stat(fd).");
3942
3943#define OS_FSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003944 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003945
3946static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003947os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003948
3949static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003950os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003951{
3952 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003953 static const char * const _keywords[] = {"fd", NULL};
3954 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003955 int fd;
3956
Victor Stinner3e1fad62017-01-17 01:29:01 +01003957 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003958 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003959 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003960 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003961 return_value = os_fstat_impl(module, fd);
3962
3963exit:
3964 return return_value;
3965}
3966
3967PyDoc_STRVAR(os_isatty__doc__,
3968"isatty($module, fd, /)\n"
3969"--\n"
3970"\n"
3971"Return True if the fd is connected to a terminal.\n"
3972"\n"
3973"Return True if the file descriptor is an open file descriptor\n"
3974"connected to the slave end of a terminal.");
3975
3976#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003977 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003978
3979static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003980os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003981
3982static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003983os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003984{
3985 PyObject *return_value = NULL;
3986 int fd;
3987 int _return_value;
3988
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003989 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003990 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003991 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003992 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003993 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003994 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003995 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003996 return_value = PyBool_FromLong((long)_return_value);
3997
3998exit:
3999 return return_value;
4000}
4001
4002#if defined(HAVE_PIPE)
4003
4004PyDoc_STRVAR(os_pipe__doc__,
4005"pipe($module, /)\n"
4006"--\n"
4007"\n"
4008"Create a pipe.\n"
4009"\n"
4010"Returns a tuple of two file descriptors:\n"
4011" (read_fd, write_fd)");
4012
4013#define OS_PIPE_METHODDEF \
4014 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
4015
4016static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004017os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004018
4019static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004020os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004021{
4022 return os_pipe_impl(module);
4023}
4024
4025#endif /* defined(HAVE_PIPE) */
4026
4027#if defined(HAVE_PIPE2)
4028
4029PyDoc_STRVAR(os_pipe2__doc__,
4030"pipe2($module, flags, /)\n"
4031"--\n"
4032"\n"
4033"Create a pipe with flags set atomically.\n"
4034"\n"
4035"Returns a tuple of two file descriptors:\n"
4036" (read_fd, write_fd)\n"
4037"\n"
4038"flags can be constructed by ORing together one or more of these values:\n"
4039"O_NONBLOCK, O_CLOEXEC.");
4040
4041#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004042 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004043
4044static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004045os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004046
4047static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004048os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004049{
4050 PyObject *return_value = NULL;
4051 int flags;
4052
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004053 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004054 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004055 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004056 return_value = os_pipe2_impl(module, flags);
4057
4058exit:
4059 return return_value;
4060}
4061
4062#endif /* defined(HAVE_PIPE2) */
4063
4064#if defined(HAVE_WRITEV)
4065
4066PyDoc_STRVAR(os_writev__doc__,
4067"writev($module, fd, buffers, /)\n"
4068"--\n"
4069"\n"
4070"Iterate over buffers, and write the contents of each to a file descriptor.\n"
4071"\n"
4072"Returns the total number of bytes written.\n"
4073"buffers must be a sequence of bytes-like objects.");
4074
4075#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004076 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004077
4078static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004079os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004080
4081static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004082os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004083{
4084 PyObject *return_value = NULL;
4085 int fd;
4086 PyObject *buffers;
4087 Py_ssize_t _return_value;
4088
Sylvain74453812017-06-10 06:51:48 +02004089 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
4090 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004091 goto exit;
4092 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004093 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004094 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004095 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004096 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004097 return_value = PyLong_FromSsize_t(_return_value);
4098
4099exit:
4100 return return_value;
4101}
4102
4103#endif /* defined(HAVE_WRITEV) */
4104
4105#if defined(HAVE_PWRITE)
4106
4107PyDoc_STRVAR(os_pwrite__doc__,
4108"pwrite($module, fd, buffer, offset, /)\n"
4109"--\n"
4110"\n"
4111"Write bytes to a file descriptor starting at a particular offset.\n"
4112"\n"
4113"Write buffer to fd, starting at offset bytes from the beginning of\n"
4114"the file. Returns the number of bytes writte. Does not change the\n"
4115"current file offset.");
4116
4117#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004118 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004119
4120static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004121os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004122
4123static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004124os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004125{
4126 PyObject *return_value = NULL;
4127 int fd;
4128 Py_buffer buffer = {NULL, NULL};
4129 Py_off_t offset;
4130 Py_ssize_t _return_value;
4131
Sylvain74453812017-06-10 06:51:48 +02004132 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4133 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004134 goto exit;
4135 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004136 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004137 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004138 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004139 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004140 return_value = PyLong_FromSsize_t(_return_value);
4141
4142exit:
4143 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004144 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004145 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004146 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004147
4148 return return_value;
4149}
4150
4151#endif /* defined(HAVE_PWRITE) */
4152
Pablo Galindo4defba32018-01-27 16:16:37 +00004153#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4154
4155PyDoc_STRVAR(os_pwritev__doc__,
4156"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4157"--\n"
4158"\n"
4159"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4160"\n"
4161"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4162"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4163"buffer is written before proceeding to second, and so on. The operating system may\n"
4164"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4165"This function writes the contents of each object to the file descriptor and returns\n"
4166"the total number of bytes written.\n"
4167"\n"
4168"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4169"\n"
4170"- RWF_DSYNC\n"
4171"- RWF_SYNC\n"
4172"\n"
4173"Using non-zero flags requires Linux 4.7 or newer.");
4174
4175#define OS_PWRITEV_METHODDEF \
4176 {"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},
4177
4178static Py_ssize_t
4179os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4180 int flags);
4181
4182static PyObject *
4183os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4184{
4185 PyObject *return_value = NULL;
4186 int fd;
4187 PyObject *buffers;
4188 Py_off_t offset;
4189 int flags = 0;
4190 Py_ssize_t _return_value;
4191
4192 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4193 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4194 goto exit;
4195 }
4196 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4197 if ((_return_value == -1) && PyErr_Occurred()) {
4198 goto exit;
4199 }
4200 return_value = PyLong_FromSsize_t(_return_value);
4201
4202exit:
4203 return return_value;
4204}
4205
4206#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4207
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004208#if defined(HAVE_MKFIFO)
4209
4210PyDoc_STRVAR(os_mkfifo__doc__,
4211"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4212"--\n"
4213"\n"
4214"Create a \"fifo\" (a POSIX named pipe).\n"
4215"\n"
4216"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4217" and path should be relative; path will then be relative to that directory.\n"
4218"dir_fd may not be implemented on your platform.\n"
4219" If it is unavailable, using it will raise a NotImplementedError.");
4220
4221#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004222 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004223
4224static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004225os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004226
4227static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004228os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004229{
4230 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004231 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4232 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004233 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4234 int mode = 438;
4235 int dir_fd = DEFAULT_DIR_FD;
4236
Victor Stinner3e1fad62017-01-17 01:29:01 +01004237 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004238 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004239 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004240 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004241 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4242
4243exit:
4244 /* Cleanup for path */
4245 path_cleanup(&path);
4246
4247 return return_value;
4248}
4249
4250#endif /* defined(HAVE_MKFIFO) */
4251
4252#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4253
4254PyDoc_STRVAR(os_mknod__doc__,
4255"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4256"--\n"
4257"\n"
4258"Create a node in the file system.\n"
4259"\n"
4260"Create a node in the file system (file, device special file or named pipe)\n"
4261"at path. mode specifies both the permissions to use and the\n"
4262"type of node to be created, being combined (bitwise OR) with one of\n"
4263"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4264"device defines the newly created device special file (probably using\n"
4265"os.makedev()). Otherwise device is ignored.\n"
4266"\n"
4267"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4268" and path should be relative; path will then be relative to that directory.\n"
4269"dir_fd may not be implemented on your platform.\n"
4270" If it is unavailable, using it will raise a NotImplementedError.");
4271
4272#define OS_MKNOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004273 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004274
4275static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004276os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004277 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004278
4279static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004280os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004281{
4282 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004283 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4284 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004285 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4286 int mode = 384;
4287 dev_t device = 0;
4288 int dir_fd = DEFAULT_DIR_FD;
4289
Victor Stinner3e1fad62017-01-17 01:29:01 +01004290 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004291 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004292 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004293 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004294 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4295
4296exit:
4297 /* Cleanup for path */
4298 path_cleanup(&path);
4299
4300 return return_value;
4301}
4302
4303#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4304
4305#if defined(HAVE_DEVICE_MACROS)
4306
4307PyDoc_STRVAR(os_major__doc__,
4308"major($module, device, /)\n"
4309"--\n"
4310"\n"
4311"Extracts a device major number from a raw device number.");
4312
4313#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004314 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004315
4316static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004317os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004318
4319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004320os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004321{
4322 PyObject *return_value = NULL;
4323 dev_t device;
4324 unsigned int _return_value;
4325
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004326 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004327 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004328 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004329 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004330 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004331 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004332 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004333 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4334
4335exit:
4336 return return_value;
4337}
4338
4339#endif /* defined(HAVE_DEVICE_MACROS) */
4340
4341#if defined(HAVE_DEVICE_MACROS)
4342
4343PyDoc_STRVAR(os_minor__doc__,
4344"minor($module, device, /)\n"
4345"--\n"
4346"\n"
4347"Extracts a device minor number from a raw device number.");
4348
4349#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004350 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004351
4352static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004353os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004354
4355static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004356os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004357{
4358 PyObject *return_value = NULL;
4359 dev_t device;
4360 unsigned int _return_value;
4361
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004362 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004363 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004364 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004365 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004366 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004367 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004368 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004369 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4370
4371exit:
4372 return return_value;
4373}
4374
4375#endif /* defined(HAVE_DEVICE_MACROS) */
4376
4377#if defined(HAVE_DEVICE_MACROS)
4378
4379PyDoc_STRVAR(os_makedev__doc__,
4380"makedev($module, major, minor, /)\n"
4381"--\n"
4382"\n"
4383"Composes a raw device number from the major and minor device numbers.");
4384
4385#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004386 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004387
4388static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004389os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004390
4391static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004392os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004393{
4394 PyObject *return_value = NULL;
4395 int major;
4396 int minor;
4397 dev_t _return_value;
4398
Sylvain74453812017-06-10 06:51:48 +02004399 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4400 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004401 goto exit;
4402 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004403 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004404 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004405 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004406 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004407 return_value = _PyLong_FromDev(_return_value);
4408
4409exit:
4410 return return_value;
4411}
4412
4413#endif /* defined(HAVE_DEVICE_MACROS) */
4414
Steve Dowerf7377032015-04-12 15:44:54 -04004415#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004416
4417PyDoc_STRVAR(os_ftruncate__doc__,
4418"ftruncate($module, fd, length, /)\n"
4419"--\n"
4420"\n"
4421"Truncate a file, specified by file descriptor, to a specific length.");
4422
4423#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004424 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004425
4426static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004427os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004428
4429static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004430os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004431{
4432 PyObject *return_value = NULL;
4433 int fd;
4434 Py_off_t length;
4435
Sylvain74453812017-06-10 06:51:48 +02004436 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4437 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004438 goto exit;
4439 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004440 return_value = os_ftruncate_impl(module, fd, length);
4441
4442exit:
4443 return return_value;
4444}
4445
Steve Dowerf7377032015-04-12 15:44:54 -04004446#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004447
Steve Dowerf7377032015-04-12 15:44:54 -04004448#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004449
4450PyDoc_STRVAR(os_truncate__doc__,
4451"truncate($module, /, path, length)\n"
4452"--\n"
4453"\n"
4454"Truncate a file, specified by path, to a specific length.\n"
4455"\n"
4456"On some platforms, path may also be specified as an open file descriptor.\n"
4457" If this functionality is unavailable, using it raises an exception.");
4458
4459#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004460 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004461
4462static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004463os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004464
4465static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004466os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004467{
4468 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004469 static const char * const _keywords[] = {"path", "length", NULL};
4470 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004471 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4472 Py_off_t length;
4473
Victor Stinner3e1fad62017-01-17 01:29:01 +01004474 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004475 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004476 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004477 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004478 return_value = os_truncate_impl(module, &path, length);
4479
4480exit:
4481 /* Cleanup for path */
4482 path_cleanup(&path);
4483
4484 return return_value;
4485}
4486
Steve Dowerf7377032015-04-12 15:44:54 -04004487#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004488
4489#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4490
4491PyDoc_STRVAR(os_posix_fallocate__doc__,
4492"posix_fallocate($module, fd, offset, length, /)\n"
4493"--\n"
4494"\n"
4495"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4496"\n"
4497"Ensure that the file specified by fd encompasses a range of bytes\n"
4498"starting at offset bytes from the beginning and continuing for length bytes.");
4499
4500#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004501 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004502
4503static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004504os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004505 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004506
4507static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004508os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004509{
4510 PyObject *return_value = NULL;
4511 int fd;
4512 Py_off_t offset;
4513 Py_off_t length;
4514
Sylvain74453812017-06-10 06:51:48 +02004515 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4516 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004517 goto exit;
4518 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004519 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4520
4521exit:
4522 return return_value;
4523}
4524
4525#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4526
4527#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4528
4529PyDoc_STRVAR(os_posix_fadvise__doc__,
4530"posix_fadvise($module, fd, offset, length, advice, /)\n"
4531"--\n"
4532"\n"
4533"Announce an intention to access data in a specific pattern.\n"
4534"\n"
4535"Announce an intention to access data in a specific pattern, thus allowing\n"
4536"the kernel to make optimizations.\n"
4537"The advice applies to the region of the file specified by fd starting at\n"
4538"offset and continuing for length bytes.\n"
4539"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4540"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4541"POSIX_FADV_DONTNEED.");
4542
4543#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004544 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004545
4546static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004547os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004548 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004549
4550static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004551os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004552{
4553 PyObject *return_value = NULL;
4554 int fd;
4555 Py_off_t offset;
4556 Py_off_t length;
4557 int advice;
4558
Sylvain74453812017-06-10 06:51:48 +02004559 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4560 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004561 goto exit;
4562 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004563 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4564
4565exit:
4566 return return_value;
4567}
4568
4569#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4570
4571#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4572
4573PyDoc_STRVAR(os_putenv__doc__,
4574"putenv($module, name, value, /)\n"
4575"--\n"
4576"\n"
4577"Change or add an environment variable.");
4578
4579#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004580 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004581
4582static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004583os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004584
4585static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004586os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004587{
4588 PyObject *return_value = NULL;
4589 PyObject *name;
4590 PyObject *value;
4591
Sylvain74453812017-06-10 06:51:48 +02004592 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4593 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004594 goto exit;
4595 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004596 return_value = os_putenv_impl(module, name, value);
4597
4598exit:
4599 return return_value;
4600}
4601
4602#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4603
4604#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4605
4606PyDoc_STRVAR(os_putenv__doc__,
4607"putenv($module, name, value, /)\n"
4608"--\n"
4609"\n"
4610"Change or add an environment variable.");
4611
4612#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004613 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004614
4615static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004616os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004617
4618static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004619os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004620{
4621 PyObject *return_value = NULL;
4622 PyObject *name = NULL;
4623 PyObject *value = NULL;
4624
Sylvain74453812017-06-10 06:51:48 +02004625 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4626 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004627 goto exit;
4628 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004629 return_value = os_putenv_impl(module, name, value);
4630
4631exit:
4632 /* Cleanup for name */
4633 Py_XDECREF(name);
4634 /* Cleanup for value */
4635 Py_XDECREF(value);
4636
4637 return return_value;
4638}
4639
4640#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4641
4642#if defined(HAVE_UNSETENV)
4643
4644PyDoc_STRVAR(os_unsetenv__doc__,
4645"unsetenv($module, name, /)\n"
4646"--\n"
4647"\n"
4648"Delete an environment variable.");
4649
4650#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004651 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004652
4653static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004654os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004655
4656static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004657os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004658{
4659 PyObject *return_value = NULL;
4660 PyObject *name = NULL;
4661
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004662 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004663 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004664 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004665 return_value = os_unsetenv_impl(module, name);
4666
4667exit:
4668 /* Cleanup for name */
4669 Py_XDECREF(name);
4670
4671 return return_value;
4672}
4673
4674#endif /* defined(HAVE_UNSETENV) */
4675
4676PyDoc_STRVAR(os_strerror__doc__,
4677"strerror($module, code, /)\n"
4678"--\n"
4679"\n"
4680"Translate an error code to a message string.");
4681
4682#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004683 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004684
4685static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004686os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004687
4688static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004689os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004690{
4691 PyObject *return_value = NULL;
4692 int code;
4693
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004694 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004695 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004696 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004697 return_value = os_strerror_impl(module, code);
4698
4699exit:
4700 return return_value;
4701}
4702
4703#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4704
4705PyDoc_STRVAR(os_WCOREDUMP__doc__,
4706"WCOREDUMP($module, status, /)\n"
4707"--\n"
4708"\n"
4709"Return True if the process returning status was dumped to a core file.");
4710
4711#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004712 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004713
4714static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004715os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004716
4717static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004718os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004719{
4720 PyObject *return_value = NULL;
4721 int status;
4722 int _return_value;
4723
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004724 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004725 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004726 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004727 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004728 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004729 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004730 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004731 return_value = PyBool_FromLong((long)_return_value);
4732
4733exit:
4734 return return_value;
4735}
4736
4737#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4738
4739#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4740
4741PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4742"WIFCONTINUED($module, /, status)\n"
4743"--\n"
4744"\n"
4745"Return True if a particular process was continued from a job control stop.\n"
4746"\n"
4747"Return True if the process returning status was continued from a\n"
4748"job control stop.");
4749
4750#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004751 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004752
4753static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004754os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004755
4756static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004757os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004758{
4759 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004760 static const char * const _keywords[] = {"status", NULL};
4761 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004762 int status;
4763 int _return_value;
4764
Victor Stinner3e1fad62017-01-17 01:29:01 +01004765 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004766 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004767 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004768 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004769 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004770 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004771 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004772 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004773 return_value = PyBool_FromLong((long)_return_value);
4774
4775exit:
4776 return return_value;
4777}
4778
4779#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4780
4781#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4782
4783PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4784"WIFSTOPPED($module, /, status)\n"
4785"--\n"
4786"\n"
4787"Return True if the process returning status was stopped.");
4788
4789#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004790 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004791
4792static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004793os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004794
4795static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004796os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004797{
4798 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004799 static const char * const _keywords[] = {"status", NULL};
4800 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004801 int status;
4802 int _return_value;
4803
Victor Stinner3e1fad62017-01-17 01:29:01 +01004804 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004805 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004806 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004807 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004808 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004809 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004810 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004811 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004812 return_value = PyBool_FromLong((long)_return_value);
4813
4814exit:
4815 return return_value;
4816}
4817
4818#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4819
4820#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4821
4822PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4823"WIFSIGNALED($module, /, status)\n"
4824"--\n"
4825"\n"
4826"Return True if the process returning status was terminated by a signal.");
4827
4828#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004829 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004830
4831static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004832os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004833
4834static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004835os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004836{
4837 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004838 static const char * const _keywords[] = {"status", NULL};
4839 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004840 int status;
4841 int _return_value;
4842
Victor Stinner3e1fad62017-01-17 01:29:01 +01004843 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004844 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004845 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004846 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004847 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004848 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004849 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004850 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004851 return_value = PyBool_FromLong((long)_return_value);
4852
4853exit:
4854 return return_value;
4855}
4856
4857#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4858
4859#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4860
4861PyDoc_STRVAR(os_WIFEXITED__doc__,
4862"WIFEXITED($module, /, status)\n"
4863"--\n"
4864"\n"
4865"Return True if the process returning status exited via the exit() system call.");
4866
4867#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004868 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004869
4870static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004871os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004872
4873static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004874os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004875{
4876 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004877 static const char * const _keywords[] = {"status", NULL};
4878 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004879 int status;
4880 int _return_value;
4881
Victor Stinner3e1fad62017-01-17 01:29:01 +01004882 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004883 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004884 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004885 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004886 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004887 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004888 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004889 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004890 return_value = PyBool_FromLong((long)_return_value);
4891
4892exit:
4893 return return_value;
4894}
4895
4896#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4897
4898#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4899
4900PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4901"WEXITSTATUS($module, /, status)\n"
4902"--\n"
4903"\n"
4904"Return the process return code from status.");
4905
4906#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004907 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004908
4909static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004910os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004911
4912static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004913os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004914{
4915 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004916 static const char * const _keywords[] = {"status", NULL};
4917 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004918 int status;
4919 int _return_value;
4920
Victor Stinner3e1fad62017-01-17 01:29:01 +01004921 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004922 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004923 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004924 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004925 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004926 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004927 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004928 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004929 return_value = PyLong_FromLong((long)_return_value);
4930
4931exit:
4932 return return_value;
4933}
4934
4935#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4936
4937#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4938
4939PyDoc_STRVAR(os_WTERMSIG__doc__,
4940"WTERMSIG($module, /, status)\n"
4941"--\n"
4942"\n"
4943"Return the signal that terminated the process that provided the status value.");
4944
4945#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004946 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004947
4948static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004949os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004950
4951static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004952os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004953{
4954 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004955 static const char * const _keywords[] = {"status", NULL};
4956 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004957 int status;
4958 int _return_value;
4959
Victor Stinner3e1fad62017-01-17 01:29:01 +01004960 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004961 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004962 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004963 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004964 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004965 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004966 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004967 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004968 return_value = PyLong_FromLong((long)_return_value);
4969
4970exit:
4971 return return_value;
4972}
4973
4974#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4975
4976#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4977
4978PyDoc_STRVAR(os_WSTOPSIG__doc__,
4979"WSTOPSIG($module, /, status)\n"
4980"--\n"
4981"\n"
4982"Return the signal that stopped the process that provided the status value.");
4983
4984#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004985 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004986
4987static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004988os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004989
4990static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004991os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004992{
4993 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004994 static const char * const _keywords[] = {"status", NULL};
4995 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004996 int status;
4997 int _return_value;
4998
Victor Stinner3e1fad62017-01-17 01:29:01 +01004999 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005000 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005001 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005002 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005003 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005004 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005005 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005006 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005007 return_value = PyLong_FromLong((long)_return_value);
5008
5009exit:
5010 return return_value;
5011}
5012
5013#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
5014
5015#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
5016
5017PyDoc_STRVAR(os_fstatvfs__doc__,
5018"fstatvfs($module, fd, /)\n"
5019"--\n"
5020"\n"
5021"Perform an fstatvfs system call on the given fd.\n"
5022"\n"
5023"Equivalent to statvfs(fd).");
5024
5025#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005026 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005027
5028static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005029os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005030
5031static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005032os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005033{
5034 PyObject *return_value = NULL;
5035 int fd;
5036
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005037 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005038 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005039 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005040 return_value = os_fstatvfs_impl(module, fd);
5041
5042exit:
5043 return return_value;
5044}
5045
5046#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5047
5048#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
5049
5050PyDoc_STRVAR(os_statvfs__doc__,
5051"statvfs($module, /, path)\n"
5052"--\n"
5053"\n"
5054"Perform a statvfs system call on the given path.\n"
5055"\n"
5056"path may always be specified as a string.\n"
5057"On some platforms, path may also be specified as an open file descriptor.\n"
5058" If this functionality is unavailable, using it raises an exception.");
5059
5060#define OS_STATVFS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005061 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005062
5063static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005064os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005065
5066static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005067os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005068{
5069 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005070 static const char * const _keywords[] = {"path", NULL};
5071 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005072 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
5073
Victor Stinner3e1fad62017-01-17 01:29:01 +01005074 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005075 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005076 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005077 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005078 return_value = os_statvfs_impl(module, &path);
5079
5080exit:
5081 /* Cleanup for path */
5082 path_cleanup(&path);
5083
5084 return return_value;
5085}
5086
5087#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5088
5089#if defined(MS_WINDOWS)
5090
5091PyDoc_STRVAR(os__getdiskusage__doc__,
5092"_getdiskusage($module, /, path)\n"
5093"--\n"
5094"\n"
5095"Return disk usage statistics about the given path as a (total, free) tuple.");
5096
5097#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005098 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005099
5100static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005101os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005102
5103static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005104os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005105{
5106 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005107 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005108 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5109 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005110
Victor Stinner3e1fad62017-01-17 01:29:01 +01005111 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005112 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005113 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005114 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005115 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005116
5117exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005118 /* Cleanup for path */
5119 path_cleanup(&path);
5120
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005121 return return_value;
5122}
5123
5124#endif /* defined(MS_WINDOWS) */
5125
5126#if defined(HAVE_FPATHCONF)
5127
5128PyDoc_STRVAR(os_fpathconf__doc__,
5129"fpathconf($module, fd, name, /)\n"
5130"--\n"
5131"\n"
5132"Return the configuration limit name for the file descriptor fd.\n"
5133"\n"
5134"If there is no limit, return -1.");
5135
5136#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005137 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005138
5139static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005140os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005141
5142static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005143os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005144{
5145 PyObject *return_value = NULL;
5146 int fd;
5147 int name;
5148 long _return_value;
5149
Sylvain74453812017-06-10 06:51:48 +02005150 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5151 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005152 goto exit;
5153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005154 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005155 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005156 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005157 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005158 return_value = PyLong_FromLong(_return_value);
5159
5160exit:
5161 return return_value;
5162}
5163
5164#endif /* defined(HAVE_FPATHCONF) */
5165
5166#if defined(HAVE_PATHCONF)
5167
5168PyDoc_STRVAR(os_pathconf__doc__,
5169"pathconf($module, /, path, name)\n"
5170"--\n"
5171"\n"
5172"Return the configuration limit name for the file or directory path.\n"
5173"\n"
5174"If there is no limit, return -1.\n"
5175"On some platforms, path may also be specified as an open file descriptor.\n"
5176" If this functionality is unavailable, using it raises an exception.");
5177
5178#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005179 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005180
5181static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005182os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005183
5184static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005185os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005186{
5187 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005188 static const char * const _keywords[] = {"path", "name", NULL};
5189 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005190 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5191 int name;
5192 long _return_value;
5193
Victor Stinner3e1fad62017-01-17 01:29:01 +01005194 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005195 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005196 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005197 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005198 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005199 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005200 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005201 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005202 return_value = PyLong_FromLong(_return_value);
5203
5204exit:
5205 /* Cleanup for path */
5206 path_cleanup(&path);
5207
5208 return return_value;
5209}
5210
5211#endif /* defined(HAVE_PATHCONF) */
5212
5213#if defined(HAVE_CONFSTR)
5214
5215PyDoc_STRVAR(os_confstr__doc__,
5216"confstr($module, name, /)\n"
5217"--\n"
5218"\n"
5219"Return a string-valued system configuration variable.");
5220
5221#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005222 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005223
5224static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005225os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005226
5227static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005228os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005229{
5230 PyObject *return_value = NULL;
5231 int name;
5232
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005233 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005234 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005235 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005236 return_value = os_confstr_impl(module, name);
5237
5238exit:
5239 return return_value;
5240}
5241
5242#endif /* defined(HAVE_CONFSTR) */
5243
5244#if defined(HAVE_SYSCONF)
5245
5246PyDoc_STRVAR(os_sysconf__doc__,
5247"sysconf($module, name, /)\n"
5248"--\n"
5249"\n"
5250"Return an integer-valued system configuration variable.");
5251
5252#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005253 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005254
5255static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005256os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005257
5258static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005259os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005260{
5261 PyObject *return_value = NULL;
5262 int name;
5263 long _return_value;
5264
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005265 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005266 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005267 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005268 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005269 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005270 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005271 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005272 return_value = PyLong_FromLong(_return_value);
5273
5274exit:
5275 return return_value;
5276}
5277
5278#endif /* defined(HAVE_SYSCONF) */
5279
5280PyDoc_STRVAR(os_abort__doc__,
5281"abort($module, /)\n"
5282"--\n"
5283"\n"
5284"Abort the interpreter immediately.\n"
5285"\n"
5286"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5287"on the hosting operating system. This function never returns.");
5288
5289#define OS_ABORT_METHODDEF \
5290 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5291
5292static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005293os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005294
5295static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005296os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005297{
5298 return os_abort_impl(module);
5299}
5300
Steve Dowercc16be82016-09-08 10:35:16 -07005301#if defined(MS_WINDOWS)
5302
5303PyDoc_STRVAR(os_startfile__doc__,
5304"startfile($module, /, filepath, operation=None)\n"
5305"--\n"
5306"\n"
5307"startfile(filepath [, operation])\n"
5308"\n"
5309"Start a file with its associated application.\n"
5310"\n"
5311"When \"operation\" is not specified or \"open\", this acts like\n"
5312"double-clicking the file in Explorer, or giving the file name as an\n"
5313"argument to the DOS \"start\" command: the file is opened with whatever\n"
5314"application (if any) its extension is associated.\n"
5315"When another \"operation\" is given, it specifies what should be done with\n"
5316"the file. A typical operation is \"print\".\n"
5317"\n"
5318"startfile returns as soon as the associated application is launched.\n"
5319"There is no option to wait for the application to close, and no way\n"
5320"to retrieve the application\'s exit status.\n"
5321"\n"
5322"The filepath is relative to the current directory. If you want to use\n"
5323"an absolute path, make sure the first character is not a slash (\"/\");\n"
5324"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5325
5326#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005327 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005328
5329static PyObject *
5330os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5331
5332static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005333os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005334{
5335 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005336 static const char * const _keywords[] = {"filepath", "operation", NULL};
5337 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005338 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5339 Py_UNICODE *operation = NULL;
5340
Victor Stinner3e1fad62017-01-17 01:29:01 +01005341 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005342 path_converter, &filepath, &operation)) {
5343 goto exit;
5344 }
5345 return_value = os_startfile_impl(module, &filepath, operation);
5346
5347exit:
5348 /* Cleanup for filepath */
5349 path_cleanup(&filepath);
5350
5351 return return_value;
5352}
5353
5354#endif /* defined(MS_WINDOWS) */
5355
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005356#if defined(HAVE_GETLOADAVG)
5357
5358PyDoc_STRVAR(os_getloadavg__doc__,
5359"getloadavg($module, /)\n"
5360"--\n"
5361"\n"
5362"Return average recent system load information.\n"
5363"\n"
5364"Return the number of processes in the system run queue averaged over\n"
5365"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5366"Raises OSError if the load average was unobtainable.");
5367
5368#define OS_GETLOADAVG_METHODDEF \
5369 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5370
5371static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005372os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005373
5374static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005375os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005376{
5377 return os_getloadavg_impl(module);
5378}
5379
5380#endif /* defined(HAVE_GETLOADAVG) */
5381
5382PyDoc_STRVAR(os_device_encoding__doc__,
5383"device_encoding($module, /, fd)\n"
5384"--\n"
5385"\n"
5386"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5387"\n"
5388"The file descriptor must be attached to a terminal.\n"
5389"If the device is not a terminal, return None.");
5390
5391#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005392 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005393
5394static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005395os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005396
5397static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005398os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005399{
5400 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005401 static const char * const _keywords[] = {"fd", NULL};
5402 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005403 int fd;
5404
Victor Stinner3e1fad62017-01-17 01:29:01 +01005405 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005406 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005407 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005408 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005409 return_value = os_device_encoding_impl(module, fd);
5410
5411exit:
5412 return return_value;
5413}
5414
5415#if defined(HAVE_SETRESUID)
5416
5417PyDoc_STRVAR(os_setresuid__doc__,
5418"setresuid($module, ruid, euid, suid, /)\n"
5419"--\n"
5420"\n"
5421"Set the current process\'s real, effective, and saved user ids.");
5422
5423#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005424 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005425
5426static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005427os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005428
5429static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005430os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005431{
5432 PyObject *return_value = NULL;
5433 uid_t ruid;
5434 uid_t euid;
5435 uid_t suid;
5436
Sylvain74453812017-06-10 06:51:48 +02005437 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5438 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005439 goto exit;
5440 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005441 return_value = os_setresuid_impl(module, ruid, euid, suid);
5442
5443exit:
5444 return return_value;
5445}
5446
5447#endif /* defined(HAVE_SETRESUID) */
5448
5449#if defined(HAVE_SETRESGID)
5450
5451PyDoc_STRVAR(os_setresgid__doc__,
5452"setresgid($module, rgid, egid, sgid, /)\n"
5453"--\n"
5454"\n"
5455"Set the current process\'s real, effective, and saved group ids.");
5456
5457#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005458 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005459
5460static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005461os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005462
5463static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005464os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005465{
5466 PyObject *return_value = NULL;
5467 gid_t rgid;
5468 gid_t egid;
5469 gid_t sgid;
5470
Sylvain74453812017-06-10 06:51:48 +02005471 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5472 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005473 goto exit;
5474 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005475 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5476
5477exit:
5478 return return_value;
5479}
5480
5481#endif /* defined(HAVE_SETRESGID) */
5482
5483#if defined(HAVE_GETRESUID)
5484
5485PyDoc_STRVAR(os_getresuid__doc__,
5486"getresuid($module, /)\n"
5487"--\n"
5488"\n"
5489"Return a tuple of the current process\'s real, effective, and saved user ids.");
5490
5491#define OS_GETRESUID_METHODDEF \
5492 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5493
5494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005495os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005496
5497static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005498os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005499{
5500 return os_getresuid_impl(module);
5501}
5502
5503#endif /* defined(HAVE_GETRESUID) */
5504
5505#if defined(HAVE_GETRESGID)
5506
5507PyDoc_STRVAR(os_getresgid__doc__,
5508"getresgid($module, /)\n"
5509"--\n"
5510"\n"
5511"Return a tuple of the current process\'s real, effective, and saved group ids.");
5512
5513#define OS_GETRESGID_METHODDEF \
5514 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5515
5516static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005517os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005518
5519static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005520os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005521{
5522 return os_getresgid_impl(module);
5523}
5524
5525#endif /* defined(HAVE_GETRESGID) */
5526
5527#if defined(USE_XATTRS)
5528
5529PyDoc_STRVAR(os_getxattr__doc__,
5530"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5531"--\n"
5532"\n"
5533"Return the value of extended attribute attribute on path.\n"
5534"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005535"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005536"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5537" link, getxattr will examine the symbolic link itself instead of the file\n"
5538" the link points to.");
5539
5540#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005541 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005542
5543static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005544os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005545 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005546
5547static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005548os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005549{
5550 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005551 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5552 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005553 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5554 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5555 int follow_symlinks = 1;
5556
Victor Stinner3e1fad62017-01-17 01:29:01 +01005557 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005558 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005559 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005560 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005561 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5562
5563exit:
5564 /* Cleanup for path */
5565 path_cleanup(&path);
5566 /* Cleanup for attribute */
5567 path_cleanup(&attribute);
5568
5569 return return_value;
5570}
5571
5572#endif /* defined(USE_XATTRS) */
5573
5574#if defined(USE_XATTRS)
5575
5576PyDoc_STRVAR(os_setxattr__doc__,
5577"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5578" follow_symlinks=True)\n"
5579"--\n"
5580"\n"
5581"Set extended attribute attribute on path to value.\n"
5582"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005583"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005584"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5585" link, setxattr will modify the symbolic link itself instead of the file\n"
5586" the link points to.");
5587
5588#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005589 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005590
5591static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005592os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005593 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005594
5595static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005596os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005597{
5598 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005599 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5600 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005601 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5602 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5603 Py_buffer value = {NULL, NULL};
5604 int flags = 0;
5605 int follow_symlinks = 1;
5606
Victor Stinner3e1fad62017-01-17 01:29:01 +01005607 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005608 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005609 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005610 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005611 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5612
5613exit:
5614 /* Cleanup for path */
5615 path_cleanup(&path);
5616 /* Cleanup for attribute */
5617 path_cleanup(&attribute);
5618 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005619 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005620 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005621 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005622
5623 return return_value;
5624}
5625
5626#endif /* defined(USE_XATTRS) */
5627
5628#if defined(USE_XATTRS)
5629
5630PyDoc_STRVAR(os_removexattr__doc__,
5631"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5632"--\n"
5633"\n"
5634"Remove extended attribute attribute on path.\n"
5635"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005636"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005637"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5638" link, removexattr will modify the symbolic link itself instead of the file\n"
5639" the link points to.");
5640
5641#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005642 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005643
5644static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005645os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005646 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005647
5648static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005649os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005650{
5651 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005652 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5653 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005654 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5655 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5656 int follow_symlinks = 1;
5657
Victor Stinner3e1fad62017-01-17 01:29:01 +01005658 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005659 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005660 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005661 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005662 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5663
5664exit:
5665 /* Cleanup for path */
5666 path_cleanup(&path);
5667 /* Cleanup for attribute */
5668 path_cleanup(&attribute);
5669
5670 return return_value;
5671}
5672
5673#endif /* defined(USE_XATTRS) */
5674
5675#if defined(USE_XATTRS)
5676
5677PyDoc_STRVAR(os_listxattr__doc__,
5678"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5679"--\n"
5680"\n"
5681"Return a list of extended attributes on path.\n"
5682"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005683"path may be either None, a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005684"if path is None, listxattr will examine the current directory.\n"
5685"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5686" link, listxattr will examine the symbolic link itself instead of the file\n"
5687" the link points to.");
5688
5689#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005690 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005691
5692static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005693os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005694
5695static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005696os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005697{
5698 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005699 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5700 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005701 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5702 int follow_symlinks = 1;
5703
Victor Stinner3e1fad62017-01-17 01:29:01 +01005704 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005705 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005706 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005707 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005708 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5709
5710exit:
5711 /* Cleanup for path */
5712 path_cleanup(&path);
5713
5714 return return_value;
5715}
5716
5717#endif /* defined(USE_XATTRS) */
5718
5719PyDoc_STRVAR(os_urandom__doc__,
5720"urandom($module, size, /)\n"
5721"--\n"
5722"\n"
5723"Return a bytes object containing random bytes suitable for cryptographic use.");
5724
5725#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005726 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005727
5728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005729os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005730
5731static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005732os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005733{
5734 PyObject *return_value = NULL;
5735 Py_ssize_t size;
5736
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005737 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005738 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005739 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005740 return_value = os_urandom_impl(module, size);
5741
5742exit:
5743 return return_value;
5744}
5745
5746PyDoc_STRVAR(os_cpu_count__doc__,
5747"cpu_count($module, /)\n"
5748"--\n"
5749"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005750"Return the number of CPUs in the system; return None if indeterminable.\n"
5751"\n"
5752"This number is not equivalent to the number of CPUs the current process can\n"
5753"use. The number of usable CPUs can be obtained with\n"
5754"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005755
5756#define OS_CPU_COUNT_METHODDEF \
5757 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5758
5759static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005760os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005761
5762static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005763os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005764{
5765 return os_cpu_count_impl(module);
5766}
5767
5768PyDoc_STRVAR(os_get_inheritable__doc__,
5769"get_inheritable($module, fd, /)\n"
5770"--\n"
5771"\n"
5772"Get the close-on-exe flag of the specified file descriptor.");
5773
5774#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005775 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005776
5777static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005778os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005779
5780static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005781os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005782{
5783 PyObject *return_value = NULL;
5784 int fd;
5785 int _return_value;
5786
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005787 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005788 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005789 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005790 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005791 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005792 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005793 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005794 return_value = PyBool_FromLong((long)_return_value);
5795
5796exit:
5797 return return_value;
5798}
5799
5800PyDoc_STRVAR(os_set_inheritable__doc__,
5801"set_inheritable($module, fd, inheritable, /)\n"
5802"--\n"
5803"\n"
5804"Set the inheritable flag of the specified file descriptor.");
5805
5806#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005807 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005808
5809static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005810os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005811
5812static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005813os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005814{
5815 PyObject *return_value = NULL;
5816 int fd;
5817 int inheritable;
5818
Sylvain74453812017-06-10 06:51:48 +02005819 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5820 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005821 goto exit;
5822 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005823 return_value = os_set_inheritable_impl(module, fd, inheritable);
5824
5825exit:
5826 return return_value;
5827}
5828
5829#if defined(MS_WINDOWS)
5830
5831PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5832"get_handle_inheritable($module, handle, /)\n"
5833"--\n"
5834"\n"
5835"Get the close-on-exe flag of the specified file descriptor.");
5836
5837#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005838 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005839
5840static int
Victor Stinner581139c2016-09-06 15:54:20 -07005841os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005842
5843static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005844os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005845{
5846 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005847 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005848 int _return_value;
5849
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005850 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005851 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005852 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005853 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005854 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005855 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005856 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005857 return_value = PyBool_FromLong((long)_return_value);
5858
5859exit:
5860 return return_value;
5861}
5862
5863#endif /* defined(MS_WINDOWS) */
5864
5865#if defined(MS_WINDOWS)
5866
5867PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5868"set_handle_inheritable($module, handle, inheritable, /)\n"
5869"--\n"
5870"\n"
5871"Set the inheritable flag of the specified handle.");
5872
5873#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005874 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005875
5876static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005877os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005878 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005879
5880static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005881os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005882{
5883 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005884 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005885 int inheritable;
5886
Sylvain74453812017-06-10 06:51:48 +02005887 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5888 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005889 goto exit;
5890 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005891 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5892
5893exit:
5894 return return_value;
5895}
5896
5897#endif /* defined(MS_WINDOWS) */
5898
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03005899#if !defined(MS_WINDOWS)
5900
5901PyDoc_STRVAR(os_get_blocking__doc__,
5902"get_blocking($module, fd, /)\n"
5903"--\n"
5904"\n"
5905"Get the blocking mode of the file descriptor.\n"
5906"\n"
5907"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
5908
5909#define OS_GET_BLOCKING_METHODDEF \
5910 {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
5911
5912static int
5913os_get_blocking_impl(PyObject *module, int fd);
5914
5915static PyObject *
5916os_get_blocking(PyObject *module, PyObject *arg)
5917{
5918 PyObject *return_value = NULL;
5919 int fd;
5920 int _return_value;
5921
5922 if (!PyArg_Parse(arg, "i:get_blocking", &fd)) {
5923 goto exit;
5924 }
5925 _return_value = os_get_blocking_impl(module, fd);
5926 if ((_return_value == -1) && PyErr_Occurred()) {
5927 goto exit;
5928 }
5929 return_value = PyBool_FromLong((long)_return_value);
5930
5931exit:
5932 return return_value;
5933}
5934
5935#endif /* !defined(MS_WINDOWS) */
5936
5937#if !defined(MS_WINDOWS)
5938
5939PyDoc_STRVAR(os_set_blocking__doc__,
5940"set_blocking($module, fd, blocking, /)\n"
5941"--\n"
5942"\n"
5943"Set the blocking mode of the specified file descriptor.\n"
5944"\n"
5945"Set the O_NONBLOCK flag if blocking is False,\n"
5946"clear the O_NONBLOCK flag otherwise.");
5947
5948#define OS_SET_BLOCKING_METHODDEF \
5949 {"set_blocking", (PyCFunction)os_set_blocking, METH_FASTCALL, os_set_blocking__doc__},
5950
5951static PyObject *
5952os_set_blocking_impl(PyObject *module, int fd, int blocking);
5953
5954static PyObject *
5955os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5956{
5957 PyObject *return_value = NULL;
5958 int fd;
5959 int blocking;
5960
5961 if (!_PyArg_ParseStack(args, nargs, "ii:set_blocking",
5962 &fd, &blocking)) {
5963 goto exit;
5964 }
5965 return_value = os_set_blocking_impl(module, fd, blocking);
5966
5967exit:
5968 return return_value;
5969}
5970
5971#endif /* !defined(MS_WINDOWS) */
5972
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005973PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5974"is_symlink($self, /)\n"
5975"--\n"
5976"\n"
5977"Return True if the entry is a symbolic link; cached per entry.");
5978
5979#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5980 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5981
5982static int
5983os_DirEntry_is_symlink_impl(DirEntry *self);
5984
5985static PyObject *
5986os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5987{
5988 PyObject *return_value = NULL;
5989 int _return_value;
5990
5991 _return_value = os_DirEntry_is_symlink_impl(self);
5992 if ((_return_value == -1) && PyErr_Occurred()) {
5993 goto exit;
5994 }
5995 return_value = PyBool_FromLong((long)_return_value);
5996
5997exit:
5998 return return_value;
5999}
6000
6001PyDoc_STRVAR(os_DirEntry_stat__doc__,
6002"stat($self, /, *, follow_symlinks=True)\n"
6003"--\n"
6004"\n"
6005"Return stat_result object for the entry; cached per entry.");
6006
6007#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006008 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006009
6010static PyObject *
6011os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
6012
6013static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006014os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006015{
6016 PyObject *return_value = NULL;
6017 static const char * const _keywords[] = {"follow_symlinks", NULL};
6018 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
6019 int follow_symlinks = 1;
6020
Victor Stinner3e1fad62017-01-17 01:29:01 +01006021 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006022 &follow_symlinks)) {
6023 goto exit;
6024 }
6025 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
6026
6027exit:
6028 return return_value;
6029}
6030
6031PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
6032"is_dir($self, /, *, follow_symlinks=True)\n"
6033"--\n"
6034"\n"
6035"Return True if the entry is a directory; cached per entry.");
6036
6037#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006038 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006039
6040static int
6041os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
6042
6043static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006044os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006045{
6046 PyObject *return_value = NULL;
6047 static const char * const _keywords[] = {"follow_symlinks", NULL};
6048 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
6049 int follow_symlinks = 1;
6050 int _return_value;
6051
Victor Stinner3e1fad62017-01-17 01:29:01 +01006052 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006053 &follow_symlinks)) {
6054 goto exit;
6055 }
6056 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
6057 if ((_return_value == -1) && PyErr_Occurred()) {
6058 goto exit;
6059 }
6060 return_value = PyBool_FromLong((long)_return_value);
6061
6062exit:
6063 return return_value;
6064}
6065
6066PyDoc_STRVAR(os_DirEntry_is_file__doc__,
6067"is_file($self, /, *, follow_symlinks=True)\n"
6068"--\n"
6069"\n"
6070"Return True if the entry is a file; cached per entry.");
6071
6072#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006073 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006074
6075static int
6076os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
6077
6078static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006079os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006080{
6081 PyObject *return_value = NULL;
6082 static const char * const _keywords[] = {"follow_symlinks", NULL};
6083 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
6084 int follow_symlinks = 1;
6085 int _return_value;
6086
Victor Stinner3e1fad62017-01-17 01:29:01 +01006087 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006088 &follow_symlinks)) {
6089 goto exit;
6090 }
6091 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
6092 if ((_return_value == -1) && PyErr_Occurred()) {
6093 goto exit;
6094 }
6095 return_value = PyBool_FromLong((long)_return_value);
6096
6097exit:
6098 return return_value;
6099}
6100
6101PyDoc_STRVAR(os_DirEntry_inode__doc__,
6102"inode($self, /)\n"
6103"--\n"
6104"\n"
6105"Return inode of the entry; cached per entry.");
6106
6107#define OS_DIRENTRY_INODE_METHODDEF \
6108 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
6109
6110static PyObject *
6111os_DirEntry_inode_impl(DirEntry *self);
6112
6113static PyObject *
6114os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
6115{
6116 return os_DirEntry_inode_impl(self);
6117}
6118
6119PyDoc_STRVAR(os_DirEntry___fspath____doc__,
6120"__fspath__($self, /)\n"
6121"--\n"
6122"\n"
6123"Returns the path for the entry.");
6124
6125#define OS_DIRENTRY___FSPATH___METHODDEF \
6126 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
6127
6128static PyObject *
6129os_DirEntry___fspath___impl(DirEntry *self);
6130
6131static PyObject *
6132os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
6133{
6134 return os_DirEntry___fspath___impl(self);
6135}
6136
6137PyDoc_STRVAR(os_scandir__doc__,
6138"scandir($module, /, path=None)\n"
6139"--\n"
6140"\n"
6141"Return an iterator of DirEntry objects for given path.\n"
6142"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006143"path can be specified as either str, bytes, or a path-like object. If path\n"
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006144"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
6145"all other circumstances they will be str.\n"
6146"\n"
6147"If path is None, uses the path=\'.\'.");
6148
6149#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006150 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006151
6152static PyObject *
6153os_scandir_impl(PyObject *module, path_t *path);
6154
6155static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006156os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006157{
6158 PyObject *return_value = NULL;
6159 static const char * const _keywords[] = {"path", NULL};
6160 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006161 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006162
Victor Stinner3e1fad62017-01-17 01:29:01 +01006163 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006164 path_converter, &path)) {
6165 goto exit;
6166 }
6167 return_value = os_scandir_impl(module, &path);
6168
6169exit:
6170 /* Cleanup for path */
6171 path_cleanup(&path);
6172
6173 return return_value;
6174}
6175
Ethan Furman410ef8e2016-06-04 12:06:26 -07006176PyDoc_STRVAR(os_fspath__doc__,
6177"fspath($module, /, path)\n"
6178"--\n"
6179"\n"
6180"Return the file system path representation of the object.\n"
6181"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006182"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6183"object defines __fspath__(), then return the result of that method. All other\n"
6184"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006185
6186#define OS_FSPATH_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006187 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006188
6189static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006190os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006191
6192static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006193os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006194{
6195 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006196 static const char * const _keywords[] = {"path", NULL};
6197 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006198 PyObject *path;
6199
Victor Stinner3e1fad62017-01-17 01:29:01 +01006200 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006201 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006202 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006203 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006204 return_value = os_fspath_impl(module, path);
6205
6206exit:
6207 return return_value;
6208}
6209
Victor Stinner9b1f4742016-09-06 16:18:52 -07006210#if defined(HAVE_GETRANDOM_SYSCALL)
6211
6212PyDoc_STRVAR(os_getrandom__doc__,
6213"getrandom($module, /, size, flags=0)\n"
6214"--\n"
6215"\n"
6216"Obtain a series of random bytes.");
6217
6218#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006219 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006220
6221static PyObject *
6222os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6223
6224static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006225os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006226{
6227 PyObject *return_value = NULL;
6228 static const char * const _keywords[] = {"size", "flags", NULL};
6229 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6230 Py_ssize_t size;
6231 int flags = 0;
6232
Victor Stinner3e1fad62017-01-17 01:29:01 +01006233 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006234 &size, &flags)) {
6235 goto exit;
6236 }
6237 return_value = os_getrandom_impl(module, size, flags);
6238
6239exit:
6240 return return_value;
6241}
6242
6243#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6244
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006245#ifndef OS_TTYNAME_METHODDEF
6246 #define OS_TTYNAME_METHODDEF
6247#endif /* !defined(OS_TTYNAME_METHODDEF) */
6248
6249#ifndef OS_CTERMID_METHODDEF
6250 #define OS_CTERMID_METHODDEF
6251#endif /* !defined(OS_CTERMID_METHODDEF) */
6252
6253#ifndef OS_FCHDIR_METHODDEF
6254 #define OS_FCHDIR_METHODDEF
6255#endif /* !defined(OS_FCHDIR_METHODDEF) */
6256
6257#ifndef OS_FCHMOD_METHODDEF
6258 #define OS_FCHMOD_METHODDEF
6259#endif /* !defined(OS_FCHMOD_METHODDEF) */
6260
6261#ifndef OS_LCHMOD_METHODDEF
6262 #define OS_LCHMOD_METHODDEF
6263#endif /* !defined(OS_LCHMOD_METHODDEF) */
6264
6265#ifndef OS_CHFLAGS_METHODDEF
6266 #define OS_CHFLAGS_METHODDEF
6267#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6268
6269#ifndef OS_LCHFLAGS_METHODDEF
6270 #define OS_LCHFLAGS_METHODDEF
6271#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6272
6273#ifndef OS_CHROOT_METHODDEF
6274 #define OS_CHROOT_METHODDEF
6275#endif /* !defined(OS_CHROOT_METHODDEF) */
6276
6277#ifndef OS_FSYNC_METHODDEF
6278 #define OS_FSYNC_METHODDEF
6279#endif /* !defined(OS_FSYNC_METHODDEF) */
6280
6281#ifndef OS_SYNC_METHODDEF
6282 #define OS_SYNC_METHODDEF
6283#endif /* !defined(OS_SYNC_METHODDEF) */
6284
6285#ifndef OS_FDATASYNC_METHODDEF
6286 #define OS_FDATASYNC_METHODDEF
6287#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6288
6289#ifndef OS_CHOWN_METHODDEF
6290 #define OS_CHOWN_METHODDEF
6291#endif /* !defined(OS_CHOWN_METHODDEF) */
6292
6293#ifndef OS_FCHOWN_METHODDEF
6294 #define OS_FCHOWN_METHODDEF
6295#endif /* !defined(OS_FCHOWN_METHODDEF) */
6296
6297#ifndef OS_LCHOWN_METHODDEF
6298 #define OS_LCHOWN_METHODDEF
6299#endif /* !defined(OS_LCHOWN_METHODDEF) */
6300
6301#ifndef OS_LINK_METHODDEF
6302 #define OS_LINK_METHODDEF
6303#endif /* !defined(OS_LINK_METHODDEF) */
6304
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006305#ifndef OS__GETFULLPATHNAME_METHODDEF
6306 #define OS__GETFULLPATHNAME_METHODDEF
6307#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6308
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006309#ifndef OS__GETFINALPATHNAME_METHODDEF
6310 #define OS__GETFINALPATHNAME_METHODDEF
6311#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6312
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006313#ifndef OS__ISDIR_METHODDEF
6314 #define OS__ISDIR_METHODDEF
6315#endif /* !defined(OS__ISDIR_METHODDEF) */
6316
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006317#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6318 #define OS__GETVOLUMEPATHNAME_METHODDEF
6319#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6320
6321#ifndef OS_NICE_METHODDEF
6322 #define OS_NICE_METHODDEF
6323#endif /* !defined(OS_NICE_METHODDEF) */
6324
6325#ifndef OS_GETPRIORITY_METHODDEF
6326 #define OS_GETPRIORITY_METHODDEF
6327#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6328
6329#ifndef OS_SETPRIORITY_METHODDEF
6330 #define OS_SETPRIORITY_METHODDEF
6331#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6332
6333#ifndef OS_SYSTEM_METHODDEF
6334 #define OS_SYSTEM_METHODDEF
6335#endif /* !defined(OS_SYSTEM_METHODDEF) */
6336
6337#ifndef OS_UNAME_METHODDEF
6338 #define OS_UNAME_METHODDEF
6339#endif /* !defined(OS_UNAME_METHODDEF) */
6340
6341#ifndef OS_EXECV_METHODDEF
6342 #define OS_EXECV_METHODDEF
6343#endif /* !defined(OS_EXECV_METHODDEF) */
6344
6345#ifndef OS_EXECVE_METHODDEF
6346 #define OS_EXECVE_METHODDEF
6347#endif /* !defined(OS_EXECVE_METHODDEF) */
6348
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006349#ifndef OS_POSIX_SPAWN_METHODDEF
6350 #define OS_POSIX_SPAWN_METHODDEF
6351#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6352
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006353#ifndef OS_SPAWNV_METHODDEF
6354 #define OS_SPAWNV_METHODDEF
6355#endif /* !defined(OS_SPAWNV_METHODDEF) */
6356
6357#ifndef OS_SPAWNVE_METHODDEF
6358 #define OS_SPAWNVE_METHODDEF
6359#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6360
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006361#ifndef OS_REGISTER_AT_FORK_METHODDEF
6362 #define OS_REGISTER_AT_FORK_METHODDEF
6363#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6364
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006365#ifndef OS_FORK1_METHODDEF
6366 #define OS_FORK1_METHODDEF
6367#endif /* !defined(OS_FORK1_METHODDEF) */
6368
6369#ifndef OS_FORK_METHODDEF
6370 #define OS_FORK_METHODDEF
6371#endif /* !defined(OS_FORK_METHODDEF) */
6372
6373#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6374 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6375#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6376
6377#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6378 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6379#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6380
6381#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6382 #define OS_SCHED_GETSCHEDULER_METHODDEF
6383#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6384
6385#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6386 #define OS_SCHED_SETSCHEDULER_METHODDEF
6387#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6388
6389#ifndef OS_SCHED_GETPARAM_METHODDEF
6390 #define OS_SCHED_GETPARAM_METHODDEF
6391#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6392
6393#ifndef OS_SCHED_SETPARAM_METHODDEF
6394 #define OS_SCHED_SETPARAM_METHODDEF
6395#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6396
6397#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6398 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6399#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6400
6401#ifndef OS_SCHED_YIELD_METHODDEF
6402 #define OS_SCHED_YIELD_METHODDEF
6403#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6404
6405#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6406 #define OS_SCHED_SETAFFINITY_METHODDEF
6407#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6408
6409#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6410 #define OS_SCHED_GETAFFINITY_METHODDEF
6411#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6412
6413#ifndef OS_OPENPTY_METHODDEF
6414 #define OS_OPENPTY_METHODDEF
6415#endif /* !defined(OS_OPENPTY_METHODDEF) */
6416
6417#ifndef OS_FORKPTY_METHODDEF
6418 #define OS_FORKPTY_METHODDEF
6419#endif /* !defined(OS_FORKPTY_METHODDEF) */
6420
6421#ifndef OS_GETEGID_METHODDEF
6422 #define OS_GETEGID_METHODDEF
6423#endif /* !defined(OS_GETEGID_METHODDEF) */
6424
6425#ifndef OS_GETEUID_METHODDEF
6426 #define OS_GETEUID_METHODDEF
6427#endif /* !defined(OS_GETEUID_METHODDEF) */
6428
6429#ifndef OS_GETGID_METHODDEF
6430 #define OS_GETGID_METHODDEF
6431#endif /* !defined(OS_GETGID_METHODDEF) */
6432
Berker Peksag39404992016-09-15 20:45:16 +03006433#ifndef OS_GETPID_METHODDEF
6434 #define OS_GETPID_METHODDEF
6435#endif /* !defined(OS_GETPID_METHODDEF) */
6436
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006437#ifndef OS_GETGROUPS_METHODDEF
6438 #define OS_GETGROUPS_METHODDEF
6439#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6440
6441#ifndef OS_GETPGID_METHODDEF
6442 #define OS_GETPGID_METHODDEF
6443#endif /* !defined(OS_GETPGID_METHODDEF) */
6444
6445#ifndef OS_GETPGRP_METHODDEF
6446 #define OS_GETPGRP_METHODDEF
6447#endif /* !defined(OS_GETPGRP_METHODDEF) */
6448
6449#ifndef OS_SETPGRP_METHODDEF
6450 #define OS_SETPGRP_METHODDEF
6451#endif /* !defined(OS_SETPGRP_METHODDEF) */
6452
6453#ifndef OS_GETPPID_METHODDEF
6454 #define OS_GETPPID_METHODDEF
6455#endif /* !defined(OS_GETPPID_METHODDEF) */
6456
6457#ifndef OS_GETLOGIN_METHODDEF
6458 #define OS_GETLOGIN_METHODDEF
6459#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6460
6461#ifndef OS_GETUID_METHODDEF
6462 #define OS_GETUID_METHODDEF
6463#endif /* !defined(OS_GETUID_METHODDEF) */
6464
6465#ifndef OS_KILL_METHODDEF
6466 #define OS_KILL_METHODDEF
6467#endif /* !defined(OS_KILL_METHODDEF) */
6468
6469#ifndef OS_KILLPG_METHODDEF
6470 #define OS_KILLPG_METHODDEF
6471#endif /* !defined(OS_KILLPG_METHODDEF) */
6472
6473#ifndef OS_PLOCK_METHODDEF
6474 #define OS_PLOCK_METHODDEF
6475#endif /* !defined(OS_PLOCK_METHODDEF) */
6476
6477#ifndef OS_SETUID_METHODDEF
6478 #define OS_SETUID_METHODDEF
6479#endif /* !defined(OS_SETUID_METHODDEF) */
6480
6481#ifndef OS_SETEUID_METHODDEF
6482 #define OS_SETEUID_METHODDEF
6483#endif /* !defined(OS_SETEUID_METHODDEF) */
6484
6485#ifndef OS_SETEGID_METHODDEF
6486 #define OS_SETEGID_METHODDEF
6487#endif /* !defined(OS_SETEGID_METHODDEF) */
6488
6489#ifndef OS_SETREUID_METHODDEF
6490 #define OS_SETREUID_METHODDEF
6491#endif /* !defined(OS_SETREUID_METHODDEF) */
6492
6493#ifndef OS_SETREGID_METHODDEF
6494 #define OS_SETREGID_METHODDEF
6495#endif /* !defined(OS_SETREGID_METHODDEF) */
6496
6497#ifndef OS_SETGID_METHODDEF
6498 #define OS_SETGID_METHODDEF
6499#endif /* !defined(OS_SETGID_METHODDEF) */
6500
6501#ifndef OS_SETGROUPS_METHODDEF
6502 #define OS_SETGROUPS_METHODDEF
6503#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6504
6505#ifndef OS_WAIT3_METHODDEF
6506 #define OS_WAIT3_METHODDEF
6507#endif /* !defined(OS_WAIT3_METHODDEF) */
6508
6509#ifndef OS_WAIT4_METHODDEF
6510 #define OS_WAIT4_METHODDEF
6511#endif /* !defined(OS_WAIT4_METHODDEF) */
6512
6513#ifndef OS_WAITID_METHODDEF
6514 #define OS_WAITID_METHODDEF
6515#endif /* !defined(OS_WAITID_METHODDEF) */
6516
6517#ifndef OS_WAITPID_METHODDEF
6518 #define OS_WAITPID_METHODDEF
6519#endif /* !defined(OS_WAITPID_METHODDEF) */
6520
6521#ifndef OS_WAIT_METHODDEF
6522 #define OS_WAIT_METHODDEF
6523#endif /* !defined(OS_WAIT_METHODDEF) */
6524
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006525#ifndef OS_READLINK_METHODDEF
6526 #define OS_READLINK_METHODDEF
6527#endif /* !defined(OS_READLINK_METHODDEF) */
6528
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006529#ifndef OS_SYMLINK_METHODDEF
6530 #define OS_SYMLINK_METHODDEF
6531#endif /* !defined(OS_SYMLINK_METHODDEF) */
6532
6533#ifndef OS_TIMES_METHODDEF
6534 #define OS_TIMES_METHODDEF
6535#endif /* !defined(OS_TIMES_METHODDEF) */
6536
6537#ifndef OS_GETSID_METHODDEF
6538 #define OS_GETSID_METHODDEF
6539#endif /* !defined(OS_GETSID_METHODDEF) */
6540
6541#ifndef OS_SETSID_METHODDEF
6542 #define OS_SETSID_METHODDEF
6543#endif /* !defined(OS_SETSID_METHODDEF) */
6544
6545#ifndef OS_SETPGID_METHODDEF
6546 #define OS_SETPGID_METHODDEF
6547#endif /* !defined(OS_SETPGID_METHODDEF) */
6548
6549#ifndef OS_TCGETPGRP_METHODDEF
6550 #define OS_TCGETPGRP_METHODDEF
6551#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6552
6553#ifndef OS_TCSETPGRP_METHODDEF
6554 #define OS_TCSETPGRP_METHODDEF
6555#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6556
6557#ifndef OS_LOCKF_METHODDEF
6558 #define OS_LOCKF_METHODDEF
6559#endif /* !defined(OS_LOCKF_METHODDEF) */
6560
6561#ifndef OS_READV_METHODDEF
6562 #define OS_READV_METHODDEF
6563#endif /* !defined(OS_READV_METHODDEF) */
6564
6565#ifndef OS_PREAD_METHODDEF
6566 #define OS_PREAD_METHODDEF
6567#endif /* !defined(OS_PREAD_METHODDEF) */
6568
Pablo Galindo4defba32018-01-27 16:16:37 +00006569#ifndef OS_PREADV_METHODDEF
6570 #define OS_PREADV_METHODDEF
6571#endif /* !defined(OS_PREADV_METHODDEF) */
6572
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02006573#ifndef OS__FCOPYFILE_METHODDEF
6574 #define OS__FCOPYFILE_METHODDEF
6575#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
6576
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006577#ifndef OS_PIPE_METHODDEF
6578 #define OS_PIPE_METHODDEF
6579#endif /* !defined(OS_PIPE_METHODDEF) */
6580
6581#ifndef OS_PIPE2_METHODDEF
6582 #define OS_PIPE2_METHODDEF
6583#endif /* !defined(OS_PIPE2_METHODDEF) */
6584
6585#ifndef OS_WRITEV_METHODDEF
6586 #define OS_WRITEV_METHODDEF
6587#endif /* !defined(OS_WRITEV_METHODDEF) */
6588
6589#ifndef OS_PWRITE_METHODDEF
6590 #define OS_PWRITE_METHODDEF
6591#endif /* !defined(OS_PWRITE_METHODDEF) */
6592
Pablo Galindo4defba32018-01-27 16:16:37 +00006593#ifndef OS_PWRITEV_METHODDEF
6594 #define OS_PWRITEV_METHODDEF
6595#endif /* !defined(OS_PWRITEV_METHODDEF) */
6596
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006597#ifndef OS_MKFIFO_METHODDEF
6598 #define OS_MKFIFO_METHODDEF
6599#endif /* !defined(OS_MKFIFO_METHODDEF) */
6600
6601#ifndef OS_MKNOD_METHODDEF
6602 #define OS_MKNOD_METHODDEF
6603#endif /* !defined(OS_MKNOD_METHODDEF) */
6604
6605#ifndef OS_MAJOR_METHODDEF
6606 #define OS_MAJOR_METHODDEF
6607#endif /* !defined(OS_MAJOR_METHODDEF) */
6608
6609#ifndef OS_MINOR_METHODDEF
6610 #define OS_MINOR_METHODDEF
6611#endif /* !defined(OS_MINOR_METHODDEF) */
6612
6613#ifndef OS_MAKEDEV_METHODDEF
6614 #define OS_MAKEDEV_METHODDEF
6615#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6616
6617#ifndef OS_FTRUNCATE_METHODDEF
6618 #define OS_FTRUNCATE_METHODDEF
6619#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6620
6621#ifndef OS_TRUNCATE_METHODDEF
6622 #define OS_TRUNCATE_METHODDEF
6623#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6624
6625#ifndef OS_POSIX_FALLOCATE_METHODDEF
6626 #define OS_POSIX_FALLOCATE_METHODDEF
6627#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6628
6629#ifndef OS_POSIX_FADVISE_METHODDEF
6630 #define OS_POSIX_FADVISE_METHODDEF
6631#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6632
6633#ifndef OS_PUTENV_METHODDEF
6634 #define OS_PUTENV_METHODDEF
6635#endif /* !defined(OS_PUTENV_METHODDEF) */
6636
6637#ifndef OS_UNSETENV_METHODDEF
6638 #define OS_UNSETENV_METHODDEF
6639#endif /* !defined(OS_UNSETENV_METHODDEF) */
6640
6641#ifndef OS_WCOREDUMP_METHODDEF
6642 #define OS_WCOREDUMP_METHODDEF
6643#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6644
6645#ifndef OS_WIFCONTINUED_METHODDEF
6646 #define OS_WIFCONTINUED_METHODDEF
6647#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6648
6649#ifndef OS_WIFSTOPPED_METHODDEF
6650 #define OS_WIFSTOPPED_METHODDEF
6651#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6652
6653#ifndef OS_WIFSIGNALED_METHODDEF
6654 #define OS_WIFSIGNALED_METHODDEF
6655#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6656
6657#ifndef OS_WIFEXITED_METHODDEF
6658 #define OS_WIFEXITED_METHODDEF
6659#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6660
6661#ifndef OS_WEXITSTATUS_METHODDEF
6662 #define OS_WEXITSTATUS_METHODDEF
6663#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6664
6665#ifndef OS_WTERMSIG_METHODDEF
6666 #define OS_WTERMSIG_METHODDEF
6667#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6668
6669#ifndef OS_WSTOPSIG_METHODDEF
6670 #define OS_WSTOPSIG_METHODDEF
6671#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6672
6673#ifndef OS_FSTATVFS_METHODDEF
6674 #define OS_FSTATVFS_METHODDEF
6675#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6676
6677#ifndef OS_STATVFS_METHODDEF
6678 #define OS_STATVFS_METHODDEF
6679#endif /* !defined(OS_STATVFS_METHODDEF) */
6680
6681#ifndef OS__GETDISKUSAGE_METHODDEF
6682 #define OS__GETDISKUSAGE_METHODDEF
6683#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6684
6685#ifndef OS_FPATHCONF_METHODDEF
6686 #define OS_FPATHCONF_METHODDEF
6687#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6688
6689#ifndef OS_PATHCONF_METHODDEF
6690 #define OS_PATHCONF_METHODDEF
6691#endif /* !defined(OS_PATHCONF_METHODDEF) */
6692
6693#ifndef OS_CONFSTR_METHODDEF
6694 #define OS_CONFSTR_METHODDEF
6695#endif /* !defined(OS_CONFSTR_METHODDEF) */
6696
6697#ifndef OS_SYSCONF_METHODDEF
6698 #define OS_SYSCONF_METHODDEF
6699#endif /* !defined(OS_SYSCONF_METHODDEF) */
6700
Steve Dowercc16be82016-09-08 10:35:16 -07006701#ifndef OS_STARTFILE_METHODDEF
6702 #define OS_STARTFILE_METHODDEF
6703#endif /* !defined(OS_STARTFILE_METHODDEF) */
6704
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006705#ifndef OS_GETLOADAVG_METHODDEF
6706 #define OS_GETLOADAVG_METHODDEF
6707#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6708
6709#ifndef OS_SETRESUID_METHODDEF
6710 #define OS_SETRESUID_METHODDEF
6711#endif /* !defined(OS_SETRESUID_METHODDEF) */
6712
6713#ifndef OS_SETRESGID_METHODDEF
6714 #define OS_SETRESGID_METHODDEF
6715#endif /* !defined(OS_SETRESGID_METHODDEF) */
6716
6717#ifndef OS_GETRESUID_METHODDEF
6718 #define OS_GETRESUID_METHODDEF
6719#endif /* !defined(OS_GETRESUID_METHODDEF) */
6720
6721#ifndef OS_GETRESGID_METHODDEF
6722 #define OS_GETRESGID_METHODDEF
6723#endif /* !defined(OS_GETRESGID_METHODDEF) */
6724
6725#ifndef OS_GETXATTR_METHODDEF
6726 #define OS_GETXATTR_METHODDEF
6727#endif /* !defined(OS_GETXATTR_METHODDEF) */
6728
6729#ifndef OS_SETXATTR_METHODDEF
6730 #define OS_SETXATTR_METHODDEF
6731#endif /* !defined(OS_SETXATTR_METHODDEF) */
6732
6733#ifndef OS_REMOVEXATTR_METHODDEF
6734 #define OS_REMOVEXATTR_METHODDEF
6735#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6736
6737#ifndef OS_LISTXATTR_METHODDEF
6738 #define OS_LISTXATTR_METHODDEF
6739#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6740
6741#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6742 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6743#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6744
6745#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6746 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6747#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006748
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006749#ifndef OS_GET_BLOCKING_METHODDEF
6750 #define OS_GET_BLOCKING_METHODDEF
6751#endif /* !defined(OS_GET_BLOCKING_METHODDEF) */
6752
6753#ifndef OS_SET_BLOCKING_METHODDEF
6754 #define OS_SET_BLOCKING_METHODDEF
6755#endif /* !defined(OS_SET_BLOCKING_METHODDEF) */
6756
Victor Stinner9b1f4742016-09-06 16:18:52 -07006757#ifndef OS_GETRANDOM_METHODDEF
6758 #define OS_GETRANDOM_METHODDEF
6759#endif /* !defined(OS_GETRANDOM_METHODDEF) */
BNMetricsb9427072018-11-02 15:20:19 +00006760/*[clinic end generated code: output=f2951c34e0907fb6 input=a9049054013a1b77]*/