blob: 85ba7b5839116b32b011bf3756b279175ab08a69 [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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -070037os_stat(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -070075os_lstat(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700136os_access(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700243os_chdir(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700281os_fchdir(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700334os_chmod(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700374os_fchmod(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700412os_lchmod(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700457os_chflags(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700499os_lchflags(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700537os_chroot(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700574os_fsync(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700630os_fdatasync(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700689os_chown(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700732os_fchown(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700771os_lchown(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700858os_link(PyObject *module, PyObject **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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700910os_listdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300911{
912 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300913 static const char * const _keywords[] = {"path", NULL};
914 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300915 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
916
Victor Stinner3e1fad62017-01-17 01:29:01 +0100917 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300918 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300919 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300920 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300921 return_value = os_listdir_impl(module, &path);
922
923exit:
924 /* Cleanup for path */
925 path_cleanup(&path);
926
927 return return_value;
928}
929
930#if defined(MS_WINDOWS)
931
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300932PyDoc_STRVAR(os__getfullpathname__doc__,
933"_getfullpathname($module, path, /)\n"
934"--\n"
935"\n");
936
937#define OS__GETFULLPATHNAME_METHODDEF \
938 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
939
940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300941os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300942
943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300944os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300945{
946 PyObject *return_value = NULL;
947 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
948
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300949 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300951 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300952 return_value = os__getfullpathname_impl(module, &path);
953
954exit:
955 /* Cleanup for path */
956 path_cleanup(&path);
957
958 return return_value;
959}
960
961#endif /* defined(MS_WINDOWS) */
962
963#if defined(MS_WINDOWS)
964
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300965PyDoc_STRVAR(os__getfinalpathname__doc__,
966"_getfinalpathname($module, path, /)\n"
967"--\n"
968"\n"
969"A helper function for samepath on windows.");
970
971#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300972 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300973
974static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300975os__getfinalpathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300976
977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300978os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300979{
980 PyObject *return_value = NULL;
981 PyObject *path;
982
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300983 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300985 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300986 return_value = os__getfinalpathname_impl(module, path);
987
988exit:
989 return return_value;
990}
991
992#endif /* defined(MS_WINDOWS) */
993
994#if defined(MS_WINDOWS)
995
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300996PyDoc_STRVAR(os__isdir__doc__,
997"_isdir($module, path, /)\n"
998"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +0200999"\n"
1000"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001001
1002#define OS__ISDIR_METHODDEF \
1003 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1004
1005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001006os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001007
1008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001009os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001010{
1011 PyObject *return_value = NULL;
1012 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1013
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001014 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001015 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001016 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001017 return_value = os__isdir_impl(module, &path);
1018
1019exit:
1020 /* Cleanup for path */
1021 path_cleanup(&path);
1022
1023 return return_value;
1024}
1025
1026#endif /* defined(MS_WINDOWS) */
1027
1028#if defined(MS_WINDOWS)
1029
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001030PyDoc_STRVAR(os__getvolumepathname__doc__,
1031"_getvolumepathname($module, /, path)\n"
1032"--\n"
1033"\n"
1034"A helper function for ismount on Win32.");
1035
1036#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001037 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001038
1039static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001040os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001041
1042static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001043os__getvolumepathname(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001044{
1045 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001046 static const char * const _keywords[] = {"path", NULL};
1047 static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001048 PyObject *path;
1049
Victor Stinner3e1fad62017-01-17 01:29:01 +01001050 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001051 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001053 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001054 return_value = os__getvolumepathname_impl(module, path);
1055
1056exit:
1057 return return_value;
1058}
1059
1060#endif /* defined(MS_WINDOWS) */
1061
1062PyDoc_STRVAR(os_mkdir__doc__,
1063"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1064"--\n"
1065"\n"
1066"Create a directory.\n"
1067"\n"
1068"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1069" and path should be relative; path will then be relative to that directory.\n"
1070"dir_fd may not be implemented on your platform.\n"
1071" If it is unavailable, using it will raise a NotImplementedError.\n"
1072"\n"
1073"The mode argument is ignored on Windows.");
1074
1075#define OS_MKDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001076 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001077
1078static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001079os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001080
1081static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001082os_mkdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001083{
1084 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001085 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1086 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001087 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1088 int mode = 511;
1089 int dir_fd = DEFAULT_DIR_FD;
1090
Victor Stinner3e1fad62017-01-17 01:29:01 +01001091 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001092 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001094 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001095 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1096
1097exit:
1098 /* Cleanup for path */
1099 path_cleanup(&path);
1100
1101 return return_value;
1102}
1103
1104#if defined(HAVE_NICE)
1105
1106PyDoc_STRVAR(os_nice__doc__,
1107"nice($module, increment, /)\n"
1108"--\n"
1109"\n"
1110"Add increment to the priority of process and return the new priority.");
1111
1112#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001113 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001114
1115static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001116os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001117
1118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001119os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001120{
1121 PyObject *return_value = NULL;
1122 int increment;
1123
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001124 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001125 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001126 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001127 return_value = os_nice_impl(module, increment);
1128
1129exit:
1130 return return_value;
1131}
1132
1133#endif /* defined(HAVE_NICE) */
1134
1135#if defined(HAVE_GETPRIORITY)
1136
1137PyDoc_STRVAR(os_getpriority__doc__,
1138"getpriority($module, /, which, who)\n"
1139"--\n"
1140"\n"
1141"Return program scheduling priority.");
1142
1143#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001144 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001145
1146static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001147os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001148
1149static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001150os_getpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001151{
1152 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001153 static const char * const _keywords[] = {"which", "who", NULL};
1154 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001155 int which;
1156 int who;
1157
Victor Stinner3e1fad62017-01-17 01:29:01 +01001158 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001159 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001160 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001161 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001162 return_value = os_getpriority_impl(module, which, who);
1163
1164exit:
1165 return return_value;
1166}
1167
1168#endif /* defined(HAVE_GETPRIORITY) */
1169
1170#if defined(HAVE_SETPRIORITY)
1171
1172PyDoc_STRVAR(os_setpriority__doc__,
1173"setpriority($module, /, which, who, priority)\n"
1174"--\n"
1175"\n"
1176"Set program scheduling priority.");
1177
1178#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001179 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001180
1181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001182os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001183
1184static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001185os_setpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001186{
1187 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001188 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1189 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001190 int which;
1191 int who;
1192 int priority;
1193
Victor Stinner3e1fad62017-01-17 01:29:01 +01001194 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001195 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001197 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001198 return_value = os_setpriority_impl(module, which, who, priority);
1199
1200exit:
1201 return return_value;
1202}
1203
1204#endif /* defined(HAVE_SETPRIORITY) */
1205
1206PyDoc_STRVAR(os_rename__doc__,
1207"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1208"--\n"
1209"\n"
1210"Rename a file or directory.\n"
1211"\n"
1212"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1213" descriptor open to a directory, and the respective path string (src or dst)\n"
1214" should be relative; the path will then be relative to that directory.\n"
1215"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1216" If they are unavailable, using them will raise a NotImplementedError.");
1217
1218#define OS_RENAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001219 {"rename", (PyCFunction)os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001220
1221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001222os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001223 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001224
1225static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001226os_rename(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001227{
1228 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001229 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1230 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001231 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1232 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1233 int src_dir_fd = DEFAULT_DIR_FD;
1234 int dst_dir_fd = DEFAULT_DIR_FD;
1235
Victor Stinner3e1fad62017-01-17 01:29:01 +01001236 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001237 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001238 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001239 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001240 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1241
1242exit:
1243 /* Cleanup for src */
1244 path_cleanup(&src);
1245 /* Cleanup for dst */
1246 path_cleanup(&dst);
1247
1248 return return_value;
1249}
1250
1251PyDoc_STRVAR(os_replace__doc__,
1252"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1253"--\n"
1254"\n"
1255"Rename a file or directory, overwriting the destination.\n"
1256"\n"
1257"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1258" descriptor open to a directory, and the respective path string (src or dst)\n"
1259" should be relative; the path will then be relative to that directory.\n"
1260"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1261" If they are unavailable, using them will raise a NotImplementedError.\"");
1262
1263#define OS_REPLACE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001264 {"replace", (PyCFunction)os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001265
1266static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001267os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1268 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001269
1270static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001271os_replace(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001272{
1273 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001274 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1275 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001276 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1277 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1278 int src_dir_fd = DEFAULT_DIR_FD;
1279 int dst_dir_fd = DEFAULT_DIR_FD;
1280
Victor Stinner3e1fad62017-01-17 01:29:01 +01001281 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001282 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001285 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1286
1287exit:
1288 /* Cleanup for src */
1289 path_cleanup(&src);
1290 /* Cleanup for dst */
1291 path_cleanup(&dst);
1292
1293 return return_value;
1294}
1295
1296PyDoc_STRVAR(os_rmdir__doc__,
1297"rmdir($module, /, path, *, dir_fd=None)\n"
1298"--\n"
1299"\n"
1300"Remove a directory.\n"
1301"\n"
1302"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1303" and path should be relative; path will then be relative to that directory.\n"
1304"dir_fd may not be implemented on your platform.\n"
1305" If it is unavailable, using it will raise a NotImplementedError.");
1306
1307#define OS_RMDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001308 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001309
1310static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001311os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001312
1313static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001314os_rmdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001315{
1316 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001317 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1318 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001319 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1320 int dir_fd = DEFAULT_DIR_FD;
1321
Victor Stinner3e1fad62017-01-17 01:29:01 +01001322 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001323 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001324 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001325 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001326 return_value = os_rmdir_impl(module, &path, dir_fd);
1327
1328exit:
1329 /* Cleanup for path */
1330 path_cleanup(&path);
1331
1332 return return_value;
1333}
1334
1335#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1336
1337PyDoc_STRVAR(os_system__doc__,
1338"system($module, /, command)\n"
1339"--\n"
1340"\n"
1341"Execute the command in a subshell.");
1342
1343#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001344 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001345
1346static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001347os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001348
1349static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001350os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001351{
1352 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001353 static const char * const _keywords[] = {"command", NULL};
1354 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001355 Py_UNICODE *command;
1356 long _return_value;
1357
Victor Stinner3e1fad62017-01-17 01:29:01 +01001358 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001359 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001360 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001361 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001362 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001363 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001364 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001365 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001366 return_value = PyLong_FromLong(_return_value);
1367
1368exit:
1369 return return_value;
1370}
1371
1372#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1373
1374#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1375
1376PyDoc_STRVAR(os_system__doc__,
1377"system($module, /, command)\n"
1378"--\n"
1379"\n"
1380"Execute the command in a subshell.");
1381
1382#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001383 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001384
1385static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001386os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001387
1388static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001389os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390{
1391 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001392 static const char * const _keywords[] = {"command", NULL};
1393 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001394 PyObject *command = NULL;
1395 long _return_value;
1396
Victor Stinner3e1fad62017-01-17 01:29:01 +01001397 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001398 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001399 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001400 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001401 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001402 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001404 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001405 return_value = PyLong_FromLong(_return_value);
1406
1407exit:
1408 /* Cleanup for command */
1409 Py_XDECREF(command);
1410
1411 return return_value;
1412}
1413
1414#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1415
1416PyDoc_STRVAR(os_umask__doc__,
1417"umask($module, mask, /)\n"
1418"--\n"
1419"\n"
1420"Set the current numeric umask and return the previous umask.");
1421
1422#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001423 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001424
1425static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001426os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001427
1428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001429os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001430{
1431 PyObject *return_value = NULL;
1432 int mask;
1433
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001434 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001435 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001436 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001437 return_value = os_umask_impl(module, mask);
1438
1439exit:
1440 return return_value;
1441}
1442
1443PyDoc_STRVAR(os_unlink__doc__,
1444"unlink($module, /, path, *, dir_fd=None)\n"
1445"--\n"
1446"\n"
1447"Remove a file (same as remove()).\n"
1448"\n"
1449"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1450" and path should be relative; path will then be relative to that directory.\n"
1451"dir_fd may not be implemented on your platform.\n"
1452" If it is unavailable, using it will raise a NotImplementedError.");
1453
1454#define OS_UNLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001455 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001456
1457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001458os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001459
1460static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001461os_unlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001462{
1463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001464 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1465 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001466 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1467 int dir_fd = DEFAULT_DIR_FD;
1468
Victor Stinner3e1fad62017-01-17 01:29:01 +01001469 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001470 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001473 return_value = os_unlink_impl(module, &path, dir_fd);
1474
1475exit:
1476 /* Cleanup for path */
1477 path_cleanup(&path);
1478
1479 return return_value;
1480}
1481
1482PyDoc_STRVAR(os_remove__doc__,
1483"remove($module, /, path, *, dir_fd=None)\n"
1484"--\n"
1485"\n"
1486"Remove a file (same as unlink()).\n"
1487"\n"
1488"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1489" and path should be relative; path will then be relative to that directory.\n"
1490"dir_fd may not be implemented on your platform.\n"
1491" If it is unavailable, using it will raise a NotImplementedError.");
1492
1493#define OS_REMOVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001494 {"remove", (PyCFunction)os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001495
1496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001497os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001498
1499static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001500os_remove(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001501{
1502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001503 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1504 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001505 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1506 int dir_fd = DEFAULT_DIR_FD;
1507
Victor Stinner3e1fad62017-01-17 01:29:01 +01001508 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001509 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001510 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001511 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001512 return_value = os_remove_impl(module, &path, dir_fd);
1513
1514exit:
1515 /* Cleanup for path */
1516 path_cleanup(&path);
1517
1518 return return_value;
1519}
1520
1521#if defined(HAVE_UNAME)
1522
1523PyDoc_STRVAR(os_uname__doc__,
1524"uname($module, /)\n"
1525"--\n"
1526"\n"
1527"Return an object identifying the current operating system.\n"
1528"\n"
1529"The object behaves like a named tuple with the following fields:\n"
1530" (sysname, nodename, release, version, machine)");
1531
1532#define OS_UNAME_METHODDEF \
1533 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1534
1535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001536os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001537
1538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001539os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001540{
1541 return os_uname_impl(module);
1542}
1543
1544#endif /* defined(HAVE_UNAME) */
1545
1546PyDoc_STRVAR(os_utime__doc__,
1547"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1548" follow_symlinks=True)\n"
1549"--\n"
1550"\n"
1551"Set the access and modified time of path.\n"
1552"\n"
1553"path may always be specified as a string.\n"
1554"On some platforms, path may also be specified as an open file descriptor.\n"
1555" If this functionality is unavailable, using it raises an exception.\n"
1556"\n"
1557"If times is not None, it must be a tuple (atime, mtime);\n"
1558" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001559"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001560" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1561" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001562"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001563"Specifying tuples for both times and ns is an error.\n"
1564"\n"
1565"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1566" and path should be relative; path will then be relative to that directory.\n"
1567"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1568" link, utime will modify the symbolic link itself instead of the file the\n"
1569" link points to.\n"
1570"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1571" as an open file descriptor.\n"
1572"dir_fd and follow_symlinks may not be available on your platform.\n"
1573" If they are unavailable, using them will raise a NotImplementedError.");
1574
1575#define OS_UTIME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001576 {"utime", (PyCFunction)os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001577
1578static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001579os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1580 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001581
1582static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001583os_utime(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001584{
1585 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001586 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1587 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001588 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1589 PyObject *times = NULL;
1590 PyObject *ns = NULL;
1591 int dir_fd = DEFAULT_DIR_FD;
1592 int follow_symlinks = 1;
1593
Victor Stinner3e1fad62017-01-17 01:29:01 +01001594 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001595 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001596 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001597 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001598 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1599
1600exit:
1601 /* Cleanup for path */
1602 path_cleanup(&path);
1603
1604 return return_value;
1605}
1606
1607PyDoc_STRVAR(os__exit__doc__,
1608"_exit($module, /, status)\n"
1609"--\n"
1610"\n"
1611"Exit to the system with specified status, without normal exit processing.");
1612
1613#define OS__EXIT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001614 {"_exit", (PyCFunction)os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001615
1616static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001617os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001618
1619static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001620os__exit(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001621{
1622 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001623 static const char * const _keywords[] = {"status", NULL};
1624 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001625 int status;
1626
Victor Stinner3e1fad62017-01-17 01:29:01 +01001627 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001628 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001629 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001630 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001631 return_value = os__exit_impl(module, status);
1632
1633exit:
1634 return return_value;
1635}
1636
1637#if defined(HAVE_EXECV)
1638
1639PyDoc_STRVAR(os_execv__doc__,
1640"execv($module, path, argv, /)\n"
1641"--\n"
1642"\n"
1643"Execute an executable path with arguments, replacing current process.\n"
1644"\n"
1645" path\n"
1646" Path of executable file.\n"
1647" argv\n"
1648" Tuple or list of strings.");
1649
1650#define OS_EXECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001651 {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001652
1653static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001654os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001655
1656static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001657os_execv(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001658{
1659 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001660 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001661 PyObject *argv;
1662
Sylvain74453812017-06-10 06:51:48 +02001663 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
1664 path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001665 goto exit;
1666 }
Steve Dowercc16be82016-09-08 10:35:16 -07001667 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001668
1669exit:
1670 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001671 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001672
1673 return return_value;
1674}
1675
1676#endif /* defined(HAVE_EXECV) */
1677
1678#if defined(HAVE_EXECV)
1679
1680PyDoc_STRVAR(os_execve__doc__,
1681"execve($module, /, path, argv, env)\n"
1682"--\n"
1683"\n"
1684"Execute an executable path with arguments, replacing current process.\n"
1685"\n"
1686" path\n"
1687" Path of executable file.\n"
1688" argv\n"
1689" Tuple or list of strings.\n"
1690" env\n"
1691" Dictionary of strings mapping to strings.");
1692
1693#define OS_EXECVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001694 {"execve", (PyCFunction)os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001695
1696static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001697os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001698
1699static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001700os_execve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001701{
1702 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001703 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1704 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001705 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1706 PyObject *argv;
1707 PyObject *env;
1708
Victor Stinner3e1fad62017-01-17 01:29:01 +01001709 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001710 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001711 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001712 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001713 return_value = os_execve_impl(module, &path, argv, env);
1714
1715exit:
1716 /* Cleanup for path */
1717 path_cleanup(&path);
1718
1719 return return_value;
1720}
1721
1722#endif /* defined(HAVE_EXECV) */
1723
Steve Dowercc16be82016-09-08 10:35:16 -07001724#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001725
1726PyDoc_STRVAR(os_spawnv__doc__,
1727"spawnv($module, mode, path, argv, /)\n"
1728"--\n"
1729"\n"
1730"Execute the program specified by path in a new process.\n"
1731"\n"
1732" mode\n"
1733" Mode of process creation.\n"
1734" path\n"
1735" Path of executable file.\n"
1736" argv\n"
1737" Tuple or list of strings.");
1738
1739#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001740 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001741
1742static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001743os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001744
1745static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001746os_spawnv(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001747{
1748 PyObject *return_value = NULL;
1749 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001750 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001751 PyObject *argv;
1752
Sylvain74453812017-06-10 06:51:48 +02001753 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1754 &mode, path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001755 goto exit;
1756 }
Steve Dowercc16be82016-09-08 10:35:16 -07001757 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001758
1759exit:
1760 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001761 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001762
1763 return return_value;
1764}
1765
Steve Dowercc16be82016-09-08 10:35:16 -07001766#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001767
Steve Dowercc16be82016-09-08 10:35:16 -07001768#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001769
1770PyDoc_STRVAR(os_spawnve__doc__,
1771"spawnve($module, mode, path, argv, env, /)\n"
1772"--\n"
1773"\n"
1774"Execute the program specified by path in a new process.\n"
1775"\n"
1776" mode\n"
1777" Mode of process creation.\n"
1778" path\n"
1779" Path of executable file.\n"
1780" argv\n"
1781" Tuple or list of strings.\n"
1782" env\n"
1783" Dictionary of strings mapping to strings.");
1784
1785#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001786 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001787
1788static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001789os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001790 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001791
1792static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001793os_spawnve(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001794{
1795 PyObject *return_value = NULL;
1796 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001797 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001798 PyObject *argv;
1799 PyObject *env;
1800
Sylvain74453812017-06-10 06:51:48 +02001801 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1802 &mode, path_converter, &path, &argv, &env)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001803 goto exit;
1804 }
Steve Dowercc16be82016-09-08 10:35:16 -07001805 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001806
1807exit:
1808 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001809 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001810
1811 return return_value;
1812}
1813
Steve Dowercc16be82016-09-08 10:35:16 -07001814#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001815
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001816#if defined(HAVE_FORK)
1817
1818PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001819"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1820" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001821"--\n"
1822"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001823"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001824"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001825" before\n"
1826" A callable to be called in the parent before the fork() syscall.\n"
1827" after_in_child\n"
1828" A callable to be called in the child after fork().\n"
1829" after_in_parent\n"
1830" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001831"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001832"\'before\' callbacks are called in reverse order.\n"
1833"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001834
1835#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001836 {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001837
1838static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001839os_register_at_fork_impl(PyObject *module, PyObject *before,
1840 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001841
1842static PyObject *
1843os_register_at_fork(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
1844{
1845 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001846 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1847 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1848 PyObject *before = NULL;
1849 PyObject *after_in_child = NULL;
1850 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001851
1852 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001853 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001854 goto exit;
1855 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001856 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001857
1858exit:
1859 return return_value;
1860}
1861
1862#endif /* defined(HAVE_FORK) */
1863
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001864#if defined(HAVE_FORK1)
1865
1866PyDoc_STRVAR(os_fork1__doc__,
1867"fork1($module, /)\n"
1868"--\n"
1869"\n"
1870"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1871"\n"
1872"Return 0 to child process and PID of child to parent process.");
1873
1874#define OS_FORK1_METHODDEF \
1875 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1876
1877static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001878os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001879
1880static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001881os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001882{
1883 return os_fork1_impl(module);
1884}
1885
1886#endif /* defined(HAVE_FORK1) */
1887
1888#if defined(HAVE_FORK)
1889
1890PyDoc_STRVAR(os_fork__doc__,
1891"fork($module, /)\n"
1892"--\n"
1893"\n"
1894"Fork a child process.\n"
1895"\n"
1896"Return 0 to child process and PID of child to parent process.");
1897
1898#define OS_FORK_METHODDEF \
1899 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1900
1901static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001902os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001903
1904static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001905os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001906{
1907 return os_fork_impl(module);
1908}
1909
1910#endif /* defined(HAVE_FORK) */
1911
1912#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1913
1914PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1915"sched_get_priority_max($module, /, policy)\n"
1916"--\n"
1917"\n"
1918"Get the maximum scheduling priority for policy.");
1919
1920#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001921 {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001922
1923static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001924os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001925
1926static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001927os_sched_get_priority_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001928{
1929 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001930 static const char * const _keywords[] = {"policy", NULL};
1931 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001932 int policy;
1933
Victor Stinner3e1fad62017-01-17 01:29:01 +01001934 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001935 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001936 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001937 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001938 return_value = os_sched_get_priority_max_impl(module, policy);
1939
1940exit:
1941 return return_value;
1942}
1943
1944#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1945
1946#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1947
1948PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1949"sched_get_priority_min($module, /, policy)\n"
1950"--\n"
1951"\n"
1952"Get the minimum scheduling priority for policy.");
1953
1954#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001955 {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001956
1957static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001958os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001959
1960static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001961os_sched_get_priority_min(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001962{
1963 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001964 static const char * const _keywords[] = {"policy", NULL};
1965 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001966 int policy;
1967
Victor Stinner3e1fad62017-01-17 01:29:01 +01001968 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001969 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001970 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001971 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001972 return_value = os_sched_get_priority_min_impl(module, policy);
1973
1974exit:
1975 return return_value;
1976}
1977
1978#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1979
1980#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1981
1982PyDoc_STRVAR(os_sched_getscheduler__doc__,
1983"sched_getscheduler($module, pid, /)\n"
1984"--\n"
1985"\n"
1986"Get the scheduling policy for the process identifiedy by pid.\n"
1987"\n"
1988"Passing 0 for pid returns the scheduling policy for the calling process.");
1989
1990#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001991 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001992
1993static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001994os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001995
1996static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001997os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001998{
1999 PyObject *return_value = NULL;
2000 pid_t pid;
2001
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002002 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002003 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002004 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002005 return_value = os_sched_getscheduler_impl(module, pid);
2006
2007exit:
2008 return return_value;
2009}
2010
2011#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2012
2013#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
2014
2015PyDoc_STRVAR(os_sched_param__doc__,
2016"sched_param(sched_priority)\n"
2017"--\n"
2018"\n"
2019"Current has only one field: sched_priority\");\n"
2020"\n"
2021" sched_priority\n"
2022" A scheduling parameter.");
2023
2024static PyObject *
2025os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2026
2027static PyObject *
2028os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2029{
2030 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002031 static const char * const _keywords[] = {"sched_priority", NULL};
2032 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002033 PyObject *sched_priority;
2034
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002035 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002036 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002037 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002038 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002039 return_value = os_sched_param_impl(type, sched_priority);
2040
2041exit:
2042 return return_value;
2043}
2044
2045#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2046
2047#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2048
2049PyDoc_STRVAR(os_sched_setscheduler__doc__,
2050"sched_setscheduler($module, pid, policy, param, /)\n"
2051"--\n"
2052"\n"
2053"Set the scheduling policy for the process identified by pid.\n"
2054"\n"
2055"If pid is 0, the calling process is changed.\n"
2056"param is an instance of sched_param.");
2057
2058#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002059 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002060
2061static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002062os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002063 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002064
2065static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002066os_sched_setscheduler(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002067{
2068 PyObject *return_value = NULL;
2069 pid_t pid;
2070 int policy;
2071 struct sched_param param;
2072
Sylvain74453812017-06-10 06:51:48 +02002073 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2074 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002075 goto exit;
2076 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002077 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2078
2079exit:
2080 return return_value;
2081}
2082
2083#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2084
2085#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2086
2087PyDoc_STRVAR(os_sched_getparam__doc__,
2088"sched_getparam($module, pid, /)\n"
2089"--\n"
2090"\n"
2091"Returns scheduling parameters for the process identified by pid.\n"
2092"\n"
2093"If pid is 0, returns parameters for the calling process.\n"
2094"Return value is an instance of sched_param.");
2095
2096#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002097 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002098
2099static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002100os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002101
2102static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002103os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002104{
2105 PyObject *return_value = NULL;
2106 pid_t pid;
2107
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002108 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002109 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002110 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002111 return_value = os_sched_getparam_impl(module, pid);
2112
2113exit:
2114 return return_value;
2115}
2116
2117#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2118
2119#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2120
2121PyDoc_STRVAR(os_sched_setparam__doc__,
2122"sched_setparam($module, pid, param, /)\n"
2123"--\n"
2124"\n"
2125"Set scheduling parameters for the process identified by pid.\n"
2126"\n"
2127"If pid is 0, sets parameters for the calling process.\n"
2128"param should be an instance of sched_param.");
2129
2130#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002131 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002132
2133static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002134os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002135 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002136
2137static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002138os_sched_setparam(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002139{
2140 PyObject *return_value = NULL;
2141 pid_t pid;
2142 struct sched_param param;
2143
Sylvain74453812017-06-10 06:51:48 +02002144 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2145 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002146 goto exit;
2147 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002148 return_value = os_sched_setparam_impl(module, pid, &param);
2149
2150exit:
2151 return return_value;
2152}
2153
2154#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2155
2156#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2157
2158PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2159"sched_rr_get_interval($module, pid, /)\n"
2160"--\n"
2161"\n"
2162"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2163"\n"
2164"Value returned is a float.");
2165
2166#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002167 {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002168
2169static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002170os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002171
2172static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002173os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002174{
2175 PyObject *return_value = NULL;
2176 pid_t pid;
2177 double _return_value;
2178
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002179 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002180 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002181 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002182 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002183 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002184 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002185 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002186 return_value = PyFloat_FromDouble(_return_value);
2187
2188exit:
2189 return return_value;
2190}
2191
2192#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2193
2194#if defined(HAVE_SCHED_H)
2195
2196PyDoc_STRVAR(os_sched_yield__doc__,
2197"sched_yield($module, /)\n"
2198"--\n"
2199"\n"
2200"Voluntarily relinquish the CPU.");
2201
2202#define OS_SCHED_YIELD_METHODDEF \
2203 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2204
2205static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002206os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002207
2208static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002209os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002210{
2211 return os_sched_yield_impl(module);
2212}
2213
2214#endif /* defined(HAVE_SCHED_H) */
2215
2216#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2217
2218PyDoc_STRVAR(os_sched_setaffinity__doc__,
2219"sched_setaffinity($module, pid, mask, /)\n"
2220"--\n"
2221"\n"
2222"Set the CPU affinity of the process identified by pid to mask.\n"
2223"\n"
2224"mask should be an iterable of integers identifying CPUs.");
2225
2226#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002227 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002228
2229static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002230os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002231
2232static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002233os_sched_setaffinity(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002234{
2235 PyObject *return_value = NULL;
2236 pid_t pid;
2237 PyObject *mask;
2238
Sylvain74453812017-06-10 06:51:48 +02002239 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2240 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002241 goto exit;
2242 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002243 return_value = os_sched_setaffinity_impl(module, pid, mask);
2244
2245exit:
2246 return return_value;
2247}
2248
2249#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2250
2251#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2252
2253PyDoc_STRVAR(os_sched_getaffinity__doc__,
2254"sched_getaffinity($module, pid, /)\n"
2255"--\n"
2256"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002257"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002258"\n"
2259"The affinity is returned as a set of CPU identifiers.");
2260
2261#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002262 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002263
2264static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002265os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002266
2267static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002268os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002269{
2270 PyObject *return_value = NULL;
2271 pid_t pid;
2272
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002273 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002274 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002275 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002276 return_value = os_sched_getaffinity_impl(module, pid);
2277
2278exit:
2279 return return_value;
2280}
2281
2282#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2283
2284#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2285
2286PyDoc_STRVAR(os_openpty__doc__,
2287"openpty($module, /)\n"
2288"--\n"
2289"\n"
2290"Open a pseudo-terminal.\n"
2291"\n"
2292"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2293"for both the master and slave ends.");
2294
2295#define OS_OPENPTY_METHODDEF \
2296 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2297
2298static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002299os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002300
2301static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002302os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002303{
2304 return os_openpty_impl(module);
2305}
2306
2307#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2308
2309#if defined(HAVE_FORKPTY)
2310
2311PyDoc_STRVAR(os_forkpty__doc__,
2312"forkpty($module, /)\n"
2313"--\n"
2314"\n"
2315"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2316"\n"
2317"Returns a tuple of (pid, master_fd).\n"
2318"Like fork(), return pid of 0 to the child process,\n"
2319"and pid of child to the parent process.\n"
2320"To both, return fd of newly opened pseudo-terminal.");
2321
2322#define OS_FORKPTY_METHODDEF \
2323 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2324
2325static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002326os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002327
2328static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002329os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002330{
2331 return os_forkpty_impl(module);
2332}
2333
2334#endif /* defined(HAVE_FORKPTY) */
2335
2336#if defined(HAVE_GETEGID)
2337
2338PyDoc_STRVAR(os_getegid__doc__,
2339"getegid($module, /)\n"
2340"--\n"
2341"\n"
2342"Return the current process\'s effective group id.");
2343
2344#define OS_GETEGID_METHODDEF \
2345 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2346
2347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002348os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002349
2350static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002351os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002352{
2353 return os_getegid_impl(module);
2354}
2355
2356#endif /* defined(HAVE_GETEGID) */
2357
2358#if defined(HAVE_GETEUID)
2359
2360PyDoc_STRVAR(os_geteuid__doc__,
2361"geteuid($module, /)\n"
2362"--\n"
2363"\n"
2364"Return the current process\'s effective user id.");
2365
2366#define OS_GETEUID_METHODDEF \
2367 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2368
2369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002370os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002371
2372static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002373os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002374{
2375 return os_geteuid_impl(module);
2376}
2377
2378#endif /* defined(HAVE_GETEUID) */
2379
2380#if defined(HAVE_GETGID)
2381
2382PyDoc_STRVAR(os_getgid__doc__,
2383"getgid($module, /)\n"
2384"--\n"
2385"\n"
2386"Return the current process\'s group id.");
2387
2388#define OS_GETGID_METHODDEF \
2389 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2390
2391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002392os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002393
2394static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002395os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002396{
2397 return os_getgid_impl(module);
2398}
2399
2400#endif /* defined(HAVE_GETGID) */
2401
Berker Peksag39404992016-09-15 20:45:16 +03002402#if defined(HAVE_GETPID)
2403
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002404PyDoc_STRVAR(os_getpid__doc__,
2405"getpid($module, /)\n"
2406"--\n"
2407"\n"
2408"Return the current process id.");
2409
2410#define OS_GETPID_METHODDEF \
2411 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2412
2413static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002414os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002415
2416static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002417os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002418{
2419 return os_getpid_impl(module);
2420}
2421
Berker Peksag39404992016-09-15 20:45:16 +03002422#endif /* defined(HAVE_GETPID) */
2423
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002424#if defined(HAVE_GETGROUPS)
2425
2426PyDoc_STRVAR(os_getgroups__doc__,
2427"getgroups($module, /)\n"
2428"--\n"
2429"\n"
2430"Return list of supplemental group IDs for the process.");
2431
2432#define OS_GETGROUPS_METHODDEF \
2433 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2434
2435static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002436os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002437
2438static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002439os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002440{
2441 return os_getgroups_impl(module);
2442}
2443
2444#endif /* defined(HAVE_GETGROUPS) */
2445
2446#if defined(HAVE_GETPGID)
2447
2448PyDoc_STRVAR(os_getpgid__doc__,
2449"getpgid($module, /, pid)\n"
2450"--\n"
2451"\n"
2452"Call the system call getpgid(), and return the result.");
2453
2454#define OS_GETPGID_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002455 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002456
2457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002458os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002459
2460static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002461os_getpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002462{
2463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002464 static const char * const _keywords[] = {"pid", NULL};
2465 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002466 pid_t pid;
2467
Victor Stinner3e1fad62017-01-17 01:29:01 +01002468 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002469 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002470 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002471 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002472 return_value = os_getpgid_impl(module, pid);
2473
2474exit:
2475 return return_value;
2476}
2477
2478#endif /* defined(HAVE_GETPGID) */
2479
2480#if defined(HAVE_GETPGRP)
2481
2482PyDoc_STRVAR(os_getpgrp__doc__,
2483"getpgrp($module, /)\n"
2484"--\n"
2485"\n"
2486"Return the current process group id.");
2487
2488#define OS_GETPGRP_METHODDEF \
2489 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2490
2491static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002492os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002493
2494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002495os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002496{
2497 return os_getpgrp_impl(module);
2498}
2499
2500#endif /* defined(HAVE_GETPGRP) */
2501
2502#if defined(HAVE_SETPGRP)
2503
2504PyDoc_STRVAR(os_setpgrp__doc__,
2505"setpgrp($module, /)\n"
2506"--\n"
2507"\n"
2508"Make the current process the leader of its process group.");
2509
2510#define OS_SETPGRP_METHODDEF \
2511 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2512
2513static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002514os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002515
2516static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002517os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002518{
2519 return os_setpgrp_impl(module);
2520}
2521
2522#endif /* defined(HAVE_SETPGRP) */
2523
2524#if defined(HAVE_GETPPID)
2525
2526PyDoc_STRVAR(os_getppid__doc__,
2527"getppid($module, /)\n"
2528"--\n"
2529"\n"
2530"Return the parent\'s process id.\n"
2531"\n"
2532"If the parent process has already exited, Windows machines will still\n"
2533"return its id; others systems will return the id of the \'init\' process (1).");
2534
2535#define OS_GETPPID_METHODDEF \
2536 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2537
2538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002539os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002540
2541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002542os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002543{
2544 return os_getppid_impl(module);
2545}
2546
2547#endif /* defined(HAVE_GETPPID) */
2548
2549#if defined(HAVE_GETLOGIN)
2550
2551PyDoc_STRVAR(os_getlogin__doc__,
2552"getlogin($module, /)\n"
2553"--\n"
2554"\n"
2555"Return the actual login name.");
2556
2557#define OS_GETLOGIN_METHODDEF \
2558 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2559
2560static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002561os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002562
2563static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002564os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002565{
2566 return os_getlogin_impl(module);
2567}
2568
2569#endif /* defined(HAVE_GETLOGIN) */
2570
2571#if defined(HAVE_GETUID)
2572
2573PyDoc_STRVAR(os_getuid__doc__,
2574"getuid($module, /)\n"
2575"--\n"
2576"\n"
2577"Return the current process\'s user id.");
2578
2579#define OS_GETUID_METHODDEF \
2580 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2581
2582static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002583os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002584
2585static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002586os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002587{
2588 return os_getuid_impl(module);
2589}
2590
2591#endif /* defined(HAVE_GETUID) */
2592
2593#if defined(HAVE_KILL)
2594
2595PyDoc_STRVAR(os_kill__doc__,
2596"kill($module, pid, signal, /)\n"
2597"--\n"
2598"\n"
2599"Kill a process with a signal.");
2600
2601#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002602 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002603
2604static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002605os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002606
2607static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002608os_kill(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002609{
2610 PyObject *return_value = NULL;
2611 pid_t pid;
2612 Py_ssize_t signal;
2613
Sylvain74453812017-06-10 06:51:48 +02002614 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2615 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002616 goto exit;
2617 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002618 return_value = os_kill_impl(module, pid, signal);
2619
2620exit:
2621 return return_value;
2622}
2623
2624#endif /* defined(HAVE_KILL) */
2625
2626#if defined(HAVE_KILLPG)
2627
2628PyDoc_STRVAR(os_killpg__doc__,
2629"killpg($module, pgid, signal, /)\n"
2630"--\n"
2631"\n"
2632"Kill a process group with a signal.");
2633
2634#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002635 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002636
2637static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002638os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002639
2640static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002641os_killpg(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002642{
2643 PyObject *return_value = NULL;
2644 pid_t pgid;
2645 int signal;
2646
Sylvain74453812017-06-10 06:51:48 +02002647 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2648 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002649 goto exit;
2650 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002651 return_value = os_killpg_impl(module, pgid, signal);
2652
2653exit:
2654 return return_value;
2655}
2656
2657#endif /* defined(HAVE_KILLPG) */
2658
2659#if defined(HAVE_PLOCK)
2660
2661PyDoc_STRVAR(os_plock__doc__,
2662"plock($module, op, /)\n"
2663"--\n"
2664"\n"
2665"Lock program segments into memory.\");");
2666
2667#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002668 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002669
2670static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002671os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002672
2673static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002674os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002675{
2676 PyObject *return_value = NULL;
2677 int op;
2678
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002679 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002680 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002681 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002682 return_value = os_plock_impl(module, op);
2683
2684exit:
2685 return return_value;
2686}
2687
2688#endif /* defined(HAVE_PLOCK) */
2689
2690#if defined(HAVE_SETUID)
2691
2692PyDoc_STRVAR(os_setuid__doc__,
2693"setuid($module, uid, /)\n"
2694"--\n"
2695"\n"
2696"Set the current process\'s user id.");
2697
2698#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002699 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002700
2701static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002702os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002703
2704static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002705os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002706{
2707 PyObject *return_value = NULL;
2708 uid_t uid;
2709
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002710 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002711 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002712 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002713 return_value = os_setuid_impl(module, uid);
2714
2715exit:
2716 return return_value;
2717}
2718
2719#endif /* defined(HAVE_SETUID) */
2720
2721#if defined(HAVE_SETEUID)
2722
2723PyDoc_STRVAR(os_seteuid__doc__,
2724"seteuid($module, euid, /)\n"
2725"--\n"
2726"\n"
2727"Set the current process\'s effective user id.");
2728
2729#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002730 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002731
2732static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002733os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002734
2735static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002736os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002737{
2738 PyObject *return_value = NULL;
2739 uid_t euid;
2740
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002741 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002742 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002743 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002744 return_value = os_seteuid_impl(module, euid);
2745
2746exit:
2747 return return_value;
2748}
2749
2750#endif /* defined(HAVE_SETEUID) */
2751
2752#if defined(HAVE_SETEGID)
2753
2754PyDoc_STRVAR(os_setegid__doc__,
2755"setegid($module, egid, /)\n"
2756"--\n"
2757"\n"
2758"Set the current process\'s effective group id.");
2759
2760#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002761 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002762
2763static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002764os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002765
2766static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002767os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002768{
2769 PyObject *return_value = NULL;
2770 gid_t egid;
2771
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002772 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002773 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002774 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002775 return_value = os_setegid_impl(module, egid);
2776
2777exit:
2778 return return_value;
2779}
2780
2781#endif /* defined(HAVE_SETEGID) */
2782
2783#if defined(HAVE_SETREUID)
2784
2785PyDoc_STRVAR(os_setreuid__doc__,
2786"setreuid($module, ruid, euid, /)\n"
2787"--\n"
2788"\n"
2789"Set the current process\'s real and effective user ids.");
2790
2791#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002792 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002793
2794static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002795os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002796
2797static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002798os_setreuid(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002799{
2800 PyObject *return_value = NULL;
2801 uid_t ruid;
2802 uid_t euid;
2803
Sylvain74453812017-06-10 06:51:48 +02002804 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2805 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002806 goto exit;
2807 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002808 return_value = os_setreuid_impl(module, ruid, euid);
2809
2810exit:
2811 return return_value;
2812}
2813
2814#endif /* defined(HAVE_SETREUID) */
2815
2816#if defined(HAVE_SETREGID)
2817
2818PyDoc_STRVAR(os_setregid__doc__,
2819"setregid($module, rgid, egid, /)\n"
2820"--\n"
2821"\n"
2822"Set the current process\'s real and effective group ids.");
2823
2824#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002825 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002826
2827static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002828os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002829
2830static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002831os_setregid(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002832{
2833 PyObject *return_value = NULL;
2834 gid_t rgid;
2835 gid_t egid;
2836
Sylvain74453812017-06-10 06:51:48 +02002837 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2838 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002839 goto exit;
2840 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002841 return_value = os_setregid_impl(module, rgid, egid);
2842
2843exit:
2844 return return_value;
2845}
2846
2847#endif /* defined(HAVE_SETREGID) */
2848
2849#if defined(HAVE_SETGID)
2850
2851PyDoc_STRVAR(os_setgid__doc__,
2852"setgid($module, gid, /)\n"
2853"--\n"
2854"\n"
2855"Set the current process\'s group id.");
2856
2857#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002858 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002859
2860static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002861os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002862
2863static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002864os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002865{
2866 PyObject *return_value = NULL;
2867 gid_t gid;
2868
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002869 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002870 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002871 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002872 return_value = os_setgid_impl(module, gid);
2873
2874exit:
2875 return return_value;
2876}
2877
2878#endif /* defined(HAVE_SETGID) */
2879
2880#if defined(HAVE_SETGROUPS)
2881
2882PyDoc_STRVAR(os_setgroups__doc__,
2883"setgroups($module, groups, /)\n"
2884"--\n"
2885"\n"
2886"Set the groups of the current process to list.");
2887
2888#define OS_SETGROUPS_METHODDEF \
2889 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2890
2891#endif /* defined(HAVE_SETGROUPS) */
2892
2893#if defined(HAVE_WAIT3)
2894
2895PyDoc_STRVAR(os_wait3__doc__,
2896"wait3($module, /, options)\n"
2897"--\n"
2898"\n"
2899"Wait for completion of a child process.\n"
2900"\n"
2901"Returns a tuple of information about the child process:\n"
2902" (pid, status, rusage)");
2903
2904#define OS_WAIT3_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002905 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002906
2907static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002908os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002909
2910static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002911os_wait3(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002912{
2913 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002914 static const char * const _keywords[] = {"options", NULL};
2915 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002916 int options;
2917
Victor Stinner3e1fad62017-01-17 01:29:01 +01002918 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002919 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002920 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002921 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002922 return_value = os_wait3_impl(module, options);
2923
2924exit:
2925 return return_value;
2926}
2927
2928#endif /* defined(HAVE_WAIT3) */
2929
2930#if defined(HAVE_WAIT4)
2931
2932PyDoc_STRVAR(os_wait4__doc__,
2933"wait4($module, /, pid, options)\n"
2934"--\n"
2935"\n"
2936"Wait for completion of a specific child process.\n"
2937"\n"
2938"Returns a tuple of information about the child process:\n"
2939" (pid, status, rusage)");
2940
2941#define OS_WAIT4_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002942 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002943
2944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002945os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002946
2947static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002948os_wait4(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002949{
2950 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002951 static const char * const _keywords[] = {"pid", "options", NULL};
2952 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002953 pid_t pid;
2954 int options;
2955
Victor Stinner3e1fad62017-01-17 01:29:01 +01002956 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002957 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002958 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002959 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002960 return_value = os_wait4_impl(module, pid, options);
2961
2962exit:
2963 return return_value;
2964}
2965
2966#endif /* defined(HAVE_WAIT4) */
2967
2968#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2969
2970PyDoc_STRVAR(os_waitid__doc__,
2971"waitid($module, idtype, id, options, /)\n"
2972"--\n"
2973"\n"
2974"Returns the result of waiting for a process or processes.\n"
2975"\n"
2976" idtype\n"
2977" Must be one of be P_PID, P_PGID or P_ALL.\n"
2978" id\n"
2979" The id to wait on.\n"
2980" options\n"
2981" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2982" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2983"\n"
2984"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2985"no children in a waitable state.");
2986
2987#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002988 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002989
2990static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002991os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002992
2993static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002994os_waitid(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002995{
2996 PyObject *return_value = NULL;
2997 idtype_t idtype;
2998 id_t id;
2999 int options;
3000
Sylvain74453812017-06-10 06:51:48 +02003001 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3002 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003003 goto exit;
3004 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003005 return_value = os_waitid_impl(module, idtype, id, options);
3006
3007exit:
3008 return return_value;
3009}
3010
3011#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3012
3013#if defined(HAVE_WAITPID)
3014
3015PyDoc_STRVAR(os_waitpid__doc__,
3016"waitpid($module, pid, options, /)\n"
3017"--\n"
3018"\n"
3019"Wait for completion of a given child process.\n"
3020"\n"
3021"Returns a tuple of information regarding the child process:\n"
3022" (pid, status)\n"
3023"\n"
3024"The options argument is ignored on Windows.");
3025
3026#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003027 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003028
3029static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003030os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003031
3032static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003033os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003034{
3035 PyObject *return_value = NULL;
3036 pid_t pid;
3037 int options;
3038
Sylvain74453812017-06-10 06:51:48 +02003039 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3040 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003041 goto exit;
3042 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003043 return_value = os_waitpid_impl(module, pid, options);
3044
3045exit:
3046 return return_value;
3047}
3048
3049#endif /* defined(HAVE_WAITPID) */
3050
3051#if defined(HAVE_CWAIT)
3052
3053PyDoc_STRVAR(os_waitpid__doc__,
3054"waitpid($module, pid, options, /)\n"
3055"--\n"
3056"\n"
3057"Wait for completion of a given process.\n"
3058"\n"
3059"Returns a tuple of information regarding the process:\n"
3060" (pid, status << 8)\n"
3061"\n"
3062"The options argument is ignored on Windows.");
3063
3064#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003065 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003066
3067static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003068os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003069
3070static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003071os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003072{
3073 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003074 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003075 int options;
3076
Sylvain74453812017-06-10 06:51:48 +02003077 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3078 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003079 goto exit;
3080 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003081 return_value = os_waitpid_impl(module, pid, options);
3082
3083exit:
3084 return return_value;
3085}
3086
3087#endif /* defined(HAVE_CWAIT) */
3088
3089#if defined(HAVE_WAIT)
3090
3091PyDoc_STRVAR(os_wait__doc__,
3092"wait($module, /)\n"
3093"--\n"
3094"\n"
3095"Wait for completion of a child process.\n"
3096"\n"
3097"Returns a tuple of information about the child process:\n"
3098" (pid, status)");
3099
3100#define OS_WAIT_METHODDEF \
3101 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3102
3103static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003104os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003105
3106static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003107os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003108{
3109 return os_wait_impl(module);
3110}
3111
3112#endif /* defined(HAVE_WAIT) */
3113
3114#if defined(HAVE_SYMLINK)
3115
3116PyDoc_STRVAR(os_symlink__doc__,
3117"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3118"--\n"
3119"\n"
3120"Create a symbolic link pointing to src named dst.\n"
3121"\n"
3122"target_is_directory is required on Windows if the target is to be\n"
3123" interpreted as a directory. (On Windows, symlink requires\n"
3124" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3125" target_is_directory is ignored on non-Windows platforms.\n"
3126"\n"
3127"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3128" and path should be relative; path will then be relative to that directory.\n"
3129"dir_fd may not be implemented on your platform.\n"
3130" If it is unavailable, using it will raise a NotImplementedError.");
3131
3132#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003133 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003134
3135static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003136os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003137 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003138
3139static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003140os_symlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003141{
3142 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003143 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3144 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003145 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3146 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3147 int target_is_directory = 0;
3148 int dir_fd = DEFAULT_DIR_FD;
3149
Victor Stinner3e1fad62017-01-17 01:29:01 +01003150 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003151 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003152 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003154 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3155
3156exit:
3157 /* Cleanup for src */
3158 path_cleanup(&src);
3159 /* Cleanup for dst */
3160 path_cleanup(&dst);
3161
3162 return return_value;
3163}
3164
3165#endif /* defined(HAVE_SYMLINK) */
3166
3167#if defined(HAVE_TIMES)
3168
3169PyDoc_STRVAR(os_times__doc__,
3170"times($module, /)\n"
3171"--\n"
3172"\n"
3173"Return a collection containing process timing information.\n"
3174"\n"
3175"The object returned behaves like a named tuple with these fields:\n"
3176" (utime, stime, cutime, cstime, elapsed_time)\n"
3177"All fields are floating point numbers.");
3178
3179#define OS_TIMES_METHODDEF \
3180 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3181
3182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003183os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003184
3185static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003186os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003187{
3188 return os_times_impl(module);
3189}
3190
3191#endif /* defined(HAVE_TIMES) */
3192
3193#if defined(HAVE_GETSID)
3194
3195PyDoc_STRVAR(os_getsid__doc__,
3196"getsid($module, pid, /)\n"
3197"--\n"
3198"\n"
3199"Call the system call getsid(pid) and return the result.");
3200
3201#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003202 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003203
3204static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003205os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003206
3207static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003208os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003209{
3210 PyObject *return_value = NULL;
3211 pid_t pid;
3212
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003213 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003214 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003215 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003216 return_value = os_getsid_impl(module, pid);
3217
3218exit:
3219 return return_value;
3220}
3221
3222#endif /* defined(HAVE_GETSID) */
3223
3224#if defined(HAVE_SETSID)
3225
3226PyDoc_STRVAR(os_setsid__doc__,
3227"setsid($module, /)\n"
3228"--\n"
3229"\n"
3230"Call the system call setsid().");
3231
3232#define OS_SETSID_METHODDEF \
3233 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3234
3235static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003236os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003237
3238static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003239os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003240{
3241 return os_setsid_impl(module);
3242}
3243
3244#endif /* defined(HAVE_SETSID) */
3245
3246#if defined(HAVE_SETPGID)
3247
3248PyDoc_STRVAR(os_setpgid__doc__,
3249"setpgid($module, pid, pgrp, /)\n"
3250"--\n"
3251"\n"
3252"Call the system call setpgid(pid, pgrp).");
3253
3254#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003255 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003256
3257static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003258os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003259
3260static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003261os_setpgid(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003262{
3263 PyObject *return_value = NULL;
3264 pid_t pid;
3265 pid_t pgrp;
3266
Sylvain74453812017-06-10 06:51:48 +02003267 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3268 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003269 goto exit;
3270 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003271 return_value = os_setpgid_impl(module, pid, pgrp);
3272
3273exit:
3274 return return_value;
3275}
3276
3277#endif /* defined(HAVE_SETPGID) */
3278
3279#if defined(HAVE_TCGETPGRP)
3280
3281PyDoc_STRVAR(os_tcgetpgrp__doc__,
3282"tcgetpgrp($module, fd, /)\n"
3283"--\n"
3284"\n"
3285"Return the process group associated with the terminal specified by fd.");
3286
3287#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003288 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003289
3290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003291os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003292
3293static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003294os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003295{
3296 PyObject *return_value = NULL;
3297 int fd;
3298
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003299 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003300 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003301 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003302 return_value = os_tcgetpgrp_impl(module, fd);
3303
3304exit:
3305 return return_value;
3306}
3307
3308#endif /* defined(HAVE_TCGETPGRP) */
3309
3310#if defined(HAVE_TCSETPGRP)
3311
3312PyDoc_STRVAR(os_tcsetpgrp__doc__,
3313"tcsetpgrp($module, fd, pgid, /)\n"
3314"--\n"
3315"\n"
3316"Set the process group associated with the terminal specified by fd.");
3317
3318#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003319 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003320
3321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003322os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003323
3324static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003325os_tcsetpgrp(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003326{
3327 PyObject *return_value = NULL;
3328 int fd;
3329 pid_t pgid;
3330
Sylvain74453812017-06-10 06:51:48 +02003331 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3332 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003333 goto exit;
3334 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003335 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3336
3337exit:
3338 return return_value;
3339}
3340
3341#endif /* defined(HAVE_TCSETPGRP) */
3342
3343PyDoc_STRVAR(os_open__doc__,
3344"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3345"--\n"
3346"\n"
3347"Open a file for low level IO. Returns a file descriptor (integer).\n"
3348"\n"
3349"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3350" and path should be relative; path will then be relative to that directory.\n"
3351"dir_fd may not be implemented on your platform.\n"
3352" If it is unavailable, using it will raise a NotImplementedError.");
3353
3354#define OS_OPEN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003355 {"open", (PyCFunction)os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003356
3357static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003358os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003359
3360static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003361os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003362{
3363 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003364 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3365 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003366 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3367 int flags;
3368 int mode = 511;
3369 int dir_fd = DEFAULT_DIR_FD;
3370 int _return_value;
3371
Victor Stinner3e1fad62017-01-17 01:29:01 +01003372 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003373 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003374 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003375 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003376 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003377 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003378 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003379 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003380 return_value = PyLong_FromLong((long)_return_value);
3381
3382exit:
3383 /* Cleanup for path */
3384 path_cleanup(&path);
3385
3386 return return_value;
3387}
3388
3389PyDoc_STRVAR(os_close__doc__,
3390"close($module, /, fd)\n"
3391"--\n"
3392"\n"
3393"Close a file descriptor.");
3394
3395#define OS_CLOSE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003396 {"close", (PyCFunction)os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003397
3398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003399os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003400
3401static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003402os_close(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003403{
3404 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003405 static const char * const _keywords[] = {"fd", NULL};
3406 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003407 int fd;
3408
Victor Stinner3e1fad62017-01-17 01:29:01 +01003409 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003410 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003411 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003412 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003413 return_value = os_close_impl(module, fd);
3414
3415exit:
3416 return return_value;
3417}
3418
3419PyDoc_STRVAR(os_closerange__doc__,
3420"closerange($module, fd_low, fd_high, /)\n"
3421"--\n"
3422"\n"
3423"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3424
3425#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003426 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003427
3428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003429os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003430
3431static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003432os_closerange(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003433{
3434 PyObject *return_value = NULL;
3435 int fd_low;
3436 int fd_high;
3437
Sylvain74453812017-06-10 06:51:48 +02003438 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3439 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003440 goto exit;
3441 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003442 return_value = os_closerange_impl(module, fd_low, fd_high);
3443
3444exit:
3445 return return_value;
3446}
3447
3448PyDoc_STRVAR(os_dup__doc__,
3449"dup($module, fd, /)\n"
3450"--\n"
3451"\n"
3452"Return a duplicate of a file descriptor.");
3453
3454#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003455 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003456
3457static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003458os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003459
3460static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003461os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003462{
3463 PyObject *return_value = NULL;
3464 int fd;
3465 int _return_value;
3466
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003467 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003468 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003469 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003470 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003471 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003472 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003473 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003474 return_value = PyLong_FromLong((long)_return_value);
3475
3476exit:
3477 return return_value;
3478}
3479
3480PyDoc_STRVAR(os_dup2__doc__,
3481"dup2($module, /, fd, fd2, inheritable=True)\n"
3482"--\n"
3483"\n"
3484"Duplicate file descriptor.");
3485
3486#define OS_DUP2_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003487 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003488
3489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003490os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003491
3492static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003493os_dup2(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003494{
3495 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003496 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3497 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003498 int fd;
3499 int fd2;
3500 int inheritable = 1;
3501
Victor Stinner3e1fad62017-01-17 01:29:01 +01003502 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003503 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003504 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003505 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003506 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3507
3508exit:
3509 return return_value;
3510}
3511
3512#if defined(HAVE_LOCKF)
3513
3514PyDoc_STRVAR(os_lockf__doc__,
3515"lockf($module, fd, command, length, /)\n"
3516"--\n"
3517"\n"
3518"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3519"\n"
3520" fd\n"
3521" An open file descriptor.\n"
3522" command\n"
3523" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3524" length\n"
3525" The number of bytes to lock, starting at the current position.");
3526
3527#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003528 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003529
3530static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003531os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003532
3533static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003534os_lockf(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003535{
3536 PyObject *return_value = NULL;
3537 int fd;
3538 int command;
3539 Py_off_t length;
3540
Sylvain74453812017-06-10 06:51:48 +02003541 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3542 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003543 goto exit;
3544 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003545 return_value = os_lockf_impl(module, fd, command, length);
3546
3547exit:
3548 return return_value;
3549}
3550
3551#endif /* defined(HAVE_LOCKF) */
3552
3553PyDoc_STRVAR(os_lseek__doc__,
3554"lseek($module, fd, position, how, /)\n"
3555"--\n"
3556"\n"
3557"Set the position of a file descriptor. Return the new position.\n"
3558"\n"
3559"Return the new cursor position in number of bytes\n"
3560"relative to the beginning of the file.");
3561
3562#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003563 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003564
3565static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003566os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003567
3568static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003569os_lseek(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003570{
3571 PyObject *return_value = NULL;
3572 int fd;
3573 Py_off_t position;
3574 int how;
3575 Py_off_t _return_value;
3576
Sylvain74453812017-06-10 06:51:48 +02003577 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3578 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003579 goto exit;
3580 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003581 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003582 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003583 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003584 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003585 return_value = PyLong_FromPy_off_t(_return_value);
3586
3587exit:
3588 return return_value;
3589}
3590
3591PyDoc_STRVAR(os_read__doc__,
3592"read($module, fd, length, /)\n"
3593"--\n"
3594"\n"
3595"Read from a file descriptor. Returns a bytes object.");
3596
3597#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003598 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003599
3600static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003601os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003602
3603static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003604os_read(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003605{
3606 PyObject *return_value = NULL;
3607 int fd;
3608 Py_ssize_t length;
3609
Sylvain74453812017-06-10 06:51:48 +02003610 if (!_PyArg_ParseStack(args, nargs, "in:read",
3611 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003612 goto exit;
3613 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003614 return_value = os_read_impl(module, fd, length);
3615
3616exit:
3617 return return_value;
3618}
3619
3620#if defined(HAVE_READV)
3621
3622PyDoc_STRVAR(os_readv__doc__,
3623"readv($module, fd, buffers, /)\n"
3624"--\n"
3625"\n"
3626"Read from a file descriptor fd into an iterable of buffers.\n"
3627"\n"
3628"The buffers should be mutable buffers accepting bytes.\n"
3629"readv will transfer data into each buffer until it is full\n"
3630"and then move on to the next buffer in the sequence to hold\n"
3631"the rest of the data.\n"
3632"\n"
3633"readv returns the total number of bytes read,\n"
3634"which may be less than the total capacity of all the buffers.");
3635
3636#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003637 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003638
3639static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003640os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003641
3642static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003643os_readv(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003644{
3645 PyObject *return_value = NULL;
3646 int fd;
3647 PyObject *buffers;
3648 Py_ssize_t _return_value;
3649
Sylvain74453812017-06-10 06:51:48 +02003650 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3651 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003652 goto exit;
3653 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003654 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003655 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003656 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003657 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003658 return_value = PyLong_FromSsize_t(_return_value);
3659
3660exit:
3661 return return_value;
3662}
3663
3664#endif /* defined(HAVE_READV) */
3665
3666#if defined(HAVE_PREAD)
3667
3668PyDoc_STRVAR(os_pread__doc__,
3669"pread($module, fd, length, offset, /)\n"
3670"--\n"
3671"\n"
3672"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3673"\n"
3674"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3675"the beginning of the file. The file offset remains unchanged.");
3676
3677#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003678 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003679
3680static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003681os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003682
3683static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003684os_pread(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003685{
3686 PyObject *return_value = NULL;
3687 int fd;
3688 int length;
3689 Py_off_t offset;
3690
Sylvain74453812017-06-10 06:51:48 +02003691 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3692 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003693 goto exit;
3694 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003695 return_value = os_pread_impl(module, fd, length, offset);
3696
3697exit:
3698 return return_value;
3699}
3700
3701#endif /* defined(HAVE_PREAD) */
3702
3703PyDoc_STRVAR(os_write__doc__,
3704"write($module, fd, data, /)\n"
3705"--\n"
3706"\n"
3707"Write a bytes object to a file descriptor.");
3708
3709#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003710 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003711
3712static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003713os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003714
3715static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003716os_write(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003717{
3718 PyObject *return_value = NULL;
3719 int fd;
3720 Py_buffer data = {NULL, NULL};
3721 Py_ssize_t _return_value;
3722
Sylvain74453812017-06-10 06:51:48 +02003723 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3724 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003725 goto exit;
3726 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003727 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003728 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003729 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003730 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003731 return_value = PyLong_FromSsize_t(_return_value);
3732
3733exit:
3734 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003735 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003736 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003737 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003738
3739 return return_value;
3740}
3741
3742PyDoc_STRVAR(os_fstat__doc__,
3743"fstat($module, /, fd)\n"
3744"--\n"
3745"\n"
3746"Perform a stat system call on the given file descriptor.\n"
3747"\n"
3748"Like stat(), but for an open file descriptor.\n"
3749"Equivalent to os.stat(fd).");
3750
3751#define OS_FSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003752 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003753
3754static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003755os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003756
3757static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003758os_fstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003759{
3760 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003761 static const char * const _keywords[] = {"fd", NULL};
3762 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003763 int fd;
3764
Victor Stinner3e1fad62017-01-17 01:29:01 +01003765 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003766 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003767 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003768 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003769 return_value = os_fstat_impl(module, fd);
3770
3771exit:
3772 return return_value;
3773}
3774
3775PyDoc_STRVAR(os_isatty__doc__,
3776"isatty($module, fd, /)\n"
3777"--\n"
3778"\n"
3779"Return True if the fd is connected to a terminal.\n"
3780"\n"
3781"Return True if the file descriptor is an open file descriptor\n"
3782"connected to the slave end of a terminal.");
3783
3784#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003785 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003786
3787static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003788os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003789
3790static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003791os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003792{
3793 PyObject *return_value = NULL;
3794 int fd;
3795 int _return_value;
3796
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003797 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003798 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003799 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003800 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003801 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003802 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003803 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003804 return_value = PyBool_FromLong((long)_return_value);
3805
3806exit:
3807 return return_value;
3808}
3809
3810#if defined(HAVE_PIPE)
3811
3812PyDoc_STRVAR(os_pipe__doc__,
3813"pipe($module, /)\n"
3814"--\n"
3815"\n"
3816"Create a pipe.\n"
3817"\n"
3818"Returns a tuple of two file descriptors:\n"
3819" (read_fd, write_fd)");
3820
3821#define OS_PIPE_METHODDEF \
3822 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3823
3824static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003825os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003826
3827static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003828os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003829{
3830 return os_pipe_impl(module);
3831}
3832
3833#endif /* defined(HAVE_PIPE) */
3834
3835#if defined(HAVE_PIPE2)
3836
3837PyDoc_STRVAR(os_pipe2__doc__,
3838"pipe2($module, flags, /)\n"
3839"--\n"
3840"\n"
3841"Create a pipe with flags set atomically.\n"
3842"\n"
3843"Returns a tuple of two file descriptors:\n"
3844" (read_fd, write_fd)\n"
3845"\n"
3846"flags can be constructed by ORing together one or more of these values:\n"
3847"O_NONBLOCK, O_CLOEXEC.");
3848
3849#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003850 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003851
3852static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003853os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003854
3855static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003856os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003857{
3858 PyObject *return_value = NULL;
3859 int flags;
3860
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003861 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003862 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003863 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003864 return_value = os_pipe2_impl(module, flags);
3865
3866exit:
3867 return return_value;
3868}
3869
3870#endif /* defined(HAVE_PIPE2) */
3871
3872#if defined(HAVE_WRITEV)
3873
3874PyDoc_STRVAR(os_writev__doc__,
3875"writev($module, fd, buffers, /)\n"
3876"--\n"
3877"\n"
3878"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3879"\n"
3880"Returns the total number of bytes written.\n"
3881"buffers must be a sequence of bytes-like objects.");
3882
3883#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003884 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003885
3886static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003887os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003888
3889static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003890os_writev(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003891{
3892 PyObject *return_value = NULL;
3893 int fd;
3894 PyObject *buffers;
3895 Py_ssize_t _return_value;
3896
Sylvain74453812017-06-10 06:51:48 +02003897 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
3898 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003899 goto exit;
3900 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003901 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003902 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003903 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003904 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003905 return_value = PyLong_FromSsize_t(_return_value);
3906
3907exit:
3908 return return_value;
3909}
3910
3911#endif /* defined(HAVE_WRITEV) */
3912
3913#if defined(HAVE_PWRITE)
3914
3915PyDoc_STRVAR(os_pwrite__doc__,
3916"pwrite($module, fd, buffer, offset, /)\n"
3917"--\n"
3918"\n"
3919"Write bytes to a file descriptor starting at a particular offset.\n"
3920"\n"
3921"Write buffer to fd, starting at offset bytes from the beginning of\n"
3922"the file. Returns the number of bytes writte. Does not change the\n"
3923"current file offset.");
3924
3925#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003926 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003927
3928static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003929os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003930
3931static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003932os_pwrite(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003933{
3934 PyObject *return_value = NULL;
3935 int fd;
3936 Py_buffer buffer = {NULL, NULL};
3937 Py_off_t offset;
3938 Py_ssize_t _return_value;
3939
Sylvain74453812017-06-10 06:51:48 +02003940 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
3941 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003942 goto exit;
3943 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003944 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003945 if ((_return_value == -1) && PyErr_Occurred()) {
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 = PyLong_FromSsize_t(_return_value);
3949
3950exit:
3951 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003952 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003953 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003954 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003955
3956 return return_value;
3957}
3958
3959#endif /* defined(HAVE_PWRITE) */
3960
3961#if defined(HAVE_MKFIFO)
3962
3963PyDoc_STRVAR(os_mkfifo__doc__,
3964"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
3965"--\n"
3966"\n"
3967"Create a \"fifo\" (a POSIX named pipe).\n"
3968"\n"
3969"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3970" and path should be relative; path will then be relative to that directory.\n"
3971"dir_fd may not be implemented on your platform.\n"
3972" If it is unavailable, using it will raise a NotImplementedError.");
3973
3974#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003975 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003976
3977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003978os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003979
3980static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003981os_mkfifo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003982{
3983 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003984 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
3985 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003986 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
3987 int mode = 438;
3988 int dir_fd = DEFAULT_DIR_FD;
3989
Victor Stinner3e1fad62017-01-17 01:29:01 +01003990 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003991 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003992 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003993 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003994 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
3995
3996exit:
3997 /* Cleanup for path */
3998 path_cleanup(&path);
3999
4000 return return_value;
4001}
4002
4003#endif /* defined(HAVE_MKFIFO) */
4004
4005#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4006
4007PyDoc_STRVAR(os_mknod__doc__,
4008"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4009"--\n"
4010"\n"
4011"Create a node in the file system.\n"
4012"\n"
4013"Create a node in the file system (file, device special file or named pipe)\n"
4014"at path. mode specifies both the permissions to use and the\n"
4015"type of node to be created, being combined (bitwise OR) with one of\n"
4016"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4017"device defines the newly created device special file (probably using\n"
4018"os.makedev()). Otherwise device is ignored.\n"
4019"\n"
4020"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4021" and path should be relative; path will then be relative to that directory.\n"
4022"dir_fd may not be implemented on your platform.\n"
4023" If it is unavailable, using it will raise a NotImplementedError.");
4024
4025#define OS_MKNOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004026 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004027
4028static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004029os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004030 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004031
4032static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004033os_mknod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004034{
4035 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004036 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4037 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004038 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4039 int mode = 384;
4040 dev_t device = 0;
4041 int dir_fd = DEFAULT_DIR_FD;
4042
Victor Stinner3e1fad62017-01-17 01:29:01 +01004043 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004044 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004045 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004046 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004047 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4048
4049exit:
4050 /* Cleanup for path */
4051 path_cleanup(&path);
4052
4053 return return_value;
4054}
4055
4056#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4057
4058#if defined(HAVE_DEVICE_MACROS)
4059
4060PyDoc_STRVAR(os_major__doc__,
4061"major($module, device, /)\n"
4062"--\n"
4063"\n"
4064"Extracts a device major number from a raw device number.");
4065
4066#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004067 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004068
4069static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004070os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004071
4072static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004073os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004074{
4075 PyObject *return_value = NULL;
4076 dev_t device;
4077 unsigned int _return_value;
4078
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004079 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004080 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004081 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004082 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004083 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004084 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004085 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004086 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4087
4088exit:
4089 return return_value;
4090}
4091
4092#endif /* defined(HAVE_DEVICE_MACROS) */
4093
4094#if defined(HAVE_DEVICE_MACROS)
4095
4096PyDoc_STRVAR(os_minor__doc__,
4097"minor($module, device, /)\n"
4098"--\n"
4099"\n"
4100"Extracts a device minor number from a raw device number.");
4101
4102#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004103 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004104
4105static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004106os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004107
4108static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004109os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004110{
4111 PyObject *return_value = NULL;
4112 dev_t device;
4113 unsigned int _return_value;
4114
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004115 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004116 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004117 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004118 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004119 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004120 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004121 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004122 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4123
4124exit:
4125 return return_value;
4126}
4127
4128#endif /* defined(HAVE_DEVICE_MACROS) */
4129
4130#if defined(HAVE_DEVICE_MACROS)
4131
4132PyDoc_STRVAR(os_makedev__doc__,
4133"makedev($module, major, minor, /)\n"
4134"--\n"
4135"\n"
4136"Composes a raw device number from the major and minor device numbers.");
4137
4138#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004139 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004140
4141static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004142os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004143
4144static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004145os_makedev(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004146{
4147 PyObject *return_value = NULL;
4148 int major;
4149 int minor;
4150 dev_t _return_value;
4151
Sylvain74453812017-06-10 06:51:48 +02004152 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4153 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004154 goto exit;
4155 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004156 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004157 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004158 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004159 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004160 return_value = _PyLong_FromDev(_return_value);
4161
4162exit:
4163 return return_value;
4164}
4165
4166#endif /* defined(HAVE_DEVICE_MACROS) */
4167
Steve Dowerf7377032015-04-12 15:44:54 -04004168#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004169
4170PyDoc_STRVAR(os_ftruncate__doc__,
4171"ftruncate($module, fd, length, /)\n"
4172"--\n"
4173"\n"
4174"Truncate a file, specified by file descriptor, to a specific length.");
4175
4176#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004177 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004178
4179static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004180os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004181
4182static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004183os_ftruncate(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004184{
4185 PyObject *return_value = NULL;
4186 int fd;
4187 Py_off_t length;
4188
Sylvain74453812017-06-10 06:51:48 +02004189 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4190 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004191 goto exit;
4192 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004193 return_value = os_ftruncate_impl(module, fd, length);
4194
4195exit:
4196 return return_value;
4197}
4198
Steve Dowerf7377032015-04-12 15:44:54 -04004199#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004200
Steve Dowerf7377032015-04-12 15:44:54 -04004201#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004202
4203PyDoc_STRVAR(os_truncate__doc__,
4204"truncate($module, /, path, length)\n"
4205"--\n"
4206"\n"
4207"Truncate a file, specified by path, to a specific length.\n"
4208"\n"
4209"On some platforms, path may also be specified as an open file descriptor.\n"
4210" If this functionality is unavailable, using it raises an exception.");
4211
4212#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004213 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004214
4215static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004216os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004217
4218static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004219os_truncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004220{
4221 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004222 static const char * const _keywords[] = {"path", "length", NULL};
4223 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004224 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4225 Py_off_t length;
4226
Victor Stinner3e1fad62017-01-17 01:29:01 +01004227 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004228 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004229 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004230 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004231 return_value = os_truncate_impl(module, &path, length);
4232
4233exit:
4234 /* Cleanup for path */
4235 path_cleanup(&path);
4236
4237 return return_value;
4238}
4239
Steve Dowerf7377032015-04-12 15:44:54 -04004240#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004241
4242#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4243
4244PyDoc_STRVAR(os_posix_fallocate__doc__,
4245"posix_fallocate($module, fd, offset, length, /)\n"
4246"--\n"
4247"\n"
4248"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4249"\n"
4250"Ensure that the file specified by fd encompasses a range of bytes\n"
4251"starting at offset bytes from the beginning and continuing for length bytes.");
4252
4253#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004254 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004255
4256static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004257os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004258 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004259
4260static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004261os_posix_fallocate(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004262{
4263 PyObject *return_value = NULL;
4264 int fd;
4265 Py_off_t offset;
4266 Py_off_t length;
4267
Sylvain74453812017-06-10 06:51:48 +02004268 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4269 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004270 goto exit;
4271 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004272 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4273
4274exit:
4275 return return_value;
4276}
4277
4278#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4279
4280#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4281
4282PyDoc_STRVAR(os_posix_fadvise__doc__,
4283"posix_fadvise($module, fd, offset, length, advice, /)\n"
4284"--\n"
4285"\n"
4286"Announce an intention to access data in a specific pattern.\n"
4287"\n"
4288"Announce an intention to access data in a specific pattern, thus allowing\n"
4289"the kernel to make optimizations.\n"
4290"The advice applies to the region of the file specified by fd starting at\n"
4291"offset and continuing for length bytes.\n"
4292"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4293"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4294"POSIX_FADV_DONTNEED.");
4295
4296#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004297 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004298
4299static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004300os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004301 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004302
4303static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004304os_posix_fadvise(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004305{
4306 PyObject *return_value = NULL;
4307 int fd;
4308 Py_off_t offset;
4309 Py_off_t length;
4310 int advice;
4311
Sylvain74453812017-06-10 06:51:48 +02004312 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4313 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004314 goto exit;
4315 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004316 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4317
4318exit:
4319 return return_value;
4320}
4321
4322#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4323
4324#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4325
4326PyDoc_STRVAR(os_putenv__doc__,
4327"putenv($module, name, value, /)\n"
4328"--\n"
4329"\n"
4330"Change or add an environment variable.");
4331
4332#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004333 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004334
4335static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004336os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004337
4338static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004339os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004340{
4341 PyObject *return_value = NULL;
4342 PyObject *name;
4343 PyObject *value;
4344
Sylvain74453812017-06-10 06:51:48 +02004345 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4346 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004347 goto exit;
4348 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004349 return_value = os_putenv_impl(module, name, value);
4350
4351exit:
4352 return return_value;
4353}
4354
4355#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4356
4357#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4358
4359PyDoc_STRVAR(os_putenv__doc__,
4360"putenv($module, name, value, /)\n"
4361"--\n"
4362"\n"
4363"Change or add an environment variable.");
4364
4365#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004366 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004367
4368static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004369os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004370
4371static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004372os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004373{
4374 PyObject *return_value = NULL;
4375 PyObject *name = NULL;
4376 PyObject *value = NULL;
4377
Sylvain74453812017-06-10 06:51:48 +02004378 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4379 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004380 goto exit;
4381 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004382 return_value = os_putenv_impl(module, name, value);
4383
4384exit:
4385 /* Cleanup for name */
4386 Py_XDECREF(name);
4387 /* Cleanup for value */
4388 Py_XDECREF(value);
4389
4390 return return_value;
4391}
4392
4393#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4394
4395#if defined(HAVE_UNSETENV)
4396
4397PyDoc_STRVAR(os_unsetenv__doc__,
4398"unsetenv($module, name, /)\n"
4399"--\n"
4400"\n"
4401"Delete an environment variable.");
4402
4403#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004404 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004405
4406static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004407os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004408
4409static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004410os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004411{
4412 PyObject *return_value = NULL;
4413 PyObject *name = NULL;
4414
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004415 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004416 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004417 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004418 return_value = os_unsetenv_impl(module, name);
4419
4420exit:
4421 /* Cleanup for name */
4422 Py_XDECREF(name);
4423
4424 return return_value;
4425}
4426
4427#endif /* defined(HAVE_UNSETENV) */
4428
4429PyDoc_STRVAR(os_strerror__doc__,
4430"strerror($module, code, /)\n"
4431"--\n"
4432"\n"
4433"Translate an error code to a message string.");
4434
4435#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004436 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004437
4438static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004439os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004440
4441static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004442os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004443{
4444 PyObject *return_value = NULL;
4445 int code;
4446
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004447 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004448 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004449 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004450 return_value = os_strerror_impl(module, code);
4451
4452exit:
4453 return return_value;
4454}
4455
4456#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4457
4458PyDoc_STRVAR(os_WCOREDUMP__doc__,
4459"WCOREDUMP($module, status, /)\n"
4460"--\n"
4461"\n"
4462"Return True if the process returning status was dumped to a core file.");
4463
4464#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004465 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004466
4467static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004468os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004469
4470static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004471os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004472{
4473 PyObject *return_value = NULL;
4474 int status;
4475 int _return_value;
4476
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004477 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004478 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004479 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004480 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004481 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004482 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004483 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004484 return_value = PyBool_FromLong((long)_return_value);
4485
4486exit:
4487 return return_value;
4488}
4489
4490#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4491
4492#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4493
4494PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4495"WIFCONTINUED($module, /, status)\n"
4496"--\n"
4497"\n"
4498"Return True if a particular process was continued from a job control stop.\n"
4499"\n"
4500"Return True if the process returning status was continued from a\n"
4501"job control stop.");
4502
4503#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004504 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004505
4506static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004507os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004508
4509static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004510os_WIFCONTINUED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004511{
4512 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004513 static const char * const _keywords[] = {"status", NULL};
4514 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004515 int status;
4516 int _return_value;
4517
Victor Stinner3e1fad62017-01-17 01:29:01 +01004518 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004519 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004520 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004521 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004522 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004523 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004524 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004525 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004526 return_value = PyBool_FromLong((long)_return_value);
4527
4528exit:
4529 return return_value;
4530}
4531
4532#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4533
4534#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4535
4536PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4537"WIFSTOPPED($module, /, status)\n"
4538"--\n"
4539"\n"
4540"Return True if the process returning status was stopped.");
4541
4542#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004543 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004544
4545static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004546os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004547
4548static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004549os_WIFSTOPPED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004550{
4551 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004552 static const char * const _keywords[] = {"status", NULL};
4553 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004554 int status;
4555 int _return_value;
4556
Victor Stinner3e1fad62017-01-17 01:29:01 +01004557 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004558 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004559 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004560 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004561 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004562 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004563 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004564 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004565 return_value = PyBool_FromLong((long)_return_value);
4566
4567exit:
4568 return return_value;
4569}
4570
4571#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4572
4573#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4574
4575PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4576"WIFSIGNALED($module, /, status)\n"
4577"--\n"
4578"\n"
4579"Return True if the process returning status was terminated by a signal.");
4580
4581#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004582 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004583
4584static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004585os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004586
4587static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004588os_WIFSIGNALED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004589{
4590 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004591 static const char * const _keywords[] = {"status", NULL};
4592 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004593 int status;
4594 int _return_value;
4595
Victor Stinner3e1fad62017-01-17 01:29:01 +01004596 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004597 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004598 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004599 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004600 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004601 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004602 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004604 return_value = PyBool_FromLong((long)_return_value);
4605
4606exit:
4607 return return_value;
4608}
4609
4610#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4611
4612#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4613
4614PyDoc_STRVAR(os_WIFEXITED__doc__,
4615"WIFEXITED($module, /, status)\n"
4616"--\n"
4617"\n"
4618"Return True if the process returning status exited via the exit() system call.");
4619
4620#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004621 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004622
4623static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004624os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004625
4626static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004627os_WIFEXITED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004628{
4629 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004630 static const char * const _keywords[] = {"status", NULL};
4631 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004632 int status;
4633 int _return_value;
4634
Victor Stinner3e1fad62017-01-17 01:29:01 +01004635 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004636 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004637 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004638 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004639 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004640 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004641 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004642 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004643 return_value = PyBool_FromLong((long)_return_value);
4644
4645exit:
4646 return return_value;
4647}
4648
4649#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4650
4651#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4652
4653PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4654"WEXITSTATUS($module, /, status)\n"
4655"--\n"
4656"\n"
4657"Return the process return code from status.");
4658
4659#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004660 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004661
4662static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004663os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004664
4665static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004666os_WEXITSTATUS(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004667{
4668 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004669 static const char * const _keywords[] = {"status", NULL};
4670 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004671 int status;
4672 int _return_value;
4673
Victor Stinner3e1fad62017-01-17 01:29:01 +01004674 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004675 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004676 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004677 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004678 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004679 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004680 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004681 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004682 return_value = PyLong_FromLong((long)_return_value);
4683
4684exit:
4685 return return_value;
4686}
4687
4688#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4689
4690#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4691
4692PyDoc_STRVAR(os_WTERMSIG__doc__,
4693"WTERMSIG($module, /, status)\n"
4694"--\n"
4695"\n"
4696"Return the signal that terminated the process that provided the status value.");
4697
4698#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004699 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004700
4701static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004702os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004703
4704static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004705os_WTERMSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004706{
4707 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004708 static const char * const _keywords[] = {"status", NULL};
4709 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004710 int status;
4711 int _return_value;
4712
Victor Stinner3e1fad62017-01-17 01:29:01 +01004713 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004714 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004715 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004716 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004717 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004718 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004719 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004720 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004721 return_value = PyLong_FromLong((long)_return_value);
4722
4723exit:
4724 return return_value;
4725}
4726
4727#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4728
4729#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4730
4731PyDoc_STRVAR(os_WSTOPSIG__doc__,
4732"WSTOPSIG($module, /, status)\n"
4733"--\n"
4734"\n"
4735"Return the signal that stopped the process that provided the status value.");
4736
4737#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004738 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004739
4740static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004741os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004742
4743static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004744os_WSTOPSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004745{
4746 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004747 static const char * const _keywords[] = {"status", NULL};
4748 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004749 int status;
4750 int _return_value;
4751
Victor Stinner3e1fad62017-01-17 01:29:01 +01004752 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004753 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004754 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004755 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004756 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004757 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004758 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004759 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004760 return_value = PyLong_FromLong((long)_return_value);
4761
4762exit:
4763 return return_value;
4764}
4765
4766#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4767
4768#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4769
4770PyDoc_STRVAR(os_fstatvfs__doc__,
4771"fstatvfs($module, fd, /)\n"
4772"--\n"
4773"\n"
4774"Perform an fstatvfs system call on the given fd.\n"
4775"\n"
4776"Equivalent to statvfs(fd).");
4777
4778#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004779 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004780
4781static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004782os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004783
4784static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004785os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004786{
4787 PyObject *return_value = NULL;
4788 int fd;
4789
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004790 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004791 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004792 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004793 return_value = os_fstatvfs_impl(module, fd);
4794
4795exit:
4796 return return_value;
4797}
4798
4799#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4800
4801#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4802
4803PyDoc_STRVAR(os_statvfs__doc__,
4804"statvfs($module, /, path)\n"
4805"--\n"
4806"\n"
4807"Perform a statvfs system call on the given path.\n"
4808"\n"
4809"path may always be specified as a string.\n"
4810"On some platforms, path may also be specified as an open file descriptor.\n"
4811" If this functionality is unavailable, using it raises an exception.");
4812
4813#define OS_STATVFS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004814 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004815
4816static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004817os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004818
4819static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004820os_statvfs(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004821{
4822 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004823 static const char * const _keywords[] = {"path", NULL};
4824 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004825 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4826
Victor Stinner3e1fad62017-01-17 01:29:01 +01004827 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004828 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004829 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004830 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004831 return_value = os_statvfs_impl(module, &path);
4832
4833exit:
4834 /* Cleanup for path */
4835 path_cleanup(&path);
4836
4837 return return_value;
4838}
4839
4840#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4841
4842#if defined(MS_WINDOWS)
4843
4844PyDoc_STRVAR(os__getdiskusage__doc__,
4845"_getdiskusage($module, /, path)\n"
4846"--\n"
4847"\n"
4848"Return disk usage statistics about the given path as a (total, free) tuple.");
4849
4850#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004851 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004852
4853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004854os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004855
4856static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004857os__getdiskusage(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004858{
4859 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004860 static const char * const _keywords[] = {"path", NULL};
4861 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004862 Py_UNICODE *path;
4863
Victor Stinner3e1fad62017-01-17 01:29:01 +01004864 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004865 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004866 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004867 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004868 return_value = os__getdiskusage_impl(module, path);
4869
4870exit:
4871 return return_value;
4872}
4873
4874#endif /* defined(MS_WINDOWS) */
4875
4876#if defined(HAVE_FPATHCONF)
4877
4878PyDoc_STRVAR(os_fpathconf__doc__,
4879"fpathconf($module, fd, name, /)\n"
4880"--\n"
4881"\n"
4882"Return the configuration limit name for the file descriptor fd.\n"
4883"\n"
4884"If there is no limit, return -1.");
4885
4886#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004887 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004888
4889static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004890os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004891
4892static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004893os_fpathconf(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004894{
4895 PyObject *return_value = NULL;
4896 int fd;
4897 int name;
4898 long _return_value;
4899
Sylvain74453812017-06-10 06:51:48 +02004900 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
4901 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004902 goto exit;
4903 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004904 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004905 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004906 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004907 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004908 return_value = PyLong_FromLong(_return_value);
4909
4910exit:
4911 return return_value;
4912}
4913
4914#endif /* defined(HAVE_FPATHCONF) */
4915
4916#if defined(HAVE_PATHCONF)
4917
4918PyDoc_STRVAR(os_pathconf__doc__,
4919"pathconf($module, /, path, name)\n"
4920"--\n"
4921"\n"
4922"Return the configuration limit name for the file or directory path.\n"
4923"\n"
4924"If there is no limit, return -1.\n"
4925"On some platforms, path may also be specified as an open file descriptor.\n"
4926" If this functionality is unavailable, using it raises an exception.");
4927
4928#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004929 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004930
4931static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004932os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004933
4934static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004935os_pathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004936{
4937 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004938 static const char * const _keywords[] = {"path", "name", NULL};
4939 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004940 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
4941 int name;
4942 long _return_value;
4943
Victor Stinner3e1fad62017-01-17 01:29:01 +01004944 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004945 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004946 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004947 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004948 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004949 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004951 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004952 return_value = PyLong_FromLong(_return_value);
4953
4954exit:
4955 /* Cleanup for path */
4956 path_cleanup(&path);
4957
4958 return return_value;
4959}
4960
4961#endif /* defined(HAVE_PATHCONF) */
4962
4963#if defined(HAVE_CONFSTR)
4964
4965PyDoc_STRVAR(os_confstr__doc__,
4966"confstr($module, name, /)\n"
4967"--\n"
4968"\n"
4969"Return a string-valued system configuration variable.");
4970
4971#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004972 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004973
4974static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004975os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004976
4977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004978os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004979{
4980 PyObject *return_value = NULL;
4981 int name;
4982
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004983 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004985 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004986 return_value = os_confstr_impl(module, name);
4987
4988exit:
4989 return return_value;
4990}
4991
4992#endif /* defined(HAVE_CONFSTR) */
4993
4994#if defined(HAVE_SYSCONF)
4995
4996PyDoc_STRVAR(os_sysconf__doc__,
4997"sysconf($module, name, /)\n"
4998"--\n"
4999"\n"
5000"Return an integer-valued system configuration variable.");
5001
5002#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005003 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005004
5005static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005006os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005007
5008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005009os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005010{
5011 PyObject *return_value = NULL;
5012 int name;
5013 long _return_value;
5014
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005015 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005016 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005017 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005018 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005019 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005020 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005021 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005022 return_value = PyLong_FromLong(_return_value);
5023
5024exit:
5025 return return_value;
5026}
5027
5028#endif /* defined(HAVE_SYSCONF) */
5029
5030PyDoc_STRVAR(os_abort__doc__,
5031"abort($module, /)\n"
5032"--\n"
5033"\n"
5034"Abort the interpreter immediately.\n"
5035"\n"
5036"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5037"on the hosting operating system. This function never returns.");
5038
5039#define OS_ABORT_METHODDEF \
5040 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5041
5042static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005043os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005044
5045static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005046os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005047{
5048 return os_abort_impl(module);
5049}
5050
Steve Dowercc16be82016-09-08 10:35:16 -07005051#if defined(MS_WINDOWS)
5052
5053PyDoc_STRVAR(os_startfile__doc__,
5054"startfile($module, /, filepath, operation=None)\n"
5055"--\n"
5056"\n"
5057"startfile(filepath [, operation])\n"
5058"\n"
5059"Start a file with its associated application.\n"
5060"\n"
5061"When \"operation\" is not specified or \"open\", this acts like\n"
5062"double-clicking the file in Explorer, or giving the file name as an\n"
5063"argument to the DOS \"start\" command: the file is opened with whatever\n"
5064"application (if any) its extension is associated.\n"
5065"When another \"operation\" is given, it specifies what should be done with\n"
5066"the file. A typical operation is \"print\".\n"
5067"\n"
5068"startfile returns as soon as the associated application is launched.\n"
5069"There is no option to wait for the application to close, and no way\n"
5070"to retrieve the application\'s exit status.\n"
5071"\n"
5072"The filepath is relative to the current directory. If you want to use\n"
5073"an absolute path, make sure the first character is not a slash (\"/\");\n"
5074"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5075
5076#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005077 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005078
5079static PyObject *
5080os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5081
5082static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005083os_startfile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005084{
5085 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005086 static const char * const _keywords[] = {"filepath", "operation", NULL};
5087 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005088 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5089 Py_UNICODE *operation = NULL;
5090
Victor Stinner3e1fad62017-01-17 01:29:01 +01005091 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005092 path_converter, &filepath, &operation)) {
5093 goto exit;
5094 }
5095 return_value = os_startfile_impl(module, &filepath, operation);
5096
5097exit:
5098 /* Cleanup for filepath */
5099 path_cleanup(&filepath);
5100
5101 return return_value;
5102}
5103
5104#endif /* defined(MS_WINDOWS) */
5105
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005106#if defined(HAVE_GETLOADAVG)
5107
5108PyDoc_STRVAR(os_getloadavg__doc__,
5109"getloadavg($module, /)\n"
5110"--\n"
5111"\n"
5112"Return average recent system load information.\n"
5113"\n"
5114"Return the number of processes in the system run queue averaged over\n"
5115"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5116"Raises OSError if the load average was unobtainable.");
5117
5118#define OS_GETLOADAVG_METHODDEF \
5119 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5120
5121static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005122os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005123
5124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005125os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005126{
5127 return os_getloadavg_impl(module);
5128}
5129
5130#endif /* defined(HAVE_GETLOADAVG) */
5131
5132PyDoc_STRVAR(os_device_encoding__doc__,
5133"device_encoding($module, /, fd)\n"
5134"--\n"
5135"\n"
5136"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5137"\n"
5138"The file descriptor must be attached to a terminal.\n"
5139"If the device is not a terminal, return None.");
5140
5141#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005142 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005143
5144static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005145os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005146
5147static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005148os_device_encoding(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005149{
5150 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005151 static const char * const _keywords[] = {"fd", NULL};
5152 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005153 int fd;
5154
Victor Stinner3e1fad62017-01-17 01:29:01 +01005155 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005156 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005157 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005158 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005159 return_value = os_device_encoding_impl(module, fd);
5160
5161exit:
5162 return return_value;
5163}
5164
5165#if defined(HAVE_SETRESUID)
5166
5167PyDoc_STRVAR(os_setresuid__doc__,
5168"setresuid($module, ruid, euid, suid, /)\n"
5169"--\n"
5170"\n"
5171"Set the current process\'s real, effective, and saved user ids.");
5172
5173#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005174 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005175
5176static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005177os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005178
5179static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005180os_setresuid(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005181{
5182 PyObject *return_value = NULL;
5183 uid_t ruid;
5184 uid_t euid;
5185 uid_t suid;
5186
Sylvain74453812017-06-10 06:51:48 +02005187 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5188 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005189 goto exit;
5190 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005191 return_value = os_setresuid_impl(module, ruid, euid, suid);
5192
5193exit:
5194 return return_value;
5195}
5196
5197#endif /* defined(HAVE_SETRESUID) */
5198
5199#if defined(HAVE_SETRESGID)
5200
5201PyDoc_STRVAR(os_setresgid__doc__,
5202"setresgid($module, rgid, egid, sgid, /)\n"
5203"--\n"
5204"\n"
5205"Set the current process\'s real, effective, and saved group ids.");
5206
5207#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005208 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005209
5210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005211os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005212
5213static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005214os_setresgid(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005215{
5216 PyObject *return_value = NULL;
5217 gid_t rgid;
5218 gid_t egid;
5219 gid_t sgid;
5220
Sylvain74453812017-06-10 06:51:48 +02005221 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5222 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005223 goto exit;
5224 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005225 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5226
5227exit:
5228 return return_value;
5229}
5230
5231#endif /* defined(HAVE_SETRESGID) */
5232
5233#if defined(HAVE_GETRESUID)
5234
5235PyDoc_STRVAR(os_getresuid__doc__,
5236"getresuid($module, /)\n"
5237"--\n"
5238"\n"
5239"Return a tuple of the current process\'s real, effective, and saved user ids.");
5240
5241#define OS_GETRESUID_METHODDEF \
5242 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5243
5244static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005245os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005246
5247static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005248os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005249{
5250 return os_getresuid_impl(module);
5251}
5252
5253#endif /* defined(HAVE_GETRESUID) */
5254
5255#if defined(HAVE_GETRESGID)
5256
5257PyDoc_STRVAR(os_getresgid__doc__,
5258"getresgid($module, /)\n"
5259"--\n"
5260"\n"
5261"Return a tuple of the current process\'s real, effective, and saved group ids.");
5262
5263#define OS_GETRESGID_METHODDEF \
5264 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5265
5266static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005267os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005268
5269static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005270os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005271{
5272 return os_getresgid_impl(module);
5273}
5274
5275#endif /* defined(HAVE_GETRESGID) */
5276
5277#if defined(USE_XATTRS)
5278
5279PyDoc_STRVAR(os_getxattr__doc__,
5280"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5281"--\n"
5282"\n"
5283"Return the value of extended attribute attribute on path.\n"
5284"\n"
5285"path may be either a string or an open file descriptor.\n"
5286"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5287" link, getxattr will examine the symbolic link itself instead of the file\n"
5288" the link points to.");
5289
5290#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005291 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005292
5293static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005294os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005295 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005296
5297static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005298os_getxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005299{
5300 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005301 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5302 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005303 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5304 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5305 int follow_symlinks = 1;
5306
Victor Stinner3e1fad62017-01-17 01:29:01 +01005307 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005308 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005309 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005310 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005311 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5312
5313exit:
5314 /* Cleanup for path */
5315 path_cleanup(&path);
5316 /* Cleanup for attribute */
5317 path_cleanup(&attribute);
5318
5319 return return_value;
5320}
5321
5322#endif /* defined(USE_XATTRS) */
5323
5324#if defined(USE_XATTRS)
5325
5326PyDoc_STRVAR(os_setxattr__doc__,
5327"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5328" follow_symlinks=True)\n"
5329"--\n"
5330"\n"
5331"Set extended attribute attribute on path to value.\n"
5332"\n"
5333"path may be either a string or an open file descriptor.\n"
5334"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5335" link, setxattr will modify the symbolic link itself instead of the file\n"
5336" the link points to.");
5337
5338#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005339 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005340
5341static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005342os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005343 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005344
5345static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005346os_setxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005347{
5348 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005349 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5350 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005351 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5352 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5353 Py_buffer value = {NULL, NULL};
5354 int flags = 0;
5355 int follow_symlinks = 1;
5356
Victor Stinner3e1fad62017-01-17 01:29:01 +01005357 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005358 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005359 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005360 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005361 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5362
5363exit:
5364 /* Cleanup for path */
5365 path_cleanup(&path);
5366 /* Cleanup for attribute */
5367 path_cleanup(&attribute);
5368 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005369 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005370 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005371 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005372
5373 return return_value;
5374}
5375
5376#endif /* defined(USE_XATTRS) */
5377
5378#if defined(USE_XATTRS)
5379
5380PyDoc_STRVAR(os_removexattr__doc__,
5381"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5382"--\n"
5383"\n"
5384"Remove extended attribute attribute on path.\n"
5385"\n"
5386"path may be either a string or an open file descriptor.\n"
5387"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5388" link, removexattr will modify the symbolic link itself instead of the file\n"
5389" the link points to.");
5390
5391#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005392 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005393
5394static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005395os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005396 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005397
5398static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005399os_removexattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005400{
5401 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005402 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5403 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005404 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5405 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5406 int follow_symlinks = 1;
5407
Victor Stinner3e1fad62017-01-17 01:29:01 +01005408 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005409 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005410 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005411 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005412 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5413
5414exit:
5415 /* Cleanup for path */
5416 path_cleanup(&path);
5417 /* Cleanup for attribute */
5418 path_cleanup(&attribute);
5419
5420 return return_value;
5421}
5422
5423#endif /* defined(USE_XATTRS) */
5424
5425#if defined(USE_XATTRS)
5426
5427PyDoc_STRVAR(os_listxattr__doc__,
5428"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5429"--\n"
5430"\n"
5431"Return a list of extended attributes on path.\n"
5432"\n"
5433"path may be either None, a string, or an open file descriptor.\n"
5434"if path is None, listxattr will examine the current directory.\n"
5435"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5436" link, listxattr will examine the symbolic link itself instead of the file\n"
5437" the link points to.");
5438
5439#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005440 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005441
5442static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005443os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005444
5445static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005446os_listxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005447{
5448 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005449 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5450 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005451 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5452 int follow_symlinks = 1;
5453
Victor Stinner3e1fad62017-01-17 01:29:01 +01005454 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005455 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005456 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005457 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005458 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5459
5460exit:
5461 /* Cleanup for path */
5462 path_cleanup(&path);
5463
5464 return return_value;
5465}
5466
5467#endif /* defined(USE_XATTRS) */
5468
5469PyDoc_STRVAR(os_urandom__doc__,
5470"urandom($module, size, /)\n"
5471"--\n"
5472"\n"
5473"Return a bytes object containing random bytes suitable for cryptographic use.");
5474
5475#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005476 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005477
5478static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005479os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005480
5481static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005482os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005483{
5484 PyObject *return_value = NULL;
5485 Py_ssize_t size;
5486
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005487 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005488 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005489 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005490 return_value = os_urandom_impl(module, size);
5491
5492exit:
5493 return return_value;
5494}
5495
5496PyDoc_STRVAR(os_cpu_count__doc__,
5497"cpu_count($module, /)\n"
5498"--\n"
5499"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005500"Return the number of CPUs in the system; return None if indeterminable.\n"
5501"\n"
5502"This number is not equivalent to the number of CPUs the current process can\n"
5503"use. The number of usable CPUs can be obtained with\n"
5504"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005505
5506#define OS_CPU_COUNT_METHODDEF \
5507 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5508
5509static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005510os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005511
5512static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005513os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005514{
5515 return os_cpu_count_impl(module);
5516}
5517
5518PyDoc_STRVAR(os_get_inheritable__doc__,
5519"get_inheritable($module, fd, /)\n"
5520"--\n"
5521"\n"
5522"Get the close-on-exe flag of the specified file descriptor.");
5523
5524#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005525 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005526
5527static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005528os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005529
5530static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005531os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005532{
5533 PyObject *return_value = NULL;
5534 int fd;
5535 int _return_value;
5536
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005537 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005538 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005539 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005540 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005541 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005542 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005543 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005544 return_value = PyBool_FromLong((long)_return_value);
5545
5546exit:
5547 return return_value;
5548}
5549
5550PyDoc_STRVAR(os_set_inheritable__doc__,
5551"set_inheritable($module, fd, inheritable, /)\n"
5552"--\n"
5553"\n"
5554"Set the inheritable flag of the specified file descriptor.");
5555
5556#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005557 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005558
5559static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005560os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005561
5562static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005563os_set_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005564{
5565 PyObject *return_value = NULL;
5566 int fd;
5567 int inheritable;
5568
Sylvain74453812017-06-10 06:51:48 +02005569 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5570 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005571 goto exit;
5572 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005573 return_value = os_set_inheritable_impl(module, fd, inheritable);
5574
5575exit:
5576 return return_value;
5577}
5578
5579#if defined(MS_WINDOWS)
5580
5581PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5582"get_handle_inheritable($module, handle, /)\n"
5583"--\n"
5584"\n"
5585"Get the close-on-exe flag of the specified file descriptor.");
5586
5587#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005588 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005589
5590static int
Victor Stinner581139c2016-09-06 15:54:20 -07005591os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005592
5593static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005594os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005595{
5596 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005597 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005598 int _return_value;
5599
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005600 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005601 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005602 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005603 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005604 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005605 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005606 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005607 return_value = PyBool_FromLong((long)_return_value);
5608
5609exit:
5610 return return_value;
5611}
5612
5613#endif /* defined(MS_WINDOWS) */
5614
5615#if defined(MS_WINDOWS)
5616
5617PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5618"set_handle_inheritable($module, handle, inheritable, /)\n"
5619"--\n"
5620"\n"
5621"Set the inheritable flag of the specified handle.");
5622
5623#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005624 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005625
5626static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005627os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005628 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005629
5630static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005631os_set_handle_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005632{
5633 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005634 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005635 int inheritable;
5636
Sylvain74453812017-06-10 06:51:48 +02005637 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5638 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005639 goto exit;
5640 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005641 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5642
5643exit:
5644 return return_value;
5645}
5646
5647#endif /* defined(MS_WINDOWS) */
5648
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005649PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5650"is_symlink($self, /)\n"
5651"--\n"
5652"\n"
5653"Return True if the entry is a symbolic link; cached per entry.");
5654
5655#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5656 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5657
5658static int
5659os_DirEntry_is_symlink_impl(DirEntry *self);
5660
5661static PyObject *
5662os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5663{
5664 PyObject *return_value = NULL;
5665 int _return_value;
5666
5667 _return_value = os_DirEntry_is_symlink_impl(self);
5668 if ((_return_value == -1) && PyErr_Occurred()) {
5669 goto exit;
5670 }
5671 return_value = PyBool_FromLong((long)_return_value);
5672
5673exit:
5674 return return_value;
5675}
5676
5677PyDoc_STRVAR(os_DirEntry_stat__doc__,
5678"stat($self, /, *, follow_symlinks=True)\n"
5679"--\n"
5680"\n"
5681"Return stat_result object for the entry; cached per entry.");
5682
5683#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005684 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005685
5686static PyObject *
5687os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5688
5689static PyObject *
5690os_DirEntry_stat(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5691{
5692 PyObject *return_value = NULL;
5693 static const char * const _keywords[] = {"follow_symlinks", NULL};
5694 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5695 int follow_symlinks = 1;
5696
Victor Stinner3e1fad62017-01-17 01:29:01 +01005697 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005698 &follow_symlinks)) {
5699 goto exit;
5700 }
5701 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5702
5703exit:
5704 return return_value;
5705}
5706
5707PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5708"is_dir($self, /, *, follow_symlinks=True)\n"
5709"--\n"
5710"\n"
5711"Return True if the entry is a directory; cached per entry.");
5712
5713#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005714 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005715
5716static int
5717os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5718
5719static PyObject *
5720os_DirEntry_is_dir(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5721{
5722 PyObject *return_value = NULL;
5723 static const char * const _keywords[] = {"follow_symlinks", NULL};
5724 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5725 int follow_symlinks = 1;
5726 int _return_value;
5727
Victor Stinner3e1fad62017-01-17 01:29:01 +01005728 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005729 &follow_symlinks)) {
5730 goto exit;
5731 }
5732 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5733 if ((_return_value == -1) && PyErr_Occurred()) {
5734 goto exit;
5735 }
5736 return_value = PyBool_FromLong((long)_return_value);
5737
5738exit:
5739 return return_value;
5740}
5741
5742PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5743"is_file($self, /, *, follow_symlinks=True)\n"
5744"--\n"
5745"\n"
5746"Return True if the entry is a file; cached per entry.");
5747
5748#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005749 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005750
5751static int
5752os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5753
5754static PyObject *
5755os_DirEntry_is_file(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5756{
5757 PyObject *return_value = NULL;
5758 static const char * const _keywords[] = {"follow_symlinks", NULL};
5759 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5760 int follow_symlinks = 1;
5761 int _return_value;
5762
Victor Stinner3e1fad62017-01-17 01:29:01 +01005763 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005764 &follow_symlinks)) {
5765 goto exit;
5766 }
5767 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5768 if ((_return_value == -1) && PyErr_Occurred()) {
5769 goto exit;
5770 }
5771 return_value = PyBool_FromLong((long)_return_value);
5772
5773exit:
5774 return return_value;
5775}
5776
5777PyDoc_STRVAR(os_DirEntry_inode__doc__,
5778"inode($self, /)\n"
5779"--\n"
5780"\n"
5781"Return inode of the entry; cached per entry.");
5782
5783#define OS_DIRENTRY_INODE_METHODDEF \
5784 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5785
5786static PyObject *
5787os_DirEntry_inode_impl(DirEntry *self);
5788
5789static PyObject *
5790os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5791{
5792 return os_DirEntry_inode_impl(self);
5793}
5794
5795PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5796"__fspath__($self, /)\n"
5797"--\n"
5798"\n"
5799"Returns the path for the entry.");
5800
5801#define OS_DIRENTRY___FSPATH___METHODDEF \
5802 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5803
5804static PyObject *
5805os_DirEntry___fspath___impl(DirEntry *self);
5806
5807static PyObject *
5808os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5809{
5810 return os_DirEntry___fspath___impl(self);
5811}
5812
5813PyDoc_STRVAR(os_scandir__doc__,
5814"scandir($module, /, path=None)\n"
5815"--\n"
5816"\n"
5817"Return an iterator of DirEntry objects for given path.\n"
5818"\n"
5819"path can be specified as either str, bytes or path-like object. If path\n"
5820"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5821"all other circumstances they will be str.\n"
5822"\n"
5823"If path is None, uses the path=\'.\'.");
5824
5825#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005826 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005827
5828static PyObject *
5829os_scandir_impl(PyObject *module, path_t *path);
5830
5831static PyObject *
5832os_scandir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5833{
5834 PyObject *return_value = NULL;
5835 static const char * const _keywords[] = {"path", NULL};
5836 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03005837 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005838
Victor Stinner3e1fad62017-01-17 01:29:01 +01005839 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005840 path_converter, &path)) {
5841 goto exit;
5842 }
5843 return_value = os_scandir_impl(module, &path);
5844
5845exit:
5846 /* Cleanup for path */
5847 path_cleanup(&path);
5848
5849 return return_value;
5850}
5851
Ethan Furman410ef8e2016-06-04 12:06:26 -07005852PyDoc_STRVAR(os_fspath__doc__,
5853"fspath($module, /, path)\n"
5854"--\n"
5855"\n"
5856"Return the file system path representation of the object.\n"
5857"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005858"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5859"object defines __fspath__(), then return the result of that method. All other\n"
5860"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005861
5862#define OS_FSPATH_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005863 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07005864
5865static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005866os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07005867
5868static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005869os_fspath(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07005870{
5871 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005872 static const char * const _keywords[] = {"path", NULL};
5873 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07005874 PyObject *path;
5875
Victor Stinner3e1fad62017-01-17 01:29:01 +01005876 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005877 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07005878 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005879 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07005880 return_value = os_fspath_impl(module, path);
5881
5882exit:
5883 return return_value;
5884}
5885
Victor Stinner9b1f4742016-09-06 16:18:52 -07005886#if defined(HAVE_GETRANDOM_SYSCALL)
5887
5888PyDoc_STRVAR(os_getrandom__doc__,
5889"getrandom($module, /, size, flags=0)\n"
5890"--\n"
5891"\n"
5892"Obtain a series of random bytes.");
5893
5894#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005895 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07005896
5897static PyObject *
5898os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
5899
5900static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005901os_getrandom(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07005902{
5903 PyObject *return_value = NULL;
5904 static const char * const _keywords[] = {"size", "flags", NULL};
5905 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
5906 Py_ssize_t size;
5907 int flags = 0;
5908
Victor Stinner3e1fad62017-01-17 01:29:01 +01005909 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07005910 &size, &flags)) {
5911 goto exit;
5912 }
5913 return_value = os_getrandom_impl(module, size, flags);
5914
5915exit:
5916 return return_value;
5917}
5918
5919#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
5920
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005921#ifndef OS_TTYNAME_METHODDEF
5922 #define OS_TTYNAME_METHODDEF
5923#endif /* !defined(OS_TTYNAME_METHODDEF) */
5924
5925#ifndef OS_CTERMID_METHODDEF
5926 #define OS_CTERMID_METHODDEF
5927#endif /* !defined(OS_CTERMID_METHODDEF) */
5928
5929#ifndef OS_FCHDIR_METHODDEF
5930 #define OS_FCHDIR_METHODDEF
5931#endif /* !defined(OS_FCHDIR_METHODDEF) */
5932
5933#ifndef OS_FCHMOD_METHODDEF
5934 #define OS_FCHMOD_METHODDEF
5935#endif /* !defined(OS_FCHMOD_METHODDEF) */
5936
5937#ifndef OS_LCHMOD_METHODDEF
5938 #define OS_LCHMOD_METHODDEF
5939#endif /* !defined(OS_LCHMOD_METHODDEF) */
5940
5941#ifndef OS_CHFLAGS_METHODDEF
5942 #define OS_CHFLAGS_METHODDEF
5943#endif /* !defined(OS_CHFLAGS_METHODDEF) */
5944
5945#ifndef OS_LCHFLAGS_METHODDEF
5946 #define OS_LCHFLAGS_METHODDEF
5947#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
5948
5949#ifndef OS_CHROOT_METHODDEF
5950 #define OS_CHROOT_METHODDEF
5951#endif /* !defined(OS_CHROOT_METHODDEF) */
5952
5953#ifndef OS_FSYNC_METHODDEF
5954 #define OS_FSYNC_METHODDEF
5955#endif /* !defined(OS_FSYNC_METHODDEF) */
5956
5957#ifndef OS_SYNC_METHODDEF
5958 #define OS_SYNC_METHODDEF
5959#endif /* !defined(OS_SYNC_METHODDEF) */
5960
5961#ifndef OS_FDATASYNC_METHODDEF
5962 #define OS_FDATASYNC_METHODDEF
5963#endif /* !defined(OS_FDATASYNC_METHODDEF) */
5964
5965#ifndef OS_CHOWN_METHODDEF
5966 #define OS_CHOWN_METHODDEF
5967#endif /* !defined(OS_CHOWN_METHODDEF) */
5968
5969#ifndef OS_FCHOWN_METHODDEF
5970 #define OS_FCHOWN_METHODDEF
5971#endif /* !defined(OS_FCHOWN_METHODDEF) */
5972
5973#ifndef OS_LCHOWN_METHODDEF
5974 #define OS_LCHOWN_METHODDEF
5975#endif /* !defined(OS_LCHOWN_METHODDEF) */
5976
5977#ifndef OS_LINK_METHODDEF
5978 #define OS_LINK_METHODDEF
5979#endif /* !defined(OS_LINK_METHODDEF) */
5980
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005981#ifndef OS__GETFULLPATHNAME_METHODDEF
5982 #define OS__GETFULLPATHNAME_METHODDEF
5983#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
5984
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005985#ifndef OS__GETFINALPATHNAME_METHODDEF
5986 #define OS__GETFINALPATHNAME_METHODDEF
5987#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
5988
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005989#ifndef OS__ISDIR_METHODDEF
5990 #define OS__ISDIR_METHODDEF
5991#endif /* !defined(OS__ISDIR_METHODDEF) */
5992
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005993#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
5994 #define OS__GETVOLUMEPATHNAME_METHODDEF
5995#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
5996
5997#ifndef OS_NICE_METHODDEF
5998 #define OS_NICE_METHODDEF
5999#endif /* !defined(OS_NICE_METHODDEF) */
6000
6001#ifndef OS_GETPRIORITY_METHODDEF
6002 #define OS_GETPRIORITY_METHODDEF
6003#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6004
6005#ifndef OS_SETPRIORITY_METHODDEF
6006 #define OS_SETPRIORITY_METHODDEF
6007#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6008
6009#ifndef OS_SYSTEM_METHODDEF
6010 #define OS_SYSTEM_METHODDEF
6011#endif /* !defined(OS_SYSTEM_METHODDEF) */
6012
6013#ifndef OS_UNAME_METHODDEF
6014 #define OS_UNAME_METHODDEF
6015#endif /* !defined(OS_UNAME_METHODDEF) */
6016
6017#ifndef OS_EXECV_METHODDEF
6018 #define OS_EXECV_METHODDEF
6019#endif /* !defined(OS_EXECV_METHODDEF) */
6020
6021#ifndef OS_EXECVE_METHODDEF
6022 #define OS_EXECVE_METHODDEF
6023#endif /* !defined(OS_EXECVE_METHODDEF) */
6024
6025#ifndef OS_SPAWNV_METHODDEF
6026 #define OS_SPAWNV_METHODDEF
6027#endif /* !defined(OS_SPAWNV_METHODDEF) */
6028
6029#ifndef OS_SPAWNVE_METHODDEF
6030 #define OS_SPAWNVE_METHODDEF
6031#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6032
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006033#ifndef OS_REGISTER_AT_FORK_METHODDEF
6034 #define OS_REGISTER_AT_FORK_METHODDEF
6035#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6036
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006037#ifndef OS_FORK1_METHODDEF
6038 #define OS_FORK1_METHODDEF
6039#endif /* !defined(OS_FORK1_METHODDEF) */
6040
6041#ifndef OS_FORK_METHODDEF
6042 #define OS_FORK_METHODDEF
6043#endif /* !defined(OS_FORK_METHODDEF) */
6044
6045#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6046 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6047#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6048
6049#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6050 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6051#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6052
6053#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6054 #define OS_SCHED_GETSCHEDULER_METHODDEF
6055#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6056
6057#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6058 #define OS_SCHED_SETSCHEDULER_METHODDEF
6059#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6060
6061#ifndef OS_SCHED_GETPARAM_METHODDEF
6062 #define OS_SCHED_GETPARAM_METHODDEF
6063#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6064
6065#ifndef OS_SCHED_SETPARAM_METHODDEF
6066 #define OS_SCHED_SETPARAM_METHODDEF
6067#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6068
6069#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6070 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6071#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6072
6073#ifndef OS_SCHED_YIELD_METHODDEF
6074 #define OS_SCHED_YIELD_METHODDEF
6075#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6076
6077#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6078 #define OS_SCHED_SETAFFINITY_METHODDEF
6079#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6080
6081#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6082 #define OS_SCHED_GETAFFINITY_METHODDEF
6083#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6084
6085#ifndef OS_OPENPTY_METHODDEF
6086 #define OS_OPENPTY_METHODDEF
6087#endif /* !defined(OS_OPENPTY_METHODDEF) */
6088
6089#ifndef OS_FORKPTY_METHODDEF
6090 #define OS_FORKPTY_METHODDEF
6091#endif /* !defined(OS_FORKPTY_METHODDEF) */
6092
6093#ifndef OS_GETEGID_METHODDEF
6094 #define OS_GETEGID_METHODDEF
6095#endif /* !defined(OS_GETEGID_METHODDEF) */
6096
6097#ifndef OS_GETEUID_METHODDEF
6098 #define OS_GETEUID_METHODDEF
6099#endif /* !defined(OS_GETEUID_METHODDEF) */
6100
6101#ifndef OS_GETGID_METHODDEF
6102 #define OS_GETGID_METHODDEF
6103#endif /* !defined(OS_GETGID_METHODDEF) */
6104
Berker Peksag39404992016-09-15 20:45:16 +03006105#ifndef OS_GETPID_METHODDEF
6106 #define OS_GETPID_METHODDEF
6107#endif /* !defined(OS_GETPID_METHODDEF) */
6108
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006109#ifndef OS_GETGROUPS_METHODDEF
6110 #define OS_GETGROUPS_METHODDEF
6111#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6112
6113#ifndef OS_GETPGID_METHODDEF
6114 #define OS_GETPGID_METHODDEF
6115#endif /* !defined(OS_GETPGID_METHODDEF) */
6116
6117#ifndef OS_GETPGRP_METHODDEF
6118 #define OS_GETPGRP_METHODDEF
6119#endif /* !defined(OS_GETPGRP_METHODDEF) */
6120
6121#ifndef OS_SETPGRP_METHODDEF
6122 #define OS_SETPGRP_METHODDEF
6123#endif /* !defined(OS_SETPGRP_METHODDEF) */
6124
6125#ifndef OS_GETPPID_METHODDEF
6126 #define OS_GETPPID_METHODDEF
6127#endif /* !defined(OS_GETPPID_METHODDEF) */
6128
6129#ifndef OS_GETLOGIN_METHODDEF
6130 #define OS_GETLOGIN_METHODDEF
6131#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6132
6133#ifndef OS_GETUID_METHODDEF
6134 #define OS_GETUID_METHODDEF
6135#endif /* !defined(OS_GETUID_METHODDEF) */
6136
6137#ifndef OS_KILL_METHODDEF
6138 #define OS_KILL_METHODDEF
6139#endif /* !defined(OS_KILL_METHODDEF) */
6140
6141#ifndef OS_KILLPG_METHODDEF
6142 #define OS_KILLPG_METHODDEF
6143#endif /* !defined(OS_KILLPG_METHODDEF) */
6144
6145#ifndef OS_PLOCK_METHODDEF
6146 #define OS_PLOCK_METHODDEF
6147#endif /* !defined(OS_PLOCK_METHODDEF) */
6148
6149#ifndef OS_SETUID_METHODDEF
6150 #define OS_SETUID_METHODDEF
6151#endif /* !defined(OS_SETUID_METHODDEF) */
6152
6153#ifndef OS_SETEUID_METHODDEF
6154 #define OS_SETEUID_METHODDEF
6155#endif /* !defined(OS_SETEUID_METHODDEF) */
6156
6157#ifndef OS_SETEGID_METHODDEF
6158 #define OS_SETEGID_METHODDEF
6159#endif /* !defined(OS_SETEGID_METHODDEF) */
6160
6161#ifndef OS_SETREUID_METHODDEF
6162 #define OS_SETREUID_METHODDEF
6163#endif /* !defined(OS_SETREUID_METHODDEF) */
6164
6165#ifndef OS_SETREGID_METHODDEF
6166 #define OS_SETREGID_METHODDEF
6167#endif /* !defined(OS_SETREGID_METHODDEF) */
6168
6169#ifndef OS_SETGID_METHODDEF
6170 #define OS_SETGID_METHODDEF
6171#endif /* !defined(OS_SETGID_METHODDEF) */
6172
6173#ifndef OS_SETGROUPS_METHODDEF
6174 #define OS_SETGROUPS_METHODDEF
6175#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6176
6177#ifndef OS_WAIT3_METHODDEF
6178 #define OS_WAIT3_METHODDEF
6179#endif /* !defined(OS_WAIT3_METHODDEF) */
6180
6181#ifndef OS_WAIT4_METHODDEF
6182 #define OS_WAIT4_METHODDEF
6183#endif /* !defined(OS_WAIT4_METHODDEF) */
6184
6185#ifndef OS_WAITID_METHODDEF
6186 #define OS_WAITID_METHODDEF
6187#endif /* !defined(OS_WAITID_METHODDEF) */
6188
6189#ifndef OS_WAITPID_METHODDEF
6190 #define OS_WAITPID_METHODDEF
6191#endif /* !defined(OS_WAITPID_METHODDEF) */
6192
6193#ifndef OS_WAIT_METHODDEF
6194 #define OS_WAIT_METHODDEF
6195#endif /* !defined(OS_WAIT_METHODDEF) */
6196
6197#ifndef OS_SYMLINK_METHODDEF
6198 #define OS_SYMLINK_METHODDEF
6199#endif /* !defined(OS_SYMLINK_METHODDEF) */
6200
6201#ifndef OS_TIMES_METHODDEF
6202 #define OS_TIMES_METHODDEF
6203#endif /* !defined(OS_TIMES_METHODDEF) */
6204
6205#ifndef OS_GETSID_METHODDEF
6206 #define OS_GETSID_METHODDEF
6207#endif /* !defined(OS_GETSID_METHODDEF) */
6208
6209#ifndef OS_SETSID_METHODDEF
6210 #define OS_SETSID_METHODDEF
6211#endif /* !defined(OS_SETSID_METHODDEF) */
6212
6213#ifndef OS_SETPGID_METHODDEF
6214 #define OS_SETPGID_METHODDEF
6215#endif /* !defined(OS_SETPGID_METHODDEF) */
6216
6217#ifndef OS_TCGETPGRP_METHODDEF
6218 #define OS_TCGETPGRP_METHODDEF
6219#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6220
6221#ifndef OS_TCSETPGRP_METHODDEF
6222 #define OS_TCSETPGRP_METHODDEF
6223#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6224
6225#ifndef OS_LOCKF_METHODDEF
6226 #define OS_LOCKF_METHODDEF
6227#endif /* !defined(OS_LOCKF_METHODDEF) */
6228
6229#ifndef OS_READV_METHODDEF
6230 #define OS_READV_METHODDEF
6231#endif /* !defined(OS_READV_METHODDEF) */
6232
6233#ifndef OS_PREAD_METHODDEF
6234 #define OS_PREAD_METHODDEF
6235#endif /* !defined(OS_PREAD_METHODDEF) */
6236
6237#ifndef OS_PIPE_METHODDEF
6238 #define OS_PIPE_METHODDEF
6239#endif /* !defined(OS_PIPE_METHODDEF) */
6240
6241#ifndef OS_PIPE2_METHODDEF
6242 #define OS_PIPE2_METHODDEF
6243#endif /* !defined(OS_PIPE2_METHODDEF) */
6244
6245#ifndef OS_WRITEV_METHODDEF
6246 #define OS_WRITEV_METHODDEF
6247#endif /* !defined(OS_WRITEV_METHODDEF) */
6248
6249#ifndef OS_PWRITE_METHODDEF
6250 #define OS_PWRITE_METHODDEF
6251#endif /* !defined(OS_PWRITE_METHODDEF) */
6252
6253#ifndef OS_MKFIFO_METHODDEF
6254 #define OS_MKFIFO_METHODDEF
6255#endif /* !defined(OS_MKFIFO_METHODDEF) */
6256
6257#ifndef OS_MKNOD_METHODDEF
6258 #define OS_MKNOD_METHODDEF
6259#endif /* !defined(OS_MKNOD_METHODDEF) */
6260
6261#ifndef OS_MAJOR_METHODDEF
6262 #define OS_MAJOR_METHODDEF
6263#endif /* !defined(OS_MAJOR_METHODDEF) */
6264
6265#ifndef OS_MINOR_METHODDEF
6266 #define OS_MINOR_METHODDEF
6267#endif /* !defined(OS_MINOR_METHODDEF) */
6268
6269#ifndef OS_MAKEDEV_METHODDEF
6270 #define OS_MAKEDEV_METHODDEF
6271#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6272
6273#ifndef OS_FTRUNCATE_METHODDEF
6274 #define OS_FTRUNCATE_METHODDEF
6275#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6276
6277#ifndef OS_TRUNCATE_METHODDEF
6278 #define OS_TRUNCATE_METHODDEF
6279#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6280
6281#ifndef OS_POSIX_FALLOCATE_METHODDEF
6282 #define OS_POSIX_FALLOCATE_METHODDEF
6283#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6284
6285#ifndef OS_POSIX_FADVISE_METHODDEF
6286 #define OS_POSIX_FADVISE_METHODDEF
6287#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6288
6289#ifndef OS_PUTENV_METHODDEF
6290 #define OS_PUTENV_METHODDEF
6291#endif /* !defined(OS_PUTENV_METHODDEF) */
6292
6293#ifndef OS_UNSETENV_METHODDEF
6294 #define OS_UNSETENV_METHODDEF
6295#endif /* !defined(OS_UNSETENV_METHODDEF) */
6296
6297#ifndef OS_WCOREDUMP_METHODDEF
6298 #define OS_WCOREDUMP_METHODDEF
6299#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6300
6301#ifndef OS_WIFCONTINUED_METHODDEF
6302 #define OS_WIFCONTINUED_METHODDEF
6303#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6304
6305#ifndef OS_WIFSTOPPED_METHODDEF
6306 #define OS_WIFSTOPPED_METHODDEF
6307#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6308
6309#ifndef OS_WIFSIGNALED_METHODDEF
6310 #define OS_WIFSIGNALED_METHODDEF
6311#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6312
6313#ifndef OS_WIFEXITED_METHODDEF
6314 #define OS_WIFEXITED_METHODDEF
6315#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6316
6317#ifndef OS_WEXITSTATUS_METHODDEF
6318 #define OS_WEXITSTATUS_METHODDEF
6319#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6320
6321#ifndef OS_WTERMSIG_METHODDEF
6322 #define OS_WTERMSIG_METHODDEF
6323#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6324
6325#ifndef OS_WSTOPSIG_METHODDEF
6326 #define OS_WSTOPSIG_METHODDEF
6327#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6328
6329#ifndef OS_FSTATVFS_METHODDEF
6330 #define OS_FSTATVFS_METHODDEF
6331#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6332
6333#ifndef OS_STATVFS_METHODDEF
6334 #define OS_STATVFS_METHODDEF
6335#endif /* !defined(OS_STATVFS_METHODDEF) */
6336
6337#ifndef OS__GETDISKUSAGE_METHODDEF
6338 #define OS__GETDISKUSAGE_METHODDEF
6339#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6340
6341#ifndef OS_FPATHCONF_METHODDEF
6342 #define OS_FPATHCONF_METHODDEF
6343#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6344
6345#ifndef OS_PATHCONF_METHODDEF
6346 #define OS_PATHCONF_METHODDEF
6347#endif /* !defined(OS_PATHCONF_METHODDEF) */
6348
6349#ifndef OS_CONFSTR_METHODDEF
6350 #define OS_CONFSTR_METHODDEF
6351#endif /* !defined(OS_CONFSTR_METHODDEF) */
6352
6353#ifndef OS_SYSCONF_METHODDEF
6354 #define OS_SYSCONF_METHODDEF
6355#endif /* !defined(OS_SYSCONF_METHODDEF) */
6356
Steve Dowercc16be82016-09-08 10:35:16 -07006357#ifndef OS_STARTFILE_METHODDEF
6358 #define OS_STARTFILE_METHODDEF
6359#endif /* !defined(OS_STARTFILE_METHODDEF) */
6360
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006361#ifndef OS_GETLOADAVG_METHODDEF
6362 #define OS_GETLOADAVG_METHODDEF
6363#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6364
6365#ifndef OS_SETRESUID_METHODDEF
6366 #define OS_SETRESUID_METHODDEF
6367#endif /* !defined(OS_SETRESUID_METHODDEF) */
6368
6369#ifndef OS_SETRESGID_METHODDEF
6370 #define OS_SETRESGID_METHODDEF
6371#endif /* !defined(OS_SETRESGID_METHODDEF) */
6372
6373#ifndef OS_GETRESUID_METHODDEF
6374 #define OS_GETRESUID_METHODDEF
6375#endif /* !defined(OS_GETRESUID_METHODDEF) */
6376
6377#ifndef OS_GETRESGID_METHODDEF
6378 #define OS_GETRESGID_METHODDEF
6379#endif /* !defined(OS_GETRESGID_METHODDEF) */
6380
6381#ifndef OS_GETXATTR_METHODDEF
6382 #define OS_GETXATTR_METHODDEF
6383#endif /* !defined(OS_GETXATTR_METHODDEF) */
6384
6385#ifndef OS_SETXATTR_METHODDEF
6386 #define OS_SETXATTR_METHODDEF
6387#endif /* !defined(OS_SETXATTR_METHODDEF) */
6388
6389#ifndef OS_REMOVEXATTR_METHODDEF
6390 #define OS_REMOVEXATTR_METHODDEF
6391#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6392
6393#ifndef OS_LISTXATTR_METHODDEF
6394 #define OS_LISTXATTR_METHODDEF
6395#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6396
6397#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6398 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6399#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6400
6401#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6402 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6403#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006404
6405#ifndef OS_GETRANDOM_METHODDEF
6406 #define OS_GETRANDOM_METHODDEF
6407#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006408/*[clinic end generated code: output=949867cb46218339 input=a9049054013a1b77]*/