blob: d6af15ffc2cac3e2781d11a0e83691e0aa6ad3f9 [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
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001724#if defined(HAVE_POSIX_SPAWN)
1725
1726PyDoc_STRVAR(os_posix_spawn__doc__,
1727"posix_spawn($module, path, argv, env, file_actions=None, /)\n"
1728"--\n"
1729"\n"
1730"Execute the program specified by path in a new process.\n"
1731"\n"
1732" path\n"
1733" Path of executable file.\n"
1734" argv\n"
1735" Tuple or list of strings.\n"
1736" env\n"
1737" Dictionary of strings mapping to strings.\n"
1738" file_actions\n"
1739" FileActions object.");
1740
1741#define OS_POSIX_SPAWN_METHODDEF \
1742 {"posix_spawn", (PyCFunction)os_posix_spawn, METH_FASTCALL, os_posix_spawn__doc__},
1743
1744static PyObject *
1745os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
1746 PyObject *env, PyObject *file_actions);
1747
1748static PyObject *
1749os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1750{
1751 PyObject *return_value = NULL;
1752 path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
1753 PyObject *argv;
1754 PyObject *env;
1755 PyObject *file_actions = Py_None;
1756
1757 if (!_PyArg_ParseStack(args, nargs, "O&OO|O:posix_spawn",
1758 path_converter, &path, &argv, &env, &file_actions)) {
1759 goto exit;
1760 }
1761 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions);
1762
1763exit:
1764 /* Cleanup for path */
1765 path_cleanup(&path);
1766
1767 return return_value;
1768}
1769
1770#endif /* defined(HAVE_POSIX_SPAWN) */
1771
Steve Dowercc16be82016-09-08 10:35:16 -07001772#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001773
1774PyDoc_STRVAR(os_spawnv__doc__,
1775"spawnv($module, mode, path, argv, /)\n"
1776"--\n"
1777"\n"
1778"Execute the program specified by path in a new process.\n"
1779"\n"
1780" mode\n"
1781" Mode of process creation.\n"
1782" path\n"
1783" Path of executable file.\n"
1784" argv\n"
1785" Tuple or list of strings.");
1786
1787#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001788 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001789
1790static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001791os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001792
1793static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001794os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001795{
1796 PyObject *return_value = NULL;
1797 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001798 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001799 PyObject *argv;
1800
Sylvain74453812017-06-10 06:51:48 +02001801 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1802 &mode, path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001803 goto exit;
1804 }
Steve Dowercc16be82016-09-08 10:35:16 -07001805 return_value = os_spawnv_impl(module, mode, &path, argv);
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
Steve Dowercc16be82016-09-08 10:35:16 -07001816#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001817
1818PyDoc_STRVAR(os_spawnve__doc__,
1819"spawnve($module, mode, path, argv, env, /)\n"
1820"--\n"
1821"\n"
1822"Execute the program specified by path in a new process.\n"
1823"\n"
1824" mode\n"
1825" Mode of process creation.\n"
1826" path\n"
1827" Path of executable file.\n"
1828" argv\n"
1829" Tuple or list of strings.\n"
1830" env\n"
1831" Dictionary of strings mapping to strings.");
1832
1833#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001834 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001835
1836static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001837os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001838 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001839
1840static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001841os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001842{
1843 PyObject *return_value = NULL;
1844 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001845 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001846 PyObject *argv;
1847 PyObject *env;
1848
Sylvain74453812017-06-10 06:51:48 +02001849 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1850 &mode, path_converter, &path, &argv, &env)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001851 goto exit;
1852 }
Steve Dowercc16be82016-09-08 10:35:16 -07001853 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001854
1855exit:
1856 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001857 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001858
1859 return return_value;
1860}
1861
Steve Dowercc16be82016-09-08 10:35:16 -07001862#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001863
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001864#if defined(HAVE_FORK)
1865
1866PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001867"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1868" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001869"--\n"
1870"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001871"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001872"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001873" before\n"
1874" A callable to be called in the parent before the fork() syscall.\n"
1875" after_in_child\n"
1876" A callable to be called in the child after fork().\n"
1877" after_in_parent\n"
1878" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001879"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001880"\'before\' callbacks are called in reverse order.\n"
1881"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001882
1883#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001884 {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001885
1886static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001887os_register_at_fork_impl(PyObject *module, PyObject *before,
1888 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001889
1890static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001891os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001892{
1893 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001894 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1895 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1896 PyObject *before = NULL;
1897 PyObject *after_in_child = NULL;
1898 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001899
1900 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001901 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001902 goto exit;
1903 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001904 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001905
1906exit:
1907 return return_value;
1908}
1909
1910#endif /* defined(HAVE_FORK) */
1911
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001912#if defined(HAVE_FORK1)
1913
1914PyDoc_STRVAR(os_fork1__doc__,
1915"fork1($module, /)\n"
1916"--\n"
1917"\n"
1918"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1919"\n"
1920"Return 0 to child process and PID of child to parent process.");
1921
1922#define OS_FORK1_METHODDEF \
1923 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1924
1925static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001926os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001927
1928static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001929os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001930{
1931 return os_fork1_impl(module);
1932}
1933
1934#endif /* defined(HAVE_FORK1) */
1935
1936#if defined(HAVE_FORK)
1937
1938PyDoc_STRVAR(os_fork__doc__,
1939"fork($module, /)\n"
1940"--\n"
1941"\n"
1942"Fork a child process.\n"
1943"\n"
1944"Return 0 to child process and PID of child to parent process.");
1945
1946#define OS_FORK_METHODDEF \
1947 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1948
1949static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001950os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001951
1952static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001953os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001954{
1955 return os_fork_impl(module);
1956}
1957
1958#endif /* defined(HAVE_FORK) */
1959
1960#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1961
1962PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1963"sched_get_priority_max($module, /, policy)\n"
1964"--\n"
1965"\n"
1966"Get the maximum scheduling priority for policy.");
1967
1968#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001969 {"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 +03001970
1971static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001972os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001973
1974static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001975os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001976{
1977 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001978 static const char * const _keywords[] = {"policy", NULL};
1979 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001980 int policy;
1981
Victor Stinner3e1fad62017-01-17 01:29:01 +01001982 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001983 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001985 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001986 return_value = os_sched_get_priority_max_impl(module, policy);
1987
1988exit:
1989 return return_value;
1990}
1991
1992#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1993
1994#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1995
1996PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1997"sched_get_priority_min($module, /, policy)\n"
1998"--\n"
1999"\n"
2000"Get the minimum scheduling priority for policy.");
2001
2002#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002003 {"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 +03002004
2005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002006os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002007
2008static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002009os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002010{
2011 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002012 static const char * const _keywords[] = {"policy", NULL};
2013 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002014 int policy;
2015
Victor Stinner3e1fad62017-01-17 01:29:01 +01002016 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002017 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002018 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002019 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002020 return_value = os_sched_get_priority_min_impl(module, policy);
2021
2022exit:
2023 return return_value;
2024}
2025
2026#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2027
2028#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2029
2030PyDoc_STRVAR(os_sched_getscheduler__doc__,
2031"sched_getscheduler($module, pid, /)\n"
2032"--\n"
2033"\n"
2034"Get the scheduling policy for the process identifiedy by pid.\n"
2035"\n"
2036"Passing 0 for pid returns the scheduling policy for the calling process.");
2037
2038#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002039 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002040
2041static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002042os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002043
2044static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002045os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002046{
2047 PyObject *return_value = NULL;
2048 pid_t pid;
2049
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002050 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002051 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002052 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002053 return_value = os_sched_getscheduler_impl(module, pid);
2054
2055exit:
2056 return return_value;
2057}
2058
2059#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2060
2061#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
2062
2063PyDoc_STRVAR(os_sched_param__doc__,
2064"sched_param(sched_priority)\n"
2065"--\n"
2066"\n"
2067"Current has only one field: sched_priority\");\n"
2068"\n"
2069" sched_priority\n"
2070" A scheduling parameter.");
2071
2072static PyObject *
2073os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2074
2075static PyObject *
2076os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2077{
2078 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002079 static const char * const _keywords[] = {"sched_priority", NULL};
2080 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002081 PyObject *sched_priority;
2082
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002083 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002084 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002087 return_value = os_sched_param_impl(type, sched_priority);
2088
2089exit:
2090 return return_value;
2091}
2092
2093#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2094
2095#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2096
2097PyDoc_STRVAR(os_sched_setscheduler__doc__,
2098"sched_setscheduler($module, pid, policy, param, /)\n"
2099"--\n"
2100"\n"
2101"Set the scheduling policy for the process identified by pid.\n"
2102"\n"
2103"If pid is 0, the calling process is changed.\n"
2104"param is an instance of sched_param.");
2105
2106#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002107 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002108
2109static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002110os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002111 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002112
2113static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002114os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002115{
2116 PyObject *return_value = NULL;
2117 pid_t pid;
2118 int policy;
2119 struct sched_param param;
2120
Sylvain74453812017-06-10 06:51:48 +02002121 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2122 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002123 goto exit;
2124 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002125 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2126
2127exit:
2128 return return_value;
2129}
2130
2131#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2132
2133#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2134
2135PyDoc_STRVAR(os_sched_getparam__doc__,
2136"sched_getparam($module, pid, /)\n"
2137"--\n"
2138"\n"
2139"Returns scheduling parameters for the process identified by pid.\n"
2140"\n"
2141"If pid is 0, returns parameters for the calling process.\n"
2142"Return value is an instance of sched_param.");
2143
2144#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002145 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002146
2147static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002148os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002149
2150static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002151os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002152{
2153 PyObject *return_value = NULL;
2154 pid_t pid;
2155
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002156 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002157 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002158 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002159 return_value = os_sched_getparam_impl(module, pid);
2160
2161exit:
2162 return return_value;
2163}
2164
2165#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2166
2167#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2168
2169PyDoc_STRVAR(os_sched_setparam__doc__,
2170"sched_setparam($module, pid, param, /)\n"
2171"--\n"
2172"\n"
2173"Set scheduling parameters for the process identified by pid.\n"
2174"\n"
2175"If pid is 0, sets parameters for the calling process.\n"
2176"param should be an instance of sched_param.");
2177
2178#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002179 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002180
2181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002182os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002183 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002184
2185static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002186os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002187{
2188 PyObject *return_value = NULL;
2189 pid_t pid;
2190 struct sched_param param;
2191
Sylvain74453812017-06-10 06:51:48 +02002192 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2193 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002194 goto exit;
2195 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002196 return_value = os_sched_setparam_impl(module, pid, &param);
2197
2198exit:
2199 return return_value;
2200}
2201
2202#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2203
2204#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2205
2206PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2207"sched_rr_get_interval($module, pid, /)\n"
2208"--\n"
2209"\n"
2210"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2211"\n"
2212"Value returned is a float.");
2213
2214#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002215 {"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 +03002216
2217static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002218os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002219
2220static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002221os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002222{
2223 PyObject *return_value = NULL;
2224 pid_t pid;
2225 double _return_value;
2226
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002227 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002228 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002229 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002230 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002231 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002232 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002233 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002234 return_value = PyFloat_FromDouble(_return_value);
2235
2236exit:
2237 return return_value;
2238}
2239
2240#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2241
2242#if defined(HAVE_SCHED_H)
2243
2244PyDoc_STRVAR(os_sched_yield__doc__,
2245"sched_yield($module, /)\n"
2246"--\n"
2247"\n"
2248"Voluntarily relinquish the CPU.");
2249
2250#define OS_SCHED_YIELD_METHODDEF \
2251 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2252
2253static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002254os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002255
2256static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002257os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002258{
2259 return os_sched_yield_impl(module);
2260}
2261
2262#endif /* defined(HAVE_SCHED_H) */
2263
2264#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2265
2266PyDoc_STRVAR(os_sched_setaffinity__doc__,
2267"sched_setaffinity($module, pid, mask, /)\n"
2268"--\n"
2269"\n"
2270"Set the CPU affinity of the process identified by pid to mask.\n"
2271"\n"
2272"mask should be an iterable of integers identifying CPUs.");
2273
2274#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002275 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002276
2277static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002278os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002279
2280static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002281os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002282{
2283 PyObject *return_value = NULL;
2284 pid_t pid;
2285 PyObject *mask;
2286
Sylvain74453812017-06-10 06:51:48 +02002287 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2288 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002289 goto exit;
2290 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002291 return_value = os_sched_setaffinity_impl(module, pid, mask);
2292
2293exit:
2294 return return_value;
2295}
2296
2297#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2298
2299#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2300
2301PyDoc_STRVAR(os_sched_getaffinity__doc__,
2302"sched_getaffinity($module, pid, /)\n"
2303"--\n"
2304"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002305"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002306"\n"
2307"The affinity is returned as a set of CPU identifiers.");
2308
2309#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002310 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002311
2312static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002313os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002314
2315static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002316os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002317{
2318 PyObject *return_value = NULL;
2319 pid_t pid;
2320
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002321 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002322 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002323 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002324 return_value = os_sched_getaffinity_impl(module, pid);
2325
2326exit:
2327 return return_value;
2328}
2329
2330#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2331
2332#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2333
2334PyDoc_STRVAR(os_openpty__doc__,
2335"openpty($module, /)\n"
2336"--\n"
2337"\n"
2338"Open a pseudo-terminal.\n"
2339"\n"
2340"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2341"for both the master and slave ends.");
2342
2343#define OS_OPENPTY_METHODDEF \
2344 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2345
2346static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002347os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002348
2349static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002350os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002351{
2352 return os_openpty_impl(module);
2353}
2354
2355#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2356
2357#if defined(HAVE_FORKPTY)
2358
2359PyDoc_STRVAR(os_forkpty__doc__,
2360"forkpty($module, /)\n"
2361"--\n"
2362"\n"
2363"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2364"\n"
2365"Returns a tuple of (pid, master_fd).\n"
2366"Like fork(), return pid of 0 to the child process,\n"
2367"and pid of child to the parent process.\n"
2368"To both, return fd of newly opened pseudo-terminal.");
2369
2370#define OS_FORKPTY_METHODDEF \
2371 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2372
2373static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002374os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002375
2376static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002377os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002378{
2379 return os_forkpty_impl(module);
2380}
2381
2382#endif /* defined(HAVE_FORKPTY) */
2383
2384#if defined(HAVE_GETEGID)
2385
2386PyDoc_STRVAR(os_getegid__doc__,
2387"getegid($module, /)\n"
2388"--\n"
2389"\n"
2390"Return the current process\'s effective group id.");
2391
2392#define OS_GETEGID_METHODDEF \
2393 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2394
2395static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002396os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002397
2398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002399os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002400{
2401 return os_getegid_impl(module);
2402}
2403
2404#endif /* defined(HAVE_GETEGID) */
2405
2406#if defined(HAVE_GETEUID)
2407
2408PyDoc_STRVAR(os_geteuid__doc__,
2409"geteuid($module, /)\n"
2410"--\n"
2411"\n"
2412"Return the current process\'s effective user id.");
2413
2414#define OS_GETEUID_METHODDEF \
2415 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2416
2417static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002418os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002419
2420static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002421os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002422{
2423 return os_geteuid_impl(module);
2424}
2425
2426#endif /* defined(HAVE_GETEUID) */
2427
2428#if defined(HAVE_GETGID)
2429
2430PyDoc_STRVAR(os_getgid__doc__,
2431"getgid($module, /)\n"
2432"--\n"
2433"\n"
2434"Return the current process\'s group id.");
2435
2436#define OS_GETGID_METHODDEF \
2437 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2438
2439static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002440os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002441
2442static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002443os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002444{
2445 return os_getgid_impl(module);
2446}
2447
2448#endif /* defined(HAVE_GETGID) */
2449
Berker Peksag39404992016-09-15 20:45:16 +03002450#if defined(HAVE_GETPID)
2451
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002452PyDoc_STRVAR(os_getpid__doc__,
2453"getpid($module, /)\n"
2454"--\n"
2455"\n"
2456"Return the current process id.");
2457
2458#define OS_GETPID_METHODDEF \
2459 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2460
2461static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002462os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002463
2464static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002465os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002466{
2467 return os_getpid_impl(module);
2468}
2469
Berker Peksag39404992016-09-15 20:45:16 +03002470#endif /* defined(HAVE_GETPID) */
2471
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002472#if defined(HAVE_GETGROUPS)
2473
2474PyDoc_STRVAR(os_getgroups__doc__,
2475"getgroups($module, /)\n"
2476"--\n"
2477"\n"
2478"Return list of supplemental group IDs for the process.");
2479
2480#define OS_GETGROUPS_METHODDEF \
2481 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2482
2483static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002484os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002485
2486static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002487os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002488{
2489 return os_getgroups_impl(module);
2490}
2491
2492#endif /* defined(HAVE_GETGROUPS) */
2493
2494#if defined(HAVE_GETPGID)
2495
2496PyDoc_STRVAR(os_getpgid__doc__,
2497"getpgid($module, /, pid)\n"
2498"--\n"
2499"\n"
2500"Call the system call getpgid(), and return the result.");
2501
2502#define OS_GETPGID_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002503 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002504
2505static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002506os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002507
2508static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002509os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002510{
2511 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002512 static const char * const _keywords[] = {"pid", NULL};
2513 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002514 pid_t pid;
2515
Victor Stinner3e1fad62017-01-17 01:29:01 +01002516 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002517 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002518 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002519 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002520 return_value = os_getpgid_impl(module, pid);
2521
2522exit:
2523 return return_value;
2524}
2525
2526#endif /* defined(HAVE_GETPGID) */
2527
2528#if defined(HAVE_GETPGRP)
2529
2530PyDoc_STRVAR(os_getpgrp__doc__,
2531"getpgrp($module, /)\n"
2532"--\n"
2533"\n"
2534"Return the current process group id.");
2535
2536#define OS_GETPGRP_METHODDEF \
2537 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2538
2539static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002540os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002541
2542static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002543os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002544{
2545 return os_getpgrp_impl(module);
2546}
2547
2548#endif /* defined(HAVE_GETPGRP) */
2549
2550#if defined(HAVE_SETPGRP)
2551
2552PyDoc_STRVAR(os_setpgrp__doc__,
2553"setpgrp($module, /)\n"
2554"--\n"
2555"\n"
2556"Make the current process the leader of its process group.");
2557
2558#define OS_SETPGRP_METHODDEF \
2559 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2560
2561static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002562os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002563
2564static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002565os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002566{
2567 return os_setpgrp_impl(module);
2568}
2569
2570#endif /* defined(HAVE_SETPGRP) */
2571
2572#if defined(HAVE_GETPPID)
2573
2574PyDoc_STRVAR(os_getppid__doc__,
2575"getppid($module, /)\n"
2576"--\n"
2577"\n"
2578"Return the parent\'s process id.\n"
2579"\n"
2580"If the parent process has already exited, Windows machines will still\n"
2581"return its id; others systems will return the id of the \'init\' process (1).");
2582
2583#define OS_GETPPID_METHODDEF \
2584 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2585
2586static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002587os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002588
2589static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002590os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002591{
2592 return os_getppid_impl(module);
2593}
2594
2595#endif /* defined(HAVE_GETPPID) */
2596
2597#if defined(HAVE_GETLOGIN)
2598
2599PyDoc_STRVAR(os_getlogin__doc__,
2600"getlogin($module, /)\n"
2601"--\n"
2602"\n"
2603"Return the actual login name.");
2604
2605#define OS_GETLOGIN_METHODDEF \
2606 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2607
2608static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002609os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002610
2611static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002612os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002613{
2614 return os_getlogin_impl(module);
2615}
2616
2617#endif /* defined(HAVE_GETLOGIN) */
2618
2619#if defined(HAVE_GETUID)
2620
2621PyDoc_STRVAR(os_getuid__doc__,
2622"getuid($module, /)\n"
2623"--\n"
2624"\n"
2625"Return the current process\'s user id.");
2626
2627#define OS_GETUID_METHODDEF \
2628 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2629
2630static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002631os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002632
2633static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002634os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002635{
2636 return os_getuid_impl(module);
2637}
2638
2639#endif /* defined(HAVE_GETUID) */
2640
2641#if defined(HAVE_KILL)
2642
2643PyDoc_STRVAR(os_kill__doc__,
2644"kill($module, pid, signal, /)\n"
2645"--\n"
2646"\n"
2647"Kill a process with a signal.");
2648
2649#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002650 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002651
2652static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002653os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002654
2655static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002656os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002657{
2658 PyObject *return_value = NULL;
2659 pid_t pid;
2660 Py_ssize_t signal;
2661
Sylvain74453812017-06-10 06:51:48 +02002662 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2663 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002664 goto exit;
2665 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002666 return_value = os_kill_impl(module, pid, signal);
2667
2668exit:
2669 return return_value;
2670}
2671
2672#endif /* defined(HAVE_KILL) */
2673
2674#if defined(HAVE_KILLPG)
2675
2676PyDoc_STRVAR(os_killpg__doc__,
2677"killpg($module, pgid, signal, /)\n"
2678"--\n"
2679"\n"
2680"Kill a process group with a signal.");
2681
2682#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002683 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002684
2685static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002686os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002687
2688static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002689os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002690{
2691 PyObject *return_value = NULL;
2692 pid_t pgid;
2693 int signal;
2694
Sylvain74453812017-06-10 06:51:48 +02002695 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2696 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002697 goto exit;
2698 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002699 return_value = os_killpg_impl(module, pgid, signal);
2700
2701exit:
2702 return return_value;
2703}
2704
2705#endif /* defined(HAVE_KILLPG) */
2706
2707#if defined(HAVE_PLOCK)
2708
2709PyDoc_STRVAR(os_plock__doc__,
2710"plock($module, op, /)\n"
2711"--\n"
2712"\n"
2713"Lock program segments into memory.\");");
2714
2715#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002716 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002717
2718static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002719os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002720
2721static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002722os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002723{
2724 PyObject *return_value = NULL;
2725 int op;
2726
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002727 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002728 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002729 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002730 return_value = os_plock_impl(module, op);
2731
2732exit:
2733 return return_value;
2734}
2735
2736#endif /* defined(HAVE_PLOCK) */
2737
2738#if defined(HAVE_SETUID)
2739
2740PyDoc_STRVAR(os_setuid__doc__,
2741"setuid($module, uid, /)\n"
2742"--\n"
2743"\n"
2744"Set the current process\'s user id.");
2745
2746#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002747 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002748
2749static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002750os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002751
2752static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002753os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002754{
2755 PyObject *return_value = NULL;
2756 uid_t uid;
2757
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002758 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002759 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002760 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002761 return_value = os_setuid_impl(module, uid);
2762
2763exit:
2764 return return_value;
2765}
2766
2767#endif /* defined(HAVE_SETUID) */
2768
2769#if defined(HAVE_SETEUID)
2770
2771PyDoc_STRVAR(os_seteuid__doc__,
2772"seteuid($module, euid, /)\n"
2773"--\n"
2774"\n"
2775"Set the current process\'s effective user id.");
2776
2777#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002778 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002779
2780static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002781os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002782
2783static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002784os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002785{
2786 PyObject *return_value = NULL;
2787 uid_t euid;
2788
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002789 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002790 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002791 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002792 return_value = os_seteuid_impl(module, euid);
2793
2794exit:
2795 return return_value;
2796}
2797
2798#endif /* defined(HAVE_SETEUID) */
2799
2800#if defined(HAVE_SETEGID)
2801
2802PyDoc_STRVAR(os_setegid__doc__,
2803"setegid($module, egid, /)\n"
2804"--\n"
2805"\n"
2806"Set the current process\'s effective group id.");
2807
2808#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002809 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002810
2811static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002812os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002813
2814static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002815os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002816{
2817 PyObject *return_value = NULL;
2818 gid_t egid;
2819
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002820 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002821 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002822 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002823 return_value = os_setegid_impl(module, egid);
2824
2825exit:
2826 return return_value;
2827}
2828
2829#endif /* defined(HAVE_SETEGID) */
2830
2831#if defined(HAVE_SETREUID)
2832
2833PyDoc_STRVAR(os_setreuid__doc__,
2834"setreuid($module, ruid, euid, /)\n"
2835"--\n"
2836"\n"
2837"Set the current process\'s real and effective user ids.");
2838
2839#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002840 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002841
2842static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002843os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002844
2845static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002846os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002847{
2848 PyObject *return_value = NULL;
2849 uid_t ruid;
2850 uid_t euid;
2851
Sylvain74453812017-06-10 06:51:48 +02002852 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2853 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002854 goto exit;
2855 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002856 return_value = os_setreuid_impl(module, ruid, euid);
2857
2858exit:
2859 return return_value;
2860}
2861
2862#endif /* defined(HAVE_SETREUID) */
2863
2864#if defined(HAVE_SETREGID)
2865
2866PyDoc_STRVAR(os_setregid__doc__,
2867"setregid($module, rgid, egid, /)\n"
2868"--\n"
2869"\n"
2870"Set the current process\'s real and effective group ids.");
2871
2872#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002873 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002874
2875static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002876os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002877
2878static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002879os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002880{
2881 PyObject *return_value = NULL;
2882 gid_t rgid;
2883 gid_t egid;
2884
Sylvain74453812017-06-10 06:51:48 +02002885 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2886 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002887 goto exit;
2888 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002889 return_value = os_setregid_impl(module, rgid, egid);
2890
2891exit:
2892 return return_value;
2893}
2894
2895#endif /* defined(HAVE_SETREGID) */
2896
2897#if defined(HAVE_SETGID)
2898
2899PyDoc_STRVAR(os_setgid__doc__,
2900"setgid($module, gid, /)\n"
2901"--\n"
2902"\n"
2903"Set the current process\'s group id.");
2904
2905#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002906 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002907
2908static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002909os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002910
2911static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002912os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002913{
2914 PyObject *return_value = NULL;
2915 gid_t gid;
2916
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002917 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002918 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002919 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002920 return_value = os_setgid_impl(module, gid);
2921
2922exit:
2923 return return_value;
2924}
2925
2926#endif /* defined(HAVE_SETGID) */
2927
2928#if defined(HAVE_SETGROUPS)
2929
2930PyDoc_STRVAR(os_setgroups__doc__,
2931"setgroups($module, groups, /)\n"
2932"--\n"
2933"\n"
2934"Set the groups of the current process to list.");
2935
2936#define OS_SETGROUPS_METHODDEF \
2937 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2938
2939#endif /* defined(HAVE_SETGROUPS) */
2940
2941#if defined(HAVE_WAIT3)
2942
2943PyDoc_STRVAR(os_wait3__doc__,
2944"wait3($module, /, options)\n"
2945"--\n"
2946"\n"
2947"Wait for completion of a child process.\n"
2948"\n"
2949"Returns a tuple of information about the child process:\n"
2950" (pid, status, rusage)");
2951
2952#define OS_WAIT3_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002953 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002954
2955static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002956os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002957
2958static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002959os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002960{
2961 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002962 static const char * const _keywords[] = {"options", NULL};
2963 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002964 int options;
2965
Victor Stinner3e1fad62017-01-17 01:29:01 +01002966 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002967 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002968 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002969 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002970 return_value = os_wait3_impl(module, options);
2971
2972exit:
2973 return return_value;
2974}
2975
2976#endif /* defined(HAVE_WAIT3) */
2977
2978#if defined(HAVE_WAIT4)
2979
2980PyDoc_STRVAR(os_wait4__doc__,
2981"wait4($module, /, pid, options)\n"
2982"--\n"
2983"\n"
2984"Wait for completion of a specific child process.\n"
2985"\n"
2986"Returns a tuple of information about the child process:\n"
2987" (pid, status, rusage)");
2988
2989#define OS_WAIT4_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002990 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002991
2992static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002993os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002994
2995static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002996os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002997{
2998 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002999 static const char * const _keywords[] = {"pid", "options", NULL};
3000 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003001 pid_t pid;
3002 int options;
3003
Victor Stinner3e1fad62017-01-17 01:29:01 +01003004 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003005 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003006 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003007 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003008 return_value = os_wait4_impl(module, pid, options);
3009
3010exit:
3011 return return_value;
3012}
3013
3014#endif /* defined(HAVE_WAIT4) */
3015
3016#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3017
3018PyDoc_STRVAR(os_waitid__doc__,
3019"waitid($module, idtype, id, options, /)\n"
3020"--\n"
3021"\n"
3022"Returns the result of waiting for a process or processes.\n"
3023"\n"
3024" idtype\n"
3025" Must be one of be P_PID, P_PGID or P_ALL.\n"
3026" id\n"
3027" The id to wait on.\n"
3028" options\n"
3029" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3030" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3031"\n"
3032"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3033"no children in a waitable state.");
3034
3035#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003036 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003037
3038static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003039os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003040
3041static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003042os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003043{
3044 PyObject *return_value = NULL;
3045 idtype_t idtype;
3046 id_t id;
3047 int options;
3048
Sylvain74453812017-06-10 06:51:48 +02003049 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3050 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003051 goto exit;
3052 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003053 return_value = os_waitid_impl(module, idtype, id, options);
3054
3055exit:
3056 return return_value;
3057}
3058
3059#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3060
3061#if defined(HAVE_WAITPID)
3062
3063PyDoc_STRVAR(os_waitpid__doc__,
3064"waitpid($module, pid, options, /)\n"
3065"--\n"
3066"\n"
3067"Wait for completion of a given child process.\n"
3068"\n"
3069"Returns a tuple of information regarding the child process:\n"
3070" (pid, status)\n"
3071"\n"
3072"The options argument is ignored on Windows.");
3073
3074#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003075 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003076
3077static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003078os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003079
3080static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003081os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003082{
3083 PyObject *return_value = NULL;
3084 pid_t pid;
3085 int options;
3086
Sylvain74453812017-06-10 06:51:48 +02003087 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3088 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003089 goto exit;
3090 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003091 return_value = os_waitpid_impl(module, pid, options);
3092
3093exit:
3094 return return_value;
3095}
3096
3097#endif /* defined(HAVE_WAITPID) */
3098
3099#if defined(HAVE_CWAIT)
3100
3101PyDoc_STRVAR(os_waitpid__doc__,
3102"waitpid($module, pid, options, /)\n"
3103"--\n"
3104"\n"
3105"Wait for completion of a given process.\n"
3106"\n"
3107"Returns a tuple of information regarding the process:\n"
3108" (pid, status << 8)\n"
3109"\n"
3110"The options argument is ignored on Windows.");
3111
3112#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003113 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003114
3115static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003116os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003117
3118static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003119os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003120{
3121 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003122 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003123 int options;
3124
Sylvain74453812017-06-10 06:51:48 +02003125 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3126 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003127 goto exit;
3128 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003129 return_value = os_waitpid_impl(module, pid, options);
3130
3131exit:
3132 return return_value;
3133}
3134
3135#endif /* defined(HAVE_CWAIT) */
3136
3137#if defined(HAVE_WAIT)
3138
3139PyDoc_STRVAR(os_wait__doc__,
3140"wait($module, /)\n"
3141"--\n"
3142"\n"
3143"Wait for completion of a child process.\n"
3144"\n"
3145"Returns a tuple of information about the child process:\n"
3146" (pid, status)");
3147
3148#define OS_WAIT_METHODDEF \
3149 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3150
3151static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003152os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003153
3154static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003155os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003156{
3157 return os_wait_impl(module);
3158}
3159
3160#endif /* defined(HAVE_WAIT) */
3161
3162#if defined(HAVE_SYMLINK)
3163
3164PyDoc_STRVAR(os_symlink__doc__,
3165"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3166"--\n"
3167"\n"
3168"Create a symbolic link pointing to src named dst.\n"
3169"\n"
3170"target_is_directory is required on Windows if the target is to be\n"
3171" interpreted as a directory. (On Windows, symlink requires\n"
3172" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3173" target_is_directory is ignored on non-Windows platforms.\n"
3174"\n"
3175"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3176" and path should be relative; path will then be relative to that directory.\n"
3177"dir_fd may not be implemented on your platform.\n"
3178" If it is unavailable, using it will raise a NotImplementedError.");
3179
3180#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003181 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003182
3183static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003184os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003185 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003186
3187static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003188os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003189{
3190 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003191 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3192 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003193 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3194 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3195 int target_is_directory = 0;
3196 int dir_fd = DEFAULT_DIR_FD;
3197
Victor Stinner3e1fad62017-01-17 01:29:01 +01003198 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003199 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003200 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003201 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003202 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3203
3204exit:
3205 /* Cleanup for src */
3206 path_cleanup(&src);
3207 /* Cleanup for dst */
3208 path_cleanup(&dst);
3209
3210 return return_value;
3211}
3212
3213#endif /* defined(HAVE_SYMLINK) */
3214
3215#if defined(HAVE_TIMES)
3216
3217PyDoc_STRVAR(os_times__doc__,
3218"times($module, /)\n"
3219"--\n"
3220"\n"
3221"Return a collection containing process timing information.\n"
3222"\n"
3223"The object returned behaves like a named tuple with these fields:\n"
3224" (utime, stime, cutime, cstime, elapsed_time)\n"
3225"All fields are floating point numbers.");
3226
3227#define OS_TIMES_METHODDEF \
3228 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3229
3230static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003231os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003232
3233static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003234os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003235{
3236 return os_times_impl(module);
3237}
3238
3239#endif /* defined(HAVE_TIMES) */
3240
3241#if defined(HAVE_GETSID)
3242
3243PyDoc_STRVAR(os_getsid__doc__,
3244"getsid($module, pid, /)\n"
3245"--\n"
3246"\n"
3247"Call the system call getsid(pid) and return the result.");
3248
3249#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003250 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003251
3252static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003253os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003254
3255static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003256os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003257{
3258 PyObject *return_value = NULL;
3259 pid_t pid;
3260
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003261 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003262 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003263 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003264 return_value = os_getsid_impl(module, pid);
3265
3266exit:
3267 return return_value;
3268}
3269
3270#endif /* defined(HAVE_GETSID) */
3271
3272#if defined(HAVE_SETSID)
3273
3274PyDoc_STRVAR(os_setsid__doc__,
3275"setsid($module, /)\n"
3276"--\n"
3277"\n"
3278"Call the system call setsid().");
3279
3280#define OS_SETSID_METHODDEF \
3281 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3282
3283static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003284os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003285
3286static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003287os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003288{
3289 return os_setsid_impl(module);
3290}
3291
3292#endif /* defined(HAVE_SETSID) */
3293
3294#if defined(HAVE_SETPGID)
3295
3296PyDoc_STRVAR(os_setpgid__doc__,
3297"setpgid($module, pid, pgrp, /)\n"
3298"--\n"
3299"\n"
3300"Call the system call setpgid(pid, pgrp).");
3301
3302#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003303 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003304
3305static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003306os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003307
3308static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003309os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003310{
3311 PyObject *return_value = NULL;
3312 pid_t pid;
3313 pid_t pgrp;
3314
Sylvain74453812017-06-10 06:51:48 +02003315 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3316 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003317 goto exit;
3318 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003319 return_value = os_setpgid_impl(module, pid, pgrp);
3320
3321exit:
3322 return return_value;
3323}
3324
3325#endif /* defined(HAVE_SETPGID) */
3326
3327#if defined(HAVE_TCGETPGRP)
3328
3329PyDoc_STRVAR(os_tcgetpgrp__doc__,
3330"tcgetpgrp($module, fd, /)\n"
3331"--\n"
3332"\n"
3333"Return the process group associated with the terminal specified by fd.");
3334
3335#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003336 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003337
3338static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003339os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003340
3341static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003342os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003343{
3344 PyObject *return_value = NULL;
3345 int fd;
3346
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003347 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003348 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003349 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003350 return_value = os_tcgetpgrp_impl(module, fd);
3351
3352exit:
3353 return return_value;
3354}
3355
3356#endif /* defined(HAVE_TCGETPGRP) */
3357
3358#if defined(HAVE_TCSETPGRP)
3359
3360PyDoc_STRVAR(os_tcsetpgrp__doc__,
3361"tcsetpgrp($module, fd, pgid, /)\n"
3362"--\n"
3363"\n"
3364"Set the process group associated with the terminal specified by fd.");
3365
3366#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003367 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003368
3369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003370os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003371
3372static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003373os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003374{
3375 PyObject *return_value = NULL;
3376 int fd;
3377 pid_t pgid;
3378
Sylvain74453812017-06-10 06:51:48 +02003379 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3380 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003381 goto exit;
3382 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003383 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3384
3385exit:
3386 return return_value;
3387}
3388
3389#endif /* defined(HAVE_TCSETPGRP) */
3390
3391PyDoc_STRVAR(os_open__doc__,
3392"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3393"--\n"
3394"\n"
3395"Open a file for low level IO. Returns a file descriptor (integer).\n"
3396"\n"
3397"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3398" and path should be relative; path will then be relative to that directory.\n"
3399"dir_fd may not be implemented on your platform.\n"
3400" If it is unavailable, using it will raise a NotImplementedError.");
3401
3402#define OS_OPEN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003403 {"open", (PyCFunction)os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003404
3405static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003406os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003407
3408static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003409os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003410{
3411 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003412 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3413 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003414 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3415 int flags;
3416 int mode = 511;
3417 int dir_fd = DEFAULT_DIR_FD;
3418 int _return_value;
3419
Victor Stinner3e1fad62017-01-17 01:29:01 +01003420 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003421 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003424 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003425 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003426 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003427 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003428 return_value = PyLong_FromLong((long)_return_value);
3429
3430exit:
3431 /* Cleanup for path */
3432 path_cleanup(&path);
3433
3434 return return_value;
3435}
3436
3437PyDoc_STRVAR(os_close__doc__,
3438"close($module, /, fd)\n"
3439"--\n"
3440"\n"
3441"Close a file descriptor.");
3442
3443#define OS_CLOSE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003444 {"close", (PyCFunction)os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003445
3446static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003447os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003448
3449static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003450os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003451{
3452 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003453 static const char * const _keywords[] = {"fd", NULL};
3454 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003455 int fd;
3456
Victor Stinner3e1fad62017-01-17 01:29:01 +01003457 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003458 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003459 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003460 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003461 return_value = os_close_impl(module, fd);
3462
3463exit:
3464 return return_value;
3465}
3466
3467PyDoc_STRVAR(os_closerange__doc__,
3468"closerange($module, fd_low, fd_high, /)\n"
3469"--\n"
3470"\n"
3471"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3472
3473#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003474 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003475
3476static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003477os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003478
3479static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003480os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003481{
3482 PyObject *return_value = NULL;
3483 int fd_low;
3484 int fd_high;
3485
Sylvain74453812017-06-10 06:51:48 +02003486 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3487 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003488 goto exit;
3489 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003490 return_value = os_closerange_impl(module, fd_low, fd_high);
3491
3492exit:
3493 return return_value;
3494}
3495
3496PyDoc_STRVAR(os_dup__doc__,
3497"dup($module, fd, /)\n"
3498"--\n"
3499"\n"
3500"Return a duplicate of a file descriptor.");
3501
3502#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003503 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003504
3505static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003506os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003507
3508static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003509os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003510{
3511 PyObject *return_value = NULL;
3512 int fd;
3513 int _return_value;
3514
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003515 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003516 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003517 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003518 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003519 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003520 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003521 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003522 return_value = PyLong_FromLong((long)_return_value);
3523
3524exit:
3525 return return_value;
3526}
3527
3528PyDoc_STRVAR(os_dup2__doc__,
3529"dup2($module, /, fd, fd2, inheritable=True)\n"
3530"--\n"
3531"\n"
3532"Duplicate file descriptor.");
3533
3534#define OS_DUP2_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003535 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003536
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003537static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003538os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003539
3540static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003541os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003542{
3543 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003544 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3545 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003546 int fd;
3547 int fd2;
3548 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003549 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003550
Victor Stinner3e1fad62017-01-17 01:29:01 +01003551 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003552 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003553 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003554 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003555 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3556 if ((_return_value == -1) && PyErr_Occurred()) {
3557 goto exit;
3558 }
3559 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003560
3561exit:
3562 return return_value;
3563}
3564
3565#if defined(HAVE_LOCKF)
3566
3567PyDoc_STRVAR(os_lockf__doc__,
3568"lockf($module, fd, command, length, /)\n"
3569"--\n"
3570"\n"
3571"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3572"\n"
3573" fd\n"
3574" An open file descriptor.\n"
3575" command\n"
3576" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3577" length\n"
3578" The number of bytes to lock, starting at the current position.");
3579
3580#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003581 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003582
3583static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003584os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003585
3586static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003587os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003588{
3589 PyObject *return_value = NULL;
3590 int fd;
3591 int command;
3592 Py_off_t length;
3593
Sylvain74453812017-06-10 06:51:48 +02003594 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3595 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003596 goto exit;
3597 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003598 return_value = os_lockf_impl(module, fd, command, length);
3599
3600exit:
3601 return return_value;
3602}
3603
3604#endif /* defined(HAVE_LOCKF) */
3605
3606PyDoc_STRVAR(os_lseek__doc__,
3607"lseek($module, fd, position, how, /)\n"
3608"--\n"
3609"\n"
3610"Set the position of a file descriptor. Return the new position.\n"
3611"\n"
3612"Return the new cursor position in number of bytes\n"
3613"relative to the beginning of the file.");
3614
3615#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003616 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003617
3618static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003619os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003620
3621static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003622os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003623{
3624 PyObject *return_value = NULL;
3625 int fd;
3626 Py_off_t position;
3627 int how;
3628 Py_off_t _return_value;
3629
Sylvain74453812017-06-10 06:51:48 +02003630 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3631 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003632 goto exit;
3633 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003634 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003635 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003636 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003637 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003638 return_value = PyLong_FromPy_off_t(_return_value);
3639
3640exit:
3641 return return_value;
3642}
3643
3644PyDoc_STRVAR(os_read__doc__,
3645"read($module, fd, length, /)\n"
3646"--\n"
3647"\n"
3648"Read from a file descriptor. Returns a bytes object.");
3649
3650#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003651 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003652
3653static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003654os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003655
3656static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003657os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003658{
3659 PyObject *return_value = NULL;
3660 int fd;
3661 Py_ssize_t length;
3662
Sylvain74453812017-06-10 06:51:48 +02003663 if (!_PyArg_ParseStack(args, nargs, "in:read",
3664 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003665 goto exit;
3666 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003667 return_value = os_read_impl(module, fd, length);
3668
3669exit:
3670 return return_value;
3671}
3672
3673#if defined(HAVE_READV)
3674
3675PyDoc_STRVAR(os_readv__doc__,
3676"readv($module, fd, buffers, /)\n"
3677"--\n"
3678"\n"
3679"Read from a file descriptor fd into an iterable of buffers.\n"
3680"\n"
3681"The buffers should be mutable buffers accepting bytes.\n"
3682"readv will transfer data into each buffer until it is full\n"
3683"and then move on to the next buffer in the sequence to hold\n"
3684"the rest of the data.\n"
3685"\n"
3686"readv returns the total number of bytes read,\n"
3687"which may be less than the total capacity of all the buffers.");
3688
3689#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003690 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003691
3692static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003693os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003694
3695static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003696os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003697{
3698 PyObject *return_value = NULL;
3699 int fd;
3700 PyObject *buffers;
3701 Py_ssize_t _return_value;
3702
Sylvain74453812017-06-10 06:51:48 +02003703 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3704 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003705 goto exit;
3706 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003707 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003708 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003709 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003710 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003711 return_value = PyLong_FromSsize_t(_return_value);
3712
3713exit:
3714 return return_value;
3715}
3716
3717#endif /* defined(HAVE_READV) */
3718
3719#if defined(HAVE_PREAD)
3720
3721PyDoc_STRVAR(os_pread__doc__,
3722"pread($module, fd, length, offset, /)\n"
3723"--\n"
3724"\n"
3725"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3726"\n"
3727"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3728"the beginning of the file. The file offset remains unchanged.");
3729
3730#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003731 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003732
3733static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003734os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003735
3736static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003737os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003738{
3739 PyObject *return_value = NULL;
3740 int fd;
3741 int length;
3742 Py_off_t offset;
3743
Sylvain74453812017-06-10 06:51:48 +02003744 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3745 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003746 goto exit;
3747 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003748 return_value = os_pread_impl(module, fd, length, offset);
3749
3750exit:
3751 return return_value;
3752}
3753
3754#endif /* defined(HAVE_PREAD) */
3755
Pablo Galindo4defba32018-01-27 16:16:37 +00003756#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3757
3758PyDoc_STRVAR(os_preadv__doc__,
3759"preadv($module, fd, buffers, offset, flags=0, /)\n"
3760"--\n"
3761"\n"
3762"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3763"\n"
3764"Combines the functionality of readv() and pread(). As readv(), it will\n"
3765"transfer data into each buffer until it is full and then move on to the next\n"
3766"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3767"specifies the file offset at which the input operation is to be performed. It\n"
3768"will return the total number of bytes read (which can be less than the total\n"
3769"capacity of all the objects).\n"
3770"\n"
3771"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3772"\n"
3773"- RWF_HIPRI\n"
3774"- RWF_NOWAIT\n"
3775"\n"
3776"Using non-zero flags requires Linux 4.6 or newer.");
3777
3778#define OS_PREADV_METHODDEF \
3779 {"preadv", (PyCFunction)os_preadv, METH_FASTCALL, os_preadv__doc__},
3780
3781static Py_ssize_t
3782os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
3783 int flags);
3784
3785static PyObject *
3786os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3787{
3788 PyObject *return_value = NULL;
3789 int fd;
3790 PyObject *buffers;
3791 Py_off_t offset;
3792 int flags = 0;
3793 Py_ssize_t _return_value;
3794
3795 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",
3796 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
3797 goto exit;
3798 }
3799 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
3800 if ((_return_value == -1) && PyErr_Occurred()) {
3801 goto exit;
3802 }
3803 return_value = PyLong_FromSsize_t(_return_value);
3804
3805exit:
3806 return return_value;
3807}
3808
3809#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
3810
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003811PyDoc_STRVAR(os_write__doc__,
3812"write($module, fd, data, /)\n"
3813"--\n"
3814"\n"
3815"Write a bytes object to a file descriptor.");
3816
3817#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003818 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003819
3820static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003821os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003822
3823static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003824os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003825{
3826 PyObject *return_value = NULL;
3827 int fd;
3828 Py_buffer data = {NULL, NULL};
3829 Py_ssize_t _return_value;
3830
Sylvain74453812017-06-10 06:51:48 +02003831 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3832 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003833 goto exit;
3834 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003835 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003836 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003837 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003838 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003839 return_value = PyLong_FromSsize_t(_return_value);
3840
3841exit:
3842 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003843 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003844 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003845 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003846
3847 return return_value;
3848}
3849
3850PyDoc_STRVAR(os_fstat__doc__,
3851"fstat($module, /, fd)\n"
3852"--\n"
3853"\n"
3854"Perform a stat system call on the given file descriptor.\n"
3855"\n"
3856"Like stat(), but for an open file descriptor.\n"
3857"Equivalent to os.stat(fd).");
3858
3859#define OS_FSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003860 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003861
3862static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003863os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003864
3865static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003866os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003867{
3868 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003869 static const char * const _keywords[] = {"fd", NULL};
3870 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003871 int fd;
3872
Victor Stinner3e1fad62017-01-17 01:29:01 +01003873 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003874 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003875 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003876 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003877 return_value = os_fstat_impl(module, fd);
3878
3879exit:
3880 return return_value;
3881}
3882
3883PyDoc_STRVAR(os_isatty__doc__,
3884"isatty($module, fd, /)\n"
3885"--\n"
3886"\n"
3887"Return True if the fd is connected to a terminal.\n"
3888"\n"
3889"Return True if the file descriptor is an open file descriptor\n"
3890"connected to the slave end of a terminal.");
3891
3892#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003893 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003894
3895static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003896os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003897
3898static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003899os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003900{
3901 PyObject *return_value = NULL;
3902 int fd;
3903 int _return_value;
3904
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003905 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003906 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003907 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003908 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003909 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003910 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003911 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003912 return_value = PyBool_FromLong((long)_return_value);
3913
3914exit:
3915 return return_value;
3916}
3917
3918#if defined(HAVE_PIPE)
3919
3920PyDoc_STRVAR(os_pipe__doc__,
3921"pipe($module, /)\n"
3922"--\n"
3923"\n"
3924"Create a pipe.\n"
3925"\n"
3926"Returns a tuple of two file descriptors:\n"
3927" (read_fd, write_fd)");
3928
3929#define OS_PIPE_METHODDEF \
3930 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3931
3932static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003933os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003934
3935static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003936os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003937{
3938 return os_pipe_impl(module);
3939}
3940
3941#endif /* defined(HAVE_PIPE) */
3942
3943#if defined(HAVE_PIPE2)
3944
3945PyDoc_STRVAR(os_pipe2__doc__,
3946"pipe2($module, flags, /)\n"
3947"--\n"
3948"\n"
3949"Create a pipe with flags set atomically.\n"
3950"\n"
3951"Returns a tuple of two file descriptors:\n"
3952" (read_fd, write_fd)\n"
3953"\n"
3954"flags can be constructed by ORing together one or more of these values:\n"
3955"O_NONBLOCK, O_CLOEXEC.");
3956
3957#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003958 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003959
3960static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003961os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003962
3963static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003964os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003965{
3966 PyObject *return_value = NULL;
3967 int flags;
3968
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003969 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003970 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003971 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003972 return_value = os_pipe2_impl(module, flags);
3973
3974exit:
3975 return return_value;
3976}
3977
3978#endif /* defined(HAVE_PIPE2) */
3979
3980#if defined(HAVE_WRITEV)
3981
3982PyDoc_STRVAR(os_writev__doc__,
3983"writev($module, fd, buffers, /)\n"
3984"--\n"
3985"\n"
3986"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3987"\n"
3988"Returns the total number of bytes written.\n"
3989"buffers must be a sequence of bytes-like objects.");
3990
3991#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003992 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003993
3994static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003995os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003996
3997static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003998os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003999{
4000 PyObject *return_value = NULL;
4001 int fd;
4002 PyObject *buffers;
4003 Py_ssize_t _return_value;
4004
Sylvain74453812017-06-10 06:51:48 +02004005 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
4006 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004007 goto exit;
4008 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004009 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004010 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004011 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004012 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004013 return_value = PyLong_FromSsize_t(_return_value);
4014
4015exit:
4016 return return_value;
4017}
4018
4019#endif /* defined(HAVE_WRITEV) */
4020
4021#if defined(HAVE_PWRITE)
4022
4023PyDoc_STRVAR(os_pwrite__doc__,
4024"pwrite($module, fd, buffer, offset, /)\n"
4025"--\n"
4026"\n"
4027"Write bytes to a file descriptor starting at a particular offset.\n"
4028"\n"
4029"Write buffer to fd, starting at offset bytes from the beginning of\n"
4030"the file. Returns the number of bytes writte. Does not change the\n"
4031"current file offset.");
4032
4033#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004034 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004035
4036static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004037os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004038
4039static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004040os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004041{
4042 PyObject *return_value = NULL;
4043 int fd;
4044 Py_buffer buffer = {NULL, NULL};
4045 Py_off_t offset;
4046 Py_ssize_t _return_value;
4047
Sylvain74453812017-06-10 06:51:48 +02004048 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4049 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004050 goto exit;
4051 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004052 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004053 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004054 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004055 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004056 return_value = PyLong_FromSsize_t(_return_value);
4057
4058exit:
4059 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004060 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004061 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004062 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004063
4064 return return_value;
4065}
4066
4067#endif /* defined(HAVE_PWRITE) */
4068
Pablo Galindo4defba32018-01-27 16:16:37 +00004069#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4070
4071PyDoc_STRVAR(os_pwritev__doc__,
4072"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4073"--\n"
4074"\n"
4075"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4076"\n"
4077"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4078"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4079"buffer is written before proceeding to second, and so on. The operating system may\n"
4080"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4081"This function writes the contents of each object to the file descriptor and returns\n"
4082"the total number of bytes written.\n"
4083"\n"
4084"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4085"\n"
4086"- RWF_DSYNC\n"
4087"- RWF_SYNC\n"
4088"\n"
4089"Using non-zero flags requires Linux 4.7 or newer.");
4090
4091#define OS_PWRITEV_METHODDEF \
4092 {"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},
4093
4094static Py_ssize_t
4095os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4096 int flags);
4097
4098static PyObject *
4099os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4100{
4101 PyObject *return_value = NULL;
4102 int fd;
4103 PyObject *buffers;
4104 Py_off_t offset;
4105 int flags = 0;
4106 Py_ssize_t _return_value;
4107
4108 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4109 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4110 goto exit;
4111 }
4112 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4113 if ((_return_value == -1) && PyErr_Occurred()) {
4114 goto exit;
4115 }
4116 return_value = PyLong_FromSsize_t(_return_value);
4117
4118exit:
4119 return return_value;
4120}
4121
4122#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4123
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004124#if defined(HAVE_MKFIFO)
4125
4126PyDoc_STRVAR(os_mkfifo__doc__,
4127"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4128"--\n"
4129"\n"
4130"Create a \"fifo\" (a POSIX named pipe).\n"
4131"\n"
4132"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4133" and path should be relative; path will then be relative to that directory.\n"
4134"dir_fd may not be implemented on your platform.\n"
4135" If it is unavailable, using it will raise a NotImplementedError.");
4136
4137#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004138 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004139
4140static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004141os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004142
4143static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004144os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004145{
4146 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004147 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4148 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004149 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4150 int mode = 438;
4151 int dir_fd = DEFAULT_DIR_FD;
4152
Victor Stinner3e1fad62017-01-17 01:29:01 +01004153 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004154 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004155 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004156 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004157 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4158
4159exit:
4160 /* Cleanup for path */
4161 path_cleanup(&path);
4162
4163 return return_value;
4164}
4165
4166#endif /* defined(HAVE_MKFIFO) */
4167
4168#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4169
4170PyDoc_STRVAR(os_mknod__doc__,
4171"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4172"--\n"
4173"\n"
4174"Create a node in the file system.\n"
4175"\n"
4176"Create a node in the file system (file, device special file or named pipe)\n"
4177"at path. mode specifies both the permissions to use and the\n"
4178"type of node to be created, being combined (bitwise OR) with one of\n"
4179"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4180"device defines the newly created device special file (probably using\n"
4181"os.makedev()). Otherwise device is ignored.\n"
4182"\n"
4183"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4184" and path should be relative; path will then be relative to that directory.\n"
4185"dir_fd may not be implemented on your platform.\n"
4186" If it is unavailable, using it will raise a NotImplementedError.");
4187
4188#define OS_MKNOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004189 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004190
4191static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004192os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004193 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004194
4195static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004196os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004197{
4198 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004199 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4200 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004201 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4202 int mode = 384;
4203 dev_t device = 0;
4204 int dir_fd = DEFAULT_DIR_FD;
4205
Victor Stinner3e1fad62017-01-17 01:29:01 +01004206 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004207 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004208 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004209 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004210 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4211
4212exit:
4213 /* Cleanup for path */
4214 path_cleanup(&path);
4215
4216 return return_value;
4217}
4218
4219#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4220
4221#if defined(HAVE_DEVICE_MACROS)
4222
4223PyDoc_STRVAR(os_major__doc__,
4224"major($module, device, /)\n"
4225"--\n"
4226"\n"
4227"Extracts a device major number from a raw device number.");
4228
4229#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004230 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004231
4232static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004233os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004234
4235static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004236os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004237{
4238 PyObject *return_value = NULL;
4239 dev_t device;
4240 unsigned int _return_value;
4241
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004242 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004243 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004244 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004245 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004246 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004247 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004248 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004249 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4250
4251exit:
4252 return return_value;
4253}
4254
4255#endif /* defined(HAVE_DEVICE_MACROS) */
4256
4257#if defined(HAVE_DEVICE_MACROS)
4258
4259PyDoc_STRVAR(os_minor__doc__,
4260"minor($module, device, /)\n"
4261"--\n"
4262"\n"
4263"Extracts a device minor number from a raw device number.");
4264
4265#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004266 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004267
4268static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004269os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004270
4271static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004272os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004273{
4274 PyObject *return_value = NULL;
4275 dev_t device;
4276 unsigned int _return_value;
4277
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004278 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004279 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004280 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004281 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004282 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004285 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4286
4287exit:
4288 return return_value;
4289}
4290
4291#endif /* defined(HAVE_DEVICE_MACROS) */
4292
4293#if defined(HAVE_DEVICE_MACROS)
4294
4295PyDoc_STRVAR(os_makedev__doc__,
4296"makedev($module, major, minor, /)\n"
4297"--\n"
4298"\n"
4299"Composes a raw device number from the major and minor device numbers.");
4300
4301#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004302 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004303
4304static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004305os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004306
4307static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004308os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004309{
4310 PyObject *return_value = NULL;
4311 int major;
4312 int minor;
4313 dev_t _return_value;
4314
Sylvain74453812017-06-10 06:51:48 +02004315 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4316 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004317 goto exit;
4318 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004319 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004320 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004321 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004322 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004323 return_value = _PyLong_FromDev(_return_value);
4324
4325exit:
4326 return return_value;
4327}
4328
4329#endif /* defined(HAVE_DEVICE_MACROS) */
4330
Steve Dowerf7377032015-04-12 15:44:54 -04004331#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004332
4333PyDoc_STRVAR(os_ftruncate__doc__,
4334"ftruncate($module, fd, length, /)\n"
4335"--\n"
4336"\n"
4337"Truncate a file, specified by file descriptor, to a specific length.");
4338
4339#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004340 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004341
4342static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004343os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004344
4345static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004346os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004347{
4348 PyObject *return_value = NULL;
4349 int fd;
4350 Py_off_t length;
4351
Sylvain74453812017-06-10 06:51:48 +02004352 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4353 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004354 goto exit;
4355 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004356 return_value = os_ftruncate_impl(module, fd, length);
4357
4358exit:
4359 return return_value;
4360}
4361
Steve Dowerf7377032015-04-12 15:44:54 -04004362#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004363
Steve Dowerf7377032015-04-12 15:44:54 -04004364#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004365
4366PyDoc_STRVAR(os_truncate__doc__,
4367"truncate($module, /, path, length)\n"
4368"--\n"
4369"\n"
4370"Truncate a file, specified by path, to a specific length.\n"
4371"\n"
4372"On some platforms, path may also be specified as an open file descriptor.\n"
4373" If this functionality is unavailable, using it raises an exception.");
4374
4375#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004376 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004377
4378static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004379os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004380
4381static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004382os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004383{
4384 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004385 static const char * const _keywords[] = {"path", "length", NULL};
4386 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004387 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4388 Py_off_t length;
4389
Victor Stinner3e1fad62017-01-17 01:29:01 +01004390 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004391 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004392 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004393 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004394 return_value = os_truncate_impl(module, &path, length);
4395
4396exit:
4397 /* Cleanup for path */
4398 path_cleanup(&path);
4399
4400 return return_value;
4401}
4402
Steve Dowerf7377032015-04-12 15:44:54 -04004403#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004404
4405#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4406
4407PyDoc_STRVAR(os_posix_fallocate__doc__,
4408"posix_fallocate($module, fd, offset, length, /)\n"
4409"--\n"
4410"\n"
4411"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4412"\n"
4413"Ensure that the file specified by fd encompasses a range of bytes\n"
4414"starting at offset bytes from the beginning and continuing for length bytes.");
4415
4416#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004417 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004418
4419static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004420os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004421 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004422
4423static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004424os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004425{
4426 PyObject *return_value = NULL;
4427 int fd;
4428 Py_off_t offset;
4429 Py_off_t length;
4430
Sylvain74453812017-06-10 06:51:48 +02004431 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4432 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004433 goto exit;
4434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004435 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4436
4437exit:
4438 return return_value;
4439}
4440
4441#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4442
4443#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4444
4445PyDoc_STRVAR(os_posix_fadvise__doc__,
4446"posix_fadvise($module, fd, offset, length, advice, /)\n"
4447"--\n"
4448"\n"
4449"Announce an intention to access data in a specific pattern.\n"
4450"\n"
4451"Announce an intention to access data in a specific pattern, thus allowing\n"
4452"the kernel to make optimizations.\n"
4453"The advice applies to the region of the file specified by fd starting at\n"
4454"offset and continuing for length bytes.\n"
4455"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4456"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4457"POSIX_FADV_DONTNEED.");
4458
4459#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004460 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004461
4462static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004463os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004464 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004465
4466static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004467os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004468{
4469 PyObject *return_value = NULL;
4470 int fd;
4471 Py_off_t offset;
4472 Py_off_t length;
4473 int advice;
4474
Sylvain74453812017-06-10 06:51:48 +02004475 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4476 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004477 goto exit;
4478 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004479 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4480
4481exit:
4482 return return_value;
4483}
4484
4485#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4486
4487#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4488
4489PyDoc_STRVAR(os_putenv__doc__,
4490"putenv($module, name, value, /)\n"
4491"--\n"
4492"\n"
4493"Change or add an environment variable.");
4494
4495#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004496 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004497
4498static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004499os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004500
4501static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004502os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004503{
4504 PyObject *return_value = NULL;
4505 PyObject *name;
4506 PyObject *value;
4507
Sylvain74453812017-06-10 06:51:48 +02004508 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4509 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004510 goto exit;
4511 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004512 return_value = os_putenv_impl(module, name, value);
4513
4514exit:
4515 return return_value;
4516}
4517
4518#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4519
4520#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4521
4522PyDoc_STRVAR(os_putenv__doc__,
4523"putenv($module, name, value, /)\n"
4524"--\n"
4525"\n"
4526"Change or add an environment variable.");
4527
4528#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004529 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004530
4531static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004532os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004533
4534static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004535os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004536{
4537 PyObject *return_value = NULL;
4538 PyObject *name = NULL;
4539 PyObject *value = NULL;
4540
Sylvain74453812017-06-10 06:51:48 +02004541 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4542 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004543 goto exit;
4544 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004545 return_value = os_putenv_impl(module, name, value);
4546
4547exit:
4548 /* Cleanup for name */
4549 Py_XDECREF(name);
4550 /* Cleanup for value */
4551 Py_XDECREF(value);
4552
4553 return return_value;
4554}
4555
4556#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4557
4558#if defined(HAVE_UNSETENV)
4559
4560PyDoc_STRVAR(os_unsetenv__doc__,
4561"unsetenv($module, name, /)\n"
4562"--\n"
4563"\n"
4564"Delete an environment variable.");
4565
4566#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004567 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004568
4569static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004570os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004571
4572static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004573os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004574{
4575 PyObject *return_value = NULL;
4576 PyObject *name = NULL;
4577
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004578 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004579 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004580 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004581 return_value = os_unsetenv_impl(module, name);
4582
4583exit:
4584 /* Cleanup for name */
4585 Py_XDECREF(name);
4586
4587 return return_value;
4588}
4589
4590#endif /* defined(HAVE_UNSETENV) */
4591
4592PyDoc_STRVAR(os_strerror__doc__,
4593"strerror($module, code, /)\n"
4594"--\n"
4595"\n"
4596"Translate an error code to a message string.");
4597
4598#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004599 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004600
4601static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004602os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004603
4604static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004605os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004606{
4607 PyObject *return_value = NULL;
4608 int code;
4609
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004610 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004611 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004612 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004613 return_value = os_strerror_impl(module, code);
4614
4615exit:
4616 return return_value;
4617}
4618
4619#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4620
4621PyDoc_STRVAR(os_WCOREDUMP__doc__,
4622"WCOREDUMP($module, status, /)\n"
4623"--\n"
4624"\n"
4625"Return True if the process returning status was dumped to a core file.");
4626
4627#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004628 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004629
4630static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004631os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004632
4633static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004634os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004635{
4636 PyObject *return_value = NULL;
4637 int status;
4638 int _return_value;
4639
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004640 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004641 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004642 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004643 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004644 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004645 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004646 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004647 return_value = PyBool_FromLong((long)_return_value);
4648
4649exit:
4650 return return_value;
4651}
4652
4653#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4654
4655#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4656
4657PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4658"WIFCONTINUED($module, /, status)\n"
4659"--\n"
4660"\n"
4661"Return True if a particular process was continued from a job control stop.\n"
4662"\n"
4663"Return True if the process returning status was continued from a\n"
4664"job control stop.");
4665
4666#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004667 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004668
4669static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004670os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004671
4672static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004673os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004674{
4675 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004676 static const char * const _keywords[] = {"status", NULL};
4677 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004678 int status;
4679 int _return_value;
4680
Victor Stinner3e1fad62017-01-17 01:29:01 +01004681 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004682 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004683 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004684 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004685 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004686 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004687 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004688 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004689 return_value = PyBool_FromLong((long)_return_value);
4690
4691exit:
4692 return return_value;
4693}
4694
4695#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4696
4697#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4698
4699PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4700"WIFSTOPPED($module, /, status)\n"
4701"--\n"
4702"\n"
4703"Return True if the process returning status was stopped.");
4704
4705#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004706 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004707
4708static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004709os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004710
4711static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004712os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004713{
4714 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004715 static const char * const _keywords[] = {"status", NULL};
4716 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004717 int status;
4718 int _return_value;
4719
Victor Stinner3e1fad62017-01-17 01:29:01 +01004720 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004721 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004722 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004723 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004724 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004725 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004726 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004727 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004728 return_value = PyBool_FromLong((long)_return_value);
4729
4730exit:
4731 return return_value;
4732}
4733
4734#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4735
4736#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4737
4738PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4739"WIFSIGNALED($module, /, status)\n"
4740"--\n"
4741"\n"
4742"Return True if the process returning status was terminated by a signal.");
4743
4744#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004745 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004746
4747static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004748os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004749
4750static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004751os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004752{
4753 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004754 static const char * const _keywords[] = {"status", NULL};
4755 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004756 int status;
4757 int _return_value;
4758
Victor Stinner3e1fad62017-01-17 01:29:01 +01004759 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004760 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004761 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004762 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004763 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004764 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004765 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004766 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004767 return_value = PyBool_FromLong((long)_return_value);
4768
4769exit:
4770 return return_value;
4771}
4772
4773#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4774
4775#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4776
4777PyDoc_STRVAR(os_WIFEXITED__doc__,
4778"WIFEXITED($module, /, status)\n"
4779"--\n"
4780"\n"
4781"Return True if the process returning status exited via the exit() system call.");
4782
4783#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004784 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004785
4786static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004787os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004788
4789static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004790os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004791{
4792 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004793 static const char * const _keywords[] = {"status", NULL};
4794 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004795 int status;
4796 int _return_value;
4797
Victor Stinner3e1fad62017-01-17 01:29:01 +01004798 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004799 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004800 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004801 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004802 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004803 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004804 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004805 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004806 return_value = PyBool_FromLong((long)_return_value);
4807
4808exit:
4809 return return_value;
4810}
4811
4812#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4813
4814#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4815
4816PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4817"WEXITSTATUS($module, /, status)\n"
4818"--\n"
4819"\n"
4820"Return the process return code from status.");
4821
4822#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004823 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004824
4825static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004826os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004827
4828static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004829os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004830{
4831 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004832 static const char * const _keywords[] = {"status", NULL};
4833 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004834 int status;
4835 int _return_value;
4836
Victor Stinner3e1fad62017-01-17 01:29:01 +01004837 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004838 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004839 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004840 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004841 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004842 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004843 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004844 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004845 return_value = PyLong_FromLong((long)_return_value);
4846
4847exit:
4848 return return_value;
4849}
4850
4851#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4852
4853#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4854
4855PyDoc_STRVAR(os_WTERMSIG__doc__,
4856"WTERMSIG($module, /, status)\n"
4857"--\n"
4858"\n"
4859"Return the signal that terminated the process that provided the status value.");
4860
4861#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004862 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004863
4864static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004865os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004866
4867static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004868os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004869{
4870 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004871 static const char * const _keywords[] = {"status", NULL};
4872 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004873 int status;
4874 int _return_value;
4875
Victor Stinner3e1fad62017-01-17 01:29:01 +01004876 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004877 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004878 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004879 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004880 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004881 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004882 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004883 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004884 return_value = PyLong_FromLong((long)_return_value);
4885
4886exit:
4887 return return_value;
4888}
4889
4890#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4891
4892#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4893
4894PyDoc_STRVAR(os_WSTOPSIG__doc__,
4895"WSTOPSIG($module, /, status)\n"
4896"--\n"
4897"\n"
4898"Return the signal that stopped the process that provided the status value.");
4899
4900#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004901 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004902
4903static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004904os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004905
4906static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004907os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004908{
4909 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004910 static const char * const _keywords[] = {"status", NULL};
4911 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004912 int status;
4913 int _return_value;
4914
Victor Stinner3e1fad62017-01-17 01:29:01 +01004915 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004916 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004917 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004918 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004919 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004920 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004921 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004922 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004923 return_value = PyLong_FromLong((long)_return_value);
4924
4925exit:
4926 return return_value;
4927}
4928
4929#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4930
4931#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4932
4933PyDoc_STRVAR(os_fstatvfs__doc__,
4934"fstatvfs($module, fd, /)\n"
4935"--\n"
4936"\n"
4937"Perform an fstatvfs system call on the given fd.\n"
4938"\n"
4939"Equivalent to statvfs(fd).");
4940
4941#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004942 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004943
4944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004945os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004946
4947static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004948os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004949{
4950 PyObject *return_value = NULL;
4951 int fd;
4952
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004953 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004954 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004955 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004956 return_value = os_fstatvfs_impl(module, fd);
4957
4958exit:
4959 return return_value;
4960}
4961
4962#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4963
4964#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4965
4966PyDoc_STRVAR(os_statvfs__doc__,
4967"statvfs($module, /, path)\n"
4968"--\n"
4969"\n"
4970"Perform a statvfs system call on the given path.\n"
4971"\n"
4972"path may always be specified as a string.\n"
4973"On some platforms, path may also be specified as an open file descriptor.\n"
4974" If this functionality is unavailable, using it raises an exception.");
4975
4976#define OS_STATVFS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004977 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004978
4979static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004980os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004981
4982static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004983os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984{
4985 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004986 static const char * const _keywords[] = {"path", NULL};
4987 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004988 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4989
Victor Stinner3e1fad62017-01-17 01:29:01 +01004990 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004991 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004992 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004993 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004994 return_value = os_statvfs_impl(module, &path);
4995
4996exit:
4997 /* Cleanup for path */
4998 path_cleanup(&path);
4999
5000 return return_value;
5001}
5002
5003#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5004
5005#if defined(MS_WINDOWS)
5006
5007PyDoc_STRVAR(os__getdiskusage__doc__,
5008"_getdiskusage($module, /, path)\n"
5009"--\n"
5010"\n"
5011"Return disk usage statistics about the given path as a (total, free) tuple.");
5012
5013#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005014 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005015
5016static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005017os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005018
5019static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005020os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005021{
5022 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005023 static const char * const _keywords[] = {"path", NULL};
5024 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005025 Py_UNICODE *path;
5026
Victor Stinner3e1fad62017-01-17 01:29:01 +01005027 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005028 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005029 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005030 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005031 return_value = os__getdiskusage_impl(module, path);
5032
5033exit:
5034 return return_value;
5035}
5036
5037#endif /* defined(MS_WINDOWS) */
5038
5039#if defined(HAVE_FPATHCONF)
5040
5041PyDoc_STRVAR(os_fpathconf__doc__,
5042"fpathconf($module, fd, name, /)\n"
5043"--\n"
5044"\n"
5045"Return the configuration limit name for the file descriptor fd.\n"
5046"\n"
5047"If there is no limit, return -1.");
5048
5049#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005050 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005051
5052static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005053os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005054
5055static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005056os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005057{
5058 PyObject *return_value = NULL;
5059 int fd;
5060 int name;
5061 long _return_value;
5062
Sylvain74453812017-06-10 06:51:48 +02005063 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5064 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005065 goto exit;
5066 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005067 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005068 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005069 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005070 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005071 return_value = PyLong_FromLong(_return_value);
5072
5073exit:
5074 return return_value;
5075}
5076
5077#endif /* defined(HAVE_FPATHCONF) */
5078
5079#if defined(HAVE_PATHCONF)
5080
5081PyDoc_STRVAR(os_pathconf__doc__,
5082"pathconf($module, /, path, name)\n"
5083"--\n"
5084"\n"
5085"Return the configuration limit name for the file or directory path.\n"
5086"\n"
5087"If there is no limit, return -1.\n"
5088"On some platforms, path may also be specified as an open file descriptor.\n"
5089" If this functionality is unavailable, using it raises an exception.");
5090
5091#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005092 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005093
5094static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005095os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005096
5097static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005098os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005099{
5100 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005101 static const char * const _keywords[] = {"path", "name", NULL};
5102 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005103 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5104 int name;
5105 long _return_value;
5106
Victor Stinner3e1fad62017-01-17 01:29:01 +01005107 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005108 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005109 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005110 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005111 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005112 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005113 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005114 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005115 return_value = PyLong_FromLong(_return_value);
5116
5117exit:
5118 /* Cleanup for path */
5119 path_cleanup(&path);
5120
5121 return return_value;
5122}
5123
5124#endif /* defined(HAVE_PATHCONF) */
5125
5126#if defined(HAVE_CONFSTR)
5127
5128PyDoc_STRVAR(os_confstr__doc__,
5129"confstr($module, name, /)\n"
5130"--\n"
5131"\n"
5132"Return a string-valued system configuration variable.");
5133
5134#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005135 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005136
5137static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005138os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005139
5140static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005141os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005142{
5143 PyObject *return_value = NULL;
5144 int name;
5145
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005146 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005147 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005148 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005149 return_value = os_confstr_impl(module, name);
5150
5151exit:
5152 return return_value;
5153}
5154
5155#endif /* defined(HAVE_CONFSTR) */
5156
5157#if defined(HAVE_SYSCONF)
5158
5159PyDoc_STRVAR(os_sysconf__doc__,
5160"sysconf($module, name, /)\n"
5161"--\n"
5162"\n"
5163"Return an integer-valued system configuration variable.");
5164
5165#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005166 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005167
5168static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005169os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005170
5171static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005172os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005173{
5174 PyObject *return_value = NULL;
5175 int name;
5176 long _return_value;
5177
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005178 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005179 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005180 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005181 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005182 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005183 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005184 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005185 return_value = PyLong_FromLong(_return_value);
5186
5187exit:
5188 return return_value;
5189}
5190
5191#endif /* defined(HAVE_SYSCONF) */
5192
5193PyDoc_STRVAR(os_abort__doc__,
5194"abort($module, /)\n"
5195"--\n"
5196"\n"
5197"Abort the interpreter immediately.\n"
5198"\n"
5199"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5200"on the hosting operating system. This function never returns.");
5201
5202#define OS_ABORT_METHODDEF \
5203 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5204
5205static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005206os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005207
5208static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005209os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005210{
5211 return os_abort_impl(module);
5212}
5213
Steve Dowercc16be82016-09-08 10:35:16 -07005214#if defined(MS_WINDOWS)
5215
5216PyDoc_STRVAR(os_startfile__doc__,
5217"startfile($module, /, filepath, operation=None)\n"
5218"--\n"
5219"\n"
5220"startfile(filepath [, operation])\n"
5221"\n"
5222"Start a file with its associated application.\n"
5223"\n"
5224"When \"operation\" is not specified or \"open\", this acts like\n"
5225"double-clicking the file in Explorer, or giving the file name as an\n"
5226"argument to the DOS \"start\" command: the file is opened with whatever\n"
5227"application (if any) its extension is associated.\n"
5228"When another \"operation\" is given, it specifies what should be done with\n"
5229"the file. A typical operation is \"print\".\n"
5230"\n"
5231"startfile returns as soon as the associated application is launched.\n"
5232"There is no option to wait for the application to close, and no way\n"
5233"to retrieve the application\'s exit status.\n"
5234"\n"
5235"The filepath is relative to the current directory. If you want to use\n"
5236"an absolute path, make sure the first character is not a slash (\"/\");\n"
5237"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5238
5239#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005240 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005241
5242static PyObject *
5243os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5244
5245static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005246os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005247{
5248 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005249 static const char * const _keywords[] = {"filepath", "operation", NULL};
5250 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005251 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5252 Py_UNICODE *operation = NULL;
5253
Victor Stinner3e1fad62017-01-17 01:29:01 +01005254 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005255 path_converter, &filepath, &operation)) {
5256 goto exit;
5257 }
5258 return_value = os_startfile_impl(module, &filepath, operation);
5259
5260exit:
5261 /* Cleanup for filepath */
5262 path_cleanup(&filepath);
5263
5264 return return_value;
5265}
5266
5267#endif /* defined(MS_WINDOWS) */
5268
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005269#if defined(HAVE_GETLOADAVG)
5270
5271PyDoc_STRVAR(os_getloadavg__doc__,
5272"getloadavg($module, /)\n"
5273"--\n"
5274"\n"
5275"Return average recent system load information.\n"
5276"\n"
5277"Return the number of processes in the system run queue averaged over\n"
5278"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5279"Raises OSError if the load average was unobtainable.");
5280
5281#define OS_GETLOADAVG_METHODDEF \
5282 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5283
5284static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005285os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005286
5287static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005288os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005289{
5290 return os_getloadavg_impl(module);
5291}
5292
5293#endif /* defined(HAVE_GETLOADAVG) */
5294
5295PyDoc_STRVAR(os_device_encoding__doc__,
5296"device_encoding($module, /, fd)\n"
5297"--\n"
5298"\n"
5299"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5300"\n"
5301"The file descriptor must be attached to a terminal.\n"
5302"If the device is not a terminal, return None.");
5303
5304#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005305 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005306
5307static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005308os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005309
5310static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005311os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005312{
5313 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005314 static const char * const _keywords[] = {"fd", NULL};
5315 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005316 int fd;
5317
Victor Stinner3e1fad62017-01-17 01:29:01 +01005318 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005319 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005320 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005321 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005322 return_value = os_device_encoding_impl(module, fd);
5323
5324exit:
5325 return return_value;
5326}
5327
5328#if defined(HAVE_SETRESUID)
5329
5330PyDoc_STRVAR(os_setresuid__doc__,
5331"setresuid($module, ruid, euid, suid, /)\n"
5332"--\n"
5333"\n"
5334"Set the current process\'s real, effective, and saved user ids.");
5335
5336#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005337 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005338
5339static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005340os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005341
5342static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005343os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005344{
5345 PyObject *return_value = NULL;
5346 uid_t ruid;
5347 uid_t euid;
5348 uid_t suid;
5349
Sylvain74453812017-06-10 06:51:48 +02005350 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5351 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005352 goto exit;
5353 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005354 return_value = os_setresuid_impl(module, ruid, euid, suid);
5355
5356exit:
5357 return return_value;
5358}
5359
5360#endif /* defined(HAVE_SETRESUID) */
5361
5362#if defined(HAVE_SETRESGID)
5363
5364PyDoc_STRVAR(os_setresgid__doc__,
5365"setresgid($module, rgid, egid, sgid, /)\n"
5366"--\n"
5367"\n"
5368"Set the current process\'s real, effective, and saved group ids.");
5369
5370#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005371 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005372
5373static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005374os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005375
5376static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005377os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005378{
5379 PyObject *return_value = NULL;
5380 gid_t rgid;
5381 gid_t egid;
5382 gid_t sgid;
5383
Sylvain74453812017-06-10 06:51:48 +02005384 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5385 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005386 goto exit;
5387 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005388 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5389
5390exit:
5391 return return_value;
5392}
5393
5394#endif /* defined(HAVE_SETRESGID) */
5395
5396#if defined(HAVE_GETRESUID)
5397
5398PyDoc_STRVAR(os_getresuid__doc__,
5399"getresuid($module, /)\n"
5400"--\n"
5401"\n"
5402"Return a tuple of the current process\'s real, effective, and saved user ids.");
5403
5404#define OS_GETRESUID_METHODDEF \
5405 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5406
5407static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005408os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005409
5410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005411os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005412{
5413 return os_getresuid_impl(module);
5414}
5415
5416#endif /* defined(HAVE_GETRESUID) */
5417
5418#if defined(HAVE_GETRESGID)
5419
5420PyDoc_STRVAR(os_getresgid__doc__,
5421"getresgid($module, /)\n"
5422"--\n"
5423"\n"
5424"Return a tuple of the current process\'s real, effective, and saved group ids.");
5425
5426#define OS_GETRESGID_METHODDEF \
5427 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5428
5429static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005430os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005431
5432static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005433os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005434{
5435 return os_getresgid_impl(module);
5436}
5437
5438#endif /* defined(HAVE_GETRESGID) */
5439
5440#if defined(USE_XATTRS)
5441
5442PyDoc_STRVAR(os_getxattr__doc__,
5443"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5444"--\n"
5445"\n"
5446"Return the value of extended attribute attribute on path.\n"
5447"\n"
5448"path may be either a string or an open file descriptor.\n"
5449"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5450" link, getxattr will examine the symbolic link itself instead of the file\n"
5451" the link points to.");
5452
5453#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005454 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005455
5456static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005457os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005458 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005459
5460static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005461os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005462{
5463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005464 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5465 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005466 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5467 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5468 int follow_symlinks = 1;
5469
Victor Stinner3e1fad62017-01-17 01:29:01 +01005470 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005471 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005472 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005473 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005474 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5475
5476exit:
5477 /* Cleanup for path */
5478 path_cleanup(&path);
5479 /* Cleanup for attribute */
5480 path_cleanup(&attribute);
5481
5482 return return_value;
5483}
5484
5485#endif /* defined(USE_XATTRS) */
5486
5487#if defined(USE_XATTRS)
5488
5489PyDoc_STRVAR(os_setxattr__doc__,
5490"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5491" follow_symlinks=True)\n"
5492"--\n"
5493"\n"
5494"Set extended attribute attribute on path to value.\n"
5495"\n"
5496"path may be either a string or an open file descriptor.\n"
5497"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5498" link, setxattr will modify the symbolic link itself instead of the file\n"
5499" the link points to.");
5500
5501#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005502 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005503
5504static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005505os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005506 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005507
5508static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005509os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005510{
5511 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005512 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5513 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005514 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5515 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5516 Py_buffer value = {NULL, NULL};
5517 int flags = 0;
5518 int follow_symlinks = 1;
5519
Victor Stinner3e1fad62017-01-17 01:29:01 +01005520 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005521 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005522 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005523 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005524 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5525
5526exit:
5527 /* Cleanup for path */
5528 path_cleanup(&path);
5529 /* Cleanup for attribute */
5530 path_cleanup(&attribute);
5531 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005532 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005533 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005534 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005535
5536 return return_value;
5537}
5538
5539#endif /* defined(USE_XATTRS) */
5540
5541#if defined(USE_XATTRS)
5542
5543PyDoc_STRVAR(os_removexattr__doc__,
5544"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5545"--\n"
5546"\n"
5547"Remove extended attribute attribute on path.\n"
5548"\n"
5549"path may be either a string or an open file descriptor.\n"
5550"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5551" link, removexattr will modify the symbolic link itself instead of the file\n"
5552" the link points to.");
5553
5554#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005555 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005556
5557static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005558os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005559 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005560
5561static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005562os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005563{
5564 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005565 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5566 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005567 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5568 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5569 int follow_symlinks = 1;
5570
Victor Stinner3e1fad62017-01-17 01:29:01 +01005571 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005572 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005573 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005574 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005575 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5576
5577exit:
5578 /* Cleanup for path */
5579 path_cleanup(&path);
5580 /* Cleanup for attribute */
5581 path_cleanup(&attribute);
5582
5583 return return_value;
5584}
5585
5586#endif /* defined(USE_XATTRS) */
5587
5588#if defined(USE_XATTRS)
5589
5590PyDoc_STRVAR(os_listxattr__doc__,
5591"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5592"--\n"
5593"\n"
5594"Return a list of extended attributes on path.\n"
5595"\n"
5596"path may be either None, a string, or an open file descriptor.\n"
5597"if path is None, listxattr will examine the current directory.\n"
5598"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5599" link, listxattr will examine the symbolic link itself instead of the file\n"
5600" the link points to.");
5601
5602#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005603 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005604
5605static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005606os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005607
5608static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005609os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005610{
5611 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005612 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5613 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005614 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5615 int follow_symlinks = 1;
5616
Victor Stinner3e1fad62017-01-17 01:29:01 +01005617 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005618 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005619 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005620 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005621 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5622
5623exit:
5624 /* Cleanup for path */
5625 path_cleanup(&path);
5626
5627 return return_value;
5628}
5629
5630#endif /* defined(USE_XATTRS) */
5631
5632PyDoc_STRVAR(os_urandom__doc__,
5633"urandom($module, size, /)\n"
5634"--\n"
5635"\n"
5636"Return a bytes object containing random bytes suitable for cryptographic use.");
5637
5638#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005639 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005640
5641static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005642os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005643
5644static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005645os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005646{
5647 PyObject *return_value = NULL;
5648 Py_ssize_t size;
5649
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005650 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005651 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005652 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005653 return_value = os_urandom_impl(module, size);
5654
5655exit:
5656 return return_value;
5657}
5658
5659PyDoc_STRVAR(os_cpu_count__doc__,
5660"cpu_count($module, /)\n"
5661"--\n"
5662"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005663"Return the number of CPUs in the system; return None if indeterminable.\n"
5664"\n"
5665"This number is not equivalent to the number of CPUs the current process can\n"
5666"use. The number of usable CPUs can be obtained with\n"
5667"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005668
5669#define OS_CPU_COUNT_METHODDEF \
5670 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5671
5672static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005673os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005674
5675static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005676os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005677{
5678 return os_cpu_count_impl(module);
5679}
5680
5681PyDoc_STRVAR(os_get_inheritable__doc__,
5682"get_inheritable($module, fd, /)\n"
5683"--\n"
5684"\n"
5685"Get the close-on-exe flag of the specified file descriptor.");
5686
5687#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005688 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005689
5690static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005691os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005692
5693static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005694os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005695{
5696 PyObject *return_value = NULL;
5697 int fd;
5698 int _return_value;
5699
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005700 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005701 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005702 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005703 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005704 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005705 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005706 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005707 return_value = PyBool_FromLong((long)_return_value);
5708
5709exit:
5710 return return_value;
5711}
5712
5713PyDoc_STRVAR(os_set_inheritable__doc__,
5714"set_inheritable($module, fd, inheritable, /)\n"
5715"--\n"
5716"\n"
5717"Set the inheritable flag of the specified file descriptor.");
5718
5719#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005720 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005721
5722static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005723os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005724
5725static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005726os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005727{
5728 PyObject *return_value = NULL;
5729 int fd;
5730 int inheritable;
5731
Sylvain74453812017-06-10 06:51:48 +02005732 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5733 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005734 goto exit;
5735 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005736 return_value = os_set_inheritable_impl(module, fd, inheritable);
5737
5738exit:
5739 return return_value;
5740}
5741
5742#if defined(MS_WINDOWS)
5743
5744PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5745"get_handle_inheritable($module, handle, /)\n"
5746"--\n"
5747"\n"
5748"Get the close-on-exe flag of the specified file descriptor.");
5749
5750#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005751 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005752
5753static int
Victor Stinner581139c2016-09-06 15:54:20 -07005754os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005755
5756static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005757os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005758{
5759 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005760 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005761 int _return_value;
5762
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005763 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005764 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005765 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005766 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005767 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005768 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005769 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005770 return_value = PyBool_FromLong((long)_return_value);
5771
5772exit:
5773 return return_value;
5774}
5775
5776#endif /* defined(MS_WINDOWS) */
5777
5778#if defined(MS_WINDOWS)
5779
5780PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5781"set_handle_inheritable($module, handle, inheritable, /)\n"
5782"--\n"
5783"\n"
5784"Set the inheritable flag of the specified handle.");
5785
5786#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005787 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005788
5789static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005790os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005791 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005792
5793static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005794os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005795{
5796 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005797 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005798 int inheritable;
5799
Sylvain74453812017-06-10 06:51:48 +02005800 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5801 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005802 goto exit;
5803 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005804 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5805
5806exit:
5807 return return_value;
5808}
5809
5810#endif /* defined(MS_WINDOWS) */
5811
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005812PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5813"is_symlink($self, /)\n"
5814"--\n"
5815"\n"
5816"Return True if the entry is a symbolic link; cached per entry.");
5817
5818#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5819 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5820
5821static int
5822os_DirEntry_is_symlink_impl(DirEntry *self);
5823
5824static PyObject *
5825os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5826{
5827 PyObject *return_value = NULL;
5828 int _return_value;
5829
5830 _return_value = os_DirEntry_is_symlink_impl(self);
5831 if ((_return_value == -1) && PyErr_Occurred()) {
5832 goto exit;
5833 }
5834 return_value = PyBool_FromLong((long)_return_value);
5835
5836exit:
5837 return return_value;
5838}
5839
5840PyDoc_STRVAR(os_DirEntry_stat__doc__,
5841"stat($self, /, *, follow_symlinks=True)\n"
5842"--\n"
5843"\n"
5844"Return stat_result object for the entry; cached per entry.");
5845
5846#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005847 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005848
5849static PyObject *
5850os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5851
5852static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005853os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005854{
5855 PyObject *return_value = NULL;
5856 static const char * const _keywords[] = {"follow_symlinks", NULL};
5857 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5858 int follow_symlinks = 1;
5859
Victor Stinner3e1fad62017-01-17 01:29:01 +01005860 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005861 &follow_symlinks)) {
5862 goto exit;
5863 }
5864 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5865
5866exit:
5867 return return_value;
5868}
5869
5870PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5871"is_dir($self, /, *, follow_symlinks=True)\n"
5872"--\n"
5873"\n"
5874"Return True if the entry is a directory; cached per entry.");
5875
5876#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005877 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005878
5879static int
5880os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5881
5882static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005883os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005884{
5885 PyObject *return_value = NULL;
5886 static const char * const _keywords[] = {"follow_symlinks", NULL};
5887 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5888 int follow_symlinks = 1;
5889 int _return_value;
5890
Victor Stinner3e1fad62017-01-17 01:29:01 +01005891 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005892 &follow_symlinks)) {
5893 goto exit;
5894 }
5895 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5896 if ((_return_value == -1) && PyErr_Occurred()) {
5897 goto exit;
5898 }
5899 return_value = PyBool_FromLong((long)_return_value);
5900
5901exit:
5902 return return_value;
5903}
5904
5905PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5906"is_file($self, /, *, follow_symlinks=True)\n"
5907"--\n"
5908"\n"
5909"Return True if the entry is a file; cached per entry.");
5910
5911#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005912 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005913
5914static int
5915os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5916
5917static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005918os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005919{
5920 PyObject *return_value = NULL;
5921 static const char * const _keywords[] = {"follow_symlinks", NULL};
5922 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5923 int follow_symlinks = 1;
5924 int _return_value;
5925
Victor Stinner3e1fad62017-01-17 01:29:01 +01005926 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005927 &follow_symlinks)) {
5928 goto exit;
5929 }
5930 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5931 if ((_return_value == -1) && PyErr_Occurred()) {
5932 goto exit;
5933 }
5934 return_value = PyBool_FromLong((long)_return_value);
5935
5936exit:
5937 return return_value;
5938}
5939
5940PyDoc_STRVAR(os_DirEntry_inode__doc__,
5941"inode($self, /)\n"
5942"--\n"
5943"\n"
5944"Return inode of the entry; cached per entry.");
5945
5946#define OS_DIRENTRY_INODE_METHODDEF \
5947 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5948
5949static PyObject *
5950os_DirEntry_inode_impl(DirEntry *self);
5951
5952static PyObject *
5953os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5954{
5955 return os_DirEntry_inode_impl(self);
5956}
5957
5958PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5959"__fspath__($self, /)\n"
5960"--\n"
5961"\n"
5962"Returns the path for the entry.");
5963
5964#define OS_DIRENTRY___FSPATH___METHODDEF \
5965 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5966
5967static PyObject *
5968os_DirEntry___fspath___impl(DirEntry *self);
5969
5970static PyObject *
5971os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5972{
5973 return os_DirEntry___fspath___impl(self);
5974}
5975
5976PyDoc_STRVAR(os_scandir__doc__,
5977"scandir($module, /, path=None)\n"
5978"--\n"
5979"\n"
5980"Return an iterator of DirEntry objects for given path.\n"
5981"\n"
5982"path can be specified as either str, bytes or path-like object. If path\n"
5983"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5984"all other circumstances they will be str.\n"
5985"\n"
5986"If path is None, uses the path=\'.\'.");
5987
5988#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005989 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005990
5991static PyObject *
5992os_scandir_impl(PyObject *module, path_t *path);
5993
5994static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005995os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005996{
5997 PyObject *return_value = NULL;
5998 static const char * const _keywords[] = {"path", NULL};
5999 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006000 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006001
Victor Stinner3e1fad62017-01-17 01:29:01 +01006002 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006003 path_converter, &path)) {
6004 goto exit;
6005 }
6006 return_value = os_scandir_impl(module, &path);
6007
6008exit:
6009 /* Cleanup for path */
6010 path_cleanup(&path);
6011
6012 return return_value;
6013}
6014
Ethan Furman410ef8e2016-06-04 12:06:26 -07006015PyDoc_STRVAR(os_fspath__doc__,
6016"fspath($module, /, path)\n"
6017"--\n"
6018"\n"
6019"Return the file system path representation of the object.\n"
6020"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006021"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6022"object defines __fspath__(), then return the result of that method. All other\n"
6023"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006024
6025#define OS_FSPATH_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006026 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006027
6028static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006029os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006030
6031static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006032os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006033{
6034 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006035 static const char * const _keywords[] = {"path", NULL};
6036 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006037 PyObject *path;
6038
Victor Stinner3e1fad62017-01-17 01:29:01 +01006039 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006040 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006041 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006042 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006043 return_value = os_fspath_impl(module, path);
6044
6045exit:
6046 return return_value;
6047}
6048
Victor Stinner9b1f4742016-09-06 16:18:52 -07006049#if defined(HAVE_GETRANDOM_SYSCALL)
6050
6051PyDoc_STRVAR(os_getrandom__doc__,
6052"getrandom($module, /, size, flags=0)\n"
6053"--\n"
6054"\n"
6055"Obtain a series of random bytes.");
6056
6057#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006058 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006059
6060static PyObject *
6061os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6062
6063static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006064os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006065{
6066 PyObject *return_value = NULL;
6067 static const char * const _keywords[] = {"size", "flags", NULL};
6068 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6069 Py_ssize_t size;
6070 int flags = 0;
6071
Victor Stinner3e1fad62017-01-17 01:29:01 +01006072 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006073 &size, &flags)) {
6074 goto exit;
6075 }
6076 return_value = os_getrandom_impl(module, size, flags);
6077
6078exit:
6079 return return_value;
6080}
6081
6082#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6083
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006084#ifndef OS_TTYNAME_METHODDEF
6085 #define OS_TTYNAME_METHODDEF
6086#endif /* !defined(OS_TTYNAME_METHODDEF) */
6087
6088#ifndef OS_CTERMID_METHODDEF
6089 #define OS_CTERMID_METHODDEF
6090#endif /* !defined(OS_CTERMID_METHODDEF) */
6091
6092#ifndef OS_FCHDIR_METHODDEF
6093 #define OS_FCHDIR_METHODDEF
6094#endif /* !defined(OS_FCHDIR_METHODDEF) */
6095
6096#ifndef OS_FCHMOD_METHODDEF
6097 #define OS_FCHMOD_METHODDEF
6098#endif /* !defined(OS_FCHMOD_METHODDEF) */
6099
6100#ifndef OS_LCHMOD_METHODDEF
6101 #define OS_LCHMOD_METHODDEF
6102#endif /* !defined(OS_LCHMOD_METHODDEF) */
6103
6104#ifndef OS_CHFLAGS_METHODDEF
6105 #define OS_CHFLAGS_METHODDEF
6106#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6107
6108#ifndef OS_LCHFLAGS_METHODDEF
6109 #define OS_LCHFLAGS_METHODDEF
6110#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6111
6112#ifndef OS_CHROOT_METHODDEF
6113 #define OS_CHROOT_METHODDEF
6114#endif /* !defined(OS_CHROOT_METHODDEF) */
6115
6116#ifndef OS_FSYNC_METHODDEF
6117 #define OS_FSYNC_METHODDEF
6118#endif /* !defined(OS_FSYNC_METHODDEF) */
6119
6120#ifndef OS_SYNC_METHODDEF
6121 #define OS_SYNC_METHODDEF
6122#endif /* !defined(OS_SYNC_METHODDEF) */
6123
6124#ifndef OS_FDATASYNC_METHODDEF
6125 #define OS_FDATASYNC_METHODDEF
6126#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6127
6128#ifndef OS_CHOWN_METHODDEF
6129 #define OS_CHOWN_METHODDEF
6130#endif /* !defined(OS_CHOWN_METHODDEF) */
6131
6132#ifndef OS_FCHOWN_METHODDEF
6133 #define OS_FCHOWN_METHODDEF
6134#endif /* !defined(OS_FCHOWN_METHODDEF) */
6135
6136#ifndef OS_LCHOWN_METHODDEF
6137 #define OS_LCHOWN_METHODDEF
6138#endif /* !defined(OS_LCHOWN_METHODDEF) */
6139
6140#ifndef OS_LINK_METHODDEF
6141 #define OS_LINK_METHODDEF
6142#endif /* !defined(OS_LINK_METHODDEF) */
6143
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006144#ifndef OS__GETFULLPATHNAME_METHODDEF
6145 #define OS__GETFULLPATHNAME_METHODDEF
6146#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6147
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006148#ifndef OS__GETFINALPATHNAME_METHODDEF
6149 #define OS__GETFINALPATHNAME_METHODDEF
6150#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6151
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006152#ifndef OS__ISDIR_METHODDEF
6153 #define OS__ISDIR_METHODDEF
6154#endif /* !defined(OS__ISDIR_METHODDEF) */
6155
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006156#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6157 #define OS__GETVOLUMEPATHNAME_METHODDEF
6158#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6159
6160#ifndef OS_NICE_METHODDEF
6161 #define OS_NICE_METHODDEF
6162#endif /* !defined(OS_NICE_METHODDEF) */
6163
6164#ifndef OS_GETPRIORITY_METHODDEF
6165 #define OS_GETPRIORITY_METHODDEF
6166#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6167
6168#ifndef OS_SETPRIORITY_METHODDEF
6169 #define OS_SETPRIORITY_METHODDEF
6170#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6171
6172#ifndef OS_SYSTEM_METHODDEF
6173 #define OS_SYSTEM_METHODDEF
6174#endif /* !defined(OS_SYSTEM_METHODDEF) */
6175
6176#ifndef OS_UNAME_METHODDEF
6177 #define OS_UNAME_METHODDEF
6178#endif /* !defined(OS_UNAME_METHODDEF) */
6179
6180#ifndef OS_EXECV_METHODDEF
6181 #define OS_EXECV_METHODDEF
6182#endif /* !defined(OS_EXECV_METHODDEF) */
6183
6184#ifndef OS_EXECVE_METHODDEF
6185 #define OS_EXECVE_METHODDEF
6186#endif /* !defined(OS_EXECVE_METHODDEF) */
6187
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006188#ifndef OS_POSIX_SPAWN_METHODDEF
6189 #define OS_POSIX_SPAWN_METHODDEF
6190#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6191
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006192#ifndef OS_SPAWNV_METHODDEF
6193 #define OS_SPAWNV_METHODDEF
6194#endif /* !defined(OS_SPAWNV_METHODDEF) */
6195
6196#ifndef OS_SPAWNVE_METHODDEF
6197 #define OS_SPAWNVE_METHODDEF
6198#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6199
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006200#ifndef OS_REGISTER_AT_FORK_METHODDEF
6201 #define OS_REGISTER_AT_FORK_METHODDEF
6202#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6203
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006204#ifndef OS_FORK1_METHODDEF
6205 #define OS_FORK1_METHODDEF
6206#endif /* !defined(OS_FORK1_METHODDEF) */
6207
6208#ifndef OS_FORK_METHODDEF
6209 #define OS_FORK_METHODDEF
6210#endif /* !defined(OS_FORK_METHODDEF) */
6211
6212#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6213 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6214#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6215
6216#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6217 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6218#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6219
6220#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6221 #define OS_SCHED_GETSCHEDULER_METHODDEF
6222#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6223
6224#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6225 #define OS_SCHED_SETSCHEDULER_METHODDEF
6226#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6227
6228#ifndef OS_SCHED_GETPARAM_METHODDEF
6229 #define OS_SCHED_GETPARAM_METHODDEF
6230#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6231
6232#ifndef OS_SCHED_SETPARAM_METHODDEF
6233 #define OS_SCHED_SETPARAM_METHODDEF
6234#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6235
6236#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6237 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6238#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6239
6240#ifndef OS_SCHED_YIELD_METHODDEF
6241 #define OS_SCHED_YIELD_METHODDEF
6242#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6243
6244#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6245 #define OS_SCHED_SETAFFINITY_METHODDEF
6246#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6247
6248#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6249 #define OS_SCHED_GETAFFINITY_METHODDEF
6250#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6251
6252#ifndef OS_OPENPTY_METHODDEF
6253 #define OS_OPENPTY_METHODDEF
6254#endif /* !defined(OS_OPENPTY_METHODDEF) */
6255
6256#ifndef OS_FORKPTY_METHODDEF
6257 #define OS_FORKPTY_METHODDEF
6258#endif /* !defined(OS_FORKPTY_METHODDEF) */
6259
6260#ifndef OS_GETEGID_METHODDEF
6261 #define OS_GETEGID_METHODDEF
6262#endif /* !defined(OS_GETEGID_METHODDEF) */
6263
6264#ifndef OS_GETEUID_METHODDEF
6265 #define OS_GETEUID_METHODDEF
6266#endif /* !defined(OS_GETEUID_METHODDEF) */
6267
6268#ifndef OS_GETGID_METHODDEF
6269 #define OS_GETGID_METHODDEF
6270#endif /* !defined(OS_GETGID_METHODDEF) */
6271
Berker Peksag39404992016-09-15 20:45:16 +03006272#ifndef OS_GETPID_METHODDEF
6273 #define OS_GETPID_METHODDEF
6274#endif /* !defined(OS_GETPID_METHODDEF) */
6275
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006276#ifndef OS_GETGROUPS_METHODDEF
6277 #define OS_GETGROUPS_METHODDEF
6278#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6279
6280#ifndef OS_GETPGID_METHODDEF
6281 #define OS_GETPGID_METHODDEF
6282#endif /* !defined(OS_GETPGID_METHODDEF) */
6283
6284#ifndef OS_GETPGRP_METHODDEF
6285 #define OS_GETPGRP_METHODDEF
6286#endif /* !defined(OS_GETPGRP_METHODDEF) */
6287
6288#ifndef OS_SETPGRP_METHODDEF
6289 #define OS_SETPGRP_METHODDEF
6290#endif /* !defined(OS_SETPGRP_METHODDEF) */
6291
6292#ifndef OS_GETPPID_METHODDEF
6293 #define OS_GETPPID_METHODDEF
6294#endif /* !defined(OS_GETPPID_METHODDEF) */
6295
6296#ifndef OS_GETLOGIN_METHODDEF
6297 #define OS_GETLOGIN_METHODDEF
6298#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6299
6300#ifndef OS_GETUID_METHODDEF
6301 #define OS_GETUID_METHODDEF
6302#endif /* !defined(OS_GETUID_METHODDEF) */
6303
6304#ifndef OS_KILL_METHODDEF
6305 #define OS_KILL_METHODDEF
6306#endif /* !defined(OS_KILL_METHODDEF) */
6307
6308#ifndef OS_KILLPG_METHODDEF
6309 #define OS_KILLPG_METHODDEF
6310#endif /* !defined(OS_KILLPG_METHODDEF) */
6311
6312#ifndef OS_PLOCK_METHODDEF
6313 #define OS_PLOCK_METHODDEF
6314#endif /* !defined(OS_PLOCK_METHODDEF) */
6315
6316#ifndef OS_SETUID_METHODDEF
6317 #define OS_SETUID_METHODDEF
6318#endif /* !defined(OS_SETUID_METHODDEF) */
6319
6320#ifndef OS_SETEUID_METHODDEF
6321 #define OS_SETEUID_METHODDEF
6322#endif /* !defined(OS_SETEUID_METHODDEF) */
6323
6324#ifndef OS_SETEGID_METHODDEF
6325 #define OS_SETEGID_METHODDEF
6326#endif /* !defined(OS_SETEGID_METHODDEF) */
6327
6328#ifndef OS_SETREUID_METHODDEF
6329 #define OS_SETREUID_METHODDEF
6330#endif /* !defined(OS_SETREUID_METHODDEF) */
6331
6332#ifndef OS_SETREGID_METHODDEF
6333 #define OS_SETREGID_METHODDEF
6334#endif /* !defined(OS_SETREGID_METHODDEF) */
6335
6336#ifndef OS_SETGID_METHODDEF
6337 #define OS_SETGID_METHODDEF
6338#endif /* !defined(OS_SETGID_METHODDEF) */
6339
6340#ifndef OS_SETGROUPS_METHODDEF
6341 #define OS_SETGROUPS_METHODDEF
6342#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6343
6344#ifndef OS_WAIT3_METHODDEF
6345 #define OS_WAIT3_METHODDEF
6346#endif /* !defined(OS_WAIT3_METHODDEF) */
6347
6348#ifndef OS_WAIT4_METHODDEF
6349 #define OS_WAIT4_METHODDEF
6350#endif /* !defined(OS_WAIT4_METHODDEF) */
6351
6352#ifndef OS_WAITID_METHODDEF
6353 #define OS_WAITID_METHODDEF
6354#endif /* !defined(OS_WAITID_METHODDEF) */
6355
6356#ifndef OS_WAITPID_METHODDEF
6357 #define OS_WAITPID_METHODDEF
6358#endif /* !defined(OS_WAITPID_METHODDEF) */
6359
6360#ifndef OS_WAIT_METHODDEF
6361 #define OS_WAIT_METHODDEF
6362#endif /* !defined(OS_WAIT_METHODDEF) */
6363
6364#ifndef OS_SYMLINK_METHODDEF
6365 #define OS_SYMLINK_METHODDEF
6366#endif /* !defined(OS_SYMLINK_METHODDEF) */
6367
6368#ifndef OS_TIMES_METHODDEF
6369 #define OS_TIMES_METHODDEF
6370#endif /* !defined(OS_TIMES_METHODDEF) */
6371
6372#ifndef OS_GETSID_METHODDEF
6373 #define OS_GETSID_METHODDEF
6374#endif /* !defined(OS_GETSID_METHODDEF) */
6375
6376#ifndef OS_SETSID_METHODDEF
6377 #define OS_SETSID_METHODDEF
6378#endif /* !defined(OS_SETSID_METHODDEF) */
6379
6380#ifndef OS_SETPGID_METHODDEF
6381 #define OS_SETPGID_METHODDEF
6382#endif /* !defined(OS_SETPGID_METHODDEF) */
6383
6384#ifndef OS_TCGETPGRP_METHODDEF
6385 #define OS_TCGETPGRP_METHODDEF
6386#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6387
6388#ifndef OS_TCSETPGRP_METHODDEF
6389 #define OS_TCSETPGRP_METHODDEF
6390#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6391
6392#ifndef OS_LOCKF_METHODDEF
6393 #define OS_LOCKF_METHODDEF
6394#endif /* !defined(OS_LOCKF_METHODDEF) */
6395
6396#ifndef OS_READV_METHODDEF
6397 #define OS_READV_METHODDEF
6398#endif /* !defined(OS_READV_METHODDEF) */
6399
6400#ifndef OS_PREAD_METHODDEF
6401 #define OS_PREAD_METHODDEF
6402#endif /* !defined(OS_PREAD_METHODDEF) */
6403
Pablo Galindo4defba32018-01-27 16:16:37 +00006404#ifndef OS_PREADV_METHODDEF
6405 #define OS_PREADV_METHODDEF
6406#endif /* !defined(OS_PREADV_METHODDEF) */
6407
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006408#ifndef OS_PIPE_METHODDEF
6409 #define OS_PIPE_METHODDEF
6410#endif /* !defined(OS_PIPE_METHODDEF) */
6411
6412#ifndef OS_PIPE2_METHODDEF
6413 #define OS_PIPE2_METHODDEF
6414#endif /* !defined(OS_PIPE2_METHODDEF) */
6415
6416#ifndef OS_WRITEV_METHODDEF
6417 #define OS_WRITEV_METHODDEF
6418#endif /* !defined(OS_WRITEV_METHODDEF) */
6419
6420#ifndef OS_PWRITE_METHODDEF
6421 #define OS_PWRITE_METHODDEF
6422#endif /* !defined(OS_PWRITE_METHODDEF) */
6423
Pablo Galindo4defba32018-01-27 16:16:37 +00006424#ifndef OS_PWRITEV_METHODDEF
6425 #define OS_PWRITEV_METHODDEF
6426#endif /* !defined(OS_PWRITEV_METHODDEF) */
6427
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006428#ifndef OS_MKFIFO_METHODDEF
6429 #define OS_MKFIFO_METHODDEF
6430#endif /* !defined(OS_MKFIFO_METHODDEF) */
6431
6432#ifndef OS_MKNOD_METHODDEF
6433 #define OS_MKNOD_METHODDEF
6434#endif /* !defined(OS_MKNOD_METHODDEF) */
6435
6436#ifndef OS_MAJOR_METHODDEF
6437 #define OS_MAJOR_METHODDEF
6438#endif /* !defined(OS_MAJOR_METHODDEF) */
6439
6440#ifndef OS_MINOR_METHODDEF
6441 #define OS_MINOR_METHODDEF
6442#endif /* !defined(OS_MINOR_METHODDEF) */
6443
6444#ifndef OS_MAKEDEV_METHODDEF
6445 #define OS_MAKEDEV_METHODDEF
6446#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6447
6448#ifndef OS_FTRUNCATE_METHODDEF
6449 #define OS_FTRUNCATE_METHODDEF
6450#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6451
6452#ifndef OS_TRUNCATE_METHODDEF
6453 #define OS_TRUNCATE_METHODDEF
6454#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6455
6456#ifndef OS_POSIX_FALLOCATE_METHODDEF
6457 #define OS_POSIX_FALLOCATE_METHODDEF
6458#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6459
6460#ifndef OS_POSIX_FADVISE_METHODDEF
6461 #define OS_POSIX_FADVISE_METHODDEF
6462#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6463
6464#ifndef OS_PUTENV_METHODDEF
6465 #define OS_PUTENV_METHODDEF
6466#endif /* !defined(OS_PUTENV_METHODDEF) */
6467
6468#ifndef OS_UNSETENV_METHODDEF
6469 #define OS_UNSETENV_METHODDEF
6470#endif /* !defined(OS_UNSETENV_METHODDEF) */
6471
6472#ifndef OS_WCOREDUMP_METHODDEF
6473 #define OS_WCOREDUMP_METHODDEF
6474#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6475
6476#ifndef OS_WIFCONTINUED_METHODDEF
6477 #define OS_WIFCONTINUED_METHODDEF
6478#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6479
6480#ifndef OS_WIFSTOPPED_METHODDEF
6481 #define OS_WIFSTOPPED_METHODDEF
6482#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6483
6484#ifndef OS_WIFSIGNALED_METHODDEF
6485 #define OS_WIFSIGNALED_METHODDEF
6486#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6487
6488#ifndef OS_WIFEXITED_METHODDEF
6489 #define OS_WIFEXITED_METHODDEF
6490#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6491
6492#ifndef OS_WEXITSTATUS_METHODDEF
6493 #define OS_WEXITSTATUS_METHODDEF
6494#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6495
6496#ifndef OS_WTERMSIG_METHODDEF
6497 #define OS_WTERMSIG_METHODDEF
6498#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6499
6500#ifndef OS_WSTOPSIG_METHODDEF
6501 #define OS_WSTOPSIG_METHODDEF
6502#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6503
6504#ifndef OS_FSTATVFS_METHODDEF
6505 #define OS_FSTATVFS_METHODDEF
6506#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6507
6508#ifndef OS_STATVFS_METHODDEF
6509 #define OS_STATVFS_METHODDEF
6510#endif /* !defined(OS_STATVFS_METHODDEF) */
6511
6512#ifndef OS__GETDISKUSAGE_METHODDEF
6513 #define OS__GETDISKUSAGE_METHODDEF
6514#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6515
6516#ifndef OS_FPATHCONF_METHODDEF
6517 #define OS_FPATHCONF_METHODDEF
6518#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6519
6520#ifndef OS_PATHCONF_METHODDEF
6521 #define OS_PATHCONF_METHODDEF
6522#endif /* !defined(OS_PATHCONF_METHODDEF) */
6523
6524#ifndef OS_CONFSTR_METHODDEF
6525 #define OS_CONFSTR_METHODDEF
6526#endif /* !defined(OS_CONFSTR_METHODDEF) */
6527
6528#ifndef OS_SYSCONF_METHODDEF
6529 #define OS_SYSCONF_METHODDEF
6530#endif /* !defined(OS_SYSCONF_METHODDEF) */
6531
Steve Dowercc16be82016-09-08 10:35:16 -07006532#ifndef OS_STARTFILE_METHODDEF
6533 #define OS_STARTFILE_METHODDEF
6534#endif /* !defined(OS_STARTFILE_METHODDEF) */
6535
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006536#ifndef OS_GETLOADAVG_METHODDEF
6537 #define OS_GETLOADAVG_METHODDEF
6538#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6539
6540#ifndef OS_SETRESUID_METHODDEF
6541 #define OS_SETRESUID_METHODDEF
6542#endif /* !defined(OS_SETRESUID_METHODDEF) */
6543
6544#ifndef OS_SETRESGID_METHODDEF
6545 #define OS_SETRESGID_METHODDEF
6546#endif /* !defined(OS_SETRESGID_METHODDEF) */
6547
6548#ifndef OS_GETRESUID_METHODDEF
6549 #define OS_GETRESUID_METHODDEF
6550#endif /* !defined(OS_GETRESUID_METHODDEF) */
6551
6552#ifndef OS_GETRESGID_METHODDEF
6553 #define OS_GETRESGID_METHODDEF
6554#endif /* !defined(OS_GETRESGID_METHODDEF) */
6555
6556#ifndef OS_GETXATTR_METHODDEF
6557 #define OS_GETXATTR_METHODDEF
6558#endif /* !defined(OS_GETXATTR_METHODDEF) */
6559
6560#ifndef OS_SETXATTR_METHODDEF
6561 #define OS_SETXATTR_METHODDEF
6562#endif /* !defined(OS_SETXATTR_METHODDEF) */
6563
6564#ifndef OS_REMOVEXATTR_METHODDEF
6565 #define OS_REMOVEXATTR_METHODDEF
6566#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6567
6568#ifndef OS_LISTXATTR_METHODDEF
6569 #define OS_LISTXATTR_METHODDEF
6570#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6571
6572#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6573 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6574#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6575
6576#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6577 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6578#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006579
6580#ifndef OS_GETRANDOM_METHODDEF
6581 #define OS_GETRANDOM_METHODDEF
6582#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006583/*[clinic end generated code: output=8e5d4a01257b6292 input=a9049054013a1b77]*/