blob: 4054389d15f33e21117521a16a2713f70039f60d [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 *
Steve Dower23ad6d02018-02-22 10:39:10 -0800975os__getfinalpathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300976
977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300978os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300979{
980 PyObject *return_value = NULL;
Steve Dower23ad6d02018-02-22 10:39:10 -0800981 path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300982
Steve Dower23ad6d02018-02-22 10:39:10 -0800983 if (!PyArg_Parse(arg, "O&:_getfinalpathname", path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300985 }
Steve Dower23ad6d02018-02-22 10:39:10 -0800986 return_value = os__getfinalpathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300987
988exit:
Steve Dower23ad6d02018-02-22 10:39:10 -0800989 /* Cleanup for path */
990 path_cleanup(&path);
991
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300992 return return_value;
993}
994
995#endif /* defined(MS_WINDOWS) */
996
997#if defined(MS_WINDOWS)
998
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300999PyDoc_STRVAR(os__isdir__doc__,
1000"_isdir($module, path, /)\n"
1001"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +02001002"\n"
1003"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001004
1005#define OS__ISDIR_METHODDEF \
1006 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1007
1008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001009os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001010
1011static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001012os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001013{
1014 PyObject *return_value = NULL;
1015 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1016
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001017 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001018 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001019 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001020 return_value = os__isdir_impl(module, &path);
1021
1022exit:
1023 /* Cleanup for path */
1024 path_cleanup(&path);
1025
1026 return return_value;
1027}
1028
1029#endif /* defined(MS_WINDOWS) */
1030
1031#if defined(MS_WINDOWS)
1032
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001033PyDoc_STRVAR(os__getvolumepathname__doc__,
1034"_getvolumepathname($module, /, path)\n"
1035"--\n"
1036"\n"
1037"A helper function for ismount on Win32.");
1038
1039#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001040 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001041
1042static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08001043os__getvolumepathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001044
1045static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001046os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001047{
1048 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001049 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08001050 static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0};
1051 path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052
Victor Stinner3e1fad62017-01-17 01:29:01 +01001053 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08001054 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001055 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001056 }
Steve Dower23ad6d02018-02-22 10:39:10 -08001057 return_value = os__getvolumepathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001058
1059exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08001060 /* Cleanup for path */
1061 path_cleanup(&path);
1062
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001063 return return_value;
1064}
1065
1066#endif /* defined(MS_WINDOWS) */
1067
1068PyDoc_STRVAR(os_mkdir__doc__,
1069"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1070"--\n"
1071"\n"
1072"Create a directory.\n"
1073"\n"
1074"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1075" and path should be relative; path will then be relative to that directory.\n"
1076"dir_fd may not be implemented on your platform.\n"
1077" If it is unavailable, using it will raise a NotImplementedError.\n"
1078"\n"
1079"The mode argument is ignored on Windows.");
1080
1081#define OS_MKDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001082 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001083
1084static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001085os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001086
1087static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001088os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001089{
1090 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001091 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1092 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1094 int mode = 511;
1095 int dir_fd = DEFAULT_DIR_FD;
1096
Victor Stinner3e1fad62017-01-17 01:29:01 +01001097 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001098 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001099 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001100 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001101 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1102
1103exit:
1104 /* Cleanup for path */
1105 path_cleanup(&path);
1106
1107 return return_value;
1108}
1109
1110#if defined(HAVE_NICE)
1111
1112PyDoc_STRVAR(os_nice__doc__,
1113"nice($module, increment, /)\n"
1114"--\n"
1115"\n"
1116"Add increment to the priority of process and return the new priority.");
1117
1118#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001119 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001120
1121static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001122os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001123
1124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001125os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001126{
1127 PyObject *return_value = NULL;
1128 int increment;
1129
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001130 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001131 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001132 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001133 return_value = os_nice_impl(module, increment);
1134
1135exit:
1136 return return_value;
1137}
1138
1139#endif /* defined(HAVE_NICE) */
1140
1141#if defined(HAVE_GETPRIORITY)
1142
1143PyDoc_STRVAR(os_getpriority__doc__,
1144"getpriority($module, /, which, who)\n"
1145"--\n"
1146"\n"
1147"Return program scheduling priority.");
1148
1149#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001150 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001151
1152static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001153os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001154
1155static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001156os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001157{
1158 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001159 static const char * const _keywords[] = {"which", "who", NULL};
1160 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001161 int which;
1162 int who;
1163
Victor Stinner3e1fad62017-01-17 01:29:01 +01001164 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001165 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001166 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001167 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001168 return_value = os_getpriority_impl(module, which, who);
1169
1170exit:
1171 return return_value;
1172}
1173
1174#endif /* defined(HAVE_GETPRIORITY) */
1175
1176#if defined(HAVE_SETPRIORITY)
1177
1178PyDoc_STRVAR(os_setpriority__doc__,
1179"setpriority($module, /, which, who, priority)\n"
1180"--\n"
1181"\n"
1182"Set program scheduling priority.");
1183
1184#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001185 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001186
1187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001188os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001189
1190static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001191os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001192{
1193 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001194 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1195 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 int which;
1197 int who;
1198 int priority;
1199
Victor Stinner3e1fad62017-01-17 01:29:01 +01001200 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001201 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001202 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001203 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001204 return_value = os_setpriority_impl(module, which, who, priority);
1205
1206exit:
1207 return return_value;
1208}
1209
1210#endif /* defined(HAVE_SETPRIORITY) */
1211
1212PyDoc_STRVAR(os_rename__doc__,
1213"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1214"--\n"
1215"\n"
1216"Rename a file or directory.\n"
1217"\n"
1218"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1219" descriptor open to a directory, and the respective path string (src or dst)\n"
1220" should be relative; the path will then be relative to that directory.\n"
1221"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1222" If they are unavailable, using them will raise a NotImplementedError.");
1223
1224#define OS_RENAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001225 {"rename", (PyCFunction)os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001226
1227static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001228os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001229 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001230
1231static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001232os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001233{
1234 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001235 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1236 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001237 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1238 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1239 int src_dir_fd = DEFAULT_DIR_FD;
1240 int dst_dir_fd = DEFAULT_DIR_FD;
1241
Victor Stinner3e1fad62017-01-17 01:29:01 +01001242 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001243 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 +03001244 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001245 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001246 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1247
1248exit:
1249 /* Cleanup for src */
1250 path_cleanup(&src);
1251 /* Cleanup for dst */
1252 path_cleanup(&dst);
1253
1254 return return_value;
1255}
1256
1257PyDoc_STRVAR(os_replace__doc__,
1258"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1259"--\n"
1260"\n"
1261"Rename a file or directory, overwriting the destination.\n"
1262"\n"
1263"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1264" descriptor open to a directory, and the respective path string (src or dst)\n"
1265" should be relative; the path will then be relative to that directory.\n"
1266"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1267" If they are unavailable, using them will raise a NotImplementedError.\"");
1268
1269#define OS_REPLACE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001270 {"replace", (PyCFunction)os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001271
1272static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001273os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1274 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001275
1276static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001277os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001278{
1279 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001280 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1281 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001282 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1283 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1284 int src_dir_fd = DEFAULT_DIR_FD;
1285 int dst_dir_fd = DEFAULT_DIR_FD;
1286
Victor Stinner3e1fad62017-01-17 01:29:01 +01001287 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001288 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 +03001289 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001290 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001291 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1292
1293exit:
1294 /* Cleanup for src */
1295 path_cleanup(&src);
1296 /* Cleanup for dst */
1297 path_cleanup(&dst);
1298
1299 return return_value;
1300}
1301
1302PyDoc_STRVAR(os_rmdir__doc__,
1303"rmdir($module, /, path, *, dir_fd=None)\n"
1304"--\n"
1305"\n"
1306"Remove a directory.\n"
1307"\n"
1308"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1309" and path should be relative; path will then be relative to that directory.\n"
1310"dir_fd may not be implemented on your platform.\n"
1311" If it is unavailable, using it will raise a NotImplementedError.");
1312
1313#define OS_RMDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001314 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001315
1316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001317os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001318
1319static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001320os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001321{
1322 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001323 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1324 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001325 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1326 int dir_fd = DEFAULT_DIR_FD;
1327
Victor Stinner3e1fad62017-01-17 01:29:01 +01001328 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001329 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001330 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001331 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001332 return_value = os_rmdir_impl(module, &path, dir_fd);
1333
1334exit:
1335 /* Cleanup for path */
1336 path_cleanup(&path);
1337
1338 return return_value;
1339}
1340
1341#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1342
1343PyDoc_STRVAR(os_system__doc__,
1344"system($module, /, command)\n"
1345"--\n"
1346"\n"
1347"Execute the command in a subshell.");
1348
1349#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001350 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001351
1352static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001353os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001354
1355static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001356os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001357{
1358 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001359 static const char * const _keywords[] = {"command", NULL};
1360 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001361 Py_UNICODE *command;
1362 long _return_value;
1363
Victor Stinner3e1fad62017-01-17 01:29:01 +01001364 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001365 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001366 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001367 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001368 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001369 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001370 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001371 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001372 return_value = PyLong_FromLong(_return_value);
1373
1374exit:
1375 return return_value;
1376}
1377
1378#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1379
1380#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1381
1382PyDoc_STRVAR(os_system__doc__,
1383"system($module, /, command)\n"
1384"--\n"
1385"\n"
1386"Execute the command in a subshell.");
1387
1388#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001389 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390
1391static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001392os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001393
1394static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001395os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001396{
1397 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001398 static const char * const _keywords[] = {"command", NULL};
1399 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001400 PyObject *command = NULL;
1401 long _return_value;
1402
Victor Stinner3e1fad62017-01-17 01:29:01 +01001403 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001404 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001405 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001406 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001407 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001408 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001409 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001410 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001411 return_value = PyLong_FromLong(_return_value);
1412
1413exit:
1414 /* Cleanup for command */
1415 Py_XDECREF(command);
1416
1417 return return_value;
1418}
1419
1420#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1421
1422PyDoc_STRVAR(os_umask__doc__,
1423"umask($module, mask, /)\n"
1424"--\n"
1425"\n"
1426"Set the current numeric umask and return the previous umask.");
1427
1428#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001429 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001430
1431static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001432os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001433
1434static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001435os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001436{
1437 PyObject *return_value = NULL;
1438 int mask;
1439
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001440 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001441 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001442 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001443 return_value = os_umask_impl(module, mask);
1444
1445exit:
1446 return return_value;
1447}
1448
1449PyDoc_STRVAR(os_unlink__doc__,
1450"unlink($module, /, path, *, dir_fd=None)\n"
1451"--\n"
1452"\n"
1453"Remove a file (same as remove()).\n"
1454"\n"
1455"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1456" and path should be relative; path will then be relative to that directory.\n"
1457"dir_fd may not be implemented on your platform.\n"
1458" If it is unavailable, using it will raise a NotImplementedError.");
1459
1460#define OS_UNLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001461 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001462
1463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001464os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001465
1466static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001467os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001468{
1469 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001470 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1471 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001472 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1473 int dir_fd = DEFAULT_DIR_FD;
1474
Victor Stinner3e1fad62017-01-17 01:29:01 +01001475 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001476 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001477 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001478 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001479 return_value = os_unlink_impl(module, &path, dir_fd);
1480
1481exit:
1482 /* Cleanup for path */
1483 path_cleanup(&path);
1484
1485 return return_value;
1486}
1487
1488PyDoc_STRVAR(os_remove__doc__,
1489"remove($module, /, path, *, dir_fd=None)\n"
1490"--\n"
1491"\n"
1492"Remove a file (same as unlink()).\n"
1493"\n"
1494"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1495" and path should be relative; path will then be relative to that directory.\n"
1496"dir_fd may not be implemented on your platform.\n"
1497" If it is unavailable, using it will raise a NotImplementedError.");
1498
1499#define OS_REMOVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001500 {"remove", (PyCFunction)os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001501
1502static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001503os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001504
1505static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001506os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001507{
1508 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001509 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1510 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001511 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1512 int dir_fd = DEFAULT_DIR_FD;
1513
Victor Stinner3e1fad62017-01-17 01:29:01 +01001514 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001515 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001516 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001517 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001518 return_value = os_remove_impl(module, &path, dir_fd);
1519
1520exit:
1521 /* Cleanup for path */
1522 path_cleanup(&path);
1523
1524 return return_value;
1525}
1526
1527#if defined(HAVE_UNAME)
1528
1529PyDoc_STRVAR(os_uname__doc__,
1530"uname($module, /)\n"
1531"--\n"
1532"\n"
1533"Return an object identifying the current operating system.\n"
1534"\n"
1535"The object behaves like a named tuple with the following fields:\n"
1536" (sysname, nodename, release, version, machine)");
1537
1538#define OS_UNAME_METHODDEF \
1539 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1540
1541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001542os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001543
1544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001545os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001546{
1547 return os_uname_impl(module);
1548}
1549
1550#endif /* defined(HAVE_UNAME) */
1551
1552PyDoc_STRVAR(os_utime__doc__,
1553"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1554" follow_symlinks=True)\n"
1555"--\n"
1556"\n"
1557"Set the access and modified time of path.\n"
1558"\n"
1559"path may always be specified as a string.\n"
1560"On some platforms, path may also be specified as an open file descriptor.\n"
1561" If this functionality is unavailable, using it raises an exception.\n"
1562"\n"
1563"If times is not None, it must be a tuple (atime, mtime);\n"
1564" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001565"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001566" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1567" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001568"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001569"Specifying tuples for both times and ns is an error.\n"
1570"\n"
1571"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1572" and path should be relative; path will then be relative to that directory.\n"
1573"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1574" link, utime will modify the symbolic link itself instead of the file the\n"
1575" link points to.\n"
1576"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1577" as an open file descriptor.\n"
1578"dir_fd and follow_symlinks may not be available on your platform.\n"
1579" If they are unavailable, using them will raise a NotImplementedError.");
1580
1581#define OS_UTIME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001582 {"utime", (PyCFunction)os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001583
1584static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001585os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1586 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001587
1588static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001589os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001590{
1591 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001592 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1593 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001594 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1595 PyObject *times = NULL;
1596 PyObject *ns = NULL;
1597 int dir_fd = DEFAULT_DIR_FD;
1598 int follow_symlinks = 1;
1599
Victor Stinner3e1fad62017-01-17 01:29:01 +01001600 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001601 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001602 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001604 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1605
1606exit:
1607 /* Cleanup for path */
1608 path_cleanup(&path);
1609
1610 return return_value;
1611}
1612
1613PyDoc_STRVAR(os__exit__doc__,
1614"_exit($module, /, status)\n"
1615"--\n"
1616"\n"
1617"Exit to the system with specified status, without normal exit processing.");
1618
1619#define OS__EXIT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001620 {"_exit", (PyCFunction)os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001621
1622static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001623os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001624
1625static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001626os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001627{
1628 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001629 static const char * const _keywords[] = {"status", NULL};
1630 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001631 int status;
1632
Victor Stinner3e1fad62017-01-17 01:29:01 +01001633 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001634 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001635 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001636 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001637 return_value = os__exit_impl(module, status);
1638
1639exit:
1640 return return_value;
1641}
1642
1643#if defined(HAVE_EXECV)
1644
1645PyDoc_STRVAR(os_execv__doc__,
1646"execv($module, path, argv, /)\n"
1647"--\n"
1648"\n"
1649"Execute an executable path with arguments, replacing current process.\n"
1650"\n"
1651" path\n"
1652" Path of executable file.\n"
1653" argv\n"
1654" Tuple or list of strings.");
1655
1656#define OS_EXECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001657 {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001658
1659static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001660os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001661
1662static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001663os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001664{
1665 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001666 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001667 PyObject *argv;
1668
Sylvain74453812017-06-10 06:51:48 +02001669 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
1670 path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001671 goto exit;
1672 }
Steve Dowercc16be82016-09-08 10:35:16 -07001673 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001674
1675exit:
1676 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001677 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001678
1679 return return_value;
1680}
1681
1682#endif /* defined(HAVE_EXECV) */
1683
1684#if defined(HAVE_EXECV)
1685
1686PyDoc_STRVAR(os_execve__doc__,
1687"execve($module, /, path, argv, env)\n"
1688"--\n"
1689"\n"
1690"Execute an executable path with arguments, replacing current process.\n"
1691"\n"
1692" path\n"
1693" Path of executable file.\n"
1694" argv\n"
1695" Tuple or list of strings.\n"
1696" env\n"
1697" Dictionary of strings mapping to strings.");
1698
1699#define OS_EXECVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001700 {"execve", (PyCFunction)os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001701
1702static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001703os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001704
1705static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001706os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001707{
1708 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001709 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1710 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001711 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1712 PyObject *argv;
1713 PyObject *env;
1714
Victor Stinner3e1fad62017-01-17 01:29:01 +01001715 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001716 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001717 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001718 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001719 return_value = os_execve_impl(module, &path, argv, env);
1720
1721exit:
1722 /* Cleanup for path */
1723 path_cleanup(&path);
1724
1725 return return_value;
1726}
1727
1728#endif /* defined(HAVE_EXECV) */
1729
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001730#if defined(HAVE_POSIX_SPAWN)
1731
1732PyDoc_STRVAR(os_posix_spawn__doc__,
1733"posix_spawn($module, path, argv, env, file_actions=None, /)\n"
1734"--\n"
1735"\n"
1736"Execute the program specified by path in a new process.\n"
1737"\n"
1738" path\n"
1739" Path of executable file.\n"
1740" argv\n"
1741" Tuple or list of strings.\n"
1742" env\n"
1743" Dictionary of strings mapping to strings.\n"
1744" file_actions\n"
1745" FileActions object.");
1746
1747#define OS_POSIX_SPAWN_METHODDEF \
1748 {"posix_spawn", (PyCFunction)os_posix_spawn, METH_FASTCALL, os_posix_spawn__doc__},
1749
1750static PyObject *
1751os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
1752 PyObject *env, PyObject *file_actions);
1753
1754static PyObject *
1755os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1756{
1757 PyObject *return_value = NULL;
1758 path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
1759 PyObject *argv;
1760 PyObject *env;
1761 PyObject *file_actions = Py_None;
1762
1763 if (!_PyArg_ParseStack(args, nargs, "O&OO|O:posix_spawn",
1764 path_converter, &path, &argv, &env, &file_actions)) {
1765 goto exit;
1766 }
1767 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions);
1768
1769exit:
1770 /* Cleanup for path */
1771 path_cleanup(&path);
1772
1773 return return_value;
1774}
1775
1776#endif /* defined(HAVE_POSIX_SPAWN) */
1777
Steve Dowercc16be82016-09-08 10:35:16 -07001778#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001779
1780PyDoc_STRVAR(os_spawnv__doc__,
1781"spawnv($module, mode, path, argv, /)\n"
1782"--\n"
1783"\n"
1784"Execute the program specified by path in a new process.\n"
1785"\n"
1786" mode\n"
1787" Mode of process creation.\n"
1788" path\n"
1789" Path of executable file.\n"
1790" argv\n"
1791" Tuple or list of strings.");
1792
1793#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001794 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001795
1796static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001797os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001798
1799static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001800os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001801{
1802 PyObject *return_value = NULL;
1803 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001804 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001805 PyObject *argv;
1806
Sylvain74453812017-06-10 06:51:48 +02001807 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1808 &mode, path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001809 goto exit;
1810 }
Steve Dowercc16be82016-09-08 10:35:16 -07001811 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001812
1813exit:
1814 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001815 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001816
1817 return return_value;
1818}
1819
Steve Dowercc16be82016-09-08 10:35:16 -07001820#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001821
Steve Dowercc16be82016-09-08 10:35:16 -07001822#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001823
1824PyDoc_STRVAR(os_spawnve__doc__,
1825"spawnve($module, mode, path, argv, env, /)\n"
1826"--\n"
1827"\n"
1828"Execute the program specified by path in a new process.\n"
1829"\n"
1830" mode\n"
1831" Mode of process creation.\n"
1832" path\n"
1833" Path of executable file.\n"
1834" argv\n"
1835" Tuple or list of strings.\n"
1836" env\n"
1837" Dictionary of strings mapping to strings.");
1838
1839#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001840 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001841
1842static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001843os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001844 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001845
1846static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001847os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001848{
1849 PyObject *return_value = NULL;
1850 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001851 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001852 PyObject *argv;
1853 PyObject *env;
1854
Sylvain74453812017-06-10 06:51:48 +02001855 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1856 &mode, path_converter, &path, &argv, &env)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001857 goto exit;
1858 }
Steve Dowercc16be82016-09-08 10:35:16 -07001859 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001860
1861exit:
1862 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001863 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001864
1865 return return_value;
1866}
1867
Steve Dowercc16be82016-09-08 10:35:16 -07001868#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001869
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001870#if defined(HAVE_FORK)
1871
1872PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001873"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1874" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001875"--\n"
1876"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001877"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001878"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001879" before\n"
1880" A callable to be called in the parent before the fork() syscall.\n"
1881" after_in_child\n"
1882" A callable to be called in the child after fork().\n"
1883" after_in_parent\n"
1884" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001885"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001886"\'before\' callbacks are called in reverse order.\n"
1887"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001888
1889#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001890 {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001891
1892static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001893os_register_at_fork_impl(PyObject *module, PyObject *before,
1894 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001895
1896static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001897os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001898{
1899 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001900 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1901 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1902 PyObject *before = NULL;
1903 PyObject *after_in_child = NULL;
1904 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001905
1906 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001907 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001908 goto exit;
1909 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001910 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001911
1912exit:
1913 return return_value;
1914}
1915
1916#endif /* defined(HAVE_FORK) */
1917
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001918#if defined(HAVE_FORK1)
1919
1920PyDoc_STRVAR(os_fork1__doc__,
1921"fork1($module, /)\n"
1922"--\n"
1923"\n"
1924"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1925"\n"
1926"Return 0 to child process and PID of child to parent process.");
1927
1928#define OS_FORK1_METHODDEF \
1929 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1930
1931static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001932os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001933
1934static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001935os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001936{
1937 return os_fork1_impl(module);
1938}
1939
1940#endif /* defined(HAVE_FORK1) */
1941
1942#if defined(HAVE_FORK)
1943
1944PyDoc_STRVAR(os_fork__doc__,
1945"fork($module, /)\n"
1946"--\n"
1947"\n"
1948"Fork a child process.\n"
1949"\n"
1950"Return 0 to child process and PID of child to parent process.");
1951
1952#define OS_FORK_METHODDEF \
1953 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1954
1955static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001956os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001957
1958static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001959os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001960{
1961 return os_fork_impl(module);
1962}
1963
1964#endif /* defined(HAVE_FORK) */
1965
1966#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1967
1968PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1969"sched_get_priority_max($module, /, policy)\n"
1970"--\n"
1971"\n"
1972"Get the maximum scheduling priority for policy.");
1973
1974#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001975 {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001976
1977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001978os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001979
1980static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001981os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001982{
1983 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001984 static const char * const _keywords[] = {"policy", NULL};
1985 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001986 int policy;
1987
Victor Stinner3e1fad62017-01-17 01:29:01 +01001988 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001989 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001990 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001991 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001992 return_value = os_sched_get_priority_max_impl(module, policy);
1993
1994exit:
1995 return return_value;
1996}
1997
1998#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1999
2000#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2001
2002PyDoc_STRVAR(os_sched_get_priority_min__doc__,
2003"sched_get_priority_min($module, /, policy)\n"
2004"--\n"
2005"\n"
2006"Get the minimum scheduling priority for policy.");
2007
2008#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002009 {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002010
2011static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002012os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002013
2014static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002015os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002016{
2017 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002018 static const char * const _keywords[] = {"policy", NULL};
2019 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002020 int policy;
2021
Victor Stinner3e1fad62017-01-17 01:29:01 +01002022 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002023 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002024 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002025 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002026 return_value = os_sched_get_priority_min_impl(module, policy);
2027
2028exit:
2029 return return_value;
2030}
2031
2032#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2033
2034#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2035
2036PyDoc_STRVAR(os_sched_getscheduler__doc__,
2037"sched_getscheduler($module, pid, /)\n"
2038"--\n"
2039"\n"
2040"Get the scheduling policy for the process identifiedy by pid.\n"
2041"\n"
2042"Passing 0 for pid returns the scheduling policy for the calling process.");
2043
2044#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002045 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002046
2047static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002048os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002049
2050static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002051os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002052{
2053 PyObject *return_value = NULL;
2054 pid_t pid;
2055
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002056 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002057 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002058 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002059 return_value = os_sched_getscheduler_impl(module, pid);
2060
2061exit:
2062 return return_value;
2063}
2064
2065#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2066
2067#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
2068
2069PyDoc_STRVAR(os_sched_param__doc__,
2070"sched_param(sched_priority)\n"
2071"--\n"
2072"\n"
2073"Current has only one field: sched_priority\");\n"
2074"\n"
2075" sched_priority\n"
2076" A scheduling parameter.");
2077
2078static PyObject *
2079os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2080
2081static PyObject *
2082os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2083{
2084 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002085 static const char * const _keywords[] = {"sched_priority", NULL};
2086 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002087 PyObject *sched_priority;
2088
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002089 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002090 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002091 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002092 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002093 return_value = os_sched_param_impl(type, sched_priority);
2094
2095exit:
2096 return return_value;
2097}
2098
2099#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2100
2101#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2102
2103PyDoc_STRVAR(os_sched_setscheduler__doc__,
2104"sched_setscheduler($module, pid, policy, param, /)\n"
2105"--\n"
2106"\n"
2107"Set the scheduling policy for the process identified by pid.\n"
2108"\n"
2109"If pid is 0, the calling process is changed.\n"
2110"param is an instance of sched_param.");
2111
2112#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002113 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002114
2115static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002116os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002117 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002118
2119static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002120os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002121{
2122 PyObject *return_value = NULL;
2123 pid_t pid;
2124 int policy;
2125 struct sched_param param;
2126
Sylvain74453812017-06-10 06:51:48 +02002127 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2128 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002129 goto exit;
2130 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002131 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2132
2133exit:
2134 return return_value;
2135}
2136
2137#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2138
2139#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2140
2141PyDoc_STRVAR(os_sched_getparam__doc__,
2142"sched_getparam($module, pid, /)\n"
2143"--\n"
2144"\n"
2145"Returns scheduling parameters for the process identified by pid.\n"
2146"\n"
2147"If pid is 0, returns parameters for the calling process.\n"
2148"Return value is an instance of sched_param.");
2149
2150#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002151 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002152
2153static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002154os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002155
2156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002157os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002158{
2159 PyObject *return_value = NULL;
2160 pid_t pid;
2161
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002162 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002163 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002164 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002165 return_value = os_sched_getparam_impl(module, pid);
2166
2167exit:
2168 return return_value;
2169}
2170
2171#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2172
2173#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2174
2175PyDoc_STRVAR(os_sched_setparam__doc__,
2176"sched_setparam($module, pid, param, /)\n"
2177"--\n"
2178"\n"
2179"Set scheduling parameters for the process identified by pid.\n"
2180"\n"
2181"If pid is 0, sets parameters for the calling process.\n"
2182"param should be an instance of sched_param.");
2183
2184#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002185 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002186
2187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002188os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002189 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002190
2191static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002192os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002193{
2194 PyObject *return_value = NULL;
2195 pid_t pid;
2196 struct sched_param param;
2197
Sylvain74453812017-06-10 06:51:48 +02002198 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2199 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002200 goto exit;
2201 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002202 return_value = os_sched_setparam_impl(module, pid, &param);
2203
2204exit:
2205 return return_value;
2206}
2207
2208#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2209
2210#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2211
2212PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2213"sched_rr_get_interval($module, pid, /)\n"
2214"--\n"
2215"\n"
2216"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2217"\n"
2218"Value returned is a float.");
2219
2220#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002221 {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002222
2223static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002224os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002225
2226static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002227os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002228{
2229 PyObject *return_value = NULL;
2230 pid_t pid;
2231 double _return_value;
2232
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002233 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002234 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002235 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002236 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002237 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002238 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002239 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002240 return_value = PyFloat_FromDouble(_return_value);
2241
2242exit:
2243 return return_value;
2244}
2245
2246#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2247
2248#if defined(HAVE_SCHED_H)
2249
2250PyDoc_STRVAR(os_sched_yield__doc__,
2251"sched_yield($module, /)\n"
2252"--\n"
2253"\n"
2254"Voluntarily relinquish the CPU.");
2255
2256#define OS_SCHED_YIELD_METHODDEF \
2257 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2258
2259static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002260os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002261
2262static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002263os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002264{
2265 return os_sched_yield_impl(module);
2266}
2267
2268#endif /* defined(HAVE_SCHED_H) */
2269
2270#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2271
2272PyDoc_STRVAR(os_sched_setaffinity__doc__,
2273"sched_setaffinity($module, pid, mask, /)\n"
2274"--\n"
2275"\n"
2276"Set the CPU affinity of the process identified by pid to mask.\n"
2277"\n"
2278"mask should be an iterable of integers identifying CPUs.");
2279
2280#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002281 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002282
2283static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002284os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002285
2286static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002287os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002288{
2289 PyObject *return_value = NULL;
2290 pid_t pid;
2291 PyObject *mask;
2292
Sylvain74453812017-06-10 06:51:48 +02002293 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2294 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002295 goto exit;
2296 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002297 return_value = os_sched_setaffinity_impl(module, pid, mask);
2298
2299exit:
2300 return return_value;
2301}
2302
2303#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2304
2305#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2306
2307PyDoc_STRVAR(os_sched_getaffinity__doc__,
2308"sched_getaffinity($module, pid, /)\n"
2309"--\n"
2310"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002311"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002312"\n"
2313"The affinity is returned as a set of CPU identifiers.");
2314
2315#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002316 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002317
2318static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002319os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002320
2321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002322os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002323{
2324 PyObject *return_value = NULL;
2325 pid_t pid;
2326
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002327 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002328 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002329 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002330 return_value = os_sched_getaffinity_impl(module, pid);
2331
2332exit:
2333 return return_value;
2334}
2335
2336#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2337
2338#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2339
2340PyDoc_STRVAR(os_openpty__doc__,
2341"openpty($module, /)\n"
2342"--\n"
2343"\n"
2344"Open a pseudo-terminal.\n"
2345"\n"
2346"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2347"for both the master and slave ends.");
2348
2349#define OS_OPENPTY_METHODDEF \
2350 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2351
2352static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002353os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002354
2355static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002356os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002357{
2358 return os_openpty_impl(module);
2359}
2360
2361#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2362
2363#if defined(HAVE_FORKPTY)
2364
2365PyDoc_STRVAR(os_forkpty__doc__,
2366"forkpty($module, /)\n"
2367"--\n"
2368"\n"
2369"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2370"\n"
2371"Returns a tuple of (pid, master_fd).\n"
2372"Like fork(), return pid of 0 to the child process,\n"
2373"and pid of child to the parent process.\n"
2374"To both, return fd of newly opened pseudo-terminal.");
2375
2376#define OS_FORKPTY_METHODDEF \
2377 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2378
2379static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002380os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002381
2382static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002383os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002384{
2385 return os_forkpty_impl(module);
2386}
2387
2388#endif /* defined(HAVE_FORKPTY) */
2389
2390#if defined(HAVE_GETEGID)
2391
2392PyDoc_STRVAR(os_getegid__doc__,
2393"getegid($module, /)\n"
2394"--\n"
2395"\n"
2396"Return the current process\'s effective group id.");
2397
2398#define OS_GETEGID_METHODDEF \
2399 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2400
2401static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002402os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002403
2404static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002405os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002406{
2407 return os_getegid_impl(module);
2408}
2409
2410#endif /* defined(HAVE_GETEGID) */
2411
2412#if defined(HAVE_GETEUID)
2413
2414PyDoc_STRVAR(os_geteuid__doc__,
2415"geteuid($module, /)\n"
2416"--\n"
2417"\n"
2418"Return the current process\'s effective user id.");
2419
2420#define OS_GETEUID_METHODDEF \
2421 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2422
2423static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002424os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002425
2426static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002427os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002428{
2429 return os_geteuid_impl(module);
2430}
2431
2432#endif /* defined(HAVE_GETEUID) */
2433
2434#if defined(HAVE_GETGID)
2435
2436PyDoc_STRVAR(os_getgid__doc__,
2437"getgid($module, /)\n"
2438"--\n"
2439"\n"
2440"Return the current process\'s group id.");
2441
2442#define OS_GETGID_METHODDEF \
2443 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2444
2445static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002446os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002447
2448static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002449os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002450{
2451 return os_getgid_impl(module);
2452}
2453
2454#endif /* defined(HAVE_GETGID) */
2455
Berker Peksag39404992016-09-15 20:45:16 +03002456#if defined(HAVE_GETPID)
2457
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002458PyDoc_STRVAR(os_getpid__doc__,
2459"getpid($module, /)\n"
2460"--\n"
2461"\n"
2462"Return the current process id.");
2463
2464#define OS_GETPID_METHODDEF \
2465 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2466
2467static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002468os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002469
2470static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002471os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002472{
2473 return os_getpid_impl(module);
2474}
2475
Berker Peksag39404992016-09-15 20:45:16 +03002476#endif /* defined(HAVE_GETPID) */
2477
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002478#if defined(HAVE_GETGROUPS)
2479
2480PyDoc_STRVAR(os_getgroups__doc__,
2481"getgroups($module, /)\n"
2482"--\n"
2483"\n"
2484"Return list of supplemental group IDs for the process.");
2485
2486#define OS_GETGROUPS_METHODDEF \
2487 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2488
2489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002490os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002491
2492static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002493os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002494{
2495 return os_getgroups_impl(module);
2496}
2497
2498#endif /* defined(HAVE_GETGROUPS) */
2499
2500#if defined(HAVE_GETPGID)
2501
2502PyDoc_STRVAR(os_getpgid__doc__,
2503"getpgid($module, /, pid)\n"
2504"--\n"
2505"\n"
2506"Call the system call getpgid(), and return the result.");
2507
2508#define OS_GETPGID_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002509 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002510
2511static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002512os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002513
2514static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002515os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002516{
2517 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002518 static const char * const _keywords[] = {"pid", NULL};
2519 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002520 pid_t pid;
2521
Victor Stinner3e1fad62017-01-17 01:29:01 +01002522 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002523 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002524 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002525 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002526 return_value = os_getpgid_impl(module, pid);
2527
2528exit:
2529 return return_value;
2530}
2531
2532#endif /* defined(HAVE_GETPGID) */
2533
2534#if defined(HAVE_GETPGRP)
2535
2536PyDoc_STRVAR(os_getpgrp__doc__,
2537"getpgrp($module, /)\n"
2538"--\n"
2539"\n"
2540"Return the current process group id.");
2541
2542#define OS_GETPGRP_METHODDEF \
2543 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2544
2545static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002546os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002547
2548static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002549os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002550{
2551 return os_getpgrp_impl(module);
2552}
2553
2554#endif /* defined(HAVE_GETPGRP) */
2555
2556#if defined(HAVE_SETPGRP)
2557
2558PyDoc_STRVAR(os_setpgrp__doc__,
2559"setpgrp($module, /)\n"
2560"--\n"
2561"\n"
2562"Make the current process the leader of its process group.");
2563
2564#define OS_SETPGRP_METHODDEF \
2565 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2566
2567static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002568os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002569
2570static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002571os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002572{
2573 return os_setpgrp_impl(module);
2574}
2575
2576#endif /* defined(HAVE_SETPGRP) */
2577
2578#if defined(HAVE_GETPPID)
2579
2580PyDoc_STRVAR(os_getppid__doc__,
2581"getppid($module, /)\n"
2582"--\n"
2583"\n"
2584"Return the parent\'s process id.\n"
2585"\n"
2586"If the parent process has already exited, Windows machines will still\n"
2587"return its id; others systems will return the id of the \'init\' process (1).");
2588
2589#define OS_GETPPID_METHODDEF \
2590 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2591
2592static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002593os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002594
2595static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002596os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002597{
2598 return os_getppid_impl(module);
2599}
2600
2601#endif /* defined(HAVE_GETPPID) */
2602
2603#if defined(HAVE_GETLOGIN)
2604
2605PyDoc_STRVAR(os_getlogin__doc__,
2606"getlogin($module, /)\n"
2607"--\n"
2608"\n"
2609"Return the actual login name.");
2610
2611#define OS_GETLOGIN_METHODDEF \
2612 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2613
2614static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002615os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002616
2617static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002618os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002619{
2620 return os_getlogin_impl(module);
2621}
2622
2623#endif /* defined(HAVE_GETLOGIN) */
2624
2625#if defined(HAVE_GETUID)
2626
2627PyDoc_STRVAR(os_getuid__doc__,
2628"getuid($module, /)\n"
2629"--\n"
2630"\n"
2631"Return the current process\'s user id.");
2632
2633#define OS_GETUID_METHODDEF \
2634 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2635
2636static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002637os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002638
2639static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002640os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002641{
2642 return os_getuid_impl(module);
2643}
2644
2645#endif /* defined(HAVE_GETUID) */
2646
2647#if defined(HAVE_KILL)
2648
2649PyDoc_STRVAR(os_kill__doc__,
2650"kill($module, pid, signal, /)\n"
2651"--\n"
2652"\n"
2653"Kill a process with a signal.");
2654
2655#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002656 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002657
2658static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002659os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002660
2661static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002662os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002663{
2664 PyObject *return_value = NULL;
2665 pid_t pid;
2666 Py_ssize_t signal;
2667
Sylvain74453812017-06-10 06:51:48 +02002668 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2669 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002670 goto exit;
2671 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002672 return_value = os_kill_impl(module, pid, signal);
2673
2674exit:
2675 return return_value;
2676}
2677
2678#endif /* defined(HAVE_KILL) */
2679
2680#if defined(HAVE_KILLPG)
2681
2682PyDoc_STRVAR(os_killpg__doc__,
2683"killpg($module, pgid, signal, /)\n"
2684"--\n"
2685"\n"
2686"Kill a process group with a signal.");
2687
2688#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002689 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002690
2691static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002692os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002693
2694static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002695os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002696{
2697 PyObject *return_value = NULL;
2698 pid_t pgid;
2699 int signal;
2700
Sylvain74453812017-06-10 06:51:48 +02002701 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2702 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002703 goto exit;
2704 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002705 return_value = os_killpg_impl(module, pgid, signal);
2706
2707exit:
2708 return return_value;
2709}
2710
2711#endif /* defined(HAVE_KILLPG) */
2712
2713#if defined(HAVE_PLOCK)
2714
2715PyDoc_STRVAR(os_plock__doc__,
2716"plock($module, op, /)\n"
2717"--\n"
2718"\n"
2719"Lock program segments into memory.\");");
2720
2721#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002722 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002723
2724static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002725os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002726
2727static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002728os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002729{
2730 PyObject *return_value = NULL;
2731 int op;
2732
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002733 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002734 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002735 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002736 return_value = os_plock_impl(module, op);
2737
2738exit:
2739 return return_value;
2740}
2741
2742#endif /* defined(HAVE_PLOCK) */
2743
2744#if defined(HAVE_SETUID)
2745
2746PyDoc_STRVAR(os_setuid__doc__,
2747"setuid($module, uid, /)\n"
2748"--\n"
2749"\n"
2750"Set the current process\'s user id.");
2751
2752#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002753 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002754
2755static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002756os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002757
2758static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002759os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002760{
2761 PyObject *return_value = NULL;
2762 uid_t uid;
2763
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002764 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002765 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002766 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002767 return_value = os_setuid_impl(module, uid);
2768
2769exit:
2770 return return_value;
2771}
2772
2773#endif /* defined(HAVE_SETUID) */
2774
2775#if defined(HAVE_SETEUID)
2776
2777PyDoc_STRVAR(os_seteuid__doc__,
2778"seteuid($module, euid, /)\n"
2779"--\n"
2780"\n"
2781"Set the current process\'s effective user id.");
2782
2783#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002784 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002785
2786static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002787os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002788
2789static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002790os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002791{
2792 PyObject *return_value = NULL;
2793 uid_t euid;
2794
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002795 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002796 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002797 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002798 return_value = os_seteuid_impl(module, euid);
2799
2800exit:
2801 return return_value;
2802}
2803
2804#endif /* defined(HAVE_SETEUID) */
2805
2806#if defined(HAVE_SETEGID)
2807
2808PyDoc_STRVAR(os_setegid__doc__,
2809"setegid($module, egid, /)\n"
2810"--\n"
2811"\n"
2812"Set the current process\'s effective group id.");
2813
2814#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002815 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002816
2817static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002818os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002819
2820static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002821os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002822{
2823 PyObject *return_value = NULL;
2824 gid_t egid;
2825
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002826 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002827 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002828 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002829 return_value = os_setegid_impl(module, egid);
2830
2831exit:
2832 return return_value;
2833}
2834
2835#endif /* defined(HAVE_SETEGID) */
2836
2837#if defined(HAVE_SETREUID)
2838
2839PyDoc_STRVAR(os_setreuid__doc__,
2840"setreuid($module, ruid, euid, /)\n"
2841"--\n"
2842"\n"
2843"Set the current process\'s real and effective user ids.");
2844
2845#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002846 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002847
2848static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002849os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002850
2851static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002852os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002853{
2854 PyObject *return_value = NULL;
2855 uid_t ruid;
2856 uid_t euid;
2857
Sylvain74453812017-06-10 06:51:48 +02002858 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2859 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002860 goto exit;
2861 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002862 return_value = os_setreuid_impl(module, ruid, euid);
2863
2864exit:
2865 return return_value;
2866}
2867
2868#endif /* defined(HAVE_SETREUID) */
2869
2870#if defined(HAVE_SETREGID)
2871
2872PyDoc_STRVAR(os_setregid__doc__,
2873"setregid($module, rgid, egid, /)\n"
2874"--\n"
2875"\n"
2876"Set the current process\'s real and effective group ids.");
2877
2878#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002879 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002880
2881static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002882os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002883
2884static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002885os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002886{
2887 PyObject *return_value = NULL;
2888 gid_t rgid;
2889 gid_t egid;
2890
Sylvain74453812017-06-10 06:51:48 +02002891 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2892 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002893 goto exit;
2894 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002895 return_value = os_setregid_impl(module, rgid, egid);
2896
2897exit:
2898 return return_value;
2899}
2900
2901#endif /* defined(HAVE_SETREGID) */
2902
2903#if defined(HAVE_SETGID)
2904
2905PyDoc_STRVAR(os_setgid__doc__,
2906"setgid($module, gid, /)\n"
2907"--\n"
2908"\n"
2909"Set the current process\'s group id.");
2910
2911#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002912 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002913
2914static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002915os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002916
2917static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002918os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002919{
2920 PyObject *return_value = NULL;
2921 gid_t gid;
2922
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002923 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002924 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002925 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002926 return_value = os_setgid_impl(module, gid);
2927
2928exit:
2929 return return_value;
2930}
2931
2932#endif /* defined(HAVE_SETGID) */
2933
2934#if defined(HAVE_SETGROUPS)
2935
2936PyDoc_STRVAR(os_setgroups__doc__,
2937"setgroups($module, groups, /)\n"
2938"--\n"
2939"\n"
2940"Set the groups of the current process to list.");
2941
2942#define OS_SETGROUPS_METHODDEF \
2943 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2944
2945#endif /* defined(HAVE_SETGROUPS) */
2946
2947#if defined(HAVE_WAIT3)
2948
2949PyDoc_STRVAR(os_wait3__doc__,
2950"wait3($module, /, options)\n"
2951"--\n"
2952"\n"
2953"Wait for completion of a child process.\n"
2954"\n"
2955"Returns a tuple of information about the child process:\n"
2956" (pid, status, rusage)");
2957
2958#define OS_WAIT3_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002959 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002960
2961static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002962os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002963
2964static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002965os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002966{
2967 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002968 static const char * const _keywords[] = {"options", NULL};
2969 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002970 int options;
2971
Victor Stinner3e1fad62017-01-17 01:29:01 +01002972 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002973 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002974 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002975 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002976 return_value = os_wait3_impl(module, options);
2977
2978exit:
2979 return return_value;
2980}
2981
2982#endif /* defined(HAVE_WAIT3) */
2983
2984#if defined(HAVE_WAIT4)
2985
2986PyDoc_STRVAR(os_wait4__doc__,
2987"wait4($module, /, pid, options)\n"
2988"--\n"
2989"\n"
2990"Wait for completion of a specific child process.\n"
2991"\n"
2992"Returns a tuple of information about the child process:\n"
2993" (pid, status, rusage)");
2994
2995#define OS_WAIT4_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002996 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002997
2998static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002999os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003000
3001static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003002os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003003{
3004 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003005 static const char * const _keywords[] = {"pid", "options", NULL};
3006 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003007 pid_t pid;
3008 int options;
3009
Victor Stinner3e1fad62017-01-17 01:29:01 +01003010 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003011 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003012 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003013 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003014 return_value = os_wait4_impl(module, pid, options);
3015
3016exit:
3017 return return_value;
3018}
3019
3020#endif /* defined(HAVE_WAIT4) */
3021
3022#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3023
3024PyDoc_STRVAR(os_waitid__doc__,
3025"waitid($module, idtype, id, options, /)\n"
3026"--\n"
3027"\n"
3028"Returns the result of waiting for a process or processes.\n"
3029"\n"
3030" idtype\n"
3031" Must be one of be P_PID, P_PGID or P_ALL.\n"
3032" id\n"
3033" The id to wait on.\n"
3034" options\n"
3035" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3036" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3037"\n"
3038"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3039"no children in a waitable state.");
3040
3041#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003042 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003043
3044static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003045os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003046
3047static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003048os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003049{
3050 PyObject *return_value = NULL;
3051 idtype_t idtype;
3052 id_t id;
3053 int options;
3054
Sylvain74453812017-06-10 06:51:48 +02003055 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3056 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003057 goto exit;
3058 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003059 return_value = os_waitid_impl(module, idtype, id, options);
3060
3061exit:
3062 return return_value;
3063}
3064
3065#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3066
3067#if defined(HAVE_WAITPID)
3068
3069PyDoc_STRVAR(os_waitpid__doc__,
3070"waitpid($module, pid, options, /)\n"
3071"--\n"
3072"\n"
3073"Wait for completion of a given child process.\n"
3074"\n"
3075"Returns a tuple of information regarding the child process:\n"
3076" (pid, status)\n"
3077"\n"
3078"The options argument is ignored on Windows.");
3079
3080#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003081 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003082
3083static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003084os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003085
3086static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003087os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003088{
3089 PyObject *return_value = NULL;
3090 pid_t pid;
3091 int options;
3092
Sylvain74453812017-06-10 06:51:48 +02003093 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3094 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003095 goto exit;
3096 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003097 return_value = os_waitpid_impl(module, pid, options);
3098
3099exit:
3100 return return_value;
3101}
3102
3103#endif /* defined(HAVE_WAITPID) */
3104
3105#if defined(HAVE_CWAIT)
3106
3107PyDoc_STRVAR(os_waitpid__doc__,
3108"waitpid($module, pid, options, /)\n"
3109"--\n"
3110"\n"
3111"Wait for completion of a given process.\n"
3112"\n"
3113"Returns a tuple of information regarding the process:\n"
3114" (pid, status << 8)\n"
3115"\n"
3116"The options argument is ignored on Windows.");
3117
3118#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003119 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003120
3121static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003122os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003123
3124static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003125os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003126{
3127 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003128 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003129 int options;
3130
Sylvain74453812017-06-10 06:51:48 +02003131 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3132 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003133 goto exit;
3134 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003135 return_value = os_waitpid_impl(module, pid, options);
3136
3137exit:
3138 return return_value;
3139}
3140
3141#endif /* defined(HAVE_CWAIT) */
3142
3143#if defined(HAVE_WAIT)
3144
3145PyDoc_STRVAR(os_wait__doc__,
3146"wait($module, /)\n"
3147"--\n"
3148"\n"
3149"Wait for completion of a child process.\n"
3150"\n"
3151"Returns a tuple of information about the child process:\n"
3152" (pid, status)");
3153
3154#define OS_WAIT_METHODDEF \
3155 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3156
3157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003158os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003159
3160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003161os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003162{
3163 return os_wait_impl(module);
3164}
3165
3166#endif /* defined(HAVE_WAIT) */
3167
3168#if defined(HAVE_SYMLINK)
3169
3170PyDoc_STRVAR(os_symlink__doc__,
3171"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3172"--\n"
3173"\n"
3174"Create a symbolic link pointing to src named dst.\n"
3175"\n"
3176"target_is_directory is required on Windows if the target is to be\n"
3177" interpreted as a directory. (On Windows, symlink requires\n"
3178" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3179" target_is_directory is ignored on non-Windows platforms.\n"
3180"\n"
3181"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3182" and path should be relative; path will then be relative to that directory.\n"
3183"dir_fd may not be implemented on your platform.\n"
3184" If it is unavailable, using it will raise a NotImplementedError.");
3185
3186#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003187 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003188
3189static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003190os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003191 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003192
3193static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003194os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003195{
3196 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003197 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3198 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003199 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3200 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3201 int target_is_directory = 0;
3202 int dir_fd = DEFAULT_DIR_FD;
3203
Victor Stinner3e1fad62017-01-17 01:29:01 +01003204 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003205 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003206 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003207 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003208 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3209
3210exit:
3211 /* Cleanup for src */
3212 path_cleanup(&src);
3213 /* Cleanup for dst */
3214 path_cleanup(&dst);
3215
3216 return return_value;
3217}
3218
3219#endif /* defined(HAVE_SYMLINK) */
3220
3221#if defined(HAVE_TIMES)
3222
3223PyDoc_STRVAR(os_times__doc__,
3224"times($module, /)\n"
3225"--\n"
3226"\n"
3227"Return a collection containing process timing information.\n"
3228"\n"
3229"The object returned behaves like a named tuple with these fields:\n"
3230" (utime, stime, cutime, cstime, elapsed_time)\n"
3231"All fields are floating point numbers.");
3232
3233#define OS_TIMES_METHODDEF \
3234 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3235
3236static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003237os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003238
3239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003240os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003241{
3242 return os_times_impl(module);
3243}
3244
3245#endif /* defined(HAVE_TIMES) */
3246
3247#if defined(HAVE_GETSID)
3248
3249PyDoc_STRVAR(os_getsid__doc__,
3250"getsid($module, pid, /)\n"
3251"--\n"
3252"\n"
3253"Call the system call getsid(pid) and return the result.");
3254
3255#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003256 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003257
3258static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003259os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003260
3261static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003262os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003263{
3264 PyObject *return_value = NULL;
3265 pid_t pid;
3266
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003267 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003268 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003269 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003270 return_value = os_getsid_impl(module, pid);
3271
3272exit:
3273 return return_value;
3274}
3275
3276#endif /* defined(HAVE_GETSID) */
3277
3278#if defined(HAVE_SETSID)
3279
3280PyDoc_STRVAR(os_setsid__doc__,
3281"setsid($module, /)\n"
3282"--\n"
3283"\n"
3284"Call the system call setsid().");
3285
3286#define OS_SETSID_METHODDEF \
3287 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3288
3289static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003290os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003291
3292static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003293os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003294{
3295 return os_setsid_impl(module);
3296}
3297
3298#endif /* defined(HAVE_SETSID) */
3299
3300#if defined(HAVE_SETPGID)
3301
3302PyDoc_STRVAR(os_setpgid__doc__,
3303"setpgid($module, pid, pgrp, /)\n"
3304"--\n"
3305"\n"
3306"Call the system call setpgid(pid, pgrp).");
3307
3308#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003309 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003310
3311static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003312os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003313
3314static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003315os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003316{
3317 PyObject *return_value = NULL;
3318 pid_t pid;
3319 pid_t pgrp;
3320
Sylvain74453812017-06-10 06:51:48 +02003321 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3322 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003323 goto exit;
3324 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003325 return_value = os_setpgid_impl(module, pid, pgrp);
3326
3327exit:
3328 return return_value;
3329}
3330
3331#endif /* defined(HAVE_SETPGID) */
3332
3333#if defined(HAVE_TCGETPGRP)
3334
3335PyDoc_STRVAR(os_tcgetpgrp__doc__,
3336"tcgetpgrp($module, fd, /)\n"
3337"--\n"
3338"\n"
3339"Return the process group associated with the terminal specified by fd.");
3340
3341#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003342 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003343
3344static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003345os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003346
3347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003348os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003349{
3350 PyObject *return_value = NULL;
3351 int fd;
3352
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003353 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003354 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003355 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003356 return_value = os_tcgetpgrp_impl(module, fd);
3357
3358exit:
3359 return return_value;
3360}
3361
3362#endif /* defined(HAVE_TCGETPGRP) */
3363
3364#if defined(HAVE_TCSETPGRP)
3365
3366PyDoc_STRVAR(os_tcsetpgrp__doc__,
3367"tcsetpgrp($module, fd, pgid, /)\n"
3368"--\n"
3369"\n"
3370"Set the process group associated with the terminal specified by fd.");
3371
3372#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003373 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003374
3375static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003376os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003377
3378static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003379os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003380{
3381 PyObject *return_value = NULL;
3382 int fd;
3383 pid_t pgid;
3384
Sylvain74453812017-06-10 06:51:48 +02003385 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3386 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003387 goto exit;
3388 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003389 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3390
3391exit:
3392 return return_value;
3393}
3394
3395#endif /* defined(HAVE_TCSETPGRP) */
3396
3397PyDoc_STRVAR(os_open__doc__,
3398"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3399"--\n"
3400"\n"
3401"Open a file for low level IO. Returns a file descriptor (integer).\n"
3402"\n"
3403"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3404" and path should be relative; path will then be relative to that directory.\n"
3405"dir_fd may not be implemented on your platform.\n"
3406" If it is unavailable, using it will raise a NotImplementedError.");
3407
3408#define OS_OPEN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003409 {"open", (PyCFunction)os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003410
3411static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003412os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003413
3414static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003415os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003416{
3417 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003418 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3419 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003420 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3421 int flags;
3422 int mode = 511;
3423 int dir_fd = DEFAULT_DIR_FD;
3424 int _return_value;
3425
Victor Stinner3e1fad62017-01-17 01:29:01 +01003426 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003427 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003428 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003429 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003430 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003431 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003432 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003433 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003434 return_value = PyLong_FromLong((long)_return_value);
3435
3436exit:
3437 /* Cleanup for path */
3438 path_cleanup(&path);
3439
3440 return return_value;
3441}
3442
3443PyDoc_STRVAR(os_close__doc__,
3444"close($module, /, fd)\n"
3445"--\n"
3446"\n"
3447"Close a file descriptor.");
3448
3449#define OS_CLOSE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003450 {"close", (PyCFunction)os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003451
3452static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003453os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003454
3455static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003456os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003457{
3458 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003459 static const char * const _keywords[] = {"fd", NULL};
3460 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003461 int fd;
3462
Victor Stinner3e1fad62017-01-17 01:29:01 +01003463 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003464 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003465 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003466 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003467 return_value = os_close_impl(module, fd);
3468
3469exit:
3470 return return_value;
3471}
3472
3473PyDoc_STRVAR(os_closerange__doc__,
3474"closerange($module, fd_low, fd_high, /)\n"
3475"--\n"
3476"\n"
3477"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3478
3479#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003480 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003481
3482static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003483os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003484
3485static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003486os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003487{
3488 PyObject *return_value = NULL;
3489 int fd_low;
3490 int fd_high;
3491
Sylvain74453812017-06-10 06:51:48 +02003492 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3493 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003494 goto exit;
3495 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003496 return_value = os_closerange_impl(module, fd_low, fd_high);
3497
3498exit:
3499 return return_value;
3500}
3501
3502PyDoc_STRVAR(os_dup__doc__,
3503"dup($module, fd, /)\n"
3504"--\n"
3505"\n"
3506"Return a duplicate of a file descriptor.");
3507
3508#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003509 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003510
3511static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003512os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003513
3514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003515os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003516{
3517 PyObject *return_value = NULL;
3518 int fd;
3519 int _return_value;
3520
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003521 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003522 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003523 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003524 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003525 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003526 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003527 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003528 return_value = PyLong_FromLong((long)_return_value);
3529
3530exit:
3531 return return_value;
3532}
3533
3534PyDoc_STRVAR(os_dup2__doc__,
3535"dup2($module, /, fd, fd2, inheritable=True)\n"
3536"--\n"
3537"\n"
3538"Duplicate file descriptor.");
3539
3540#define OS_DUP2_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003541 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003542
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003543static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003544os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003545
3546static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003547os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003548{
3549 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003550 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3551 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003552 int fd;
3553 int fd2;
3554 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003555 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003556
Victor Stinner3e1fad62017-01-17 01:29:01 +01003557 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003558 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003559 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003560 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003561 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3562 if ((_return_value == -1) && PyErr_Occurred()) {
3563 goto exit;
3564 }
3565 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003566
3567exit:
3568 return return_value;
3569}
3570
3571#if defined(HAVE_LOCKF)
3572
3573PyDoc_STRVAR(os_lockf__doc__,
3574"lockf($module, fd, command, length, /)\n"
3575"--\n"
3576"\n"
3577"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3578"\n"
3579" fd\n"
3580" An open file descriptor.\n"
3581" command\n"
3582" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3583" length\n"
3584" The number of bytes to lock, starting at the current position.");
3585
3586#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003587 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003588
3589static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003590os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003591
3592static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003593os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003594{
3595 PyObject *return_value = NULL;
3596 int fd;
3597 int command;
3598 Py_off_t length;
3599
Sylvain74453812017-06-10 06:51:48 +02003600 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3601 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003602 goto exit;
3603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003604 return_value = os_lockf_impl(module, fd, command, length);
3605
3606exit:
3607 return return_value;
3608}
3609
3610#endif /* defined(HAVE_LOCKF) */
3611
3612PyDoc_STRVAR(os_lseek__doc__,
3613"lseek($module, fd, position, how, /)\n"
3614"--\n"
3615"\n"
3616"Set the position of a file descriptor. Return the new position.\n"
3617"\n"
3618"Return the new cursor position in number of bytes\n"
3619"relative to the beginning of the file.");
3620
3621#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003622 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003623
3624static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003625os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003626
3627static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003628os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003629{
3630 PyObject *return_value = NULL;
3631 int fd;
3632 Py_off_t position;
3633 int how;
3634 Py_off_t _return_value;
3635
Sylvain74453812017-06-10 06:51:48 +02003636 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3637 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003638 goto exit;
3639 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003640 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003641 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003642 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003643 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003644 return_value = PyLong_FromPy_off_t(_return_value);
3645
3646exit:
3647 return return_value;
3648}
3649
3650PyDoc_STRVAR(os_read__doc__,
3651"read($module, fd, length, /)\n"
3652"--\n"
3653"\n"
3654"Read from a file descriptor. Returns a bytes object.");
3655
3656#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003657 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003658
3659static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003660os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003661
3662static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003663os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003664{
3665 PyObject *return_value = NULL;
3666 int fd;
3667 Py_ssize_t length;
3668
Sylvain74453812017-06-10 06:51:48 +02003669 if (!_PyArg_ParseStack(args, nargs, "in:read",
3670 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003671 goto exit;
3672 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003673 return_value = os_read_impl(module, fd, length);
3674
3675exit:
3676 return return_value;
3677}
3678
3679#if defined(HAVE_READV)
3680
3681PyDoc_STRVAR(os_readv__doc__,
3682"readv($module, fd, buffers, /)\n"
3683"--\n"
3684"\n"
3685"Read from a file descriptor fd into an iterable of buffers.\n"
3686"\n"
3687"The buffers should be mutable buffers accepting bytes.\n"
3688"readv will transfer data into each buffer until it is full\n"
3689"and then move on to the next buffer in the sequence to hold\n"
3690"the rest of the data.\n"
3691"\n"
3692"readv returns the total number of bytes read,\n"
3693"which may be less than the total capacity of all the buffers.");
3694
3695#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003696 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003697
3698static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003699os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003700
3701static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003702os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003703{
3704 PyObject *return_value = NULL;
3705 int fd;
3706 PyObject *buffers;
3707 Py_ssize_t _return_value;
3708
Sylvain74453812017-06-10 06:51:48 +02003709 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3710 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003711 goto exit;
3712 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003713 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003714 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003715 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003716 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003717 return_value = PyLong_FromSsize_t(_return_value);
3718
3719exit:
3720 return return_value;
3721}
3722
3723#endif /* defined(HAVE_READV) */
3724
3725#if defined(HAVE_PREAD)
3726
3727PyDoc_STRVAR(os_pread__doc__,
3728"pread($module, fd, length, offset, /)\n"
3729"--\n"
3730"\n"
3731"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3732"\n"
3733"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3734"the beginning of the file. The file offset remains unchanged.");
3735
3736#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003737 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003738
3739static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003740os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003741
3742static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003743os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003744{
3745 PyObject *return_value = NULL;
3746 int fd;
3747 int length;
3748 Py_off_t offset;
3749
Sylvain74453812017-06-10 06:51:48 +02003750 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3751 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003752 goto exit;
3753 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003754 return_value = os_pread_impl(module, fd, length, offset);
3755
3756exit:
3757 return return_value;
3758}
3759
3760#endif /* defined(HAVE_PREAD) */
3761
Pablo Galindo4defba32018-01-27 16:16:37 +00003762#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3763
3764PyDoc_STRVAR(os_preadv__doc__,
3765"preadv($module, fd, buffers, offset, flags=0, /)\n"
3766"--\n"
3767"\n"
3768"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3769"\n"
3770"Combines the functionality of readv() and pread(). As readv(), it will\n"
3771"transfer data into each buffer until it is full and then move on to the next\n"
3772"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3773"specifies the file offset at which the input operation is to be performed. It\n"
3774"will return the total number of bytes read (which can be less than the total\n"
3775"capacity of all the objects).\n"
3776"\n"
3777"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3778"\n"
3779"- RWF_HIPRI\n"
3780"- RWF_NOWAIT\n"
3781"\n"
3782"Using non-zero flags requires Linux 4.6 or newer.");
3783
3784#define OS_PREADV_METHODDEF \
3785 {"preadv", (PyCFunction)os_preadv, METH_FASTCALL, os_preadv__doc__},
3786
3787static Py_ssize_t
3788os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
3789 int flags);
3790
3791static PyObject *
3792os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3793{
3794 PyObject *return_value = NULL;
3795 int fd;
3796 PyObject *buffers;
3797 Py_off_t offset;
3798 int flags = 0;
3799 Py_ssize_t _return_value;
3800
3801 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",
3802 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
3803 goto exit;
3804 }
3805 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
3806 if ((_return_value == -1) && PyErr_Occurred()) {
3807 goto exit;
3808 }
3809 return_value = PyLong_FromSsize_t(_return_value);
3810
3811exit:
3812 return return_value;
3813}
3814
3815#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
3816
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003817PyDoc_STRVAR(os_write__doc__,
3818"write($module, fd, data, /)\n"
3819"--\n"
3820"\n"
3821"Write a bytes object to a file descriptor.");
3822
3823#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003824 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003825
3826static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003827os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003828
3829static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003830os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003831{
3832 PyObject *return_value = NULL;
3833 int fd;
3834 Py_buffer data = {NULL, NULL};
3835 Py_ssize_t _return_value;
3836
Sylvain74453812017-06-10 06:51:48 +02003837 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3838 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003839 goto exit;
3840 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003841 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003842 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003843 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003844 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003845 return_value = PyLong_FromSsize_t(_return_value);
3846
3847exit:
3848 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003849 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003850 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003851 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003852
3853 return return_value;
3854}
3855
3856PyDoc_STRVAR(os_fstat__doc__,
3857"fstat($module, /, fd)\n"
3858"--\n"
3859"\n"
3860"Perform a stat system call on the given file descriptor.\n"
3861"\n"
3862"Like stat(), but for an open file descriptor.\n"
3863"Equivalent to os.stat(fd).");
3864
3865#define OS_FSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003866 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003867
3868static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003869os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003870
3871static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003872os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003873{
3874 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003875 static const char * const _keywords[] = {"fd", NULL};
3876 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003877 int fd;
3878
Victor Stinner3e1fad62017-01-17 01:29:01 +01003879 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003880 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003881 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003882 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003883 return_value = os_fstat_impl(module, fd);
3884
3885exit:
3886 return return_value;
3887}
3888
3889PyDoc_STRVAR(os_isatty__doc__,
3890"isatty($module, fd, /)\n"
3891"--\n"
3892"\n"
3893"Return True if the fd is connected to a terminal.\n"
3894"\n"
3895"Return True if the file descriptor is an open file descriptor\n"
3896"connected to the slave end of a terminal.");
3897
3898#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003899 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003900
3901static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003902os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003903
3904static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003905os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003906{
3907 PyObject *return_value = NULL;
3908 int fd;
3909 int _return_value;
3910
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003911 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003912 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003913 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003914 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003915 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003916 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003917 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003918 return_value = PyBool_FromLong((long)_return_value);
3919
3920exit:
3921 return return_value;
3922}
3923
3924#if defined(HAVE_PIPE)
3925
3926PyDoc_STRVAR(os_pipe__doc__,
3927"pipe($module, /)\n"
3928"--\n"
3929"\n"
3930"Create a pipe.\n"
3931"\n"
3932"Returns a tuple of two file descriptors:\n"
3933" (read_fd, write_fd)");
3934
3935#define OS_PIPE_METHODDEF \
3936 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3937
3938static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003939os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003940
3941static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003942os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003943{
3944 return os_pipe_impl(module);
3945}
3946
3947#endif /* defined(HAVE_PIPE) */
3948
3949#if defined(HAVE_PIPE2)
3950
3951PyDoc_STRVAR(os_pipe2__doc__,
3952"pipe2($module, flags, /)\n"
3953"--\n"
3954"\n"
3955"Create a pipe with flags set atomically.\n"
3956"\n"
3957"Returns a tuple of two file descriptors:\n"
3958" (read_fd, write_fd)\n"
3959"\n"
3960"flags can be constructed by ORing together one or more of these values:\n"
3961"O_NONBLOCK, O_CLOEXEC.");
3962
3963#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003964 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003965
3966static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003967os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003968
3969static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003970os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003971{
3972 PyObject *return_value = NULL;
3973 int flags;
3974
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003975 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003976 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003977 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003978 return_value = os_pipe2_impl(module, flags);
3979
3980exit:
3981 return return_value;
3982}
3983
3984#endif /* defined(HAVE_PIPE2) */
3985
3986#if defined(HAVE_WRITEV)
3987
3988PyDoc_STRVAR(os_writev__doc__,
3989"writev($module, fd, buffers, /)\n"
3990"--\n"
3991"\n"
3992"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3993"\n"
3994"Returns the total number of bytes written.\n"
3995"buffers must be a sequence of bytes-like objects.");
3996
3997#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003998 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003999
4000static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004001os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004002
4003static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004004os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004005{
4006 PyObject *return_value = NULL;
4007 int fd;
4008 PyObject *buffers;
4009 Py_ssize_t _return_value;
4010
Sylvain74453812017-06-10 06:51:48 +02004011 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
4012 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004013 goto exit;
4014 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004015 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004016 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004017 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004018 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004019 return_value = PyLong_FromSsize_t(_return_value);
4020
4021exit:
4022 return return_value;
4023}
4024
4025#endif /* defined(HAVE_WRITEV) */
4026
4027#if defined(HAVE_PWRITE)
4028
4029PyDoc_STRVAR(os_pwrite__doc__,
4030"pwrite($module, fd, buffer, offset, /)\n"
4031"--\n"
4032"\n"
4033"Write bytes to a file descriptor starting at a particular offset.\n"
4034"\n"
4035"Write buffer to fd, starting at offset bytes from the beginning of\n"
4036"the file. Returns the number of bytes writte. Does not change the\n"
4037"current file offset.");
4038
4039#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004040 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004041
4042static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004043os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004044
4045static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004046os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004047{
4048 PyObject *return_value = NULL;
4049 int fd;
4050 Py_buffer buffer = {NULL, NULL};
4051 Py_off_t offset;
4052 Py_ssize_t _return_value;
4053
Sylvain74453812017-06-10 06:51:48 +02004054 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4055 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004056 goto exit;
4057 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004058 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004059 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004060 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004061 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004062 return_value = PyLong_FromSsize_t(_return_value);
4063
4064exit:
4065 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004066 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004067 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004068 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004069
4070 return return_value;
4071}
4072
4073#endif /* defined(HAVE_PWRITE) */
4074
Pablo Galindo4defba32018-01-27 16:16:37 +00004075#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4076
4077PyDoc_STRVAR(os_pwritev__doc__,
4078"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4079"--\n"
4080"\n"
4081"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4082"\n"
4083"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4084"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4085"buffer is written before proceeding to second, and so on. The operating system may\n"
4086"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4087"This function writes the contents of each object to the file descriptor and returns\n"
4088"the total number of bytes written.\n"
4089"\n"
4090"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4091"\n"
4092"- RWF_DSYNC\n"
4093"- RWF_SYNC\n"
4094"\n"
4095"Using non-zero flags requires Linux 4.7 or newer.");
4096
4097#define OS_PWRITEV_METHODDEF \
4098 {"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},
4099
4100static Py_ssize_t
4101os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4102 int flags);
4103
4104static PyObject *
4105os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4106{
4107 PyObject *return_value = NULL;
4108 int fd;
4109 PyObject *buffers;
4110 Py_off_t offset;
4111 int flags = 0;
4112 Py_ssize_t _return_value;
4113
4114 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4115 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4116 goto exit;
4117 }
4118 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4119 if ((_return_value == -1) && PyErr_Occurred()) {
4120 goto exit;
4121 }
4122 return_value = PyLong_FromSsize_t(_return_value);
4123
4124exit:
4125 return return_value;
4126}
4127
4128#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4129
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004130#if defined(HAVE_MKFIFO)
4131
4132PyDoc_STRVAR(os_mkfifo__doc__,
4133"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4134"--\n"
4135"\n"
4136"Create a \"fifo\" (a POSIX named pipe).\n"
4137"\n"
4138"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4139" and path should be relative; path will then be relative to that directory.\n"
4140"dir_fd may not be implemented on your platform.\n"
4141" If it is unavailable, using it will raise a NotImplementedError.");
4142
4143#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004144 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004145
4146static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004147os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004148
4149static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004150os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004151{
4152 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004153 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4154 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004155 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4156 int mode = 438;
4157 int dir_fd = DEFAULT_DIR_FD;
4158
Victor Stinner3e1fad62017-01-17 01:29:01 +01004159 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004160 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004161 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004162 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004163 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4164
4165exit:
4166 /* Cleanup for path */
4167 path_cleanup(&path);
4168
4169 return return_value;
4170}
4171
4172#endif /* defined(HAVE_MKFIFO) */
4173
4174#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4175
4176PyDoc_STRVAR(os_mknod__doc__,
4177"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4178"--\n"
4179"\n"
4180"Create a node in the file system.\n"
4181"\n"
4182"Create a node in the file system (file, device special file or named pipe)\n"
4183"at path. mode specifies both the permissions to use and the\n"
4184"type of node to be created, being combined (bitwise OR) with one of\n"
4185"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4186"device defines the newly created device special file (probably using\n"
4187"os.makedev()). Otherwise device is ignored.\n"
4188"\n"
4189"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4190" and path should be relative; path will then be relative to that directory.\n"
4191"dir_fd may not be implemented on your platform.\n"
4192" If it is unavailable, using it will raise a NotImplementedError.");
4193
4194#define OS_MKNOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004195 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004196
4197static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004198os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004199 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004200
4201static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004202os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004203{
4204 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004205 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4206 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004207 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4208 int mode = 384;
4209 dev_t device = 0;
4210 int dir_fd = DEFAULT_DIR_FD;
4211
Victor Stinner3e1fad62017-01-17 01:29:01 +01004212 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004213 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004214 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004215 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004216 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4217
4218exit:
4219 /* Cleanup for path */
4220 path_cleanup(&path);
4221
4222 return return_value;
4223}
4224
4225#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4226
4227#if defined(HAVE_DEVICE_MACROS)
4228
4229PyDoc_STRVAR(os_major__doc__,
4230"major($module, device, /)\n"
4231"--\n"
4232"\n"
4233"Extracts a device major number from a raw device number.");
4234
4235#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004236 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004237
4238static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004239os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004240
4241static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004242os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004243{
4244 PyObject *return_value = NULL;
4245 dev_t device;
4246 unsigned int _return_value;
4247
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004248 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004249 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004250 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004251 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004252 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004253 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004254 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004255 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4256
4257exit:
4258 return return_value;
4259}
4260
4261#endif /* defined(HAVE_DEVICE_MACROS) */
4262
4263#if defined(HAVE_DEVICE_MACROS)
4264
4265PyDoc_STRVAR(os_minor__doc__,
4266"minor($module, device, /)\n"
4267"--\n"
4268"\n"
4269"Extracts a device minor number from a raw device number.");
4270
4271#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004272 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004273
4274static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004275os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004276
4277static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004278os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004279{
4280 PyObject *return_value = NULL;
4281 dev_t device;
4282 unsigned int _return_value;
4283
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004284 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004285 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004286 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004287 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004288 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004289 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004290 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004291 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4292
4293exit:
4294 return return_value;
4295}
4296
4297#endif /* defined(HAVE_DEVICE_MACROS) */
4298
4299#if defined(HAVE_DEVICE_MACROS)
4300
4301PyDoc_STRVAR(os_makedev__doc__,
4302"makedev($module, major, minor, /)\n"
4303"--\n"
4304"\n"
4305"Composes a raw device number from the major and minor device numbers.");
4306
4307#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004308 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004309
4310static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004311os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004312
4313static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004314os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004315{
4316 PyObject *return_value = NULL;
4317 int major;
4318 int minor;
4319 dev_t _return_value;
4320
Sylvain74453812017-06-10 06:51:48 +02004321 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4322 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004323 goto exit;
4324 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004325 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004326 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004327 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004328 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004329 return_value = _PyLong_FromDev(_return_value);
4330
4331exit:
4332 return return_value;
4333}
4334
4335#endif /* defined(HAVE_DEVICE_MACROS) */
4336
Steve Dowerf7377032015-04-12 15:44:54 -04004337#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004338
4339PyDoc_STRVAR(os_ftruncate__doc__,
4340"ftruncate($module, fd, length, /)\n"
4341"--\n"
4342"\n"
4343"Truncate a file, specified by file descriptor, to a specific length.");
4344
4345#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004346 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004347
4348static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004349os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004350
4351static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004352os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004353{
4354 PyObject *return_value = NULL;
4355 int fd;
4356 Py_off_t length;
4357
Sylvain74453812017-06-10 06:51:48 +02004358 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4359 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004360 goto exit;
4361 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004362 return_value = os_ftruncate_impl(module, fd, length);
4363
4364exit:
4365 return return_value;
4366}
4367
Steve Dowerf7377032015-04-12 15:44:54 -04004368#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004369
Steve Dowerf7377032015-04-12 15:44:54 -04004370#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004371
4372PyDoc_STRVAR(os_truncate__doc__,
4373"truncate($module, /, path, length)\n"
4374"--\n"
4375"\n"
4376"Truncate a file, specified by path, to a specific length.\n"
4377"\n"
4378"On some platforms, path may also be specified as an open file descriptor.\n"
4379" If this functionality is unavailable, using it raises an exception.");
4380
4381#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004382 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004383
4384static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004385os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004386
4387static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004388os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004389{
4390 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004391 static const char * const _keywords[] = {"path", "length", NULL};
4392 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004393 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4394 Py_off_t length;
4395
Victor Stinner3e1fad62017-01-17 01:29:01 +01004396 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004397 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004398 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004399 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004400 return_value = os_truncate_impl(module, &path, length);
4401
4402exit:
4403 /* Cleanup for path */
4404 path_cleanup(&path);
4405
4406 return return_value;
4407}
4408
Steve Dowerf7377032015-04-12 15:44:54 -04004409#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004410
4411#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4412
4413PyDoc_STRVAR(os_posix_fallocate__doc__,
4414"posix_fallocate($module, fd, offset, length, /)\n"
4415"--\n"
4416"\n"
4417"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4418"\n"
4419"Ensure that the file specified by fd encompasses a range of bytes\n"
4420"starting at offset bytes from the beginning and continuing for length bytes.");
4421
4422#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004423 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004424
4425static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004426os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004427 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004428
4429static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004430os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004431{
4432 PyObject *return_value = NULL;
4433 int fd;
4434 Py_off_t offset;
4435 Py_off_t length;
4436
Sylvain74453812017-06-10 06:51:48 +02004437 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4438 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004439 goto exit;
4440 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004441 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4442
4443exit:
4444 return return_value;
4445}
4446
4447#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4448
4449#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4450
4451PyDoc_STRVAR(os_posix_fadvise__doc__,
4452"posix_fadvise($module, fd, offset, length, advice, /)\n"
4453"--\n"
4454"\n"
4455"Announce an intention to access data in a specific pattern.\n"
4456"\n"
4457"Announce an intention to access data in a specific pattern, thus allowing\n"
4458"the kernel to make optimizations.\n"
4459"The advice applies to the region of the file specified by fd starting at\n"
4460"offset and continuing for length bytes.\n"
4461"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4462"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4463"POSIX_FADV_DONTNEED.");
4464
4465#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004466 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004467
4468static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004469os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004470 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004471
4472static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004473os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004474{
4475 PyObject *return_value = NULL;
4476 int fd;
4477 Py_off_t offset;
4478 Py_off_t length;
4479 int advice;
4480
Sylvain74453812017-06-10 06:51:48 +02004481 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4482 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004483 goto exit;
4484 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004485 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4486
4487exit:
4488 return return_value;
4489}
4490
4491#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4492
4493#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4494
4495PyDoc_STRVAR(os_putenv__doc__,
4496"putenv($module, name, value, /)\n"
4497"--\n"
4498"\n"
4499"Change or add an environment variable.");
4500
4501#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004502 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004503
4504static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004505os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004506
4507static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004508os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004509{
4510 PyObject *return_value = NULL;
4511 PyObject *name;
4512 PyObject *value;
4513
Sylvain74453812017-06-10 06:51:48 +02004514 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4515 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004516 goto exit;
4517 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004518 return_value = os_putenv_impl(module, name, value);
4519
4520exit:
4521 return return_value;
4522}
4523
4524#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4525
4526#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4527
4528PyDoc_STRVAR(os_putenv__doc__,
4529"putenv($module, name, value, /)\n"
4530"--\n"
4531"\n"
4532"Change or add an environment variable.");
4533
4534#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004535 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004536
4537static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004538os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004539
4540static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004541os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004542{
4543 PyObject *return_value = NULL;
4544 PyObject *name = NULL;
4545 PyObject *value = NULL;
4546
Sylvain74453812017-06-10 06:51:48 +02004547 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4548 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004549 goto exit;
4550 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004551 return_value = os_putenv_impl(module, name, value);
4552
4553exit:
4554 /* Cleanup for name */
4555 Py_XDECREF(name);
4556 /* Cleanup for value */
4557 Py_XDECREF(value);
4558
4559 return return_value;
4560}
4561
4562#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4563
4564#if defined(HAVE_UNSETENV)
4565
4566PyDoc_STRVAR(os_unsetenv__doc__,
4567"unsetenv($module, name, /)\n"
4568"--\n"
4569"\n"
4570"Delete an environment variable.");
4571
4572#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004573 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004574
4575static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004576os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004577
4578static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004579os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004580{
4581 PyObject *return_value = NULL;
4582 PyObject *name = NULL;
4583
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004584 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004585 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004586 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004587 return_value = os_unsetenv_impl(module, name);
4588
4589exit:
4590 /* Cleanup for name */
4591 Py_XDECREF(name);
4592
4593 return return_value;
4594}
4595
4596#endif /* defined(HAVE_UNSETENV) */
4597
4598PyDoc_STRVAR(os_strerror__doc__,
4599"strerror($module, code, /)\n"
4600"--\n"
4601"\n"
4602"Translate an error code to a message string.");
4603
4604#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004605 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004606
4607static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004608os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004609
4610static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004611os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004612{
4613 PyObject *return_value = NULL;
4614 int code;
4615
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004616 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004617 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004618 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004619 return_value = os_strerror_impl(module, code);
4620
4621exit:
4622 return return_value;
4623}
4624
4625#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4626
4627PyDoc_STRVAR(os_WCOREDUMP__doc__,
4628"WCOREDUMP($module, status, /)\n"
4629"--\n"
4630"\n"
4631"Return True if the process returning status was dumped to a core file.");
4632
4633#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004634 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004635
4636static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004637os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004638
4639static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004640os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004641{
4642 PyObject *return_value = NULL;
4643 int status;
4644 int _return_value;
4645
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004646 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004647 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004648 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004649 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004650 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004651 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004652 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004653 return_value = PyBool_FromLong((long)_return_value);
4654
4655exit:
4656 return return_value;
4657}
4658
4659#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4660
4661#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4662
4663PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4664"WIFCONTINUED($module, /, status)\n"
4665"--\n"
4666"\n"
4667"Return True if a particular process was continued from a job control stop.\n"
4668"\n"
4669"Return True if the process returning status was continued from a\n"
4670"job control stop.");
4671
4672#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004673 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004674
4675static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004676os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004677
4678static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004679os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004680{
4681 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004682 static const char * const _keywords[] = {"status", NULL};
4683 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004684 int status;
4685 int _return_value;
4686
Victor Stinner3e1fad62017-01-17 01:29:01 +01004687 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004688 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004689 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004690 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004691 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004692 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004693 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004694 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004695 return_value = PyBool_FromLong((long)_return_value);
4696
4697exit:
4698 return return_value;
4699}
4700
4701#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4702
4703#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4704
4705PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4706"WIFSTOPPED($module, /, status)\n"
4707"--\n"
4708"\n"
4709"Return True if the process returning status was stopped.");
4710
4711#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004712 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004713
4714static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004715os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004716
4717static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004718os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004719{
4720 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004721 static const char * const _keywords[] = {"status", NULL};
4722 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004723 int status;
4724 int _return_value;
4725
Victor Stinner3e1fad62017-01-17 01:29:01 +01004726 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004727 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004728 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004729 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004730 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004731 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004732 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004733 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004734 return_value = PyBool_FromLong((long)_return_value);
4735
4736exit:
4737 return return_value;
4738}
4739
4740#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4741
4742#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4743
4744PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4745"WIFSIGNALED($module, /, status)\n"
4746"--\n"
4747"\n"
4748"Return True if the process returning status was terminated by a signal.");
4749
4750#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004751 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004752
4753static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004754os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004755
4756static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004757os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004758{
4759 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004760 static const char * const _keywords[] = {"status", NULL};
4761 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004762 int status;
4763 int _return_value;
4764
Victor Stinner3e1fad62017-01-17 01:29:01 +01004765 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004766 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004767 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004768 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004769 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004770 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004771 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004772 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004773 return_value = PyBool_FromLong((long)_return_value);
4774
4775exit:
4776 return return_value;
4777}
4778
4779#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4780
4781#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4782
4783PyDoc_STRVAR(os_WIFEXITED__doc__,
4784"WIFEXITED($module, /, status)\n"
4785"--\n"
4786"\n"
4787"Return True if the process returning status exited via the exit() system call.");
4788
4789#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004790 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004791
4792static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004793os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004794
4795static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004796os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004797{
4798 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004799 static const char * const _keywords[] = {"status", NULL};
4800 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004801 int status;
4802 int _return_value;
4803
Victor Stinner3e1fad62017-01-17 01:29:01 +01004804 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004805 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004806 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004807 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004808 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004809 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004810 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004811 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004812 return_value = PyBool_FromLong((long)_return_value);
4813
4814exit:
4815 return return_value;
4816}
4817
4818#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4819
4820#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4821
4822PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4823"WEXITSTATUS($module, /, status)\n"
4824"--\n"
4825"\n"
4826"Return the process return code from status.");
4827
4828#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004829 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004830
4831static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004832os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004833
4834static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004835os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004836{
4837 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004838 static const char * const _keywords[] = {"status", NULL};
4839 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004840 int status;
4841 int _return_value;
4842
Victor Stinner3e1fad62017-01-17 01:29:01 +01004843 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004844 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004845 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004846 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004847 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004848 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004849 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004850 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004851 return_value = PyLong_FromLong((long)_return_value);
4852
4853exit:
4854 return return_value;
4855}
4856
4857#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4858
4859#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4860
4861PyDoc_STRVAR(os_WTERMSIG__doc__,
4862"WTERMSIG($module, /, status)\n"
4863"--\n"
4864"\n"
4865"Return the signal that terminated the process that provided the status value.");
4866
4867#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004868 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004869
4870static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004871os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004872
4873static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004874os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004875{
4876 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004877 static const char * const _keywords[] = {"status", NULL};
4878 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004879 int status;
4880 int _return_value;
4881
Victor Stinner3e1fad62017-01-17 01:29:01 +01004882 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004883 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004884 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004885 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004886 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004887 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004888 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004889 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004890 return_value = PyLong_FromLong((long)_return_value);
4891
4892exit:
4893 return return_value;
4894}
4895
4896#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4897
4898#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4899
4900PyDoc_STRVAR(os_WSTOPSIG__doc__,
4901"WSTOPSIG($module, /, status)\n"
4902"--\n"
4903"\n"
4904"Return the signal that stopped the process that provided the status value.");
4905
4906#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004907 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004908
4909static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004910os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004911
4912static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004913os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004914{
4915 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004916 static const char * const _keywords[] = {"status", NULL};
4917 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004918 int status;
4919 int _return_value;
4920
Victor Stinner3e1fad62017-01-17 01:29:01 +01004921 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004922 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004923 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004924 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004925 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004926 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004927 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004928 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004929 return_value = PyLong_FromLong((long)_return_value);
4930
4931exit:
4932 return return_value;
4933}
4934
4935#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4936
4937#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4938
4939PyDoc_STRVAR(os_fstatvfs__doc__,
4940"fstatvfs($module, fd, /)\n"
4941"--\n"
4942"\n"
4943"Perform an fstatvfs system call on the given fd.\n"
4944"\n"
4945"Equivalent to statvfs(fd).");
4946
4947#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004948 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004949
4950static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004951os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004952
4953static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004954os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004955{
4956 PyObject *return_value = NULL;
4957 int fd;
4958
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004959 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004960 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004961 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004962 return_value = os_fstatvfs_impl(module, fd);
4963
4964exit:
4965 return return_value;
4966}
4967
4968#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4969
4970#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4971
4972PyDoc_STRVAR(os_statvfs__doc__,
4973"statvfs($module, /, path)\n"
4974"--\n"
4975"\n"
4976"Perform a statvfs system call on the given path.\n"
4977"\n"
4978"path may always be specified as a string.\n"
4979"On some platforms, path may also be specified as an open file descriptor.\n"
4980" If this functionality is unavailable, using it raises an exception.");
4981
4982#define OS_STATVFS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004983 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984
4985static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004986os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004987
4988static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004989os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004990{
4991 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004992 static const char * const _keywords[] = {"path", NULL};
4993 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004994 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4995
Victor Stinner3e1fad62017-01-17 01:29:01 +01004996 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004997 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004998 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004999 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005000 return_value = os_statvfs_impl(module, &path);
5001
5002exit:
5003 /* Cleanup for path */
5004 path_cleanup(&path);
5005
5006 return return_value;
5007}
5008
5009#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5010
5011#if defined(MS_WINDOWS)
5012
5013PyDoc_STRVAR(os__getdiskusage__doc__,
5014"_getdiskusage($module, /, path)\n"
5015"--\n"
5016"\n"
5017"Return disk usage statistics about the given path as a (total, free) tuple.");
5018
5019#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005020 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005021
5022static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005023os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005024
5025static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005026os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005027{
5028 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005029 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005030 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5031 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005032
Victor Stinner3e1fad62017-01-17 01:29:01 +01005033 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005034 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005035 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005036 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005037 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005038
5039exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005040 /* Cleanup for path */
5041 path_cleanup(&path);
5042
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005043 return return_value;
5044}
5045
5046#endif /* defined(MS_WINDOWS) */
5047
5048#if defined(HAVE_FPATHCONF)
5049
5050PyDoc_STRVAR(os_fpathconf__doc__,
5051"fpathconf($module, fd, name, /)\n"
5052"--\n"
5053"\n"
5054"Return the configuration limit name for the file descriptor fd.\n"
5055"\n"
5056"If there is no limit, return -1.");
5057
5058#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005059 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005060
5061static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005062os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005063
5064static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005065os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005066{
5067 PyObject *return_value = NULL;
5068 int fd;
5069 int name;
5070 long _return_value;
5071
Sylvain74453812017-06-10 06:51:48 +02005072 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5073 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005074 goto exit;
5075 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005076 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005077 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005078 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005079 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005080 return_value = PyLong_FromLong(_return_value);
5081
5082exit:
5083 return return_value;
5084}
5085
5086#endif /* defined(HAVE_FPATHCONF) */
5087
5088#if defined(HAVE_PATHCONF)
5089
5090PyDoc_STRVAR(os_pathconf__doc__,
5091"pathconf($module, /, path, name)\n"
5092"--\n"
5093"\n"
5094"Return the configuration limit name for the file or directory path.\n"
5095"\n"
5096"If there is no limit, return -1.\n"
5097"On some platforms, path may also be specified as an open file descriptor.\n"
5098" If this functionality is unavailable, using it raises an exception.");
5099
5100#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005101 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005102
5103static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005104os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005105
5106static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005107os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005108{
5109 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005110 static const char * const _keywords[] = {"path", "name", NULL};
5111 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005112 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5113 int name;
5114 long _return_value;
5115
Victor Stinner3e1fad62017-01-17 01:29:01 +01005116 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005117 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005118 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005119 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005120 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005121 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005122 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005123 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005124 return_value = PyLong_FromLong(_return_value);
5125
5126exit:
5127 /* Cleanup for path */
5128 path_cleanup(&path);
5129
5130 return return_value;
5131}
5132
5133#endif /* defined(HAVE_PATHCONF) */
5134
5135#if defined(HAVE_CONFSTR)
5136
5137PyDoc_STRVAR(os_confstr__doc__,
5138"confstr($module, name, /)\n"
5139"--\n"
5140"\n"
5141"Return a string-valued system configuration variable.");
5142
5143#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005144 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005145
5146static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005147os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005148
5149static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005150os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005151{
5152 PyObject *return_value = NULL;
5153 int name;
5154
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005155 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005156 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005157 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005158 return_value = os_confstr_impl(module, name);
5159
5160exit:
5161 return return_value;
5162}
5163
5164#endif /* defined(HAVE_CONFSTR) */
5165
5166#if defined(HAVE_SYSCONF)
5167
5168PyDoc_STRVAR(os_sysconf__doc__,
5169"sysconf($module, name, /)\n"
5170"--\n"
5171"\n"
5172"Return an integer-valued system configuration variable.");
5173
5174#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005175 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005176
5177static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005178os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005179
5180static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005181os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005182{
5183 PyObject *return_value = NULL;
5184 int name;
5185 long _return_value;
5186
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005187 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005188 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005189 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005190 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005191 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005192 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005193 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005194 return_value = PyLong_FromLong(_return_value);
5195
5196exit:
5197 return return_value;
5198}
5199
5200#endif /* defined(HAVE_SYSCONF) */
5201
5202PyDoc_STRVAR(os_abort__doc__,
5203"abort($module, /)\n"
5204"--\n"
5205"\n"
5206"Abort the interpreter immediately.\n"
5207"\n"
5208"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5209"on the hosting operating system. This function never returns.");
5210
5211#define OS_ABORT_METHODDEF \
5212 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5213
5214static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005215os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005216
5217static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005218os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005219{
5220 return os_abort_impl(module);
5221}
5222
Steve Dowercc16be82016-09-08 10:35:16 -07005223#if defined(MS_WINDOWS)
5224
5225PyDoc_STRVAR(os_startfile__doc__,
5226"startfile($module, /, filepath, operation=None)\n"
5227"--\n"
5228"\n"
5229"startfile(filepath [, operation])\n"
5230"\n"
5231"Start a file with its associated application.\n"
5232"\n"
5233"When \"operation\" is not specified or \"open\", this acts like\n"
5234"double-clicking the file in Explorer, or giving the file name as an\n"
5235"argument to the DOS \"start\" command: the file is opened with whatever\n"
5236"application (if any) its extension is associated.\n"
5237"When another \"operation\" is given, it specifies what should be done with\n"
5238"the file. A typical operation is \"print\".\n"
5239"\n"
5240"startfile returns as soon as the associated application is launched.\n"
5241"There is no option to wait for the application to close, and no way\n"
5242"to retrieve the application\'s exit status.\n"
5243"\n"
5244"The filepath is relative to the current directory. If you want to use\n"
5245"an absolute path, make sure the first character is not a slash (\"/\");\n"
5246"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5247
5248#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005249 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005250
5251static PyObject *
5252os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5253
5254static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005255os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005256{
5257 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005258 static const char * const _keywords[] = {"filepath", "operation", NULL};
5259 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005260 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5261 Py_UNICODE *operation = NULL;
5262
Victor Stinner3e1fad62017-01-17 01:29:01 +01005263 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005264 path_converter, &filepath, &operation)) {
5265 goto exit;
5266 }
5267 return_value = os_startfile_impl(module, &filepath, operation);
5268
5269exit:
5270 /* Cleanup for filepath */
5271 path_cleanup(&filepath);
5272
5273 return return_value;
5274}
5275
5276#endif /* defined(MS_WINDOWS) */
5277
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005278#if defined(HAVE_GETLOADAVG)
5279
5280PyDoc_STRVAR(os_getloadavg__doc__,
5281"getloadavg($module, /)\n"
5282"--\n"
5283"\n"
5284"Return average recent system load information.\n"
5285"\n"
5286"Return the number of processes in the system run queue averaged over\n"
5287"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5288"Raises OSError if the load average was unobtainable.");
5289
5290#define OS_GETLOADAVG_METHODDEF \
5291 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5292
5293static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005294os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005295
5296static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005297os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005298{
5299 return os_getloadavg_impl(module);
5300}
5301
5302#endif /* defined(HAVE_GETLOADAVG) */
5303
5304PyDoc_STRVAR(os_device_encoding__doc__,
5305"device_encoding($module, /, fd)\n"
5306"--\n"
5307"\n"
5308"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5309"\n"
5310"The file descriptor must be attached to a terminal.\n"
5311"If the device is not a terminal, return None.");
5312
5313#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005314 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005315
5316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005317os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005318
5319static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005320os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005321{
5322 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005323 static const char * const _keywords[] = {"fd", NULL};
5324 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005325 int fd;
5326
Victor Stinner3e1fad62017-01-17 01:29:01 +01005327 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005328 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005329 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005330 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005331 return_value = os_device_encoding_impl(module, fd);
5332
5333exit:
5334 return return_value;
5335}
5336
5337#if defined(HAVE_SETRESUID)
5338
5339PyDoc_STRVAR(os_setresuid__doc__,
5340"setresuid($module, ruid, euid, suid, /)\n"
5341"--\n"
5342"\n"
5343"Set the current process\'s real, effective, and saved user ids.");
5344
5345#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005346 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005347
5348static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005349os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005350
5351static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005352os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005353{
5354 PyObject *return_value = NULL;
5355 uid_t ruid;
5356 uid_t euid;
5357 uid_t suid;
5358
Sylvain74453812017-06-10 06:51:48 +02005359 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5360 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005361 goto exit;
5362 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005363 return_value = os_setresuid_impl(module, ruid, euid, suid);
5364
5365exit:
5366 return return_value;
5367}
5368
5369#endif /* defined(HAVE_SETRESUID) */
5370
5371#if defined(HAVE_SETRESGID)
5372
5373PyDoc_STRVAR(os_setresgid__doc__,
5374"setresgid($module, rgid, egid, sgid, /)\n"
5375"--\n"
5376"\n"
5377"Set the current process\'s real, effective, and saved group ids.");
5378
5379#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005380 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005381
5382static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005383os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005384
5385static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005386os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005387{
5388 PyObject *return_value = NULL;
5389 gid_t rgid;
5390 gid_t egid;
5391 gid_t sgid;
5392
Sylvain74453812017-06-10 06:51:48 +02005393 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5394 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005395 goto exit;
5396 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005397 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5398
5399exit:
5400 return return_value;
5401}
5402
5403#endif /* defined(HAVE_SETRESGID) */
5404
5405#if defined(HAVE_GETRESUID)
5406
5407PyDoc_STRVAR(os_getresuid__doc__,
5408"getresuid($module, /)\n"
5409"--\n"
5410"\n"
5411"Return a tuple of the current process\'s real, effective, and saved user ids.");
5412
5413#define OS_GETRESUID_METHODDEF \
5414 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5415
5416static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005417os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005418
5419static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005420os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005421{
5422 return os_getresuid_impl(module);
5423}
5424
5425#endif /* defined(HAVE_GETRESUID) */
5426
5427#if defined(HAVE_GETRESGID)
5428
5429PyDoc_STRVAR(os_getresgid__doc__,
5430"getresgid($module, /)\n"
5431"--\n"
5432"\n"
5433"Return a tuple of the current process\'s real, effective, and saved group ids.");
5434
5435#define OS_GETRESGID_METHODDEF \
5436 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5437
5438static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005439os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005440
5441static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005442os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005443{
5444 return os_getresgid_impl(module);
5445}
5446
5447#endif /* defined(HAVE_GETRESGID) */
5448
5449#if defined(USE_XATTRS)
5450
5451PyDoc_STRVAR(os_getxattr__doc__,
5452"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5453"--\n"
5454"\n"
5455"Return the value of extended attribute attribute on path.\n"
5456"\n"
5457"path may be either a string or an open file descriptor.\n"
5458"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5459" link, getxattr will examine the symbolic link itself instead of the file\n"
5460" the link points to.");
5461
5462#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005463 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005464
5465static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005466os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005467 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005468
5469static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005470os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005471{
5472 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005473 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5474 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005475 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5476 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5477 int follow_symlinks = 1;
5478
Victor Stinner3e1fad62017-01-17 01:29:01 +01005479 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005480 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005481 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005482 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005483 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5484
5485exit:
5486 /* Cleanup for path */
5487 path_cleanup(&path);
5488 /* Cleanup for attribute */
5489 path_cleanup(&attribute);
5490
5491 return return_value;
5492}
5493
5494#endif /* defined(USE_XATTRS) */
5495
5496#if defined(USE_XATTRS)
5497
5498PyDoc_STRVAR(os_setxattr__doc__,
5499"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5500" follow_symlinks=True)\n"
5501"--\n"
5502"\n"
5503"Set extended attribute attribute on path to value.\n"
5504"\n"
5505"path may be either a string or an open file descriptor.\n"
5506"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5507" link, setxattr will modify the symbolic link itself instead of the file\n"
5508" the link points to.");
5509
5510#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005511 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005512
5513static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005514os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005515 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005516
5517static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005518os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005519{
5520 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005521 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5522 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005523 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5524 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5525 Py_buffer value = {NULL, NULL};
5526 int flags = 0;
5527 int follow_symlinks = 1;
5528
Victor Stinner3e1fad62017-01-17 01:29:01 +01005529 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005530 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005531 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005532 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005533 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5534
5535exit:
5536 /* Cleanup for path */
5537 path_cleanup(&path);
5538 /* Cleanup for attribute */
5539 path_cleanup(&attribute);
5540 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005541 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005542 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005543 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005544
5545 return return_value;
5546}
5547
5548#endif /* defined(USE_XATTRS) */
5549
5550#if defined(USE_XATTRS)
5551
5552PyDoc_STRVAR(os_removexattr__doc__,
5553"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5554"--\n"
5555"\n"
5556"Remove extended attribute attribute on path.\n"
5557"\n"
5558"path may be either a string or an open file descriptor.\n"
5559"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5560" link, removexattr will modify the symbolic link itself instead of the file\n"
5561" the link points to.");
5562
5563#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005564 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005565
5566static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005567os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005568 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005569
5570static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005571os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005572{
5573 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005574 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5575 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005576 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5577 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5578 int follow_symlinks = 1;
5579
Victor Stinner3e1fad62017-01-17 01:29:01 +01005580 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005581 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005582 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005583 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005584 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5585
5586exit:
5587 /* Cleanup for path */
5588 path_cleanup(&path);
5589 /* Cleanup for attribute */
5590 path_cleanup(&attribute);
5591
5592 return return_value;
5593}
5594
5595#endif /* defined(USE_XATTRS) */
5596
5597#if defined(USE_XATTRS)
5598
5599PyDoc_STRVAR(os_listxattr__doc__,
5600"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5601"--\n"
5602"\n"
5603"Return a list of extended attributes on path.\n"
5604"\n"
5605"path may be either None, a string, or an open file descriptor.\n"
5606"if path is None, listxattr will examine the current directory.\n"
5607"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5608" link, listxattr will examine the symbolic link itself instead of the file\n"
5609" the link points to.");
5610
5611#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005612 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005613
5614static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005615os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005616
5617static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005618os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005619{
5620 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005621 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5622 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005623 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5624 int follow_symlinks = 1;
5625
Victor Stinner3e1fad62017-01-17 01:29:01 +01005626 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005627 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005628 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005629 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005630 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5631
5632exit:
5633 /* Cleanup for path */
5634 path_cleanup(&path);
5635
5636 return return_value;
5637}
5638
5639#endif /* defined(USE_XATTRS) */
5640
5641PyDoc_STRVAR(os_urandom__doc__,
5642"urandom($module, size, /)\n"
5643"--\n"
5644"\n"
5645"Return a bytes object containing random bytes suitable for cryptographic use.");
5646
5647#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005648 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005649
5650static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005651os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005652
5653static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005654os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005655{
5656 PyObject *return_value = NULL;
5657 Py_ssize_t size;
5658
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005659 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005660 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005661 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005662 return_value = os_urandom_impl(module, size);
5663
5664exit:
5665 return return_value;
5666}
5667
5668PyDoc_STRVAR(os_cpu_count__doc__,
5669"cpu_count($module, /)\n"
5670"--\n"
5671"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005672"Return the number of CPUs in the system; return None if indeterminable.\n"
5673"\n"
5674"This number is not equivalent to the number of CPUs the current process can\n"
5675"use. The number of usable CPUs can be obtained with\n"
5676"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005677
5678#define OS_CPU_COUNT_METHODDEF \
5679 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5680
5681static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005682os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005683
5684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005685os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005686{
5687 return os_cpu_count_impl(module);
5688}
5689
5690PyDoc_STRVAR(os_get_inheritable__doc__,
5691"get_inheritable($module, fd, /)\n"
5692"--\n"
5693"\n"
5694"Get the close-on-exe flag of the specified file descriptor.");
5695
5696#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005697 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005698
5699static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005700os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005701
5702static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005703os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005704{
5705 PyObject *return_value = NULL;
5706 int fd;
5707 int _return_value;
5708
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005709 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005710 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005711 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005712 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005713 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005714 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005715 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005716 return_value = PyBool_FromLong((long)_return_value);
5717
5718exit:
5719 return return_value;
5720}
5721
5722PyDoc_STRVAR(os_set_inheritable__doc__,
5723"set_inheritable($module, fd, inheritable, /)\n"
5724"--\n"
5725"\n"
5726"Set the inheritable flag of the specified file descriptor.");
5727
5728#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005729 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005730
5731static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005732os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005733
5734static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005735os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005736{
5737 PyObject *return_value = NULL;
5738 int fd;
5739 int inheritable;
5740
Sylvain74453812017-06-10 06:51:48 +02005741 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5742 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005743 goto exit;
5744 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005745 return_value = os_set_inheritable_impl(module, fd, inheritable);
5746
5747exit:
5748 return return_value;
5749}
5750
5751#if defined(MS_WINDOWS)
5752
5753PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5754"get_handle_inheritable($module, handle, /)\n"
5755"--\n"
5756"\n"
5757"Get the close-on-exe flag of the specified file descriptor.");
5758
5759#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005760 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005761
5762static int
Victor Stinner581139c2016-09-06 15:54:20 -07005763os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005764
5765static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005766os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005767{
5768 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005769 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005770 int _return_value;
5771
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005772 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005773 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005774 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005775 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005776 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005777 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005778 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005779 return_value = PyBool_FromLong((long)_return_value);
5780
5781exit:
5782 return return_value;
5783}
5784
5785#endif /* defined(MS_WINDOWS) */
5786
5787#if defined(MS_WINDOWS)
5788
5789PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5790"set_handle_inheritable($module, handle, inheritable, /)\n"
5791"--\n"
5792"\n"
5793"Set the inheritable flag of the specified handle.");
5794
5795#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005796 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005797
5798static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005799os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005800 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005801
5802static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005803os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005804{
5805 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005806 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005807 int inheritable;
5808
Sylvain74453812017-06-10 06:51:48 +02005809 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5810 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005811 goto exit;
5812 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005813 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5814
5815exit:
5816 return return_value;
5817}
5818
5819#endif /* defined(MS_WINDOWS) */
5820
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005821PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5822"is_symlink($self, /)\n"
5823"--\n"
5824"\n"
5825"Return True if the entry is a symbolic link; cached per entry.");
5826
5827#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5828 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5829
5830static int
5831os_DirEntry_is_symlink_impl(DirEntry *self);
5832
5833static PyObject *
5834os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5835{
5836 PyObject *return_value = NULL;
5837 int _return_value;
5838
5839 _return_value = os_DirEntry_is_symlink_impl(self);
5840 if ((_return_value == -1) && PyErr_Occurred()) {
5841 goto exit;
5842 }
5843 return_value = PyBool_FromLong((long)_return_value);
5844
5845exit:
5846 return return_value;
5847}
5848
5849PyDoc_STRVAR(os_DirEntry_stat__doc__,
5850"stat($self, /, *, follow_symlinks=True)\n"
5851"--\n"
5852"\n"
5853"Return stat_result object for the entry; cached per entry.");
5854
5855#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005856 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005857
5858static PyObject *
5859os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5860
5861static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005862os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005863{
5864 PyObject *return_value = NULL;
5865 static const char * const _keywords[] = {"follow_symlinks", NULL};
5866 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5867 int follow_symlinks = 1;
5868
Victor Stinner3e1fad62017-01-17 01:29:01 +01005869 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005870 &follow_symlinks)) {
5871 goto exit;
5872 }
5873 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5874
5875exit:
5876 return return_value;
5877}
5878
5879PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5880"is_dir($self, /, *, follow_symlinks=True)\n"
5881"--\n"
5882"\n"
5883"Return True if the entry is a directory; cached per entry.");
5884
5885#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005886 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005887
5888static int
5889os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5890
5891static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005892os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005893{
5894 PyObject *return_value = NULL;
5895 static const char * const _keywords[] = {"follow_symlinks", NULL};
5896 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5897 int follow_symlinks = 1;
5898 int _return_value;
5899
Victor Stinner3e1fad62017-01-17 01:29:01 +01005900 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005901 &follow_symlinks)) {
5902 goto exit;
5903 }
5904 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5905 if ((_return_value == -1) && PyErr_Occurred()) {
5906 goto exit;
5907 }
5908 return_value = PyBool_FromLong((long)_return_value);
5909
5910exit:
5911 return return_value;
5912}
5913
5914PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5915"is_file($self, /, *, follow_symlinks=True)\n"
5916"--\n"
5917"\n"
5918"Return True if the entry is a file; cached per entry.");
5919
5920#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005921 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005922
5923static int
5924os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5925
5926static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005927os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005928{
5929 PyObject *return_value = NULL;
5930 static const char * const _keywords[] = {"follow_symlinks", NULL};
5931 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5932 int follow_symlinks = 1;
5933 int _return_value;
5934
Victor Stinner3e1fad62017-01-17 01:29:01 +01005935 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005936 &follow_symlinks)) {
5937 goto exit;
5938 }
5939 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5940 if ((_return_value == -1) && PyErr_Occurred()) {
5941 goto exit;
5942 }
5943 return_value = PyBool_FromLong((long)_return_value);
5944
5945exit:
5946 return return_value;
5947}
5948
5949PyDoc_STRVAR(os_DirEntry_inode__doc__,
5950"inode($self, /)\n"
5951"--\n"
5952"\n"
5953"Return inode of the entry; cached per entry.");
5954
5955#define OS_DIRENTRY_INODE_METHODDEF \
5956 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5957
5958static PyObject *
5959os_DirEntry_inode_impl(DirEntry *self);
5960
5961static PyObject *
5962os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5963{
5964 return os_DirEntry_inode_impl(self);
5965}
5966
5967PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5968"__fspath__($self, /)\n"
5969"--\n"
5970"\n"
5971"Returns the path for the entry.");
5972
5973#define OS_DIRENTRY___FSPATH___METHODDEF \
5974 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5975
5976static PyObject *
5977os_DirEntry___fspath___impl(DirEntry *self);
5978
5979static PyObject *
5980os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5981{
5982 return os_DirEntry___fspath___impl(self);
5983}
5984
5985PyDoc_STRVAR(os_scandir__doc__,
5986"scandir($module, /, path=None)\n"
5987"--\n"
5988"\n"
5989"Return an iterator of DirEntry objects for given path.\n"
5990"\n"
5991"path can be specified as either str, bytes or path-like object. If path\n"
5992"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5993"all other circumstances they will be str.\n"
5994"\n"
5995"If path is None, uses the path=\'.\'.");
5996
5997#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005998 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005999
6000static PyObject *
6001os_scandir_impl(PyObject *module, path_t *path);
6002
6003static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006004os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006005{
6006 PyObject *return_value = NULL;
6007 static const char * const _keywords[] = {"path", NULL};
6008 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006009 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006010
Victor Stinner3e1fad62017-01-17 01:29:01 +01006011 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006012 path_converter, &path)) {
6013 goto exit;
6014 }
6015 return_value = os_scandir_impl(module, &path);
6016
6017exit:
6018 /* Cleanup for path */
6019 path_cleanup(&path);
6020
6021 return return_value;
6022}
6023
Ethan Furman410ef8e2016-06-04 12:06:26 -07006024PyDoc_STRVAR(os_fspath__doc__,
6025"fspath($module, /, path)\n"
6026"--\n"
6027"\n"
6028"Return the file system path representation of the object.\n"
6029"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006030"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6031"object defines __fspath__(), then return the result of that method. All other\n"
6032"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006033
6034#define OS_FSPATH_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006035 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006036
6037static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006038os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006039
6040static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006041os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006042{
6043 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006044 static const char * const _keywords[] = {"path", NULL};
6045 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006046 PyObject *path;
6047
Victor Stinner3e1fad62017-01-17 01:29:01 +01006048 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006049 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006050 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006051 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006052 return_value = os_fspath_impl(module, path);
6053
6054exit:
6055 return return_value;
6056}
6057
Victor Stinner9b1f4742016-09-06 16:18:52 -07006058#if defined(HAVE_GETRANDOM_SYSCALL)
6059
6060PyDoc_STRVAR(os_getrandom__doc__,
6061"getrandom($module, /, size, flags=0)\n"
6062"--\n"
6063"\n"
6064"Obtain a series of random bytes.");
6065
6066#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006067 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006068
6069static PyObject *
6070os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6071
6072static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006073os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006074{
6075 PyObject *return_value = NULL;
6076 static const char * const _keywords[] = {"size", "flags", NULL};
6077 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6078 Py_ssize_t size;
6079 int flags = 0;
6080
Victor Stinner3e1fad62017-01-17 01:29:01 +01006081 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006082 &size, &flags)) {
6083 goto exit;
6084 }
6085 return_value = os_getrandom_impl(module, size, flags);
6086
6087exit:
6088 return return_value;
6089}
6090
6091#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6092
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006093#ifndef OS_TTYNAME_METHODDEF
6094 #define OS_TTYNAME_METHODDEF
6095#endif /* !defined(OS_TTYNAME_METHODDEF) */
6096
6097#ifndef OS_CTERMID_METHODDEF
6098 #define OS_CTERMID_METHODDEF
6099#endif /* !defined(OS_CTERMID_METHODDEF) */
6100
6101#ifndef OS_FCHDIR_METHODDEF
6102 #define OS_FCHDIR_METHODDEF
6103#endif /* !defined(OS_FCHDIR_METHODDEF) */
6104
6105#ifndef OS_FCHMOD_METHODDEF
6106 #define OS_FCHMOD_METHODDEF
6107#endif /* !defined(OS_FCHMOD_METHODDEF) */
6108
6109#ifndef OS_LCHMOD_METHODDEF
6110 #define OS_LCHMOD_METHODDEF
6111#endif /* !defined(OS_LCHMOD_METHODDEF) */
6112
6113#ifndef OS_CHFLAGS_METHODDEF
6114 #define OS_CHFLAGS_METHODDEF
6115#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6116
6117#ifndef OS_LCHFLAGS_METHODDEF
6118 #define OS_LCHFLAGS_METHODDEF
6119#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6120
6121#ifndef OS_CHROOT_METHODDEF
6122 #define OS_CHROOT_METHODDEF
6123#endif /* !defined(OS_CHROOT_METHODDEF) */
6124
6125#ifndef OS_FSYNC_METHODDEF
6126 #define OS_FSYNC_METHODDEF
6127#endif /* !defined(OS_FSYNC_METHODDEF) */
6128
6129#ifndef OS_SYNC_METHODDEF
6130 #define OS_SYNC_METHODDEF
6131#endif /* !defined(OS_SYNC_METHODDEF) */
6132
6133#ifndef OS_FDATASYNC_METHODDEF
6134 #define OS_FDATASYNC_METHODDEF
6135#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6136
6137#ifndef OS_CHOWN_METHODDEF
6138 #define OS_CHOWN_METHODDEF
6139#endif /* !defined(OS_CHOWN_METHODDEF) */
6140
6141#ifndef OS_FCHOWN_METHODDEF
6142 #define OS_FCHOWN_METHODDEF
6143#endif /* !defined(OS_FCHOWN_METHODDEF) */
6144
6145#ifndef OS_LCHOWN_METHODDEF
6146 #define OS_LCHOWN_METHODDEF
6147#endif /* !defined(OS_LCHOWN_METHODDEF) */
6148
6149#ifndef OS_LINK_METHODDEF
6150 #define OS_LINK_METHODDEF
6151#endif /* !defined(OS_LINK_METHODDEF) */
6152
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006153#ifndef OS__GETFULLPATHNAME_METHODDEF
6154 #define OS__GETFULLPATHNAME_METHODDEF
6155#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6156
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006157#ifndef OS__GETFINALPATHNAME_METHODDEF
6158 #define OS__GETFINALPATHNAME_METHODDEF
6159#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6160
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006161#ifndef OS__ISDIR_METHODDEF
6162 #define OS__ISDIR_METHODDEF
6163#endif /* !defined(OS__ISDIR_METHODDEF) */
6164
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006165#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6166 #define OS__GETVOLUMEPATHNAME_METHODDEF
6167#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6168
6169#ifndef OS_NICE_METHODDEF
6170 #define OS_NICE_METHODDEF
6171#endif /* !defined(OS_NICE_METHODDEF) */
6172
6173#ifndef OS_GETPRIORITY_METHODDEF
6174 #define OS_GETPRIORITY_METHODDEF
6175#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6176
6177#ifndef OS_SETPRIORITY_METHODDEF
6178 #define OS_SETPRIORITY_METHODDEF
6179#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6180
6181#ifndef OS_SYSTEM_METHODDEF
6182 #define OS_SYSTEM_METHODDEF
6183#endif /* !defined(OS_SYSTEM_METHODDEF) */
6184
6185#ifndef OS_UNAME_METHODDEF
6186 #define OS_UNAME_METHODDEF
6187#endif /* !defined(OS_UNAME_METHODDEF) */
6188
6189#ifndef OS_EXECV_METHODDEF
6190 #define OS_EXECV_METHODDEF
6191#endif /* !defined(OS_EXECV_METHODDEF) */
6192
6193#ifndef OS_EXECVE_METHODDEF
6194 #define OS_EXECVE_METHODDEF
6195#endif /* !defined(OS_EXECVE_METHODDEF) */
6196
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006197#ifndef OS_POSIX_SPAWN_METHODDEF
6198 #define OS_POSIX_SPAWN_METHODDEF
6199#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6200
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006201#ifndef OS_SPAWNV_METHODDEF
6202 #define OS_SPAWNV_METHODDEF
6203#endif /* !defined(OS_SPAWNV_METHODDEF) */
6204
6205#ifndef OS_SPAWNVE_METHODDEF
6206 #define OS_SPAWNVE_METHODDEF
6207#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6208
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006209#ifndef OS_REGISTER_AT_FORK_METHODDEF
6210 #define OS_REGISTER_AT_FORK_METHODDEF
6211#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6212
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006213#ifndef OS_FORK1_METHODDEF
6214 #define OS_FORK1_METHODDEF
6215#endif /* !defined(OS_FORK1_METHODDEF) */
6216
6217#ifndef OS_FORK_METHODDEF
6218 #define OS_FORK_METHODDEF
6219#endif /* !defined(OS_FORK_METHODDEF) */
6220
6221#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6222 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6223#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6224
6225#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6226 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6227#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6228
6229#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6230 #define OS_SCHED_GETSCHEDULER_METHODDEF
6231#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6232
6233#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6234 #define OS_SCHED_SETSCHEDULER_METHODDEF
6235#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6236
6237#ifndef OS_SCHED_GETPARAM_METHODDEF
6238 #define OS_SCHED_GETPARAM_METHODDEF
6239#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6240
6241#ifndef OS_SCHED_SETPARAM_METHODDEF
6242 #define OS_SCHED_SETPARAM_METHODDEF
6243#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6244
6245#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6246 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6247#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6248
6249#ifndef OS_SCHED_YIELD_METHODDEF
6250 #define OS_SCHED_YIELD_METHODDEF
6251#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6252
6253#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6254 #define OS_SCHED_SETAFFINITY_METHODDEF
6255#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6256
6257#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6258 #define OS_SCHED_GETAFFINITY_METHODDEF
6259#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6260
6261#ifndef OS_OPENPTY_METHODDEF
6262 #define OS_OPENPTY_METHODDEF
6263#endif /* !defined(OS_OPENPTY_METHODDEF) */
6264
6265#ifndef OS_FORKPTY_METHODDEF
6266 #define OS_FORKPTY_METHODDEF
6267#endif /* !defined(OS_FORKPTY_METHODDEF) */
6268
6269#ifndef OS_GETEGID_METHODDEF
6270 #define OS_GETEGID_METHODDEF
6271#endif /* !defined(OS_GETEGID_METHODDEF) */
6272
6273#ifndef OS_GETEUID_METHODDEF
6274 #define OS_GETEUID_METHODDEF
6275#endif /* !defined(OS_GETEUID_METHODDEF) */
6276
6277#ifndef OS_GETGID_METHODDEF
6278 #define OS_GETGID_METHODDEF
6279#endif /* !defined(OS_GETGID_METHODDEF) */
6280
Berker Peksag39404992016-09-15 20:45:16 +03006281#ifndef OS_GETPID_METHODDEF
6282 #define OS_GETPID_METHODDEF
6283#endif /* !defined(OS_GETPID_METHODDEF) */
6284
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006285#ifndef OS_GETGROUPS_METHODDEF
6286 #define OS_GETGROUPS_METHODDEF
6287#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6288
6289#ifndef OS_GETPGID_METHODDEF
6290 #define OS_GETPGID_METHODDEF
6291#endif /* !defined(OS_GETPGID_METHODDEF) */
6292
6293#ifndef OS_GETPGRP_METHODDEF
6294 #define OS_GETPGRP_METHODDEF
6295#endif /* !defined(OS_GETPGRP_METHODDEF) */
6296
6297#ifndef OS_SETPGRP_METHODDEF
6298 #define OS_SETPGRP_METHODDEF
6299#endif /* !defined(OS_SETPGRP_METHODDEF) */
6300
6301#ifndef OS_GETPPID_METHODDEF
6302 #define OS_GETPPID_METHODDEF
6303#endif /* !defined(OS_GETPPID_METHODDEF) */
6304
6305#ifndef OS_GETLOGIN_METHODDEF
6306 #define OS_GETLOGIN_METHODDEF
6307#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6308
6309#ifndef OS_GETUID_METHODDEF
6310 #define OS_GETUID_METHODDEF
6311#endif /* !defined(OS_GETUID_METHODDEF) */
6312
6313#ifndef OS_KILL_METHODDEF
6314 #define OS_KILL_METHODDEF
6315#endif /* !defined(OS_KILL_METHODDEF) */
6316
6317#ifndef OS_KILLPG_METHODDEF
6318 #define OS_KILLPG_METHODDEF
6319#endif /* !defined(OS_KILLPG_METHODDEF) */
6320
6321#ifndef OS_PLOCK_METHODDEF
6322 #define OS_PLOCK_METHODDEF
6323#endif /* !defined(OS_PLOCK_METHODDEF) */
6324
6325#ifndef OS_SETUID_METHODDEF
6326 #define OS_SETUID_METHODDEF
6327#endif /* !defined(OS_SETUID_METHODDEF) */
6328
6329#ifndef OS_SETEUID_METHODDEF
6330 #define OS_SETEUID_METHODDEF
6331#endif /* !defined(OS_SETEUID_METHODDEF) */
6332
6333#ifndef OS_SETEGID_METHODDEF
6334 #define OS_SETEGID_METHODDEF
6335#endif /* !defined(OS_SETEGID_METHODDEF) */
6336
6337#ifndef OS_SETREUID_METHODDEF
6338 #define OS_SETREUID_METHODDEF
6339#endif /* !defined(OS_SETREUID_METHODDEF) */
6340
6341#ifndef OS_SETREGID_METHODDEF
6342 #define OS_SETREGID_METHODDEF
6343#endif /* !defined(OS_SETREGID_METHODDEF) */
6344
6345#ifndef OS_SETGID_METHODDEF
6346 #define OS_SETGID_METHODDEF
6347#endif /* !defined(OS_SETGID_METHODDEF) */
6348
6349#ifndef OS_SETGROUPS_METHODDEF
6350 #define OS_SETGROUPS_METHODDEF
6351#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6352
6353#ifndef OS_WAIT3_METHODDEF
6354 #define OS_WAIT3_METHODDEF
6355#endif /* !defined(OS_WAIT3_METHODDEF) */
6356
6357#ifndef OS_WAIT4_METHODDEF
6358 #define OS_WAIT4_METHODDEF
6359#endif /* !defined(OS_WAIT4_METHODDEF) */
6360
6361#ifndef OS_WAITID_METHODDEF
6362 #define OS_WAITID_METHODDEF
6363#endif /* !defined(OS_WAITID_METHODDEF) */
6364
6365#ifndef OS_WAITPID_METHODDEF
6366 #define OS_WAITPID_METHODDEF
6367#endif /* !defined(OS_WAITPID_METHODDEF) */
6368
6369#ifndef OS_WAIT_METHODDEF
6370 #define OS_WAIT_METHODDEF
6371#endif /* !defined(OS_WAIT_METHODDEF) */
6372
6373#ifndef OS_SYMLINK_METHODDEF
6374 #define OS_SYMLINK_METHODDEF
6375#endif /* !defined(OS_SYMLINK_METHODDEF) */
6376
6377#ifndef OS_TIMES_METHODDEF
6378 #define OS_TIMES_METHODDEF
6379#endif /* !defined(OS_TIMES_METHODDEF) */
6380
6381#ifndef OS_GETSID_METHODDEF
6382 #define OS_GETSID_METHODDEF
6383#endif /* !defined(OS_GETSID_METHODDEF) */
6384
6385#ifndef OS_SETSID_METHODDEF
6386 #define OS_SETSID_METHODDEF
6387#endif /* !defined(OS_SETSID_METHODDEF) */
6388
6389#ifndef OS_SETPGID_METHODDEF
6390 #define OS_SETPGID_METHODDEF
6391#endif /* !defined(OS_SETPGID_METHODDEF) */
6392
6393#ifndef OS_TCGETPGRP_METHODDEF
6394 #define OS_TCGETPGRP_METHODDEF
6395#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6396
6397#ifndef OS_TCSETPGRP_METHODDEF
6398 #define OS_TCSETPGRP_METHODDEF
6399#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6400
6401#ifndef OS_LOCKF_METHODDEF
6402 #define OS_LOCKF_METHODDEF
6403#endif /* !defined(OS_LOCKF_METHODDEF) */
6404
6405#ifndef OS_READV_METHODDEF
6406 #define OS_READV_METHODDEF
6407#endif /* !defined(OS_READV_METHODDEF) */
6408
6409#ifndef OS_PREAD_METHODDEF
6410 #define OS_PREAD_METHODDEF
6411#endif /* !defined(OS_PREAD_METHODDEF) */
6412
Pablo Galindo4defba32018-01-27 16:16:37 +00006413#ifndef OS_PREADV_METHODDEF
6414 #define OS_PREADV_METHODDEF
6415#endif /* !defined(OS_PREADV_METHODDEF) */
6416
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006417#ifndef OS_PIPE_METHODDEF
6418 #define OS_PIPE_METHODDEF
6419#endif /* !defined(OS_PIPE_METHODDEF) */
6420
6421#ifndef OS_PIPE2_METHODDEF
6422 #define OS_PIPE2_METHODDEF
6423#endif /* !defined(OS_PIPE2_METHODDEF) */
6424
6425#ifndef OS_WRITEV_METHODDEF
6426 #define OS_WRITEV_METHODDEF
6427#endif /* !defined(OS_WRITEV_METHODDEF) */
6428
6429#ifndef OS_PWRITE_METHODDEF
6430 #define OS_PWRITE_METHODDEF
6431#endif /* !defined(OS_PWRITE_METHODDEF) */
6432
Pablo Galindo4defba32018-01-27 16:16:37 +00006433#ifndef OS_PWRITEV_METHODDEF
6434 #define OS_PWRITEV_METHODDEF
6435#endif /* !defined(OS_PWRITEV_METHODDEF) */
6436
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006437#ifndef OS_MKFIFO_METHODDEF
6438 #define OS_MKFIFO_METHODDEF
6439#endif /* !defined(OS_MKFIFO_METHODDEF) */
6440
6441#ifndef OS_MKNOD_METHODDEF
6442 #define OS_MKNOD_METHODDEF
6443#endif /* !defined(OS_MKNOD_METHODDEF) */
6444
6445#ifndef OS_MAJOR_METHODDEF
6446 #define OS_MAJOR_METHODDEF
6447#endif /* !defined(OS_MAJOR_METHODDEF) */
6448
6449#ifndef OS_MINOR_METHODDEF
6450 #define OS_MINOR_METHODDEF
6451#endif /* !defined(OS_MINOR_METHODDEF) */
6452
6453#ifndef OS_MAKEDEV_METHODDEF
6454 #define OS_MAKEDEV_METHODDEF
6455#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6456
6457#ifndef OS_FTRUNCATE_METHODDEF
6458 #define OS_FTRUNCATE_METHODDEF
6459#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6460
6461#ifndef OS_TRUNCATE_METHODDEF
6462 #define OS_TRUNCATE_METHODDEF
6463#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6464
6465#ifndef OS_POSIX_FALLOCATE_METHODDEF
6466 #define OS_POSIX_FALLOCATE_METHODDEF
6467#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6468
6469#ifndef OS_POSIX_FADVISE_METHODDEF
6470 #define OS_POSIX_FADVISE_METHODDEF
6471#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6472
6473#ifndef OS_PUTENV_METHODDEF
6474 #define OS_PUTENV_METHODDEF
6475#endif /* !defined(OS_PUTENV_METHODDEF) */
6476
6477#ifndef OS_UNSETENV_METHODDEF
6478 #define OS_UNSETENV_METHODDEF
6479#endif /* !defined(OS_UNSETENV_METHODDEF) */
6480
6481#ifndef OS_WCOREDUMP_METHODDEF
6482 #define OS_WCOREDUMP_METHODDEF
6483#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6484
6485#ifndef OS_WIFCONTINUED_METHODDEF
6486 #define OS_WIFCONTINUED_METHODDEF
6487#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6488
6489#ifndef OS_WIFSTOPPED_METHODDEF
6490 #define OS_WIFSTOPPED_METHODDEF
6491#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6492
6493#ifndef OS_WIFSIGNALED_METHODDEF
6494 #define OS_WIFSIGNALED_METHODDEF
6495#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6496
6497#ifndef OS_WIFEXITED_METHODDEF
6498 #define OS_WIFEXITED_METHODDEF
6499#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6500
6501#ifndef OS_WEXITSTATUS_METHODDEF
6502 #define OS_WEXITSTATUS_METHODDEF
6503#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6504
6505#ifndef OS_WTERMSIG_METHODDEF
6506 #define OS_WTERMSIG_METHODDEF
6507#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6508
6509#ifndef OS_WSTOPSIG_METHODDEF
6510 #define OS_WSTOPSIG_METHODDEF
6511#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6512
6513#ifndef OS_FSTATVFS_METHODDEF
6514 #define OS_FSTATVFS_METHODDEF
6515#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6516
6517#ifndef OS_STATVFS_METHODDEF
6518 #define OS_STATVFS_METHODDEF
6519#endif /* !defined(OS_STATVFS_METHODDEF) */
6520
6521#ifndef OS__GETDISKUSAGE_METHODDEF
6522 #define OS__GETDISKUSAGE_METHODDEF
6523#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6524
6525#ifndef OS_FPATHCONF_METHODDEF
6526 #define OS_FPATHCONF_METHODDEF
6527#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6528
6529#ifndef OS_PATHCONF_METHODDEF
6530 #define OS_PATHCONF_METHODDEF
6531#endif /* !defined(OS_PATHCONF_METHODDEF) */
6532
6533#ifndef OS_CONFSTR_METHODDEF
6534 #define OS_CONFSTR_METHODDEF
6535#endif /* !defined(OS_CONFSTR_METHODDEF) */
6536
6537#ifndef OS_SYSCONF_METHODDEF
6538 #define OS_SYSCONF_METHODDEF
6539#endif /* !defined(OS_SYSCONF_METHODDEF) */
6540
Steve Dowercc16be82016-09-08 10:35:16 -07006541#ifndef OS_STARTFILE_METHODDEF
6542 #define OS_STARTFILE_METHODDEF
6543#endif /* !defined(OS_STARTFILE_METHODDEF) */
6544
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006545#ifndef OS_GETLOADAVG_METHODDEF
6546 #define OS_GETLOADAVG_METHODDEF
6547#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6548
6549#ifndef OS_SETRESUID_METHODDEF
6550 #define OS_SETRESUID_METHODDEF
6551#endif /* !defined(OS_SETRESUID_METHODDEF) */
6552
6553#ifndef OS_SETRESGID_METHODDEF
6554 #define OS_SETRESGID_METHODDEF
6555#endif /* !defined(OS_SETRESGID_METHODDEF) */
6556
6557#ifndef OS_GETRESUID_METHODDEF
6558 #define OS_GETRESUID_METHODDEF
6559#endif /* !defined(OS_GETRESUID_METHODDEF) */
6560
6561#ifndef OS_GETRESGID_METHODDEF
6562 #define OS_GETRESGID_METHODDEF
6563#endif /* !defined(OS_GETRESGID_METHODDEF) */
6564
6565#ifndef OS_GETXATTR_METHODDEF
6566 #define OS_GETXATTR_METHODDEF
6567#endif /* !defined(OS_GETXATTR_METHODDEF) */
6568
6569#ifndef OS_SETXATTR_METHODDEF
6570 #define OS_SETXATTR_METHODDEF
6571#endif /* !defined(OS_SETXATTR_METHODDEF) */
6572
6573#ifndef OS_REMOVEXATTR_METHODDEF
6574 #define OS_REMOVEXATTR_METHODDEF
6575#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6576
6577#ifndef OS_LISTXATTR_METHODDEF
6578 #define OS_LISTXATTR_METHODDEF
6579#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6580
6581#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6582 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6583#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6584
6585#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6586 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6587#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006588
6589#ifndef OS_GETRANDOM_METHODDEF
6590 #define OS_GETRANDOM_METHODDEF
6591#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Steve Dower23ad6d02018-02-22 10:39:10 -08006592/*[clinic end generated code: output=fc603214822bdda6 input=a9049054013a1b77]*/