blob: caa1cacd3f0a9ee8f6b27fcae9d70a1e8b019f04 [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"
BNMetrics08026b12018-11-02 17:56:25 +000012" Path to be examined; can be string, bytes, a path-like object or\n"
Xiang Zhang4459e002017-01-22 13:04:17 +080013" open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030014" dir_fd\n"
15" If not None, it should be a file descriptor open to a directory,\n"
16" and path should be a relative string; path will then be relative to\n"
17" that directory.\n"
18" follow_symlinks\n"
19" If False, and the last element of the path is a symbolic link,\n"
20" stat will examine the symbolic link itself instead of the file\n"
21" the link points to.\n"
22"\n"
23"dir_fd and follow_symlinks may not be implemented\n"
24" on your platform. If they are unavailable, using them will raise a\n"
25" NotImplementedError.\n"
26"\n"
27"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
28" an open file descriptor.");
29
30#define OS_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030031 {"stat", (PyCFunction)os_stat, METH_FASTCALL|METH_KEYWORDS, os_stat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030032
33static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030034os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030035
36static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020037os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030038{
39 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030040 static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
41 static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030042 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
43 int dir_fd = DEFAULT_DIR_FD;
44 int follow_symlinks = 1;
45
Victor Stinner3e1fad62017-01-17 01:29:01 +010046 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030047 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030048 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030049 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030050 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
51
52exit:
53 /* Cleanup for path */
54 path_cleanup(&path);
55
56 return return_value;
57}
58
59PyDoc_STRVAR(os_lstat__doc__,
60"lstat($module, /, path, *, dir_fd=None)\n"
61"--\n"
62"\n"
63"Perform a stat system call on the given path, without following symbolic links.\n"
64"\n"
65"Like stat(), but do not follow symbolic links.\n"
66"Equivalent to stat(path, follow_symlinks=False).");
67
68#define OS_LSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030069 {"lstat", (PyCFunction)os_lstat, METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030070
71static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030072os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030073
74static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020075os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030076{
77 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030078 static const char * const _keywords[] = {"path", "dir_fd", NULL};
79 static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030080 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
81 int dir_fd = DEFAULT_DIR_FD;
82
Victor Stinner3e1fad62017-01-17 01:29:01 +010083 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030084 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030087 return_value = os_lstat_impl(module, &path, dir_fd);
88
89exit:
90 /* Cleanup for path */
91 path_cleanup(&path);
92
93 return return_value;
94}
95
96PyDoc_STRVAR(os_access__doc__,
97"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
98" follow_symlinks=True)\n"
99"--\n"
100"\n"
101"Use the real uid/gid to test for access to a path.\n"
102"\n"
103" path\n"
BNMetrics08026b12018-11-02 17:56:25 +0000104" Path to be tested; can be string, bytes, or a path-like object.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300105" mode\n"
106" Operating-system mode bitfield. Can be F_OK to test existence,\n"
107" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
108" dir_fd\n"
109" If not None, it should be a file descriptor open to a directory,\n"
110" and path should be relative; path will then be relative to that\n"
111" directory.\n"
112" effective_ids\n"
113" If True, access will use the effective uid/gid instead of\n"
114" the real uid/gid.\n"
115" follow_symlinks\n"
116" If False, and the last element of the path is a symbolic link,\n"
117" access will examine the symbolic link itself instead of the file\n"
118" the link points to.\n"
119"\n"
120"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
121" on your platform. If they are unavailable, using them will raise a\n"
122" NotImplementedError.\n"
123"\n"
124"Note that most operations will use the effective uid/gid, therefore this\n"
125" routine can be used in a suid/sgid environment to test if the invoking user\n"
126" has the specified access to the path.");
127
128#define OS_ACCESS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300129 {"access", (PyCFunction)os_access, METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130
131static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300132os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400133 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300134
135static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200136os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300137{
138 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300139 static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
140 static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0};
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700141 path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300142 int mode;
143 int dir_fd = DEFAULT_DIR_FD;
144 int effective_ids = 0;
145 int follow_symlinks = 1;
146 int _return_value;
147
Victor Stinner3e1fad62017-01-17 01:29:01 +0100148 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300149 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300150 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300151 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300152 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300153 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300154 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300155 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300156 return_value = PyBool_FromLong((long)_return_value);
157
158exit:
159 /* Cleanup for path */
160 path_cleanup(&path);
161
162 return return_value;
163}
164
165#if defined(HAVE_TTYNAME)
166
167PyDoc_STRVAR(os_ttyname__doc__,
168"ttyname($module, fd, /)\n"
169"--\n"
170"\n"
171"Return the name of the terminal device connected to \'fd\'.\n"
172"\n"
173" fd\n"
174" Integer file descriptor handle.");
175
176#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300177 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300178
179static char *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300180os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300181
182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300183os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300184{
185 PyObject *return_value = NULL;
186 int fd;
187 char *_return_value;
188
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300189 if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300190 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300191 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300192 _return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300193 if (_return_value == NULL) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300194 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300195 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300196 return_value = PyUnicode_DecodeFSDefault(_return_value);
197
198exit:
199 return return_value;
200}
201
202#endif /* defined(HAVE_TTYNAME) */
203
204#if defined(HAVE_CTERMID)
205
206PyDoc_STRVAR(os_ctermid__doc__,
207"ctermid($module, /)\n"
208"--\n"
209"\n"
210"Return the name of the controlling terminal for this process.");
211
212#define OS_CTERMID_METHODDEF \
213 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
214
215static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300216os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300217
218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300219os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300220{
221 return os_ctermid_impl(module);
222}
223
224#endif /* defined(HAVE_CTERMID) */
225
226PyDoc_STRVAR(os_chdir__doc__,
227"chdir($module, /, path)\n"
228"--\n"
229"\n"
230"Change the current working directory to the specified path.\n"
231"\n"
232"path may always be specified as a string.\n"
233"On some platforms, path may also be specified as an open file descriptor.\n"
234" If this functionality is unavailable, using it raises an exception.");
235
236#define OS_CHDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300237 {"chdir", (PyCFunction)os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300238
239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300240os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300241
242static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200243os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300244{
245 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300246 static const char * const _keywords[] = {"path", NULL};
247 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300248 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
249
Victor Stinner3e1fad62017-01-17 01:29:01 +0100250 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300251 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300252 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300253 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300254 return_value = os_chdir_impl(module, &path);
255
256exit:
257 /* Cleanup for path */
258 path_cleanup(&path);
259
260 return return_value;
261}
262
263#if defined(HAVE_FCHDIR)
264
265PyDoc_STRVAR(os_fchdir__doc__,
266"fchdir($module, /, fd)\n"
267"--\n"
268"\n"
269"Change to the directory of the given file descriptor.\n"
270"\n"
271"fd must be opened on a directory, not a file.\n"
272"Equivalent to os.chdir(fd).");
273
274#define OS_FCHDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300275 {"fchdir", (PyCFunction)os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300276
277static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300278os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300279
280static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200281os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300282{
283 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300284 static const char * const _keywords[] = {"fd", NULL};
285 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300286 int fd;
287
Victor Stinner3e1fad62017-01-17 01:29:01 +0100288 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300289 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300290 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300291 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300292 return_value = os_fchdir_impl(module, fd);
293
294exit:
295 return return_value;
296}
297
298#endif /* defined(HAVE_FCHDIR) */
299
300PyDoc_STRVAR(os_chmod__doc__,
301"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
302"--\n"
303"\n"
304"Change the access permissions of a file.\n"
305"\n"
306" path\n"
BNMetrics08026b12018-11-02 17:56:25 +0000307" Path to be modified. May always be specified as a str, bytes, or a path-like object.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300308" On some platforms, path may also be specified as an open file descriptor.\n"
309" If this functionality is unavailable, using it raises an exception.\n"
310" mode\n"
311" Operating-system mode bitfield.\n"
312" dir_fd\n"
313" If not None, it should be a file descriptor open to a directory,\n"
314" and path should be relative; path will then be relative to that\n"
315" directory.\n"
316" follow_symlinks\n"
317" If False, and the last element of the path is a symbolic link,\n"
318" chmod will modify the symbolic link itself instead of the file\n"
319" the link points to.\n"
320"\n"
321"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
322" an open file descriptor.\n"
323"dir_fd and follow_symlinks may not be implemented on your platform.\n"
324" If they are unavailable, using them will raise a NotImplementedError.");
325
326#define OS_CHMOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300327 {"chmod", (PyCFunction)os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300328
329static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300330os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400331 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300332
333static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200334os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300335{
336 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300337 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
338 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300339 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
340 int mode;
341 int dir_fd = DEFAULT_DIR_FD;
342 int follow_symlinks = 1;
343
Victor Stinner3e1fad62017-01-17 01:29:01 +0100344 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300345 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300346 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300347 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300348 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
349
350exit:
351 /* Cleanup for path */
352 path_cleanup(&path);
353
354 return return_value;
355}
356
357#if defined(HAVE_FCHMOD)
358
359PyDoc_STRVAR(os_fchmod__doc__,
360"fchmod($module, /, fd, mode)\n"
361"--\n"
362"\n"
363"Change the access permissions of the file given by file descriptor fd.\n"
364"\n"
365"Equivalent to os.chmod(fd, mode).");
366
367#define OS_FCHMOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300368 {"fchmod", (PyCFunction)os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300369
370static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300371os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300372
373static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200374os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300375{
376 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300377 static const char * const _keywords[] = {"fd", "mode", NULL};
378 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300379 int fd;
380 int mode;
381
Victor Stinner3e1fad62017-01-17 01:29:01 +0100382 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300383 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300386 return_value = os_fchmod_impl(module, fd, mode);
387
388exit:
389 return return_value;
390}
391
392#endif /* defined(HAVE_FCHMOD) */
393
394#if defined(HAVE_LCHMOD)
395
396PyDoc_STRVAR(os_lchmod__doc__,
397"lchmod($module, /, path, mode)\n"
398"--\n"
399"\n"
400"Change the access permissions of a file, without following symbolic links.\n"
401"\n"
402"If path is a symlink, this affects the link itself rather than the target.\n"
403"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
404
405#define OS_LCHMOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300406 {"lchmod", (PyCFunction)os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300407
408static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300409os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300410
411static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200412os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300413{
414 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300415 static const char * const _keywords[] = {"path", "mode", NULL};
416 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300417 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
418 int mode;
419
Victor Stinner3e1fad62017-01-17 01:29:01 +0100420 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300421 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300424 return_value = os_lchmod_impl(module, &path, mode);
425
426exit:
427 /* Cleanup for path */
428 path_cleanup(&path);
429
430 return return_value;
431}
432
433#endif /* defined(HAVE_LCHMOD) */
434
435#if defined(HAVE_CHFLAGS)
436
437PyDoc_STRVAR(os_chflags__doc__,
438"chflags($module, /, path, flags, follow_symlinks=True)\n"
439"--\n"
440"\n"
441"Set file flags.\n"
442"\n"
443"If follow_symlinks is False, and the last element of the path is a symbolic\n"
444" link, chflags will change flags on the symbolic link itself instead of the\n"
445" file the link points to.\n"
446"follow_symlinks may not be implemented on your platform. If it is\n"
447"unavailable, using it will raise a NotImplementedError.");
448
449#define OS_CHFLAGS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300450 {"chflags", (PyCFunction)os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300451
452static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300453os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400454 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300455
456static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200457os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300458{
459 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300460 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
461 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300462 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
463 unsigned long flags;
464 int follow_symlinks = 1;
465
Victor Stinner3e1fad62017-01-17 01:29:01 +0100466 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300467 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300468 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300469 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300470 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
471
472exit:
473 /* Cleanup for path */
474 path_cleanup(&path);
475
476 return return_value;
477}
478
479#endif /* defined(HAVE_CHFLAGS) */
480
481#if defined(HAVE_LCHFLAGS)
482
483PyDoc_STRVAR(os_lchflags__doc__,
484"lchflags($module, /, path, flags)\n"
485"--\n"
486"\n"
487"Set file flags.\n"
488"\n"
489"This function will not follow symbolic links.\n"
490"Equivalent to chflags(path, flags, follow_symlinks=False).");
491
492#define OS_LCHFLAGS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300493 {"lchflags", (PyCFunction)os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300494
495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300496os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300497
498static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200499os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300500{
501 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300502 static const char * const _keywords[] = {"path", "flags", NULL};
503 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
505 unsigned long flags;
506
Victor Stinner3e1fad62017-01-17 01:29:01 +0100507 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300508 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300511 return_value = os_lchflags_impl(module, &path, flags);
512
513exit:
514 /* Cleanup for path */
515 path_cleanup(&path);
516
517 return return_value;
518}
519
520#endif /* defined(HAVE_LCHFLAGS) */
521
522#if defined(HAVE_CHROOT)
523
524PyDoc_STRVAR(os_chroot__doc__,
525"chroot($module, /, path)\n"
526"--\n"
527"\n"
528"Change root directory to path.");
529
530#define OS_CHROOT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300531 {"chroot", (PyCFunction)os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300532
533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300534os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300535
536static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200537os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300538{
539 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300540 static const char * const _keywords[] = {"path", NULL};
541 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300542 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
543
Victor Stinner3e1fad62017-01-17 01:29:01 +0100544 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300545 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300546 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300547 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300548 return_value = os_chroot_impl(module, &path);
549
550exit:
551 /* Cleanup for path */
552 path_cleanup(&path);
553
554 return return_value;
555}
556
557#endif /* defined(HAVE_CHROOT) */
558
559#if defined(HAVE_FSYNC)
560
561PyDoc_STRVAR(os_fsync__doc__,
562"fsync($module, /, fd)\n"
563"--\n"
564"\n"
565"Force write of fd to disk.");
566
567#define OS_FSYNC_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300568 {"fsync", (PyCFunction)os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300569
570static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300571os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300572
573static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200574os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300575{
576 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300577 static const char * const _keywords[] = {"fd", NULL};
578 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300579 int fd;
580
Victor Stinner3e1fad62017-01-17 01:29:01 +0100581 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300582 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300583 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300584 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300585 return_value = os_fsync_impl(module, fd);
586
587exit:
588 return return_value;
589}
590
591#endif /* defined(HAVE_FSYNC) */
592
593#if defined(HAVE_SYNC)
594
595PyDoc_STRVAR(os_sync__doc__,
596"sync($module, /)\n"
597"--\n"
598"\n"
599"Force write of everything to disk.");
600
601#define OS_SYNC_METHODDEF \
602 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
603
604static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300605os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300606
607static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300608os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300609{
610 return os_sync_impl(module);
611}
612
613#endif /* defined(HAVE_SYNC) */
614
615#if defined(HAVE_FDATASYNC)
616
617PyDoc_STRVAR(os_fdatasync__doc__,
618"fdatasync($module, /, fd)\n"
619"--\n"
620"\n"
621"Force write of fd to disk without forcing update of metadata.");
622
623#define OS_FDATASYNC_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300624 {"fdatasync", (PyCFunction)os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300625
626static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300627os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300628
629static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200630os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300631{
632 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300633 static const char * const _keywords[] = {"fd", NULL};
634 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300635 int fd;
636
Victor Stinner3e1fad62017-01-17 01:29:01 +0100637 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300638 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300639 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300640 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300641 return_value = os_fdatasync_impl(module, fd);
642
643exit:
644 return return_value;
645}
646
647#endif /* defined(HAVE_FDATASYNC) */
648
649#if defined(HAVE_CHOWN)
650
651PyDoc_STRVAR(os_chown__doc__,
652"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
653"--\n"
654"\n"
655"Change the owner and group id of path to the numeric uid and gid.\\\n"
656"\n"
657" path\n"
BNMetrics08026b12018-11-02 17:56:25 +0000658" Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300659" dir_fd\n"
660" If not None, it should be a file descriptor open to a directory,\n"
661" and path should be relative; path will then be relative to that\n"
662" directory.\n"
663" follow_symlinks\n"
664" If False, and the last element of the path is a symbolic link,\n"
665" stat will examine the symbolic link itself instead of the file\n"
666" the link points to.\n"
667"\n"
668"path may always be specified as a string.\n"
669"On some platforms, path may also be specified as an open file descriptor.\n"
670" If this functionality is unavailable, using it raises an exception.\n"
671"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
672" and path should be relative; path will then be relative to that directory.\n"
673"If follow_symlinks is False, and the last element of the path is a symbolic\n"
674" link, chown will modify the symbolic link itself instead of the file the\n"
675" link points to.\n"
676"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
677" an open file descriptor.\n"
678"dir_fd and follow_symlinks may not be implemented on your platform.\n"
679" If they are unavailable, using them will raise a NotImplementedError.");
680
681#define OS_CHOWN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300682 {"chown", (PyCFunction)os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300683
684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300685os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400686 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300687
688static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200689os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300690{
691 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300692 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
693 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300694 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
695 uid_t uid;
696 gid_t gid;
697 int dir_fd = DEFAULT_DIR_FD;
698 int follow_symlinks = 1;
699
Victor Stinner3e1fad62017-01-17 01:29:01 +0100700 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300701 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300702 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300703 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300704 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
705
706exit:
707 /* Cleanup for path */
708 path_cleanup(&path);
709
710 return return_value;
711}
712
713#endif /* defined(HAVE_CHOWN) */
714
715#if defined(HAVE_FCHOWN)
716
717PyDoc_STRVAR(os_fchown__doc__,
718"fchown($module, /, fd, uid, gid)\n"
719"--\n"
720"\n"
721"Change the owner and group id of the file specified by file descriptor.\n"
722"\n"
723"Equivalent to os.chown(fd, uid, gid).");
724
725#define OS_FCHOWN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300726 {"fchown", (PyCFunction)os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300727
728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300729os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300730
731static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200732os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300733{
734 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300735 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
736 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300737 int fd;
738 uid_t uid;
739 gid_t gid;
740
Victor Stinner3e1fad62017-01-17 01:29:01 +0100741 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300742 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300743 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300744 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300745 return_value = os_fchown_impl(module, fd, uid, gid);
746
747exit:
748 return return_value;
749}
750
751#endif /* defined(HAVE_FCHOWN) */
752
753#if defined(HAVE_LCHOWN)
754
755PyDoc_STRVAR(os_lchown__doc__,
756"lchown($module, /, path, uid, gid)\n"
757"--\n"
758"\n"
759"Change the owner and group id of path to the numeric uid and gid.\n"
760"\n"
761"This function will not follow symbolic links.\n"
762"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
763
764#define OS_LCHOWN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300765 {"lchown", (PyCFunction)os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300766
767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300768os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300769
770static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200771os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300772{
773 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300774 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
775 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300776 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
777 uid_t uid;
778 gid_t gid;
779
Victor Stinner3e1fad62017-01-17 01:29:01 +0100780 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300781 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300782 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300783 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300784 return_value = os_lchown_impl(module, &path, uid, gid);
785
786exit:
787 /* Cleanup for path */
788 path_cleanup(&path);
789
790 return return_value;
791}
792
793#endif /* defined(HAVE_LCHOWN) */
794
795PyDoc_STRVAR(os_getcwd__doc__,
796"getcwd($module, /)\n"
797"--\n"
798"\n"
799"Return a unicode string representing the current working directory.");
800
801#define OS_GETCWD_METHODDEF \
802 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
803
804static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300805os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300806
807static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300808os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300809{
810 return os_getcwd_impl(module);
811}
812
813PyDoc_STRVAR(os_getcwdb__doc__,
814"getcwdb($module, /)\n"
815"--\n"
816"\n"
817"Return a bytes string representing the current working directory.");
818
819#define OS_GETCWDB_METHODDEF \
820 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
821
822static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300823os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300824
825static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300826os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300827{
828 return os_getcwdb_impl(module);
829}
830
831#if defined(HAVE_LINK)
832
833PyDoc_STRVAR(os_link__doc__,
834"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
835" follow_symlinks=True)\n"
836"--\n"
837"\n"
838"Create a hard link to a file.\n"
839"\n"
840"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
841" descriptor open to a directory, and the respective path string (src or dst)\n"
842" should be relative; the path will then be relative to that directory.\n"
843"If follow_symlinks is False, and the last element of src is a symbolic\n"
844" link, link will create a link to the symbolic link itself instead of the\n"
845" file the link points to.\n"
846"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
847" platform. If they are unavailable, using them will raise a\n"
848" NotImplementedError.");
849
850#define OS_LINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300851 {"link", (PyCFunction)os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300852
853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300854os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400855 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300856
857static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200858os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300859{
860 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300861 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
862 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300863 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
864 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
865 int src_dir_fd = DEFAULT_DIR_FD;
866 int dst_dir_fd = DEFAULT_DIR_FD;
867 int follow_symlinks = 1;
868
Victor Stinner3e1fad62017-01-17 01:29:01 +0100869 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300870 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300871 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300872 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300873 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
874
875exit:
876 /* Cleanup for src */
877 path_cleanup(&src);
878 /* Cleanup for dst */
879 path_cleanup(&dst);
880
881 return return_value;
882}
883
884#endif /* defined(HAVE_LINK) */
885
886PyDoc_STRVAR(os_listdir__doc__,
887"listdir($module, /, path=None)\n"
888"--\n"
889"\n"
890"Return a list containing the names of the files in the directory.\n"
891"\n"
BNMetrics08026b12018-11-02 17:56:25 +0000892"path can be specified as either str, bytes, or a path-like object. If path is bytes,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300893" the filenames returned will also be bytes; in all other circumstances\n"
894" the filenames returned will be str.\n"
895"If path is None, uses the path=\'.\'.\n"
896"On some platforms, path may also be specified as an open file descriptor;\\\n"
897" the file descriptor must refer to a directory.\n"
898" If this functionality is unavailable, using it raises NotImplementedError.\n"
899"\n"
900"The list is in arbitrary order. It does not include the special\n"
901"entries \'.\' and \'..\' even if they are present in the directory.");
902
903#define OS_LISTDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300904 {"listdir", (PyCFunction)os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300905
906static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300907os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300908
909static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200910os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300911{
912 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300913 static const char * const _keywords[] = {"path", NULL};
914 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300915 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
916
Victor Stinner3e1fad62017-01-17 01:29:01 +0100917 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300918 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300919 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300920 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300921 return_value = os_listdir_impl(module, &path);
922
923exit:
924 /* Cleanup for path */
925 path_cleanup(&path);
926
927 return return_value;
928}
929
930#if defined(MS_WINDOWS)
931
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300932PyDoc_STRVAR(os__getfullpathname__doc__,
933"_getfullpathname($module, path, /)\n"
934"--\n"
935"\n");
936
937#define OS__GETFULLPATHNAME_METHODDEF \
938 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
939
940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300941os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300942
943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300944os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300945{
946 PyObject *return_value = NULL;
947 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
948
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300949 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300951 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300952 return_value = os__getfullpathname_impl(module, &path);
953
954exit:
955 /* Cleanup for path */
956 path_cleanup(&path);
957
958 return return_value;
959}
960
961#endif /* defined(MS_WINDOWS) */
962
963#if defined(MS_WINDOWS)
964
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300965PyDoc_STRVAR(os__getfinalpathname__doc__,
966"_getfinalpathname($module, path, /)\n"
967"--\n"
968"\n"
969"A helper function for samepath on windows.");
970
971#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300972 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300973
974static PyObject *
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -0800975os__getfinalpathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300976
977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300978os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300979{
980 PyObject *return_value = NULL;
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -0800981 path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300982
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -0800983 if (!PyArg_Parse(arg, "O&:_getfinalpathname", path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300985 }
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -0800986 return_value = os__getfinalpathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300987
988exit:
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -0800989 /* Cleanup for path */
990 path_cleanup(&path);
991
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300992 return return_value;
993}
994
995#endif /* defined(MS_WINDOWS) */
996
997#if defined(MS_WINDOWS)
998
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300999PyDoc_STRVAR(os__isdir__doc__,
1000"_isdir($module, path, /)\n"
1001"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +02001002"\n"
1003"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001004
1005#define OS__ISDIR_METHODDEF \
1006 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1007
1008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001009os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001010
1011static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001012os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001013{
1014 PyObject *return_value = NULL;
1015 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1016
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001017 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001018 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001019 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001020 return_value = os__isdir_impl(module, &path);
1021
1022exit:
1023 /* Cleanup for path */
1024 path_cleanup(&path);
1025
1026 return return_value;
1027}
1028
1029#endif /* defined(MS_WINDOWS) */
1030
1031#if defined(MS_WINDOWS)
1032
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001033PyDoc_STRVAR(os__getvolumepathname__doc__,
1034"_getvolumepathname($module, /, path)\n"
1035"--\n"
1036"\n"
1037"A helper function for ismount on Win32.");
1038
1039#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001040 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001041
1042static PyObject *
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08001043os__getvolumepathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001044
1045static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001046os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001047{
1048 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001049 static const char * const _keywords[] = {"path", NULL};
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08001050 static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0};
1051 path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052
Victor Stinner3e1fad62017-01-17 01:29:01 +01001053 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08001054 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001055 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001056 }
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08001057 return_value = os__getvolumepathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001058
1059exit:
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08001060 /* Cleanup for path */
1061 path_cleanup(&path);
1062
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001063 return return_value;
1064}
1065
1066#endif /* defined(MS_WINDOWS) */
1067
1068PyDoc_STRVAR(os_mkdir__doc__,
1069"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1070"--\n"
1071"\n"
1072"Create a directory.\n"
1073"\n"
1074"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1075" and path should be relative; path will then be relative to that directory.\n"
1076"dir_fd may not be implemented on your platform.\n"
1077" If it is unavailable, using it will raise a NotImplementedError.\n"
1078"\n"
1079"The mode argument is ignored on Windows.");
1080
1081#define OS_MKDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001082 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001083
1084static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001085os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001086
1087static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001088os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001089{
1090 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001091 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1092 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1094 int mode = 511;
1095 int dir_fd = DEFAULT_DIR_FD;
1096
Victor Stinner3e1fad62017-01-17 01:29:01 +01001097 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001098 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001099 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001100 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001101 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1102
1103exit:
1104 /* Cleanup for path */
1105 path_cleanup(&path);
1106
1107 return return_value;
1108}
1109
1110#if defined(HAVE_NICE)
1111
1112PyDoc_STRVAR(os_nice__doc__,
1113"nice($module, increment, /)\n"
1114"--\n"
1115"\n"
1116"Add increment to the priority of process and return the new priority.");
1117
1118#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001119 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001120
1121static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001122os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001123
1124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001125os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001126{
1127 PyObject *return_value = NULL;
1128 int increment;
1129
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001130 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001131 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001132 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001133 return_value = os_nice_impl(module, increment);
1134
1135exit:
1136 return return_value;
1137}
1138
1139#endif /* defined(HAVE_NICE) */
1140
1141#if defined(HAVE_GETPRIORITY)
1142
1143PyDoc_STRVAR(os_getpriority__doc__,
1144"getpriority($module, /, which, who)\n"
1145"--\n"
1146"\n"
1147"Return program scheduling priority.");
1148
1149#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001150 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001151
1152static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001153os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001154
1155static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001156os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001157{
1158 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001159 static const char * const _keywords[] = {"which", "who", NULL};
1160 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001161 int which;
1162 int who;
1163
Victor Stinner3e1fad62017-01-17 01:29:01 +01001164 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001165 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001166 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001167 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001168 return_value = os_getpriority_impl(module, which, who);
1169
1170exit:
1171 return return_value;
1172}
1173
1174#endif /* defined(HAVE_GETPRIORITY) */
1175
1176#if defined(HAVE_SETPRIORITY)
1177
1178PyDoc_STRVAR(os_setpriority__doc__,
1179"setpriority($module, /, which, who, priority)\n"
1180"--\n"
1181"\n"
1182"Set program scheduling priority.");
1183
1184#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001185 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001186
1187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001188os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001189
1190static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001191os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001192{
1193 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001194 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1195 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 int which;
1197 int who;
1198 int priority;
1199
Victor Stinner3e1fad62017-01-17 01:29:01 +01001200 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001201 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001202 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001203 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001204 return_value = os_setpriority_impl(module, which, who, priority);
1205
1206exit:
1207 return return_value;
1208}
1209
1210#endif /* defined(HAVE_SETPRIORITY) */
1211
1212PyDoc_STRVAR(os_rename__doc__,
1213"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1214"--\n"
1215"\n"
1216"Rename a file or directory.\n"
1217"\n"
1218"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1219" descriptor open to a directory, and the respective path string (src or dst)\n"
1220" should be relative; the path will then be relative to that directory.\n"
1221"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1222" If they are unavailable, using them will raise a NotImplementedError.");
1223
1224#define OS_RENAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001225 {"rename", (PyCFunction)os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001226
1227static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001228os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001229 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001230
1231static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001232os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001233{
1234 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001235 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1236 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001237 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1238 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1239 int src_dir_fd = DEFAULT_DIR_FD;
1240 int dst_dir_fd = DEFAULT_DIR_FD;
1241
Victor Stinner3e1fad62017-01-17 01:29:01 +01001242 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001243 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001244 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001245 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001246 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1247
1248exit:
1249 /* Cleanup for src */
1250 path_cleanup(&src);
1251 /* Cleanup for dst */
1252 path_cleanup(&dst);
1253
1254 return return_value;
1255}
1256
1257PyDoc_STRVAR(os_replace__doc__,
1258"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1259"--\n"
1260"\n"
1261"Rename a file or directory, overwriting the destination.\n"
1262"\n"
1263"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1264" descriptor open to a directory, and the respective path string (src or dst)\n"
1265" should be relative; the path will then be relative to that directory.\n"
1266"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
Benjamin Peterson00cc0fe2019-02-12 20:36:09 -08001267" If they are unavailable, using them will raise a NotImplementedError.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001268
1269#define OS_REPLACE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001270 {"replace", (PyCFunction)os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001271
1272static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001273os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1274 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001275
1276static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001277os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001278{
1279 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001280 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1281 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001282 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1283 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1284 int src_dir_fd = DEFAULT_DIR_FD;
1285 int dst_dir_fd = DEFAULT_DIR_FD;
1286
Victor Stinner3e1fad62017-01-17 01:29:01 +01001287 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001288 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001289 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001290 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001291 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1292
1293exit:
1294 /* Cleanup for src */
1295 path_cleanup(&src);
1296 /* Cleanup for dst */
1297 path_cleanup(&dst);
1298
1299 return return_value;
1300}
1301
1302PyDoc_STRVAR(os_rmdir__doc__,
1303"rmdir($module, /, path, *, dir_fd=None)\n"
1304"--\n"
1305"\n"
1306"Remove a directory.\n"
1307"\n"
1308"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1309" and path should be relative; path will then be relative to that directory.\n"
1310"dir_fd may not be implemented on your platform.\n"
1311" If it is unavailable, using it will raise a NotImplementedError.");
1312
1313#define OS_RMDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001314 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001315
1316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001317os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001318
1319static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001320os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001321{
1322 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001323 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1324 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001325 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1326 int dir_fd = DEFAULT_DIR_FD;
1327
Victor Stinner3e1fad62017-01-17 01:29:01 +01001328 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001329 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001330 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001331 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001332 return_value = os_rmdir_impl(module, &path, dir_fd);
1333
1334exit:
1335 /* Cleanup for path */
1336 path_cleanup(&path);
1337
1338 return return_value;
1339}
1340
1341#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1342
1343PyDoc_STRVAR(os_system__doc__,
1344"system($module, /, command)\n"
1345"--\n"
1346"\n"
1347"Execute the command in a subshell.");
1348
1349#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001350 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001351
1352static long
Serhiy Storchaka45a7b762018-12-14 11:56:48 +02001353os_system_impl(PyObject *module, const Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001354
1355static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001356os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001357{
1358 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001359 static const char * const _keywords[] = {"command", NULL};
1360 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka45a7b762018-12-14 11:56:48 +02001361 const Py_UNICODE *command;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001362 long _return_value;
1363
Victor Stinner3e1fad62017-01-17 01:29:01 +01001364 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001365 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001366 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001367 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001368 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001369 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001370 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001371 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001372 return_value = PyLong_FromLong(_return_value);
1373
1374exit:
1375 return return_value;
1376}
1377
1378#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1379
1380#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1381
1382PyDoc_STRVAR(os_system__doc__,
1383"system($module, /, command)\n"
1384"--\n"
1385"\n"
1386"Execute the command in a subshell.");
1387
1388#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001389 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390
1391static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001392os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001393
1394static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001395os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001396{
1397 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001398 static const char * const _keywords[] = {"command", NULL};
1399 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001400 PyObject *command = NULL;
1401 long _return_value;
1402
Victor Stinner3e1fad62017-01-17 01:29:01 +01001403 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001404 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001405 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001406 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001407 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001408 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001409 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001410 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001411 return_value = PyLong_FromLong(_return_value);
1412
1413exit:
1414 /* Cleanup for command */
1415 Py_XDECREF(command);
1416
1417 return return_value;
1418}
1419
1420#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1421
1422PyDoc_STRVAR(os_umask__doc__,
1423"umask($module, mask, /)\n"
1424"--\n"
1425"\n"
1426"Set the current numeric umask and return the previous umask.");
1427
1428#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001429 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001430
1431static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001432os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001433
1434static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001435os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001436{
1437 PyObject *return_value = NULL;
1438 int mask;
1439
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001440 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001441 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001442 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001443 return_value = os_umask_impl(module, mask);
1444
1445exit:
1446 return return_value;
1447}
1448
1449PyDoc_STRVAR(os_unlink__doc__,
1450"unlink($module, /, path, *, dir_fd=None)\n"
1451"--\n"
1452"\n"
1453"Remove a file (same as remove()).\n"
1454"\n"
1455"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1456" and path should be relative; path will then be relative to that directory.\n"
1457"dir_fd may not be implemented on your platform.\n"
1458" If it is unavailable, using it will raise a NotImplementedError.");
1459
1460#define OS_UNLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001461 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001462
1463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001464os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001465
1466static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001467os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001468{
1469 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001470 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1471 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001472 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1473 int dir_fd = DEFAULT_DIR_FD;
1474
Victor Stinner3e1fad62017-01-17 01:29:01 +01001475 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001476 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001477 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001478 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001479 return_value = os_unlink_impl(module, &path, dir_fd);
1480
1481exit:
1482 /* Cleanup for path */
1483 path_cleanup(&path);
1484
1485 return return_value;
1486}
1487
1488PyDoc_STRVAR(os_remove__doc__,
1489"remove($module, /, path, *, dir_fd=None)\n"
1490"--\n"
1491"\n"
1492"Remove a file (same as unlink()).\n"
1493"\n"
1494"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1495" and path should be relative; path will then be relative to that directory.\n"
1496"dir_fd may not be implemented on your platform.\n"
1497" If it is unavailable, using it will raise a NotImplementedError.");
1498
1499#define OS_REMOVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001500 {"remove", (PyCFunction)os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001501
1502static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001503os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001504
1505static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001506os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001507{
1508 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001509 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1510 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001511 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1512 int dir_fd = DEFAULT_DIR_FD;
1513
Victor Stinner3e1fad62017-01-17 01:29:01 +01001514 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001515 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001516 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001517 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001518 return_value = os_remove_impl(module, &path, dir_fd);
1519
1520exit:
1521 /* Cleanup for path */
1522 path_cleanup(&path);
1523
1524 return return_value;
1525}
1526
1527#if defined(HAVE_UNAME)
1528
1529PyDoc_STRVAR(os_uname__doc__,
1530"uname($module, /)\n"
1531"--\n"
1532"\n"
1533"Return an object identifying the current operating system.\n"
1534"\n"
1535"The object behaves like a named tuple with the following fields:\n"
1536" (sysname, nodename, release, version, machine)");
1537
1538#define OS_UNAME_METHODDEF \
1539 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1540
1541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001542os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001543
1544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001545os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001546{
1547 return os_uname_impl(module);
1548}
1549
1550#endif /* defined(HAVE_UNAME) */
1551
1552PyDoc_STRVAR(os_utime__doc__,
1553"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1554" follow_symlinks=True)\n"
1555"--\n"
1556"\n"
1557"Set the access and modified time of path.\n"
1558"\n"
1559"path may always be specified as a string.\n"
1560"On some platforms, path may also be specified as an open file descriptor.\n"
1561" If this functionality is unavailable, using it raises an exception.\n"
1562"\n"
1563"If times is not None, it must be a tuple (atime, mtime);\n"
1564" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001565"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001566" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1567" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001568"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001569"Specifying tuples for both times and ns is an error.\n"
1570"\n"
1571"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1572" and path should be relative; path will then be relative to that directory.\n"
1573"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1574" link, utime will modify the symbolic link itself instead of the file the\n"
1575" link points to.\n"
1576"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1577" as an open file descriptor.\n"
1578"dir_fd and follow_symlinks may not be available on your platform.\n"
1579" If they are unavailable, using them will raise a NotImplementedError.");
1580
1581#define OS_UTIME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001582 {"utime", (PyCFunction)os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001583
1584static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001585os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1586 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001587
1588static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001589os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001590{
1591 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001592 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1593 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001594 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1595 PyObject *times = NULL;
1596 PyObject *ns = NULL;
1597 int dir_fd = DEFAULT_DIR_FD;
1598 int follow_symlinks = 1;
1599
Victor Stinner3e1fad62017-01-17 01:29:01 +01001600 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001601 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001602 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001604 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1605
1606exit:
1607 /* Cleanup for path */
1608 path_cleanup(&path);
1609
1610 return return_value;
1611}
1612
1613PyDoc_STRVAR(os__exit__doc__,
1614"_exit($module, /, status)\n"
1615"--\n"
1616"\n"
1617"Exit to the system with specified status, without normal exit processing.");
1618
1619#define OS__EXIT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001620 {"_exit", (PyCFunction)os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001621
1622static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001623os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001624
1625static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001626os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001627{
1628 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001629 static const char * const _keywords[] = {"status", NULL};
1630 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001631 int status;
1632
Victor Stinner3e1fad62017-01-17 01:29:01 +01001633 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001634 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001635 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001636 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001637 return_value = os__exit_impl(module, status);
1638
1639exit:
1640 return return_value;
1641}
1642
1643#if defined(HAVE_EXECV)
1644
1645PyDoc_STRVAR(os_execv__doc__,
1646"execv($module, path, argv, /)\n"
1647"--\n"
1648"\n"
1649"Execute an executable path with arguments, replacing current process.\n"
1650"\n"
1651" path\n"
1652" Path of executable file.\n"
1653" argv\n"
1654" Tuple or list of strings.");
1655
1656#define OS_EXECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001657 {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001658
1659static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001660os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001661
1662static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001663os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001664{
1665 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001666 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001667 PyObject *argv;
1668
Sylvain74453812017-06-10 06:51:48 +02001669 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
1670 path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001671 goto exit;
1672 }
Steve Dowercc16be82016-09-08 10:35:16 -07001673 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001674
1675exit:
1676 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001677 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001678
1679 return return_value;
1680}
1681
1682#endif /* defined(HAVE_EXECV) */
1683
1684#if defined(HAVE_EXECV)
1685
1686PyDoc_STRVAR(os_execve__doc__,
1687"execve($module, /, path, argv, env)\n"
1688"--\n"
1689"\n"
1690"Execute an executable path with arguments, replacing current process.\n"
1691"\n"
1692" path\n"
1693" Path of executable file.\n"
1694" argv\n"
1695" Tuple or list of strings.\n"
1696" env\n"
1697" Dictionary of strings mapping to strings.");
1698
1699#define OS_EXECVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001700 {"execve", (PyCFunction)os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001701
1702static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001703os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001704
1705static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001706os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001707{
1708 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001709 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1710 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001711 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1712 PyObject *argv;
1713 PyObject *env;
1714
Victor Stinner3e1fad62017-01-17 01:29:01 +01001715 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001716 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001717 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001718 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001719 return_value = os_execve_impl(module, &path, argv, env);
1720
1721exit:
1722 /* Cleanup for path */
1723 path_cleanup(&path);
1724
1725 return return_value;
1726}
1727
1728#endif /* defined(HAVE_EXECV) */
1729
Steve Dowercc16be82016-09-08 10:35:16 -07001730#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001731
1732PyDoc_STRVAR(os_spawnv__doc__,
1733"spawnv($module, mode, path, argv, /)\n"
1734"--\n"
1735"\n"
1736"Execute the program specified by path in a new process.\n"
1737"\n"
1738" mode\n"
1739" Mode of process creation.\n"
1740" path\n"
1741" Path of executable file.\n"
1742" argv\n"
1743" Tuple or list of strings.");
1744
1745#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001746 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001747
1748static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001749os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001750
1751static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001752os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001753{
1754 PyObject *return_value = NULL;
1755 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001756 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001757 PyObject *argv;
1758
Sylvain74453812017-06-10 06:51:48 +02001759 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1760 &mode, path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001761 goto exit;
1762 }
Steve Dowercc16be82016-09-08 10:35:16 -07001763 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001764
1765exit:
1766 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001767 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001768
1769 return return_value;
1770}
1771
Steve Dowercc16be82016-09-08 10:35:16 -07001772#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001773
Steve Dowercc16be82016-09-08 10:35:16 -07001774#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001775
1776PyDoc_STRVAR(os_spawnve__doc__,
1777"spawnve($module, mode, path, argv, env, /)\n"
1778"--\n"
1779"\n"
1780"Execute the program specified by path in a new process.\n"
1781"\n"
1782" mode\n"
1783" Mode of process creation.\n"
1784" path\n"
1785" Path of executable file.\n"
1786" argv\n"
1787" Tuple or list of strings.\n"
1788" env\n"
1789" Dictionary of strings mapping to strings.");
1790
1791#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001792 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001793
1794static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001795os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001796 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001797
1798static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001799os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001800{
1801 PyObject *return_value = NULL;
1802 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001803 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001804 PyObject *argv;
1805 PyObject *env;
1806
Sylvain74453812017-06-10 06:51:48 +02001807 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1808 &mode, path_converter, &path, &argv, &env)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001809 goto exit;
1810 }
Steve Dowercc16be82016-09-08 10:35:16 -07001811 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001812
1813exit:
1814 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001815 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001816
1817 return return_value;
1818}
1819
Steve Dowercc16be82016-09-08 10:35:16 -07001820#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001821
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001822#if defined(HAVE_FORK)
1823
1824PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001825"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1826" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001827"--\n"
1828"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001829"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001830"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001831" before\n"
1832" A callable to be called in the parent before the fork() syscall.\n"
1833" after_in_child\n"
1834" A callable to be called in the child after fork().\n"
1835" after_in_parent\n"
1836" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001837"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001838"\'before\' callbacks are called in reverse order.\n"
1839"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001840
1841#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001842 {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001843
1844static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001845os_register_at_fork_impl(PyObject *module, PyObject *before,
1846 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001847
1848static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001849os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001850{
1851 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001852 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1853 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1854 PyObject *before = NULL;
1855 PyObject *after_in_child = NULL;
1856 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001857
1858 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001859 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001860 goto exit;
1861 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001862 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001863
1864exit:
1865 return return_value;
1866}
1867
1868#endif /* defined(HAVE_FORK) */
1869
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001870#if defined(HAVE_FORK1)
1871
1872PyDoc_STRVAR(os_fork1__doc__,
1873"fork1($module, /)\n"
1874"--\n"
1875"\n"
1876"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1877"\n"
1878"Return 0 to child process and PID of child to parent process.");
1879
1880#define OS_FORK1_METHODDEF \
1881 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1882
1883static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001884os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001885
1886static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001887os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001888{
1889 return os_fork1_impl(module);
1890}
1891
1892#endif /* defined(HAVE_FORK1) */
1893
1894#if defined(HAVE_FORK)
1895
1896PyDoc_STRVAR(os_fork__doc__,
1897"fork($module, /)\n"
1898"--\n"
1899"\n"
1900"Fork a child process.\n"
1901"\n"
1902"Return 0 to child process and PID of child to parent process.");
1903
1904#define OS_FORK_METHODDEF \
1905 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1906
1907static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001908os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001909
1910static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001911os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001912{
1913 return os_fork_impl(module);
1914}
1915
1916#endif /* defined(HAVE_FORK) */
1917
1918#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1919
1920PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1921"sched_get_priority_max($module, /, policy)\n"
1922"--\n"
1923"\n"
1924"Get the maximum scheduling priority for policy.");
1925
1926#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001927 {"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 +03001928
1929static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001930os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001931
1932static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001933os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001934{
1935 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001936 static const char * const _keywords[] = {"policy", NULL};
1937 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001938 int policy;
1939
Victor Stinner3e1fad62017-01-17 01:29:01 +01001940 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001941 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001942 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001943 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001944 return_value = os_sched_get_priority_max_impl(module, policy);
1945
1946exit:
1947 return return_value;
1948}
1949
1950#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1951
1952#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1953
1954PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1955"sched_get_priority_min($module, /, policy)\n"
1956"--\n"
1957"\n"
1958"Get the minimum scheduling priority for policy.");
1959
1960#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001961 {"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 +03001962
1963static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001964os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001965
1966static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001967os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001968{
1969 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001970 static const char * const _keywords[] = {"policy", NULL};
1971 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001972 int policy;
1973
Victor Stinner3e1fad62017-01-17 01:29:01 +01001974 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001975 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001976 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001977 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001978 return_value = os_sched_get_priority_min_impl(module, policy);
1979
1980exit:
1981 return return_value;
1982}
1983
1984#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1985
1986#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1987
1988PyDoc_STRVAR(os_sched_getscheduler__doc__,
1989"sched_getscheduler($module, pid, /)\n"
1990"--\n"
1991"\n"
1992"Get the scheduling policy for the process identifiedy by pid.\n"
1993"\n"
1994"Passing 0 for pid returns the scheduling policy for the calling process.");
1995
1996#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001997 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001998
1999static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002000os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002001
2002static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002003os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002004{
2005 PyObject *return_value = NULL;
2006 pid_t pid;
2007
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002008 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002009 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002010 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002011 return_value = os_sched_getscheduler_impl(module, pid);
2012
2013exit:
2014 return return_value;
2015}
2016
2017#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2018
2019#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
2020
2021PyDoc_STRVAR(os_sched_param__doc__,
2022"sched_param(sched_priority)\n"
2023"--\n"
2024"\n"
2025"Current has only one field: sched_priority\");\n"
2026"\n"
2027" sched_priority\n"
2028" A scheduling parameter.");
2029
2030static PyObject *
2031os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2032
2033static PyObject *
2034os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2035{
2036 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002037 static const char * const _keywords[] = {"sched_priority", NULL};
2038 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002039 PyObject *sched_priority;
2040
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002041 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002042 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002043 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002044 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002045 return_value = os_sched_param_impl(type, sched_priority);
2046
2047exit:
2048 return return_value;
2049}
2050
2051#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2052
2053#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2054
2055PyDoc_STRVAR(os_sched_setscheduler__doc__,
2056"sched_setscheduler($module, pid, policy, param, /)\n"
2057"--\n"
2058"\n"
2059"Set the scheduling policy for the process identified by pid.\n"
2060"\n"
2061"If pid is 0, the calling process is changed.\n"
2062"param is an instance of sched_param.");
2063
2064#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002065 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002066
2067static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002068os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002069 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002070
2071static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002072os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002073{
2074 PyObject *return_value = NULL;
2075 pid_t pid;
2076 int policy;
2077 struct sched_param param;
2078
Sylvain74453812017-06-10 06:51:48 +02002079 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2080 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002081 goto exit;
2082 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002083 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2084
2085exit:
2086 return return_value;
2087}
2088
2089#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2090
2091#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2092
2093PyDoc_STRVAR(os_sched_getparam__doc__,
2094"sched_getparam($module, pid, /)\n"
2095"--\n"
2096"\n"
2097"Returns scheduling parameters for the process identified by pid.\n"
2098"\n"
2099"If pid is 0, returns parameters for the calling process.\n"
2100"Return value is an instance of sched_param.");
2101
2102#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002103 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002104
2105static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002106os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002107
2108static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002109os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002110{
2111 PyObject *return_value = NULL;
2112 pid_t pid;
2113
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002114 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002115 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002116 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002117 return_value = os_sched_getparam_impl(module, pid);
2118
2119exit:
2120 return return_value;
2121}
2122
2123#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2124
2125#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2126
2127PyDoc_STRVAR(os_sched_setparam__doc__,
2128"sched_setparam($module, pid, param, /)\n"
2129"--\n"
2130"\n"
2131"Set scheduling parameters for the process identified by pid.\n"
2132"\n"
2133"If pid is 0, sets parameters for the calling process.\n"
2134"param should be an instance of sched_param.");
2135
2136#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002137 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002138
2139static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002140os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002141 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002142
2143static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002144os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002145{
2146 PyObject *return_value = NULL;
2147 pid_t pid;
2148 struct sched_param param;
2149
Sylvain74453812017-06-10 06:51:48 +02002150 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2151 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002152 goto exit;
2153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002154 return_value = os_sched_setparam_impl(module, pid, &param);
2155
2156exit:
2157 return return_value;
2158}
2159
2160#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2161
2162#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2163
2164PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2165"sched_rr_get_interval($module, pid, /)\n"
2166"--\n"
2167"\n"
2168"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2169"\n"
2170"Value returned is a float.");
2171
2172#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002173 {"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 +03002174
2175static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002176os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002177
2178static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002179os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002180{
2181 PyObject *return_value = NULL;
2182 pid_t pid;
2183 double _return_value;
2184
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002185 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002186 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002187 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002188 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002189 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002190 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002191 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002192 return_value = PyFloat_FromDouble(_return_value);
2193
2194exit:
2195 return return_value;
2196}
2197
2198#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2199
2200#if defined(HAVE_SCHED_H)
2201
2202PyDoc_STRVAR(os_sched_yield__doc__,
2203"sched_yield($module, /)\n"
2204"--\n"
2205"\n"
2206"Voluntarily relinquish the CPU.");
2207
2208#define OS_SCHED_YIELD_METHODDEF \
2209 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2210
2211static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002212os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002213
2214static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002215os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002216{
2217 return os_sched_yield_impl(module);
2218}
2219
2220#endif /* defined(HAVE_SCHED_H) */
2221
2222#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2223
2224PyDoc_STRVAR(os_sched_setaffinity__doc__,
2225"sched_setaffinity($module, pid, mask, /)\n"
2226"--\n"
2227"\n"
2228"Set the CPU affinity of the process identified by pid to mask.\n"
2229"\n"
2230"mask should be an iterable of integers identifying CPUs.");
2231
2232#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002233 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002234
2235static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002236os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002237
2238static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002239os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002240{
2241 PyObject *return_value = NULL;
2242 pid_t pid;
2243 PyObject *mask;
2244
Sylvain74453812017-06-10 06:51:48 +02002245 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2246 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002247 goto exit;
2248 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002249 return_value = os_sched_setaffinity_impl(module, pid, mask);
2250
2251exit:
2252 return return_value;
2253}
2254
2255#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2256
2257#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2258
2259PyDoc_STRVAR(os_sched_getaffinity__doc__,
2260"sched_getaffinity($module, pid, /)\n"
2261"--\n"
2262"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002263"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002264"\n"
2265"The affinity is returned as a set of CPU identifiers.");
2266
2267#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002268 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002269
2270static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002271os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002272
2273static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002274os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002275{
2276 PyObject *return_value = NULL;
2277 pid_t pid;
2278
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002279 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002280 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002281 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002282 return_value = os_sched_getaffinity_impl(module, pid);
2283
2284exit:
2285 return return_value;
2286}
2287
2288#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2289
2290#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2291
2292PyDoc_STRVAR(os_openpty__doc__,
2293"openpty($module, /)\n"
2294"--\n"
2295"\n"
2296"Open a pseudo-terminal.\n"
2297"\n"
2298"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2299"for both the master and slave ends.");
2300
2301#define OS_OPENPTY_METHODDEF \
2302 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2303
2304static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002305os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002306
2307static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002308os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002309{
2310 return os_openpty_impl(module);
2311}
2312
2313#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2314
2315#if defined(HAVE_FORKPTY)
2316
2317PyDoc_STRVAR(os_forkpty__doc__,
2318"forkpty($module, /)\n"
2319"--\n"
2320"\n"
2321"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2322"\n"
2323"Returns a tuple of (pid, master_fd).\n"
2324"Like fork(), return pid of 0 to the child process,\n"
2325"and pid of child to the parent process.\n"
2326"To both, return fd of newly opened pseudo-terminal.");
2327
2328#define OS_FORKPTY_METHODDEF \
2329 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2330
2331static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002332os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002333
2334static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002335os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002336{
2337 return os_forkpty_impl(module);
2338}
2339
2340#endif /* defined(HAVE_FORKPTY) */
2341
2342#if defined(HAVE_GETEGID)
2343
2344PyDoc_STRVAR(os_getegid__doc__,
2345"getegid($module, /)\n"
2346"--\n"
2347"\n"
2348"Return the current process\'s effective group id.");
2349
2350#define OS_GETEGID_METHODDEF \
2351 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2352
2353static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002354os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002355
2356static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002357os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002358{
2359 return os_getegid_impl(module);
2360}
2361
2362#endif /* defined(HAVE_GETEGID) */
2363
2364#if defined(HAVE_GETEUID)
2365
2366PyDoc_STRVAR(os_geteuid__doc__,
2367"geteuid($module, /)\n"
2368"--\n"
2369"\n"
2370"Return the current process\'s effective user id.");
2371
2372#define OS_GETEUID_METHODDEF \
2373 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2374
2375static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002376os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002377
2378static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002379os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002380{
2381 return os_geteuid_impl(module);
2382}
2383
2384#endif /* defined(HAVE_GETEUID) */
2385
2386#if defined(HAVE_GETGID)
2387
2388PyDoc_STRVAR(os_getgid__doc__,
2389"getgid($module, /)\n"
2390"--\n"
2391"\n"
2392"Return the current process\'s group id.");
2393
2394#define OS_GETGID_METHODDEF \
2395 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2396
2397static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002398os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002399
2400static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002401os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002402{
2403 return os_getgid_impl(module);
2404}
2405
2406#endif /* defined(HAVE_GETGID) */
2407
Berker Peksag39404992016-09-15 20:45:16 +03002408#if defined(HAVE_GETPID)
2409
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002410PyDoc_STRVAR(os_getpid__doc__,
2411"getpid($module, /)\n"
2412"--\n"
2413"\n"
2414"Return the current process id.");
2415
2416#define OS_GETPID_METHODDEF \
2417 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2418
2419static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002420os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002421
2422static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002423os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002424{
2425 return os_getpid_impl(module);
2426}
2427
Berker Peksag39404992016-09-15 20:45:16 +03002428#endif /* defined(HAVE_GETPID) */
2429
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002430#if defined(HAVE_GETGROUPS)
2431
2432PyDoc_STRVAR(os_getgroups__doc__,
2433"getgroups($module, /)\n"
2434"--\n"
2435"\n"
2436"Return list of supplemental group IDs for the process.");
2437
2438#define OS_GETGROUPS_METHODDEF \
2439 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2440
2441static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002442os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002443
2444static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002445os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002446{
2447 return os_getgroups_impl(module);
2448}
2449
2450#endif /* defined(HAVE_GETGROUPS) */
2451
2452#if defined(HAVE_GETPGID)
2453
2454PyDoc_STRVAR(os_getpgid__doc__,
2455"getpgid($module, /, pid)\n"
2456"--\n"
2457"\n"
2458"Call the system call getpgid(), and return the result.");
2459
2460#define OS_GETPGID_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002461 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002462
2463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002464os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002465
2466static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002467os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002468{
2469 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002470 static const char * const _keywords[] = {"pid", NULL};
2471 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002472 pid_t pid;
2473
Victor Stinner3e1fad62017-01-17 01:29:01 +01002474 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002475 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002476 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002477 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002478 return_value = os_getpgid_impl(module, pid);
2479
2480exit:
2481 return return_value;
2482}
2483
2484#endif /* defined(HAVE_GETPGID) */
2485
2486#if defined(HAVE_GETPGRP)
2487
2488PyDoc_STRVAR(os_getpgrp__doc__,
2489"getpgrp($module, /)\n"
2490"--\n"
2491"\n"
2492"Return the current process group id.");
2493
2494#define OS_GETPGRP_METHODDEF \
2495 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2496
2497static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002498os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002499
2500static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002501os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002502{
2503 return os_getpgrp_impl(module);
2504}
2505
2506#endif /* defined(HAVE_GETPGRP) */
2507
2508#if defined(HAVE_SETPGRP)
2509
2510PyDoc_STRVAR(os_setpgrp__doc__,
2511"setpgrp($module, /)\n"
2512"--\n"
2513"\n"
2514"Make the current process the leader of its process group.");
2515
2516#define OS_SETPGRP_METHODDEF \
2517 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2518
2519static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002520os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002521
2522static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002523os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002524{
2525 return os_setpgrp_impl(module);
2526}
2527
2528#endif /* defined(HAVE_SETPGRP) */
2529
2530#if defined(HAVE_GETPPID)
2531
2532PyDoc_STRVAR(os_getppid__doc__,
2533"getppid($module, /)\n"
2534"--\n"
2535"\n"
2536"Return the parent\'s process id.\n"
2537"\n"
2538"If the parent process has already exited, Windows machines will still\n"
2539"return its id; others systems will return the id of the \'init\' process (1).");
2540
2541#define OS_GETPPID_METHODDEF \
2542 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2543
2544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002545os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002546
2547static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002548os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002549{
2550 return os_getppid_impl(module);
2551}
2552
2553#endif /* defined(HAVE_GETPPID) */
2554
2555#if defined(HAVE_GETLOGIN)
2556
2557PyDoc_STRVAR(os_getlogin__doc__,
2558"getlogin($module, /)\n"
2559"--\n"
2560"\n"
2561"Return the actual login name.");
2562
2563#define OS_GETLOGIN_METHODDEF \
2564 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2565
2566static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002567os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002568
2569static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002570os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002571{
2572 return os_getlogin_impl(module);
2573}
2574
2575#endif /* defined(HAVE_GETLOGIN) */
2576
2577#if defined(HAVE_GETUID)
2578
2579PyDoc_STRVAR(os_getuid__doc__,
2580"getuid($module, /)\n"
2581"--\n"
2582"\n"
2583"Return the current process\'s user id.");
2584
2585#define OS_GETUID_METHODDEF \
2586 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2587
2588static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002589os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002590
2591static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002592os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002593{
2594 return os_getuid_impl(module);
2595}
2596
2597#endif /* defined(HAVE_GETUID) */
2598
2599#if defined(HAVE_KILL)
2600
2601PyDoc_STRVAR(os_kill__doc__,
2602"kill($module, pid, signal, /)\n"
2603"--\n"
2604"\n"
2605"Kill a process with a signal.");
2606
2607#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002608 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002609
2610static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002611os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002612
2613static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002614os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002615{
2616 PyObject *return_value = NULL;
2617 pid_t pid;
2618 Py_ssize_t signal;
2619
Sylvain74453812017-06-10 06:51:48 +02002620 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2621 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002622 goto exit;
2623 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002624 return_value = os_kill_impl(module, pid, signal);
2625
2626exit:
2627 return return_value;
2628}
2629
2630#endif /* defined(HAVE_KILL) */
2631
2632#if defined(HAVE_KILLPG)
2633
2634PyDoc_STRVAR(os_killpg__doc__,
2635"killpg($module, pgid, signal, /)\n"
2636"--\n"
2637"\n"
2638"Kill a process group with a signal.");
2639
2640#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002641 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002642
2643static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002644os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002645
2646static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002647os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002648{
2649 PyObject *return_value = NULL;
2650 pid_t pgid;
2651 int signal;
2652
Sylvain74453812017-06-10 06:51:48 +02002653 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2654 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002655 goto exit;
2656 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002657 return_value = os_killpg_impl(module, pgid, signal);
2658
2659exit:
2660 return return_value;
2661}
2662
2663#endif /* defined(HAVE_KILLPG) */
2664
2665#if defined(HAVE_PLOCK)
2666
2667PyDoc_STRVAR(os_plock__doc__,
2668"plock($module, op, /)\n"
2669"--\n"
2670"\n"
2671"Lock program segments into memory.\");");
2672
2673#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002674 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002675
2676static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002677os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002678
2679static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002680os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002681{
2682 PyObject *return_value = NULL;
2683 int op;
2684
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002685 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002686 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002687 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002688 return_value = os_plock_impl(module, op);
2689
2690exit:
2691 return return_value;
2692}
2693
2694#endif /* defined(HAVE_PLOCK) */
2695
2696#if defined(HAVE_SETUID)
2697
2698PyDoc_STRVAR(os_setuid__doc__,
2699"setuid($module, uid, /)\n"
2700"--\n"
2701"\n"
2702"Set the current process\'s user id.");
2703
2704#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002705 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002706
2707static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002708os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002709
2710static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002711os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002712{
2713 PyObject *return_value = NULL;
2714 uid_t uid;
2715
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002716 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002717 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002718 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002719 return_value = os_setuid_impl(module, uid);
2720
2721exit:
2722 return return_value;
2723}
2724
2725#endif /* defined(HAVE_SETUID) */
2726
2727#if defined(HAVE_SETEUID)
2728
2729PyDoc_STRVAR(os_seteuid__doc__,
2730"seteuid($module, euid, /)\n"
2731"--\n"
2732"\n"
2733"Set the current process\'s effective user id.");
2734
2735#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002736 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002737
2738static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002739os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002740
2741static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002742os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002743{
2744 PyObject *return_value = NULL;
2745 uid_t euid;
2746
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002747 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002748 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002749 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002750 return_value = os_seteuid_impl(module, euid);
2751
2752exit:
2753 return return_value;
2754}
2755
2756#endif /* defined(HAVE_SETEUID) */
2757
2758#if defined(HAVE_SETEGID)
2759
2760PyDoc_STRVAR(os_setegid__doc__,
2761"setegid($module, egid, /)\n"
2762"--\n"
2763"\n"
2764"Set the current process\'s effective group id.");
2765
2766#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002767 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002768
2769static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002770os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002771
2772static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002773os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002774{
2775 PyObject *return_value = NULL;
2776 gid_t egid;
2777
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002778 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002779 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002780 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002781 return_value = os_setegid_impl(module, egid);
2782
2783exit:
2784 return return_value;
2785}
2786
2787#endif /* defined(HAVE_SETEGID) */
2788
2789#if defined(HAVE_SETREUID)
2790
2791PyDoc_STRVAR(os_setreuid__doc__,
2792"setreuid($module, ruid, euid, /)\n"
2793"--\n"
2794"\n"
2795"Set the current process\'s real and effective user ids.");
2796
2797#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002798 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002799
2800static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002801os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002802
2803static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002804os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002805{
2806 PyObject *return_value = NULL;
2807 uid_t ruid;
2808 uid_t euid;
2809
Sylvain74453812017-06-10 06:51:48 +02002810 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2811 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002812 goto exit;
2813 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002814 return_value = os_setreuid_impl(module, ruid, euid);
2815
2816exit:
2817 return return_value;
2818}
2819
2820#endif /* defined(HAVE_SETREUID) */
2821
2822#if defined(HAVE_SETREGID)
2823
2824PyDoc_STRVAR(os_setregid__doc__,
2825"setregid($module, rgid, egid, /)\n"
2826"--\n"
2827"\n"
2828"Set the current process\'s real and effective group ids.");
2829
2830#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002831 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002832
2833static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002834os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002835
2836static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002837os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002838{
2839 PyObject *return_value = NULL;
2840 gid_t rgid;
2841 gid_t egid;
2842
Sylvain74453812017-06-10 06:51:48 +02002843 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2844 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002845 goto exit;
2846 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002847 return_value = os_setregid_impl(module, rgid, egid);
2848
2849exit:
2850 return return_value;
2851}
2852
2853#endif /* defined(HAVE_SETREGID) */
2854
2855#if defined(HAVE_SETGID)
2856
2857PyDoc_STRVAR(os_setgid__doc__,
2858"setgid($module, gid, /)\n"
2859"--\n"
2860"\n"
2861"Set the current process\'s group id.");
2862
2863#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002864 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002865
2866static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002867os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002868
2869static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002870os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002871{
2872 PyObject *return_value = NULL;
2873 gid_t gid;
2874
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002875 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002876 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002877 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002878 return_value = os_setgid_impl(module, gid);
2879
2880exit:
2881 return return_value;
2882}
2883
2884#endif /* defined(HAVE_SETGID) */
2885
2886#if defined(HAVE_SETGROUPS)
2887
2888PyDoc_STRVAR(os_setgroups__doc__,
2889"setgroups($module, groups, /)\n"
2890"--\n"
2891"\n"
2892"Set the groups of the current process to list.");
2893
2894#define OS_SETGROUPS_METHODDEF \
2895 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2896
2897#endif /* defined(HAVE_SETGROUPS) */
2898
2899#if defined(HAVE_WAIT3)
2900
2901PyDoc_STRVAR(os_wait3__doc__,
2902"wait3($module, /, options)\n"
2903"--\n"
2904"\n"
2905"Wait for completion of a child process.\n"
2906"\n"
2907"Returns a tuple of information about the child process:\n"
2908" (pid, status, rusage)");
2909
2910#define OS_WAIT3_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002911 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002912
2913static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002914os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002915
2916static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002917os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002918{
2919 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002920 static const char * const _keywords[] = {"options", NULL};
2921 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002922 int options;
2923
Victor Stinner3e1fad62017-01-17 01:29:01 +01002924 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002925 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002926 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002927 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002928 return_value = os_wait3_impl(module, options);
2929
2930exit:
2931 return return_value;
2932}
2933
2934#endif /* defined(HAVE_WAIT3) */
2935
2936#if defined(HAVE_WAIT4)
2937
2938PyDoc_STRVAR(os_wait4__doc__,
2939"wait4($module, /, pid, options)\n"
2940"--\n"
2941"\n"
2942"Wait for completion of a specific child process.\n"
2943"\n"
2944"Returns a tuple of information about the child process:\n"
2945" (pid, status, rusage)");
2946
2947#define OS_WAIT4_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002948 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002949
2950static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002951os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002952
2953static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002954os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002955{
2956 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002957 static const char * const _keywords[] = {"pid", "options", NULL};
2958 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002959 pid_t pid;
2960 int options;
2961
Victor Stinner3e1fad62017-01-17 01:29:01 +01002962 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002963 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002964 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002965 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002966 return_value = os_wait4_impl(module, pid, options);
2967
2968exit:
2969 return return_value;
2970}
2971
2972#endif /* defined(HAVE_WAIT4) */
2973
2974#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2975
2976PyDoc_STRVAR(os_waitid__doc__,
2977"waitid($module, idtype, id, options, /)\n"
2978"--\n"
2979"\n"
2980"Returns the result of waiting for a process or processes.\n"
2981"\n"
2982" idtype\n"
2983" Must be one of be P_PID, P_PGID or P_ALL.\n"
2984" id\n"
2985" The id to wait on.\n"
2986" options\n"
2987" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2988" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2989"\n"
2990"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2991"no children in a waitable state.");
2992
2993#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002994 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002995
2996static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002997os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002998
2999static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003000os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003001{
3002 PyObject *return_value = NULL;
3003 idtype_t idtype;
3004 id_t id;
3005 int options;
3006
Sylvain74453812017-06-10 06:51:48 +02003007 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3008 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003009 goto exit;
3010 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003011 return_value = os_waitid_impl(module, idtype, id, options);
3012
3013exit:
3014 return return_value;
3015}
3016
3017#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3018
3019#if defined(HAVE_WAITPID)
3020
3021PyDoc_STRVAR(os_waitpid__doc__,
3022"waitpid($module, pid, options, /)\n"
3023"--\n"
3024"\n"
3025"Wait for completion of a given child process.\n"
3026"\n"
3027"Returns a tuple of information regarding the child process:\n"
3028" (pid, status)\n"
3029"\n"
3030"The options argument is ignored on Windows.");
3031
3032#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003033 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003034
3035static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003036os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003037
3038static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003039os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003040{
3041 PyObject *return_value = NULL;
3042 pid_t pid;
3043 int options;
3044
Sylvain74453812017-06-10 06:51:48 +02003045 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3046 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003047 goto exit;
3048 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003049 return_value = os_waitpid_impl(module, pid, options);
3050
3051exit:
3052 return return_value;
3053}
3054
3055#endif /* defined(HAVE_WAITPID) */
3056
3057#if defined(HAVE_CWAIT)
3058
3059PyDoc_STRVAR(os_waitpid__doc__,
3060"waitpid($module, pid, options, /)\n"
3061"--\n"
3062"\n"
3063"Wait for completion of a given process.\n"
3064"\n"
3065"Returns a tuple of information regarding the process:\n"
3066" (pid, status << 8)\n"
3067"\n"
3068"The options argument is ignored on Windows.");
3069
3070#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003071 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003072
3073static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003074os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003075
3076static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003077os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003078{
3079 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003080 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003081 int options;
3082
Sylvain74453812017-06-10 06:51:48 +02003083 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3084 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003085 goto exit;
3086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003087 return_value = os_waitpid_impl(module, pid, options);
3088
3089exit:
3090 return return_value;
3091}
3092
3093#endif /* defined(HAVE_CWAIT) */
3094
3095#if defined(HAVE_WAIT)
3096
3097PyDoc_STRVAR(os_wait__doc__,
3098"wait($module, /)\n"
3099"--\n"
3100"\n"
3101"Wait for completion of a child process.\n"
3102"\n"
3103"Returns a tuple of information about the child process:\n"
3104" (pid, status)");
3105
3106#define OS_WAIT_METHODDEF \
3107 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3108
3109static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003110os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003111
3112static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003113os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003114{
3115 return os_wait_impl(module);
3116}
3117
3118#endif /* defined(HAVE_WAIT) */
3119
3120#if defined(HAVE_SYMLINK)
3121
3122PyDoc_STRVAR(os_symlink__doc__,
3123"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3124"--\n"
3125"\n"
3126"Create a symbolic link pointing to src named dst.\n"
3127"\n"
3128"target_is_directory is required on Windows if the target is to be\n"
3129" interpreted as a directory. (On Windows, symlink requires\n"
3130" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3131" target_is_directory is ignored on non-Windows platforms.\n"
3132"\n"
3133"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3134" and path should be relative; path will then be relative to that directory.\n"
3135"dir_fd may not be implemented on your platform.\n"
3136" If it is unavailable, using it will raise a NotImplementedError.");
3137
3138#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003139 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003140
3141static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003142os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003143 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003144
3145static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003146os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003147{
3148 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003149 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3150 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003151 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3152 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3153 int target_is_directory = 0;
3154 int dir_fd = DEFAULT_DIR_FD;
3155
Victor Stinner3e1fad62017-01-17 01:29:01 +01003156 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003157 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003158 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003159 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003160 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3161
3162exit:
3163 /* Cleanup for src */
3164 path_cleanup(&src);
3165 /* Cleanup for dst */
3166 path_cleanup(&dst);
3167
3168 return return_value;
3169}
3170
3171#endif /* defined(HAVE_SYMLINK) */
3172
3173#if defined(HAVE_TIMES)
3174
3175PyDoc_STRVAR(os_times__doc__,
3176"times($module, /)\n"
3177"--\n"
3178"\n"
3179"Return a collection containing process timing information.\n"
3180"\n"
3181"The object returned behaves like a named tuple with these fields:\n"
3182" (utime, stime, cutime, cstime, elapsed_time)\n"
3183"All fields are floating point numbers.");
3184
3185#define OS_TIMES_METHODDEF \
3186 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3187
3188static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003189os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003190
3191static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003192os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003193{
3194 return os_times_impl(module);
3195}
3196
3197#endif /* defined(HAVE_TIMES) */
3198
3199#if defined(HAVE_GETSID)
3200
3201PyDoc_STRVAR(os_getsid__doc__,
3202"getsid($module, pid, /)\n"
3203"--\n"
3204"\n"
3205"Call the system call getsid(pid) and return the result.");
3206
3207#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003208 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003209
3210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003211os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003212
3213static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003214os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003215{
3216 PyObject *return_value = NULL;
3217 pid_t pid;
3218
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003219 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003220 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003221 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003222 return_value = os_getsid_impl(module, pid);
3223
3224exit:
3225 return return_value;
3226}
3227
3228#endif /* defined(HAVE_GETSID) */
3229
3230#if defined(HAVE_SETSID)
3231
3232PyDoc_STRVAR(os_setsid__doc__,
3233"setsid($module, /)\n"
3234"--\n"
3235"\n"
3236"Call the system call setsid().");
3237
3238#define OS_SETSID_METHODDEF \
3239 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3240
3241static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003242os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003243
3244static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003245os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003246{
3247 return os_setsid_impl(module);
3248}
3249
3250#endif /* defined(HAVE_SETSID) */
3251
3252#if defined(HAVE_SETPGID)
3253
3254PyDoc_STRVAR(os_setpgid__doc__,
3255"setpgid($module, pid, pgrp, /)\n"
3256"--\n"
3257"\n"
3258"Call the system call setpgid(pid, pgrp).");
3259
3260#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003261 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003262
3263static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003264os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003265
3266static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003267os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003268{
3269 PyObject *return_value = NULL;
3270 pid_t pid;
3271 pid_t pgrp;
3272
Sylvain74453812017-06-10 06:51:48 +02003273 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3274 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003275 goto exit;
3276 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003277 return_value = os_setpgid_impl(module, pid, pgrp);
3278
3279exit:
3280 return return_value;
3281}
3282
3283#endif /* defined(HAVE_SETPGID) */
3284
3285#if defined(HAVE_TCGETPGRP)
3286
3287PyDoc_STRVAR(os_tcgetpgrp__doc__,
3288"tcgetpgrp($module, fd, /)\n"
3289"--\n"
3290"\n"
3291"Return the process group associated with the terminal specified by fd.");
3292
3293#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003294 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003295
3296static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003297os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003298
3299static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003300os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003301{
3302 PyObject *return_value = NULL;
3303 int fd;
3304
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003305 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003306 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003307 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003308 return_value = os_tcgetpgrp_impl(module, fd);
3309
3310exit:
3311 return return_value;
3312}
3313
3314#endif /* defined(HAVE_TCGETPGRP) */
3315
3316#if defined(HAVE_TCSETPGRP)
3317
3318PyDoc_STRVAR(os_tcsetpgrp__doc__,
3319"tcsetpgrp($module, fd, pgid, /)\n"
3320"--\n"
3321"\n"
3322"Set the process group associated with the terminal specified by fd.");
3323
3324#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003325 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003326
3327static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003328os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003329
3330static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003331os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003332{
3333 PyObject *return_value = NULL;
3334 int fd;
3335 pid_t pgid;
3336
Sylvain74453812017-06-10 06:51:48 +02003337 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3338 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003339 goto exit;
3340 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003341 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3342
3343exit:
3344 return return_value;
3345}
3346
3347#endif /* defined(HAVE_TCSETPGRP) */
3348
3349PyDoc_STRVAR(os_open__doc__,
3350"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3351"--\n"
3352"\n"
3353"Open a file for low level IO. Returns a file descriptor (integer).\n"
3354"\n"
3355"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3356" and path should be relative; path will then be relative to that directory.\n"
3357"dir_fd may not be implemented on your platform.\n"
3358" If it is unavailable, using it will raise a NotImplementedError.");
3359
3360#define OS_OPEN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003361 {"open", (PyCFunction)os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003362
3363static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003364os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003365
3366static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003367os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003368{
3369 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003370 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3371 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003372 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3373 int flags;
3374 int mode = 511;
3375 int dir_fd = DEFAULT_DIR_FD;
3376 int _return_value;
3377
Victor Stinner3e1fad62017-01-17 01:29:01 +01003378 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003379 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003380 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003381 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003382 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003383 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003386 return_value = PyLong_FromLong((long)_return_value);
3387
3388exit:
3389 /* Cleanup for path */
3390 path_cleanup(&path);
3391
3392 return return_value;
3393}
3394
3395PyDoc_STRVAR(os_close__doc__,
3396"close($module, /, fd)\n"
3397"--\n"
3398"\n"
3399"Close a file descriptor.");
3400
3401#define OS_CLOSE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003402 {"close", (PyCFunction)os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003403
3404static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003405os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003406
3407static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003408os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003409{
3410 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003411 static const char * const _keywords[] = {"fd", NULL};
3412 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003413 int fd;
3414
Victor Stinner3e1fad62017-01-17 01:29:01 +01003415 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003416 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003417 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003418 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003419 return_value = os_close_impl(module, fd);
3420
3421exit:
3422 return return_value;
3423}
3424
3425PyDoc_STRVAR(os_closerange__doc__,
3426"closerange($module, fd_low, fd_high, /)\n"
3427"--\n"
3428"\n"
3429"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3430
3431#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003432 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003433
3434static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003435os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003436
3437static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003438os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003439{
3440 PyObject *return_value = NULL;
3441 int fd_low;
3442 int fd_high;
3443
Sylvain74453812017-06-10 06:51:48 +02003444 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3445 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003446 goto exit;
3447 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003448 return_value = os_closerange_impl(module, fd_low, fd_high);
3449
3450exit:
3451 return return_value;
3452}
3453
3454PyDoc_STRVAR(os_dup__doc__,
3455"dup($module, fd, /)\n"
3456"--\n"
3457"\n"
3458"Return a duplicate of a file descriptor.");
3459
3460#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003461 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003462
3463static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003464os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003465
3466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003467os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003468{
3469 PyObject *return_value = NULL;
3470 int fd;
3471 int _return_value;
3472
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003473 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003474 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003475 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003476 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003477 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003478 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003479 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003480 return_value = PyLong_FromLong((long)_return_value);
3481
3482exit:
3483 return return_value;
3484}
3485
3486PyDoc_STRVAR(os_dup2__doc__,
3487"dup2($module, /, fd, fd2, inheritable=True)\n"
3488"--\n"
3489"\n"
3490"Duplicate file descriptor.");
3491
3492#define OS_DUP2_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003493 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003494
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003495static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003496os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003497
3498static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003499os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003500{
3501 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003502 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3503 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003504 int fd;
3505 int fd2;
3506 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003507 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003508
Victor Stinner3e1fad62017-01-17 01:29:01 +01003509 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003510 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003511 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003512 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003513 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3514 if ((_return_value == -1) && PyErr_Occurred()) {
3515 goto exit;
3516 }
3517 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003518
3519exit:
3520 return return_value;
3521}
3522
3523#if defined(HAVE_LOCKF)
3524
3525PyDoc_STRVAR(os_lockf__doc__,
3526"lockf($module, fd, command, length, /)\n"
3527"--\n"
3528"\n"
3529"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3530"\n"
3531" fd\n"
3532" An open file descriptor.\n"
3533" command\n"
3534" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3535" length\n"
3536" The number of bytes to lock, starting at the current position.");
3537
3538#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003539 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003540
3541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003542os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003543
3544static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003545os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003546{
3547 PyObject *return_value = NULL;
3548 int fd;
3549 int command;
3550 Py_off_t length;
3551
Sylvain74453812017-06-10 06:51:48 +02003552 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3553 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003554 goto exit;
3555 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003556 return_value = os_lockf_impl(module, fd, command, length);
3557
3558exit:
3559 return return_value;
3560}
3561
3562#endif /* defined(HAVE_LOCKF) */
3563
3564PyDoc_STRVAR(os_lseek__doc__,
3565"lseek($module, fd, position, how, /)\n"
3566"--\n"
3567"\n"
3568"Set the position of a file descriptor. Return the new position.\n"
3569"\n"
3570"Return the new cursor position in number of bytes\n"
3571"relative to the beginning of the file.");
3572
3573#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003574 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003575
3576static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003577os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003578
3579static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003580os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003581{
3582 PyObject *return_value = NULL;
3583 int fd;
3584 Py_off_t position;
3585 int how;
3586 Py_off_t _return_value;
3587
Sylvain74453812017-06-10 06:51:48 +02003588 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3589 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003590 goto exit;
3591 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003592 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003593 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003594 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003595 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003596 return_value = PyLong_FromPy_off_t(_return_value);
3597
3598exit:
3599 return return_value;
3600}
3601
3602PyDoc_STRVAR(os_read__doc__,
3603"read($module, fd, length, /)\n"
3604"--\n"
3605"\n"
3606"Read from a file descriptor. Returns a bytes object.");
3607
3608#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003609 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003610
3611static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003612os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003613
3614static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003615os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003616{
3617 PyObject *return_value = NULL;
3618 int fd;
3619 Py_ssize_t length;
3620
Sylvain74453812017-06-10 06:51:48 +02003621 if (!_PyArg_ParseStack(args, nargs, "in:read",
3622 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003623 goto exit;
3624 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003625 return_value = os_read_impl(module, fd, length);
3626
3627exit:
3628 return return_value;
3629}
3630
3631#if defined(HAVE_READV)
3632
3633PyDoc_STRVAR(os_readv__doc__,
3634"readv($module, fd, buffers, /)\n"
3635"--\n"
3636"\n"
3637"Read from a file descriptor fd into an iterable of buffers.\n"
3638"\n"
3639"The buffers should be mutable buffers accepting bytes.\n"
3640"readv will transfer data into each buffer until it is full\n"
3641"and then move on to the next buffer in the sequence to hold\n"
3642"the rest of the data.\n"
3643"\n"
3644"readv returns the total number of bytes read,\n"
3645"which may be less than the total capacity of all the buffers.");
3646
3647#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003648 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003649
3650static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003651os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003652
3653static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003654os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003655{
3656 PyObject *return_value = NULL;
3657 int fd;
3658 PyObject *buffers;
3659 Py_ssize_t _return_value;
3660
Sylvain74453812017-06-10 06:51:48 +02003661 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3662 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003663 goto exit;
3664 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003665 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003666 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003667 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003668 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003669 return_value = PyLong_FromSsize_t(_return_value);
3670
3671exit:
3672 return return_value;
3673}
3674
3675#endif /* defined(HAVE_READV) */
3676
3677#if defined(HAVE_PREAD)
3678
3679PyDoc_STRVAR(os_pread__doc__,
3680"pread($module, fd, length, offset, /)\n"
3681"--\n"
3682"\n"
3683"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3684"\n"
3685"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3686"the beginning of the file. The file offset remains unchanged.");
3687
3688#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003689 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003690
3691static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003692os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003693
3694static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003695os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003696{
3697 PyObject *return_value = NULL;
3698 int fd;
3699 int length;
3700 Py_off_t offset;
3701
Sylvain74453812017-06-10 06:51:48 +02003702 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3703 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003704 goto exit;
3705 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003706 return_value = os_pread_impl(module, fd, length, offset);
3707
3708exit:
3709 return return_value;
3710}
3711
3712#endif /* defined(HAVE_PREAD) */
3713
Pablo Galindo4defba32018-01-27 16:16:37 +00003714#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3715
3716PyDoc_STRVAR(os_preadv__doc__,
3717"preadv($module, fd, buffers, offset, flags=0, /)\n"
3718"--\n"
3719"\n"
3720"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3721"\n"
3722"Combines the functionality of readv() and pread(). As readv(), it will\n"
3723"transfer data into each buffer until it is full and then move on to the next\n"
3724"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3725"specifies the file offset at which the input operation is to be performed. It\n"
3726"will return the total number of bytes read (which can be less than the total\n"
3727"capacity of all the objects).\n"
3728"\n"
3729"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3730"\n"
3731"- RWF_HIPRI\n"
3732"- RWF_NOWAIT\n"
3733"\n"
3734"Using non-zero flags requires Linux 4.6 or newer.");
3735
3736#define OS_PREADV_METHODDEF \
3737 {"preadv", (PyCFunction)os_preadv, METH_FASTCALL, os_preadv__doc__},
3738
3739static Py_ssize_t
3740os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
3741 int flags);
3742
3743static PyObject *
3744os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3745{
3746 PyObject *return_value = NULL;
3747 int fd;
3748 PyObject *buffers;
3749 Py_off_t offset;
3750 int flags = 0;
3751 Py_ssize_t _return_value;
3752
3753 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",
3754 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
3755 goto exit;
3756 }
3757 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
3758 if ((_return_value == -1) && PyErr_Occurred()) {
3759 goto exit;
3760 }
3761 return_value = PyLong_FromSsize_t(_return_value);
3762
3763exit:
3764 return return_value;
3765}
3766
3767#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
3768
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003769PyDoc_STRVAR(os_write__doc__,
3770"write($module, fd, data, /)\n"
3771"--\n"
3772"\n"
3773"Write a bytes object to a file descriptor.");
3774
3775#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003776 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003777
3778static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003779os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003780
3781static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003782os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003783{
3784 PyObject *return_value = NULL;
3785 int fd;
3786 Py_buffer data = {NULL, NULL};
3787 Py_ssize_t _return_value;
3788
Sylvain74453812017-06-10 06:51:48 +02003789 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3790 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003791 goto exit;
3792 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003793 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003794 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003795 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003796 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003797 return_value = PyLong_FromSsize_t(_return_value);
3798
3799exit:
3800 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003801 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003802 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003803 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003804
3805 return return_value;
3806}
3807
3808PyDoc_STRVAR(os_fstat__doc__,
3809"fstat($module, /, fd)\n"
3810"--\n"
3811"\n"
3812"Perform a stat system call on the given file descriptor.\n"
3813"\n"
3814"Like stat(), but for an open file descriptor.\n"
3815"Equivalent to os.stat(fd).");
3816
3817#define OS_FSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003818 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003819
3820static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003821os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003822
3823static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003824os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003825{
3826 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003827 static const char * const _keywords[] = {"fd", NULL};
3828 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003829 int fd;
3830
Victor Stinner3e1fad62017-01-17 01:29:01 +01003831 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003832 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003833 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003834 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003835 return_value = os_fstat_impl(module, fd);
3836
3837exit:
3838 return return_value;
3839}
3840
3841PyDoc_STRVAR(os_isatty__doc__,
3842"isatty($module, fd, /)\n"
3843"--\n"
3844"\n"
3845"Return True if the fd is connected to a terminal.\n"
3846"\n"
3847"Return True if the file descriptor is an open file descriptor\n"
3848"connected to the slave end of a terminal.");
3849
3850#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003851 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003852
3853static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003854os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003855
3856static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003857os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003858{
3859 PyObject *return_value = NULL;
3860 int fd;
3861 int _return_value;
3862
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003863 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003864 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003865 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003866 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003867 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003868 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003869 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003870 return_value = PyBool_FromLong((long)_return_value);
3871
3872exit:
3873 return return_value;
3874}
3875
3876#if defined(HAVE_PIPE)
3877
3878PyDoc_STRVAR(os_pipe__doc__,
3879"pipe($module, /)\n"
3880"--\n"
3881"\n"
3882"Create a pipe.\n"
3883"\n"
3884"Returns a tuple of two file descriptors:\n"
3885" (read_fd, write_fd)");
3886
3887#define OS_PIPE_METHODDEF \
3888 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3889
3890static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003891os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003892
3893static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003894os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003895{
3896 return os_pipe_impl(module);
3897}
3898
3899#endif /* defined(HAVE_PIPE) */
3900
3901#if defined(HAVE_PIPE2)
3902
3903PyDoc_STRVAR(os_pipe2__doc__,
3904"pipe2($module, flags, /)\n"
3905"--\n"
3906"\n"
3907"Create a pipe with flags set atomically.\n"
3908"\n"
3909"Returns a tuple of two file descriptors:\n"
3910" (read_fd, write_fd)\n"
3911"\n"
3912"flags can be constructed by ORing together one or more of these values:\n"
3913"O_NONBLOCK, O_CLOEXEC.");
3914
3915#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003916 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003917
3918static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003919os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003920
3921static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003922os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003923{
3924 PyObject *return_value = NULL;
3925 int flags;
3926
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003927 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003928 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003929 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003930 return_value = os_pipe2_impl(module, flags);
3931
3932exit:
3933 return return_value;
3934}
3935
3936#endif /* defined(HAVE_PIPE2) */
3937
3938#if defined(HAVE_WRITEV)
3939
3940PyDoc_STRVAR(os_writev__doc__,
3941"writev($module, fd, buffers, /)\n"
3942"--\n"
3943"\n"
3944"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3945"\n"
3946"Returns the total number of bytes written.\n"
3947"buffers must be a sequence of bytes-like objects.");
3948
3949#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003950 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003951
3952static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003953os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003954
3955static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003956os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003957{
3958 PyObject *return_value = NULL;
3959 int fd;
3960 PyObject *buffers;
3961 Py_ssize_t _return_value;
3962
Sylvain74453812017-06-10 06:51:48 +02003963 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
3964 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003965 goto exit;
3966 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003967 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003968 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003969 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003970 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003971 return_value = PyLong_FromSsize_t(_return_value);
3972
3973exit:
3974 return return_value;
3975}
3976
3977#endif /* defined(HAVE_WRITEV) */
3978
3979#if defined(HAVE_PWRITE)
3980
3981PyDoc_STRVAR(os_pwrite__doc__,
3982"pwrite($module, fd, buffer, offset, /)\n"
3983"--\n"
3984"\n"
3985"Write bytes to a file descriptor starting at a particular offset.\n"
3986"\n"
3987"Write buffer to fd, starting at offset bytes from the beginning of\n"
3988"the file. Returns the number of bytes writte. Does not change the\n"
3989"current file offset.");
3990
3991#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003992 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003993
3994static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003995os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003996
3997static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003998os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003999{
4000 PyObject *return_value = NULL;
4001 int fd;
4002 Py_buffer buffer = {NULL, NULL};
4003 Py_off_t offset;
4004 Py_ssize_t _return_value;
4005
Sylvain74453812017-06-10 06:51:48 +02004006 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4007 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004008 goto exit;
4009 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004010 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004011 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004012 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004013 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004014 return_value = PyLong_FromSsize_t(_return_value);
4015
4016exit:
4017 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004018 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004019 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004020 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004021
4022 return return_value;
4023}
4024
4025#endif /* defined(HAVE_PWRITE) */
4026
Pablo Galindo4defba32018-01-27 16:16:37 +00004027#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4028
4029PyDoc_STRVAR(os_pwritev__doc__,
4030"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4031"--\n"
4032"\n"
4033"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4034"\n"
4035"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4036"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4037"buffer is written before proceeding to second, and so on. The operating system may\n"
4038"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4039"This function writes the contents of each object to the file descriptor and returns\n"
4040"the total number of bytes written.\n"
4041"\n"
4042"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4043"\n"
4044"- RWF_DSYNC\n"
4045"- RWF_SYNC\n"
4046"\n"
4047"Using non-zero flags requires Linux 4.7 or newer.");
4048
4049#define OS_PWRITEV_METHODDEF \
4050 {"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},
4051
4052static Py_ssize_t
4053os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4054 int flags);
4055
4056static PyObject *
4057os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4058{
4059 PyObject *return_value = NULL;
4060 int fd;
4061 PyObject *buffers;
4062 Py_off_t offset;
4063 int flags = 0;
4064 Py_ssize_t _return_value;
4065
4066 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4067 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4068 goto exit;
4069 }
4070 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4071 if ((_return_value == -1) && PyErr_Occurred()) {
4072 goto exit;
4073 }
4074 return_value = PyLong_FromSsize_t(_return_value);
4075
4076exit:
4077 return return_value;
4078}
4079
4080#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4081
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004082#if defined(HAVE_MKFIFO)
4083
4084PyDoc_STRVAR(os_mkfifo__doc__,
4085"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4086"--\n"
4087"\n"
4088"Create a \"fifo\" (a POSIX named pipe).\n"
4089"\n"
4090"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4091" and path should be relative; path will then be relative to that directory.\n"
4092"dir_fd may not be implemented on your platform.\n"
4093" If it is unavailable, using it will raise a NotImplementedError.");
4094
4095#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004096 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004097
4098static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004099os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004100
4101static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004102os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004103{
4104 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004105 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4106 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004107 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4108 int mode = 438;
4109 int dir_fd = DEFAULT_DIR_FD;
4110
Victor Stinner3e1fad62017-01-17 01:29:01 +01004111 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004112 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004113 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004114 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004115 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4116
4117exit:
4118 /* Cleanup for path */
4119 path_cleanup(&path);
4120
4121 return return_value;
4122}
4123
4124#endif /* defined(HAVE_MKFIFO) */
4125
4126#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4127
4128PyDoc_STRVAR(os_mknod__doc__,
4129"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4130"--\n"
4131"\n"
4132"Create a node in the file system.\n"
4133"\n"
4134"Create a node in the file system (file, device special file or named pipe)\n"
4135"at path. mode specifies both the permissions to use and the\n"
4136"type of node to be created, being combined (bitwise OR) with one of\n"
4137"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4138"device defines the newly created device special file (probably using\n"
4139"os.makedev()). Otherwise device is ignored.\n"
4140"\n"
4141"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4142" and path should be relative; path will then be relative to that directory.\n"
4143"dir_fd may not be implemented on your platform.\n"
4144" If it is unavailable, using it will raise a NotImplementedError.");
4145
4146#define OS_MKNOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004147 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004148
4149static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004150os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004151 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004152
4153static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004154os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004155{
4156 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004157 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4158 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004159 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4160 int mode = 384;
4161 dev_t device = 0;
4162 int dir_fd = DEFAULT_DIR_FD;
4163
Victor Stinner3e1fad62017-01-17 01:29:01 +01004164 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004165 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004166 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004167 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004168 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4169
4170exit:
4171 /* Cleanup for path */
4172 path_cleanup(&path);
4173
4174 return return_value;
4175}
4176
4177#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4178
4179#if defined(HAVE_DEVICE_MACROS)
4180
4181PyDoc_STRVAR(os_major__doc__,
4182"major($module, device, /)\n"
4183"--\n"
4184"\n"
4185"Extracts a device major number from a raw device number.");
4186
4187#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004188 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004189
4190static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004191os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004192
4193static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004194os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004195{
4196 PyObject *return_value = NULL;
4197 dev_t device;
4198 unsigned int _return_value;
4199
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004200 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004201 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004202 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004203 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004204 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004205 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004206 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004207 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4208
4209exit:
4210 return return_value;
4211}
4212
4213#endif /* defined(HAVE_DEVICE_MACROS) */
4214
4215#if defined(HAVE_DEVICE_MACROS)
4216
4217PyDoc_STRVAR(os_minor__doc__,
4218"minor($module, device, /)\n"
4219"--\n"
4220"\n"
4221"Extracts a device minor number from a raw device number.");
4222
4223#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004224 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004225
4226static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004227os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004228
4229static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004230os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004231{
4232 PyObject *return_value = NULL;
4233 dev_t device;
4234 unsigned int _return_value;
4235
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004236 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004237 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004238 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004239 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004240 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004241 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004242 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004243 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4244
4245exit:
4246 return return_value;
4247}
4248
4249#endif /* defined(HAVE_DEVICE_MACROS) */
4250
4251#if defined(HAVE_DEVICE_MACROS)
4252
4253PyDoc_STRVAR(os_makedev__doc__,
4254"makedev($module, major, minor, /)\n"
4255"--\n"
4256"\n"
4257"Composes a raw device number from the major and minor device numbers.");
4258
4259#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004260 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004261
4262static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004263os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004264
4265static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004266os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004267{
4268 PyObject *return_value = NULL;
4269 int major;
4270 int minor;
4271 dev_t _return_value;
4272
Sylvain74453812017-06-10 06:51:48 +02004273 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4274 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004275 goto exit;
4276 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004277 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004278 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004279 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004280 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004281 return_value = _PyLong_FromDev(_return_value);
4282
4283exit:
4284 return return_value;
4285}
4286
4287#endif /* defined(HAVE_DEVICE_MACROS) */
4288
Steve Dowerf7377032015-04-12 15:44:54 -04004289#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004290
4291PyDoc_STRVAR(os_ftruncate__doc__,
4292"ftruncate($module, fd, length, /)\n"
4293"--\n"
4294"\n"
4295"Truncate a file, specified by file descriptor, to a specific length.");
4296
4297#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004298 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004299
4300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004301os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004302
4303static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004304os_ftruncate(PyObject *module, PyObject *const *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 length;
4309
Sylvain74453812017-06-10 06:51:48 +02004310 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4311 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004312 goto exit;
4313 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004314 return_value = os_ftruncate_impl(module, fd, length);
4315
4316exit:
4317 return return_value;
4318}
4319
Steve Dowerf7377032015-04-12 15:44:54 -04004320#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004321
Steve Dowerf7377032015-04-12 15:44:54 -04004322#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004323
4324PyDoc_STRVAR(os_truncate__doc__,
4325"truncate($module, /, path, length)\n"
4326"--\n"
4327"\n"
4328"Truncate a file, specified by path, to a specific length.\n"
4329"\n"
4330"On some platforms, path may also be specified as an open file descriptor.\n"
4331" If this functionality is unavailable, using it raises an exception.");
4332
4333#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004334 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004335
4336static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004337os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004338
4339static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004340os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004341{
4342 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004343 static const char * const _keywords[] = {"path", "length", NULL};
4344 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004345 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4346 Py_off_t length;
4347
Victor Stinner3e1fad62017-01-17 01:29:01 +01004348 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004349 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004350 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004351 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004352 return_value = os_truncate_impl(module, &path, length);
4353
4354exit:
4355 /* Cleanup for path */
4356 path_cleanup(&path);
4357
4358 return return_value;
4359}
4360
Steve Dowerf7377032015-04-12 15:44:54 -04004361#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004362
4363#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4364
4365PyDoc_STRVAR(os_posix_fallocate__doc__,
4366"posix_fallocate($module, fd, offset, length, /)\n"
4367"--\n"
4368"\n"
4369"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4370"\n"
4371"Ensure that the file specified by fd encompasses a range of bytes\n"
4372"starting at offset bytes from the beginning and continuing for length bytes.");
4373
4374#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004375 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004376
4377static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004378os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004379 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004380
4381static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004382os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004383{
4384 PyObject *return_value = NULL;
4385 int fd;
4386 Py_off_t offset;
4387 Py_off_t length;
4388
Sylvain74453812017-06-10 06:51:48 +02004389 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4390 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004391 goto exit;
4392 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004393 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4394
4395exit:
4396 return return_value;
4397}
4398
4399#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4400
4401#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4402
4403PyDoc_STRVAR(os_posix_fadvise__doc__,
4404"posix_fadvise($module, fd, offset, length, advice, /)\n"
4405"--\n"
4406"\n"
4407"Announce an intention to access data in a specific pattern.\n"
4408"\n"
4409"Announce an intention to access data in a specific pattern, thus allowing\n"
4410"the kernel to make optimizations.\n"
4411"The advice applies to the region of the file specified by fd starting at\n"
4412"offset and continuing for length bytes.\n"
4413"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4414"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4415"POSIX_FADV_DONTNEED.");
4416
4417#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004418 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004419
4420static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004421os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004422 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004423
4424static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004425os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004426{
4427 PyObject *return_value = NULL;
4428 int fd;
4429 Py_off_t offset;
4430 Py_off_t length;
4431 int advice;
4432
Sylvain74453812017-06-10 06:51:48 +02004433 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4434 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004435 goto exit;
4436 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004437 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4438
4439exit:
4440 return return_value;
4441}
4442
4443#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4444
4445#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4446
4447PyDoc_STRVAR(os_putenv__doc__,
4448"putenv($module, name, value, /)\n"
4449"--\n"
4450"\n"
4451"Change or add an environment variable.");
4452
4453#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004454 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004455
4456static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004457os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004458
4459static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004460os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004461{
4462 PyObject *return_value = NULL;
4463 PyObject *name;
4464 PyObject *value;
4465
Sylvain74453812017-06-10 06:51:48 +02004466 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4467 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004468 goto exit;
4469 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004470 return_value = os_putenv_impl(module, name, value);
4471
4472exit:
4473 return return_value;
4474}
4475
4476#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4477
4478#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4479
4480PyDoc_STRVAR(os_putenv__doc__,
4481"putenv($module, name, value, /)\n"
4482"--\n"
4483"\n"
4484"Change or add an environment variable.");
4485
4486#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004487 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004488
4489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004490os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004491
4492static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004493os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004494{
4495 PyObject *return_value = NULL;
4496 PyObject *name = NULL;
4497 PyObject *value = NULL;
4498
Sylvain74453812017-06-10 06:51:48 +02004499 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4500 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004501 goto exit;
4502 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004503 return_value = os_putenv_impl(module, name, value);
4504
4505exit:
4506 /* Cleanup for name */
4507 Py_XDECREF(name);
4508 /* Cleanup for value */
4509 Py_XDECREF(value);
4510
4511 return return_value;
4512}
4513
4514#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4515
4516#if defined(HAVE_UNSETENV)
4517
4518PyDoc_STRVAR(os_unsetenv__doc__,
4519"unsetenv($module, name, /)\n"
4520"--\n"
4521"\n"
4522"Delete an environment variable.");
4523
4524#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004525 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004526
4527static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004528os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004529
4530static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004531os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004532{
4533 PyObject *return_value = NULL;
4534 PyObject *name = NULL;
4535
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004536 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004537 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004538 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004539 return_value = os_unsetenv_impl(module, name);
4540
4541exit:
4542 /* Cleanup for name */
4543 Py_XDECREF(name);
4544
4545 return return_value;
4546}
4547
4548#endif /* defined(HAVE_UNSETENV) */
4549
4550PyDoc_STRVAR(os_strerror__doc__,
4551"strerror($module, code, /)\n"
4552"--\n"
4553"\n"
4554"Translate an error code to a message string.");
4555
4556#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004557 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004558
4559static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004560os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004561
4562static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004563os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004564{
4565 PyObject *return_value = NULL;
4566 int code;
4567
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004568 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004569 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004570 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004571 return_value = os_strerror_impl(module, code);
4572
4573exit:
4574 return return_value;
4575}
4576
4577#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4578
4579PyDoc_STRVAR(os_WCOREDUMP__doc__,
4580"WCOREDUMP($module, status, /)\n"
4581"--\n"
4582"\n"
4583"Return True if the process returning status was dumped to a core file.");
4584
4585#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004586 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004587
4588static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004589os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004590
4591static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004592os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004593{
4594 PyObject *return_value = NULL;
4595 int status;
4596 int _return_value;
4597
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004598 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004599 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004600 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004601 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004602 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004603 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004604 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004605 return_value = PyBool_FromLong((long)_return_value);
4606
4607exit:
4608 return return_value;
4609}
4610
4611#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4612
4613#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4614
4615PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4616"WIFCONTINUED($module, /, status)\n"
4617"--\n"
4618"\n"
4619"Return True if a particular process was continued from a job control stop.\n"
4620"\n"
4621"Return True if the process returning status was continued from a\n"
4622"job control stop.");
4623
4624#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004625 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004626
4627static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004628os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004629
4630static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004631os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004632{
4633 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004634 static const char * const _keywords[] = {"status", NULL};
4635 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004636 int status;
4637 int _return_value;
4638
Victor Stinner3e1fad62017-01-17 01:29:01 +01004639 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004640 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004641 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004642 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004643 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004644 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004645 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004646 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004647 return_value = PyBool_FromLong((long)_return_value);
4648
4649exit:
4650 return return_value;
4651}
4652
4653#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4654
4655#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4656
4657PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4658"WIFSTOPPED($module, /, status)\n"
4659"--\n"
4660"\n"
4661"Return True if the process returning status was stopped.");
4662
4663#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004664 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004665
4666static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004667os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004668
4669static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004670os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004671{
4672 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004673 static const char * const _keywords[] = {"status", NULL};
4674 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004675 int status;
4676 int _return_value;
4677
Victor Stinner3e1fad62017-01-17 01:29:01 +01004678 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004679 &status)) {
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 = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004683 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004684 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004685 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004686 return_value = PyBool_FromLong((long)_return_value);
4687
4688exit:
4689 return return_value;
4690}
4691
4692#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4693
4694#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4695
4696PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4697"WIFSIGNALED($module, /, status)\n"
4698"--\n"
4699"\n"
4700"Return True if the process returning status was terminated by a signal.");
4701
4702#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004703 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004704
4705static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004706os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004707
4708static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004709os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004710{
4711 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004712 static const char * const _keywords[] = {"status", NULL};
4713 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004714 int status;
4715 int _return_value;
4716
Victor Stinner3e1fad62017-01-17 01:29:01 +01004717 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004718 &status)) {
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 = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004722 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004723 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004724 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004725 return_value = PyBool_FromLong((long)_return_value);
4726
4727exit:
4728 return return_value;
4729}
4730
4731#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4732
4733#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4734
4735PyDoc_STRVAR(os_WIFEXITED__doc__,
4736"WIFEXITED($module, /, status)\n"
4737"--\n"
4738"\n"
4739"Return True if the process returning status exited via the exit() system call.");
4740
4741#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004742 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004743
4744static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004745os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004746
4747static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004748os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004749{
4750 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004751 static const char * const _keywords[] = {"status", NULL};
4752 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004753 int status;
4754 int _return_value;
4755
Victor Stinner3e1fad62017-01-17 01:29:01 +01004756 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004757 &status)) {
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 = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004761 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004762 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004763 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004764 return_value = PyBool_FromLong((long)_return_value);
4765
4766exit:
4767 return return_value;
4768}
4769
4770#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4771
4772#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4773
4774PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4775"WEXITSTATUS($module, /, status)\n"
4776"--\n"
4777"\n"
4778"Return the process return code from status.");
4779
4780#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004781 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004782
4783static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004784os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004785
4786static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004787os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004788{
4789 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004790 static const char * const _keywords[] = {"status", NULL};
4791 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004792 int status;
4793 int _return_value;
4794
Victor Stinner3e1fad62017-01-17 01:29:01 +01004795 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004796 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004797 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004798 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004799 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004800 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004801 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004802 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004803 return_value = PyLong_FromLong((long)_return_value);
4804
4805exit:
4806 return return_value;
4807}
4808
4809#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4810
4811#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4812
4813PyDoc_STRVAR(os_WTERMSIG__doc__,
4814"WTERMSIG($module, /, status)\n"
4815"--\n"
4816"\n"
4817"Return the signal that terminated the process that provided the status value.");
4818
4819#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004820 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004821
4822static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004823os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004824
4825static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004826os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004827{
4828 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004829 static const char * const _keywords[] = {"status", NULL};
4830 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004831 int status;
4832 int _return_value;
4833
Victor Stinner3e1fad62017-01-17 01:29:01 +01004834 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004835 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004836 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004837 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004838 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004839 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004840 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004841 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004842 return_value = PyLong_FromLong((long)_return_value);
4843
4844exit:
4845 return return_value;
4846}
4847
4848#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4849
4850#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4851
4852PyDoc_STRVAR(os_WSTOPSIG__doc__,
4853"WSTOPSIG($module, /, status)\n"
4854"--\n"
4855"\n"
4856"Return the signal that stopped the process that provided the status value.");
4857
4858#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004859 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004860
4861static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004862os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004863
4864static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004865os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004866{
4867 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004868 static const char * const _keywords[] = {"status", NULL};
4869 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004870 int status;
4871 int _return_value;
4872
Victor Stinner3e1fad62017-01-17 01:29:01 +01004873 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004874 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004875 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004876 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004877 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004878 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004879 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004880 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004881 return_value = PyLong_FromLong((long)_return_value);
4882
4883exit:
4884 return return_value;
4885}
4886
4887#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4888
4889#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4890
4891PyDoc_STRVAR(os_fstatvfs__doc__,
4892"fstatvfs($module, fd, /)\n"
4893"--\n"
4894"\n"
4895"Perform an fstatvfs system call on the given fd.\n"
4896"\n"
4897"Equivalent to statvfs(fd).");
4898
4899#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004900 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004901
4902static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004903os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004904
4905static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004906os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004907{
4908 PyObject *return_value = NULL;
4909 int fd;
4910
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004911 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004912 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004913 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004914 return_value = os_fstatvfs_impl(module, fd);
4915
4916exit:
4917 return return_value;
4918}
4919
4920#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4921
4922#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4923
4924PyDoc_STRVAR(os_statvfs__doc__,
4925"statvfs($module, /, path)\n"
4926"--\n"
4927"\n"
4928"Perform a statvfs system call on the given path.\n"
4929"\n"
4930"path may always be specified as a string.\n"
4931"On some platforms, path may also be specified as an open file descriptor.\n"
4932" If this functionality is unavailable, using it raises an exception.");
4933
4934#define OS_STATVFS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004935 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004936
4937static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004938os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004939
4940static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004941os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004942{
4943 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004944 static const char * const _keywords[] = {"path", NULL};
4945 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004946 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4947
Victor Stinner3e1fad62017-01-17 01:29:01 +01004948 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004949 path_converter, &path)) {
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 = os_statvfs_impl(module, &path);
4953
4954exit:
4955 /* Cleanup for path */
4956 path_cleanup(&path);
4957
4958 return return_value;
4959}
4960
4961#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4962
4963#if defined(MS_WINDOWS)
4964
4965PyDoc_STRVAR(os__getdiskusage__doc__,
4966"_getdiskusage($module, /, path)\n"
4967"--\n"
4968"\n"
4969"Return disk usage statistics about the given path as a (total, free) tuple.");
4970
4971#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004972 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004973
4974static PyObject *
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08004975os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004976
4977static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004978os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004979{
4980 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004981 static const char * const _keywords[] = {"path", NULL};
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08004982 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
4983 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984
Victor Stinner3e1fad62017-01-17 01:29:01 +01004985 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08004986 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004987 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004988 }
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08004989 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004990
4991exit:
Miss Islington (bot)01dd52f2018-02-22 11:02:12 -08004992 /* Cleanup for path */
4993 path_cleanup(&path);
4994
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004995 return return_value;
4996}
4997
4998#endif /* defined(MS_WINDOWS) */
4999
5000#if defined(HAVE_FPATHCONF)
5001
5002PyDoc_STRVAR(os_fpathconf__doc__,
5003"fpathconf($module, fd, name, /)\n"
5004"--\n"
5005"\n"
5006"Return the configuration limit name for the file descriptor fd.\n"
5007"\n"
5008"If there is no limit, return -1.");
5009
5010#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005011 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005012
5013static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005014os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005015
5016static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005017os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005018{
5019 PyObject *return_value = NULL;
5020 int fd;
5021 int name;
5022 long _return_value;
5023
Sylvain74453812017-06-10 06:51:48 +02005024 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5025 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005026 goto exit;
5027 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005028 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005029 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005030 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005031 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005032 return_value = PyLong_FromLong(_return_value);
5033
5034exit:
5035 return return_value;
5036}
5037
5038#endif /* defined(HAVE_FPATHCONF) */
5039
5040#if defined(HAVE_PATHCONF)
5041
5042PyDoc_STRVAR(os_pathconf__doc__,
5043"pathconf($module, /, path, name)\n"
5044"--\n"
5045"\n"
5046"Return the configuration limit name for the file or directory path.\n"
5047"\n"
5048"If there is no limit, return -1.\n"
5049"On some platforms, path may also be specified as an open file descriptor.\n"
5050" If this functionality is unavailable, using it raises an exception.");
5051
5052#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005053 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005054
5055static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005056os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005057
5058static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005059os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005060{
5061 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005062 static const char * const _keywords[] = {"path", "name", NULL};
5063 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005064 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5065 int name;
5066 long _return_value;
5067
Victor Stinner3e1fad62017-01-17 01:29:01 +01005068 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005069 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005070 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005071 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005072 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005073 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005074 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005075 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005076 return_value = PyLong_FromLong(_return_value);
5077
5078exit:
5079 /* Cleanup for path */
5080 path_cleanup(&path);
5081
5082 return return_value;
5083}
5084
5085#endif /* defined(HAVE_PATHCONF) */
5086
5087#if defined(HAVE_CONFSTR)
5088
5089PyDoc_STRVAR(os_confstr__doc__,
5090"confstr($module, name, /)\n"
5091"--\n"
5092"\n"
5093"Return a string-valued system configuration variable.");
5094
5095#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005096 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005097
5098static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005099os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005100
5101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005102os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005103{
5104 PyObject *return_value = NULL;
5105 int name;
5106
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005107 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005109 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005110 return_value = os_confstr_impl(module, name);
5111
5112exit:
5113 return return_value;
5114}
5115
5116#endif /* defined(HAVE_CONFSTR) */
5117
5118#if defined(HAVE_SYSCONF)
5119
5120PyDoc_STRVAR(os_sysconf__doc__,
5121"sysconf($module, name, /)\n"
5122"--\n"
5123"\n"
5124"Return an integer-valued system configuration variable.");
5125
5126#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005127 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005128
5129static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005130os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005131
5132static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005133os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005134{
5135 PyObject *return_value = NULL;
5136 int name;
5137 long _return_value;
5138
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005139 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005140 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005141 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005142 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005143 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005144 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005145 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005146 return_value = PyLong_FromLong(_return_value);
5147
5148exit:
5149 return return_value;
5150}
5151
5152#endif /* defined(HAVE_SYSCONF) */
5153
5154PyDoc_STRVAR(os_abort__doc__,
5155"abort($module, /)\n"
5156"--\n"
5157"\n"
5158"Abort the interpreter immediately.\n"
5159"\n"
5160"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5161"on the hosting operating system. This function never returns.");
5162
5163#define OS_ABORT_METHODDEF \
5164 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5165
5166static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005167os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005168
5169static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005170os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005171{
5172 return os_abort_impl(module);
5173}
5174
Steve Dowercc16be82016-09-08 10:35:16 -07005175#if defined(MS_WINDOWS)
5176
5177PyDoc_STRVAR(os_startfile__doc__,
5178"startfile($module, /, filepath, operation=None)\n"
5179"--\n"
5180"\n"
5181"startfile(filepath [, operation])\n"
5182"\n"
5183"Start a file with its associated application.\n"
5184"\n"
5185"When \"operation\" is not specified or \"open\", this acts like\n"
5186"double-clicking the file in Explorer, or giving the file name as an\n"
5187"argument to the DOS \"start\" command: the file is opened with whatever\n"
5188"application (if any) its extension is associated.\n"
5189"When another \"operation\" is given, it specifies what should be done with\n"
5190"the file. A typical operation is \"print\".\n"
5191"\n"
5192"startfile returns as soon as the associated application is launched.\n"
5193"There is no option to wait for the application to close, and no way\n"
5194"to retrieve the application\'s exit status.\n"
5195"\n"
5196"The filepath is relative to the current directory. If you want to use\n"
5197"an absolute path, make sure the first character is not a slash (\"/\");\n"
5198"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5199
5200#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005201 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005202
5203static PyObject *
Serhiy Storchaka45a7b762018-12-14 11:56:48 +02005204os_startfile_impl(PyObject *module, path_t *filepath,
5205 const Py_UNICODE *operation);
Steve Dowercc16be82016-09-08 10:35:16 -07005206
5207static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005208os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005209{
5210 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005211 static const char * const _keywords[] = {"filepath", "operation", NULL};
5212 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005213 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
Serhiy Storchaka45a7b762018-12-14 11:56:48 +02005214 const Py_UNICODE *operation = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07005215
Victor Stinner3e1fad62017-01-17 01:29:01 +01005216 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005217 path_converter, &filepath, &operation)) {
5218 goto exit;
5219 }
5220 return_value = os_startfile_impl(module, &filepath, operation);
5221
5222exit:
5223 /* Cleanup for filepath */
5224 path_cleanup(&filepath);
5225
5226 return return_value;
5227}
5228
5229#endif /* defined(MS_WINDOWS) */
5230
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005231#if defined(HAVE_GETLOADAVG)
5232
5233PyDoc_STRVAR(os_getloadavg__doc__,
5234"getloadavg($module, /)\n"
5235"--\n"
5236"\n"
5237"Return average recent system load information.\n"
5238"\n"
5239"Return the number of processes in the system run queue averaged over\n"
5240"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5241"Raises OSError if the load average was unobtainable.");
5242
5243#define OS_GETLOADAVG_METHODDEF \
5244 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5245
5246static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005247os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005248
5249static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005250os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005251{
5252 return os_getloadavg_impl(module);
5253}
5254
5255#endif /* defined(HAVE_GETLOADAVG) */
5256
5257PyDoc_STRVAR(os_device_encoding__doc__,
5258"device_encoding($module, /, fd)\n"
5259"--\n"
5260"\n"
5261"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5262"\n"
5263"The file descriptor must be attached to a terminal.\n"
5264"If the device is not a terminal, return None.");
5265
5266#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005267 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005268
5269static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005270os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005271
5272static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005273os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005274{
5275 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005276 static const char * const _keywords[] = {"fd", NULL};
5277 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005278 int fd;
5279
Victor Stinner3e1fad62017-01-17 01:29:01 +01005280 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005281 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005282 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005283 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005284 return_value = os_device_encoding_impl(module, fd);
5285
5286exit:
5287 return return_value;
5288}
5289
5290#if defined(HAVE_SETRESUID)
5291
5292PyDoc_STRVAR(os_setresuid__doc__,
5293"setresuid($module, ruid, euid, suid, /)\n"
5294"--\n"
5295"\n"
5296"Set the current process\'s real, effective, and saved user ids.");
5297
5298#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005299 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005300
5301static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005302os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005303
5304static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005305os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005306{
5307 PyObject *return_value = NULL;
5308 uid_t ruid;
5309 uid_t euid;
5310 uid_t suid;
5311
Sylvain74453812017-06-10 06:51:48 +02005312 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5313 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005314 goto exit;
5315 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005316 return_value = os_setresuid_impl(module, ruid, euid, suid);
5317
5318exit:
5319 return return_value;
5320}
5321
5322#endif /* defined(HAVE_SETRESUID) */
5323
5324#if defined(HAVE_SETRESGID)
5325
5326PyDoc_STRVAR(os_setresgid__doc__,
5327"setresgid($module, rgid, egid, sgid, /)\n"
5328"--\n"
5329"\n"
5330"Set the current process\'s real, effective, and saved group ids.");
5331
5332#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005333 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005334
5335static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005336os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005337
5338static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005339os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005340{
5341 PyObject *return_value = NULL;
5342 gid_t rgid;
5343 gid_t egid;
5344 gid_t sgid;
5345
Sylvain74453812017-06-10 06:51:48 +02005346 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5347 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005348 goto exit;
5349 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005350 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5351
5352exit:
5353 return return_value;
5354}
5355
5356#endif /* defined(HAVE_SETRESGID) */
5357
5358#if defined(HAVE_GETRESUID)
5359
5360PyDoc_STRVAR(os_getresuid__doc__,
5361"getresuid($module, /)\n"
5362"--\n"
5363"\n"
5364"Return a tuple of the current process\'s real, effective, and saved user ids.");
5365
5366#define OS_GETRESUID_METHODDEF \
5367 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5368
5369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005370os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005371
5372static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005373os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005374{
5375 return os_getresuid_impl(module);
5376}
5377
5378#endif /* defined(HAVE_GETRESUID) */
5379
5380#if defined(HAVE_GETRESGID)
5381
5382PyDoc_STRVAR(os_getresgid__doc__,
5383"getresgid($module, /)\n"
5384"--\n"
5385"\n"
5386"Return a tuple of the current process\'s real, effective, and saved group ids.");
5387
5388#define OS_GETRESGID_METHODDEF \
5389 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5390
5391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005392os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005393
5394static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005395os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005396{
5397 return os_getresgid_impl(module);
5398}
5399
5400#endif /* defined(HAVE_GETRESGID) */
5401
5402#if defined(USE_XATTRS)
5403
5404PyDoc_STRVAR(os_getxattr__doc__,
5405"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5406"--\n"
5407"\n"
5408"Return the value of extended attribute attribute on path.\n"
5409"\n"
BNMetrics08026b12018-11-02 17:56:25 +00005410"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005411"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5412" link, getxattr will examine the symbolic link itself instead of the file\n"
5413" the link points to.");
5414
5415#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005416 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005417
5418static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005419os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005420 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005421
5422static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005423os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005424{
5425 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005426 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5427 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005428 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5429 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5430 int follow_symlinks = 1;
5431
Victor Stinner3e1fad62017-01-17 01:29:01 +01005432 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005433 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005434 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005435 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005436 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5437
5438exit:
5439 /* Cleanup for path */
5440 path_cleanup(&path);
5441 /* Cleanup for attribute */
5442 path_cleanup(&attribute);
5443
5444 return return_value;
5445}
5446
5447#endif /* defined(USE_XATTRS) */
5448
5449#if defined(USE_XATTRS)
5450
5451PyDoc_STRVAR(os_setxattr__doc__,
5452"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5453" follow_symlinks=True)\n"
5454"--\n"
5455"\n"
5456"Set extended attribute attribute on path to value.\n"
5457"\n"
BNMetrics08026b12018-11-02 17:56:25 +00005458"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005459"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5460" link, setxattr will modify the symbolic link itself instead of the file\n"
5461" the link points to.");
5462
5463#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005464 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005465
5466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005467os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005468 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005469
5470static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005471os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005472{
5473 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005474 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5475 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005476 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5477 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5478 Py_buffer value = {NULL, NULL};
5479 int flags = 0;
5480 int follow_symlinks = 1;
5481
Victor Stinner3e1fad62017-01-17 01:29:01 +01005482 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005483 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005484 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005485 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005486 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5487
5488exit:
5489 /* Cleanup for path */
5490 path_cleanup(&path);
5491 /* Cleanup for attribute */
5492 path_cleanup(&attribute);
5493 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005494 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005495 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005496 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005497
5498 return return_value;
5499}
5500
5501#endif /* defined(USE_XATTRS) */
5502
5503#if defined(USE_XATTRS)
5504
5505PyDoc_STRVAR(os_removexattr__doc__,
5506"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5507"--\n"
5508"\n"
5509"Remove extended attribute attribute on path.\n"
5510"\n"
BNMetrics08026b12018-11-02 17:56:25 +00005511"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005512"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5513" link, removexattr will modify the symbolic link itself instead of the file\n"
5514" the link points to.");
5515
5516#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005517 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005518
5519static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005520os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005521 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005522
5523static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005524os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005525{
5526 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005527 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5528 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005529 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5530 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5531 int follow_symlinks = 1;
5532
Victor Stinner3e1fad62017-01-17 01:29:01 +01005533 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005534 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005535 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005536 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005537 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5538
5539exit:
5540 /* Cleanup for path */
5541 path_cleanup(&path);
5542 /* Cleanup for attribute */
5543 path_cleanup(&attribute);
5544
5545 return return_value;
5546}
5547
5548#endif /* defined(USE_XATTRS) */
5549
5550#if defined(USE_XATTRS)
5551
5552PyDoc_STRVAR(os_listxattr__doc__,
5553"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5554"--\n"
5555"\n"
5556"Return a list of extended attributes on path.\n"
5557"\n"
BNMetrics08026b12018-11-02 17:56:25 +00005558"path may be either None, a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005559"if path is None, listxattr will examine the current directory.\n"
5560"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5561" link, listxattr will examine the symbolic link itself instead of the file\n"
5562" the link points to.");
5563
5564#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005565 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005566
5567static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005568os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005569
5570static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005571os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005572{
5573 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005574 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5575 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005576 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5577 int follow_symlinks = 1;
5578
Victor Stinner3e1fad62017-01-17 01:29:01 +01005579 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005580 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005581 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005582 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005583 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5584
5585exit:
5586 /* Cleanup for path */
5587 path_cleanup(&path);
5588
5589 return return_value;
5590}
5591
5592#endif /* defined(USE_XATTRS) */
5593
5594PyDoc_STRVAR(os_urandom__doc__,
5595"urandom($module, size, /)\n"
5596"--\n"
5597"\n"
5598"Return a bytes object containing random bytes suitable for cryptographic use.");
5599
5600#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005601 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005602
5603static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005604os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005605
5606static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005607os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005608{
5609 PyObject *return_value = NULL;
5610 Py_ssize_t size;
5611
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005612 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005613 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005614 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005615 return_value = os_urandom_impl(module, size);
5616
5617exit:
5618 return return_value;
5619}
5620
5621PyDoc_STRVAR(os_cpu_count__doc__,
5622"cpu_count($module, /)\n"
5623"--\n"
5624"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005625"Return the number of CPUs in the system; return None if indeterminable.\n"
5626"\n"
5627"This number is not equivalent to the number of CPUs the current process can\n"
5628"use. The number of usable CPUs can be obtained with\n"
5629"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005630
5631#define OS_CPU_COUNT_METHODDEF \
5632 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5633
5634static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005635os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005636
5637static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005638os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005639{
5640 return os_cpu_count_impl(module);
5641}
5642
5643PyDoc_STRVAR(os_get_inheritable__doc__,
5644"get_inheritable($module, fd, /)\n"
5645"--\n"
5646"\n"
5647"Get the close-on-exe flag of the specified file descriptor.");
5648
5649#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005650 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005651
5652static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005653os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005654
5655static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005656os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005657{
5658 PyObject *return_value = NULL;
5659 int fd;
5660 int _return_value;
5661
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005662 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005663 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005664 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005665 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005666 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005667 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005668 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005669 return_value = PyBool_FromLong((long)_return_value);
5670
5671exit:
5672 return return_value;
5673}
5674
5675PyDoc_STRVAR(os_set_inheritable__doc__,
5676"set_inheritable($module, fd, inheritable, /)\n"
5677"--\n"
5678"\n"
5679"Set the inheritable flag of the specified file descriptor.");
5680
5681#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005682 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005683
5684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005685os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005686
5687static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005688os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005689{
5690 PyObject *return_value = NULL;
5691 int fd;
5692 int inheritable;
5693
Sylvain74453812017-06-10 06:51:48 +02005694 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5695 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005696 goto exit;
5697 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005698 return_value = os_set_inheritable_impl(module, fd, inheritable);
5699
5700exit:
5701 return return_value;
5702}
5703
5704#if defined(MS_WINDOWS)
5705
5706PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5707"get_handle_inheritable($module, handle, /)\n"
5708"--\n"
5709"\n"
5710"Get the close-on-exe flag of the specified file descriptor.");
5711
5712#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005713 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005714
5715static int
Victor Stinner581139c2016-09-06 15:54:20 -07005716os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005717
5718static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005719os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005720{
5721 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005722 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005723 int _return_value;
5724
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005725 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005726 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005727 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005728 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005729 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005730 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005731 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005732 return_value = PyBool_FromLong((long)_return_value);
5733
5734exit:
5735 return return_value;
5736}
5737
5738#endif /* defined(MS_WINDOWS) */
5739
5740#if defined(MS_WINDOWS)
5741
5742PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5743"set_handle_inheritable($module, handle, inheritable, /)\n"
5744"--\n"
5745"\n"
5746"Set the inheritable flag of the specified handle.");
5747
5748#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005749 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005750
5751static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005752os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005753 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005754
5755static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005756os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005757{
5758 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005759 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005760 int inheritable;
5761
Sylvain74453812017-06-10 06:51:48 +02005762 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5763 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005764 goto exit;
5765 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005766 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5767
5768exit:
5769 return return_value;
5770}
5771
5772#endif /* defined(MS_WINDOWS) */
5773
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005774PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5775"is_symlink($self, /)\n"
5776"--\n"
5777"\n"
5778"Return True if the entry is a symbolic link; cached per entry.");
5779
5780#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5781 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5782
5783static int
5784os_DirEntry_is_symlink_impl(DirEntry *self);
5785
5786static PyObject *
5787os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5788{
5789 PyObject *return_value = NULL;
5790 int _return_value;
5791
5792 _return_value = os_DirEntry_is_symlink_impl(self);
5793 if ((_return_value == -1) && PyErr_Occurred()) {
5794 goto exit;
5795 }
5796 return_value = PyBool_FromLong((long)_return_value);
5797
5798exit:
5799 return return_value;
5800}
5801
5802PyDoc_STRVAR(os_DirEntry_stat__doc__,
5803"stat($self, /, *, follow_symlinks=True)\n"
5804"--\n"
5805"\n"
5806"Return stat_result object for the entry; cached per entry.");
5807
5808#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005809 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005810
5811static PyObject *
5812os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5813
5814static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005815os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005816{
5817 PyObject *return_value = NULL;
5818 static const char * const _keywords[] = {"follow_symlinks", NULL};
5819 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5820 int follow_symlinks = 1;
5821
Victor Stinner3e1fad62017-01-17 01:29:01 +01005822 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005823 &follow_symlinks)) {
5824 goto exit;
5825 }
5826 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5827
5828exit:
5829 return return_value;
5830}
5831
5832PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5833"is_dir($self, /, *, follow_symlinks=True)\n"
5834"--\n"
5835"\n"
5836"Return True if the entry is a directory; cached per entry.");
5837
5838#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005839 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005840
5841static int
5842os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5843
5844static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005845os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005846{
5847 PyObject *return_value = NULL;
5848 static const char * const _keywords[] = {"follow_symlinks", NULL};
5849 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5850 int follow_symlinks = 1;
5851 int _return_value;
5852
Victor Stinner3e1fad62017-01-17 01:29:01 +01005853 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005854 &follow_symlinks)) {
5855 goto exit;
5856 }
5857 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5858 if ((_return_value == -1) && PyErr_Occurred()) {
5859 goto exit;
5860 }
5861 return_value = PyBool_FromLong((long)_return_value);
5862
5863exit:
5864 return return_value;
5865}
5866
5867PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5868"is_file($self, /, *, follow_symlinks=True)\n"
5869"--\n"
5870"\n"
5871"Return True if the entry is a file; cached per entry.");
5872
5873#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005874 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005875
5876static int
5877os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5878
5879static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005880os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005881{
5882 PyObject *return_value = NULL;
5883 static const char * const _keywords[] = {"follow_symlinks", NULL};
5884 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5885 int follow_symlinks = 1;
5886 int _return_value;
5887
Victor Stinner3e1fad62017-01-17 01:29:01 +01005888 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005889 &follow_symlinks)) {
5890 goto exit;
5891 }
5892 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5893 if ((_return_value == -1) && PyErr_Occurred()) {
5894 goto exit;
5895 }
5896 return_value = PyBool_FromLong((long)_return_value);
5897
5898exit:
5899 return return_value;
5900}
5901
5902PyDoc_STRVAR(os_DirEntry_inode__doc__,
5903"inode($self, /)\n"
5904"--\n"
5905"\n"
5906"Return inode of the entry; cached per entry.");
5907
5908#define OS_DIRENTRY_INODE_METHODDEF \
5909 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5910
5911static PyObject *
5912os_DirEntry_inode_impl(DirEntry *self);
5913
5914static PyObject *
5915os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5916{
5917 return os_DirEntry_inode_impl(self);
5918}
5919
5920PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5921"__fspath__($self, /)\n"
5922"--\n"
5923"\n"
5924"Returns the path for the entry.");
5925
5926#define OS_DIRENTRY___FSPATH___METHODDEF \
5927 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5928
5929static PyObject *
5930os_DirEntry___fspath___impl(DirEntry *self);
5931
5932static PyObject *
5933os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5934{
5935 return os_DirEntry___fspath___impl(self);
5936}
5937
5938PyDoc_STRVAR(os_scandir__doc__,
5939"scandir($module, /, path=None)\n"
5940"--\n"
5941"\n"
5942"Return an iterator of DirEntry objects for given path.\n"
5943"\n"
BNMetrics08026b12018-11-02 17:56:25 +00005944"path can be specified as either str, bytes, or a path-like object. If path\n"
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005945"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5946"all other circumstances they will be str.\n"
5947"\n"
5948"If path is None, uses the path=\'.\'.");
5949
5950#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005951 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005952
5953static PyObject *
5954os_scandir_impl(PyObject *module, path_t *path);
5955
5956static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005957os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005958{
5959 PyObject *return_value = NULL;
5960 static const char * const _keywords[] = {"path", NULL};
5961 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03005962 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005963
Victor Stinner3e1fad62017-01-17 01:29:01 +01005964 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005965 path_converter, &path)) {
5966 goto exit;
5967 }
5968 return_value = os_scandir_impl(module, &path);
5969
5970exit:
5971 /* Cleanup for path */
5972 path_cleanup(&path);
5973
5974 return return_value;
5975}
5976
Ethan Furman410ef8e2016-06-04 12:06:26 -07005977PyDoc_STRVAR(os_fspath__doc__,
5978"fspath($module, /, path)\n"
5979"--\n"
5980"\n"
5981"Return the file system path representation of the object.\n"
5982"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005983"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5984"object defines __fspath__(), then return the result of that method. All other\n"
5985"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005986
5987#define OS_FSPATH_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005988 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07005989
5990static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005991os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07005992
5993static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005994os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07005995{
5996 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005997 static const char * const _keywords[] = {"path", NULL};
5998 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07005999 PyObject *path;
6000
Victor Stinner3e1fad62017-01-17 01:29:01 +01006001 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006002 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006003 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006004 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006005 return_value = os_fspath_impl(module, path);
6006
6007exit:
6008 return return_value;
6009}
6010
Victor Stinner9b1f4742016-09-06 16:18:52 -07006011#if defined(HAVE_GETRANDOM_SYSCALL)
6012
6013PyDoc_STRVAR(os_getrandom__doc__,
6014"getrandom($module, /, size, flags=0)\n"
6015"--\n"
6016"\n"
6017"Obtain a series of random bytes.");
6018
6019#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006020 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006021
6022static PyObject *
6023os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6024
6025static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006026os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006027{
6028 PyObject *return_value = NULL;
6029 static const char * const _keywords[] = {"size", "flags", NULL};
6030 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6031 Py_ssize_t size;
6032 int flags = 0;
6033
Victor Stinner3e1fad62017-01-17 01:29:01 +01006034 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006035 &size, &flags)) {
6036 goto exit;
6037 }
6038 return_value = os_getrandom_impl(module, size, flags);
6039
6040exit:
6041 return return_value;
6042}
6043
6044#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6045
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006046#ifndef OS_TTYNAME_METHODDEF
6047 #define OS_TTYNAME_METHODDEF
6048#endif /* !defined(OS_TTYNAME_METHODDEF) */
6049
6050#ifndef OS_CTERMID_METHODDEF
6051 #define OS_CTERMID_METHODDEF
6052#endif /* !defined(OS_CTERMID_METHODDEF) */
6053
6054#ifndef OS_FCHDIR_METHODDEF
6055 #define OS_FCHDIR_METHODDEF
6056#endif /* !defined(OS_FCHDIR_METHODDEF) */
6057
6058#ifndef OS_FCHMOD_METHODDEF
6059 #define OS_FCHMOD_METHODDEF
6060#endif /* !defined(OS_FCHMOD_METHODDEF) */
6061
6062#ifndef OS_LCHMOD_METHODDEF
6063 #define OS_LCHMOD_METHODDEF
6064#endif /* !defined(OS_LCHMOD_METHODDEF) */
6065
6066#ifndef OS_CHFLAGS_METHODDEF
6067 #define OS_CHFLAGS_METHODDEF
6068#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6069
6070#ifndef OS_LCHFLAGS_METHODDEF
6071 #define OS_LCHFLAGS_METHODDEF
6072#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6073
6074#ifndef OS_CHROOT_METHODDEF
6075 #define OS_CHROOT_METHODDEF
6076#endif /* !defined(OS_CHROOT_METHODDEF) */
6077
6078#ifndef OS_FSYNC_METHODDEF
6079 #define OS_FSYNC_METHODDEF
6080#endif /* !defined(OS_FSYNC_METHODDEF) */
6081
6082#ifndef OS_SYNC_METHODDEF
6083 #define OS_SYNC_METHODDEF
6084#endif /* !defined(OS_SYNC_METHODDEF) */
6085
6086#ifndef OS_FDATASYNC_METHODDEF
6087 #define OS_FDATASYNC_METHODDEF
6088#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6089
6090#ifndef OS_CHOWN_METHODDEF
6091 #define OS_CHOWN_METHODDEF
6092#endif /* !defined(OS_CHOWN_METHODDEF) */
6093
6094#ifndef OS_FCHOWN_METHODDEF
6095 #define OS_FCHOWN_METHODDEF
6096#endif /* !defined(OS_FCHOWN_METHODDEF) */
6097
6098#ifndef OS_LCHOWN_METHODDEF
6099 #define OS_LCHOWN_METHODDEF
6100#endif /* !defined(OS_LCHOWN_METHODDEF) */
6101
6102#ifndef OS_LINK_METHODDEF
6103 #define OS_LINK_METHODDEF
6104#endif /* !defined(OS_LINK_METHODDEF) */
6105
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006106#ifndef OS__GETFULLPATHNAME_METHODDEF
6107 #define OS__GETFULLPATHNAME_METHODDEF
6108#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6109
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006110#ifndef OS__GETFINALPATHNAME_METHODDEF
6111 #define OS__GETFINALPATHNAME_METHODDEF
6112#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6113
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006114#ifndef OS__ISDIR_METHODDEF
6115 #define OS__ISDIR_METHODDEF
6116#endif /* !defined(OS__ISDIR_METHODDEF) */
6117
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006118#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6119 #define OS__GETVOLUMEPATHNAME_METHODDEF
6120#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6121
6122#ifndef OS_NICE_METHODDEF
6123 #define OS_NICE_METHODDEF
6124#endif /* !defined(OS_NICE_METHODDEF) */
6125
6126#ifndef OS_GETPRIORITY_METHODDEF
6127 #define OS_GETPRIORITY_METHODDEF
6128#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6129
6130#ifndef OS_SETPRIORITY_METHODDEF
6131 #define OS_SETPRIORITY_METHODDEF
6132#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6133
6134#ifndef OS_SYSTEM_METHODDEF
6135 #define OS_SYSTEM_METHODDEF
6136#endif /* !defined(OS_SYSTEM_METHODDEF) */
6137
6138#ifndef OS_UNAME_METHODDEF
6139 #define OS_UNAME_METHODDEF
6140#endif /* !defined(OS_UNAME_METHODDEF) */
6141
6142#ifndef OS_EXECV_METHODDEF
6143 #define OS_EXECV_METHODDEF
6144#endif /* !defined(OS_EXECV_METHODDEF) */
6145
6146#ifndef OS_EXECVE_METHODDEF
6147 #define OS_EXECVE_METHODDEF
6148#endif /* !defined(OS_EXECVE_METHODDEF) */
6149
6150#ifndef OS_SPAWNV_METHODDEF
6151 #define OS_SPAWNV_METHODDEF
6152#endif /* !defined(OS_SPAWNV_METHODDEF) */
6153
6154#ifndef OS_SPAWNVE_METHODDEF
6155 #define OS_SPAWNVE_METHODDEF
6156#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6157
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006158#ifndef OS_REGISTER_AT_FORK_METHODDEF
6159 #define OS_REGISTER_AT_FORK_METHODDEF
6160#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6161
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006162#ifndef OS_FORK1_METHODDEF
6163 #define OS_FORK1_METHODDEF
6164#endif /* !defined(OS_FORK1_METHODDEF) */
6165
6166#ifndef OS_FORK_METHODDEF
6167 #define OS_FORK_METHODDEF
6168#endif /* !defined(OS_FORK_METHODDEF) */
6169
6170#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6171 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6172#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6173
6174#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6175 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6176#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6177
6178#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6179 #define OS_SCHED_GETSCHEDULER_METHODDEF
6180#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6181
6182#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6183 #define OS_SCHED_SETSCHEDULER_METHODDEF
6184#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6185
6186#ifndef OS_SCHED_GETPARAM_METHODDEF
6187 #define OS_SCHED_GETPARAM_METHODDEF
6188#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6189
6190#ifndef OS_SCHED_SETPARAM_METHODDEF
6191 #define OS_SCHED_SETPARAM_METHODDEF
6192#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6193
6194#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6195 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6196#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6197
6198#ifndef OS_SCHED_YIELD_METHODDEF
6199 #define OS_SCHED_YIELD_METHODDEF
6200#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6201
6202#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6203 #define OS_SCHED_SETAFFINITY_METHODDEF
6204#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6205
6206#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6207 #define OS_SCHED_GETAFFINITY_METHODDEF
6208#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6209
6210#ifndef OS_OPENPTY_METHODDEF
6211 #define OS_OPENPTY_METHODDEF
6212#endif /* !defined(OS_OPENPTY_METHODDEF) */
6213
6214#ifndef OS_FORKPTY_METHODDEF
6215 #define OS_FORKPTY_METHODDEF
6216#endif /* !defined(OS_FORKPTY_METHODDEF) */
6217
6218#ifndef OS_GETEGID_METHODDEF
6219 #define OS_GETEGID_METHODDEF
6220#endif /* !defined(OS_GETEGID_METHODDEF) */
6221
6222#ifndef OS_GETEUID_METHODDEF
6223 #define OS_GETEUID_METHODDEF
6224#endif /* !defined(OS_GETEUID_METHODDEF) */
6225
6226#ifndef OS_GETGID_METHODDEF
6227 #define OS_GETGID_METHODDEF
6228#endif /* !defined(OS_GETGID_METHODDEF) */
6229
Berker Peksag39404992016-09-15 20:45:16 +03006230#ifndef OS_GETPID_METHODDEF
6231 #define OS_GETPID_METHODDEF
6232#endif /* !defined(OS_GETPID_METHODDEF) */
6233
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006234#ifndef OS_GETGROUPS_METHODDEF
6235 #define OS_GETGROUPS_METHODDEF
6236#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6237
6238#ifndef OS_GETPGID_METHODDEF
6239 #define OS_GETPGID_METHODDEF
6240#endif /* !defined(OS_GETPGID_METHODDEF) */
6241
6242#ifndef OS_GETPGRP_METHODDEF
6243 #define OS_GETPGRP_METHODDEF
6244#endif /* !defined(OS_GETPGRP_METHODDEF) */
6245
6246#ifndef OS_SETPGRP_METHODDEF
6247 #define OS_SETPGRP_METHODDEF
6248#endif /* !defined(OS_SETPGRP_METHODDEF) */
6249
6250#ifndef OS_GETPPID_METHODDEF
6251 #define OS_GETPPID_METHODDEF
6252#endif /* !defined(OS_GETPPID_METHODDEF) */
6253
6254#ifndef OS_GETLOGIN_METHODDEF
6255 #define OS_GETLOGIN_METHODDEF
6256#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6257
6258#ifndef OS_GETUID_METHODDEF
6259 #define OS_GETUID_METHODDEF
6260#endif /* !defined(OS_GETUID_METHODDEF) */
6261
6262#ifndef OS_KILL_METHODDEF
6263 #define OS_KILL_METHODDEF
6264#endif /* !defined(OS_KILL_METHODDEF) */
6265
6266#ifndef OS_KILLPG_METHODDEF
6267 #define OS_KILLPG_METHODDEF
6268#endif /* !defined(OS_KILLPG_METHODDEF) */
6269
6270#ifndef OS_PLOCK_METHODDEF
6271 #define OS_PLOCK_METHODDEF
6272#endif /* !defined(OS_PLOCK_METHODDEF) */
6273
6274#ifndef OS_SETUID_METHODDEF
6275 #define OS_SETUID_METHODDEF
6276#endif /* !defined(OS_SETUID_METHODDEF) */
6277
6278#ifndef OS_SETEUID_METHODDEF
6279 #define OS_SETEUID_METHODDEF
6280#endif /* !defined(OS_SETEUID_METHODDEF) */
6281
6282#ifndef OS_SETEGID_METHODDEF
6283 #define OS_SETEGID_METHODDEF
6284#endif /* !defined(OS_SETEGID_METHODDEF) */
6285
6286#ifndef OS_SETREUID_METHODDEF
6287 #define OS_SETREUID_METHODDEF
6288#endif /* !defined(OS_SETREUID_METHODDEF) */
6289
6290#ifndef OS_SETREGID_METHODDEF
6291 #define OS_SETREGID_METHODDEF
6292#endif /* !defined(OS_SETREGID_METHODDEF) */
6293
6294#ifndef OS_SETGID_METHODDEF
6295 #define OS_SETGID_METHODDEF
6296#endif /* !defined(OS_SETGID_METHODDEF) */
6297
6298#ifndef OS_SETGROUPS_METHODDEF
6299 #define OS_SETGROUPS_METHODDEF
6300#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6301
6302#ifndef OS_WAIT3_METHODDEF
6303 #define OS_WAIT3_METHODDEF
6304#endif /* !defined(OS_WAIT3_METHODDEF) */
6305
6306#ifndef OS_WAIT4_METHODDEF
6307 #define OS_WAIT4_METHODDEF
6308#endif /* !defined(OS_WAIT4_METHODDEF) */
6309
6310#ifndef OS_WAITID_METHODDEF
6311 #define OS_WAITID_METHODDEF
6312#endif /* !defined(OS_WAITID_METHODDEF) */
6313
6314#ifndef OS_WAITPID_METHODDEF
6315 #define OS_WAITPID_METHODDEF
6316#endif /* !defined(OS_WAITPID_METHODDEF) */
6317
6318#ifndef OS_WAIT_METHODDEF
6319 #define OS_WAIT_METHODDEF
6320#endif /* !defined(OS_WAIT_METHODDEF) */
6321
6322#ifndef OS_SYMLINK_METHODDEF
6323 #define OS_SYMLINK_METHODDEF
6324#endif /* !defined(OS_SYMLINK_METHODDEF) */
6325
6326#ifndef OS_TIMES_METHODDEF
6327 #define OS_TIMES_METHODDEF
6328#endif /* !defined(OS_TIMES_METHODDEF) */
6329
6330#ifndef OS_GETSID_METHODDEF
6331 #define OS_GETSID_METHODDEF
6332#endif /* !defined(OS_GETSID_METHODDEF) */
6333
6334#ifndef OS_SETSID_METHODDEF
6335 #define OS_SETSID_METHODDEF
6336#endif /* !defined(OS_SETSID_METHODDEF) */
6337
6338#ifndef OS_SETPGID_METHODDEF
6339 #define OS_SETPGID_METHODDEF
6340#endif /* !defined(OS_SETPGID_METHODDEF) */
6341
6342#ifndef OS_TCGETPGRP_METHODDEF
6343 #define OS_TCGETPGRP_METHODDEF
6344#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6345
6346#ifndef OS_TCSETPGRP_METHODDEF
6347 #define OS_TCSETPGRP_METHODDEF
6348#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6349
6350#ifndef OS_LOCKF_METHODDEF
6351 #define OS_LOCKF_METHODDEF
6352#endif /* !defined(OS_LOCKF_METHODDEF) */
6353
6354#ifndef OS_READV_METHODDEF
6355 #define OS_READV_METHODDEF
6356#endif /* !defined(OS_READV_METHODDEF) */
6357
6358#ifndef OS_PREAD_METHODDEF
6359 #define OS_PREAD_METHODDEF
6360#endif /* !defined(OS_PREAD_METHODDEF) */
6361
Pablo Galindo4defba32018-01-27 16:16:37 +00006362#ifndef OS_PREADV_METHODDEF
6363 #define OS_PREADV_METHODDEF
6364#endif /* !defined(OS_PREADV_METHODDEF) */
6365
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006366#ifndef OS_PIPE_METHODDEF
6367 #define OS_PIPE_METHODDEF
6368#endif /* !defined(OS_PIPE_METHODDEF) */
6369
6370#ifndef OS_PIPE2_METHODDEF
6371 #define OS_PIPE2_METHODDEF
6372#endif /* !defined(OS_PIPE2_METHODDEF) */
6373
6374#ifndef OS_WRITEV_METHODDEF
6375 #define OS_WRITEV_METHODDEF
6376#endif /* !defined(OS_WRITEV_METHODDEF) */
6377
6378#ifndef OS_PWRITE_METHODDEF
6379 #define OS_PWRITE_METHODDEF
6380#endif /* !defined(OS_PWRITE_METHODDEF) */
6381
Pablo Galindo4defba32018-01-27 16:16:37 +00006382#ifndef OS_PWRITEV_METHODDEF
6383 #define OS_PWRITEV_METHODDEF
6384#endif /* !defined(OS_PWRITEV_METHODDEF) */
6385
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006386#ifndef OS_MKFIFO_METHODDEF
6387 #define OS_MKFIFO_METHODDEF
6388#endif /* !defined(OS_MKFIFO_METHODDEF) */
6389
6390#ifndef OS_MKNOD_METHODDEF
6391 #define OS_MKNOD_METHODDEF
6392#endif /* !defined(OS_MKNOD_METHODDEF) */
6393
6394#ifndef OS_MAJOR_METHODDEF
6395 #define OS_MAJOR_METHODDEF
6396#endif /* !defined(OS_MAJOR_METHODDEF) */
6397
6398#ifndef OS_MINOR_METHODDEF
6399 #define OS_MINOR_METHODDEF
6400#endif /* !defined(OS_MINOR_METHODDEF) */
6401
6402#ifndef OS_MAKEDEV_METHODDEF
6403 #define OS_MAKEDEV_METHODDEF
6404#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6405
6406#ifndef OS_FTRUNCATE_METHODDEF
6407 #define OS_FTRUNCATE_METHODDEF
6408#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6409
6410#ifndef OS_TRUNCATE_METHODDEF
6411 #define OS_TRUNCATE_METHODDEF
6412#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6413
6414#ifndef OS_POSIX_FALLOCATE_METHODDEF
6415 #define OS_POSIX_FALLOCATE_METHODDEF
6416#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6417
6418#ifndef OS_POSIX_FADVISE_METHODDEF
6419 #define OS_POSIX_FADVISE_METHODDEF
6420#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6421
6422#ifndef OS_PUTENV_METHODDEF
6423 #define OS_PUTENV_METHODDEF
6424#endif /* !defined(OS_PUTENV_METHODDEF) */
6425
6426#ifndef OS_UNSETENV_METHODDEF
6427 #define OS_UNSETENV_METHODDEF
6428#endif /* !defined(OS_UNSETENV_METHODDEF) */
6429
6430#ifndef OS_WCOREDUMP_METHODDEF
6431 #define OS_WCOREDUMP_METHODDEF
6432#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6433
6434#ifndef OS_WIFCONTINUED_METHODDEF
6435 #define OS_WIFCONTINUED_METHODDEF
6436#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6437
6438#ifndef OS_WIFSTOPPED_METHODDEF
6439 #define OS_WIFSTOPPED_METHODDEF
6440#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6441
6442#ifndef OS_WIFSIGNALED_METHODDEF
6443 #define OS_WIFSIGNALED_METHODDEF
6444#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6445
6446#ifndef OS_WIFEXITED_METHODDEF
6447 #define OS_WIFEXITED_METHODDEF
6448#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6449
6450#ifndef OS_WEXITSTATUS_METHODDEF
6451 #define OS_WEXITSTATUS_METHODDEF
6452#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6453
6454#ifndef OS_WTERMSIG_METHODDEF
6455 #define OS_WTERMSIG_METHODDEF
6456#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6457
6458#ifndef OS_WSTOPSIG_METHODDEF
6459 #define OS_WSTOPSIG_METHODDEF
6460#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6461
6462#ifndef OS_FSTATVFS_METHODDEF
6463 #define OS_FSTATVFS_METHODDEF
6464#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6465
6466#ifndef OS_STATVFS_METHODDEF
6467 #define OS_STATVFS_METHODDEF
6468#endif /* !defined(OS_STATVFS_METHODDEF) */
6469
6470#ifndef OS__GETDISKUSAGE_METHODDEF
6471 #define OS__GETDISKUSAGE_METHODDEF
6472#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6473
6474#ifndef OS_FPATHCONF_METHODDEF
6475 #define OS_FPATHCONF_METHODDEF
6476#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6477
6478#ifndef OS_PATHCONF_METHODDEF
6479 #define OS_PATHCONF_METHODDEF
6480#endif /* !defined(OS_PATHCONF_METHODDEF) */
6481
6482#ifndef OS_CONFSTR_METHODDEF
6483 #define OS_CONFSTR_METHODDEF
6484#endif /* !defined(OS_CONFSTR_METHODDEF) */
6485
6486#ifndef OS_SYSCONF_METHODDEF
6487 #define OS_SYSCONF_METHODDEF
6488#endif /* !defined(OS_SYSCONF_METHODDEF) */
6489
Steve Dowercc16be82016-09-08 10:35:16 -07006490#ifndef OS_STARTFILE_METHODDEF
6491 #define OS_STARTFILE_METHODDEF
6492#endif /* !defined(OS_STARTFILE_METHODDEF) */
6493
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006494#ifndef OS_GETLOADAVG_METHODDEF
6495 #define OS_GETLOADAVG_METHODDEF
6496#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6497
6498#ifndef OS_SETRESUID_METHODDEF
6499 #define OS_SETRESUID_METHODDEF
6500#endif /* !defined(OS_SETRESUID_METHODDEF) */
6501
6502#ifndef OS_SETRESGID_METHODDEF
6503 #define OS_SETRESGID_METHODDEF
6504#endif /* !defined(OS_SETRESGID_METHODDEF) */
6505
6506#ifndef OS_GETRESUID_METHODDEF
6507 #define OS_GETRESUID_METHODDEF
6508#endif /* !defined(OS_GETRESUID_METHODDEF) */
6509
6510#ifndef OS_GETRESGID_METHODDEF
6511 #define OS_GETRESGID_METHODDEF
6512#endif /* !defined(OS_GETRESGID_METHODDEF) */
6513
6514#ifndef OS_GETXATTR_METHODDEF
6515 #define OS_GETXATTR_METHODDEF
6516#endif /* !defined(OS_GETXATTR_METHODDEF) */
6517
6518#ifndef OS_SETXATTR_METHODDEF
6519 #define OS_SETXATTR_METHODDEF
6520#endif /* !defined(OS_SETXATTR_METHODDEF) */
6521
6522#ifndef OS_REMOVEXATTR_METHODDEF
6523 #define OS_REMOVEXATTR_METHODDEF
6524#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6525
6526#ifndef OS_LISTXATTR_METHODDEF
6527 #define OS_LISTXATTR_METHODDEF
6528#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6529
6530#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6531 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6532#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6533
6534#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6535 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6536#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006537
6538#ifndef OS_GETRANDOM_METHODDEF
6539 #define OS_GETRANDOM_METHODDEF
6540#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Benjamin Peterson00cc0fe2019-02-12 20:36:09 -08006541/*[clinic end generated code: output=32c935671ee020d5 input=a9049054013a1b77]*/