blob: 6f4c028e7efef57a90219bd8faeaa4c0b5e4bfa5 [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"
Xiang Zhang4459e002017-01-22 13:04:17 +080012" Path to be examined; can be string, bytes, path-like object or\n"
13" 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"
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700104" Path to be tested; can be string or bytes\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"
307" Path to be modified. May always be specified as a str or bytes.\n"
308" On some platforms, path may also be specified as an open file descriptor.\n"
309" If this functionality is unavailable, using it raises an exception.\n"
310" mode\n"
311" Operating-system mode bitfield.\n"
312" dir_fd\n"
313" If not None, it should be a file descriptor open to a directory,\n"
314" and path should be relative; path will then be relative to that\n"
315" directory.\n"
316" follow_symlinks\n"
317" If False, and the last element of the path is a symbolic link,\n"
318" chmod will modify the symbolic link itself instead of the file\n"
319" the link points to.\n"
320"\n"
321"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
322" an open file descriptor.\n"
323"dir_fd and follow_symlinks may not be implemented on your platform.\n"
324" If they are unavailable, using them will raise a NotImplementedError.");
325
326#define OS_CHMOD_METHODDEF \
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"
658" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
659" dir_fd\n"
660" If not None, it should be a file descriptor open to a directory,\n"
661" and path should be relative; path will then be relative to that\n"
662" directory.\n"
663" follow_symlinks\n"
664" If False, and the last element of the path is a symbolic link,\n"
665" stat will examine the symbolic link itself instead of the file\n"
666" the link points to.\n"
667"\n"
668"path may always be specified as a string.\n"
669"On some platforms, path may also be specified as an open file descriptor.\n"
670" If this functionality is unavailable, using it raises an exception.\n"
671"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
672" and path should be relative; path will then be relative to that directory.\n"
673"If follow_symlinks is False, and the last element of the path is a symbolic\n"
674" link, chown will modify the symbolic link itself instead of the file the\n"
675" link points to.\n"
676"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
677" an open file descriptor.\n"
678"dir_fd and follow_symlinks may not be implemented on your platform.\n"
679" If they are unavailable, using them will raise a NotImplementedError.");
680
681#define OS_CHOWN_METHODDEF \
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"
892"path can be specified as either str or bytes. If path is bytes,\n"
893" the filenames returned will also be bytes; in all other circumstances\n"
894" the filenames returned will be str.\n"
895"If path is None, uses the path=\'.\'.\n"
896"On some platforms, path may also be specified as an open file descriptor;\\\n"
897" the file descriptor must refer to a directory.\n"
898" If this functionality is unavailable, using it raises NotImplementedError.\n"
899"\n"
900"The list is in arbitrary order. It does not include the special\n"
901"entries \'.\' and \'..\' even if they are present in the directory.");
902
903#define OS_LISTDIR_METHODDEF \
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 *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300975os__getfinalpathname_impl(PyObject *module, PyObject *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;
981 PyObject *path;
982
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300983 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300985 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300986 return_value = os__getfinalpathname_impl(module, path);
987
988exit:
989 return return_value;
990}
991
992#endif /* defined(MS_WINDOWS) */
993
994#if defined(MS_WINDOWS)
995
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300996PyDoc_STRVAR(os__isdir__doc__,
997"_isdir($module, path, /)\n"
998"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +0200999"\n"
1000"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001001
1002#define OS__ISDIR_METHODDEF \
1003 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1004
1005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001006os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001007
1008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001009os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001010{
1011 PyObject *return_value = NULL;
1012 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1013
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001014 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001015 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001016 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001017 return_value = os__isdir_impl(module, &path);
1018
1019exit:
1020 /* Cleanup for path */
1021 path_cleanup(&path);
1022
1023 return return_value;
1024}
1025
1026#endif /* defined(MS_WINDOWS) */
1027
1028#if defined(MS_WINDOWS)
1029
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001030PyDoc_STRVAR(os__getvolumepathname__doc__,
1031"_getvolumepathname($module, /, path)\n"
1032"--\n"
1033"\n"
1034"A helper function for ismount on Win32.");
1035
1036#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001037 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001038
1039static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001040os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001041
1042static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001043os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001044{
1045 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001046 static const char * const _keywords[] = {"path", NULL};
1047 static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001048 PyObject *path;
1049
Victor Stinner3e1fad62017-01-17 01:29:01 +01001050 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001051 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001053 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001054 return_value = os__getvolumepathname_impl(module, path);
1055
1056exit:
1057 return return_value;
1058}
1059
1060#endif /* defined(MS_WINDOWS) */
1061
1062PyDoc_STRVAR(os_mkdir__doc__,
1063"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1064"--\n"
1065"\n"
1066"Create a directory.\n"
1067"\n"
1068"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1069" and path should be relative; path will then be relative to that directory.\n"
1070"dir_fd may not be implemented on your platform.\n"
1071" If it is unavailable, using it will raise a NotImplementedError.\n"
1072"\n"
1073"The mode argument is ignored on Windows.");
1074
1075#define OS_MKDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001076 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001077
1078static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001079os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001080
1081static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001082os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001083{
1084 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001085 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1086 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001087 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1088 int mode = 511;
1089 int dir_fd = DEFAULT_DIR_FD;
1090
Victor Stinner3e1fad62017-01-17 01:29:01 +01001091 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001092 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001094 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001095 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1096
1097exit:
1098 /* Cleanup for path */
1099 path_cleanup(&path);
1100
1101 return return_value;
1102}
1103
1104#if defined(HAVE_NICE)
1105
1106PyDoc_STRVAR(os_nice__doc__,
1107"nice($module, increment, /)\n"
1108"--\n"
1109"\n"
1110"Add increment to the priority of process and return the new priority.");
1111
1112#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001113 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001114
1115static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001116os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001117
1118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001119os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001120{
1121 PyObject *return_value = NULL;
1122 int increment;
1123
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001124 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001125 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001126 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001127 return_value = os_nice_impl(module, increment);
1128
1129exit:
1130 return return_value;
1131}
1132
1133#endif /* defined(HAVE_NICE) */
1134
1135#if defined(HAVE_GETPRIORITY)
1136
1137PyDoc_STRVAR(os_getpriority__doc__,
1138"getpriority($module, /, which, who)\n"
1139"--\n"
1140"\n"
1141"Return program scheduling priority.");
1142
1143#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001144 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001145
1146static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001147os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001148
1149static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001150os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001151{
1152 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001153 static const char * const _keywords[] = {"which", "who", NULL};
1154 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001155 int which;
1156 int who;
1157
Victor Stinner3e1fad62017-01-17 01:29:01 +01001158 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001159 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001160 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001161 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001162 return_value = os_getpriority_impl(module, which, who);
1163
1164exit:
1165 return return_value;
1166}
1167
1168#endif /* defined(HAVE_GETPRIORITY) */
1169
1170#if defined(HAVE_SETPRIORITY)
1171
1172PyDoc_STRVAR(os_setpriority__doc__,
1173"setpriority($module, /, which, who, priority)\n"
1174"--\n"
1175"\n"
1176"Set program scheduling priority.");
1177
1178#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001179 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001180
1181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001182os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001183
1184static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001185os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001186{
1187 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001188 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1189 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001190 int which;
1191 int who;
1192 int priority;
1193
Victor Stinner3e1fad62017-01-17 01:29:01 +01001194 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001195 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001197 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001198 return_value = os_setpriority_impl(module, which, who, priority);
1199
1200exit:
1201 return return_value;
1202}
1203
1204#endif /* defined(HAVE_SETPRIORITY) */
1205
1206PyDoc_STRVAR(os_rename__doc__,
1207"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1208"--\n"
1209"\n"
1210"Rename a file or directory.\n"
1211"\n"
1212"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1213" descriptor open to a directory, and the respective path string (src or dst)\n"
1214" should be relative; the path will then be relative to that directory.\n"
1215"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1216" If they are unavailable, using them will raise a NotImplementedError.");
1217
1218#define OS_RENAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001219 {"rename", (PyCFunction)os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001220
1221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001222os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001223 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001224
1225static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001226os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001227{
1228 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001229 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1230 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001231 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1232 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1233 int src_dir_fd = DEFAULT_DIR_FD;
1234 int dst_dir_fd = DEFAULT_DIR_FD;
1235
Victor Stinner3e1fad62017-01-17 01:29:01 +01001236 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001237 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 +03001238 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001239 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001240 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1241
1242exit:
1243 /* Cleanup for src */
1244 path_cleanup(&src);
1245 /* Cleanup for dst */
1246 path_cleanup(&dst);
1247
1248 return return_value;
1249}
1250
1251PyDoc_STRVAR(os_replace__doc__,
1252"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1253"--\n"
1254"\n"
1255"Rename a file or directory, overwriting the destination.\n"
1256"\n"
1257"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1258" descriptor open to a directory, and the respective path string (src or dst)\n"
1259" should be relative; the path will then be relative to that directory.\n"
1260"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1261" If they are unavailable, using them will raise a NotImplementedError.\"");
1262
1263#define OS_REPLACE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001264 {"replace", (PyCFunction)os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001265
1266static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001267os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1268 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001269
1270static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001271os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001272{
1273 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001274 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1275 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001276 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1277 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1278 int src_dir_fd = DEFAULT_DIR_FD;
1279 int dst_dir_fd = DEFAULT_DIR_FD;
1280
Victor Stinner3e1fad62017-01-17 01:29:01 +01001281 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001282 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 +03001283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001285 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1286
1287exit:
1288 /* Cleanup for src */
1289 path_cleanup(&src);
1290 /* Cleanup for dst */
1291 path_cleanup(&dst);
1292
1293 return return_value;
1294}
1295
1296PyDoc_STRVAR(os_rmdir__doc__,
1297"rmdir($module, /, path, *, dir_fd=None)\n"
1298"--\n"
1299"\n"
1300"Remove a directory.\n"
1301"\n"
1302"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1303" and path should be relative; path will then be relative to that directory.\n"
1304"dir_fd may not be implemented on your platform.\n"
1305" If it is unavailable, using it will raise a NotImplementedError.");
1306
1307#define OS_RMDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001308 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001309
1310static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001311os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001312
1313static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001314os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001315{
1316 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001317 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1318 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001319 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1320 int dir_fd = DEFAULT_DIR_FD;
1321
Victor Stinner3e1fad62017-01-17 01:29:01 +01001322 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001323 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001324 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001325 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001326 return_value = os_rmdir_impl(module, &path, dir_fd);
1327
1328exit:
1329 /* Cleanup for path */
1330 path_cleanup(&path);
1331
1332 return return_value;
1333}
1334
1335#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1336
1337PyDoc_STRVAR(os_system__doc__,
1338"system($module, /, command)\n"
1339"--\n"
1340"\n"
1341"Execute the command in a subshell.");
1342
1343#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001344 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001345
1346static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001347os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001348
1349static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001350os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001351{
1352 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001353 static const char * const _keywords[] = {"command", NULL};
1354 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001355 Py_UNICODE *command;
1356 long _return_value;
1357
Victor Stinner3e1fad62017-01-17 01:29:01 +01001358 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001359 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001360 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001361 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001362 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001363 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001364 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001365 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001366 return_value = PyLong_FromLong(_return_value);
1367
1368exit:
1369 return return_value;
1370}
1371
1372#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1373
1374#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1375
1376PyDoc_STRVAR(os_system__doc__,
1377"system($module, /, command)\n"
1378"--\n"
1379"\n"
1380"Execute the command in a subshell.");
1381
1382#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001383 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001384
1385static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001386os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001387
1388static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001389os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390{
1391 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001392 static const char * const _keywords[] = {"command", NULL};
1393 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001394 PyObject *command = NULL;
1395 long _return_value;
1396
Victor Stinner3e1fad62017-01-17 01:29:01 +01001397 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001398 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001399 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001400 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001401 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001402 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001404 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001405 return_value = PyLong_FromLong(_return_value);
1406
1407exit:
1408 /* Cleanup for command */
1409 Py_XDECREF(command);
1410
1411 return return_value;
1412}
1413
1414#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1415
1416PyDoc_STRVAR(os_umask__doc__,
1417"umask($module, mask, /)\n"
1418"--\n"
1419"\n"
1420"Set the current numeric umask and return the previous umask.");
1421
1422#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001423 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001424
1425static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001426os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001427
1428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001429os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001430{
1431 PyObject *return_value = NULL;
1432 int mask;
1433
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001434 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001435 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001436 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001437 return_value = os_umask_impl(module, mask);
1438
1439exit:
1440 return return_value;
1441}
1442
1443PyDoc_STRVAR(os_unlink__doc__,
1444"unlink($module, /, path, *, dir_fd=None)\n"
1445"--\n"
1446"\n"
1447"Remove a file (same as remove()).\n"
1448"\n"
1449"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1450" and path should be relative; path will then be relative to that directory.\n"
1451"dir_fd may not be implemented on your platform.\n"
1452" If it is unavailable, using it will raise a NotImplementedError.");
1453
1454#define OS_UNLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001455 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001456
1457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001458os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001459
1460static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001461os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001462{
1463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001464 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1465 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001466 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1467 int dir_fd = DEFAULT_DIR_FD;
1468
Victor Stinner3e1fad62017-01-17 01:29:01 +01001469 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001470 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001473 return_value = os_unlink_impl(module, &path, dir_fd);
1474
1475exit:
1476 /* Cleanup for path */
1477 path_cleanup(&path);
1478
1479 return return_value;
1480}
1481
1482PyDoc_STRVAR(os_remove__doc__,
1483"remove($module, /, path, *, dir_fd=None)\n"
1484"--\n"
1485"\n"
1486"Remove a file (same as unlink()).\n"
1487"\n"
1488"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1489" and path should be relative; path will then be relative to that directory.\n"
1490"dir_fd may not be implemented on your platform.\n"
1491" If it is unavailable, using it will raise a NotImplementedError.");
1492
1493#define OS_REMOVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001494 {"remove", (PyCFunction)os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001495
1496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001497os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001498
1499static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001500os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001501{
1502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001503 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1504 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001505 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1506 int dir_fd = DEFAULT_DIR_FD;
1507
Victor Stinner3e1fad62017-01-17 01:29:01 +01001508 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001509 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001510 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001511 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001512 return_value = os_remove_impl(module, &path, dir_fd);
1513
1514exit:
1515 /* Cleanup for path */
1516 path_cleanup(&path);
1517
1518 return return_value;
1519}
1520
1521#if defined(HAVE_UNAME)
1522
1523PyDoc_STRVAR(os_uname__doc__,
1524"uname($module, /)\n"
1525"--\n"
1526"\n"
1527"Return an object identifying the current operating system.\n"
1528"\n"
1529"The object behaves like a named tuple with the following fields:\n"
1530" (sysname, nodename, release, version, machine)");
1531
1532#define OS_UNAME_METHODDEF \
1533 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1534
1535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001536os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001537
1538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001539os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001540{
1541 return os_uname_impl(module);
1542}
1543
1544#endif /* defined(HAVE_UNAME) */
1545
1546PyDoc_STRVAR(os_utime__doc__,
1547"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1548" follow_symlinks=True)\n"
1549"--\n"
1550"\n"
1551"Set the access and modified time of path.\n"
1552"\n"
1553"path may always be specified as a string.\n"
1554"On some platforms, path may also be specified as an open file descriptor.\n"
1555" If this functionality is unavailable, using it raises an exception.\n"
1556"\n"
1557"If times is not None, it must be a tuple (atime, mtime);\n"
1558" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001559"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001560" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1561" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001562"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001563"Specifying tuples for both times and ns is an error.\n"
1564"\n"
1565"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1566" and path should be relative; path will then be relative to that directory.\n"
1567"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1568" link, utime will modify the symbolic link itself instead of the file the\n"
1569" link points to.\n"
1570"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1571" as an open file descriptor.\n"
1572"dir_fd and follow_symlinks may not be available on your platform.\n"
1573" If they are unavailable, using them will raise a NotImplementedError.");
1574
1575#define OS_UTIME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001576 {"utime", (PyCFunction)os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001577
1578static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001579os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1580 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001581
1582static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001583os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001584{
1585 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001586 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1587 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001588 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1589 PyObject *times = NULL;
1590 PyObject *ns = NULL;
1591 int dir_fd = DEFAULT_DIR_FD;
1592 int follow_symlinks = 1;
1593
Victor Stinner3e1fad62017-01-17 01:29:01 +01001594 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001595 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001596 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001597 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001598 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1599
1600exit:
1601 /* Cleanup for path */
1602 path_cleanup(&path);
1603
1604 return return_value;
1605}
1606
1607PyDoc_STRVAR(os__exit__doc__,
1608"_exit($module, /, status)\n"
1609"--\n"
1610"\n"
1611"Exit to the system with specified status, without normal exit processing.");
1612
1613#define OS__EXIT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001614 {"_exit", (PyCFunction)os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001615
1616static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001617os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001618
1619static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001620os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001621{
1622 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001623 static const char * const _keywords[] = {"status", NULL};
1624 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001625 int status;
1626
Victor Stinner3e1fad62017-01-17 01:29:01 +01001627 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001628 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001629 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001630 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001631 return_value = os__exit_impl(module, status);
1632
1633exit:
1634 return return_value;
1635}
1636
1637#if defined(HAVE_EXECV)
1638
1639PyDoc_STRVAR(os_execv__doc__,
1640"execv($module, path, argv, /)\n"
1641"--\n"
1642"\n"
1643"Execute an executable path with arguments, replacing current process.\n"
1644"\n"
1645" path\n"
1646" Path of executable file.\n"
1647" argv\n"
1648" Tuple or list of strings.");
1649
1650#define OS_EXECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001651 {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001652
1653static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001654os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001655
1656static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001657os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001658{
1659 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001660 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001661 PyObject *argv;
1662
Sylvain74453812017-06-10 06:51:48 +02001663 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
1664 path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001665 goto exit;
1666 }
Steve Dowercc16be82016-09-08 10:35:16 -07001667 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001668
1669exit:
1670 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001671 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001672
1673 return return_value;
1674}
1675
1676#endif /* defined(HAVE_EXECV) */
1677
1678#if defined(HAVE_EXECV)
1679
1680PyDoc_STRVAR(os_execve__doc__,
1681"execve($module, /, path, argv, env)\n"
1682"--\n"
1683"\n"
1684"Execute an executable path with arguments, replacing current process.\n"
1685"\n"
1686" path\n"
1687" Path of executable file.\n"
1688" argv\n"
1689" Tuple or list of strings.\n"
1690" env\n"
1691" Dictionary of strings mapping to strings.");
1692
1693#define OS_EXECVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001694 {"execve", (PyCFunction)os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001695
1696static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001697os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001698
1699static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001700os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001701{
1702 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001703 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1704 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001705 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1706 PyObject *argv;
1707 PyObject *env;
1708
Victor Stinner3e1fad62017-01-17 01:29:01 +01001709 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001710 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001711 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001712 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001713 return_value = os_execve_impl(module, &path, argv, env);
1714
1715exit:
1716 /* Cleanup for path */
1717 path_cleanup(&path);
1718
1719 return return_value;
1720}
1721
1722#endif /* defined(HAVE_EXECV) */
1723
Steve Dowercc16be82016-09-08 10:35:16 -07001724#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001725
1726PyDoc_STRVAR(os_spawnv__doc__,
1727"spawnv($module, mode, path, argv, /)\n"
1728"--\n"
1729"\n"
1730"Execute the program specified by path in a new process.\n"
1731"\n"
1732" mode\n"
1733" Mode of process creation.\n"
1734" path\n"
1735" Path of executable file.\n"
1736" argv\n"
1737" Tuple or list of strings.");
1738
1739#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001740 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001741
1742static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001743os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001744
1745static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001746os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001747{
1748 PyObject *return_value = NULL;
1749 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001750 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001751 PyObject *argv;
1752
Sylvain74453812017-06-10 06:51:48 +02001753 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1754 &mode, path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001755 goto exit;
1756 }
Steve Dowercc16be82016-09-08 10:35:16 -07001757 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001758
1759exit:
1760 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001761 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001762
1763 return return_value;
1764}
1765
Steve Dowercc16be82016-09-08 10:35:16 -07001766#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001767
Steve Dowercc16be82016-09-08 10:35:16 -07001768#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001769
1770PyDoc_STRVAR(os_spawnve__doc__,
1771"spawnve($module, mode, path, argv, env, /)\n"
1772"--\n"
1773"\n"
1774"Execute the program specified by path in a new process.\n"
1775"\n"
1776" mode\n"
1777" Mode of process creation.\n"
1778" path\n"
1779" Path of executable file.\n"
1780" argv\n"
1781" Tuple or list of strings.\n"
1782" env\n"
1783" Dictionary of strings mapping to strings.");
1784
1785#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001786 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001787
1788static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001789os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001790 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001791
1792static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001793os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001794{
1795 PyObject *return_value = NULL;
1796 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001797 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001798 PyObject *argv;
1799 PyObject *env;
1800
Sylvain74453812017-06-10 06:51:48 +02001801 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1802 &mode, path_converter, &path, &argv, &env)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001803 goto exit;
1804 }
Steve Dowercc16be82016-09-08 10:35:16 -07001805 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001806
1807exit:
1808 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001809 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001810
1811 return return_value;
1812}
1813
Steve Dowercc16be82016-09-08 10:35:16 -07001814#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001815
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001816#if defined(HAVE_FORK)
1817
1818PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001819"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1820" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001821"--\n"
1822"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001823"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001824"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001825" before\n"
1826" A callable to be called in the parent before the fork() syscall.\n"
1827" after_in_child\n"
1828" A callable to be called in the child after fork().\n"
1829" after_in_parent\n"
1830" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001831"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001832"\'before\' callbacks are called in reverse order.\n"
1833"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001834
1835#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001836 {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001837
1838static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001839os_register_at_fork_impl(PyObject *module, PyObject *before,
1840 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001841
1842static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001843os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001844{
1845 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001846 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1847 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1848 PyObject *before = NULL;
1849 PyObject *after_in_child = NULL;
1850 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001851
1852 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001853 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001854 goto exit;
1855 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001856 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001857
1858exit:
1859 return return_value;
1860}
1861
1862#endif /* defined(HAVE_FORK) */
1863
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001864#if defined(HAVE_FORK1)
1865
1866PyDoc_STRVAR(os_fork1__doc__,
1867"fork1($module, /)\n"
1868"--\n"
1869"\n"
1870"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1871"\n"
1872"Return 0 to child process and PID of child to parent process.");
1873
1874#define OS_FORK1_METHODDEF \
1875 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1876
1877static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001878os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001879
1880static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001881os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001882{
1883 return os_fork1_impl(module);
1884}
1885
1886#endif /* defined(HAVE_FORK1) */
1887
1888#if defined(HAVE_FORK)
1889
1890PyDoc_STRVAR(os_fork__doc__,
1891"fork($module, /)\n"
1892"--\n"
1893"\n"
1894"Fork a child process.\n"
1895"\n"
1896"Return 0 to child process and PID of child to parent process.");
1897
1898#define OS_FORK_METHODDEF \
1899 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1900
1901static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001902os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001903
1904static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001905os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001906{
1907 return os_fork_impl(module);
1908}
1909
1910#endif /* defined(HAVE_FORK) */
1911
1912#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1913
1914PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1915"sched_get_priority_max($module, /, policy)\n"
1916"--\n"
1917"\n"
1918"Get the maximum scheduling priority for policy.");
1919
1920#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001921 {"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 +03001922
1923static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001924os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001925
1926static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001927os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001928{
1929 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001930 static const char * const _keywords[] = {"policy", NULL};
1931 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001932 int policy;
1933
Victor Stinner3e1fad62017-01-17 01:29:01 +01001934 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001935 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001936 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001937 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001938 return_value = os_sched_get_priority_max_impl(module, policy);
1939
1940exit:
1941 return return_value;
1942}
1943
1944#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1945
1946#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1947
1948PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1949"sched_get_priority_min($module, /, policy)\n"
1950"--\n"
1951"\n"
1952"Get the minimum scheduling priority for policy.");
1953
1954#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001955 {"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 +03001956
1957static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001958os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001959
1960static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001961os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001962{
1963 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001964 static const char * const _keywords[] = {"policy", NULL};
1965 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001966 int policy;
1967
Victor Stinner3e1fad62017-01-17 01:29:01 +01001968 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001969 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001970 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001971 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001972 return_value = os_sched_get_priority_min_impl(module, policy);
1973
1974exit:
1975 return return_value;
1976}
1977
1978#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1979
1980#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1981
1982PyDoc_STRVAR(os_sched_getscheduler__doc__,
1983"sched_getscheduler($module, pid, /)\n"
1984"--\n"
1985"\n"
1986"Get the scheduling policy for the process identifiedy by pid.\n"
1987"\n"
1988"Passing 0 for pid returns the scheduling policy for the calling process.");
1989
1990#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001991 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001992
1993static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001994os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001995
1996static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001997os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001998{
1999 PyObject *return_value = NULL;
2000 pid_t pid;
2001
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002002 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002003 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002004 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002005 return_value = os_sched_getscheduler_impl(module, pid);
2006
2007exit:
2008 return return_value;
2009}
2010
2011#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2012
2013#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
2014
2015PyDoc_STRVAR(os_sched_param__doc__,
2016"sched_param(sched_priority)\n"
2017"--\n"
2018"\n"
2019"Current has only one field: sched_priority\");\n"
2020"\n"
2021" sched_priority\n"
2022" A scheduling parameter.");
2023
2024static PyObject *
2025os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2026
2027static PyObject *
2028os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2029{
2030 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002031 static const char * const _keywords[] = {"sched_priority", NULL};
2032 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002033 PyObject *sched_priority;
2034
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002035 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002036 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002037 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002038 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002039 return_value = os_sched_param_impl(type, sched_priority);
2040
2041exit:
2042 return return_value;
2043}
2044
2045#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2046
2047#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2048
2049PyDoc_STRVAR(os_sched_setscheduler__doc__,
2050"sched_setscheduler($module, pid, policy, param, /)\n"
2051"--\n"
2052"\n"
2053"Set the scheduling policy for the process identified by pid.\n"
2054"\n"
2055"If pid is 0, the calling process is changed.\n"
2056"param is an instance of sched_param.");
2057
2058#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002059 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002060
2061static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002062os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002063 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002064
2065static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002066os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002067{
2068 PyObject *return_value = NULL;
2069 pid_t pid;
2070 int policy;
2071 struct sched_param param;
2072
Sylvain74453812017-06-10 06:51:48 +02002073 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2074 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002075 goto exit;
2076 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002077 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2078
2079exit:
2080 return return_value;
2081}
2082
2083#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2084
2085#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2086
2087PyDoc_STRVAR(os_sched_getparam__doc__,
2088"sched_getparam($module, pid, /)\n"
2089"--\n"
2090"\n"
2091"Returns scheduling parameters for the process identified by pid.\n"
2092"\n"
2093"If pid is 0, returns parameters for the calling process.\n"
2094"Return value is an instance of sched_param.");
2095
2096#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002097 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002098
2099static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002100os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002101
2102static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002103os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002104{
2105 PyObject *return_value = NULL;
2106 pid_t pid;
2107
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002108 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002109 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002110 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002111 return_value = os_sched_getparam_impl(module, pid);
2112
2113exit:
2114 return return_value;
2115}
2116
2117#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2118
2119#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2120
2121PyDoc_STRVAR(os_sched_setparam__doc__,
2122"sched_setparam($module, pid, param, /)\n"
2123"--\n"
2124"\n"
2125"Set scheduling parameters for the process identified by pid.\n"
2126"\n"
2127"If pid is 0, sets parameters for the calling process.\n"
2128"param should be an instance of sched_param.");
2129
2130#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002131 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002132
2133static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002134os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002135 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002136
2137static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002138os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002139{
2140 PyObject *return_value = NULL;
2141 pid_t pid;
2142 struct sched_param param;
2143
Sylvain74453812017-06-10 06:51:48 +02002144 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2145 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002146 goto exit;
2147 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002148 return_value = os_sched_setparam_impl(module, pid, &param);
2149
2150exit:
2151 return return_value;
2152}
2153
2154#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2155
2156#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2157
2158PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2159"sched_rr_get_interval($module, pid, /)\n"
2160"--\n"
2161"\n"
2162"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2163"\n"
2164"Value returned is a float.");
2165
2166#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002167 {"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 +03002168
2169static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002170os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002171
2172static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002173os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002174{
2175 PyObject *return_value = NULL;
2176 pid_t pid;
2177 double _return_value;
2178
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002179 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002180 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002181 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002182 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002183 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002184 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002185 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002186 return_value = PyFloat_FromDouble(_return_value);
2187
2188exit:
2189 return return_value;
2190}
2191
2192#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2193
2194#if defined(HAVE_SCHED_H)
2195
2196PyDoc_STRVAR(os_sched_yield__doc__,
2197"sched_yield($module, /)\n"
2198"--\n"
2199"\n"
2200"Voluntarily relinquish the CPU.");
2201
2202#define OS_SCHED_YIELD_METHODDEF \
2203 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2204
2205static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002206os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002207
2208static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002209os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002210{
2211 return os_sched_yield_impl(module);
2212}
2213
2214#endif /* defined(HAVE_SCHED_H) */
2215
2216#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2217
2218PyDoc_STRVAR(os_sched_setaffinity__doc__,
2219"sched_setaffinity($module, pid, mask, /)\n"
2220"--\n"
2221"\n"
2222"Set the CPU affinity of the process identified by pid to mask.\n"
2223"\n"
2224"mask should be an iterable of integers identifying CPUs.");
2225
2226#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002227 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002228
2229static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002230os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002231
2232static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002233os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002234{
2235 PyObject *return_value = NULL;
2236 pid_t pid;
2237 PyObject *mask;
2238
Sylvain74453812017-06-10 06:51:48 +02002239 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2240 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002241 goto exit;
2242 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002243 return_value = os_sched_setaffinity_impl(module, pid, mask);
2244
2245exit:
2246 return return_value;
2247}
2248
2249#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2250
2251#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2252
2253PyDoc_STRVAR(os_sched_getaffinity__doc__,
2254"sched_getaffinity($module, pid, /)\n"
2255"--\n"
2256"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002257"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002258"\n"
2259"The affinity is returned as a set of CPU identifiers.");
2260
2261#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002262 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002263
2264static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002265os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002266
2267static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002268os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002269{
2270 PyObject *return_value = NULL;
2271 pid_t pid;
2272
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002273 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002274 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002275 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002276 return_value = os_sched_getaffinity_impl(module, pid);
2277
2278exit:
2279 return return_value;
2280}
2281
2282#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2283
2284#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2285
2286PyDoc_STRVAR(os_openpty__doc__,
2287"openpty($module, /)\n"
2288"--\n"
2289"\n"
2290"Open a pseudo-terminal.\n"
2291"\n"
2292"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2293"for both the master and slave ends.");
2294
2295#define OS_OPENPTY_METHODDEF \
2296 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2297
2298static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002299os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002300
2301static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002302os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002303{
2304 return os_openpty_impl(module);
2305}
2306
2307#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2308
2309#if defined(HAVE_FORKPTY)
2310
2311PyDoc_STRVAR(os_forkpty__doc__,
2312"forkpty($module, /)\n"
2313"--\n"
2314"\n"
2315"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2316"\n"
2317"Returns a tuple of (pid, master_fd).\n"
2318"Like fork(), return pid of 0 to the child process,\n"
2319"and pid of child to the parent process.\n"
2320"To both, return fd of newly opened pseudo-terminal.");
2321
2322#define OS_FORKPTY_METHODDEF \
2323 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2324
2325static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002326os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002327
2328static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002329os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002330{
2331 return os_forkpty_impl(module);
2332}
2333
2334#endif /* defined(HAVE_FORKPTY) */
2335
2336#if defined(HAVE_GETEGID)
2337
2338PyDoc_STRVAR(os_getegid__doc__,
2339"getegid($module, /)\n"
2340"--\n"
2341"\n"
2342"Return the current process\'s effective group id.");
2343
2344#define OS_GETEGID_METHODDEF \
2345 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2346
2347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002348os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002349
2350static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002351os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002352{
2353 return os_getegid_impl(module);
2354}
2355
2356#endif /* defined(HAVE_GETEGID) */
2357
2358#if defined(HAVE_GETEUID)
2359
2360PyDoc_STRVAR(os_geteuid__doc__,
2361"geteuid($module, /)\n"
2362"--\n"
2363"\n"
2364"Return the current process\'s effective user id.");
2365
2366#define OS_GETEUID_METHODDEF \
2367 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2368
2369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002370os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002371
2372static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002373os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002374{
2375 return os_geteuid_impl(module);
2376}
2377
2378#endif /* defined(HAVE_GETEUID) */
2379
2380#if defined(HAVE_GETGID)
2381
2382PyDoc_STRVAR(os_getgid__doc__,
2383"getgid($module, /)\n"
2384"--\n"
2385"\n"
2386"Return the current process\'s group id.");
2387
2388#define OS_GETGID_METHODDEF \
2389 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2390
2391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002392os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002393
2394static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002395os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002396{
2397 return os_getgid_impl(module);
2398}
2399
2400#endif /* defined(HAVE_GETGID) */
2401
Berker Peksag39404992016-09-15 20:45:16 +03002402#if defined(HAVE_GETPID)
2403
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002404PyDoc_STRVAR(os_getpid__doc__,
2405"getpid($module, /)\n"
2406"--\n"
2407"\n"
2408"Return the current process id.");
2409
2410#define OS_GETPID_METHODDEF \
2411 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2412
2413static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002414os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002415
2416static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002417os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002418{
2419 return os_getpid_impl(module);
2420}
2421
Berker Peksag39404992016-09-15 20:45:16 +03002422#endif /* defined(HAVE_GETPID) */
2423
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002424#if defined(HAVE_GETGROUPS)
2425
2426PyDoc_STRVAR(os_getgroups__doc__,
2427"getgroups($module, /)\n"
2428"--\n"
2429"\n"
2430"Return list of supplemental group IDs for the process.");
2431
2432#define OS_GETGROUPS_METHODDEF \
2433 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2434
2435static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002436os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002437
2438static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002439os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002440{
2441 return os_getgroups_impl(module);
2442}
2443
2444#endif /* defined(HAVE_GETGROUPS) */
2445
2446#if defined(HAVE_GETPGID)
2447
2448PyDoc_STRVAR(os_getpgid__doc__,
2449"getpgid($module, /, pid)\n"
2450"--\n"
2451"\n"
2452"Call the system call getpgid(), and return the result.");
2453
2454#define OS_GETPGID_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002455 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002456
2457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002458os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002459
2460static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002461os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002462{
2463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002464 static const char * const _keywords[] = {"pid", NULL};
2465 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002466 pid_t pid;
2467
Victor Stinner3e1fad62017-01-17 01:29:01 +01002468 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002469 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002470 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002471 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002472 return_value = os_getpgid_impl(module, pid);
2473
2474exit:
2475 return return_value;
2476}
2477
2478#endif /* defined(HAVE_GETPGID) */
2479
2480#if defined(HAVE_GETPGRP)
2481
2482PyDoc_STRVAR(os_getpgrp__doc__,
2483"getpgrp($module, /)\n"
2484"--\n"
2485"\n"
2486"Return the current process group id.");
2487
2488#define OS_GETPGRP_METHODDEF \
2489 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2490
2491static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002492os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002493
2494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002495os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002496{
2497 return os_getpgrp_impl(module);
2498}
2499
2500#endif /* defined(HAVE_GETPGRP) */
2501
2502#if defined(HAVE_SETPGRP)
2503
2504PyDoc_STRVAR(os_setpgrp__doc__,
2505"setpgrp($module, /)\n"
2506"--\n"
2507"\n"
2508"Make the current process the leader of its process group.");
2509
2510#define OS_SETPGRP_METHODDEF \
2511 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2512
2513static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002514os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002515
2516static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002517os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002518{
2519 return os_setpgrp_impl(module);
2520}
2521
2522#endif /* defined(HAVE_SETPGRP) */
2523
2524#if defined(HAVE_GETPPID)
2525
2526PyDoc_STRVAR(os_getppid__doc__,
2527"getppid($module, /)\n"
2528"--\n"
2529"\n"
2530"Return the parent\'s process id.\n"
2531"\n"
2532"If the parent process has already exited, Windows machines will still\n"
2533"return its id; others systems will return the id of the \'init\' process (1).");
2534
2535#define OS_GETPPID_METHODDEF \
2536 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2537
2538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002539os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002540
2541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002542os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002543{
2544 return os_getppid_impl(module);
2545}
2546
2547#endif /* defined(HAVE_GETPPID) */
2548
2549#if defined(HAVE_GETLOGIN)
2550
2551PyDoc_STRVAR(os_getlogin__doc__,
2552"getlogin($module, /)\n"
2553"--\n"
2554"\n"
2555"Return the actual login name.");
2556
2557#define OS_GETLOGIN_METHODDEF \
2558 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2559
2560static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002561os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002562
2563static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002564os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002565{
2566 return os_getlogin_impl(module);
2567}
2568
2569#endif /* defined(HAVE_GETLOGIN) */
2570
2571#if defined(HAVE_GETUID)
2572
2573PyDoc_STRVAR(os_getuid__doc__,
2574"getuid($module, /)\n"
2575"--\n"
2576"\n"
2577"Return the current process\'s user id.");
2578
2579#define OS_GETUID_METHODDEF \
2580 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2581
2582static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002583os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002584
2585static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002586os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002587{
2588 return os_getuid_impl(module);
2589}
2590
2591#endif /* defined(HAVE_GETUID) */
2592
2593#if defined(HAVE_KILL)
2594
2595PyDoc_STRVAR(os_kill__doc__,
2596"kill($module, pid, signal, /)\n"
2597"--\n"
2598"\n"
2599"Kill a process with a signal.");
2600
2601#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002602 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002603
2604static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002605os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002606
2607static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002608os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002609{
2610 PyObject *return_value = NULL;
2611 pid_t pid;
2612 Py_ssize_t signal;
2613
Sylvain74453812017-06-10 06:51:48 +02002614 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2615 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002616 goto exit;
2617 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002618 return_value = os_kill_impl(module, pid, signal);
2619
2620exit:
2621 return return_value;
2622}
2623
2624#endif /* defined(HAVE_KILL) */
2625
2626#if defined(HAVE_KILLPG)
2627
2628PyDoc_STRVAR(os_killpg__doc__,
2629"killpg($module, pgid, signal, /)\n"
2630"--\n"
2631"\n"
2632"Kill a process group with a signal.");
2633
2634#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002635 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002636
2637static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002638os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002639
2640static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002641os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002642{
2643 PyObject *return_value = NULL;
2644 pid_t pgid;
2645 int signal;
2646
Sylvain74453812017-06-10 06:51:48 +02002647 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2648 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002649 goto exit;
2650 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002651 return_value = os_killpg_impl(module, pgid, signal);
2652
2653exit:
2654 return return_value;
2655}
2656
2657#endif /* defined(HAVE_KILLPG) */
2658
2659#if defined(HAVE_PLOCK)
2660
2661PyDoc_STRVAR(os_plock__doc__,
2662"plock($module, op, /)\n"
2663"--\n"
2664"\n"
2665"Lock program segments into memory.\");");
2666
2667#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002668 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002669
2670static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002671os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002672
2673static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002674os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002675{
2676 PyObject *return_value = NULL;
2677 int op;
2678
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002679 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002680 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002681 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002682 return_value = os_plock_impl(module, op);
2683
2684exit:
2685 return return_value;
2686}
2687
2688#endif /* defined(HAVE_PLOCK) */
2689
2690#if defined(HAVE_SETUID)
2691
2692PyDoc_STRVAR(os_setuid__doc__,
2693"setuid($module, uid, /)\n"
2694"--\n"
2695"\n"
2696"Set the current process\'s user id.");
2697
2698#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002699 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002700
2701static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002702os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002703
2704static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002705os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002706{
2707 PyObject *return_value = NULL;
2708 uid_t uid;
2709
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002710 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002711 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002712 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002713 return_value = os_setuid_impl(module, uid);
2714
2715exit:
2716 return return_value;
2717}
2718
2719#endif /* defined(HAVE_SETUID) */
2720
2721#if defined(HAVE_SETEUID)
2722
2723PyDoc_STRVAR(os_seteuid__doc__,
2724"seteuid($module, euid, /)\n"
2725"--\n"
2726"\n"
2727"Set the current process\'s effective user id.");
2728
2729#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002730 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002731
2732static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002733os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002734
2735static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002736os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002737{
2738 PyObject *return_value = NULL;
2739 uid_t euid;
2740
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002741 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002742 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002743 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002744 return_value = os_seteuid_impl(module, euid);
2745
2746exit:
2747 return return_value;
2748}
2749
2750#endif /* defined(HAVE_SETEUID) */
2751
2752#if defined(HAVE_SETEGID)
2753
2754PyDoc_STRVAR(os_setegid__doc__,
2755"setegid($module, egid, /)\n"
2756"--\n"
2757"\n"
2758"Set the current process\'s effective group id.");
2759
2760#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002761 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002762
2763static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002764os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002765
2766static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002767os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002768{
2769 PyObject *return_value = NULL;
2770 gid_t egid;
2771
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002772 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002773 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002774 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002775 return_value = os_setegid_impl(module, egid);
2776
2777exit:
2778 return return_value;
2779}
2780
2781#endif /* defined(HAVE_SETEGID) */
2782
2783#if defined(HAVE_SETREUID)
2784
2785PyDoc_STRVAR(os_setreuid__doc__,
2786"setreuid($module, ruid, euid, /)\n"
2787"--\n"
2788"\n"
2789"Set the current process\'s real and effective user ids.");
2790
2791#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002792 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002793
2794static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002795os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002796
2797static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002798os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002799{
2800 PyObject *return_value = NULL;
2801 uid_t ruid;
2802 uid_t euid;
2803
Sylvain74453812017-06-10 06:51:48 +02002804 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2805 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002806 goto exit;
2807 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002808 return_value = os_setreuid_impl(module, ruid, euid);
2809
2810exit:
2811 return return_value;
2812}
2813
2814#endif /* defined(HAVE_SETREUID) */
2815
2816#if defined(HAVE_SETREGID)
2817
2818PyDoc_STRVAR(os_setregid__doc__,
2819"setregid($module, rgid, egid, /)\n"
2820"--\n"
2821"\n"
2822"Set the current process\'s real and effective group ids.");
2823
2824#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002825 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002826
2827static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002828os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002829
2830static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002831os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002832{
2833 PyObject *return_value = NULL;
2834 gid_t rgid;
2835 gid_t egid;
2836
Sylvain74453812017-06-10 06:51:48 +02002837 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2838 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002839 goto exit;
2840 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002841 return_value = os_setregid_impl(module, rgid, egid);
2842
2843exit:
2844 return return_value;
2845}
2846
2847#endif /* defined(HAVE_SETREGID) */
2848
2849#if defined(HAVE_SETGID)
2850
2851PyDoc_STRVAR(os_setgid__doc__,
2852"setgid($module, gid, /)\n"
2853"--\n"
2854"\n"
2855"Set the current process\'s group id.");
2856
2857#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002858 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002859
2860static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002861os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002862
2863static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002864os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002865{
2866 PyObject *return_value = NULL;
2867 gid_t gid;
2868
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002869 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002870 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002871 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002872 return_value = os_setgid_impl(module, gid);
2873
2874exit:
2875 return return_value;
2876}
2877
2878#endif /* defined(HAVE_SETGID) */
2879
2880#if defined(HAVE_SETGROUPS)
2881
2882PyDoc_STRVAR(os_setgroups__doc__,
2883"setgroups($module, groups, /)\n"
2884"--\n"
2885"\n"
2886"Set the groups of the current process to list.");
2887
2888#define OS_SETGROUPS_METHODDEF \
2889 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2890
2891#endif /* defined(HAVE_SETGROUPS) */
2892
2893#if defined(HAVE_WAIT3)
2894
2895PyDoc_STRVAR(os_wait3__doc__,
2896"wait3($module, /, options)\n"
2897"--\n"
2898"\n"
2899"Wait for completion of a child process.\n"
2900"\n"
2901"Returns a tuple of information about the child process:\n"
2902" (pid, status, rusage)");
2903
2904#define OS_WAIT3_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002905 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002906
2907static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002908os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002909
2910static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002911os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002912{
2913 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002914 static const char * const _keywords[] = {"options", NULL};
2915 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002916 int options;
2917
Victor Stinner3e1fad62017-01-17 01:29:01 +01002918 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002919 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002920 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002921 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002922 return_value = os_wait3_impl(module, options);
2923
2924exit:
2925 return return_value;
2926}
2927
2928#endif /* defined(HAVE_WAIT3) */
2929
2930#if defined(HAVE_WAIT4)
2931
2932PyDoc_STRVAR(os_wait4__doc__,
2933"wait4($module, /, pid, options)\n"
2934"--\n"
2935"\n"
2936"Wait for completion of a specific child process.\n"
2937"\n"
2938"Returns a tuple of information about the child process:\n"
2939" (pid, status, rusage)");
2940
2941#define OS_WAIT4_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002942 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002943
2944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002945os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002946
2947static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002948os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002949{
2950 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002951 static const char * const _keywords[] = {"pid", "options", NULL};
2952 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002953 pid_t pid;
2954 int options;
2955
Victor Stinner3e1fad62017-01-17 01:29:01 +01002956 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002957 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002958 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002959 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002960 return_value = os_wait4_impl(module, pid, options);
2961
2962exit:
2963 return return_value;
2964}
2965
2966#endif /* defined(HAVE_WAIT4) */
2967
2968#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2969
2970PyDoc_STRVAR(os_waitid__doc__,
2971"waitid($module, idtype, id, options, /)\n"
2972"--\n"
2973"\n"
2974"Returns the result of waiting for a process or processes.\n"
2975"\n"
2976" idtype\n"
2977" Must be one of be P_PID, P_PGID or P_ALL.\n"
2978" id\n"
2979" The id to wait on.\n"
2980" options\n"
2981" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2982" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2983"\n"
2984"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2985"no children in a waitable state.");
2986
2987#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002988 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002989
2990static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002991os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002992
2993static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002994os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002995{
2996 PyObject *return_value = NULL;
2997 idtype_t idtype;
2998 id_t id;
2999 int options;
3000
Sylvain74453812017-06-10 06:51:48 +02003001 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3002 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003003 goto exit;
3004 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003005 return_value = os_waitid_impl(module, idtype, id, options);
3006
3007exit:
3008 return return_value;
3009}
3010
3011#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3012
3013#if defined(HAVE_WAITPID)
3014
3015PyDoc_STRVAR(os_waitpid__doc__,
3016"waitpid($module, pid, options, /)\n"
3017"--\n"
3018"\n"
3019"Wait for completion of a given child process.\n"
3020"\n"
3021"Returns a tuple of information regarding the child process:\n"
3022" (pid, status)\n"
3023"\n"
3024"The options argument is ignored on Windows.");
3025
3026#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003027 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003028
3029static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003030os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003031
3032static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003033os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003034{
3035 PyObject *return_value = NULL;
3036 pid_t pid;
3037 int options;
3038
Sylvain74453812017-06-10 06:51:48 +02003039 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3040 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003041 goto exit;
3042 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003043 return_value = os_waitpid_impl(module, pid, options);
3044
3045exit:
3046 return return_value;
3047}
3048
3049#endif /* defined(HAVE_WAITPID) */
3050
3051#if defined(HAVE_CWAIT)
3052
3053PyDoc_STRVAR(os_waitpid__doc__,
3054"waitpid($module, pid, options, /)\n"
3055"--\n"
3056"\n"
3057"Wait for completion of a given process.\n"
3058"\n"
3059"Returns a tuple of information regarding the process:\n"
3060" (pid, status << 8)\n"
3061"\n"
3062"The options argument is ignored on Windows.");
3063
3064#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003065 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003066
3067static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003068os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003069
3070static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003071os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003072{
3073 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003074 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003075 int options;
3076
Sylvain74453812017-06-10 06:51:48 +02003077 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3078 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003079 goto exit;
3080 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003081 return_value = os_waitpid_impl(module, pid, options);
3082
3083exit:
3084 return return_value;
3085}
3086
3087#endif /* defined(HAVE_CWAIT) */
3088
3089#if defined(HAVE_WAIT)
3090
3091PyDoc_STRVAR(os_wait__doc__,
3092"wait($module, /)\n"
3093"--\n"
3094"\n"
3095"Wait for completion of a child process.\n"
3096"\n"
3097"Returns a tuple of information about the child process:\n"
3098" (pid, status)");
3099
3100#define OS_WAIT_METHODDEF \
3101 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3102
3103static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003104os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003105
3106static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003107os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003108{
3109 return os_wait_impl(module);
3110}
3111
3112#endif /* defined(HAVE_WAIT) */
3113
3114#if defined(HAVE_SYMLINK)
3115
3116PyDoc_STRVAR(os_symlink__doc__,
3117"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3118"--\n"
3119"\n"
3120"Create a symbolic link pointing to src named dst.\n"
3121"\n"
3122"target_is_directory is required on Windows if the target is to be\n"
3123" interpreted as a directory. (On Windows, symlink requires\n"
3124" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3125" target_is_directory is ignored on non-Windows platforms.\n"
3126"\n"
3127"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3128" and path should be relative; path will then be relative to that directory.\n"
3129"dir_fd may not be implemented on your platform.\n"
3130" If it is unavailable, using it will raise a NotImplementedError.");
3131
3132#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003133 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003134
3135static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003136os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003137 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003138
3139static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003140os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003141{
3142 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003143 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3144 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003145 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3146 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3147 int target_is_directory = 0;
3148 int dir_fd = DEFAULT_DIR_FD;
3149
Victor Stinner3e1fad62017-01-17 01:29:01 +01003150 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003151 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003152 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003154 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3155
3156exit:
3157 /* Cleanup for src */
3158 path_cleanup(&src);
3159 /* Cleanup for dst */
3160 path_cleanup(&dst);
3161
3162 return return_value;
3163}
3164
3165#endif /* defined(HAVE_SYMLINK) */
3166
3167#if defined(HAVE_TIMES)
3168
3169PyDoc_STRVAR(os_times__doc__,
3170"times($module, /)\n"
3171"--\n"
3172"\n"
3173"Return a collection containing process timing information.\n"
3174"\n"
3175"The object returned behaves like a named tuple with these fields:\n"
3176" (utime, stime, cutime, cstime, elapsed_time)\n"
3177"All fields are floating point numbers.");
3178
3179#define OS_TIMES_METHODDEF \
3180 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3181
3182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003183os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003184
3185static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003186os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003187{
3188 return os_times_impl(module);
3189}
3190
3191#endif /* defined(HAVE_TIMES) */
3192
3193#if defined(HAVE_GETSID)
3194
3195PyDoc_STRVAR(os_getsid__doc__,
3196"getsid($module, pid, /)\n"
3197"--\n"
3198"\n"
3199"Call the system call getsid(pid) and return the result.");
3200
3201#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003202 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003203
3204static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003205os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003206
3207static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003208os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003209{
3210 PyObject *return_value = NULL;
3211 pid_t pid;
3212
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003213 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003214 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003215 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003216 return_value = os_getsid_impl(module, pid);
3217
3218exit:
3219 return return_value;
3220}
3221
3222#endif /* defined(HAVE_GETSID) */
3223
3224#if defined(HAVE_SETSID)
3225
3226PyDoc_STRVAR(os_setsid__doc__,
3227"setsid($module, /)\n"
3228"--\n"
3229"\n"
3230"Call the system call setsid().");
3231
3232#define OS_SETSID_METHODDEF \
3233 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3234
3235static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003236os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003237
3238static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003239os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003240{
3241 return os_setsid_impl(module);
3242}
3243
3244#endif /* defined(HAVE_SETSID) */
3245
3246#if defined(HAVE_SETPGID)
3247
3248PyDoc_STRVAR(os_setpgid__doc__,
3249"setpgid($module, pid, pgrp, /)\n"
3250"--\n"
3251"\n"
3252"Call the system call setpgid(pid, pgrp).");
3253
3254#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003255 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003256
3257static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003258os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003259
3260static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003261os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003262{
3263 PyObject *return_value = NULL;
3264 pid_t pid;
3265 pid_t pgrp;
3266
Sylvain74453812017-06-10 06:51:48 +02003267 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3268 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003269 goto exit;
3270 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003271 return_value = os_setpgid_impl(module, pid, pgrp);
3272
3273exit:
3274 return return_value;
3275}
3276
3277#endif /* defined(HAVE_SETPGID) */
3278
3279#if defined(HAVE_TCGETPGRP)
3280
3281PyDoc_STRVAR(os_tcgetpgrp__doc__,
3282"tcgetpgrp($module, fd, /)\n"
3283"--\n"
3284"\n"
3285"Return the process group associated with the terminal specified by fd.");
3286
3287#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003288 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003289
3290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003291os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003292
3293static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003294os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003295{
3296 PyObject *return_value = NULL;
3297 int fd;
3298
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003299 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003300 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003301 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003302 return_value = os_tcgetpgrp_impl(module, fd);
3303
3304exit:
3305 return return_value;
3306}
3307
3308#endif /* defined(HAVE_TCGETPGRP) */
3309
3310#if defined(HAVE_TCSETPGRP)
3311
3312PyDoc_STRVAR(os_tcsetpgrp__doc__,
3313"tcsetpgrp($module, fd, pgid, /)\n"
3314"--\n"
3315"\n"
3316"Set the process group associated with the terminal specified by fd.");
3317
3318#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003319 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003320
3321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003322os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003323
3324static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003325os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003326{
3327 PyObject *return_value = NULL;
3328 int fd;
3329 pid_t pgid;
3330
Sylvain74453812017-06-10 06:51:48 +02003331 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3332 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003333 goto exit;
3334 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003335 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3336
3337exit:
3338 return return_value;
3339}
3340
3341#endif /* defined(HAVE_TCSETPGRP) */
3342
3343PyDoc_STRVAR(os_open__doc__,
3344"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3345"--\n"
3346"\n"
3347"Open a file for low level IO. Returns a file descriptor (integer).\n"
3348"\n"
3349"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3350" and path should be relative; path will then be relative to that directory.\n"
3351"dir_fd may not be implemented on your platform.\n"
3352" If it is unavailable, using it will raise a NotImplementedError.");
3353
3354#define OS_OPEN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003355 {"open", (PyCFunction)os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003356
3357static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003358os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003359
3360static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003361os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003362{
3363 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003364 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3365 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003366 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3367 int flags;
3368 int mode = 511;
3369 int dir_fd = DEFAULT_DIR_FD;
3370 int _return_value;
3371
Victor Stinner3e1fad62017-01-17 01:29:01 +01003372 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003373 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003374 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003375 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003376 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003377 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003378 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003379 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003380 return_value = PyLong_FromLong((long)_return_value);
3381
3382exit:
3383 /* Cleanup for path */
3384 path_cleanup(&path);
3385
3386 return return_value;
3387}
3388
3389PyDoc_STRVAR(os_close__doc__,
3390"close($module, /, fd)\n"
3391"--\n"
3392"\n"
3393"Close a file descriptor.");
3394
3395#define OS_CLOSE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003396 {"close", (PyCFunction)os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003397
3398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003399os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003400
3401static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003402os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003403{
3404 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003405 static const char * const _keywords[] = {"fd", NULL};
3406 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003407 int fd;
3408
Victor Stinner3e1fad62017-01-17 01:29:01 +01003409 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003410 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003411 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003412 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003413 return_value = os_close_impl(module, fd);
3414
3415exit:
3416 return return_value;
3417}
3418
3419PyDoc_STRVAR(os_closerange__doc__,
3420"closerange($module, fd_low, fd_high, /)\n"
3421"--\n"
3422"\n"
3423"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3424
3425#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003426 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003427
3428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003429os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003430
3431static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003432os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003433{
3434 PyObject *return_value = NULL;
3435 int fd_low;
3436 int fd_high;
3437
Sylvain74453812017-06-10 06:51:48 +02003438 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3439 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003440 goto exit;
3441 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003442 return_value = os_closerange_impl(module, fd_low, fd_high);
3443
3444exit:
3445 return return_value;
3446}
3447
3448PyDoc_STRVAR(os_dup__doc__,
3449"dup($module, fd, /)\n"
3450"--\n"
3451"\n"
3452"Return a duplicate of a file descriptor.");
3453
3454#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003455 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003456
3457static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003458os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003459
3460static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003461os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003462{
3463 PyObject *return_value = NULL;
3464 int fd;
3465 int _return_value;
3466
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003467 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003468 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003469 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003470 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003471 if ((_return_value == -1) && PyErr_Occurred()) {
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 = PyLong_FromLong((long)_return_value);
3475
3476exit:
3477 return return_value;
3478}
3479
3480PyDoc_STRVAR(os_dup2__doc__,
3481"dup2($module, /, fd, fd2, inheritable=True)\n"
3482"--\n"
3483"\n"
3484"Duplicate file descriptor.");
3485
3486#define OS_DUP2_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003487 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003488
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003489static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003490os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003491
3492static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003493os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003494{
3495 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003496 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3497 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003498 int fd;
3499 int fd2;
3500 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003501 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003502
Victor Stinner3e1fad62017-01-17 01:29:01 +01003503 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003504 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003505 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003506 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003507 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3508 if ((_return_value == -1) && PyErr_Occurred()) {
3509 goto exit;
3510 }
3511 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003512
3513exit:
3514 return return_value;
3515}
3516
3517#if defined(HAVE_LOCKF)
3518
3519PyDoc_STRVAR(os_lockf__doc__,
3520"lockf($module, fd, command, length, /)\n"
3521"--\n"
3522"\n"
3523"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3524"\n"
3525" fd\n"
3526" An open file descriptor.\n"
3527" command\n"
3528" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3529" length\n"
3530" The number of bytes to lock, starting at the current position.");
3531
3532#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003533 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003534
3535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003536os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003537
3538static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003539os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003540{
3541 PyObject *return_value = NULL;
3542 int fd;
3543 int command;
3544 Py_off_t length;
3545
Sylvain74453812017-06-10 06:51:48 +02003546 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3547 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003548 goto exit;
3549 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003550 return_value = os_lockf_impl(module, fd, command, length);
3551
3552exit:
3553 return return_value;
3554}
3555
3556#endif /* defined(HAVE_LOCKF) */
3557
3558PyDoc_STRVAR(os_lseek__doc__,
3559"lseek($module, fd, position, how, /)\n"
3560"--\n"
3561"\n"
3562"Set the position of a file descriptor. Return the new position.\n"
3563"\n"
3564"Return the new cursor position in number of bytes\n"
3565"relative to the beginning of the file.");
3566
3567#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003568 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003569
3570static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003571os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003572
3573static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003574os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003575{
3576 PyObject *return_value = NULL;
3577 int fd;
3578 Py_off_t position;
3579 int how;
3580 Py_off_t _return_value;
3581
Sylvain74453812017-06-10 06:51:48 +02003582 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3583 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003584 goto exit;
3585 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003586 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003587 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003588 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003589 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003590 return_value = PyLong_FromPy_off_t(_return_value);
3591
3592exit:
3593 return return_value;
3594}
3595
3596PyDoc_STRVAR(os_read__doc__,
3597"read($module, fd, length, /)\n"
3598"--\n"
3599"\n"
3600"Read from a file descriptor. Returns a bytes object.");
3601
3602#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003603 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003604
3605static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003606os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003607
3608static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003609os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003610{
3611 PyObject *return_value = NULL;
3612 int fd;
3613 Py_ssize_t length;
3614
Sylvain74453812017-06-10 06:51:48 +02003615 if (!_PyArg_ParseStack(args, nargs, "in:read",
3616 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003617 goto exit;
3618 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003619 return_value = os_read_impl(module, fd, length);
3620
3621exit:
3622 return return_value;
3623}
3624
3625#if defined(HAVE_READV)
3626
3627PyDoc_STRVAR(os_readv__doc__,
3628"readv($module, fd, buffers, /)\n"
3629"--\n"
3630"\n"
3631"Read from a file descriptor fd into an iterable of buffers.\n"
3632"\n"
3633"The buffers should be mutable buffers accepting bytes.\n"
3634"readv will transfer data into each buffer until it is full\n"
3635"and then move on to the next buffer in the sequence to hold\n"
3636"the rest of the data.\n"
3637"\n"
3638"readv returns the total number of bytes read,\n"
3639"which may be less than the total capacity of all the buffers.");
3640
3641#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003642 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003643
3644static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003645os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003646
3647static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003648os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003649{
3650 PyObject *return_value = NULL;
3651 int fd;
3652 PyObject *buffers;
3653 Py_ssize_t _return_value;
3654
Sylvain74453812017-06-10 06:51:48 +02003655 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3656 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003657 goto exit;
3658 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003659 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003660 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003661 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003662 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003663 return_value = PyLong_FromSsize_t(_return_value);
3664
3665exit:
3666 return return_value;
3667}
3668
3669#endif /* defined(HAVE_READV) */
3670
3671#if defined(HAVE_PREAD)
3672
3673PyDoc_STRVAR(os_pread__doc__,
3674"pread($module, fd, length, offset, /)\n"
3675"--\n"
3676"\n"
3677"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3678"\n"
3679"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3680"the beginning of the file. The file offset remains unchanged.");
3681
3682#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003683 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003684
3685static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003686os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003687
3688static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003689os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003690{
3691 PyObject *return_value = NULL;
3692 int fd;
3693 int length;
3694 Py_off_t offset;
3695
Sylvain74453812017-06-10 06:51:48 +02003696 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3697 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003698 goto exit;
3699 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003700 return_value = os_pread_impl(module, fd, length, offset);
3701
3702exit:
3703 return return_value;
3704}
3705
3706#endif /* defined(HAVE_PREAD) */
3707
3708PyDoc_STRVAR(os_write__doc__,
3709"write($module, fd, data, /)\n"
3710"--\n"
3711"\n"
3712"Write a bytes object to a file descriptor.");
3713
3714#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003715 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003716
3717static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003718os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003719
3720static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003721os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003722{
3723 PyObject *return_value = NULL;
3724 int fd;
3725 Py_buffer data = {NULL, NULL};
3726 Py_ssize_t _return_value;
3727
Sylvain74453812017-06-10 06:51:48 +02003728 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3729 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003730 goto exit;
3731 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003732 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003733 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003734 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003735 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003736 return_value = PyLong_FromSsize_t(_return_value);
3737
3738exit:
3739 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003740 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003741 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003742 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003743
3744 return return_value;
3745}
3746
3747PyDoc_STRVAR(os_fstat__doc__,
3748"fstat($module, /, fd)\n"
3749"--\n"
3750"\n"
3751"Perform a stat system call on the given file descriptor.\n"
3752"\n"
3753"Like stat(), but for an open file descriptor.\n"
3754"Equivalent to os.stat(fd).");
3755
3756#define OS_FSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003757 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003758
3759static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003760os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003761
3762static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003763os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003764{
3765 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003766 static const char * const _keywords[] = {"fd", NULL};
3767 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003768 int fd;
3769
Victor Stinner3e1fad62017-01-17 01:29:01 +01003770 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003771 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003772 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003773 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003774 return_value = os_fstat_impl(module, fd);
3775
3776exit:
3777 return return_value;
3778}
3779
3780PyDoc_STRVAR(os_isatty__doc__,
3781"isatty($module, fd, /)\n"
3782"--\n"
3783"\n"
3784"Return True if the fd is connected to a terminal.\n"
3785"\n"
3786"Return True if the file descriptor is an open file descriptor\n"
3787"connected to the slave end of a terminal.");
3788
3789#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003790 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003791
3792static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003793os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003794
3795static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003796os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003797{
3798 PyObject *return_value = NULL;
3799 int fd;
3800 int _return_value;
3801
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003802 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003803 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003804 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003805 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003806 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003807 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003808 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003809 return_value = PyBool_FromLong((long)_return_value);
3810
3811exit:
3812 return return_value;
3813}
3814
3815#if defined(HAVE_PIPE)
3816
3817PyDoc_STRVAR(os_pipe__doc__,
3818"pipe($module, /)\n"
3819"--\n"
3820"\n"
3821"Create a pipe.\n"
3822"\n"
3823"Returns a tuple of two file descriptors:\n"
3824" (read_fd, write_fd)");
3825
3826#define OS_PIPE_METHODDEF \
3827 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3828
3829static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003830os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003831
3832static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003833os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003834{
3835 return os_pipe_impl(module);
3836}
3837
3838#endif /* defined(HAVE_PIPE) */
3839
3840#if defined(HAVE_PIPE2)
3841
3842PyDoc_STRVAR(os_pipe2__doc__,
3843"pipe2($module, flags, /)\n"
3844"--\n"
3845"\n"
3846"Create a pipe with flags set atomically.\n"
3847"\n"
3848"Returns a tuple of two file descriptors:\n"
3849" (read_fd, write_fd)\n"
3850"\n"
3851"flags can be constructed by ORing together one or more of these values:\n"
3852"O_NONBLOCK, O_CLOEXEC.");
3853
3854#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003855 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003856
3857static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003858os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003859
3860static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003861os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003862{
3863 PyObject *return_value = NULL;
3864 int flags;
3865
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003866 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003867 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003868 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003869 return_value = os_pipe2_impl(module, flags);
3870
3871exit:
3872 return return_value;
3873}
3874
3875#endif /* defined(HAVE_PIPE2) */
3876
3877#if defined(HAVE_WRITEV)
3878
3879PyDoc_STRVAR(os_writev__doc__,
3880"writev($module, fd, buffers, /)\n"
3881"--\n"
3882"\n"
3883"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3884"\n"
3885"Returns the total number of bytes written.\n"
3886"buffers must be a sequence of bytes-like objects.");
3887
3888#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003889 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003890
3891static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003892os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003893
3894static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003895os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003896{
3897 PyObject *return_value = NULL;
3898 int fd;
3899 PyObject *buffers;
3900 Py_ssize_t _return_value;
3901
Sylvain74453812017-06-10 06:51:48 +02003902 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
3903 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003904 goto exit;
3905 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003906 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003907 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003908 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003909 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003910 return_value = PyLong_FromSsize_t(_return_value);
3911
3912exit:
3913 return return_value;
3914}
3915
3916#endif /* defined(HAVE_WRITEV) */
3917
3918#if defined(HAVE_PWRITE)
3919
3920PyDoc_STRVAR(os_pwrite__doc__,
3921"pwrite($module, fd, buffer, offset, /)\n"
3922"--\n"
3923"\n"
3924"Write bytes to a file descriptor starting at a particular offset.\n"
3925"\n"
3926"Write buffer to fd, starting at offset bytes from the beginning of\n"
3927"the file. Returns the number of bytes writte. Does not change the\n"
3928"current file offset.");
3929
3930#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003931 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003932
3933static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003934os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003935
3936static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003937os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003938{
3939 PyObject *return_value = NULL;
3940 int fd;
3941 Py_buffer buffer = {NULL, NULL};
3942 Py_off_t offset;
3943 Py_ssize_t _return_value;
3944
Sylvain74453812017-06-10 06:51:48 +02003945 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
3946 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003947 goto exit;
3948 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003949 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003950 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003951 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003952 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003953 return_value = PyLong_FromSsize_t(_return_value);
3954
3955exit:
3956 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003957 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003958 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003959 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003960
3961 return return_value;
3962}
3963
3964#endif /* defined(HAVE_PWRITE) */
3965
3966#if defined(HAVE_MKFIFO)
3967
3968PyDoc_STRVAR(os_mkfifo__doc__,
3969"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
3970"--\n"
3971"\n"
3972"Create a \"fifo\" (a POSIX named pipe).\n"
3973"\n"
3974"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3975" and path should be relative; path will then be relative to that directory.\n"
3976"dir_fd may not be implemented on your platform.\n"
3977" If it is unavailable, using it will raise a NotImplementedError.");
3978
3979#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003980 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003981
3982static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003983os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003984
3985static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003986os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003987{
3988 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003989 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
3990 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003991 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
3992 int mode = 438;
3993 int dir_fd = DEFAULT_DIR_FD;
3994
Victor Stinner3e1fad62017-01-17 01:29:01 +01003995 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003996 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003997 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003998 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003999 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4000
4001exit:
4002 /* Cleanup for path */
4003 path_cleanup(&path);
4004
4005 return return_value;
4006}
4007
4008#endif /* defined(HAVE_MKFIFO) */
4009
4010#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4011
4012PyDoc_STRVAR(os_mknod__doc__,
4013"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4014"--\n"
4015"\n"
4016"Create a node in the file system.\n"
4017"\n"
4018"Create a node in the file system (file, device special file or named pipe)\n"
4019"at path. mode specifies both the permissions to use and the\n"
4020"type of node to be created, being combined (bitwise OR) with one of\n"
4021"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4022"device defines the newly created device special file (probably using\n"
4023"os.makedev()). Otherwise device is ignored.\n"
4024"\n"
4025"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4026" and path should be relative; path will then be relative to that directory.\n"
4027"dir_fd may not be implemented on your platform.\n"
4028" If it is unavailable, using it will raise a NotImplementedError.");
4029
4030#define OS_MKNOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004031 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004032
4033static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004034os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004035 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004036
4037static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004038os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004039{
4040 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004041 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4042 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004043 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4044 int mode = 384;
4045 dev_t device = 0;
4046 int dir_fd = DEFAULT_DIR_FD;
4047
Victor Stinner3e1fad62017-01-17 01:29:01 +01004048 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004049 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004050 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004051 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004052 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4053
4054exit:
4055 /* Cleanup for path */
4056 path_cleanup(&path);
4057
4058 return return_value;
4059}
4060
4061#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4062
4063#if defined(HAVE_DEVICE_MACROS)
4064
4065PyDoc_STRVAR(os_major__doc__,
4066"major($module, device, /)\n"
4067"--\n"
4068"\n"
4069"Extracts a device major number from a raw device number.");
4070
4071#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004072 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004073
4074static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004075os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004076
4077static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004078os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004079{
4080 PyObject *return_value = NULL;
4081 dev_t device;
4082 unsigned int _return_value;
4083
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004084 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004087 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004088 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004089 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004090 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004091 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4092
4093exit:
4094 return return_value;
4095}
4096
4097#endif /* defined(HAVE_DEVICE_MACROS) */
4098
4099#if defined(HAVE_DEVICE_MACROS)
4100
4101PyDoc_STRVAR(os_minor__doc__,
4102"minor($module, device, /)\n"
4103"--\n"
4104"\n"
4105"Extracts a device minor number from a raw device number.");
4106
4107#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004108 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004109
4110static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004111os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004112
4113static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004114os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004115{
4116 PyObject *return_value = NULL;
4117 dev_t device;
4118 unsigned int _return_value;
4119
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004120 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004121 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004122 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004123 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004124 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004125 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004126 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004127 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4128
4129exit:
4130 return return_value;
4131}
4132
4133#endif /* defined(HAVE_DEVICE_MACROS) */
4134
4135#if defined(HAVE_DEVICE_MACROS)
4136
4137PyDoc_STRVAR(os_makedev__doc__,
4138"makedev($module, major, minor, /)\n"
4139"--\n"
4140"\n"
4141"Composes a raw device number from the major and minor device numbers.");
4142
4143#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004144 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004145
4146static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004147os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004148
4149static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004150os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004151{
4152 PyObject *return_value = NULL;
4153 int major;
4154 int minor;
4155 dev_t _return_value;
4156
Sylvain74453812017-06-10 06:51:48 +02004157 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4158 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004159 goto exit;
4160 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004161 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004162 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004163 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004164 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004165 return_value = _PyLong_FromDev(_return_value);
4166
4167exit:
4168 return return_value;
4169}
4170
4171#endif /* defined(HAVE_DEVICE_MACROS) */
4172
Steve Dowerf7377032015-04-12 15:44:54 -04004173#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004174
4175PyDoc_STRVAR(os_ftruncate__doc__,
4176"ftruncate($module, fd, length, /)\n"
4177"--\n"
4178"\n"
4179"Truncate a file, specified by file descriptor, to a specific length.");
4180
4181#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004182 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004183
4184static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004185os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004186
4187static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004188os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004189{
4190 PyObject *return_value = NULL;
4191 int fd;
4192 Py_off_t length;
4193
Sylvain74453812017-06-10 06:51:48 +02004194 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4195 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004196 goto exit;
4197 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004198 return_value = os_ftruncate_impl(module, fd, length);
4199
4200exit:
4201 return return_value;
4202}
4203
Steve Dowerf7377032015-04-12 15:44:54 -04004204#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004205
Steve Dowerf7377032015-04-12 15:44:54 -04004206#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004207
4208PyDoc_STRVAR(os_truncate__doc__,
4209"truncate($module, /, path, length)\n"
4210"--\n"
4211"\n"
4212"Truncate a file, specified by path, to a specific length.\n"
4213"\n"
4214"On some platforms, path may also be specified as an open file descriptor.\n"
4215" If this functionality is unavailable, using it raises an exception.");
4216
4217#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004218 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004219
4220static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004221os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004222
4223static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004224os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004225{
4226 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004227 static const char * const _keywords[] = {"path", "length", NULL};
4228 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004229 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4230 Py_off_t length;
4231
Victor Stinner3e1fad62017-01-17 01:29:01 +01004232 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004233 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004234 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004235 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004236 return_value = os_truncate_impl(module, &path, length);
4237
4238exit:
4239 /* Cleanup for path */
4240 path_cleanup(&path);
4241
4242 return return_value;
4243}
4244
Steve Dowerf7377032015-04-12 15:44:54 -04004245#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004246
4247#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4248
4249PyDoc_STRVAR(os_posix_fallocate__doc__,
4250"posix_fallocate($module, fd, offset, length, /)\n"
4251"--\n"
4252"\n"
4253"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4254"\n"
4255"Ensure that the file specified by fd encompasses a range of bytes\n"
4256"starting at offset bytes from the beginning and continuing for length bytes.");
4257
4258#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004259 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004260
4261static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004262os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004263 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004264
4265static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004266os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004267{
4268 PyObject *return_value = NULL;
4269 int fd;
4270 Py_off_t offset;
4271 Py_off_t length;
4272
Sylvain74453812017-06-10 06:51:48 +02004273 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4274 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004275 goto exit;
4276 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004277 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4278
4279exit:
4280 return return_value;
4281}
4282
4283#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4284
4285#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4286
4287PyDoc_STRVAR(os_posix_fadvise__doc__,
4288"posix_fadvise($module, fd, offset, length, advice, /)\n"
4289"--\n"
4290"\n"
4291"Announce an intention to access data in a specific pattern.\n"
4292"\n"
4293"Announce an intention to access data in a specific pattern, thus allowing\n"
4294"the kernel to make optimizations.\n"
4295"The advice applies to the region of the file specified by fd starting at\n"
4296"offset and continuing for length bytes.\n"
4297"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4298"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4299"POSIX_FADV_DONTNEED.");
4300
4301#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004302 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004303
4304static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004305os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004306 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004307
4308static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004309os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004310{
4311 PyObject *return_value = NULL;
4312 int fd;
4313 Py_off_t offset;
4314 Py_off_t length;
4315 int advice;
4316
Sylvain74453812017-06-10 06:51:48 +02004317 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4318 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004319 goto exit;
4320 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004321 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4322
4323exit:
4324 return return_value;
4325}
4326
4327#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4328
4329#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4330
4331PyDoc_STRVAR(os_putenv__doc__,
4332"putenv($module, name, value, /)\n"
4333"--\n"
4334"\n"
4335"Change or add an environment variable.");
4336
4337#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004338 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004339
4340static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004341os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004342
4343static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004344os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004345{
4346 PyObject *return_value = NULL;
4347 PyObject *name;
4348 PyObject *value;
4349
Sylvain74453812017-06-10 06:51:48 +02004350 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4351 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004352 goto exit;
4353 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004354 return_value = os_putenv_impl(module, name, value);
4355
4356exit:
4357 return return_value;
4358}
4359
4360#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4361
4362#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4363
4364PyDoc_STRVAR(os_putenv__doc__,
4365"putenv($module, name, value, /)\n"
4366"--\n"
4367"\n"
4368"Change or add an environment variable.");
4369
4370#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004371 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004372
4373static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004374os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004375
4376static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004377os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004378{
4379 PyObject *return_value = NULL;
4380 PyObject *name = NULL;
4381 PyObject *value = NULL;
4382
Sylvain74453812017-06-10 06:51:48 +02004383 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4384 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004385 goto exit;
4386 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004387 return_value = os_putenv_impl(module, name, value);
4388
4389exit:
4390 /* Cleanup for name */
4391 Py_XDECREF(name);
4392 /* Cleanup for value */
4393 Py_XDECREF(value);
4394
4395 return return_value;
4396}
4397
4398#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4399
4400#if defined(HAVE_UNSETENV)
4401
4402PyDoc_STRVAR(os_unsetenv__doc__,
4403"unsetenv($module, name, /)\n"
4404"--\n"
4405"\n"
4406"Delete an environment variable.");
4407
4408#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004409 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004410
4411static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004412os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004413
4414static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004415os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004416{
4417 PyObject *return_value = NULL;
4418 PyObject *name = NULL;
4419
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004420 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004421 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004422 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004423 return_value = os_unsetenv_impl(module, name);
4424
4425exit:
4426 /* Cleanup for name */
4427 Py_XDECREF(name);
4428
4429 return return_value;
4430}
4431
4432#endif /* defined(HAVE_UNSETENV) */
4433
4434PyDoc_STRVAR(os_strerror__doc__,
4435"strerror($module, code, /)\n"
4436"--\n"
4437"\n"
4438"Translate an error code to a message string.");
4439
4440#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004441 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004442
4443static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004444os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004445
4446static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004447os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004448{
4449 PyObject *return_value = NULL;
4450 int code;
4451
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004452 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004453 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004454 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004455 return_value = os_strerror_impl(module, code);
4456
4457exit:
4458 return return_value;
4459}
4460
4461#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4462
4463PyDoc_STRVAR(os_WCOREDUMP__doc__,
4464"WCOREDUMP($module, status, /)\n"
4465"--\n"
4466"\n"
4467"Return True if the process returning status was dumped to a core file.");
4468
4469#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004470 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004471
4472static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004473os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004474
4475static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004476os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004477{
4478 PyObject *return_value = NULL;
4479 int status;
4480 int _return_value;
4481
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004482 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004483 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004484 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004485 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004486 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004487 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004488 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004489 return_value = PyBool_FromLong((long)_return_value);
4490
4491exit:
4492 return return_value;
4493}
4494
4495#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4496
4497#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4498
4499PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4500"WIFCONTINUED($module, /, status)\n"
4501"--\n"
4502"\n"
4503"Return True if a particular process was continued from a job control stop.\n"
4504"\n"
4505"Return True if the process returning status was continued from a\n"
4506"job control stop.");
4507
4508#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004509 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004510
4511static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004512os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004513
4514static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004515os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004516{
4517 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004518 static const char * const _keywords[] = {"status", NULL};
4519 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004520 int status;
4521 int _return_value;
4522
Victor Stinner3e1fad62017-01-17 01:29:01 +01004523 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004524 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004525 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004526 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004527 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004528 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004529 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004530 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004531 return_value = PyBool_FromLong((long)_return_value);
4532
4533exit:
4534 return return_value;
4535}
4536
4537#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4538
4539#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4540
4541PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4542"WIFSTOPPED($module, /, status)\n"
4543"--\n"
4544"\n"
4545"Return True if the process returning status was stopped.");
4546
4547#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004548 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004549
4550static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004551os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004552
4553static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004554os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004555{
4556 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004557 static const char * const _keywords[] = {"status", NULL};
4558 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004559 int status;
4560 int _return_value;
4561
Victor Stinner3e1fad62017-01-17 01:29:01 +01004562 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004563 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004564 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004565 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004566 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004567 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004568 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004569 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004570 return_value = PyBool_FromLong((long)_return_value);
4571
4572exit:
4573 return return_value;
4574}
4575
4576#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4577
4578#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4579
4580PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4581"WIFSIGNALED($module, /, status)\n"
4582"--\n"
4583"\n"
4584"Return True if the process returning status was terminated by a signal.");
4585
4586#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004587 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004588
4589static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004590os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004591
4592static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004593os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004594{
4595 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004596 static const char * const _keywords[] = {"status", NULL};
4597 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004598 int status;
4599 int _return_value;
4600
Victor Stinner3e1fad62017-01-17 01:29:01 +01004601 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004602 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004603 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004604 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004605 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004606 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004607 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004608 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004609 return_value = PyBool_FromLong((long)_return_value);
4610
4611exit:
4612 return return_value;
4613}
4614
4615#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4616
4617#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4618
4619PyDoc_STRVAR(os_WIFEXITED__doc__,
4620"WIFEXITED($module, /, status)\n"
4621"--\n"
4622"\n"
4623"Return True if the process returning status exited via the exit() system call.");
4624
4625#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004626 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004627
4628static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004629os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004630
4631static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004632os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004633{
4634 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004635 static const char * const _keywords[] = {"status", NULL};
4636 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004637 int status;
4638 int _return_value;
4639
Victor Stinner3e1fad62017-01-17 01:29:01 +01004640 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004641 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004642 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004643 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004644 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004645 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004646 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004647 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004648 return_value = PyBool_FromLong((long)_return_value);
4649
4650exit:
4651 return return_value;
4652}
4653
4654#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4655
4656#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4657
4658PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4659"WEXITSTATUS($module, /, status)\n"
4660"--\n"
4661"\n"
4662"Return the process return code from status.");
4663
4664#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004665 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004666
4667static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004668os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004669
4670static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004671os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004672{
4673 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004674 static const char * const _keywords[] = {"status", NULL};
4675 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004676 int status;
4677 int _return_value;
4678
Victor Stinner3e1fad62017-01-17 01:29:01 +01004679 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004680 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004681 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004682 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004683 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004684 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004685 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004686 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004687 return_value = PyLong_FromLong((long)_return_value);
4688
4689exit:
4690 return return_value;
4691}
4692
4693#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4694
4695#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4696
4697PyDoc_STRVAR(os_WTERMSIG__doc__,
4698"WTERMSIG($module, /, status)\n"
4699"--\n"
4700"\n"
4701"Return the signal that terminated the process that provided the status value.");
4702
4703#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004704 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004705
4706static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004707os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708
4709static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004710os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004711{
4712 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004713 static const char * const _keywords[] = {"status", NULL};
4714 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004715 int status;
4716 int _return_value;
4717
Victor Stinner3e1fad62017-01-17 01:29:01 +01004718 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004719 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004720 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004721 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004722 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004723 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004724 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004725 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004726 return_value = PyLong_FromLong((long)_return_value);
4727
4728exit:
4729 return return_value;
4730}
4731
4732#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4733
4734#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4735
4736PyDoc_STRVAR(os_WSTOPSIG__doc__,
4737"WSTOPSIG($module, /, status)\n"
4738"--\n"
4739"\n"
4740"Return the signal that stopped the process that provided the status value.");
4741
4742#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004743 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004744
4745static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004746os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004747
4748static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004749os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004750{
4751 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004752 static const char * const _keywords[] = {"status", NULL};
4753 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004754 int status;
4755 int _return_value;
4756
Victor Stinner3e1fad62017-01-17 01:29:01 +01004757 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004758 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004759 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004760 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004761 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004762 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004763 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004764 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004765 return_value = PyLong_FromLong((long)_return_value);
4766
4767exit:
4768 return return_value;
4769}
4770
4771#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4772
4773#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4774
4775PyDoc_STRVAR(os_fstatvfs__doc__,
4776"fstatvfs($module, fd, /)\n"
4777"--\n"
4778"\n"
4779"Perform an fstatvfs system call on the given fd.\n"
4780"\n"
4781"Equivalent to statvfs(fd).");
4782
4783#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004784 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004785
4786static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004787os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004788
4789static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004790os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004791{
4792 PyObject *return_value = NULL;
4793 int fd;
4794
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004795 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004796 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004797 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004798 return_value = os_fstatvfs_impl(module, fd);
4799
4800exit:
4801 return return_value;
4802}
4803
4804#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4805
4806#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4807
4808PyDoc_STRVAR(os_statvfs__doc__,
4809"statvfs($module, /, path)\n"
4810"--\n"
4811"\n"
4812"Perform a statvfs system call on the given path.\n"
4813"\n"
4814"path may always be specified as a string.\n"
4815"On some platforms, path may also be specified as an open file descriptor.\n"
4816" If this functionality is unavailable, using it raises an exception.");
4817
4818#define OS_STATVFS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004819 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004820
4821static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004822os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004823
4824static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004825os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004826{
4827 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004828 static const char * const _keywords[] = {"path", NULL};
4829 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004830 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4831
Victor Stinner3e1fad62017-01-17 01:29:01 +01004832 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004833 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004834 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004835 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004836 return_value = os_statvfs_impl(module, &path);
4837
4838exit:
4839 /* Cleanup for path */
4840 path_cleanup(&path);
4841
4842 return return_value;
4843}
4844
4845#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4846
4847#if defined(MS_WINDOWS)
4848
4849PyDoc_STRVAR(os__getdiskusage__doc__,
4850"_getdiskusage($module, /, path)\n"
4851"--\n"
4852"\n"
4853"Return disk usage statistics about the given path as a (total, free) tuple.");
4854
4855#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004856 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004857
4858static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004859os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004860
4861static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004862os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004863{
4864 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004865 static const char * const _keywords[] = {"path", NULL};
4866 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004867 Py_UNICODE *path;
4868
Victor Stinner3e1fad62017-01-17 01:29:01 +01004869 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004870 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004871 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004872 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004873 return_value = os__getdiskusage_impl(module, path);
4874
4875exit:
4876 return return_value;
4877}
4878
4879#endif /* defined(MS_WINDOWS) */
4880
4881#if defined(HAVE_FPATHCONF)
4882
4883PyDoc_STRVAR(os_fpathconf__doc__,
4884"fpathconf($module, fd, name, /)\n"
4885"--\n"
4886"\n"
4887"Return the configuration limit name for the file descriptor fd.\n"
4888"\n"
4889"If there is no limit, return -1.");
4890
4891#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004892 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004893
4894static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004895os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004896
4897static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004898os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004899{
4900 PyObject *return_value = NULL;
4901 int fd;
4902 int name;
4903 long _return_value;
4904
Sylvain74453812017-06-10 06:51:48 +02004905 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
4906 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004907 goto exit;
4908 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004909 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004910 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004911 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004912 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004913 return_value = PyLong_FromLong(_return_value);
4914
4915exit:
4916 return return_value;
4917}
4918
4919#endif /* defined(HAVE_FPATHCONF) */
4920
4921#if defined(HAVE_PATHCONF)
4922
4923PyDoc_STRVAR(os_pathconf__doc__,
4924"pathconf($module, /, path, name)\n"
4925"--\n"
4926"\n"
4927"Return the configuration limit name for the file or directory path.\n"
4928"\n"
4929"If there is no limit, return -1.\n"
4930"On some platforms, path may also be specified as an open file descriptor.\n"
4931" If this functionality is unavailable, using it raises an exception.");
4932
4933#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004934 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004935
4936static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004937os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004938
4939static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004940os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004941{
4942 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004943 static const char * const _keywords[] = {"path", "name", NULL};
4944 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004945 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
4946 int name;
4947 long _return_value;
4948
Victor Stinner3e1fad62017-01-17 01:29:01 +01004949 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004950 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004951 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004952 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004953 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004954 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004955 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004956 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004957 return_value = PyLong_FromLong(_return_value);
4958
4959exit:
4960 /* Cleanup for path */
4961 path_cleanup(&path);
4962
4963 return return_value;
4964}
4965
4966#endif /* defined(HAVE_PATHCONF) */
4967
4968#if defined(HAVE_CONFSTR)
4969
4970PyDoc_STRVAR(os_confstr__doc__,
4971"confstr($module, name, /)\n"
4972"--\n"
4973"\n"
4974"Return a string-valued system configuration variable.");
4975
4976#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004977 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004978
4979static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004980os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004981
4982static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004983os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984{
4985 PyObject *return_value = NULL;
4986 int name;
4987
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004988 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004989 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004990 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004991 return_value = os_confstr_impl(module, name);
4992
4993exit:
4994 return return_value;
4995}
4996
4997#endif /* defined(HAVE_CONFSTR) */
4998
4999#if defined(HAVE_SYSCONF)
5000
5001PyDoc_STRVAR(os_sysconf__doc__,
5002"sysconf($module, name, /)\n"
5003"--\n"
5004"\n"
5005"Return an integer-valued system configuration variable.");
5006
5007#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005008 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005009
5010static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005011os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005012
5013static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005014os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005015{
5016 PyObject *return_value = NULL;
5017 int name;
5018 long _return_value;
5019
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005020 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005021 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005022 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005023 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005024 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005025 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005026 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005027 return_value = PyLong_FromLong(_return_value);
5028
5029exit:
5030 return return_value;
5031}
5032
5033#endif /* defined(HAVE_SYSCONF) */
5034
5035PyDoc_STRVAR(os_abort__doc__,
5036"abort($module, /)\n"
5037"--\n"
5038"\n"
5039"Abort the interpreter immediately.\n"
5040"\n"
5041"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5042"on the hosting operating system. This function never returns.");
5043
5044#define OS_ABORT_METHODDEF \
5045 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5046
5047static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005048os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005049
5050static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005051os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005052{
5053 return os_abort_impl(module);
5054}
5055
Steve Dowercc16be82016-09-08 10:35:16 -07005056#if defined(MS_WINDOWS)
5057
5058PyDoc_STRVAR(os_startfile__doc__,
5059"startfile($module, /, filepath, operation=None)\n"
5060"--\n"
5061"\n"
5062"startfile(filepath [, operation])\n"
5063"\n"
5064"Start a file with its associated application.\n"
5065"\n"
5066"When \"operation\" is not specified or \"open\", this acts like\n"
5067"double-clicking the file in Explorer, or giving the file name as an\n"
5068"argument to the DOS \"start\" command: the file is opened with whatever\n"
5069"application (if any) its extension is associated.\n"
5070"When another \"operation\" is given, it specifies what should be done with\n"
5071"the file. A typical operation is \"print\".\n"
5072"\n"
5073"startfile returns as soon as the associated application is launched.\n"
5074"There is no option to wait for the application to close, and no way\n"
5075"to retrieve the application\'s exit status.\n"
5076"\n"
5077"The filepath is relative to the current directory. If you want to use\n"
5078"an absolute path, make sure the first character is not a slash (\"/\");\n"
5079"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5080
5081#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005082 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005083
5084static PyObject *
5085os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5086
5087static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005088os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005089{
5090 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005091 static const char * const _keywords[] = {"filepath", "operation", NULL};
5092 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005093 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5094 Py_UNICODE *operation = NULL;
5095
Victor Stinner3e1fad62017-01-17 01:29:01 +01005096 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005097 path_converter, &filepath, &operation)) {
5098 goto exit;
5099 }
5100 return_value = os_startfile_impl(module, &filepath, operation);
5101
5102exit:
5103 /* Cleanup for filepath */
5104 path_cleanup(&filepath);
5105
5106 return return_value;
5107}
5108
5109#endif /* defined(MS_WINDOWS) */
5110
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005111#if defined(HAVE_GETLOADAVG)
5112
5113PyDoc_STRVAR(os_getloadavg__doc__,
5114"getloadavg($module, /)\n"
5115"--\n"
5116"\n"
5117"Return average recent system load information.\n"
5118"\n"
5119"Return the number of processes in the system run queue averaged over\n"
5120"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5121"Raises OSError if the load average was unobtainable.");
5122
5123#define OS_GETLOADAVG_METHODDEF \
5124 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5125
5126static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005127os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005128
5129static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005130os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005131{
5132 return os_getloadavg_impl(module);
5133}
5134
5135#endif /* defined(HAVE_GETLOADAVG) */
5136
5137PyDoc_STRVAR(os_device_encoding__doc__,
5138"device_encoding($module, /, fd)\n"
5139"--\n"
5140"\n"
5141"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5142"\n"
5143"The file descriptor must be attached to a terminal.\n"
5144"If the device is not a terminal, return None.");
5145
5146#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005147 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005148
5149static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005150os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005151
5152static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005153os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005154{
5155 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005156 static const char * const _keywords[] = {"fd", NULL};
5157 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005158 int fd;
5159
Victor Stinner3e1fad62017-01-17 01:29:01 +01005160 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005161 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005162 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005163 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005164 return_value = os_device_encoding_impl(module, fd);
5165
5166exit:
5167 return return_value;
5168}
5169
5170#if defined(HAVE_SETRESUID)
5171
5172PyDoc_STRVAR(os_setresuid__doc__,
5173"setresuid($module, ruid, euid, suid, /)\n"
5174"--\n"
5175"\n"
5176"Set the current process\'s real, effective, and saved user ids.");
5177
5178#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005179 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005180
5181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005182os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005183
5184static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005185os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005186{
5187 PyObject *return_value = NULL;
5188 uid_t ruid;
5189 uid_t euid;
5190 uid_t suid;
5191
Sylvain74453812017-06-10 06:51:48 +02005192 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5193 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005194 goto exit;
5195 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005196 return_value = os_setresuid_impl(module, ruid, euid, suid);
5197
5198exit:
5199 return return_value;
5200}
5201
5202#endif /* defined(HAVE_SETRESUID) */
5203
5204#if defined(HAVE_SETRESGID)
5205
5206PyDoc_STRVAR(os_setresgid__doc__,
5207"setresgid($module, rgid, egid, sgid, /)\n"
5208"--\n"
5209"\n"
5210"Set the current process\'s real, effective, and saved group ids.");
5211
5212#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005213 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005214
5215static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005216os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005217
5218static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005219os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005220{
5221 PyObject *return_value = NULL;
5222 gid_t rgid;
5223 gid_t egid;
5224 gid_t sgid;
5225
Sylvain74453812017-06-10 06:51:48 +02005226 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5227 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005228 goto exit;
5229 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005230 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5231
5232exit:
5233 return return_value;
5234}
5235
5236#endif /* defined(HAVE_SETRESGID) */
5237
5238#if defined(HAVE_GETRESUID)
5239
5240PyDoc_STRVAR(os_getresuid__doc__,
5241"getresuid($module, /)\n"
5242"--\n"
5243"\n"
5244"Return a tuple of the current process\'s real, effective, and saved user ids.");
5245
5246#define OS_GETRESUID_METHODDEF \
5247 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5248
5249static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005250os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005251
5252static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005253os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005254{
5255 return os_getresuid_impl(module);
5256}
5257
5258#endif /* defined(HAVE_GETRESUID) */
5259
5260#if defined(HAVE_GETRESGID)
5261
5262PyDoc_STRVAR(os_getresgid__doc__,
5263"getresgid($module, /)\n"
5264"--\n"
5265"\n"
5266"Return a tuple of the current process\'s real, effective, and saved group ids.");
5267
5268#define OS_GETRESGID_METHODDEF \
5269 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5270
5271static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005272os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005273
5274static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005275os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005276{
5277 return os_getresgid_impl(module);
5278}
5279
5280#endif /* defined(HAVE_GETRESGID) */
5281
5282#if defined(USE_XATTRS)
5283
5284PyDoc_STRVAR(os_getxattr__doc__,
5285"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5286"--\n"
5287"\n"
5288"Return the value of extended attribute attribute on path.\n"
5289"\n"
5290"path may be either a string or an open file descriptor.\n"
5291"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5292" link, getxattr will examine the symbolic link itself instead of the file\n"
5293" the link points to.");
5294
5295#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005296 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005297
5298static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005299os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005300 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005301
5302static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005303os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005304{
5305 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005306 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5307 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005308 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5309 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5310 int follow_symlinks = 1;
5311
Victor Stinner3e1fad62017-01-17 01:29:01 +01005312 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005313 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005314 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005315 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005316 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5317
5318exit:
5319 /* Cleanup for path */
5320 path_cleanup(&path);
5321 /* Cleanup for attribute */
5322 path_cleanup(&attribute);
5323
5324 return return_value;
5325}
5326
5327#endif /* defined(USE_XATTRS) */
5328
5329#if defined(USE_XATTRS)
5330
5331PyDoc_STRVAR(os_setxattr__doc__,
5332"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5333" follow_symlinks=True)\n"
5334"--\n"
5335"\n"
5336"Set extended attribute attribute on path to value.\n"
5337"\n"
5338"path may be either a string or an open file descriptor.\n"
5339"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5340" link, setxattr will modify the symbolic link itself instead of the file\n"
5341" the link points to.");
5342
5343#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005344 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005345
5346static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005347os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005348 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005349
5350static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005351os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005352{
5353 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005354 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5355 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005356 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5357 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5358 Py_buffer value = {NULL, NULL};
5359 int flags = 0;
5360 int follow_symlinks = 1;
5361
Victor Stinner3e1fad62017-01-17 01:29:01 +01005362 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005363 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005364 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005365 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005366 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5367
5368exit:
5369 /* Cleanup for path */
5370 path_cleanup(&path);
5371 /* Cleanup for attribute */
5372 path_cleanup(&attribute);
5373 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005374 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005375 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005376 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005377
5378 return return_value;
5379}
5380
5381#endif /* defined(USE_XATTRS) */
5382
5383#if defined(USE_XATTRS)
5384
5385PyDoc_STRVAR(os_removexattr__doc__,
5386"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5387"--\n"
5388"\n"
5389"Remove extended attribute attribute on path.\n"
5390"\n"
5391"path may be either a string or an open file descriptor.\n"
5392"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5393" link, removexattr will modify the symbolic link itself instead of the file\n"
5394" the link points to.");
5395
5396#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005397 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005398
5399static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005400os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005401 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005402
5403static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005404os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005405{
5406 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005407 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5408 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005409 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5410 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5411 int follow_symlinks = 1;
5412
Victor Stinner3e1fad62017-01-17 01:29:01 +01005413 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005414 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005415 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005416 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005417 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5418
5419exit:
5420 /* Cleanup for path */
5421 path_cleanup(&path);
5422 /* Cleanup for attribute */
5423 path_cleanup(&attribute);
5424
5425 return return_value;
5426}
5427
5428#endif /* defined(USE_XATTRS) */
5429
5430#if defined(USE_XATTRS)
5431
5432PyDoc_STRVAR(os_listxattr__doc__,
5433"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5434"--\n"
5435"\n"
5436"Return a list of extended attributes on path.\n"
5437"\n"
5438"path may be either None, a string, or an open file descriptor.\n"
5439"if path is None, listxattr will examine the current directory.\n"
5440"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5441" link, listxattr will examine the symbolic link itself instead of the file\n"
5442" the link points to.");
5443
5444#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005445 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005446
5447static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005448os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005449
5450static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005451os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005452{
5453 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005454 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5455 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005456 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5457 int follow_symlinks = 1;
5458
Victor Stinner3e1fad62017-01-17 01:29:01 +01005459 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005460 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005461 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005462 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005463 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5464
5465exit:
5466 /* Cleanup for path */
5467 path_cleanup(&path);
5468
5469 return return_value;
5470}
5471
5472#endif /* defined(USE_XATTRS) */
5473
5474PyDoc_STRVAR(os_urandom__doc__,
5475"urandom($module, size, /)\n"
5476"--\n"
5477"\n"
5478"Return a bytes object containing random bytes suitable for cryptographic use.");
5479
5480#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005481 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005482
5483static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005484os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005485
5486static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005487os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005488{
5489 PyObject *return_value = NULL;
5490 Py_ssize_t size;
5491
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005492 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005493 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005494 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005495 return_value = os_urandom_impl(module, size);
5496
5497exit:
5498 return return_value;
5499}
5500
5501PyDoc_STRVAR(os_cpu_count__doc__,
5502"cpu_count($module, /)\n"
5503"--\n"
5504"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005505"Return the number of CPUs in the system; return None if indeterminable.\n"
5506"\n"
5507"This number is not equivalent to the number of CPUs the current process can\n"
5508"use. The number of usable CPUs can be obtained with\n"
5509"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005510
5511#define OS_CPU_COUNT_METHODDEF \
5512 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5513
5514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005515os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005516
5517static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005518os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005519{
5520 return os_cpu_count_impl(module);
5521}
5522
5523PyDoc_STRVAR(os_get_inheritable__doc__,
5524"get_inheritable($module, fd, /)\n"
5525"--\n"
5526"\n"
5527"Get the close-on-exe flag of the specified file descriptor.");
5528
5529#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005530 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005531
5532static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005533os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005534
5535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005536os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005537{
5538 PyObject *return_value = NULL;
5539 int fd;
5540 int _return_value;
5541
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005542 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005543 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005544 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005545 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005546 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005547 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005548 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005549 return_value = PyBool_FromLong((long)_return_value);
5550
5551exit:
5552 return return_value;
5553}
5554
5555PyDoc_STRVAR(os_set_inheritable__doc__,
5556"set_inheritable($module, fd, inheritable, /)\n"
5557"--\n"
5558"\n"
5559"Set the inheritable flag of the specified file descriptor.");
5560
5561#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005562 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005563
5564static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005565os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005566
5567static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005568os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005569{
5570 PyObject *return_value = NULL;
5571 int fd;
5572 int inheritable;
5573
Sylvain74453812017-06-10 06:51:48 +02005574 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5575 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005576 goto exit;
5577 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005578 return_value = os_set_inheritable_impl(module, fd, inheritable);
5579
5580exit:
5581 return return_value;
5582}
5583
5584#if defined(MS_WINDOWS)
5585
5586PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5587"get_handle_inheritable($module, handle, /)\n"
5588"--\n"
5589"\n"
5590"Get the close-on-exe flag of the specified file descriptor.");
5591
5592#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005593 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005594
5595static int
Victor Stinner581139c2016-09-06 15:54:20 -07005596os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005597
5598static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005599os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005600{
5601 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005602 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005603 int _return_value;
5604
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005605 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005606 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005607 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005608 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005609 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005610 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005611 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005612 return_value = PyBool_FromLong((long)_return_value);
5613
5614exit:
5615 return return_value;
5616}
5617
5618#endif /* defined(MS_WINDOWS) */
5619
5620#if defined(MS_WINDOWS)
5621
5622PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5623"set_handle_inheritable($module, handle, inheritable, /)\n"
5624"--\n"
5625"\n"
5626"Set the inheritable flag of the specified handle.");
5627
5628#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005629 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005630
5631static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005632os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005633 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005634
5635static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005636os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005637{
5638 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005639 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005640 int inheritable;
5641
Sylvain74453812017-06-10 06:51:48 +02005642 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5643 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005644 goto exit;
5645 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005646 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5647
5648exit:
5649 return return_value;
5650}
5651
5652#endif /* defined(MS_WINDOWS) */
5653
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005654PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5655"is_symlink($self, /)\n"
5656"--\n"
5657"\n"
5658"Return True if the entry is a symbolic link; cached per entry.");
5659
5660#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5661 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5662
5663static int
5664os_DirEntry_is_symlink_impl(DirEntry *self);
5665
5666static PyObject *
5667os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5668{
5669 PyObject *return_value = NULL;
5670 int _return_value;
5671
5672 _return_value = os_DirEntry_is_symlink_impl(self);
5673 if ((_return_value == -1) && PyErr_Occurred()) {
5674 goto exit;
5675 }
5676 return_value = PyBool_FromLong((long)_return_value);
5677
5678exit:
5679 return return_value;
5680}
5681
5682PyDoc_STRVAR(os_DirEntry_stat__doc__,
5683"stat($self, /, *, follow_symlinks=True)\n"
5684"--\n"
5685"\n"
5686"Return stat_result object for the entry; cached per entry.");
5687
5688#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005689 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005690
5691static PyObject *
5692os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5693
5694static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005695os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005696{
5697 PyObject *return_value = NULL;
5698 static const char * const _keywords[] = {"follow_symlinks", NULL};
5699 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5700 int follow_symlinks = 1;
5701
Victor Stinner3e1fad62017-01-17 01:29:01 +01005702 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005703 &follow_symlinks)) {
5704 goto exit;
5705 }
5706 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5707
5708exit:
5709 return return_value;
5710}
5711
5712PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5713"is_dir($self, /, *, follow_symlinks=True)\n"
5714"--\n"
5715"\n"
5716"Return True if the entry is a directory; cached per entry.");
5717
5718#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005719 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005720
5721static int
5722os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5723
5724static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005725os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005726{
5727 PyObject *return_value = NULL;
5728 static const char * const _keywords[] = {"follow_symlinks", NULL};
5729 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5730 int follow_symlinks = 1;
5731 int _return_value;
5732
Victor Stinner3e1fad62017-01-17 01:29:01 +01005733 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005734 &follow_symlinks)) {
5735 goto exit;
5736 }
5737 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5738 if ((_return_value == -1) && PyErr_Occurred()) {
5739 goto exit;
5740 }
5741 return_value = PyBool_FromLong((long)_return_value);
5742
5743exit:
5744 return return_value;
5745}
5746
5747PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5748"is_file($self, /, *, follow_symlinks=True)\n"
5749"--\n"
5750"\n"
5751"Return True if the entry is a file; cached per entry.");
5752
5753#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005754 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005755
5756static int
5757os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5758
5759static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005760os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005761{
5762 PyObject *return_value = NULL;
5763 static const char * const _keywords[] = {"follow_symlinks", NULL};
5764 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5765 int follow_symlinks = 1;
5766 int _return_value;
5767
Victor Stinner3e1fad62017-01-17 01:29:01 +01005768 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005769 &follow_symlinks)) {
5770 goto exit;
5771 }
5772 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5773 if ((_return_value == -1) && PyErr_Occurred()) {
5774 goto exit;
5775 }
5776 return_value = PyBool_FromLong((long)_return_value);
5777
5778exit:
5779 return return_value;
5780}
5781
5782PyDoc_STRVAR(os_DirEntry_inode__doc__,
5783"inode($self, /)\n"
5784"--\n"
5785"\n"
5786"Return inode of the entry; cached per entry.");
5787
5788#define OS_DIRENTRY_INODE_METHODDEF \
5789 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5790
5791static PyObject *
5792os_DirEntry_inode_impl(DirEntry *self);
5793
5794static PyObject *
5795os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5796{
5797 return os_DirEntry_inode_impl(self);
5798}
5799
5800PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5801"__fspath__($self, /)\n"
5802"--\n"
5803"\n"
5804"Returns the path for the entry.");
5805
5806#define OS_DIRENTRY___FSPATH___METHODDEF \
5807 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5808
5809static PyObject *
5810os_DirEntry___fspath___impl(DirEntry *self);
5811
5812static PyObject *
5813os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5814{
5815 return os_DirEntry___fspath___impl(self);
5816}
5817
5818PyDoc_STRVAR(os_scandir__doc__,
5819"scandir($module, /, path=None)\n"
5820"--\n"
5821"\n"
5822"Return an iterator of DirEntry objects for given path.\n"
5823"\n"
5824"path can be specified as either str, bytes or path-like object. If path\n"
5825"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5826"all other circumstances they will be str.\n"
5827"\n"
5828"If path is None, uses the path=\'.\'.");
5829
5830#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005831 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005832
5833static PyObject *
5834os_scandir_impl(PyObject *module, path_t *path);
5835
5836static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005837os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005838{
5839 PyObject *return_value = NULL;
5840 static const char * const _keywords[] = {"path", NULL};
5841 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03005842 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005843
Victor Stinner3e1fad62017-01-17 01:29:01 +01005844 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005845 path_converter, &path)) {
5846 goto exit;
5847 }
5848 return_value = os_scandir_impl(module, &path);
5849
5850exit:
5851 /* Cleanup for path */
5852 path_cleanup(&path);
5853
5854 return return_value;
5855}
5856
Ethan Furman410ef8e2016-06-04 12:06:26 -07005857PyDoc_STRVAR(os_fspath__doc__,
5858"fspath($module, /, path)\n"
5859"--\n"
5860"\n"
5861"Return the file system path representation of the object.\n"
5862"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005863"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5864"object defines __fspath__(), then return the result of that method. All other\n"
5865"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005866
5867#define OS_FSPATH_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005868 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07005869
5870static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005871os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07005872
5873static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005874os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07005875{
5876 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005877 static const char * const _keywords[] = {"path", NULL};
5878 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07005879 PyObject *path;
5880
Victor Stinner3e1fad62017-01-17 01:29:01 +01005881 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005882 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07005883 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005884 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07005885 return_value = os_fspath_impl(module, path);
5886
5887exit:
5888 return return_value;
5889}
5890
Victor Stinner9b1f4742016-09-06 16:18:52 -07005891#if defined(HAVE_GETRANDOM_SYSCALL)
5892
5893PyDoc_STRVAR(os_getrandom__doc__,
5894"getrandom($module, /, size, flags=0)\n"
5895"--\n"
5896"\n"
5897"Obtain a series of random bytes.");
5898
5899#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005900 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07005901
5902static PyObject *
5903os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
5904
5905static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005906os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07005907{
5908 PyObject *return_value = NULL;
5909 static const char * const _keywords[] = {"size", "flags", NULL};
5910 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
5911 Py_ssize_t size;
5912 int flags = 0;
5913
Victor Stinner3e1fad62017-01-17 01:29:01 +01005914 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07005915 &size, &flags)) {
5916 goto exit;
5917 }
5918 return_value = os_getrandom_impl(module, size, flags);
5919
5920exit:
5921 return return_value;
5922}
5923
5924#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
5925
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005926#ifndef OS_TTYNAME_METHODDEF
5927 #define OS_TTYNAME_METHODDEF
5928#endif /* !defined(OS_TTYNAME_METHODDEF) */
5929
5930#ifndef OS_CTERMID_METHODDEF
5931 #define OS_CTERMID_METHODDEF
5932#endif /* !defined(OS_CTERMID_METHODDEF) */
5933
5934#ifndef OS_FCHDIR_METHODDEF
5935 #define OS_FCHDIR_METHODDEF
5936#endif /* !defined(OS_FCHDIR_METHODDEF) */
5937
5938#ifndef OS_FCHMOD_METHODDEF
5939 #define OS_FCHMOD_METHODDEF
5940#endif /* !defined(OS_FCHMOD_METHODDEF) */
5941
5942#ifndef OS_LCHMOD_METHODDEF
5943 #define OS_LCHMOD_METHODDEF
5944#endif /* !defined(OS_LCHMOD_METHODDEF) */
5945
5946#ifndef OS_CHFLAGS_METHODDEF
5947 #define OS_CHFLAGS_METHODDEF
5948#endif /* !defined(OS_CHFLAGS_METHODDEF) */
5949
5950#ifndef OS_LCHFLAGS_METHODDEF
5951 #define OS_LCHFLAGS_METHODDEF
5952#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
5953
5954#ifndef OS_CHROOT_METHODDEF
5955 #define OS_CHROOT_METHODDEF
5956#endif /* !defined(OS_CHROOT_METHODDEF) */
5957
5958#ifndef OS_FSYNC_METHODDEF
5959 #define OS_FSYNC_METHODDEF
5960#endif /* !defined(OS_FSYNC_METHODDEF) */
5961
5962#ifndef OS_SYNC_METHODDEF
5963 #define OS_SYNC_METHODDEF
5964#endif /* !defined(OS_SYNC_METHODDEF) */
5965
5966#ifndef OS_FDATASYNC_METHODDEF
5967 #define OS_FDATASYNC_METHODDEF
5968#endif /* !defined(OS_FDATASYNC_METHODDEF) */
5969
5970#ifndef OS_CHOWN_METHODDEF
5971 #define OS_CHOWN_METHODDEF
5972#endif /* !defined(OS_CHOWN_METHODDEF) */
5973
5974#ifndef OS_FCHOWN_METHODDEF
5975 #define OS_FCHOWN_METHODDEF
5976#endif /* !defined(OS_FCHOWN_METHODDEF) */
5977
5978#ifndef OS_LCHOWN_METHODDEF
5979 #define OS_LCHOWN_METHODDEF
5980#endif /* !defined(OS_LCHOWN_METHODDEF) */
5981
5982#ifndef OS_LINK_METHODDEF
5983 #define OS_LINK_METHODDEF
5984#endif /* !defined(OS_LINK_METHODDEF) */
5985
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005986#ifndef OS__GETFULLPATHNAME_METHODDEF
5987 #define OS__GETFULLPATHNAME_METHODDEF
5988#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
5989
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005990#ifndef OS__GETFINALPATHNAME_METHODDEF
5991 #define OS__GETFINALPATHNAME_METHODDEF
5992#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
5993
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005994#ifndef OS__ISDIR_METHODDEF
5995 #define OS__ISDIR_METHODDEF
5996#endif /* !defined(OS__ISDIR_METHODDEF) */
5997
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005998#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
5999 #define OS__GETVOLUMEPATHNAME_METHODDEF
6000#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6001
6002#ifndef OS_NICE_METHODDEF
6003 #define OS_NICE_METHODDEF
6004#endif /* !defined(OS_NICE_METHODDEF) */
6005
6006#ifndef OS_GETPRIORITY_METHODDEF
6007 #define OS_GETPRIORITY_METHODDEF
6008#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6009
6010#ifndef OS_SETPRIORITY_METHODDEF
6011 #define OS_SETPRIORITY_METHODDEF
6012#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6013
6014#ifndef OS_SYSTEM_METHODDEF
6015 #define OS_SYSTEM_METHODDEF
6016#endif /* !defined(OS_SYSTEM_METHODDEF) */
6017
6018#ifndef OS_UNAME_METHODDEF
6019 #define OS_UNAME_METHODDEF
6020#endif /* !defined(OS_UNAME_METHODDEF) */
6021
6022#ifndef OS_EXECV_METHODDEF
6023 #define OS_EXECV_METHODDEF
6024#endif /* !defined(OS_EXECV_METHODDEF) */
6025
6026#ifndef OS_EXECVE_METHODDEF
6027 #define OS_EXECVE_METHODDEF
6028#endif /* !defined(OS_EXECVE_METHODDEF) */
6029
6030#ifndef OS_SPAWNV_METHODDEF
6031 #define OS_SPAWNV_METHODDEF
6032#endif /* !defined(OS_SPAWNV_METHODDEF) */
6033
6034#ifndef OS_SPAWNVE_METHODDEF
6035 #define OS_SPAWNVE_METHODDEF
6036#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6037
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006038#ifndef OS_REGISTER_AT_FORK_METHODDEF
6039 #define OS_REGISTER_AT_FORK_METHODDEF
6040#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6041
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006042#ifndef OS_FORK1_METHODDEF
6043 #define OS_FORK1_METHODDEF
6044#endif /* !defined(OS_FORK1_METHODDEF) */
6045
6046#ifndef OS_FORK_METHODDEF
6047 #define OS_FORK_METHODDEF
6048#endif /* !defined(OS_FORK_METHODDEF) */
6049
6050#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6051 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6052#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6053
6054#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6055 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6056#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6057
6058#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6059 #define OS_SCHED_GETSCHEDULER_METHODDEF
6060#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6061
6062#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6063 #define OS_SCHED_SETSCHEDULER_METHODDEF
6064#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6065
6066#ifndef OS_SCHED_GETPARAM_METHODDEF
6067 #define OS_SCHED_GETPARAM_METHODDEF
6068#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6069
6070#ifndef OS_SCHED_SETPARAM_METHODDEF
6071 #define OS_SCHED_SETPARAM_METHODDEF
6072#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6073
6074#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6075 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6076#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6077
6078#ifndef OS_SCHED_YIELD_METHODDEF
6079 #define OS_SCHED_YIELD_METHODDEF
6080#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6081
6082#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6083 #define OS_SCHED_SETAFFINITY_METHODDEF
6084#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6085
6086#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6087 #define OS_SCHED_GETAFFINITY_METHODDEF
6088#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6089
6090#ifndef OS_OPENPTY_METHODDEF
6091 #define OS_OPENPTY_METHODDEF
6092#endif /* !defined(OS_OPENPTY_METHODDEF) */
6093
6094#ifndef OS_FORKPTY_METHODDEF
6095 #define OS_FORKPTY_METHODDEF
6096#endif /* !defined(OS_FORKPTY_METHODDEF) */
6097
6098#ifndef OS_GETEGID_METHODDEF
6099 #define OS_GETEGID_METHODDEF
6100#endif /* !defined(OS_GETEGID_METHODDEF) */
6101
6102#ifndef OS_GETEUID_METHODDEF
6103 #define OS_GETEUID_METHODDEF
6104#endif /* !defined(OS_GETEUID_METHODDEF) */
6105
6106#ifndef OS_GETGID_METHODDEF
6107 #define OS_GETGID_METHODDEF
6108#endif /* !defined(OS_GETGID_METHODDEF) */
6109
Berker Peksag39404992016-09-15 20:45:16 +03006110#ifndef OS_GETPID_METHODDEF
6111 #define OS_GETPID_METHODDEF
6112#endif /* !defined(OS_GETPID_METHODDEF) */
6113
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006114#ifndef OS_GETGROUPS_METHODDEF
6115 #define OS_GETGROUPS_METHODDEF
6116#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6117
6118#ifndef OS_GETPGID_METHODDEF
6119 #define OS_GETPGID_METHODDEF
6120#endif /* !defined(OS_GETPGID_METHODDEF) */
6121
6122#ifndef OS_GETPGRP_METHODDEF
6123 #define OS_GETPGRP_METHODDEF
6124#endif /* !defined(OS_GETPGRP_METHODDEF) */
6125
6126#ifndef OS_SETPGRP_METHODDEF
6127 #define OS_SETPGRP_METHODDEF
6128#endif /* !defined(OS_SETPGRP_METHODDEF) */
6129
6130#ifndef OS_GETPPID_METHODDEF
6131 #define OS_GETPPID_METHODDEF
6132#endif /* !defined(OS_GETPPID_METHODDEF) */
6133
6134#ifndef OS_GETLOGIN_METHODDEF
6135 #define OS_GETLOGIN_METHODDEF
6136#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6137
6138#ifndef OS_GETUID_METHODDEF
6139 #define OS_GETUID_METHODDEF
6140#endif /* !defined(OS_GETUID_METHODDEF) */
6141
6142#ifndef OS_KILL_METHODDEF
6143 #define OS_KILL_METHODDEF
6144#endif /* !defined(OS_KILL_METHODDEF) */
6145
6146#ifndef OS_KILLPG_METHODDEF
6147 #define OS_KILLPG_METHODDEF
6148#endif /* !defined(OS_KILLPG_METHODDEF) */
6149
6150#ifndef OS_PLOCK_METHODDEF
6151 #define OS_PLOCK_METHODDEF
6152#endif /* !defined(OS_PLOCK_METHODDEF) */
6153
6154#ifndef OS_SETUID_METHODDEF
6155 #define OS_SETUID_METHODDEF
6156#endif /* !defined(OS_SETUID_METHODDEF) */
6157
6158#ifndef OS_SETEUID_METHODDEF
6159 #define OS_SETEUID_METHODDEF
6160#endif /* !defined(OS_SETEUID_METHODDEF) */
6161
6162#ifndef OS_SETEGID_METHODDEF
6163 #define OS_SETEGID_METHODDEF
6164#endif /* !defined(OS_SETEGID_METHODDEF) */
6165
6166#ifndef OS_SETREUID_METHODDEF
6167 #define OS_SETREUID_METHODDEF
6168#endif /* !defined(OS_SETREUID_METHODDEF) */
6169
6170#ifndef OS_SETREGID_METHODDEF
6171 #define OS_SETREGID_METHODDEF
6172#endif /* !defined(OS_SETREGID_METHODDEF) */
6173
6174#ifndef OS_SETGID_METHODDEF
6175 #define OS_SETGID_METHODDEF
6176#endif /* !defined(OS_SETGID_METHODDEF) */
6177
6178#ifndef OS_SETGROUPS_METHODDEF
6179 #define OS_SETGROUPS_METHODDEF
6180#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6181
6182#ifndef OS_WAIT3_METHODDEF
6183 #define OS_WAIT3_METHODDEF
6184#endif /* !defined(OS_WAIT3_METHODDEF) */
6185
6186#ifndef OS_WAIT4_METHODDEF
6187 #define OS_WAIT4_METHODDEF
6188#endif /* !defined(OS_WAIT4_METHODDEF) */
6189
6190#ifndef OS_WAITID_METHODDEF
6191 #define OS_WAITID_METHODDEF
6192#endif /* !defined(OS_WAITID_METHODDEF) */
6193
6194#ifndef OS_WAITPID_METHODDEF
6195 #define OS_WAITPID_METHODDEF
6196#endif /* !defined(OS_WAITPID_METHODDEF) */
6197
6198#ifndef OS_WAIT_METHODDEF
6199 #define OS_WAIT_METHODDEF
6200#endif /* !defined(OS_WAIT_METHODDEF) */
6201
6202#ifndef OS_SYMLINK_METHODDEF
6203 #define OS_SYMLINK_METHODDEF
6204#endif /* !defined(OS_SYMLINK_METHODDEF) */
6205
6206#ifndef OS_TIMES_METHODDEF
6207 #define OS_TIMES_METHODDEF
6208#endif /* !defined(OS_TIMES_METHODDEF) */
6209
6210#ifndef OS_GETSID_METHODDEF
6211 #define OS_GETSID_METHODDEF
6212#endif /* !defined(OS_GETSID_METHODDEF) */
6213
6214#ifndef OS_SETSID_METHODDEF
6215 #define OS_SETSID_METHODDEF
6216#endif /* !defined(OS_SETSID_METHODDEF) */
6217
6218#ifndef OS_SETPGID_METHODDEF
6219 #define OS_SETPGID_METHODDEF
6220#endif /* !defined(OS_SETPGID_METHODDEF) */
6221
6222#ifndef OS_TCGETPGRP_METHODDEF
6223 #define OS_TCGETPGRP_METHODDEF
6224#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6225
6226#ifndef OS_TCSETPGRP_METHODDEF
6227 #define OS_TCSETPGRP_METHODDEF
6228#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6229
6230#ifndef OS_LOCKF_METHODDEF
6231 #define OS_LOCKF_METHODDEF
6232#endif /* !defined(OS_LOCKF_METHODDEF) */
6233
6234#ifndef OS_READV_METHODDEF
6235 #define OS_READV_METHODDEF
6236#endif /* !defined(OS_READV_METHODDEF) */
6237
6238#ifndef OS_PREAD_METHODDEF
6239 #define OS_PREAD_METHODDEF
6240#endif /* !defined(OS_PREAD_METHODDEF) */
6241
6242#ifndef OS_PIPE_METHODDEF
6243 #define OS_PIPE_METHODDEF
6244#endif /* !defined(OS_PIPE_METHODDEF) */
6245
6246#ifndef OS_PIPE2_METHODDEF
6247 #define OS_PIPE2_METHODDEF
6248#endif /* !defined(OS_PIPE2_METHODDEF) */
6249
6250#ifndef OS_WRITEV_METHODDEF
6251 #define OS_WRITEV_METHODDEF
6252#endif /* !defined(OS_WRITEV_METHODDEF) */
6253
6254#ifndef OS_PWRITE_METHODDEF
6255 #define OS_PWRITE_METHODDEF
6256#endif /* !defined(OS_PWRITE_METHODDEF) */
6257
6258#ifndef OS_MKFIFO_METHODDEF
6259 #define OS_MKFIFO_METHODDEF
6260#endif /* !defined(OS_MKFIFO_METHODDEF) */
6261
6262#ifndef OS_MKNOD_METHODDEF
6263 #define OS_MKNOD_METHODDEF
6264#endif /* !defined(OS_MKNOD_METHODDEF) */
6265
6266#ifndef OS_MAJOR_METHODDEF
6267 #define OS_MAJOR_METHODDEF
6268#endif /* !defined(OS_MAJOR_METHODDEF) */
6269
6270#ifndef OS_MINOR_METHODDEF
6271 #define OS_MINOR_METHODDEF
6272#endif /* !defined(OS_MINOR_METHODDEF) */
6273
6274#ifndef OS_MAKEDEV_METHODDEF
6275 #define OS_MAKEDEV_METHODDEF
6276#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6277
6278#ifndef OS_FTRUNCATE_METHODDEF
6279 #define OS_FTRUNCATE_METHODDEF
6280#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6281
6282#ifndef OS_TRUNCATE_METHODDEF
6283 #define OS_TRUNCATE_METHODDEF
6284#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6285
6286#ifndef OS_POSIX_FALLOCATE_METHODDEF
6287 #define OS_POSIX_FALLOCATE_METHODDEF
6288#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6289
6290#ifndef OS_POSIX_FADVISE_METHODDEF
6291 #define OS_POSIX_FADVISE_METHODDEF
6292#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6293
6294#ifndef OS_PUTENV_METHODDEF
6295 #define OS_PUTENV_METHODDEF
6296#endif /* !defined(OS_PUTENV_METHODDEF) */
6297
6298#ifndef OS_UNSETENV_METHODDEF
6299 #define OS_UNSETENV_METHODDEF
6300#endif /* !defined(OS_UNSETENV_METHODDEF) */
6301
6302#ifndef OS_WCOREDUMP_METHODDEF
6303 #define OS_WCOREDUMP_METHODDEF
6304#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6305
6306#ifndef OS_WIFCONTINUED_METHODDEF
6307 #define OS_WIFCONTINUED_METHODDEF
6308#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6309
6310#ifndef OS_WIFSTOPPED_METHODDEF
6311 #define OS_WIFSTOPPED_METHODDEF
6312#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6313
6314#ifndef OS_WIFSIGNALED_METHODDEF
6315 #define OS_WIFSIGNALED_METHODDEF
6316#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6317
6318#ifndef OS_WIFEXITED_METHODDEF
6319 #define OS_WIFEXITED_METHODDEF
6320#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6321
6322#ifndef OS_WEXITSTATUS_METHODDEF
6323 #define OS_WEXITSTATUS_METHODDEF
6324#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6325
6326#ifndef OS_WTERMSIG_METHODDEF
6327 #define OS_WTERMSIG_METHODDEF
6328#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6329
6330#ifndef OS_WSTOPSIG_METHODDEF
6331 #define OS_WSTOPSIG_METHODDEF
6332#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6333
6334#ifndef OS_FSTATVFS_METHODDEF
6335 #define OS_FSTATVFS_METHODDEF
6336#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6337
6338#ifndef OS_STATVFS_METHODDEF
6339 #define OS_STATVFS_METHODDEF
6340#endif /* !defined(OS_STATVFS_METHODDEF) */
6341
6342#ifndef OS__GETDISKUSAGE_METHODDEF
6343 #define OS__GETDISKUSAGE_METHODDEF
6344#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6345
6346#ifndef OS_FPATHCONF_METHODDEF
6347 #define OS_FPATHCONF_METHODDEF
6348#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6349
6350#ifndef OS_PATHCONF_METHODDEF
6351 #define OS_PATHCONF_METHODDEF
6352#endif /* !defined(OS_PATHCONF_METHODDEF) */
6353
6354#ifndef OS_CONFSTR_METHODDEF
6355 #define OS_CONFSTR_METHODDEF
6356#endif /* !defined(OS_CONFSTR_METHODDEF) */
6357
6358#ifndef OS_SYSCONF_METHODDEF
6359 #define OS_SYSCONF_METHODDEF
6360#endif /* !defined(OS_SYSCONF_METHODDEF) */
6361
Steve Dowercc16be82016-09-08 10:35:16 -07006362#ifndef OS_STARTFILE_METHODDEF
6363 #define OS_STARTFILE_METHODDEF
6364#endif /* !defined(OS_STARTFILE_METHODDEF) */
6365
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006366#ifndef OS_GETLOADAVG_METHODDEF
6367 #define OS_GETLOADAVG_METHODDEF
6368#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6369
6370#ifndef OS_SETRESUID_METHODDEF
6371 #define OS_SETRESUID_METHODDEF
6372#endif /* !defined(OS_SETRESUID_METHODDEF) */
6373
6374#ifndef OS_SETRESGID_METHODDEF
6375 #define OS_SETRESGID_METHODDEF
6376#endif /* !defined(OS_SETRESGID_METHODDEF) */
6377
6378#ifndef OS_GETRESUID_METHODDEF
6379 #define OS_GETRESUID_METHODDEF
6380#endif /* !defined(OS_GETRESUID_METHODDEF) */
6381
6382#ifndef OS_GETRESGID_METHODDEF
6383 #define OS_GETRESGID_METHODDEF
6384#endif /* !defined(OS_GETRESGID_METHODDEF) */
6385
6386#ifndef OS_GETXATTR_METHODDEF
6387 #define OS_GETXATTR_METHODDEF
6388#endif /* !defined(OS_GETXATTR_METHODDEF) */
6389
6390#ifndef OS_SETXATTR_METHODDEF
6391 #define OS_SETXATTR_METHODDEF
6392#endif /* !defined(OS_SETXATTR_METHODDEF) */
6393
6394#ifndef OS_REMOVEXATTR_METHODDEF
6395 #define OS_REMOVEXATTR_METHODDEF
6396#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6397
6398#ifndef OS_LISTXATTR_METHODDEF
6399 #define OS_LISTXATTR_METHODDEF
6400#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6401
6402#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6403 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6404#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6405
6406#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6407 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6408#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006409
6410#ifndef OS_GETRANDOM_METHODDEF
6411 #define OS_GETRANDOM_METHODDEF
6412#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08006413/*[clinic end generated code: output=6345053cd5992caf input=a9049054013a1b77]*/