blob: 7a2188504ac57e4791591d17a899a085c6362ec1 [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"
Serhiy Storchakaef347532018-05-01 16:45:04 +03001745" A sequence of file action tuples.");
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001746
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
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003856#if defined(__APPLE__)
3857
3858PyDoc_STRVAR(os__fcopyfile__doc__,
3859"_fcopyfile($module, infd, outfd, flags, /)\n"
3860"--\n"
3861"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07003862"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003863
3864#define OS__FCOPYFILE_METHODDEF \
3865 {"_fcopyfile", (PyCFunction)os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
3866
3867static PyObject *
3868os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
3869
3870static PyObject *
3871os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3872{
3873 PyObject *return_value = NULL;
3874 int infd;
3875 int outfd;
3876 int flags;
3877
3878 if (!_PyArg_ParseStack(args, nargs, "iii:_fcopyfile",
3879 &infd, &outfd, &flags)) {
3880 goto exit;
3881 }
3882 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
3883
3884exit:
3885 return return_value;
3886}
3887
3888#endif /* defined(__APPLE__) */
3889
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003890PyDoc_STRVAR(os_fstat__doc__,
3891"fstat($module, /, fd)\n"
3892"--\n"
3893"\n"
3894"Perform a stat system call on the given file descriptor.\n"
3895"\n"
3896"Like stat(), but for an open file descriptor.\n"
3897"Equivalent to os.stat(fd).");
3898
3899#define OS_FSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003900 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003901
3902static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003903os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003904
3905static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003906os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003907{
3908 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003909 static const char * const _keywords[] = {"fd", NULL};
3910 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003911 int fd;
3912
Victor Stinner3e1fad62017-01-17 01:29:01 +01003913 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003914 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003915 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003916 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003917 return_value = os_fstat_impl(module, fd);
3918
3919exit:
3920 return return_value;
3921}
3922
3923PyDoc_STRVAR(os_isatty__doc__,
3924"isatty($module, fd, /)\n"
3925"--\n"
3926"\n"
3927"Return True if the fd is connected to a terminal.\n"
3928"\n"
3929"Return True if the file descriptor is an open file descriptor\n"
3930"connected to the slave end of a terminal.");
3931
3932#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003933 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003934
3935static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003936os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003937
3938static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003939os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003940{
3941 PyObject *return_value = NULL;
3942 int fd;
3943 int _return_value;
3944
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003945 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003946 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003947 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003948 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003949 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003951 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003952 return_value = PyBool_FromLong((long)_return_value);
3953
3954exit:
3955 return return_value;
3956}
3957
3958#if defined(HAVE_PIPE)
3959
3960PyDoc_STRVAR(os_pipe__doc__,
3961"pipe($module, /)\n"
3962"--\n"
3963"\n"
3964"Create a pipe.\n"
3965"\n"
3966"Returns a tuple of two file descriptors:\n"
3967" (read_fd, write_fd)");
3968
3969#define OS_PIPE_METHODDEF \
3970 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3971
3972static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003973os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003974
3975static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003976os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003977{
3978 return os_pipe_impl(module);
3979}
3980
3981#endif /* defined(HAVE_PIPE) */
3982
3983#if defined(HAVE_PIPE2)
3984
3985PyDoc_STRVAR(os_pipe2__doc__,
3986"pipe2($module, flags, /)\n"
3987"--\n"
3988"\n"
3989"Create a pipe with flags set atomically.\n"
3990"\n"
3991"Returns a tuple of two file descriptors:\n"
3992" (read_fd, write_fd)\n"
3993"\n"
3994"flags can be constructed by ORing together one or more of these values:\n"
3995"O_NONBLOCK, O_CLOEXEC.");
3996
3997#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003998 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003999
4000static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004001os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004002
4003static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004004os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004005{
4006 PyObject *return_value = NULL;
4007 int flags;
4008
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004009 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004010 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004011 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004012 return_value = os_pipe2_impl(module, flags);
4013
4014exit:
4015 return return_value;
4016}
4017
4018#endif /* defined(HAVE_PIPE2) */
4019
4020#if defined(HAVE_WRITEV)
4021
4022PyDoc_STRVAR(os_writev__doc__,
4023"writev($module, fd, buffers, /)\n"
4024"--\n"
4025"\n"
4026"Iterate over buffers, and write the contents of each to a file descriptor.\n"
4027"\n"
4028"Returns the total number of bytes written.\n"
4029"buffers must be a sequence of bytes-like objects.");
4030
4031#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004032 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004033
4034static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004035os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004036
4037static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004038os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004039{
4040 PyObject *return_value = NULL;
4041 int fd;
4042 PyObject *buffers;
4043 Py_ssize_t _return_value;
4044
Sylvain74453812017-06-10 06:51:48 +02004045 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
4046 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004047 goto exit;
4048 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004049 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004050 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004051 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004052 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004053 return_value = PyLong_FromSsize_t(_return_value);
4054
4055exit:
4056 return return_value;
4057}
4058
4059#endif /* defined(HAVE_WRITEV) */
4060
4061#if defined(HAVE_PWRITE)
4062
4063PyDoc_STRVAR(os_pwrite__doc__,
4064"pwrite($module, fd, buffer, offset, /)\n"
4065"--\n"
4066"\n"
4067"Write bytes to a file descriptor starting at a particular offset.\n"
4068"\n"
4069"Write buffer to fd, starting at offset bytes from the beginning of\n"
4070"the file. Returns the number of bytes writte. Does not change the\n"
4071"current file offset.");
4072
4073#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004074 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004075
4076static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004077os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004078
4079static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004080os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004081{
4082 PyObject *return_value = NULL;
4083 int fd;
4084 Py_buffer buffer = {NULL, NULL};
4085 Py_off_t offset;
4086 Py_ssize_t _return_value;
4087
Sylvain74453812017-06-10 06:51:48 +02004088 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4089 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004090 goto exit;
4091 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004092 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004093 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004094 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004095 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004096 return_value = PyLong_FromSsize_t(_return_value);
4097
4098exit:
4099 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004100 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004101 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004102 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004103
4104 return return_value;
4105}
4106
4107#endif /* defined(HAVE_PWRITE) */
4108
Pablo Galindo4defba32018-01-27 16:16:37 +00004109#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4110
4111PyDoc_STRVAR(os_pwritev__doc__,
4112"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4113"--\n"
4114"\n"
4115"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4116"\n"
4117"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4118"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4119"buffer is written before proceeding to second, and so on. The operating system may\n"
4120"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4121"This function writes the contents of each object to the file descriptor and returns\n"
4122"the total number of bytes written.\n"
4123"\n"
4124"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4125"\n"
4126"- RWF_DSYNC\n"
4127"- RWF_SYNC\n"
4128"\n"
4129"Using non-zero flags requires Linux 4.7 or newer.");
4130
4131#define OS_PWRITEV_METHODDEF \
4132 {"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},
4133
4134static Py_ssize_t
4135os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4136 int flags);
4137
4138static PyObject *
4139os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4140{
4141 PyObject *return_value = NULL;
4142 int fd;
4143 PyObject *buffers;
4144 Py_off_t offset;
4145 int flags = 0;
4146 Py_ssize_t _return_value;
4147
4148 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4149 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4150 goto exit;
4151 }
4152 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4153 if ((_return_value == -1) && PyErr_Occurred()) {
4154 goto exit;
4155 }
4156 return_value = PyLong_FromSsize_t(_return_value);
4157
4158exit:
4159 return return_value;
4160}
4161
4162#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4163
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004164#if defined(HAVE_MKFIFO)
4165
4166PyDoc_STRVAR(os_mkfifo__doc__,
4167"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4168"--\n"
4169"\n"
4170"Create a \"fifo\" (a POSIX named pipe).\n"
4171"\n"
4172"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4173" and path should be relative; path will then be relative to that directory.\n"
4174"dir_fd may not be implemented on your platform.\n"
4175" If it is unavailable, using it will raise a NotImplementedError.");
4176
4177#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004178 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004179
4180static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004181os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004182
4183static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004184os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004185{
4186 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004187 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4188 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004189 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4190 int mode = 438;
4191 int dir_fd = DEFAULT_DIR_FD;
4192
Victor Stinner3e1fad62017-01-17 01:29:01 +01004193 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004194 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004195 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004196 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004197 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4198
4199exit:
4200 /* Cleanup for path */
4201 path_cleanup(&path);
4202
4203 return return_value;
4204}
4205
4206#endif /* defined(HAVE_MKFIFO) */
4207
4208#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4209
4210PyDoc_STRVAR(os_mknod__doc__,
4211"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4212"--\n"
4213"\n"
4214"Create a node in the file system.\n"
4215"\n"
4216"Create a node in the file system (file, device special file or named pipe)\n"
4217"at path. mode specifies both the permissions to use and the\n"
4218"type of node to be created, being combined (bitwise OR) with one of\n"
4219"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4220"device defines the newly created device special file (probably using\n"
4221"os.makedev()). Otherwise device is ignored.\n"
4222"\n"
4223"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4224" and path should be relative; path will then be relative to that directory.\n"
4225"dir_fd may not be implemented on your platform.\n"
4226" If it is unavailable, using it will raise a NotImplementedError.");
4227
4228#define OS_MKNOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004229 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004230
4231static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004232os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004233 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004234
4235static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004236os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004237{
4238 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004239 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4240 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004241 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4242 int mode = 384;
4243 dev_t device = 0;
4244 int dir_fd = DEFAULT_DIR_FD;
4245
Victor Stinner3e1fad62017-01-17 01:29:01 +01004246 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004247 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004248 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004249 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004250 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4251
4252exit:
4253 /* Cleanup for path */
4254 path_cleanup(&path);
4255
4256 return return_value;
4257}
4258
4259#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4260
4261#if defined(HAVE_DEVICE_MACROS)
4262
4263PyDoc_STRVAR(os_major__doc__,
4264"major($module, device, /)\n"
4265"--\n"
4266"\n"
4267"Extracts a device major number from a raw device number.");
4268
4269#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004270 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004271
4272static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004273os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004274
4275static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004276os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004277{
4278 PyObject *return_value = NULL;
4279 dev_t device;
4280 unsigned int _return_value;
4281
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004282 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004285 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004286 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004287 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004288 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004289 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4290
4291exit:
4292 return return_value;
4293}
4294
4295#endif /* defined(HAVE_DEVICE_MACROS) */
4296
4297#if defined(HAVE_DEVICE_MACROS)
4298
4299PyDoc_STRVAR(os_minor__doc__,
4300"minor($module, device, /)\n"
4301"--\n"
4302"\n"
4303"Extracts a device minor number from a raw device number.");
4304
4305#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004306 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004307
4308static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004309os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004310
4311static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004312os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004313{
4314 PyObject *return_value = NULL;
4315 dev_t device;
4316 unsigned int _return_value;
4317
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004318 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004319 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004320 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004321 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004322 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004323 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004324 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004325 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4326
4327exit:
4328 return return_value;
4329}
4330
4331#endif /* defined(HAVE_DEVICE_MACROS) */
4332
4333#if defined(HAVE_DEVICE_MACROS)
4334
4335PyDoc_STRVAR(os_makedev__doc__,
4336"makedev($module, major, minor, /)\n"
4337"--\n"
4338"\n"
4339"Composes a raw device number from the major and minor device numbers.");
4340
4341#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004342 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004343
4344static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004345os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004346
4347static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004348os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004349{
4350 PyObject *return_value = NULL;
4351 int major;
4352 int minor;
4353 dev_t _return_value;
4354
Sylvain74453812017-06-10 06:51:48 +02004355 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4356 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004357 goto exit;
4358 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004359 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004360 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004361 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004362 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004363 return_value = _PyLong_FromDev(_return_value);
4364
4365exit:
4366 return return_value;
4367}
4368
4369#endif /* defined(HAVE_DEVICE_MACROS) */
4370
Steve Dowerf7377032015-04-12 15:44:54 -04004371#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004372
4373PyDoc_STRVAR(os_ftruncate__doc__,
4374"ftruncate($module, fd, length, /)\n"
4375"--\n"
4376"\n"
4377"Truncate a file, specified by file descriptor, to a specific length.");
4378
4379#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004380 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004381
4382static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004383os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004384
4385static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004386os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004387{
4388 PyObject *return_value = NULL;
4389 int fd;
4390 Py_off_t length;
4391
Sylvain74453812017-06-10 06:51:48 +02004392 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4393 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004394 goto exit;
4395 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004396 return_value = os_ftruncate_impl(module, fd, length);
4397
4398exit:
4399 return return_value;
4400}
4401
Steve Dowerf7377032015-04-12 15:44:54 -04004402#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004403
Steve Dowerf7377032015-04-12 15:44:54 -04004404#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004405
4406PyDoc_STRVAR(os_truncate__doc__,
4407"truncate($module, /, path, length)\n"
4408"--\n"
4409"\n"
4410"Truncate a file, specified by path, to a specific length.\n"
4411"\n"
4412"On some platforms, path may also be specified as an open file descriptor.\n"
4413" If this functionality is unavailable, using it raises an exception.");
4414
4415#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004416 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004417
4418static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004419os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004420
4421static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004422os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004423{
4424 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004425 static const char * const _keywords[] = {"path", "length", NULL};
4426 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004427 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4428 Py_off_t length;
4429
Victor Stinner3e1fad62017-01-17 01:29:01 +01004430 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004431 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004432 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004433 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004434 return_value = os_truncate_impl(module, &path, length);
4435
4436exit:
4437 /* Cleanup for path */
4438 path_cleanup(&path);
4439
4440 return return_value;
4441}
4442
Steve Dowerf7377032015-04-12 15:44:54 -04004443#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004444
4445#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4446
4447PyDoc_STRVAR(os_posix_fallocate__doc__,
4448"posix_fallocate($module, fd, offset, length, /)\n"
4449"--\n"
4450"\n"
4451"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4452"\n"
4453"Ensure that the file specified by fd encompasses a range of bytes\n"
4454"starting at offset bytes from the beginning and continuing for length bytes.");
4455
4456#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004457 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004458
4459static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004460os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004461 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004462
4463static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004464os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004465{
4466 PyObject *return_value = NULL;
4467 int fd;
4468 Py_off_t offset;
4469 Py_off_t length;
4470
Sylvain74453812017-06-10 06:51:48 +02004471 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4472 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004473 goto exit;
4474 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004475 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4476
4477exit:
4478 return return_value;
4479}
4480
4481#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4482
4483#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4484
4485PyDoc_STRVAR(os_posix_fadvise__doc__,
4486"posix_fadvise($module, fd, offset, length, advice, /)\n"
4487"--\n"
4488"\n"
4489"Announce an intention to access data in a specific pattern.\n"
4490"\n"
4491"Announce an intention to access data in a specific pattern, thus allowing\n"
4492"the kernel to make optimizations.\n"
4493"The advice applies to the region of the file specified by fd starting at\n"
4494"offset and continuing for length bytes.\n"
4495"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4496"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4497"POSIX_FADV_DONTNEED.");
4498
4499#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004500 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004501
4502static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004503os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004504 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004505
4506static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004507os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004508{
4509 PyObject *return_value = NULL;
4510 int fd;
4511 Py_off_t offset;
4512 Py_off_t length;
4513 int advice;
4514
Sylvain74453812017-06-10 06:51:48 +02004515 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4516 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004517 goto exit;
4518 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004519 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4520
4521exit:
4522 return return_value;
4523}
4524
4525#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4526
4527#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4528
4529PyDoc_STRVAR(os_putenv__doc__,
4530"putenv($module, name, value, /)\n"
4531"--\n"
4532"\n"
4533"Change or add an environment variable.");
4534
4535#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004536 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004537
4538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004539os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004540
4541static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004542os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004543{
4544 PyObject *return_value = NULL;
4545 PyObject *name;
4546 PyObject *value;
4547
Sylvain74453812017-06-10 06:51:48 +02004548 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4549 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004550 goto exit;
4551 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004552 return_value = os_putenv_impl(module, name, value);
4553
4554exit:
4555 return return_value;
4556}
4557
4558#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4559
4560#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4561
4562PyDoc_STRVAR(os_putenv__doc__,
4563"putenv($module, name, value, /)\n"
4564"--\n"
4565"\n"
4566"Change or add an environment variable.");
4567
4568#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004569 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004570
4571static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004572os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004573
4574static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004575os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004576{
4577 PyObject *return_value = NULL;
4578 PyObject *name = NULL;
4579 PyObject *value = NULL;
4580
Sylvain74453812017-06-10 06:51:48 +02004581 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4582 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004583 goto exit;
4584 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004585 return_value = os_putenv_impl(module, name, value);
4586
4587exit:
4588 /* Cleanup for name */
4589 Py_XDECREF(name);
4590 /* Cleanup for value */
4591 Py_XDECREF(value);
4592
4593 return return_value;
4594}
4595
4596#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4597
4598#if defined(HAVE_UNSETENV)
4599
4600PyDoc_STRVAR(os_unsetenv__doc__,
4601"unsetenv($module, name, /)\n"
4602"--\n"
4603"\n"
4604"Delete an environment variable.");
4605
4606#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004607 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004608
4609static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004610os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004611
4612static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004613os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004614{
4615 PyObject *return_value = NULL;
4616 PyObject *name = NULL;
4617
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004618 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004619 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004620 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004621 return_value = os_unsetenv_impl(module, name);
4622
4623exit:
4624 /* Cleanup for name */
4625 Py_XDECREF(name);
4626
4627 return return_value;
4628}
4629
4630#endif /* defined(HAVE_UNSETENV) */
4631
4632PyDoc_STRVAR(os_strerror__doc__,
4633"strerror($module, code, /)\n"
4634"--\n"
4635"\n"
4636"Translate an error code to a message string.");
4637
4638#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004639 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004640
4641static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004642os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004643
4644static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004645os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004646{
4647 PyObject *return_value = NULL;
4648 int code;
4649
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004650 if (!PyArg_Parse(arg, "i:strerror", &code)) {
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 = os_strerror_impl(module, code);
4654
4655exit:
4656 return return_value;
4657}
4658
4659#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4660
4661PyDoc_STRVAR(os_WCOREDUMP__doc__,
4662"WCOREDUMP($module, status, /)\n"
4663"--\n"
4664"\n"
4665"Return True if the process returning status was dumped to a core file.");
4666
4667#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004668 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004669
4670static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004671os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004672
4673static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004674os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004675{
4676 PyObject *return_value = NULL;
4677 int status;
4678 int _return_value;
4679
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004680 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004681 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004682 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004683 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004684 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004685 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004686 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004687 return_value = PyBool_FromLong((long)_return_value);
4688
4689exit:
4690 return return_value;
4691}
4692
4693#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4694
4695#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4696
4697PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4698"WIFCONTINUED($module, /, status)\n"
4699"--\n"
4700"\n"
4701"Return True if a particular process was continued from a job control stop.\n"
4702"\n"
4703"Return True if the process returning status was continued from a\n"
4704"job control stop.");
4705
4706#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004707 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708
4709static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004710os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004711
4712static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004713os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004714{
4715 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004716 static const char * const _keywords[] = {"status", NULL};
4717 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004718 int status;
4719 int _return_value;
4720
Victor Stinner3e1fad62017-01-17 01:29:01 +01004721 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004722 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004723 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004724 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004725 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004726 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004727 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004728 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004729 return_value = PyBool_FromLong((long)_return_value);
4730
4731exit:
4732 return return_value;
4733}
4734
4735#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4736
4737#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4738
4739PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4740"WIFSTOPPED($module, /, status)\n"
4741"--\n"
4742"\n"
4743"Return True if the process returning status was stopped.");
4744
4745#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004746 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004747
4748static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004749os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004750
4751static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004752os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004753{
4754 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004755 static const char * const _keywords[] = {"status", NULL};
4756 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004757 int status;
4758 int _return_value;
4759
Victor Stinner3e1fad62017-01-17 01:29:01 +01004760 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004761 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004762 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004763 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004764 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004765 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004766 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004767 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004768 return_value = PyBool_FromLong((long)_return_value);
4769
4770exit:
4771 return return_value;
4772}
4773
4774#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4775
4776#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4777
4778PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4779"WIFSIGNALED($module, /, status)\n"
4780"--\n"
4781"\n"
4782"Return True if the process returning status was terminated by a signal.");
4783
4784#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004785 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004786
4787static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004788os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004789
4790static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004791os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004792{
4793 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004794 static const char * const _keywords[] = {"status", NULL};
4795 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004796 int status;
4797 int _return_value;
4798
Victor Stinner3e1fad62017-01-17 01:29:01 +01004799 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004800 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004801 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004802 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004803 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004804 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004805 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004806 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004807 return_value = PyBool_FromLong((long)_return_value);
4808
4809exit:
4810 return return_value;
4811}
4812
4813#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4814
4815#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4816
4817PyDoc_STRVAR(os_WIFEXITED__doc__,
4818"WIFEXITED($module, /, status)\n"
4819"--\n"
4820"\n"
4821"Return True if the process returning status exited via the exit() system call.");
4822
4823#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004824 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004825
4826static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004827os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004828
4829static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004830os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004831{
4832 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004833 static const char * const _keywords[] = {"status", NULL};
4834 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004835 int status;
4836 int _return_value;
4837
Victor Stinner3e1fad62017-01-17 01:29:01 +01004838 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004839 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004840 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004841 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004842 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004843 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004844 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004845 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004846 return_value = PyBool_FromLong((long)_return_value);
4847
4848exit:
4849 return return_value;
4850}
4851
4852#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4853
4854#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4855
4856PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4857"WEXITSTATUS($module, /, status)\n"
4858"--\n"
4859"\n"
4860"Return the process return code from status.");
4861
4862#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004863 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004864
4865static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004866os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004867
4868static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004869os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004870{
4871 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004872 static const char * const _keywords[] = {"status", NULL};
4873 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004874 int status;
4875 int _return_value;
4876
Victor Stinner3e1fad62017-01-17 01:29:01 +01004877 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004878 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004879 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004880 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004881 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004882 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004883 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004884 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004885 return_value = PyLong_FromLong((long)_return_value);
4886
4887exit:
4888 return return_value;
4889}
4890
4891#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4892
4893#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4894
4895PyDoc_STRVAR(os_WTERMSIG__doc__,
4896"WTERMSIG($module, /, status)\n"
4897"--\n"
4898"\n"
4899"Return the signal that terminated the process that provided the status value.");
4900
4901#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004902 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004903
4904static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004905os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004906
4907static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004908os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004909{
4910 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004911 static const char * const _keywords[] = {"status", NULL};
4912 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004913 int status;
4914 int _return_value;
4915
Victor Stinner3e1fad62017-01-17 01:29:01 +01004916 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004917 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004918 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004919 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004920 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004921 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004922 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004923 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004924 return_value = PyLong_FromLong((long)_return_value);
4925
4926exit:
4927 return return_value;
4928}
4929
4930#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4931
4932#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4933
4934PyDoc_STRVAR(os_WSTOPSIG__doc__,
4935"WSTOPSIG($module, /, status)\n"
4936"--\n"
4937"\n"
4938"Return the signal that stopped the process that provided the status value.");
4939
4940#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004941 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004942
4943static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004944os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004945
4946static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004947os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004948{
4949 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004950 static const char * const _keywords[] = {"status", NULL};
4951 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004952 int status;
4953 int _return_value;
4954
Victor Stinner3e1fad62017-01-17 01:29:01 +01004955 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004956 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004957 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004958 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004959 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004960 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004961 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004962 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004963 return_value = PyLong_FromLong((long)_return_value);
4964
4965exit:
4966 return return_value;
4967}
4968
4969#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4970
4971#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4972
4973PyDoc_STRVAR(os_fstatvfs__doc__,
4974"fstatvfs($module, fd, /)\n"
4975"--\n"
4976"\n"
4977"Perform an fstatvfs system call on the given fd.\n"
4978"\n"
4979"Equivalent to statvfs(fd).");
4980
4981#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004982 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004983
4984static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004985os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004986
4987static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004988os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004989{
4990 PyObject *return_value = NULL;
4991 int fd;
4992
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004993 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004994 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004995 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004996 return_value = os_fstatvfs_impl(module, fd);
4997
4998exit:
4999 return return_value;
5000}
5001
5002#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5003
5004#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
5005
5006PyDoc_STRVAR(os_statvfs__doc__,
5007"statvfs($module, /, path)\n"
5008"--\n"
5009"\n"
5010"Perform a statvfs system call on the given path.\n"
5011"\n"
5012"path may always be specified as a string.\n"
5013"On some platforms, path may also be specified as an open file descriptor.\n"
5014" If this functionality is unavailable, using it raises an exception.");
5015
5016#define OS_STATVFS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005017 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005018
5019static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005020os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005021
5022static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005023os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005024{
5025 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005026 static const char * const _keywords[] = {"path", NULL};
5027 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005028 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
5029
Victor Stinner3e1fad62017-01-17 01:29:01 +01005030 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005031 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005032 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005033 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005034 return_value = os_statvfs_impl(module, &path);
5035
5036exit:
5037 /* Cleanup for path */
5038 path_cleanup(&path);
5039
5040 return return_value;
5041}
5042
5043#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5044
5045#if defined(MS_WINDOWS)
5046
5047PyDoc_STRVAR(os__getdiskusage__doc__,
5048"_getdiskusage($module, /, path)\n"
5049"--\n"
5050"\n"
5051"Return disk usage statistics about the given path as a (total, free) tuple.");
5052
5053#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005054 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005055
5056static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005057os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005058
5059static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005060os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005061{
5062 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005063 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005064 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5065 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005066
Victor Stinner3e1fad62017-01-17 01:29:01 +01005067 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005068 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005069 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005070 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005071 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005072
5073exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005074 /* Cleanup for path */
5075 path_cleanup(&path);
5076
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005077 return return_value;
5078}
5079
5080#endif /* defined(MS_WINDOWS) */
5081
5082#if defined(HAVE_FPATHCONF)
5083
5084PyDoc_STRVAR(os_fpathconf__doc__,
5085"fpathconf($module, fd, name, /)\n"
5086"--\n"
5087"\n"
5088"Return the configuration limit name for the file descriptor fd.\n"
5089"\n"
5090"If there is no limit, return -1.");
5091
5092#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005093 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005094
5095static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005096os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005097
5098static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005099os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005100{
5101 PyObject *return_value = NULL;
5102 int fd;
5103 int name;
5104 long _return_value;
5105
Sylvain74453812017-06-10 06:51:48 +02005106 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5107 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005108 goto exit;
5109 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005110 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005111 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005112 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005113 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005114 return_value = PyLong_FromLong(_return_value);
5115
5116exit:
5117 return return_value;
5118}
5119
5120#endif /* defined(HAVE_FPATHCONF) */
5121
5122#if defined(HAVE_PATHCONF)
5123
5124PyDoc_STRVAR(os_pathconf__doc__,
5125"pathconf($module, /, path, name)\n"
5126"--\n"
5127"\n"
5128"Return the configuration limit name for the file or directory path.\n"
5129"\n"
5130"If there is no limit, return -1.\n"
5131"On some platforms, path may also be specified as an open file descriptor.\n"
5132" If this functionality is unavailable, using it raises an exception.");
5133
5134#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005135 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005136
5137static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005138os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005139
5140static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005141os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005142{
5143 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005144 static const char * const _keywords[] = {"path", "name", NULL};
5145 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005146 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5147 int name;
5148 long _return_value;
5149
Victor Stinner3e1fad62017-01-17 01:29:01 +01005150 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005151 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005152 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005154 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005155 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005156 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005157 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005158 return_value = PyLong_FromLong(_return_value);
5159
5160exit:
5161 /* Cleanup for path */
5162 path_cleanup(&path);
5163
5164 return return_value;
5165}
5166
5167#endif /* defined(HAVE_PATHCONF) */
5168
5169#if defined(HAVE_CONFSTR)
5170
5171PyDoc_STRVAR(os_confstr__doc__,
5172"confstr($module, name, /)\n"
5173"--\n"
5174"\n"
5175"Return a string-valued system configuration variable.");
5176
5177#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005178 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005179
5180static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005181os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005182
5183static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005184os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005185{
5186 PyObject *return_value = NULL;
5187 int name;
5188
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005189 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005190 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005191 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005192 return_value = os_confstr_impl(module, name);
5193
5194exit:
5195 return return_value;
5196}
5197
5198#endif /* defined(HAVE_CONFSTR) */
5199
5200#if defined(HAVE_SYSCONF)
5201
5202PyDoc_STRVAR(os_sysconf__doc__,
5203"sysconf($module, name, /)\n"
5204"--\n"
5205"\n"
5206"Return an integer-valued system configuration variable.");
5207
5208#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005209 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005210
5211static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005212os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005213
5214static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005215os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005216{
5217 PyObject *return_value = NULL;
5218 int name;
5219 long _return_value;
5220
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005221 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005222 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005223 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005224 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005225 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005226 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005227 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005228 return_value = PyLong_FromLong(_return_value);
5229
5230exit:
5231 return return_value;
5232}
5233
5234#endif /* defined(HAVE_SYSCONF) */
5235
5236PyDoc_STRVAR(os_abort__doc__,
5237"abort($module, /)\n"
5238"--\n"
5239"\n"
5240"Abort the interpreter immediately.\n"
5241"\n"
5242"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5243"on the hosting operating system. This function never returns.");
5244
5245#define OS_ABORT_METHODDEF \
5246 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5247
5248static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005249os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005250
5251static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005252os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005253{
5254 return os_abort_impl(module);
5255}
5256
Steve Dowercc16be82016-09-08 10:35:16 -07005257#if defined(MS_WINDOWS)
5258
5259PyDoc_STRVAR(os_startfile__doc__,
5260"startfile($module, /, filepath, operation=None)\n"
5261"--\n"
5262"\n"
5263"startfile(filepath [, operation])\n"
5264"\n"
5265"Start a file with its associated application.\n"
5266"\n"
5267"When \"operation\" is not specified or \"open\", this acts like\n"
5268"double-clicking the file in Explorer, or giving the file name as an\n"
5269"argument to the DOS \"start\" command: the file is opened with whatever\n"
5270"application (if any) its extension is associated.\n"
5271"When another \"operation\" is given, it specifies what should be done with\n"
5272"the file. A typical operation is \"print\".\n"
5273"\n"
5274"startfile returns as soon as the associated application is launched.\n"
5275"There is no option to wait for the application to close, and no way\n"
5276"to retrieve the application\'s exit status.\n"
5277"\n"
5278"The filepath is relative to the current directory. If you want to use\n"
5279"an absolute path, make sure the first character is not a slash (\"/\");\n"
5280"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5281
5282#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005283 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005284
5285static PyObject *
5286os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5287
5288static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005289os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005290{
5291 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005292 static const char * const _keywords[] = {"filepath", "operation", NULL};
5293 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005294 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5295 Py_UNICODE *operation = NULL;
5296
Victor Stinner3e1fad62017-01-17 01:29:01 +01005297 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005298 path_converter, &filepath, &operation)) {
5299 goto exit;
5300 }
5301 return_value = os_startfile_impl(module, &filepath, operation);
5302
5303exit:
5304 /* Cleanup for filepath */
5305 path_cleanup(&filepath);
5306
5307 return return_value;
5308}
5309
5310#endif /* defined(MS_WINDOWS) */
5311
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005312#if defined(HAVE_GETLOADAVG)
5313
5314PyDoc_STRVAR(os_getloadavg__doc__,
5315"getloadavg($module, /)\n"
5316"--\n"
5317"\n"
5318"Return average recent system load information.\n"
5319"\n"
5320"Return the number of processes in the system run queue averaged over\n"
5321"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5322"Raises OSError if the load average was unobtainable.");
5323
5324#define OS_GETLOADAVG_METHODDEF \
5325 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5326
5327static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005328os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005329
5330static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005331os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005332{
5333 return os_getloadavg_impl(module);
5334}
5335
5336#endif /* defined(HAVE_GETLOADAVG) */
5337
5338PyDoc_STRVAR(os_device_encoding__doc__,
5339"device_encoding($module, /, fd)\n"
5340"--\n"
5341"\n"
5342"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5343"\n"
5344"The file descriptor must be attached to a terminal.\n"
5345"If the device is not a terminal, return None.");
5346
5347#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005348 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005349
5350static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005351os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005352
5353static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005354os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005355{
5356 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005357 static const char * const _keywords[] = {"fd", NULL};
5358 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005359 int fd;
5360
Victor Stinner3e1fad62017-01-17 01:29:01 +01005361 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005362 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005363 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005364 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005365 return_value = os_device_encoding_impl(module, fd);
5366
5367exit:
5368 return return_value;
5369}
5370
5371#if defined(HAVE_SETRESUID)
5372
5373PyDoc_STRVAR(os_setresuid__doc__,
5374"setresuid($module, ruid, euid, suid, /)\n"
5375"--\n"
5376"\n"
5377"Set the current process\'s real, effective, and saved user ids.");
5378
5379#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005380 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005381
5382static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005383os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005384
5385static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005386os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005387{
5388 PyObject *return_value = NULL;
5389 uid_t ruid;
5390 uid_t euid;
5391 uid_t suid;
5392
Sylvain74453812017-06-10 06:51:48 +02005393 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5394 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005395 goto exit;
5396 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005397 return_value = os_setresuid_impl(module, ruid, euid, suid);
5398
5399exit:
5400 return return_value;
5401}
5402
5403#endif /* defined(HAVE_SETRESUID) */
5404
5405#if defined(HAVE_SETRESGID)
5406
5407PyDoc_STRVAR(os_setresgid__doc__,
5408"setresgid($module, rgid, egid, sgid, /)\n"
5409"--\n"
5410"\n"
5411"Set the current process\'s real, effective, and saved group ids.");
5412
5413#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005414 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005415
5416static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005417os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005418
5419static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005420os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005421{
5422 PyObject *return_value = NULL;
5423 gid_t rgid;
5424 gid_t egid;
5425 gid_t sgid;
5426
Sylvain74453812017-06-10 06:51:48 +02005427 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5428 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005429 goto exit;
5430 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005431 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5432
5433exit:
5434 return return_value;
5435}
5436
5437#endif /* defined(HAVE_SETRESGID) */
5438
5439#if defined(HAVE_GETRESUID)
5440
5441PyDoc_STRVAR(os_getresuid__doc__,
5442"getresuid($module, /)\n"
5443"--\n"
5444"\n"
5445"Return a tuple of the current process\'s real, effective, and saved user ids.");
5446
5447#define OS_GETRESUID_METHODDEF \
5448 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5449
5450static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005451os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005452
5453static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005454os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005455{
5456 return os_getresuid_impl(module);
5457}
5458
5459#endif /* defined(HAVE_GETRESUID) */
5460
5461#if defined(HAVE_GETRESGID)
5462
5463PyDoc_STRVAR(os_getresgid__doc__,
5464"getresgid($module, /)\n"
5465"--\n"
5466"\n"
5467"Return a tuple of the current process\'s real, effective, and saved group ids.");
5468
5469#define OS_GETRESGID_METHODDEF \
5470 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5471
5472static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005473os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005474
5475static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005476os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005477{
5478 return os_getresgid_impl(module);
5479}
5480
5481#endif /* defined(HAVE_GETRESGID) */
5482
5483#if defined(USE_XATTRS)
5484
5485PyDoc_STRVAR(os_getxattr__doc__,
5486"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5487"--\n"
5488"\n"
5489"Return the value of extended attribute attribute on path.\n"
5490"\n"
5491"path may be either a string or an open file descriptor.\n"
5492"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5493" link, getxattr will examine the symbolic link itself instead of the file\n"
5494" the link points to.");
5495
5496#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005497 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005498
5499static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005500os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005501 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005502
5503static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005504os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005505{
5506 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005507 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5508 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005509 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5510 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5511 int follow_symlinks = 1;
5512
Victor Stinner3e1fad62017-01-17 01:29:01 +01005513 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005514 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005515 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005516 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005517 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5518
5519exit:
5520 /* Cleanup for path */
5521 path_cleanup(&path);
5522 /* Cleanup for attribute */
5523 path_cleanup(&attribute);
5524
5525 return return_value;
5526}
5527
5528#endif /* defined(USE_XATTRS) */
5529
5530#if defined(USE_XATTRS)
5531
5532PyDoc_STRVAR(os_setxattr__doc__,
5533"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5534" follow_symlinks=True)\n"
5535"--\n"
5536"\n"
5537"Set extended attribute attribute on path to value.\n"
5538"\n"
5539"path may be either a string or an open file descriptor.\n"
5540"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5541" link, setxattr will modify the symbolic link itself instead of the file\n"
5542" the link points to.");
5543
5544#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005545 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005546
5547static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005548os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005549 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005550
5551static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005552os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005553{
5554 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005555 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5556 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005557 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5558 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5559 Py_buffer value = {NULL, NULL};
5560 int flags = 0;
5561 int follow_symlinks = 1;
5562
Victor Stinner3e1fad62017-01-17 01:29:01 +01005563 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005564 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005565 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005566 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005567 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5568
5569exit:
5570 /* Cleanup for path */
5571 path_cleanup(&path);
5572 /* Cleanup for attribute */
5573 path_cleanup(&attribute);
5574 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005575 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005576 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005577 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005578
5579 return return_value;
5580}
5581
5582#endif /* defined(USE_XATTRS) */
5583
5584#if defined(USE_XATTRS)
5585
5586PyDoc_STRVAR(os_removexattr__doc__,
5587"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5588"--\n"
5589"\n"
5590"Remove extended attribute attribute on path.\n"
5591"\n"
5592"path may be either a string or an open file descriptor.\n"
5593"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5594" link, removexattr will modify the symbolic link itself instead of the file\n"
5595" the link points to.");
5596
5597#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005598 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005599
5600static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005601os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005602 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005603
5604static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005605os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005606{
5607 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005608 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5609 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005610 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5611 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5612 int follow_symlinks = 1;
5613
Victor Stinner3e1fad62017-01-17 01:29:01 +01005614 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005615 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005616 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005617 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005618 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5619
5620exit:
5621 /* Cleanup for path */
5622 path_cleanup(&path);
5623 /* Cleanup for attribute */
5624 path_cleanup(&attribute);
5625
5626 return return_value;
5627}
5628
5629#endif /* defined(USE_XATTRS) */
5630
5631#if defined(USE_XATTRS)
5632
5633PyDoc_STRVAR(os_listxattr__doc__,
5634"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5635"--\n"
5636"\n"
5637"Return a list of extended attributes on path.\n"
5638"\n"
5639"path may be either None, a string, or an open file descriptor.\n"
5640"if path is None, listxattr will examine the current directory.\n"
5641"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5642" link, listxattr will examine the symbolic link itself instead of the file\n"
5643" the link points to.");
5644
5645#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005646 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005647
5648static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005649os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005650
5651static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005652os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005653{
5654 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005655 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5656 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005657 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5658 int follow_symlinks = 1;
5659
Victor Stinner3e1fad62017-01-17 01:29:01 +01005660 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005661 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005662 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005663 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005664 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5665
5666exit:
5667 /* Cleanup for path */
5668 path_cleanup(&path);
5669
5670 return return_value;
5671}
5672
5673#endif /* defined(USE_XATTRS) */
5674
5675PyDoc_STRVAR(os_urandom__doc__,
5676"urandom($module, size, /)\n"
5677"--\n"
5678"\n"
5679"Return a bytes object containing random bytes suitable for cryptographic use.");
5680
5681#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005682 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005683
5684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005685os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005686
5687static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005688os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005689{
5690 PyObject *return_value = NULL;
5691 Py_ssize_t size;
5692
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005693 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005694 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005695 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005696 return_value = os_urandom_impl(module, size);
5697
5698exit:
5699 return return_value;
5700}
5701
5702PyDoc_STRVAR(os_cpu_count__doc__,
5703"cpu_count($module, /)\n"
5704"--\n"
5705"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005706"Return the number of CPUs in the system; return None if indeterminable.\n"
5707"\n"
5708"This number is not equivalent to the number of CPUs the current process can\n"
5709"use. The number of usable CPUs can be obtained with\n"
5710"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005711
5712#define OS_CPU_COUNT_METHODDEF \
5713 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5714
5715static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005716os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005717
5718static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005719os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005720{
5721 return os_cpu_count_impl(module);
5722}
5723
5724PyDoc_STRVAR(os_get_inheritable__doc__,
5725"get_inheritable($module, fd, /)\n"
5726"--\n"
5727"\n"
5728"Get the close-on-exe flag of the specified file descriptor.");
5729
5730#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005731 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005732
5733static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005734os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005735
5736static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005737os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005738{
5739 PyObject *return_value = NULL;
5740 int fd;
5741 int _return_value;
5742
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005743 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005744 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005745 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005746 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005747 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005748 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005749 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005750 return_value = PyBool_FromLong((long)_return_value);
5751
5752exit:
5753 return return_value;
5754}
5755
5756PyDoc_STRVAR(os_set_inheritable__doc__,
5757"set_inheritable($module, fd, inheritable, /)\n"
5758"--\n"
5759"\n"
5760"Set the inheritable flag of the specified file descriptor.");
5761
5762#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005763 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005764
5765static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005766os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005767
5768static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005769os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005770{
5771 PyObject *return_value = NULL;
5772 int fd;
5773 int inheritable;
5774
Sylvain74453812017-06-10 06:51:48 +02005775 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5776 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005777 goto exit;
5778 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005779 return_value = os_set_inheritable_impl(module, fd, inheritable);
5780
5781exit:
5782 return return_value;
5783}
5784
5785#if defined(MS_WINDOWS)
5786
5787PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5788"get_handle_inheritable($module, handle, /)\n"
5789"--\n"
5790"\n"
5791"Get the close-on-exe flag of the specified file descriptor.");
5792
5793#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005794 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005795
5796static int
Victor Stinner581139c2016-09-06 15:54:20 -07005797os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005798
5799static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005800os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005801{
5802 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005803 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005804 int _return_value;
5805
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005806 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005807 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005808 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005809 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005810 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005811 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005812 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005813 return_value = PyBool_FromLong((long)_return_value);
5814
5815exit:
5816 return return_value;
5817}
5818
5819#endif /* defined(MS_WINDOWS) */
5820
5821#if defined(MS_WINDOWS)
5822
5823PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5824"set_handle_inheritable($module, handle, inheritable, /)\n"
5825"--\n"
5826"\n"
5827"Set the inheritable flag of the specified handle.");
5828
5829#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005830 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005831
5832static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005833os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005834 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005835
5836static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005837os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005838{
5839 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005840 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005841 int inheritable;
5842
Sylvain74453812017-06-10 06:51:48 +02005843 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5844 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005845 goto exit;
5846 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005847 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5848
5849exit:
5850 return return_value;
5851}
5852
5853#endif /* defined(MS_WINDOWS) */
5854
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005855PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5856"is_symlink($self, /)\n"
5857"--\n"
5858"\n"
5859"Return True if the entry is a symbolic link; cached per entry.");
5860
5861#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5862 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5863
5864static int
5865os_DirEntry_is_symlink_impl(DirEntry *self);
5866
5867static PyObject *
5868os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5869{
5870 PyObject *return_value = NULL;
5871 int _return_value;
5872
5873 _return_value = os_DirEntry_is_symlink_impl(self);
5874 if ((_return_value == -1) && PyErr_Occurred()) {
5875 goto exit;
5876 }
5877 return_value = PyBool_FromLong((long)_return_value);
5878
5879exit:
5880 return return_value;
5881}
5882
5883PyDoc_STRVAR(os_DirEntry_stat__doc__,
5884"stat($self, /, *, follow_symlinks=True)\n"
5885"--\n"
5886"\n"
5887"Return stat_result object for the entry; cached per entry.");
5888
5889#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005890 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005891
5892static PyObject *
5893os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5894
5895static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005896os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005897{
5898 PyObject *return_value = NULL;
5899 static const char * const _keywords[] = {"follow_symlinks", NULL};
5900 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5901 int follow_symlinks = 1;
5902
Victor Stinner3e1fad62017-01-17 01:29:01 +01005903 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005904 &follow_symlinks)) {
5905 goto exit;
5906 }
5907 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5908
5909exit:
5910 return return_value;
5911}
5912
5913PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5914"is_dir($self, /, *, follow_symlinks=True)\n"
5915"--\n"
5916"\n"
5917"Return True if the entry is a directory; cached per entry.");
5918
5919#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005920 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005921
5922static int
5923os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5924
5925static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005926os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005927{
5928 PyObject *return_value = NULL;
5929 static const char * const _keywords[] = {"follow_symlinks", NULL};
5930 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5931 int follow_symlinks = 1;
5932 int _return_value;
5933
Victor Stinner3e1fad62017-01-17 01:29:01 +01005934 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005935 &follow_symlinks)) {
5936 goto exit;
5937 }
5938 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5939 if ((_return_value == -1) && PyErr_Occurred()) {
5940 goto exit;
5941 }
5942 return_value = PyBool_FromLong((long)_return_value);
5943
5944exit:
5945 return return_value;
5946}
5947
5948PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5949"is_file($self, /, *, follow_symlinks=True)\n"
5950"--\n"
5951"\n"
5952"Return True if the entry is a file; cached per entry.");
5953
5954#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005955 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005956
5957static int
5958os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5959
5960static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005961os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005962{
5963 PyObject *return_value = NULL;
5964 static const char * const _keywords[] = {"follow_symlinks", NULL};
5965 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5966 int follow_symlinks = 1;
5967 int _return_value;
5968
Victor Stinner3e1fad62017-01-17 01:29:01 +01005969 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005970 &follow_symlinks)) {
5971 goto exit;
5972 }
5973 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5974 if ((_return_value == -1) && PyErr_Occurred()) {
5975 goto exit;
5976 }
5977 return_value = PyBool_FromLong((long)_return_value);
5978
5979exit:
5980 return return_value;
5981}
5982
5983PyDoc_STRVAR(os_DirEntry_inode__doc__,
5984"inode($self, /)\n"
5985"--\n"
5986"\n"
5987"Return inode of the entry; cached per entry.");
5988
5989#define OS_DIRENTRY_INODE_METHODDEF \
5990 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5991
5992static PyObject *
5993os_DirEntry_inode_impl(DirEntry *self);
5994
5995static PyObject *
5996os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5997{
5998 return os_DirEntry_inode_impl(self);
5999}
6000
6001PyDoc_STRVAR(os_DirEntry___fspath____doc__,
6002"__fspath__($self, /)\n"
6003"--\n"
6004"\n"
6005"Returns the path for the entry.");
6006
6007#define OS_DIRENTRY___FSPATH___METHODDEF \
6008 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
6009
6010static PyObject *
6011os_DirEntry___fspath___impl(DirEntry *self);
6012
6013static PyObject *
6014os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
6015{
6016 return os_DirEntry___fspath___impl(self);
6017}
6018
6019PyDoc_STRVAR(os_scandir__doc__,
6020"scandir($module, /, path=None)\n"
6021"--\n"
6022"\n"
6023"Return an iterator of DirEntry objects for given path.\n"
6024"\n"
6025"path can be specified as either str, bytes or path-like object. If path\n"
6026"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
6027"all other circumstances they will be str.\n"
6028"\n"
6029"If path is None, uses the path=\'.\'.");
6030
6031#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006032 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006033
6034static PyObject *
6035os_scandir_impl(PyObject *module, path_t *path);
6036
6037static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006038os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006039{
6040 PyObject *return_value = NULL;
6041 static const char * const _keywords[] = {"path", NULL};
6042 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006043 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006044
Victor Stinner3e1fad62017-01-17 01:29:01 +01006045 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006046 path_converter, &path)) {
6047 goto exit;
6048 }
6049 return_value = os_scandir_impl(module, &path);
6050
6051exit:
6052 /* Cleanup for path */
6053 path_cleanup(&path);
6054
6055 return return_value;
6056}
6057
Ethan Furman410ef8e2016-06-04 12:06:26 -07006058PyDoc_STRVAR(os_fspath__doc__,
6059"fspath($module, /, path)\n"
6060"--\n"
6061"\n"
6062"Return the file system path representation of the object.\n"
6063"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006064"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6065"object defines __fspath__(), then return the result of that method. All other\n"
6066"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006067
6068#define OS_FSPATH_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006069 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006070
6071static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006072os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006073
6074static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006075os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006076{
6077 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006078 static const char * const _keywords[] = {"path", NULL};
6079 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006080 PyObject *path;
6081
Victor Stinner3e1fad62017-01-17 01:29:01 +01006082 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006083 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006084 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006085 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006086 return_value = os_fspath_impl(module, path);
6087
6088exit:
6089 return return_value;
6090}
6091
Victor Stinner9b1f4742016-09-06 16:18:52 -07006092#if defined(HAVE_GETRANDOM_SYSCALL)
6093
6094PyDoc_STRVAR(os_getrandom__doc__,
6095"getrandom($module, /, size, flags=0)\n"
6096"--\n"
6097"\n"
6098"Obtain a series of random bytes.");
6099
6100#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006101 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006102
6103static PyObject *
6104os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6105
6106static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006107os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006108{
6109 PyObject *return_value = NULL;
6110 static const char * const _keywords[] = {"size", "flags", NULL};
6111 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6112 Py_ssize_t size;
6113 int flags = 0;
6114
Victor Stinner3e1fad62017-01-17 01:29:01 +01006115 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006116 &size, &flags)) {
6117 goto exit;
6118 }
6119 return_value = os_getrandom_impl(module, size, flags);
6120
6121exit:
6122 return return_value;
6123}
6124
6125#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6126
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006127#ifndef OS_TTYNAME_METHODDEF
6128 #define OS_TTYNAME_METHODDEF
6129#endif /* !defined(OS_TTYNAME_METHODDEF) */
6130
6131#ifndef OS_CTERMID_METHODDEF
6132 #define OS_CTERMID_METHODDEF
6133#endif /* !defined(OS_CTERMID_METHODDEF) */
6134
6135#ifndef OS_FCHDIR_METHODDEF
6136 #define OS_FCHDIR_METHODDEF
6137#endif /* !defined(OS_FCHDIR_METHODDEF) */
6138
6139#ifndef OS_FCHMOD_METHODDEF
6140 #define OS_FCHMOD_METHODDEF
6141#endif /* !defined(OS_FCHMOD_METHODDEF) */
6142
6143#ifndef OS_LCHMOD_METHODDEF
6144 #define OS_LCHMOD_METHODDEF
6145#endif /* !defined(OS_LCHMOD_METHODDEF) */
6146
6147#ifndef OS_CHFLAGS_METHODDEF
6148 #define OS_CHFLAGS_METHODDEF
6149#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6150
6151#ifndef OS_LCHFLAGS_METHODDEF
6152 #define OS_LCHFLAGS_METHODDEF
6153#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6154
6155#ifndef OS_CHROOT_METHODDEF
6156 #define OS_CHROOT_METHODDEF
6157#endif /* !defined(OS_CHROOT_METHODDEF) */
6158
6159#ifndef OS_FSYNC_METHODDEF
6160 #define OS_FSYNC_METHODDEF
6161#endif /* !defined(OS_FSYNC_METHODDEF) */
6162
6163#ifndef OS_SYNC_METHODDEF
6164 #define OS_SYNC_METHODDEF
6165#endif /* !defined(OS_SYNC_METHODDEF) */
6166
6167#ifndef OS_FDATASYNC_METHODDEF
6168 #define OS_FDATASYNC_METHODDEF
6169#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6170
6171#ifndef OS_CHOWN_METHODDEF
6172 #define OS_CHOWN_METHODDEF
6173#endif /* !defined(OS_CHOWN_METHODDEF) */
6174
6175#ifndef OS_FCHOWN_METHODDEF
6176 #define OS_FCHOWN_METHODDEF
6177#endif /* !defined(OS_FCHOWN_METHODDEF) */
6178
6179#ifndef OS_LCHOWN_METHODDEF
6180 #define OS_LCHOWN_METHODDEF
6181#endif /* !defined(OS_LCHOWN_METHODDEF) */
6182
6183#ifndef OS_LINK_METHODDEF
6184 #define OS_LINK_METHODDEF
6185#endif /* !defined(OS_LINK_METHODDEF) */
6186
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006187#ifndef OS__GETFULLPATHNAME_METHODDEF
6188 #define OS__GETFULLPATHNAME_METHODDEF
6189#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6190
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006191#ifndef OS__GETFINALPATHNAME_METHODDEF
6192 #define OS__GETFINALPATHNAME_METHODDEF
6193#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6194
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006195#ifndef OS__ISDIR_METHODDEF
6196 #define OS__ISDIR_METHODDEF
6197#endif /* !defined(OS__ISDIR_METHODDEF) */
6198
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006199#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6200 #define OS__GETVOLUMEPATHNAME_METHODDEF
6201#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6202
6203#ifndef OS_NICE_METHODDEF
6204 #define OS_NICE_METHODDEF
6205#endif /* !defined(OS_NICE_METHODDEF) */
6206
6207#ifndef OS_GETPRIORITY_METHODDEF
6208 #define OS_GETPRIORITY_METHODDEF
6209#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6210
6211#ifndef OS_SETPRIORITY_METHODDEF
6212 #define OS_SETPRIORITY_METHODDEF
6213#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6214
6215#ifndef OS_SYSTEM_METHODDEF
6216 #define OS_SYSTEM_METHODDEF
6217#endif /* !defined(OS_SYSTEM_METHODDEF) */
6218
6219#ifndef OS_UNAME_METHODDEF
6220 #define OS_UNAME_METHODDEF
6221#endif /* !defined(OS_UNAME_METHODDEF) */
6222
6223#ifndef OS_EXECV_METHODDEF
6224 #define OS_EXECV_METHODDEF
6225#endif /* !defined(OS_EXECV_METHODDEF) */
6226
6227#ifndef OS_EXECVE_METHODDEF
6228 #define OS_EXECVE_METHODDEF
6229#endif /* !defined(OS_EXECVE_METHODDEF) */
6230
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006231#ifndef OS_POSIX_SPAWN_METHODDEF
6232 #define OS_POSIX_SPAWN_METHODDEF
6233#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6234
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006235#ifndef OS_SPAWNV_METHODDEF
6236 #define OS_SPAWNV_METHODDEF
6237#endif /* !defined(OS_SPAWNV_METHODDEF) */
6238
6239#ifndef OS_SPAWNVE_METHODDEF
6240 #define OS_SPAWNVE_METHODDEF
6241#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6242
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006243#ifndef OS_REGISTER_AT_FORK_METHODDEF
6244 #define OS_REGISTER_AT_FORK_METHODDEF
6245#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6246
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006247#ifndef OS_FORK1_METHODDEF
6248 #define OS_FORK1_METHODDEF
6249#endif /* !defined(OS_FORK1_METHODDEF) */
6250
6251#ifndef OS_FORK_METHODDEF
6252 #define OS_FORK_METHODDEF
6253#endif /* !defined(OS_FORK_METHODDEF) */
6254
6255#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6256 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6257#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6258
6259#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6260 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6261#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6262
6263#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6264 #define OS_SCHED_GETSCHEDULER_METHODDEF
6265#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6266
6267#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6268 #define OS_SCHED_SETSCHEDULER_METHODDEF
6269#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6270
6271#ifndef OS_SCHED_GETPARAM_METHODDEF
6272 #define OS_SCHED_GETPARAM_METHODDEF
6273#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6274
6275#ifndef OS_SCHED_SETPARAM_METHODDEF
6276 #define OS_SCHED_SETPARAM_METHODDEF
6277#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6278
6279#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6280 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6281#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6282
6283#ifndef OS_SCHED_YIELD_METHODDEF
6284 #define OS_SCHED_YIELD_METHODDEF
6285#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6286
6287#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6288 #define OS_SCHED_SETAFFINITY_METHODDEF
6289#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6290
6291#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6292 #define OS_SCHED_GETAFFINITY_METHODDEF
6293#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6294
6295#ifndef OS_OPENPTY_METHODDEF
6296 #define OS_OPENPTY_METHODDEF
6297#endif /* !defined(OS_OPENPTY_METHODDEF) */
6298
6299#ifndef OS_FORKPTY_METHODDEF
6300 #define OS_FORKPTY_METHODDEF
6301#endif /* !defined(OS_FORKPTY_METHODDEF) */
6302
6303#ifndef OS_GETEGID_METHODDEF
6304 #define OS_GETEGID_METHODDEF
6305#endif /* !defined(OS_GETEGID_METHODDEF) */
6306
6307#ifndef OS_GETEUID_METHODDEF
6308 #define OS_GETEUID_METHODDEF
6309#endif /* !defined(OS_GETEUID_METHODDEF) */
6310
6311#ifndef OS_GETGID_METHODDEF
6312 #define OS_GETGID_METHODDEF
6313#endif /* !defined(OS_GETGID_METHODDEF) */
6314
Berker Peksag39404992016-09-15 20:45:16 +03006315#ifndef OS_GETPID_METHODDEF
6316 #define OS_GETPID_METHODDEF
6317#endif /* !defined(OS_GETPID_METHODDEF) */
6318
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006319#ifndef OS_GETGROUPS_METHODDEF
6320 #define OS_GETGROUPS_METHODDEF
6321#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6322
6323#ifndef OS_GETPGID_METHODDEF
6324 #define OS_GETPGID_METHODDEF
6325#endif /* !defined(OS_GETPGID_METHODDEF) */
6326
6327#ifndef OS_GETPGRP_METHODDEF
6328 #define OS_GETPGRP_METHODDEF
6329#endif /* !defined(OS_GETPGRP_METHODDEF) */
6330
6331#ifndef OS_SETPGRP_METHODDEF
6332 #define OS_SETPGRP_METHODDEF
6333#endif /* !defined(OS_SETPGRP_METHODDEF) */
6334
6335#ifndef OS_GETPPID_METHODDEF
6336 #define OS_GETPPID_METHODDEF
6337#endif /* !defined(OS_GETPPID_METHODDEF) */
6338
6339#ifndef OS_GETLOGIN_METHODDEF
6340 #define OS_GETLOGIN_METHODDEF
6341#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6342
6343#ifndef OS_GETUID_METHODDEF
6344 #define OS_GETUID_METHODDEF
6345#endif /* !defined(OS_GETUID_METHODDEF) */
6346
6347#ifndef OS_KILL_METHODDEF
6348 #define OS_KILL_METHODDEF
6349#endif /* !defined(OS_KILL_METHODDEF) */
6350
6351#ifndef OS_KILLPG_METHODDEF
6352 #define OS_KILLPG_METHODDEF
6353#endif /* !defined(OS_KILLPG_METHODDEF) */
6354
6355#ifndef OS_PLOCK_METHODDEF
6356 #define OS_PLOCK_METHODDEF
6357#endif /* !defined(OS_PLOCK_METHODDEF) */
6358
6359#ifndef OS_SETUID_METHODDEF
6360 #define OS_SETUID_METHODDEF
6361#endif /* !defined(OS_SETUID_METHODDEF) */
6362
6363#ifndef OS_SETEUID_METHODDEF
6364 #define OS_SETEUID_METHODDEF
6365#endif /* !defined(OS_SETEUID_METHODDEF) */
6366
6367#ifndef OS_SETEGID_METHODDEF
6368 #define OS_SETEGID_METHODDEF
6369#endif /* !defined(OS_SETEGID_METHODDEF) */
6370
6371#ifndef OS_SETREUID_METHODDEF
6372 #define OS_SETREUID_METHODDEF
6373#endif /* !defined(OS_SETREUID_METHODDEF) */
6374
6375#ifndef OS_SETREGID_METHODDEF
6376 #define OS_SETREGID_METHODDEF
6377#endif /* !defined(OS_SETREGID_METHODDEF) */
6378
6379#ifndef OS_SETGID_METHODDEF
6380 #define OS_SETGID_METHODDEF
6381#endif /* !defined(OS_SETGID_METHODDEF) */
6382
6383#ifndef OS_SETGROUPS_METHODDEF
6384 #define OS_SETGROUPS_METHODDEF
6385#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6386
6387#ifndef OS_WAIT3_METHODDEF
6388 #define OS_WAIT3_METHODDEF
6389#endif /* !defined(OS_WAIT3_METHODDEF) */
6390
6391#ifndef OS_WAIT4_METHODDEF
6392 #define OS_WAIT4_METHODDEF
6393#endif /* !defined(OS_WAIT4_METHODDEF) */
6394
6395#ifndef OS_WAITID_METHODDEF
6396 #define OS_WAITID_METHODDEF
6397#endif /* !defined(OS_WAITID_METHODDEF) */
6398
6399#ifndef OS_WAITPID_METHODDEF
6400 #define OS_WAITPID_METHODDEF
6401#endif /* !defined(OS_WAITPID_METHODDEF) */
6402
6403#ifndef OS_WAIT_METHODDEF
6404 #define OS_WAIT_METHODDEF
6405#endif /* !defined(OS_WAIT_METHODDEF) */
6406
6407#ifndef OS_SYMLINK_METHODDEF
6408 #define OS_SYMLINK_METHODDEF
6409#endif /* !defined(OS_SYMLINK_METHODDEF) */
6410
6411#ifndef OS_TIMES_METHODDEF
6412 #define OS_TIMES_METHODDEF
6413#endif /* !defined(OS_TIMES_METHODDEF) */
6414
6415#ifndef OS_GETSID_METHODDEF
6416 #define OS_GETSID_METHODDEF
6417#endif /* !defined(OS_GETSID_METHODDEF) */
6418
6419#ifndef OS_SETSID_METHODDEF
6420 #define OS_SETSID_METHODDEF
6421#endif /* !defined(OS_SETSID_METHODDEF) */
6422
6423#ifndef OS_SETPGID_METHODDEF
6424 #define OS_SETPGID_METHODDEF
6425#endif /* !defined(OS_SETPGID_METHODDEF) */
6426
6427#ifndef OS_TCGETPGRP_METHODDEF
6428 #define OS_TCGETPGRP_METHODDEF
6429#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6430
6431#ifndef OS_TCSETPGRP_METHODDEF
6432 #define OS_TCSETPGRP_METHODDEF
6433#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6434
6435#ifndef OS_LOCKF_METHODDEF
6436 #define OS_LOCKF_METHODDEF
6437#endif /* !defined(OS_LOCKF_METHODDEF) */
6438
6439#ifndef OS_READV_METHODDEF
6440 #define OS_READV_METHODDEF
6441#endif /* !defined(OS_READV_METHODDEF) */
6442
6443#ifndef OS_PREAD_METHODDEF
6444 #define OS_PREAD_METHODDEF
6445#endif /* !defined(OS_PREAD_METHODDEF) */
6446
Pablo Galindo4defba32018-01-27 16:16:37 +00006447#ifndef OS_PREADV_METHODDEF
6448 #define OS_PREADV_METHODDEF
6449#endif /* !defined(OS_PREADV_METHODDEF) */
6450
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02006451#ifndef OS__FCOPYFILE_METHODDEF
6452 #define OS__FCOPYFILE_METHODDEF
6453#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
6454
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006455#ifndef OS_PIPE_METHODDEF
6456 #define OS_PIPE_METHODDEF
6457#endif /* !defined(OS_PIPE_METHODDEF) */
6458
6459#ifndef OS_PIPE2_METHODDEF
6460 #define OS_PIPE2_METHODDEF
6461#endif /* !defined(OS_PIPE2_METHODDEF) */
6462
6463#ifndef OS_WRITEV_METHODDEF
6464 #define OS_WRITEV_METHODDEF
6465#endif /* !defined(OS_WRITEV_METHODDEF) */
6466
6467#ifndef OS_PWRITE_METHODDEF
6468 #define OS_PWRITE_METHODDEF
6469#endif /* !defined(OS_PWRITE_METHODDEF) */
6470
Pablo Galindo4defba32018-01-27 16:16:37 +00006471#ifndef OS_PWRITEV_METHODDEF
6472 #define OS_PWRITEV_METHODDEF
6473#endif /* !defined(OS_PWRITEV_METHODDEF) */
6474
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006475#ifndef OS_MKFIFO_METHODDEF
6476 #define OS_MKFIFO_METHODDEF
6477#endif /* !defined(OS_MKFIFO_METHODDEF) */
6478
6479#ifndef OS_MKNOD_METHODDEF
6480 #define OS_MKNOD_METHODDEF
6481#endif /* !defined(OS_MKNOD_METHODDEF) */
6482
6483#ifndef OS_MAJOR_METHODDEF
6484 #define OS_MAJOR_METHODDEF
6485#endif /* !defined(OS_MAJOR_METHODDEF) */
6486
6487#ifndef OS_MINOR_METHODDEF
6488 #define OS_MINOR_METHODDEF
6489#endif /* !defined(OS_MINOR_METHODDEF) */
6490
6491#ifndef OS_MAKEDEV_METHODDEF
6492 #define OS_MAKEDEV_METHODDEF
6493#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6494
6495#ifndef OS_FTRUNCATE_METHODDEF
6496 #define OS_FTRUNCATE_METHODDEF
6497#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6498
6499#ifndef OS_TRUNCATE_METHODDEF
6500 #define OS_TRUNCATE_METHODDEF
6501#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6502
6503#ifndef OS_POSIX_FALLOCATE_METHODDEF
6504 #define OS_POSIX_FALLOCATE_METHODDEF
6505#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6506
6507#ifndef OS_POSIX_FADVISE_METHODDEF
6508 #define OS_POSIX_FADVISE_METHODDEF
6509#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6510
6511#ifndef OS_PUTENV_METHODDEF
6512 #define OS_PUTENV_METHODDEF
6513#endif /* !defined(OS_PUTENV_METHODDEF) */
6514
6515#ifndef OS_UNSETENV_METHODDEF
6516 #define OS_UNSETENV_METHODDEF
6517#endif /* !defined(OS_UNSETENV_METHODDEF) */
6518
6519#ifndef OS_WCOREDUMP_METHODDEF
6520 #define OS_WCOREDUMP_METHODDEF
6521#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6522
6523#ifndef OS_WIFCONTINUED_METHODDEF
6524 #define OS_WIFCONTINUED_METHODDEF
6525#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6526
6527#ifndef OS_WIFSTOPPED_METHODDEF
6528 #define OS_WIFSTOPPED_METHODDEF
6529#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6530
6531#ifndef OS_WIFSIGNALED_METHODDEF
6532 #define OS_WIFSIGNALED_METHODDEF
6533#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6534
6535#ifndef OS_WIFEXITED_METHODDEF
6536 #define OS_WIFEXITED_METHODDEF
6537#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6538
6539#ifndef OS_WEXITSTATUS_METHODDEF
6540 #define OS_WEXITSTATUS_METHODDEF
6541#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6542
6543#ifndef OS_WTERMSIG_METHODDEF
6544 #define OS_WTERMSIG_METHODDEF
6545#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6546
6547#ifndef OS_WSTOPSIG_METHODDEF
6548 #define OS_WSTOPSIG_METHODDEF
6549#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6550
6551#ifndef OS_FSTATVFS_METHODDEF
6552 #define OS_FSTATVFS_METHODDEF
6553#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6554
6555#ifndef OS_STATVFS_METHODDEF
6556 #define OS_STATVFS_METHODDEF
6557#endif /* !defined(OS_STATVFS_METHODDEF) */
6558
6559#ifndef OS__GETDISKUSAGE_METHODDEF
6560 #define OS__GETDISKUSAGE_METHODDEF
6561#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6562
6563#ifndef OS_FPATHCONF_METHODDEF
6564 #define OS_FPATHCONF_METHODDEF
6565#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6566
6567#ifndef OS_PATHCONF_METHODDEF
6568 #define OS_PATHCONF_METHODDEF
6569#endif /* !defined(OS_PATHCONF_METHODDEF) */
6570
6571#ifndef OS_CONFSTR_METHODDEF
6572 #define OS_CONFSTR_METHODDEF
6573#endif /* !defined(OS_CONFSTR_METHODDEF) */
6574
6575#ifndef OS_SYSCONF_METHODDEF
6576 #define OS_SYSCONF_METHODDEF
6577#endif /* !defined(OS_SYSCONF_METHODDEF) */
6578
Steve Dowercc16be82016-09-08 10:35:16 -07006579#ifndef OS_STARTFILE_METHODDEF
6580 #define OS_STARTFILE_METHODDEF
6581#endif /* !defined(OS_STARTFILE_METHODDEF) */
6582
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006583#ifndef OS_GETLOADAVG_METHODDEF
6584 #define OS_GETLOADAVG_METHODDEF
6585#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6586
6587#ifndef OS_SETRESUID_METHODDEF
6588 #define OS_SETRESUID_METHODDEF
6589#endif /* !defined(OS_SETRESUID_METHODDEF) */
6590
6591#ifndef OS_SETRESGID_METHODDEF
6592 #define OS_SETRESGID_METHODDEF
6593#endif /* !defined(OS_SETRESGID_METHODDEF) */
6594
6595#ifndef OS_GETRESUID_METHODDEF
6596 #define OS_GETRESUID_METHODDEF
6597#endif /* !defined(OS_GETRESUID_METHODDEF) */
6598
6599#ifndef OS_GETRESGID_METHODDEF
6600 #define OS_GETRESGID_METHODDEF
6601#endif /* !defined(OS_GETRESGID_METHODDEF) */
6602
6603#ifndef OS_GETXATTR_METHODDEF
6604 #define OS_GETXATTR_METHODDEF
6605#endif /* !defined(OS_GETXATTR_METHODDEF) */
6606
6607#ifndef OS_SETXATTR_METHODDEF
6608 #define OS_SETXATTR_METHODDEF
6609#endif /* !defined(OS_SETXATTR_METHODDEF) */
6610
6611#ifndef OS_REMOVEXATTR_METHODDEF
6612 #define OS_REMOVEXATTR_METHODDEF
6613#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6614
6615#ifndef OS_LISTXATTR_METHODDEF
6616 #define OS_LISTXATTR_METHODDEF
6617#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6618
6619#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6620 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6621#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6622
6623#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6624 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6625#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006626
6627#ifndef OS_GETRANDOM_METHODDEF
6628 #define OS_GETRANDOM_METHODDEF
6629#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07006630/*[clinic end generated code: output=47fb6a3e88cba6d9 input=a9049054013a1b77]*/