blob: 26dedd1a734147b7e0deb2de282d43c13516fd29 [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"
12" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
13" dir_fd\n"
14" If not None, it should be a file descriptor open to a directory,\n"
15" and path should be a relative string; path will then be relative to\n"
16" that directory.\n"
17" follow_symlinks\n"
18" If False, and the last element of the path is a symbolic link,\n"
19" stat will examine the symbolic link itself instead of the file\n"
20" the link points to.\n"
21"\n"
22"dir_fd and follow_symlinks may not be implemented\n"
23" on your platform. If they are unavailable, using them will raise a\n"
24" NotImplementedError.\n"
25"\n"
26"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
27" an open file descriptor.");
28
29#define OS_STAT_METHODDEF \
30 {"stat", (PyCFunction)os_stat, METH_VARARGS|METH_KEYWORDS, os_stat__doc__},
31
32static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030033os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030034
35static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030036os_stat(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030037{
38 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030039 static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
40 static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030041 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
42 int dir_fd = DEFAULT_DIR_FD;
43 int follow_symlinks = 1;
44
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030045 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030046 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030047 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030048 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030049 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
50
51exit:
52 /* Cleanup for path */
53 path_cleanup(&path);
54
55 return return_value;
56}
57
58PyDoc_STRVAR(os_lstat__doc__,
59"lstat($module, /, path, *, dir_fd=None)\n"
60"--\n"
61"\n"
62"Perform a stat system call on the given path, without following symbolic links.\n"
63"\n"
64"Like stat(), but do not follow symbolic links.\n"
65"Equivalent to stat(path, follow_symlinks=False).");
66
67#define OS_LSTAT_METHODDEF \
68 {"lstat", (PyCFunction)os_lstat, METH_VARARGS|METH_KEYWORDS, os_lstat__doc__},
69
70static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030071os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030072
73static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030074os_lstat(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030075{
76 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030077 static const char * const _keywords[] = {"path", "dir_fd", NULL};
78 static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030079 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
80 int dir_fd = DEFAULT_DIR_FD;
81
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030082 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030083 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030084 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030085 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030086 return_value = os_lstat_impl(module, &path, dir_fd);
87
88exit:
89 /* Cleanup for path */
90 path_cleanup(&path);
91
92 return return_value;
93}
94
95PyDoc_STRVAR(os_access__doc__,
96"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
97" follow_symlinks=True)\n"
98"--\n"
99"\n"
100"Use the real uid/gid to test for access to a path.\n"
101"\n"
102" path\n"
103" Path to be tested; can be string, bytes, or open-file-descriptor int.\n"
104" mode\n"
105" Operating-system mode bitfield. Can be F_OK to test existence,\n"
106" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
107" dir_fd\n"
108" If not None, it should be a file descriptor open to a directory,\n"
109" and path should be relative; path will then be relative to that\n"
110" directory.\n"
111" effective_ids\n"
112" If True, access will use the effective uid/gid instead of\n"
113" the real uid/gid.\n"
114" follow_symlinks\n"
115" If False, and the last element of the path is a symbolic link,\n"
116" access will examine the symbolic link itself instead of the file\n"
117" the link points to.\n"
118"\n"
119"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
120" on your platform. If they are unavailable, using them will raise a\n"
121" NotImplementedError.\n"
122"\n"
123"Note that most operations will use the effective uid/gid, therefore this\n"
124" routine can be used in a suid/sgid environment to test if the invoking user\n"
125" has the specified access to the path.");
126
127#define OS_ACCESS_METHODDEF \
128 {"access", (PyCFunction)os_access, METH_VARARGS|METH_KEYWORDS, os_access__doc__},
129
130static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300131os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400132 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300133
134static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300135os_access(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300136{
137 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300138 static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
139 static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300140 path_t path = PATH_T_INITIALIZE("access", "path", 0, 1);
141 int mode;
142 int dir_fd = DEFAULT_DIR_FD;
143 int effective_ids = 0;
144 int follow_symlinks = 1;
145 int _return_value;
146
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300147 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300148 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300149 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300150 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300151 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300152 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300153 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300154 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300155 return_value = PyBool_FromLong((long)_return_value);
156
157exit:
158 /* Cleanup for path */
159 path_cleanup(&path);
160
161 return return_value;
162}
163
164#if defined(HAVE_TTYNAME)
165
166PyDoc_STRVAR(os_ttyname__doc__,
167"ttyname($module, fd, /)\n"
168"--\n"
169"\n"
170"Return the name of the terminal device connected to \'fd\'.\n"
171"\n"
172" fd\n"
173" Integer file descriptor handle.");
174
175#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300176 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300177
178static char *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300179os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300180
181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300182os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300183{
184 PyObject *return_value = NULL;
185 int fd;
186 char *_return_value;
187
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300188 if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300189 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300190 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300191 _return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300192 if (_return_value == NULL) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300193 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300194 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300195 return_value = PyUnicode_DecodeFSDefault(_return_value);
196
197exit:
198 return return_value;
199}
200
201#endif /* defined(HAVE_TTYNAME) */
202
203#if defined(HAVE_CTERMID)
204
205PyDoc_STRVAR(os_ctermid__doc__,
206"ctermid($module, /)\n"
207"--\n"
208"\n"
209"Return the name of the controlling terminal for this process.");
210
211#define OS_CTERMID_METHODDEF \
212 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
213
214static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300215os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300216
217static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300218os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300219{
220 return os_ctermid_impl(module);
221}
222
223#endif /* defined(HAVE_CTERMID) */
224
225PyDoc_STRVAR(os_chdir__doc__,
226"chdir($module, /, path)\n"
227"--\n"
228"\n"
229"Change the current working directory to the specified path.\n"
230"\n"
231"path may always be specified as a string.\n"
232"On some platforms, path may also be specified as an open file descriptor.\n"
233" If this functionality is unavailable, using it raises an exception.");
234
235#define OS_CHDIR_METHODDEF \
236 {"chdir", (PyCFunction)os_chdir, METH_VARARGS|METH_KEYWORDS, os_chdir__doc__},
237
238static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300239os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300240
241static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300242os_chdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300243{
244 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300245 static const char * const _keywords[] = {"path", NULL};
246 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300247 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
248
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300249 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300250 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300251 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300252 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300253 return_value = os_chdir_impl(module, &path);
254
255exit:
256 /* Cleanup for path */
257 path_cleanup(&path);
258
259 return return_value;
260}
261
262#if defined(HAVE_FCHDIR)
263
264PyDoc_STRVAR(os_fchdir__doc__,
265"fchdir($module, /, fd)\n"
266"--\n"
267"\n"
268"Change to the directory of the given file descriptor.\n"
269"\n"
270"fd must be opened on a directory, not a file.\n"
271"Equivalent to os.chdir(fd).");
272
273#define OS_FCHDIR_METHODDEF \
274 {"fchdir", (PyCFunction)os_fchdir, METH_VARARGS|METH_KEYWORDS, os_fchdir__doc__},
275
276static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300277os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300278
279static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300280os_fchdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300281{
282 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300283 static const char * const _keywords[] = {"fd", NULL};
284 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300285 int fd;
286
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300287 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300288 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300289 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300290 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300291 return_value = os_fchdir_impl(module, fd);
292
293exit:
294 return return_value;
295}
296
297#endif /* defined(HAVE_FCHDIR) */
298
299PyDoc_STRVAR(os_chmod__doc__,
300"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
301"--\n"
302"\n"
303"Change the access permissions of a file.\n"
304"\n"
305" path\n"
306" Path to be modified. May always be specified as a str or bytes.\n"
307" On some platforms, path may also be specified as an open file descriptor.\n"
308" If this functionality is unavailable, using it raises an exception.\n"
309" mode\n"
310" Operating-system mode bitfield.\n"
311" dir_fd\n"
312" If not None, it should be a file descriptor open to a directory,\n"
313" and path should be relative; path will then be relative to that\n"
314" directory.\n"
315" follow_symlinks\n"
316" If False, and the last element of the path is a symbolic link,\n"
317" chmod will modify the symbolic link itself instead of the file\n"
318" the link points to.\n"
319"\n"
320"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
321" an open file descriptor.\n"
322"dir_fd and follow_symlinks may not be implemented on your platform.\n"
323" If they are unavailable, using them will raise a NotImplementedError.");
324
325#define OS_CHMOD_METHODDEF \
326 {"chmod", (PyCFunction)os_chmod, METH_VARARGS|METH_KEYWORDS, os_chmod__doc__},
327
328static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300329os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400330 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300331
332static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300333os_chmod(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300334{
335 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300336 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
337 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300338 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
339 int mode;
340 int dir_fd = DEFAULT_DIR_FD;
341 int follow_symlinks = 1;
342
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300343 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300344 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300345 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300346 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300347 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
348
349exit:
350 /* Cleanup for path */
351 path_cleanup(&path);
352
353 return return_value;
354}
355
356#if defined(HAVE_FCHMOD)
357
358PyDoc_STRVAR(os_fchmod__doc__,
359"fchmod($module, /, fd, mode)\n"
360"--\n"
361"\n"
362"Change the access permissions of the file given by file descriptor fd.\n"
363"\n"
364"Equivalent to os.chmod(fd, mode).");
365
366#define OS_FCHMOD_METHODDEF \
367 {"fchmod", (PyCFunction)os_fchmod, METH_VARARGS|METH_KEYWORDS, os_fchmod__doc__},
368
369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300370os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300371
372static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300373os_fchmod(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300374{
375 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300376 static const char * const _keywords[] = {"fd", "mode", NULL};
377 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300378 int fd;
379 int mode;
380
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300381 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300382 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300383 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300384 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300385 return_value = os_fchmod_impl(module, fd, mode);
386
387exit:
388 return return_value;
389}
390
391#endif /* defined(HAVE_FCHMOD) */
392
393#if defined(HAVE_LCHMOD)
394
395PyDoc_STRVAR(os_lchmod__doc__,
396"lchmod($module, /, path, mode)\n"
397"--\n"
398"\n"
399"Change the access permissions of a file, without following symbolic links.\n"
400"\n"
401"If path is a symlink, this affects the link itself rather than the target.\n"
402"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
403
404#define OS_LCHMOD_METHODDEF \
405 {"lchmod", (PyCFunction)os_lchmod, METH_VARARGS|METH_KEYWORDS, os_lchmod__doc__},
406
407static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300408os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300409
410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300411os_lchmod(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300412{
413 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300414 static const char * const _keywords[] = {"path", "mode", NULL};
415 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300416 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
417 int mode;
418
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300419 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300420 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300421 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300422 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300423 return_value = os_lchmod_impl(module, &path, mode);
424
425exit:
426 /* Cleanup for path */
427 path_cleanup(&path);
428
429 return return_value;
430}
431
432#endif /* defined(HAVE_LCHMOD) */
433
434#if defined(HAVE_CHFLAGS)
435
436PyDoc_STRVAR(os_chflags__doc__,
437"chflags($module, /, path, flags, follow_symlinks=True)\n"
438"--\n"
439"\n"
440"Set file flags.\n"
441"\n"
442"If follow_symlinks is False, and the last element of the path is a symbolic\n"
443" link, chflags will change flags on the symbolic link itself instead of the\n"
444" file the link points to.\n"
445"follow_symlinks may not be implemented on your platform. If it is\n"
446"unavailable, using it will raise a NotImplementedError.");
447
448#define OS_CHFLAGS_METHODDEF \
449 {"chflags", (PyCFunction)os_chflags, METH_VARARGS|METH_KEYWORDS, os_chflags__doc__},
450
451static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300452os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400453 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300454
455static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300456os_chflags(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300457{
458 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300459 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
460 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300461 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
462 unsigned long flags;
463 int follow_symlinks = 1;
464
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300465 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300466 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300467 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300468 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300469 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
470
471exit:
472 /* Cleanup for path */
473 path_cleanup(&path);
474
475 return return_value;
476}
477
478#endif /* defined(HAVE_CHFLAGS) */
479
480#if defined(HAVE_LCHFLAGS)
481
482PyDoc_STRVAR(os_lchflags__doc__,
483"lchflags($module, /, path, flags)\n"
484"--\n"
485"\n"
486"Set file flags.\n"
487"\n"
488"This function will not follow symbolic links.\n"
489"Equivalent to chflags(path, flags, follow_symlinks=False).");
490
491#define OS_LCHFLAGS_METHODDEF \
492 {"lchflags", (PyCFunction)os_lchflags, METH_VARARGS|METH_KEYWORDS, os_lchflags__doc__},
493
494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300495os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300496
497static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300498os_lchflags(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300499{
500 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300501 static const char * const _keywords[] = {"path", "flags", NULL};
502 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300503 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
504 unsigned long flags;
505
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300506 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300507 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300508 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300509 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300510 return_value = os_lchflags_impl(module, &path, flags);
511
512exit:
513 /* Cleanup for path */
514 path_cleanup(&path);
515
516 return return_value;
517}
518
519#endif /* defined(HAVE_LCHFLAGS) */
520
521#if defined(HAVE_CHROOT)
522
523PyDoc_STRVAR(os_chroot__doc__,
524"chroot($module, /, path)\n"
525"--\n"
526"\n"
527"Change root directory to path.");
528
529#define OS_CHROOT_METHODDEF \
530 {"chroot", (PyCFunction)os_chroot, METH_VARARGS|METH_KEYWORDS, os_chroot__doc__},
531
532static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300533os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300534
535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300536os_chroot(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300537{
538 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300539 static const char * const _keywords[] = {"path", NULL};
540 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300541 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
542
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300543 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300544 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300545 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300546 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300547 return_value = os_chroot_impl(module, &path);
548
549exit:
550 /* Cleanup for path */
551 path_cleanup(&path);
552
553 return return_value;
554}
555
556#endif /* defined(HAVE_CHROOT) */
557
558#if defined(HAVE_FSYNC)
559
560PyDoc_STRVAR(os_fsync__doc__,
561"fsync($module, /, fd)\n"
562"--\n"
563"\n"
564"Force write of fd to disk.");
565
566#define OS_FSYNC_METHODDEF \
567 {"fsync", (PyCFunction)os_fsync, METH_VARARGS|METH_KEYWORDS, os_fsync__doc__},
568
569static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300570os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300571
572static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300573os_fsync(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300574{
575 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300576 static const char * const _keywords[] = {"fd", NULL};
577 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300578 int fd;
579
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300580 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300581 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300582 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300583 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300584 return_value = os_fsync_impl(module, fd);
585
586exit:
587 return return_value;
588}
589
590#endif /* defined(HAVE_FSYNC) */
591
592#if defined(HAVE_SYNC)
593
594PyDoc_STRVAR(os_sync__doc__,
595"sync($module, /)\n"
596"--\n"
597"\n"
598"Force write of everything to disk.");
599
600#define OS_SYNC_METHODDEF \
601 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
602
603static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300604os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300605
606static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300607os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300608{
609 return os_sync_impl(module);
610}
611
612#endif /* defined(HAVE_SYNC) */
613
614#if defined(HAVE_FDATASYNC)
615
616PyDoc_STRVAR(os_fdatasync__doc__,
617"fdatasync($module, /, fd)\n"
618"--\n"
619"\n"
620"Force write of fd to disk without forcing update of metadata.");
621
622#define OS_FDATASYNC_METHODDEF \
623 {"fdatasync", (PyCFunction)os_fdatasync, METH_VARARGS|METH_KEYWORDS, os_fdatasync__doc__},
624
625static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300626os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300627
628static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300629os_fdatasync(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300630{
631 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300632 static const char * const _keywords[] = {"fd", NULL};
633 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300634 int fd;
635
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300636 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300637 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300638 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300639 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300640 return_value = os_fdatasync_impl(module, fd);
641
642exit:
643 return return_value;
644}
645
646#endif /* defined(HAVE_FDATASYNC) */
647
648#if defined(HAVE_CHOWN)
649
650PyDoc_STRVAR(os_chown__doc__,
651"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
652"--\n"
653"\n"
654"Change the owner and group id of path to the numeric uid and gid.\\\n"
655"\n"
656" path\n"
657" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
658" dir_fd\n"
659" If not None, it should be a file descriptor open to a directory,\n"
660" and path should be relative; path will then be relative to that\n"
661" directory.\n"
662" follow_symlinks\n"
663" If False, and the last element of the path is a symbolic link,\n"
664" stat will examine the symbolic link itself instead of the file\n"
665" the link points to.\n"
666"\n"
667"path may always be specified as a string.\n"
668"On some platforms, path may also be specified as an open file descriptor.\n"
669" If this functionality is unavailable, using it raises an exception.\n"
670"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
671" and path should be relative; path will then be relative to that directory.\n"
672"If follow_symlinks is False, and the last element of the path is a symbolic\n"
673" link, chown will modify the symbolic link itself instead of the file the\n"
674" link points to.\n"
675"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
676" an open file descriptor.\n"
677"dir_fd and follow_symlinks may not be implemented on your platform.\n"
678" If they are unavailable, using them will raise a NotImplementedError.");
679
680#define OS_CHOWN_METHODDEF \
681 {"chown", (PyCFunction)os_chown, METH_VARARGS|METH_KEYWORDS, os_chown__doc__},
682
683static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300684os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400685 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300686
687static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300688os_chown(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300689{
690 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300691 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
692 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300693 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
694 uid_t uid;
695 gid_t gid;
696 int dir_fd = DEFAULT_DIR_FD;
697 int follow_symlinks = 1;
698
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300699 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300700 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 +0300701 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300702 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300703 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
704
705exit:
706 /* Cleanup for path */
707 path_cleanup(&path);
708
709 return return_value;
710}
711
712#endif /* defined(HAVE_CHOWN) */
713
714#if defined(HAVE_FCHOWN)
715
716PyDoc_STRVAR(os_fchown__doc__,
717"fchown($module, /, fd, uid, gid)\n"
718"--\n"
719"\n"
720"Change the owner and group id of the file specified by file descriptor.\n"
721"\n"
722"Equivalent to os.chown(fd, uid, gid).");
723
724#define OS_FCHOWN_METHODDEF \
725 {"fchown", (PyCFunction)os_fchown, METH_VARARGS|METH_KEYWORDS, os_fchown__doc__},
726
727static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300728os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300729
730static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300731os_fchown(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300732{
733 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300734 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
735 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300736 int fd;
737 uid_t uid;
738 gid_t gid;
739
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300740 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300741 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300742 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300743 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300744 return_value = os_fchown_impl(module, fd, uid, gid);
745
746exit:
747 return return_value;
748}
749
750#endif /* defined(HAVE_FCHOWN) */
751
752#if defined(HAVE_LCHOWN)
753
754PyDoc_STRVAR(os_lchown__doc__,
755"lchown($module, /, path, uid, gid)\n"
756"--\n"
757"\n"
758"Change the owner and group id of path to the numeric uid and gid.\n"
759"\n"
760"This function will not follow symbolic links.\n"
761"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
762
763#define OS_LCHOWN_METHODDEF \
764 {"lchown", (PyCFunction)os_lchown, METH_VARARGS|METH_KEYWORDS, os_lchown__doc__},
765
766static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300767os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300768
769static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300770os_lchown(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300771{
772 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300773 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
774 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300775 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
776 uid_t uid;
777 gid_t gid;
778
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300779 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300780 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300781 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300782 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300783 return_value = os_lchown_impl(module, &path, uid, gid);
784
785exit:
786 /* Cleanup for path */
787 path_cleanup(&path);
788
789 return return_value;
790}
791
792#endif /* defined(HAVE_LCHOWN) */
793
794PyDoc_STRVAR(os_getcwd__doc__,
795"getcwd($module, /)\n"
796"--\n"
797"\n"
798"Return a unicode string representing the current working directory.");
799
800#define OS_GETCWD_METHODDEF \
801 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
802
803static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300804os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300805
806static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300807os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300808{
809 return os_getcwd_impl(module);
810}
811
812PyDoc_STRVAR(os_getcwdb__doc__,
813"getcwdb($module, /)\n"
814"--\n"
815"\n"
816"Return a bytes string representing the current working directory.");
817
818#define OS_GETCWDB_METHODDEF \
819 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
820
821static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300822os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300823
824static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300825os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300826{
827 return os_getcwdb_impl(module);
828}
829
830#if defined(HAVE_LINK)
831
832PyDoc_STRVAR(os_link__doc__,
833"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
834" follow_symlinks=True)\n"
835"--\n"
836"\n"
837"Create a hard link to a file.\n"
838"\n"
839"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
840" descriptor open to a directory, and the respective path string (src or dst)\n"
841" should be relative; the path will then be relative to that directory.\n"
842"If follow_symlinks is False, and the last element of src is a symbolic\n"
843" link, link will create a link to the symbolic link itself instead of the\n"
844" file the link points to.\n"
845"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
846" platform. If they are unavailable, using them will raise a\n"
847" NotImplementedError.");
848
849#define OS_LINK_METHODDEF \
850 {"link", (PyCFunction)os_link, METH_VARARGS|METH_KEYWORDS, os_link__doc__},
851
852static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300853os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400854 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300855
856static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300857os_link(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300858{
859 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300860 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
861 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300862 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
863 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
864 int src_dir_fd = DEFAULT_DIR_FD;
865 int dst_dir_fd = DEFAULT_DIR_FD;
866 int follow_symlinks = 1;
867
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300868 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300869 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 +0300870 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300871 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300872 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
873
874exit:
875 /* Cleanup for src */
876 path_cleanup(&src);
877 /* Cleanup for dst */
878 path_cleanup(&dst);
879
880 return return_value;
881}
882
883#endif /* defined(HAVE_LINK) */
884
885PyDoc_STRVAR(os_listdir__doc__,
886"listdir($module, /, path=None)\n"
887"--\n"
888"\n"
889"Return a list containing the names of the files in the directory.\n"
890"\n"
891"path can be specified as either str or bytes. If path is bytes,\n"
892" the filenames returned will also be bytes; in all other circumstances\n"
893" the filenames returned will be str.\n"
894"If path is None, uses the path=\'.\'.\n"
895"On some platforms, path may also be specified as an open file descriptor;\\\n"
896" the file descriptor must refer to a directory.\n"
897" If this functionality is unavailable, using it raises NotImplementedError.\n"
898"\n"
899"The list is in arbitrary order. It does not include the special\n"
900"entries \'.\' and \'..\' even if they are present in the directory.");
901
902#define OS_LISTDIR_METHODDEF \
903 {"listdir", (PyCFunction)os_listdir, METH_VARARGS|METH_KEYWORDS, os_listdir__doc__},
904
905static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300906os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300907
908static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300909os_listdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300910{
911 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300912 static const char * const _keywords[] = {"path", NULL};
913 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300914 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
915
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300916 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300917 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300918 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300919 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300920 return_value = os_listdir_impl(module, &path);
921
922exit:
923 /* Cleanup for path */
924 path_cleanup(&path);
925
926 return return_value;
927}
928
929#if defined(MS_WINDOWS)
930
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300931PyDoc_STRVAR(os__getfullpathname__doc__,
932"_getfullpathname($module, path, /)\n"
933"--\n"
934"\n");
935
936#define OS__GETFULLPATHNAME_METHODDEF \
937 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
938
939static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300940os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300941
942static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300943os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300944{
945 PyObject *return_value = NULL;
946 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
947
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300948 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300949 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300950 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300951 return_value = os__getfullpathname_impl(module, &path);
952
953exit:
954 /* Cleanup for path */
955 path_cleanup(&path);
956
957 return return_value;
958}
959
960#endif /* defined(MS_WINDOWS) */
961
962#if defined(MS_WINDOWS)
963
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300964PyDoc_STRVAR(os__getfinalpathname__doc__,
965"_getfinalpathname($module, path, /)\n"
966"--\n"
967"\n"
968"A helper function for samepath on windows.");
969
970#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300971 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300972
973static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300974os__getfinalpathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300975
976static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300977os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300978{
979 PyObject *return_value = NULL;
980 PyObject *path;
981
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300982 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300983 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300984 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300985 return_value = os__getfinalpathname_impl(module, path);
986
987exit:
988 return return_value;
989}
990
991#endif /* defined(MS_WINDOWS) */
992
993#if defined(MS_WINDOWS)
994
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300995PyDoc_STRVAR(os__isdir__doc__,
996"_isdir($module, path, /)\n"
997"--\n"
998"\n");
999
1000#define OS__ISDIR_METHODDEF \
1001 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1002
1003static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001004os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001005
1006static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001007os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001008{
1009 PyObject *return_value = NULL;
1010 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1011
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001012 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001013 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001014 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001015 return_value = os__isdir_impl(module, &path);
1016
1017exit:
1018 /* Cleanup for path */
1019 path_cleanup(&path);
1020
1021 return return_value;
1022}
1023
1024#endif /* defined(MS_WINDOWS) */
1025
1026#if defined(MS_WINDOWS)
1027
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001028PyDoc_STRVAR(os__getvolumepathname__doc__,
1029"_getvolumepathname($module, /, path)\n"
1030"--\n"
1031"\n"
1032"A helper function for ismount on Win32.");
1033
1034#define OS__GETVOLUMEPATHNAME_METHODDEF \
1035 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_VARARGS|METH_KEYWORDS, os__getvolumepathname__doc__},
1036
1037static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001038os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001039
1040static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001041os__getvolumepathname(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001042{
1043 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001044 static const char * const _keywords[] = {"path", NULL};
1045 static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001046 PyObject *path;
1047
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001048 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001049 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001050 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001051 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052 return_value = os__getvolumepathname_impl(module, path);
1053
1054exit:
1055 return return_value;
1056}
1057
1058#endif /* defined(MS_WINDOWS) */
1059
1060PyDoc_STRVAR(os_mkdir__doc__,
1061"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1062"--\n"
1063"\n"
1064"Create a directory.\n"
1065"\n"
1066"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1067" and path should be relative; path will then be relative to that directory.\n"
1068"dir_fd may not be implemented on your platform.\n"
1069" If it is unavailable, using it will raise a NotImplementedError.\n"
1070"\n"
1071"The mode argument is ignored on Windows.");
1072
1073#define OS_MKDIR_METHODDEF \
1074 {"mkdir", (PyCFunction)os_mkdir, METH_VARARGS|METH_KEYWORDS, os_mkdir__doc__},
1075
1076static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001077os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001078
1079static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001080os_mkdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001081{
1082 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001083 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1084 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001085 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1086 int mode = 511;
1087 int dir_fd = DEFAULT_DIR_FD;
1088
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001089 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001090 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001091 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001092 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1094
1095exit:
1096 /* Cleanup for path */
1097 path_cleanup(&path);
1098
1099 return return_value;
1100}
1101
1102#if defined(HAVE_NICE)
1103
1104PyDoc_STRVAR(os_nice__doc__,
1105"nice($module, increment, /)\n"
1106"--\n"
1107"\n"
1108"Add increment to the priority of process and return the new priority.");
1109
1110#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001111 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001112
1113static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001114os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001115
1116static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001117os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001118{
1119 PyObject *return_value = NULL;
1120 int increment;
1121
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001122 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001123 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001124 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001125 return_value = os_nice_impl(module, increment);
1126
1127exit:
1128 return return_value;
1129}
1130
1131#endif /* defined(HAVE_NICE) */
1132
1133#if defined(HAVE_GETPRIORITY)
1134
1135PyDoc_STRVAR(os_getpriority__doc__,
1136"getpriority($module, /, which, who)\n"
1137"--\n"
1138"\n"
1139"Return program scheduling priority.");
1140
1141#define OS_GETPRIORITY_METHODDEF \
1142 {"getpriority", (PyCFunction)os_getpriority, METH_VARARGS|METH_KEYWORDS, os_getpriority__doc__},
1143
1144static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001145os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001146
1147static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001148os_getpriority(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001149{
1150 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001151 static const char * const _keywords[] = {"which", "who", NULL};
1152 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001153 int which;
1154 int who;
1155
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001156 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001157 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001158 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001159 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001160 return_value = os_getpriority_impl(module, which, who);
1161
1162exit:
1163 return return_value;
1164}
1165
1166#endif /* defined(HAVE_GETPRIORITY) */
1167
1168#if defined(HAVE_SETPRIORITY)
1169
1170PyDoc_STRVAR(os_setpriority__doc__,
1171"setpriority($module, /, which, who, priority)\n"
1172"--\n"
1173"\n"
1174"Set program scheduling priority.");
1175
1176#define OS_SETPRIORITY_METHODDEF \
1177 {"setpriority", (PyCFunction)os_setpriority, METH_VARARGS|METH_KEYWORDS, os_setpriority__doc__},
1178
1179static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001180os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001181
1182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001183os_setpriority(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001184{
1185 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001186 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1187 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001188 int which;
1189 int who;
1190 int priority;
1191
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001192 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001193 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001194 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001195 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 return_value = os_setpriority_impl(module, which, who, priority);
1197
1198exit:
1199 return return_value;
1200}
1201
1202#endif /* defined(HAVE_SETPRIORITY) */
1203
1204PyDoc_STRVAR(os_rename__doc__,
1205"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1206"--\n"
1207"\n"
1208"Rename a file or directory.\n"
1209"\n"
1210"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1211" descriptor open to a directory, and the respective path string (src or dst)\n"
1212" should be relative; the path will then be relative to that directory.\n"
1213"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1214" If they are unavailable, using them will raise a NotImplementedError.");
1215
1216#define OS_RENAME_METHODDEF \
1217 {"rename", (PyCFunction)os_rename, METH_VARARGS|METH_KEYWORDS, os_rename__doc__},
1218
1219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001220os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001221 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001222
1223static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001224os_rename(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001225{
1226 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001227 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1228 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001229 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1230 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1231 int src_dir_fd = DEFAULT_DIR_FD;
1232 int dst_dir_fd = DEFAULT_DIR_FD;
1233
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001234 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001235 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 +03001236 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001237 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001238 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1239
1240exit:
1241 /* Cleanup for src */
1242 path_cleanup(&src);
1243 /* Cleanup for dst */
1244 path_cleanup(&dst);
1245
1246 return return_value;
1247}
1248
1249PyDoc_STRVAR(os_replace__doc__,
1250"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1251"--\n"
1252"\n"
1253"Rename a file or directory, overwriting the destination.\n"
1254"\n"
1255"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1256" descriptor open to a directory, and the respective path string (src or dst)\n"
1257" should be relative; the path will then be relative to that directory.\n"
1258"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1259" If they are unavailable, using them will raise a NotImplementedError.\"");
1260
1261#define OS_REPLACE_METHODDEF \
1262 {"replace", (PyCFunction)os_replace, METH_VARARGS|METH_KEYWORDS, os_replace__doc__},
1263
1264static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001265os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1266 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001267
1268static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001269os_replace(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001270{
1271 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001272 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1273 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001274 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1275 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1276 int src_dir_fd = DEFAULT_DIR_FD;
1277 int dst_dir_fd = DEFAULT_DIR_FD;
1278
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001279 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001280 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 +03001281 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001282 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001283 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1284
1285exit:
1286 /* Cleanup for src */
1287 path_cleanup(&src);
1288 /* Cleanup for dst */
1289 path_cleanup(&dst);
1290
1291 return return_value;
1292}
1293
1294PyDoc_STRVAR(os_rmdir__doc__,
1295"rmdir($module, /, path, *, dir_fd=None)\n"
1296"--\n"
1297"\n"
1298"Remove a directory.\n"
1299"\n"
1300"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1301" and path should be relative; path will then be relative to that directory.\n"
1302"dir_fd may not be implemented on your platform.\n"
1303" If it is unavailable, using it will raise a NotImplementedError.");
1304
1305#define OS_RMDIR_METHODDEF \
1306 {"rmdir", (PyCFunction)os_rmdir, METH_VARARGS|METH_KEYWORDS, os_rmdir__doc__},
1307
1308static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001309os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001310
1311static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001312os_rmdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001313{
1314 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001315 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1316 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001317 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1318 int dir_fd = DEFAULT_DIR_FD;
1319
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001320 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001321 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001322 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001323 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001324 return_value = os_rmdir_impl(module, &path, dir_fd);
1325
1326exit:
1327 /* Cleanup for path */
1328 path_cleanup(&path);
1329
1330 return return_value;
1331}
1332
1333#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1334
1335PyDoc_STRVAR(os_system__doc__,
1336"system($module, /, command)\n"
1337"--\n"
1338"\n"
1339"Execute the command in a subshell.");
1340
1341#define OS_SYSTEM_METHODDEF \
1342 {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
1343
1344static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001345os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001346
1347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001348os_system(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001349{
1350 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001351 static const char * const _keywords[] = {"command", NULL};
1352 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001353 Py_UNICODE *command;
1354 long _return_value;
1355
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001356 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001357 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001358 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001359 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001360 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001361 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001362 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001363 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001364 return_value = PyLong_FromLong(_return_value);
1365
1366exit:
1367 return return_value;
1368}
1369
1370#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1371
1372#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1373
1374PyDoc_STRVAR(os_system__doc__,
1375"system($module, /, command)\n"
1376"--\n"
1377"\n"
1378"Execute the command in a subshell.");
1379
1380#define OS_SYSTEM_METHODDEF \
1381 {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
1382
1383static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001384os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001385
1386static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001387os_system(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001388{
1389 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001390 static const char * const _keywords[] = {"command", NULL};
1391 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001392 PyObject *command = NULL;
1393 long _return_value;
1394
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001395 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001396 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001397 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001398 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001399 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001400 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001401 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001402 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001403 return_value = PyLong_FromLong(_return_value);
1404
1405exit:
1406 /* Cleanup for command */
1407 Py_XDECREF(command);
1408
1409 return return_value;
1410}
1411
1412#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1413
1414PyDoc_STRVAR(os_umask__doc__,
1415"umask($module, mask, /)\n"
1416"--\n"
1417"\n"
1418"Set the current numeric umask and return the previous umask.");
1419
1420#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001421 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001422
1423static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001424os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001425
1426static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001427os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001428{
1429 PyObject *return_value = NULL;
1430 int mask;
1431
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001432 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001433 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001435 return_value = os_umask_impl(module, mask);
1436
1437exit:
1438 return return_value;
1439}
1440
1441PyDoc_STRVAR(os_unlink__doc__,
1442"unlink($module, /, path, *, dir_fd=None)\n"
1443"--\n"
1444"\n"
1445"Remove a file (same as remove()).\n"
1446"\n"
1447"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1448" and path should be relative; path will then be relative to that directory.\n"
1449"dir_fd may not be implemented on your platform.\n"
1450" If it is unavailable, using it will raise a NotImplementedError.");
1451
1452#define OS_UNLINK_METHODDEF \
1453 {"unlink", (PyCFunction)os_unlink, METH_VARARGS|METH_KEYWORDS, os_unlink__doc__},
1454
1455static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001456os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001457
1458static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001459os_unlink(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001460{
1461 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001462 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1463 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001464 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1465 int dir_fd = DEFAULT_DIR_FD;
1466
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001467 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001468 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001469 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001470 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471 return_value = os_unlink_impl(module, &path, dir_fd);
1472
1473exit:
1474 /* Cleanup for path */
1475 path_cleanup(&path);
1476
1477 return return_value;
1478}
1479
1480PyDoc_STRVAR(os_remove__doc__,
1481"remove($module, /, path, *, dir_fd=None)\n"
1482"--\n"
1483"\n"
1484"Remove a file (same as unlink()).\n"
1485"\n"
1486"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1487" and path should be relative; path will then be relative to that directory.\n"
1488"dir_fd may not be implemented on your platform.\n"
1489" If it is unavailable, using it will raise a NotImplementedError.");
1490
1491#define OS_REMOVE_METHODDEF \
1492 {"remove", (PyCFunction)os_remove, METH_VARARGS|METH_KEYWORDS, os_remove__doc__},
1493
1494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001495os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001496
1497static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001498os_remove(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001499{
1500 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001501 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1502 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001503 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1504 int dir_fd = DEFAULT_DIR_FD;
1505
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001506 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001507 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001508 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001509 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001510 return_value = os_remove_impl(module, &path, dir_fd);
1511
1512exit:
1513 /* Cleanup for path */
1514 path_cleanup(&path);
1515
1516 return return_value;
1517}
1518
1519#if defined(HAVE_UNAME)
1520
1521PyDoc_STRVAR(os_uname__doc__,
1522"uname($module, /)\n"
1523"--\n"
1524"\n"
1525"Return an object identifying the current operating system.\n"
1526"\n"
1527"The object behaves like a named tuple with the following fields:\n"
1528" (sysname, nodename, release, version, machine)");
1529
1530#define OS_UNAME_METHODDEF \
1531 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1532
1533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001534os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001535
1536static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001537os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001538{
1539 return os_uname_impl(module);
1540}
1541
1542#endif /* defined(HAVE_UNAME) */
1543
1544PyDoc_STRVAR(os_utime__doc__,
1545"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1546" follow_symlinks=True)\n"
1547"--\n"
1548"\n"
1549"Set the access and modified time of path.\n"
1550"\n"
1551"path may always be specified as a string.\n"
1552"On some platforms, path may also be specified as an open file descriptor.\n"
1553" If this functionality is unavailable, using it raises an exception.\n"
1554"\n"
1555"If times is not None, it must be a tuple (atime, mtime);\n"
1556" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001557"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001558" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1559" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001560"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001561"Specifying tuples for both times and ns is an error.\n"
1562"\n"
1563"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1564" and path should be relative; path will then be relative to that directory.\n"
1565"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1566" link, utime will modify the symbolic link itself instead of the file the\n"
1567" link points to.\n"
1568"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1569" as an open file descriptor.\n"
1570"dir_fd and follow_symlinks may not be available on your platform.\n"
1571" If they are unavailable, using them will raise a NotImplementedError.");
1572
1573#define OS_UTIME_METHODDEF \
1574 {"utime", (PyCFunction)os_utime, METH_VARARGS|METH_KEYWORDS, os_utime__doc__},
1575
1576static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001577os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1578 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001579
1580static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001581os_utime(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001582{
1583 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001584 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1585 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001586 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1587 PyObject *times = NULL;
1588 PyObject *ns = NULL;
1589 int dir_fd = DEFAULT_DIR_FD;
1590 int follow_symlinks = 1;
1591
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001592 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001593 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001594 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001595 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001596 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1597
1598exit:
1599 /* Cleanup for path */
1600 path_cleanup(&path);
1601
1602 return return_value;
1603}
1604
1605PyDoc_STRVAR(os__exit__doc__,
1606"_exit($module, /, status)\n"
1607"--\n"
1608"\n"
1609"Exit to the system with specified status, without normal exit processing.");
1610
1611#define OS__EXIT_METHODDEF \
1612 {"_exit", (PyCFunction)os__exit, METH_VARARGS|METH_KEYWORDS, os__exit__doc__},
1613
1614static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001615os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001616
1617static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001618os__exit(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001619{
1620 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001621 static const char * const _keywords[] = {"status", NULL};
1622 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001623 int status;
1624
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001625 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001626 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001627 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001628 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001629 return_value = os__exit_impl(module, status);
1630
1631exit:
1632 return return_value;
1633}
1634
1635#if defined(HAVE_EXECV)
1636
1637PyDoc_STRVAR(os_execv__doc__,
1638"execv($module, path, argv, /)\n"
1639"--\n"
1640"\n"
1641"Execute an executable path with arguments, replacing current process.\n"
1642"\n"
1643" path\n"
1644" Path of executable file.\n"
1645" argv\n"
1646" Tuple or list of strings.");
1647
1648#define OS_EXECV_METHODDEF \
1649 {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__},
1650
1651static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001652os_execv_impl(PyObject *module, PyObject *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001653
1654static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001655os_execv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001656{
1657 PyObject *return_value = NULL;
1658 PyObject *path = NULL;
1659 PyObject *argv;
1660
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001661 if (!PyArg_ParseTuple(args, "O&O:execv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001662 PyUnicode_FSConverter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001663 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001664 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001665 return_value = os_execv_impl(module, path, argv);
1666
1667exit:
1668 /* Cleanup for path */
1669 Py_XDECREF(path);
1670
1671 return return_value;
1672}
1673
1674#endif /* defined(HAVE_EXECV) */
1675
1676#if defined(HAVE_EXECV)
1677
1678PyDoc_STRVAR(os_execve__doc__,
1679"execve($module, /, path, argv, env)\n"
1680"--\n"
1681"\n"
1682"Execute an executable path with arguments, replacing current process.\n"
1683"\n"
1684" path\n"
1685" Path of executable file.\n"
1686" argv\n"
1687" Tuple or list of strings.\n"
1688" env\n"
1689" Dictionary of strings mapping to strings.");
1690
1691#define OS_EXECVE_METHODDEF \
1692 {"execve", (PyCFunction)os_execve, METH_VARARGS|METH_KEYWORDS, os_execve__doc__},
1693
1694static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001695os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001696
1697static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001698os_execve(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001699{
1700 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001701 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1702 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001703 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1704 PyObject *argv;
1705 PyObject *env;
1706
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001707 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001708 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001709 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001710 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001711 return_value = os_execve_impl(module, &path, argv, env);
1712
1713exit:
1714 /* Cleanup for path */
1715 path_cleanup(&path);
1716
1717 return return_value;
1718}
1719
1720#endif /* defined(HAVE_EXECV) */
1721
1722#if defined(HAVE_SPAWNV)
1723
1724PyDoc_STRVAR(os_spawnv__doc__,
1725"spawnv($module, mode, path, argv, /)\n"
1726"--\n"
1727"\n"
1728"Execute the program specified by path in a new process.\n"
1729"\n"
1730" mode\n"
1731" Mode of process creation.\n"
1732" path\n"
1733" Path of executable file.\n"
1734" argv\n"
1735" Tuple or list of strings.");
1736
1737#define OS_SPAWNV_METHODDEF \
1738 {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__},
1739
1740static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001741os_spawnv_impl(PyObject *module, int mode, PyObject *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001742
1743static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001744os_spawnv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001745{
1746 PyObject *return_value = NULL;
1747 int mode;
1748 PyObject *path = NULL;
1749 PyObject *argv;
1750
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001751 if (!PyArg_ParseTuple(args, "iO&O:spawnv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001752 &mode, PyUnicode_FSConverter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001753 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001754 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001755 return_value = os_spawnv_impl(module, mode, path, argv);
1756
1757exit:
1758 /* Cleanup for path */
1759 Py_XDECREF(path);
1760
1761 return return_value;
1762}
1763
1764#endif /* defined(HAVE_SPAWNV) */
1765
1766#if defined(HAVE_SPAWNV)
1767
1768PyDoc_STRVAR(os_spawnve__doc__,
1769"spawnve($module, mode, path, argv, env, /)\n"
1770"--\n"
1771"\n"
1772"Execute the program specified by path in a new process.\n"
1773"\n"
1774" mode\n"
1775" Mode of process creation.\n"
1776" path\n"
1777" Path of executable file.\n"
1778" argv\n"
1779" Tuple or list of strings.\n"
1780" env\n"
1781" Dictionary of strings mapping to strings.");
1782
1783#define OS_SPAWNVE_METHODDEF \
1784 {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__},
1785
1786static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001787os_spawnve_impl(PyObject *module, int mode, PyObject *path, PyObject *argv,
1788 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001789
1790static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001791os_spawnve(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001792{
1793 PyObject *return_value = NULL;
1794 int mode;
1795 PyObject *path = NULL;
1796 PyObject *argv;
1797 PyObject *env;
1798
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001799 if (!PyArg_ParseTuple(args, "iO&OO:spawnve",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001800 &mode, PyUnicode_FSConverter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001801 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001802 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001803 return_value = os_spawnve_impl(module, mode, path, argv, env);
1804
1805exit:
1806 /* Cleanup for path */
1807 Py_XDECREF(path);
1808
1809 return return_value;
1810}
1811
1812#endif /* defined(HAVE_SPAWNV) */
1813
1814#if defined(HAVE_FORK1)
1815
1816PyDoc_STRVAR(os_fork1__doc__,
1817"fork1($module, /)\n"
1818"--\n"
1819"\n"
1820"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1821"\n"
1822"Return 0 to child process and PID of child to parent process.");
1823
1824#define OS_FORK1_METHODDEF \
1825 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1826
1827static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001828os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001829
1830static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001831os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001832{
1833 return os_fork1_impl(module);
1834}
1835
1836#endif /* defined(HAVE_FORK1) */
1837
1838#if defined(HAVE_FORK)
1839
1840PyDoc_STRVAR(os_fork__doc__,
1841"fork($module, /)\n"
1842"--\n"
1843"\n"
1844"Fork a child process.\n"
1845"\n"
1846"Return 0 to child process and PID of child to parent process.");
1847
1848#define OS_FORK_METHODDEF \
1849 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1850
1851static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001852os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001853
1854static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001855os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001856{
1857 return os_fork_impl(module);
1858}
1859
1860#endif /* defined(HAVE_FORK) */
1861
1862#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1863
1864PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1865"sched_get_priority_max($module, /, policy)\n"
1866"--\n"
1867"\n"
1868"Get the maximum scheduling priority for policy.");
1869
1870#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
1871 {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_max__doc__},
1872
1873static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001874os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001875
1876static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001877os_sched_get_priority_max(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001878{
1879 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001880 static const char * const _keywords[] = {"policy", NULL};
1881 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001882 int policy;
1883
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001884 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001885 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001886 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001887 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001888 return_value = os_sched_get_priority_max_impl(module, policy);
1889
1890exit:
1891 return return_value;
1892}
1893
1894#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1895
1896#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1897
1898PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1899"sched_get_priority_min($module, /, policy)\n"
1900"--\n"
1901"\n"
1902"Get the minimum scheduling priority for policy.");
1903
1904#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
1905 {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_min__doc__},
1906
1907static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001908os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001909
1910static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001911os_sched_get_priority_min(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001912{
1913 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001914 static const char * const _keywords[] = {"policy", NULL};
1915 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001916 int policy;
1917
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001918 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001919 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001920 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001921 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001922 return_value = os_sched_get_priority_min_impl(module, policy);
1923
1924exit:
1925 return return_value;
1926}
1927
1928#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1929
1930#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1931
1932PyDoc_STRVAR(os_sched_getscheduler__doc__,
1933"sched_getscheduler($module, pid, /)\n"
1934"--\n"
1935"\n"
1936"Get the scheduling policy for the process identifiedy by pid.\n"
1937"\n"
1938"Passing 0 for pid returns the scheduling policy for the calling process.");
1939
1940#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001941 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001942
1943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001944os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001945
1946static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001947os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001948{
1949 PyObject *return_value = NULL;
1950 pid_t pid;
1951
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001952 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001953 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001954 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001955 return_value = os_sched_getscheduler_impl(module, pid);
1956
1957exit:
1958 return return_value;
1959}
1960
1961#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1962
1963#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
1964
1965PyDoc_STRVAR(os_sched_param__doc__,
1966"sched_param(sched_priority)\n"
1967"--\n"
1968"\n"
1969"Current has only one field: sched_priority\");\n"
1970"\n"
1971" sched_priority\n"
1972" A scheduling parameter.");
1973
1974static PyObject *
1975os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
1976
1977static PyObject *
1978os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1979{
1980 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001981 static const char * const _keywords[] = {"sched_priority", NULL};
1982 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001983 PyObject *sched_priority;
1984
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001985 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001986 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001987 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001988 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001989 return_value = os_sched_param_impl(type, sched_priority);
1990
1991exit:
1992 return return_value;
1993}
1994
1995#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
1996
1997#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1998
1999PyDoc_STRVAR(os_sched_setscheduler__doc__,
2000"sched_setscheduler($module, pid, policy, param, /)\n"
2001"--\n"
2002"\n"
2003"Set the scheduling policy for the process identified by pid.\n"
2004"\n"
2005"If pid is 0, the calling process is changed.\n"
2006"param is an instance of sched_param.");
2007
2008#define OS_SCHED_SETSCHEDULER_METHODDEF \
2009 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__},
2010
2011static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002012os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002013 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002014
2015static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002016os_sched_setscheduler(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002017{
2018 PyObject *return_value = NULL;
2019 pid_t pid;
2020 int policy;
2021 struct sched_param param;
2022
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002023 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002024 &pid, &policy, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002025 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002026 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002027 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2028
2029exit:
2030 return return_value;
2031}
2032
2033#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2034
2035#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2036
2037PyDoc_STRVAR(os_sched_getparam__doc__,
2038"sched_getparam($module, pid, /)\n"
2039"--\n"
2040"\n"
2041"Returns scheduling parameters for the process identified by pid.\n"
2042"\n"
2043"If pid is 0, returns parameters for the calling process.\n"
2044"Return value is an instance of sched_param.");
2045
2046#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002047 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002048
2049static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002050os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002051
2052static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002053os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002054{
2055 PyObject *return_value = NULL;
2056 pid_t pid;
2057
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002058 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002059 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002060 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002061 return_value = os_sched_getparam_impl(module, pid);
2062
2063exit:
2064 return return_value;
2065}
2066
2067#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2068
2069#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2070
2071PyDoc_STRVAR(os_sched_setparam__doc__,
2072"sched_setparam($module, pid, param, /)\n"
2073"--\n"
2074"\n"
2075"Set scheduling parameters for the process identified by pid.\n"
2076"\n"
2077"If pid is 0, sets parameters for the calling process.\n"
2078"param should be an instance of sched_param.");
2079
2080#define OS_SCHED_SETPARAM_METHODDEF \
2081 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__},
2082
2083static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002084os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002085 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002086
2087static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002088os_sched_setparam(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002089{
2090 PyObject *return_value = NULL;
2091 pid_t pid;
2092 struct sched_param param;
2093
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002094 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002095 &pid, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002096 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002097 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002098 return_value = os_sched_setparam_impl(module, pid, &param);
2099
2100exit:
2101 return return_value;
2102}
2103
2104#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2105
2106#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2107
2108PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2109"sched_rr_get_interval($module, pid, /)\n"
2110"--\n"
2111"\n"
2112"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2113"\n"
2114"Value returned is a float.");
2115
2116#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002117 {"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 +03002118
2119static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002120os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002121
2122static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002123os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002124{
2125 PyObject *return_value = NULL;
2126 pid_t pid;
2127 double _return_value;
2128
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002129 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002130 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002131 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002132 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002133 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002134 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002135 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002136 return_value = PyFloat_FromDouble(_return_value);
2137
2138exit:
2139 return return_value;
2140}
2141
2142#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2143
2144#if defined(HAVE_SCHED_H)
2145
2146PyDoc_STRVAR(os_sched_yield__doc__,
2147"sched_yield($module, /)\n"
2148"--\n"
2149"\n"
2150"Voluntarily relinquish the CPU.");
2151
2152#define OS_SCHED_YIELD_METHODDEF \
2153 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2154
2155static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002156os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002157
2158static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002159os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002160{
2161 return os_sched_yield_impl(module);
2162}
2163
2164#endif /* defined(HAVE_SCHED_H) */
2165
2166#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2167
2168PyDoc_STRVAR(os_sched_setaffinity__doc__,
2169"sched_setaffinity($module, pid, mask, /)\n"
2170"--\n"
2171"\n"
2172"Set the CPU affinity of the process identified by pid to mask.\n"
2173"\n"
2174"mask should be an iterable of integers identifying CPUs.");
2175
2176#define OS_SCHED_SETAFFINITY_METHODDEF \
2177 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__},
2178
2179static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002180os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002181
2182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002183os_sched_setaffinity(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002184{
2185 PyObject *return_value = NULL;
2186 pid_t pid;
2187 PyObject *mask;
2188
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002189 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002190 &pid, &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002191 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002192 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002193 return_value = os_sched_setaffinity_impl(module, pid, mask);
2194
2195exit:
2196 return return_value;
2197}
2198
2199#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2200
2201#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2202
2203PyDoc_STRVAR(os_sched_getaffinity__doc__,
2204"sched_getaffinity($module, pid, /)\n"
2205"--\n"
2206"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002207"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002208"\n"
2209"The affinity is returned as a set of CPU identifiers.");
2210
2211#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002212 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002213
2214static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002215os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002216
2217static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002218os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002219{
2220 PyObject *return_value = NULL;
2221 pid_t pid;
2222
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002223 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002224 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002225 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002226 return_value = os_sched_getaffinity_impl(module, pid);
2227
2228exit:
2229 return return_value;
2230}
2231
2232#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2233
2234#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2235
2236PyDoc_STRVAR(os_openpty__doc__,
2237"openpty($module, /)\n"
2238"--\n"
2239"\n"
2240"Open a pseudo-terminal.\n"
2241"\n"
2242"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2243"for both the master and slave ends.");
2244
2245#define OS_OPENPTY_METHODDEF \
2246 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2247
2248static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002249os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002250
2251static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002252os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002253{
2254 return os_openpty_impl(module);
2255}
2256
2257#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2258
2259#if defined(HAVE_FORKPTY)
2260
2261PyDoc_STRVAR(os_forkpty__doc__,
2262"forkpty($module, /)\n"
2263"--\n"
2264"\n"
2265"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2266"\n"
2267"Returns a tuple of (pid, master_fd).\n"
2268"Like fork(), return pid of 0 to the child process,\n"
2269"and pid of child to the parent process.\n"
2270"To both, return fd of newly opened pseudo-terminal.");
2271
2272#define OS_FORKPTY_METHODDEF \
2273 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2274
2275static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002276os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002277
2278static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002279os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002280{
2281 return os_forkpty_impl(module);
2282}
2283
2284#endif /* defined(HAVE_FORKPTY) */
2285
2286#if defined(HAVE_GETEGID)
2287
2288PyDoc_STRVAR(os_getegid__doc__,
2289"getegid($module, /)\n"
2290"--\n"
2291"\n"
2292"Return the current process\'s effective group id.");
2293
2294#define OS_GETEGID_METHODDEF \
2295 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2296
2297static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002298os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002299
2300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002301os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002302{
2303 return os_getegid_impl(module);
2304}
2305
2306#endif /* defined(HAVE_GETEGID) */
2307
2308#if defined(HAVE_GETEUID)
2309
2310PyDoc_STRVAR(os_geteuid__doc__,
2311"geteuid($module, /)\n"
2312"--\n"
2313"\n"
2314"Return the current process\'s effective user id.");
2315
2316#define OS_GETEUID_METHODDEF \
2317 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2318
2319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002320os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002321
2322static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002323os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002324{
2325 return os_geteuid_impl(module);
2326}
2327
2328#endif /* defined(HAVE_GETEUID) */
2329
2330#if defined(HAVE_GETGID)
2331
2332PyDoc_STRVAR(os_getgid__doc__,
2333"getgid($module, /)\n"
2334"--\n"
2335"\n"
2336"Return the current process\'s group id.");
2337
2338#define OS_GETGID_METHODDEF \
2339 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2340
2341static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002342os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002343
2344static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002345os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002346{
2347 return os_getgid_impl(module);
2348}
2349
2350#endif /* defined(HAVE_GETGID) */
2351
2352PyDoc_STRVAR(os_getpid__doc__,
2353"getpid($module, /)\n"
2354"--\n"
2355"\n"
2356"Return the current process id.");
2357
2358#define OS_GETPID_METHODDEF \
2359 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2360
2361static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002362os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002363
2364static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002365os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002366{
2367 return os_getpid_impl(module);
2368}
2369
2370#if defined(HAVE_GETGROUPS)
2371
2372PyDoc_STRVAR(os_getgroups__doc__,
2373"getgroups($module, /)\n"
2374"--\n"
2375"\n"
2376"Return list of supplemental group IDs for the process.");
2377
2378#define OS_GETGROUPS_METHODDEF \
2379 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2380
2381static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002382os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002383
2384static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002385os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002386{
2387 return os_getgroups_impl(module);
2388}
2389
2390#endif /* defined(HAVE_GETGROUPS) */
2391
2392#if defined(HAVE_GETPGID)
2393
2394PyDoc_STRVAR(os_getpgid__doc__,
2395"getpgid($module, /, pid)\n"
2396"--\n"
2397"\n"
2398"Call the system call getpgid(), and return the result.");
2399
2400#define OS_GETPGID_METHODDEF \
2401 {"getpgid", (PyCFunction)os_getpgid, METH_VARARGS|METH_KEYWORDS, os_getpgid__doc__},
2402
2403static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002404os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002405
2406static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002407os_getpgid(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002408{
2409 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002410 static const char * const _keywords[] = {"pid", NULL};
2411 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002412 pid_t pid;
2413
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002414 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002415 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002416 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002417 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002418 return_value = os_getpgid_impl(module, pid);
2419
2420exit:
2421 return return_value;
2422}
2423
2424#endif /* defined(HAVE_GETPGID) */
2425
2426#if defined(HAVE_GETPGRP)
2427
2428PyDoc_STRVAR(os_getpgrp__doc__,
2429"getpgrp($module, /)\n"
2430"--\n"
2431"\n"
2432"Return the current process group id.");
2433
2434#define OS_GETPGRP_METHODDEF \
2435 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2436
2437static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002438os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002439
2440static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002441os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002442{
2443 return os_getpgrp_impl(module);
2444}
2445
2446#endif /* defined(HAVE_GETPGRP) */
2447
2448#if defined(HAVE_SETPGRP)
2449
2450PyDoc_STRVAR(os_setpgrp__doc__,
2451"setpgrp($module, /)\n"
2452"--\n"
2453"\n"
2454"Make the current process the leader of its process group.");
2455
2456#define OS_SETPGRP_METHODDEF \
2457 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2458
2459static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002460os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002461
2462static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002463os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002464{
2465 return os_setpgrp_impl(module);
2466}
2467
2468#endif /* defined(HAVE_SETPGRP) */
2469
2470#if defined(HAVE_GETPPID)
2471
2472PyDoc_STRVAR(os_getppid__doc__,
2473"getppid($module, /)\n"
2474"--\n"
2475"\n"
2476"Return the parent\'s process id.\n"
2477"\n"
2478"If the parent process has already exited, Windows machines will still\n"
2479"return its id; others systems will return the id of the \'init\' process (1).");
2480
2481#define OS_GETPPID_METHODDEF \
2482 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2483
2484static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002485os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002486
2487static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002488os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002489{
2490 return os_getppid_impl(module);
2491}
2492
2493#endif /* defined(HAVE_GETPPID) */
2494
2495#if defined(HAVE_GETLOGIN)
2496
2497PyDoc_STRVAR(os_getlogin__doc__,
2498"getlogin($module, /)\n"
2499"--\n"
2500"\n"
2501"Return the actual login name.");
2502
2503#define OS_GETLOGIN_METHODDEF \
2504 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2505
2506static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002507os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002508
2509static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002510os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002511{
2512 return os_getlogin_impl(module);
2513}
2514
2515#endif /* defined(HAVE_GETLOGIN) */
2516
2517#if defined(HAVE_GETUID)
2518
2519PyDoc_STRVAR(os_getuid__doc__,
2520"getuid($module, /)\n"
2521"--\n"
2522"\n"
2523"Return the current process\'s user id.");
2524
2525#define OS_GETUID_METHODDEF \
2526 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2527
2528static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002529os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002530
2531static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002532os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002533{
2534 return os_getuid_impl(module);
2535}
2536
2537#endif /* defined(HAVE_GETUID) */
2538
2539#if defined(HAVE_KILL)
2540
2541PyDoc_STRVAR(os_kill__doc__,
2542"kill($module, pid, signal, /)\n"
2543"--\n"
2544"\n"
2545"Kill a process with a signal.");
2546
2547#define OS_KILL_METHODDEF \
2548 {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__},
2549
2550static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002551os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002552
2553static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002554os_kill(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002555{
2556 PyObject *return_value = NULL;
2557 pid_t pid;
2558 Py_ssize_t signal;
2559
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002560 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002561 &pid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002562 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002563 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002564 return_value = os_kill_impl(module, pid, signal);
2565
2566exit:
2567 return return_value;
2568}
2569
2570#endif /* defined(HAVE_KILL) */
2571
2572#if defined(HAVE_KILLPG)
2573
2574PyDoc_STRVAR(os_killpg__doc__,
2575"killpg($module, pgid, signal, /)\n"
2576"--\n"
2577"\n"
2578"Kill a process group with a signal.");
2579
2580#define OS_KILLPG_METHODDEF \
2581 {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__},
2582
2583static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002584os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002585
2586static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002587os_killpg(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002588{
2589 PyObject *return_value = NULL;
2590 pid_t pgid;
2591 int signal;
2592
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002593 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002594 &pgid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002595 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002596 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002597 return_value = os_killpg_impl(module, pgid, signal);
2598
2599exit:
2600 return return_value;
2601}
2602
2603#endif /* defined(HAVE_KILLPG) */
2604
2605#if defined(HAVE_PLOCK)
2606
2607PyDoc_STRVAR(os_plock__doc__,
2608"plock($module, op, /)\n"
2609"--\n"
2610"\n"
2611"Lock program segments into memory.\");");
2612
2613#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002614 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002615
2616static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002617os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002618
2619static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002620os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002621{
2622 PyObject *return_value = NULL;
2623 int op;
2624
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002625 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002626 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002627 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002628 return_value = os_plock_impl(module, op);
2629
2630exit:
2631 return return_value;
2632}
2633
2634#endif /* defined(HAVE_PLOCK) */
2635
2636#if defined(HAVE_SETUID)
2637
2638PyDoc_STRVAR(os_setuid__doc__,
2639"setuid($module, uid, /)\n"
2640"--\n"
2641"\n"
2642"Set the current process\'s user id.");
2643
2644#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002645 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002646
2647static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002648os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002649
2650static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002651os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002652{
2653 PyObject *return_value = NULL;
2654 uid_t uid;
2655
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002656 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002657 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002658 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002659 return_value = os_setuid_impl(module, uid);
2660
2661exit:
2662 return return_value;
2663}
2664
2665#endif /* defined(HAVE_SETUID) */
2666
2667#if defined(HAVE_SETEUID)
2668
2669PyDoc_STRVAR(os_seteuid__doc__,
2670"seteuid($module, euid, /)\n"
2671"--\n"
2672"\n"
2673"Set the current process\'s effective user id.");
2674
2675#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002676 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002677
2678static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002679os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002680
2681static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002682os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002683{
2684 PyObject *return_value = NULL;
2685 uid_t euid;
2686
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002687 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002688 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002689 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002690 return_value = os_seteuid_impl(module, euid);
2691
2692exit:
2693 return return_value;
2694}
2695
2696#endif /* defined(HAVE_SETEUID) */
2697
2698#if defined(HAVE_SETEGID)
2699
2700PyDoc_STRVAR(os_setegid__doc__,
2701"setegid($module, egid, /)\n"
2702"--\n"
2703"\n"
2704"Set the current process\'s effective group id.");
2705
2706#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002707 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002708
2709static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002710os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002711
2712static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002713os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002714{
2715 PyObject *return_value = NULL;
2716 gid_t egid;
2717
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002718 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002719 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002720 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002721 return_value = os_setegid_impl(module, egid);
2722
2723exit:
2724 return return_value;
2725}
2726
2727#endif /* defined(HAVE_SETEGID) */
2728
2729#if defined(HAVE_SETREUID)
2730
2731PyDoc_STRVAR(os_setreuid__doc__,
2732"setreuid($module, ruid, euid, /)\n"
2733"--\n"
2734"\n"
2735"Set the current process\'s real and effective user ids.");
2736
2737#define OS_SETREUID_METHODDEF \
2738 {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__},
2739
2740static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002741os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002742
2743static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002744os_setreuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002745{
2746 PyObject *return_value = NULL;
2747 uid_t ruid;
2748 uid_t euid;
2749
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002750 if (!PyArg_ParseTuple(args, "O&O&:setreuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002751 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002752 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002753 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002754 return_value = os_setreuid_impl(module, ruid, euid);
2755
2756exit:
2757 return return_value;
2758}
2759
2760#endif /* defined(HAVE_SETREUID) */
2761
2762#if defined(HAVE_SETREGID)
2763
2764PyDoc_STRVAR(os_setregid__doc__,
2765"setregid($module, rgid, egid, /)\n"
2766"--\n"
2767"\n"
2768"Set the current process\'s real and effective group ids.");
2769
2770#define OS_SETREGID_METHODDEF \
2771 {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__},
2772
2773static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002774os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002775
2776static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002777os_setregid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002778{
2779 PyObject *return_value = NULL;
2780 gid_t rgid;
2781 gid_t egid;
2782
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002783 if (!PyArg_ParseTuple(args, "O&O&:setregid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002784 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002785 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002786 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002787 return_value = os_setregid_impl(module, rgid, egid);
2788
2789exit:
2790 return return_value;
2791}
2792
2793#endif /* defined(HAVE_SETREGID) */
2794
2795#if defined(HAVE_SETGID)
2796
2797PyDoc_STRVAR(os_setgid__doc__,
2798"setgid($module, gid, /)\n"
2799"--\n"
2800"\n"
2801"Set the current process\'s group id.");
2802
2803#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002804 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002805
2806static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002807os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002808
2809static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002810os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002811{
2812 PyObject *return_value = NULL;
2813 gid_t gid;
2814
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002815 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002816 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002817 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002818 return_value = os_setgid_impl(module, gid);
2819
2820exit:
2821 return return_value;
2822}
2823
2824#endif /* defined(HAVE_SETGID) */
2825
2826#if defined(HAVE_SETGROUPS)
2827
2828PyDoc_STRVAR(os_setgroups__doc__,
2829"setgroups($module, groups, /)\n"
2830"--\n"
2831"\n"
2832"Set the groups of the current process to list.");
2833
2834#define OS_SETGROUPS_METHODDEF \
2835 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2836
2837#endif /* defined(HAVE_SETGROUPS) */
2838
2839#if defined(HAVE_WAIT3)
2840
2841PyDoc_STRVAR(os_wait3__doc__,
2842"wait3($module, /, options)\n"
2843"--\n"
2844"\n"
2845"Wait for completion of a child process.\n"
2846"\n"
2847"Returns a tuple of information about the child process:\n"
2848" (pid, status, rusage)");
2849
2850#define OS_WAIT3_METHODDEF \
2851 {"wait3", (PyCFunction)os_wait3, METH_VARARGS|METH_KEYWORDS, os_wait3__doc__},
2852
2853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002854os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002855
2856static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002857os_wait3(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002858{
2859 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002860 static const char * const _keywords[] = {"options", NULL};
2861 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002862 int options;
2863
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002864 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002865 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002866 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002867 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002868 return_value = os_wait3_impl(module, options);
2869
2870exit:
2871 return return_value;
2872}
2873
2874#endif /* defined(HAVE_WAIT3) */
2875
2876#if defined(HAVE_WAIT4)
2877
2878PyDoc_STRVAR(os_wait4__doc__,
2879"wait4($module, /, pid, options)\n"
2880"--\n"
2881"\n"
2882"Wait for completion of a specific child process.\n"
2883"\n"
2884"Returns a tuple of information about the child process:\n"
2885" (pid, status, rusage)");
2886
2887#define OS_WAIT4_METHODDEF \
2888 {"wait4", (PyCFunction)os_wait4, METH_VARARGS|METH_KEYWORDS, os_wait4__doc__},
2889
2890static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002891os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002892
2893static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002894os_wait4(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002895{
2896 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002897 static const char * const _keywords[] = {"pid", "options", NULL};
2898 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002899 pid_t pid;
2900 int options;
2901
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002902 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002903 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002904 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002905 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002906 return_value = os_wait4_impl(module, pid, options);
2907
2908exit:
2909 return return_value;
2910}
2911
2912#endif /* defined(HAVE_WAIT4) */
2913
2914#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2915
2916PyDoc_STRVAR(os_waitid__doc__,
2917"waitid($module, idtype, id, options, /)\n"
2918"--\n"
2919"\n"
2920"Returns the result of waiting for a process or processes.\n"
2921"\n"
2922" idtype\n"
2923" Must be one of be P_PID, P_PGID or P_ALL.\n"
2924" id\n"
2925" The id to wait on.\n"
2926" options\n"
2927" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2928" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2929"\n"
2930"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2931"no children in a waitable state.");
2932
2933#define OS_WAITID_METHODDEF \
2934 {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__},
2935
2936static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002937os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002938
2939static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002940os_waitid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002941{
2942 PyObject *return_value = NULL;
2943 idtype_t idtype;
2944 id_t id;
2945 int options;
2946
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002947 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002948 &idtype, &id, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002949 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002950 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002951 return_value = os_waitid_impl(module, idtype, id, options);
2952
2953exit:
2954 return return_value;
2955}
2956
2957#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
2958
2959#if defined(HAVE_WAITPID)
2960
2961PyDoc_STRVAR(os_waitpid__doc__,
2962"waitpid($module, pid, options, /)\n"
2963"--\n"
2964"\n"
2965"Wait for completion of a given child process.\n"
2966"\n"
2967"Returns a tuple of information regarding the child process:\n"
2968" (pid, status)\n"
2969"\n"
2970"The options argument is ignored on Windows.");
2971
2972#define OS_WAITPID_METHODDEF \
2973 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2974
2975static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002976os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002977
2978static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002979os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002980{
2981 PyObject *return_value = NULL;
2982 pid_t pid;
2983 int options;
2984
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002985 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002986 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002987 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002988 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002989 return_value = os_waitpid_impl(module, pid, options);
2990
2991exit:
2992 return return_value;
2993}
2994
2995#endif /* defined(HAVE_WAITPID) */
2996
2997#if defined(HAVE_CWAIT)
2998
2999PyDoc_STRVAR(os_waitpid__doc__,
3000"waitpid($module, pid, options, /)\n"
3001"--\n"
3002"\n"
3003"Wait for completion of a given process.\n"
3004"\n"
3005"Returns a tuple of information regarding the process:\n"
3006" (pid, status << 8)\n"
3007"\n"
3008"The options argument is ignored on Windows.");
3009
3010#define OS_WAITPID_METHODDEF \
3011 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
3012
3013static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003014os_waitpid_impl(PyObject *module, Py_intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003015
3016static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003017os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003018{
3019 PyObject *return_value = NULL;
3020 Py_intptr_t pid;
3021 int options;
3022
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003023 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003024 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003025 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003026 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003027 return_value = os_waitpid_impl(module, pid, options);
3028
3029exit:
3030 return return_value;
3031}
3032
3033#endif /* defined(HAVE_CWAIT) */
3034
3035#if defined(HAVE_WAIT)
3036
3037PyDoc_STRVAR(os_wait__doc__,
3038"wait($module, /)\n"
3039"--\n"
3040"\n"
3041"Wait for completion of a child process.\n"
3042"\n"
3043"Returns a tuple of information about the child process:\n"
3044" (pid, status)");
3045
3046#define OS_WAIT_METHODDEF \
3047 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3048
3049static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003050os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003051
3052static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003053os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003054{
3055 return os_wait_impl(module);
3056}
3057
3058#endif /* defined(HAVE_WAIT) */
3059
3060#if defined(HAVE_SYMLINK)
3061
3062PyDoc_STRVAR(os_symlink__doc__,
3063"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3064"--\n"
3065"\n"
3066"Create a symbolic link pointing to src named dst.\n"
3067"\n"
3068"target_is_directory is required on Windows if the target is to be\n"
3069" interpreted as a directory. (On Windows, symlink requires\n"
3070" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3071" target_is_directory is ignored on non-Windows platforms.\n"
3072"\n"
3073"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3074" and path should be relative; path will then be relative to that directory.\n"
3075"dir_fd may not be implemented on your platform.\n"
3076" If it is unavailable, using it will raise a NotImplementedError.");
3077
3078#define OS_SYMLINK_METHODDEF \
3079 {"symlink", (PyCFunction)os_symlink, METH_VARARGS|METH_KEYWORDS, os_symlink__doc__},
3080
3081static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003082os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003083 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003084
3085static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003086os_symlink(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003087{
3088 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003089 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3090 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003091 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3092 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3093 int target_is_directory = 0;
3094 int dir_fd = DEFAULT_DIR_FD;
3095
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003096 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003097 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003098 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003099 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003100 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3101
3102exit:
3103 /* Cleanup for src */
3104 path_cleanup(&src);
3105 /* Cleanup for dst */
3106 path_cleanup(&dst);
3107
3108 return return_value;
3109}
3110
3111#endif /* defined(HAVE_SYMLINK) */
3112
3113#if defined(HAVE_TIMES)
3114
3115PyDoc_STRVAR(os_times__doc__,
3116"times($module, /)\n"
3117"--\n"
3118"\n"
3119"Return a collection containing process timing information.\n"
3120"\n"
3121"The object returned behaves like a named tuple with these fields:\n"
3122" (utime, stime, cutime, cstime, elapsed_time)\n"
3123"All fields are floating point numbers.");
3124
3125#define OS_TIMES_METHODDEF \
3126 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3127
3128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003129os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003130
3131static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003132os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003133{
3134 return os_times_impl(module);
3135}
3136
3137#endif /* defined(HAVE_TIMES) */
3138
3139#if defined(HAVE_GETSID)
3140
3141PyDoc_STRVAR(os_getsid__doc__,
3142"getsid($module, pid, /)\n"
3143"--\n"
3144"\n"
3145"Call the system call getsid(pid) and return the result.");
3146
3147#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003148 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003149
3150static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003151os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003152
3153static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003154os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003155{
3156 PyObject *return_value = NULL;
3157 pid_t pid;
3158
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003159 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003160 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003161 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003162 return_value = os_getsid_impl(module, pid);
3163
3164exit:
3165 return return_value;
3166}
3167
3168#endif /* defined(HAVE_GETSID) */
3169
3170#if defined(HAVE_SETSID)
3171
3172PyDoc_STRVAR(os_setsid__doc__,
3173"setsid($module, /)\n"
3174"--\n"
3175"\n"
3176"Call the system call setsid().");
3177
3178#define OS_SETSID_METHODDEF \
3179 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3180
3181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003182os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003183
3184static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003185os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003186{
3187 return os_setsid_impl(module);
3188}
3189
3190#endif /* defined(HAVE_SETSID) */
3191
3192#if defined(HAVE_SETPGID)
3193
3194PyDoc_STRVAR(os_setpgid__doc__,
3195"setpgid($module, pid, pgrp, /)\n"
3196"--\n"
3197"\n"
3198"Call the system call setpgid(pid, pgrp).");
3199
3200#define OS_SETPGID_METHODDEF \
3201 {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__},
3202
3203static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003204os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003205
3206static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003207os_setpgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003208{
3209 PyObject *return_value = NULL;
3210 pid_t pid;
3211 pid_t pgrp;
3212
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003213 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003214 &pid, &pgrp)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003215 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003216 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003217 return_value = os_setpgid_impl(module, pid, pgrp);
3218
3219exit:
3220 return return_value;
3221}
3222
3223#endif /* defined(HAVE_SETPGID) */
3224
3225#if defined(HAVE_TCGETPGRP)
3226
3227PyDoc_STRVAR(os_tcgetpgrp__doc__,
3228"tcgetpgrp($module, fd, /)\n"
3229"--\n"
3230"\n"
3231"Return the process group associated with the terminal specified by fd.");
3232
3233#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003234 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003235
3236static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003237os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003238
3239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003240os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003241{
3242 PyObject *return_value = NULL;
3243 int fd;
3244
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003245 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003246 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003247 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003248 return_value = os_tcgetpgrp_impl(module, fd);
3249
3250exit:
3251 return return_value;
3252}
3253
3254#endif /* defined(HAVE_TCGETPGRP) */
3255
3256#if defined(HAVE_TCSETPGRP)
3257
3258PyDoc_STRVAR(os_tcsetpgrp__doc__,
3259"tcsetpgrp($module, fd, pgid, /)\n"
3260"--\n"
3261"\n"
3262"Set the process group associated with the terminal specified by fd.");
3263
3264#define OS_TCSETPGRP_METHODDEF \
3265 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__},
3266
3267static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003268os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003269
3270static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003271os_tcsetpgrp(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003272{
3273 PyObject *return_value = NULL;
3274 int fd;
3275 pid_t pgid;
3276
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003277 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003278 &fd, &pgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003279 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003280 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003281 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3282
3283exit:
3284 return return_value;
3285}
3286
3287#endif /* defined(HAVE_TCSETPGRP) */
3288
3289PyDoc_STRVAR(os_open__doc__,
3290"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3291"--\n"
3292"\n"
3293"Open a file for low level IO. Returns a file descriptor (integer).\n"
3294"\n"
3295"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3296" and path should be relative; path will then be relative to that directory.\n"
3297"dir_fd may not be implemented on your platform.\n"
3298" If it is unavailable, using it will raise a NotImplementedError.");
3299
3300#define OS_OPEN_METHODDEF \
3301 {"open", (PyCFunction)os_open, METH_VARARGS|METH_KEYWORDS, os_open__doc__},
3302
3303static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003304os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003305
3306static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003307os_open(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003308{
3309 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003310 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3311 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003312 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3313 int flags;
3314 int mode = 511;
3315 int dir_fd = DEFAULT_DIR_FD;
3316 int _return_value;
3317
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003318 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003319 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003320 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003321 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003322 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003323 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003324 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003325 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003326 return_value = PyLong_FromLong((long)_return_value);
3327
3328exit:
3329 /* Cleanup for path */
3330 path_cleanup(&path);
3331
3332 return return_value;
3333}
3334
3335PyDoc_STRVAR(os_close__doc__,
3336"close($module, /, fd)\n"
3337"--\n"
3338"\n"
3339"Close a file descriptor.");
3340
3341#define OS_CLOSE_METHODDEF \
3342 {"close", (PyCFunction)os_close, METH_VARARGS|METH_KEYWORDS, os_close__doc__},
3343
3344static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003345os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003346
3347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003348os_close(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003349{
3350 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003351 static const char * const _keywords[] = {"fd", NULL};
3352 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003353 int fd;
3354
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003355 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003356 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003357 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003358 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003359 return_value = os_close_impl(module, fd);
3360
3361exit:
3362 return return_value;
3363}
3364
3365PyDoc_STRVAR(os_closerange__doc__,
3366"closerange($module, fd_low, fd_high, /)\n"
3367"--\n"
3368"\n"
3369"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3370
3371#define OS_CLOSERANGE_METHODDEF \
3372 {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__},
3373
3374static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003375os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003376
3377static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003378os_closerange(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003379{
3380 PyObject *return_value = NULL;
3381 int fd_low;
3382 int fd_high;
3383
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003384 if (!PyArg_ParseTuple(args, "ii:closerange",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003385 &fd_low, &fd_high)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003386 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003387 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003388 return_value = os_closerange_impl(module, fd_low, fd_high);
3389
3390exit:
3391 return return_value;
3392}
3393
3394PyDoc_STRVAR(os_dup__doc__,
3395"dup($module, fd, /)\n"
3396"--\n"
3397"\n"
3398"Return a duplicate of a file descriptor.");
3399
3400#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003401 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003402
3403static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003404os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003405
3406static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003407os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003408{
3409 PyObject *return_value = NULL;
3410 int fd;
3411 int _return_value;
3412
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003413 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003414 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003415 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003416 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003417 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003418 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003419 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003420 return_value = PyLong_FromLong((long)_return_value);
3421
3422exit:
3423 return return_value;
3424}
3425
3426PyDoc_STRVAR(os_dup2__doc__,
3427"dup2($module, /, fd, fd2, inheritable=True)\n"
3428"--\n"
3429"\n"
3430"Duplicate file descriptor.");
3431
3432#define OS_DUP2_METHODDEF \
3433 {"dup2", (PyCFunction)os_dup2, METH_VARARGS|METH_KEYWORDS, os_dup2__doc__},
3434
3435static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003436os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003437
3438static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003439os_dup2(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003440{
3441 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003442 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3443 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003444 int fd;
3445 int fd2;
3446 int inheritable = 1;
3447
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003448 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003449 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003450 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003451 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003452 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3453
3454exit:
3455 return return_value;
3456}
3457
3458#if defined(HAVE_LOCKF)
3459
3460PyDoc_STRVAR(os_lockf__doc__,
3461"lockf($module, fd, command, length, /)\n"
3462"--\n"
3463"\n"
3464"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3465"\n"
3466" fd\n"
3467" An open file descriptor.\n"
3468" command\n"
3469" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3470" length\n"
3471" The number of bytes to lock, starting at the current position.");
3472
3473#define OS_LOCKF_METHODDEF \
3474 {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__},
3475
3476static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003477os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003478
3479static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003480os_lockf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003481{
3482 PyObject *return_value = NULL;
3483 int fd;
3484 int command;
3485 Py_off_t length;
3486
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003487 if (!PyArg_ParseTuple(args, "iiO&:lockf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003488 &fd, &command, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003489 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003490 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003491 return_value = os_lockf_impl(module, fd, command, length);
3492
3493exit:
3494 return return_value;
3495}
3496
3497#endif /* defined(HAVE_LOCKF) */
3498
3499PyDoc_STRVAR(os_lseek__doc__,
3500"lseek($module, fd, position, how, /)\n"
3501"--\n"
3502"\n"
3503"Set the position of a file descriptor. Return the new position.\n"
3504"\n"
3505"Return the new cursor position in number of bytes\n"
3506"relative to the beginning of the file.");
3507
3508#define OS_LSEEK_METHODDEF \
3509 {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__},
3510
3511static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003512os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003513
3514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003515os_lseek(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003516{
3517 PyObject *return_value = NULL;
3518 int fd;
3519 Py_off_t position;
3520 int how;
3521 Py_off_t _return_value;
3522
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003523 if (!PyArg_ParseTuple(args, "iO&i:lseek",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003524 &fd, Py_off_t_converter, &position, &how)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003525 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003526 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003527 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003528 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003529 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003530 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003531 return_value = PyLong_FromPy_off_t(_return_value);
3532
3533exit:
3534 return return_value;
3535}
3536
3537PyDoc_STRVAR(os_read__doc__,
3538"read($module, fd, length, /)\n"
3539"--\n"
3540"\n"
3541"Read from a file descriptor. Returns a bytes object.");
3542
3543#define OS_READ_METHODDEF \
3544 {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__},
3545
3546static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003547os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003548
3549static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003550os_read(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003551{
3552 PyObject *return_value = NULL;
3553 int fd;
3554 Py_ssize_t length;
3555
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003556 if (!PyArg_ParseTuple(args, "in:read",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003557 &fd, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003558 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003559 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003560 return_value = os_read_impl(module, fd, length);
3561
3562exit:
3563 return return_value;
3564}
3565
3566#if defined(HAVE_READV)
3567
3568PyDoc_STRVAR(os_readv__doc__,
3569"readv($module, fd, buffers, /)\n"
3570"--\n"
3571"\n"
3572"Read from a file descriptor fd into an iterable of buffers.\n"
3573"\n"
3574"The buffers should be mutable buffers accepting bytes.\n"
3575"readv will transfer data into each buffer until it is full\n"
3576"and then move on to the next buffer in the sequence to hold\n"
3577"the rest of the data.\n"
3578"\n"
3579"readv returns the total number of bytes read,\n"
3580"which may be less than the total capacity of all the buffers.");
3581
3582#define OS_READV_METHODDEF \
3583 {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__},
3584
3585static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003586os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003587
3588static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003589os_readv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003590{
3591 PyObject *return_value = NULL;
3592 int fd;
3593 PyObject *buffers;
3594 Py_ssize_t _return_value;
3595
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003596 if (!PyArg_ParseTuple(args, "iO:readv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003597 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003598 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003599 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003600 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003601 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003602 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003604 return_value = PyLong_FromSsize_t(_return_value);
3605
3606exit:
3607 return return_value;
3608}
3609
3610#endif /* defined(HAVE_READV) */
3611
3612#if defined(HAVE_PREAD)
3613
3614PyDoc_STRVAR(os_pread__doc__,
3615"pread($module, fd, length, offset, /)\n"
3616"--\n"
3617"\n"
3618"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3619"\n"
3620"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3621"the beginning of the file. The file offset remains unchanged.");
3622
3623#define OS_PREAD_METHODDEF \
3624 {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__},
3625
3626static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003627os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003628
3629static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003630os_pread(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003631{
3632 PyObject *return_value = NULL;
3633 int fd;
3634 int length;
3635 Py_off_t offset;
3636
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003637 if (!PyArg_ParseTuple(args, "iiO&:pread",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003638 &fd, &length, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003639 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003640 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003641 return_value = os_pread_impl(module, fd, length, offset);
3642
3643exit:
3644 return return_value;
3645}
3646
3647#endif /* defined(HAVE_PREAD) */
3648
3649PyDoc_STRVAR(os_write__doc__,
3650"write($module, fd, data, /)\n"
3651"--\n"
3652"\n"
3653"Write a bytes object to a file descriptor.");
3654
3655#define OS_WRITE_METHODDEF \
3656 {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__},
3657
3658static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003659os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003660
3661static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003662os_write(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003663{
3664 PyObject *return_value = NULL;
3665 int fd;
3666 Py_buffer data = {NULL, NULL};
3667 Py_ssize_t _return_value;
3668
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003669 if (!PyArg_ParseTuple(args, "iy*:write",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003670 &fd, &data)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003671 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003672 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003673 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003674 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003675 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003676 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003677 return_value = PyLong_FromSsize_t(_return_value);
3678
3679exit:
3680 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003681 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003682 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003683 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003684
3685 return return_value;
3686}
3687
3688PyDoc_STRVAR(os_fstat__doc__,
3689"fstat($module, /, fd)\n"
3690"--\n"
3691"\n"
3692"Perform a stat system call on the given file descriptor.\n"
3693"\n"
3694"Like stat(), but for an open file descriptor.\n"
3695"Equivalent to os.stat(fd).");
3696
3697#define OS_FSTAT_METHODDEF \
3698 {"fstat", (PyCFunction)os_fstat, METH_VARARGS|METH_KEYWORDS, os_fstat__doc__},
3699
3700static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003701os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003702
3703static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003704os_fstat(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003705{
3706 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003707 static const char * const _keywords[] = {"fd", NULL};
3708 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003709 int fd;
3710
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003711 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003712 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003713 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003714 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003715 return_value = os_fstat_impl(module, fd);
3716
3717exit:
3718 return return_value;
3719}
3720
3721PyDoc_STRVAR(os_isatty__doc__,
3722"isatty($module, fd, /)\n"
3723"--\n"
3724"\n"
3725"Return True if the fd is connected to a terminal.\n"
3726"\n"
3727"Return True if the file descriptor is an open file descriptor\n"
3728"connected to the slave end of a terminal.");
3729
3730#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003731 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003732
3733static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003734os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003735
3736static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003737os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003738{
3739 PyObject *return_value = NULL;
3740 int fd;
3741 int _return_value;
3742
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003743 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003744 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003745 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003746 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003747 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003748 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003749 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003750 return_value = PyBool_FromLong((long)_return_value);
3751
3752exit:
3753 return return_value;
3754}
3755
3756#if defined(HAVE_PIPE)
3757
3758PyDoc_STRVAR(os_pipe__doc__,
3759"pipe($module, /)\n"
3760"--\n"
3761"\n"
3762"Create a pipe.\n"
3763"\n"
3764"Returns a tuple of two file descriptors:\n"
3765" (read_fd, write_fd)");
3766
3767#define OS_PIPE_METHODDEF \
3768 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3769
3770static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003771os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003772
3773static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003774os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003775{
3776 return os_pipe_impl(module);
3777}
3778
3779#endif /* defined(HAVE_PIPE) */
3780
3781#if defined(HAVE_PIPE2)
3782
3783PyDoc_STRVAR(os_pipe2__doc__,
3784"pipe2($module, flags, /)\n"
3785"--\n"
3786"\n"
3787"Create a pipe with flags set atomically.\n"
3788"\n"
3789"Returns a tuple of two file descriptors:\n"
3790" (read_fd, write_fd)\n"
3791"\n"
3792"flags can be constructed by ORing together one or more of these values:\n"
3793"O_NONBLOCK, O_CLOEXEC.");
3794
3795#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003796 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003797
3798static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003799os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003800
3801static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003802os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003803{
3804 PyObject *return_value = NULL;
3805 int flags;
3806
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003807 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003808 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003809 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003810 return_value = os_pipe2_impl(module, flags);
3811
3812exit:
3813 return return_value;
3814}
3815
3816#endif /* defined(HAVE_PIPE2) */
3817
3818#if defined(HAVE_WRITEV)
3819
3820PyDoc_STRVAR(os_writev__doc__,
3821"writev($module, fd, buffers, /)\n"
3822"--\n"
3823"\n"
3824"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3825"\n"
3826"Returns the total number of bytes written.\n"
3827"buffers must be a sequence of bytes-like objects.");
3828
3829#define OS_WRITEV_METHODDEF \
3830 {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__},
3831
3832static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003833os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003834
3835static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003836os_writev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003837{
3838 PyObject *return_value = NULL;
3839 int fd;
3840 PyObject *buffers;
3841 Py_ssize_t _return_value;
3842
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003843 if (!PyArg_ParseTuple(args, "iO:writev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003844 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003845 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003846 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003847 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003848 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003849 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003850 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003851 return_value = PyLong_FromSsize_t(_return_value);
3852
3853exit:
3854 return return_value;
3855}
3856
3857#endif /* defined(HAVE_WRITEV) */
3858
3859#if defined(HAVE_PWRITE)
3860
3861PyDoc_STRVAR(os_pwrite__doc__,
3862"pwrite($module, fd, buffer, offset, /)\n"
3863"--\n"
3864"\n"
3865"Write bytes to a file descriptor starting at a particular offset.\n"
3866"\n"
3867"Write buffer to fd, starting at offset bytes from the beginning of\n"
3868"the file. Returns the number of bytes writte. Does not change the\n"
3869"current file offset.");
3870
3871#define OS_PWRITE_METHODDEF \
3872 {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__},
3873
3874static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003875os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003876
3877static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003878os_pwrite(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003879{
3880 PyObject *return_value = NULL;
3881 int fd;
3882 Py_buffer buffer = {NULL, NULL};
3883 Py_off_t offset;
3884 Py_ssize_t _return_value;
3885
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003886 if (!PyArg_ParseTuple(args, "iy*O&:pwrite",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003887 &fd, &buffer, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003888 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003889 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003890 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003891 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003892 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003893 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003894 return_value = PyLong_FromSsize_t(_return_value);
3895
3896exit:
3897 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003898 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003899 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003900 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003901
3902 return return_value;
3903}
3904
3905#endif /* defined(HAVE_PWRITE) */
3906
3907#if defined(HAVE_MKFIFO)
3908
3909PyDoc_STRVAR(os_mkfifo__doc__,
3910"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
3911"--\n"
3912"\n"
3913"Create a \"fifo\" (a POSIX named pipe).\n"
3914"\n"
3915"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3916" and path should be relative; path will then be relative to that directory.\n"
3917"dir_fd may not be implemented on your platform.\n"
3918" If it is unavailable, using it will raise a NotImplementedError.");
3919
3920#define OS_MKFIFO_METHODDEF \
3921 {"mkfifo", (PyCFunction)os_mkfifo, METH_VARARGS|METH_KEYWORDS, os_mkfifo__doc__},
3922
3923static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003924os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003925
3926static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003927os_mkfifo(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003928{
3929 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003930 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
3931 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003932 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
3933 int mode = 438;
3934 int dir_fd = DEFAULT_DIR_FD;
3935
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003936 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003937 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003938 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003939 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003940 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
3941
3942exit:
3943 /* Cleanup for path */
3944 path_cleanup(&path);
3945
3946 return return_value;
3947}
3948
3949#endif /* defined(HAVE_MKFIFO) */
3950
3951#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
3952
3953PyDoc_STRVAR(os_mknod__doc__,
3954"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
3955"--\n"
3956"\n"
3957"Create a node in the file system.\n"
3958"\n"
3959"Create a node in the file system (file, device special file or named pipe)\n"
3960"at path. mode specifies both the permissions to use and the\n"
3961"type of node to be created, being combined (bitwise OR) with one of\n"
3962"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
3963"device defines the newly created device special file (probably using\n"
3964"os.makedev()). Otherwise device is ignored.\n"
3965"\n"
3966"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3967" and path should be relative; path will then be relative to that directory.\n"
3968"dir_fd may not be implemented on your platform.\n"
3969" If it is unavailable, using it will raise a NotImplementedError.");
3970
3971#define OS_MKNOD_METHODDEF \
3972 {"mknod", (PyCFunction)os_mknod, METH_VARARGS|METH_KEYWORDS, os_mknod__doc__},
3973
3974static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003975os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04003976 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003977
3978static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003979os_mknod(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003980{
3981 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003982 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
3983 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003984 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
3985 int mode = 384;
3986 dev_t device = 0;
3987 int dir_fd = DEFAULT_DIR_FD;
3988
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003989 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003990 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003991 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003992 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003993 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
3994
3995exit:
3996 /* Cleanup for path */
3997 path_cleanup(&path);
3998
3999 return return_value;
4000}
4001
4002#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4003
4004#if defined(HAVE_DEVICE_MACROS)
4005
4006PyDoc_STRVAR(os_major__doc__,
4007"major($module, device, /)\n"
4008"--\n"
4009"\n"
4010"Extracts a device major number from a raw device number.");
4011
4012#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004013 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004014
4015static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004016os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004017
4018static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004019os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004020{
4021 PyObject *return_value = NULL;
4022 dev_t device;
4023 unsigned int _return_value;
4024
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004025 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004026 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004027 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004028 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004029 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004030 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004031 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004032 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4033
4034exit:
4035 return return_value;
4036}
4037
4038#endif /* defined(HAVE_DEVICE_MACROS) */
4039
4040#if defined(HAVE_DEVICE_MACROS)
4041
4042PyDoc_STRVAR(os_minor__doc__,
4043"minor($module, device, /)\n"
4044"--\n"
4045"\n"
4046"Extracts a device minor number from a raw device number.");
4047
4048#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004049 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004050
4051static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004052os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004053
4054static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004055os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004056{
4057 PyObject *return_value = NULL;
4058 dev_t device;
4059 unsigned int _return_value;
4060
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004061 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004062 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004063 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004064 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004065 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004066 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004067 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004068 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4069
4070exit:
4071 return return_value;
4072}
4073
4074#endif /* defined(HAVE_DEVICE_MACROS) */
4075
4076#if defined(HAVE_DEVICE_MACROS)
4077
4078PyDoc_STRVAR(os_makedev__doc__,
4079"makedev($module, major, minor, /)\n"
4080"--\n"
4081"\n"
4082"Composes a raw device number from the major and minor device numbers.");
4083
4084#define OS_MAKEDEV_METHODDEF \
4085 {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__},
4086
4087static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004088os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004089
4090static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004091os_makedev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004092{
4093 PyObject *return_value = NULL;
4094 int major;
4095 int minor;
4096 dev_t _return_value;
4097
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004098 if (!PyArg_ParseTuple(args, "ii:makedev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004099 &major, &minor)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004100 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004101 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004102 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004103 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004104 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004105 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004106 return_value = _PyLong_FromDev(_return_value);
4107
4108exit:
4109 return return_value;
4110}
4111
4112#endif /* defined(HAVE_DEVICE_MACROS) */
4113
Steve Dowerf7377032015-04-12 15:44:54 -04004114#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004115
4116PyDoc_STRVAR(os_ftruncate__doc__,
4117"ftruncate($module, fd, length, /)\n"
4118"--\n"
4119"\n"
4120"Truncate a file, specified by file descriptor, to a specific length.");
4121
4122#define OS_FTRUNCATE_METHODDEF \
4123 {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__},
4124
4125static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004126os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004127
4128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004129os_ftruncate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004130{
4131 PyObject *return_value = NULL;
4132 int fd;
4133 Py_off_t length;
4134
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004135 if (!PyArg_ParseTuple(args, "iO&:ftruncate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004136 &fd, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004137 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004138 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004139 return_value = os_ftruncate_impl(module, fd, length);
4140
4141exit:
4142 return return_value;
4143}
4144
Steve Dowerf7377032015-04-12 15:44:54 -04004145#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004146
Steve Dowerf7377032015-04-12 15:44:54 -04004147#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004148
4149PyDoc_STRVAR(os_truncate__doc__,
4150"truncate($module, /, path, length)\n"
4151"--\n"
4152"\n"
4153"Truncate a file, specified by path, to a specific length.\n"
4154"\n"
4155"On some platforms, path may also be specified as an open file descriptor.\n"
4156" If this functionality is unavailable, using it raises an exception.");
4157
4158#define OS_TRUNCATE_METHODDEF \
4159 {"truncate", (PyCFunction)os_truncate, METH_VARARGS|METH_KEYWORDS, os_truncate__doc__},
4160
4161static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004162os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004163
4164static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004165os_truncate(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004166{
4167 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004168 static const char * const _keywords[] = {"path", "length", NULL};
4169 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004170 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4171 Py_off_t length;
4172
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004173 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004174 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004175 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004176 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004177 return_value = os_truncate_impl(module, &path, length);
4178
4179exit:
4180 /* Cleanup for path */
4181 path_cleanup(&path);
4182
4183 return return_value;
4184}
4185
Steve Dowerf7377032015-04-12 15:44:54 -04004186#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004187
4188#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4189
4190PyDoc_STRVAR(os_posix_fallocate__doc__,
4191"posix_fallocate($module, fd, offset, length, /)\n"
4192"--\n"
4193"\n"
4194"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4195"\n"
4196"Ensure that the file specified by fd encompasses a range of bytes\n"
4197"starting at offset bytes from the beginning and continuing for length bytes.");
4198
4199#define OS_POSIX_FALLOCATE_METHODDEF \
4200 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__},
4201
4202static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004203os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004204 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004205
4206static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004207os_posix_fallocate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004208{
4209 PyObject *return_value = NULL;
4210 int fd;
4211 Py_off_t offset;
4212 Py_off_t length;
4213
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004214 if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004215 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004216 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004217 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004218 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4219
4220exit:
4221 return return_value;
4222}
4223
4224#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4225
4226#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4227
4228PyDoc_STRVAR(os_posix_fadvise__doc__,
4229"posix_fadvise($module, fd, offset, length, advice, /)\n"
4230"--\n"
4231"\n"
4232"Announce an intention to access data in a specific pattern.\n"
4233"\n"
4234"Announce an intention to access data in a specific pattern, thus allowing\n"
4235"the kernel to make optimizations.\n"
4236"The advice applies to the region of the file specified by fd starting at\n"
4237"offset and continuing for length bytes.\n"
4238"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4239"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4240"POSIX_FADV_DONTNEED.");
4241
4242#define OS_POSIX_FADVISE_METHODDEF \
4243 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__},
4244
4245static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004246os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004247 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004248
4249static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004250os_posix_fadvise(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004251{
4252 PyObject *return_value = NULL;
4253 int fd;
4254 Py_off_t offset;
4255 Py_off_t length;
4256 int advice;
4257
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004258 if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004259 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004260 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004261 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004262 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4263
4264exit:
4265 return return_value;
4266}
4267
4268#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4269
4270#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4271
4272PyDoc_STRVAR(os_putenv__doc__,
4273"putenv($module, name, value, /)\n"
4274"--\n"
4275"\n"
4276"Change or add an environment variable.");
4277
4278#define OS_PUTENV_METHODDEF \
4279 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4280
4281static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004282os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004283
4284static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004285os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004286{
4287 PyObject *return_value = NULL;
4288 PyObject *name;
4289 PyObject *value;
4290
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004291 if (!PyArg_ParseTuple(args, "UU:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004292 &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004293 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004294 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004295 return_value = os_putenv_impl(module, name, value);
4296
4297exit:
4298 return return_value;
4299}
4300
4301#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4302
4303#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4304
4305PyDoc_STRVAR(os_putenv__doc__,
4306"putenv($module, name, value, /)\n"
4307"--\n"
4308"\n"
4309"Change or add an environment variable.");
4310
4311#define OS_PUTENV_METHODDEF \
4312 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4313
4314static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004315os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004316
4317static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004318os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004319{
4320 PyObject *return_value = NULL;
4321 PyObject *name = NULL;
4322 PyObject *value = NULL;
4323
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004324 if (!PyArg_ParseTuple(args, "O&O&:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004325 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004326 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004327 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004328 return_value = os_putenv_impl(module, name, value);
4329
4330exit:
4331 /* Cleanup for name */
4332 Py_XDECREF(name);
4333 /* Cleanup for value */
4334 Py_XDECREF(value);
4335
4336 return return_value;
4337}
4338
4339#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4340
4341#if defined(HAVE_UNSETENV)
4342
4343PyDoc_STRVAR(os_unsetenv__doc__,
4344"unsetenv($module, name, /)\n"
4345"--\n"
4346"\n"
4347"Delete an environment variable.");
4348
4349#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004350 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004351
4352static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004353os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004354
4355static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004356os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004357{
4358 PyObject *return_value = NULL;
4359 PyObject *name = NULL;
4360
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004361 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004362 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004363 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004364 return_value = os_unsetenv_impl(module, name);
4365
4366exit:
4367 /* Cleanup for name */
4368 Py_XDECREF(name);
4369
4370 return return_value;
4371}
4372
4373#endif /* defined(HAVE_UNSETENV) */
4374
4375PyDoc_STRVAR(os_strerror__doc__,
4376"strerror($module, code, /)\n"
4377"--\n"
4378"\n"
4379"Translate an error code to a message string.");
4380
4381#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004382 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004383
4384static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004385os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004386
4387static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004388os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004389{
4390 PyObject *return_value = NULL;
4391 int code;
4392
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004393 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004394 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004395 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004396 return_value = os_strerror_impl(module, code);
4397
4398exit:
4399 return return_value;
4400}
4401
4402#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4403
4404PyDoc_STRVAR(os_WCOREDUMP__doc__,
4405"WCOREDUMP($module, status, /)\n"
4406"--\n"
4407"\n"
4408"Return True if the process returning status was dumped to a core file.");
4409
4410#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004411 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004412
4413static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004414os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004415
4416static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004417os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004418{
4419 PyObject *return_value = NULL;
4420 int status;
4421 int _return_value;
4422
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004423 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004424 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004425 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004426 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004427 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004428 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004429 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004430 return_value = PyBool_FromLong((long)_return_value);
4431
4432exit:
4433 return return_value;
4434}
4435
4436#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4437
4438#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4439
4440PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4441"WIFCONTINUED($module, /, status)\n"
4442"--\n"
4443"\n"
4444"Return True if a particular process was continued from a job control stop.\n"
4445"\n"
4446"Return True if the process returning status was continued from a\n"
4447"job control stop.");
4448
4449#define OS_WIFCONTINUED_METHODDEF \
4450 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_VARARGS|METH_KEYWORDS, os_WIFCONTINUED__doc__},
4451
4452static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004453os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004454
4455static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004456os_WIFCONTINUED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004457{
4458 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004459 static const char * const _keywords[] = {"status", NULL};
4460 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004461 int status;
4462 int _return_value;
4463
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004464 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004465 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004466 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004467 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004468 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004469 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004470 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004471 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004472 return_value = PyBool_FromLong((long)_return_value);
4473
4474exit:
4475 return return_value;
4476}
4477
4478#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4479
4480#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4481
4482PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4483"WIFSTOPPED($module, /, status)\n"
4484"--\n"
4485"\n"
4486"Return True if the process returning status was stopped.");
4487
4488#define OS_WIFSTOPPED_METHODDEF \
4489 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_VARARGS|METH_KEYWORDS, os_WIFSTOPPED__doc__},
4490
4491static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004492os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004493
4494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004495os_WIFSTOPPED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004496{
4497 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004498 static const char * const _keywords[] = {"status", NULL};
4499 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004500 int status;
4501 int _return_value;
4502
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004503 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004504 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004505 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004506 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004507 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004508 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004511 return_value = PyBool_FromLong((long)_return_value);
4512
4513exit:
4514 return return_value;
4515}
4516
4517#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4518
4519#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4520
4521PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4522"WIFSIGNALED($module, /, status)\n"
4523"--\n"
4524"\n"
4525"Return True if the process returning status was terminated by a signal.");
4526
4527#define OS_WIFSIGNALED_METHODDEF \
4528 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_VARARGS|METH_KEYWORDS, os_WIFSIGNALED__doc__},
4529
4530static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004531os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004532
4533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004534os_WIFSIGNALED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004535{
4536 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004537 static const char * const _keywords[] = {"status", NULL};
4538 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004539 int status;
4540 int _return_value;
4541
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004542 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004543 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004544 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004545 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004546 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004547 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004548 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004549 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004550 return_value = PyBool_FromLong((long)_return_value);
4551
4552exit:
4553 return return_value;
4554}
4555
4556#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4557
4558#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4559
4560PyDoc_STRVAR(os_WIFEXITED__doc__,
4561"WIFEXITED($module, /, status)\n"
4562"--\n"
4563"\n"
4564"Return True if the process returning status exited via the exit() system call.");
4565
4566#define OS_WIFEXITED_METHODDEF \
4567 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_VARARGS|METH_KEYWORDS, os_WIFEXITED__doc__},
4568
4569static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004570os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004571
4572static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004573os_WIFEXITED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004574{
4575 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004576 static const char * const _keywords[] = {"status", NULL};
4577 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004578 int status;
4579 int _return_value;
4580
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004581 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004582 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004583 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004584 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004585 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004586 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004587 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004588 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004589 return_value = PyBool_FromLong((long)_return_value);
4590
4591exit:
4592 return return_value;
4593}
4594
4595#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4596
4597#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4598
4599PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4600"WEXITSTATUS($module, /, status)\n"
4601"--\n"
4602"\n"
4603"Return the process return code from status.");
4604
4605#define OS_WEXITSTATUS_METHODDEF \
4606 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_VARARGS|METH_KEYWORDS, os_WEXITSTATUS__doc__},
4607
4608static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004609os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004610
4611static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004612os_WEXITSTATUS(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004613{
4614 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004615 static const char * const _keywords[] = {"status", NULL};
4616 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004617 int status;
4618 int _return_value;
4619
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004620 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004621 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004622 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004623 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004624 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004625 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004626 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004627 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004628 return_value = PyLong_FromLong((long)_return_value);
4629
4630exit:
4631 return return_value;
4632}
4633
4634#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4635
4636#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4637
4638PyDoc_STRVAR(os_WTERMSIG__doc__,
4639"WTERMSIG($module, /, status)\n"
4640"--\n"
4641"\n"
4642"Return the signal that terminated the process that provided the status value.");
4643
4644#define OS_WTERMSIG_METHODDEF \
4645 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_VARARGS|METH_KEYWORDS, os_WTERMSIG__doc__},
4646
4647static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004648os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004649
4650static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004651os_WTERMSIG(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004652{
4653 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004654 static const char * const _keywords[] = {"status", NULL};
4655 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004656 int status;
4657 int _return_value;
4658
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004659 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004660 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004661 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004662 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004663 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004664 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004665 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004666 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004667 return_value = PyLong_FromLong((long)_return_value);
4668
4669exit:
4670 return return_value;
4671}
4672
4673#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4674
4675#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4676
4677PyDoc_STRVAR(os_WSTOPSIG__doc__,
4678"WSTOPSIG($module, /, status)\n"
4679"--\n"
4680"\n"
4681"Return the signal that stopped the process that provided the status value.");
4682
4683#define OS_WSTOPSIG_METHODDEF \
4684 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_VARARGS|METH_KEYWORDS, os_WSTOPSIG__doc__},
4685
4686static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004687os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004688
4689static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004690os_WSTOPSIG(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004691{
4692 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004693 static const char * const _keywords[] = {"status", NULL};
4694 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004695 int status;
4696 int _return_value;
4697
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004698 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004699 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004700 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004701 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004702 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004703 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004704 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004705 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004706 return_value = PyLong_FromLong((long)_return_value);
4707
4708exit:
4709 return return_value;
4710}
4711
4712#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4713
4714#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4715
4716PyDoc_STRVAR(os_fstatvfs__doc__,
4717"fstatvfs($module, fd, /)\n"
4718"--\n"
4719"\n"
4720"Perform an fstatvfs system call on the given fd.\n"
4721"\n"
4722"Equivalent to statvfs(fd).");
4723
4724#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004725 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004726
4727static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004728os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004729
4730static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004731os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004732{
4733 PyObject *return_value = NULL;
4734 int fd;
4735
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004736 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004737 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004738 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004739 return_value = os_fstatvfs_impl(module, fd);
4740
4741exit:
4742 return return_value;
4743}
4744
4745#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4746
4747#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4748
4749PyDoc_STRVAR(os_statvfs__doc__,
4750"statvfs($module, /, path)\n"
4751"--\n"
4752"\n"
4753"Perform a statvfs system call on the given path.\n"
4754"\n"
4755"path may always be specified as a string.\n"
4756"On some platforms, path may also be specified as an open file descriptor.\n"
4757" If this functionality is unavailable, using it raises an exception.");
4758
4759#define OS_STATVFS_METHODDEF \
4760 {"statvfs", (PyCFunction)os_statvfs, METH_VARARGS|METH_KEYWORDS, os_statvfs__doc__},
4761
4762static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004763os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004764
4765static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004766os_statvfs(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004767{
4768 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004769 static const char * const _keywords[] = {"path", NULL};
4770 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004771 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4772
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004773 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004774 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004775 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004776 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004777 return_value = os_statvfs_impl(module, &path);
4778
4779exit:
4780 /* Cleanup for path */
4781 path_cleanup(&path);
4782
4783 return return_value;
4784}
4785
4786#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4787
4788#if defined(MS_WINDOWS)
4789
4790PyDoc_STRVAR(os__getdiskusage__doc__,
4791"_getdiskusage($module, /, path)\n"
4792"--\n"
4793"\n"
4794"Return disk usage statistics about the given path as a (total, free) tuple.");
4795
4796#define OS__GETDISKUSAGE_METHODDEF \
4797 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_VARARGS|METH_KEYWORDS, os__getdiskusage__doc__},
4798
4799static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004800os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004801
4802static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004803os__getdiskusage(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004804{
4805 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004806 static const char * const _keywords[] = {"path", NULL};
4807 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004808 Py_UNICODE *path;
4809
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004810 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004811 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004812 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004813 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004814 return_value = os__getdiskusage_impl(module, path);
4815
4816exit:
4817 return return_value;
4818}
4819
4820#endif /* defined(MS_WINDOWS) */
4821
4822#if defined(HAVE_FPATHCONF)
4823
4824PyDoc_STRVAR(os_fpathconf__doc__,
4825"fpathconf($module, fd, name, /)\n"
4826"--\n"
4827"\n"
4828"Return the configuration limit name for the file descriptor fd.\n"
4829"\n"
4830"If there is no limit, return -1.");
4831
4832#define OS_FPATHCONF_METHODDEF \
4833 {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__},
4834
4835static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004836os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004837
4838static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004839os_fpathconf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004840{
4841 PyObject *return_value = NULL;
4842 int fd;
4843 int name;
4844 long _return_value;
4845
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004846 if (!PyArg_ParseTuple(args, "iO&:fpathconf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004847 &fd, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004848 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004849 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004850 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004851 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004852 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004853 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004854 return_value = PyLong_FromLong(_return_value);
4855
4856exit:
4857 return return_value;
4858}
4859
4860#endif /* defined(HAVE_FPATHCONF) */
4861
4862#if defined(HAVE_PATHCONF)
4863
4864PyDoc_STRVAR(os_pathconf__doc__,
4865"pathconf($module, /, path, name)\n"
4866"--\n"
4867"\n"
4868"Return the configuration limit name for the file or directory path.\n"
4869"\n"
4870"If there is no limit, return -1.\n"
4871"On some platforms, path may also be specified as an open file descriptor.\n"
4872" If this functionality is unavailable, using it raises an exception.");
4873
4874#define OS_PATHCONF_METHODDEF \
4875 {"pathconf", (PyCFunction)os_pathconf, METH_VARARGS|METH_KEYWORDS, os_pathconf__doc__},
4876
4877static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004878os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004879
4880static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004881os_pathconf(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004882{
4883 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004884 static const char * const _keywords[] = {"path", "name", NULL};
4885 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004886 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
4887 int name;
4888 long _return_value;
4889
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004890 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004891 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004892 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004893 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004894 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004895 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004896 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004897 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004898 return_value = PyLong_FromLong(_return_value);
4899
4900exit:
4901 /* Cleanup for path */
4902 path_cleanup(&path);
4903
4904 return return_value;
4905}
4906
4907#endif /* defined(HAVE_PATHCONF) */
4908
4909#if defined(HAVE_CONFSTR)
4910
4911PyDoc_STRVAR(os_confstr__doc__,
4912"confstr($module, name, /)\n"
4913"--\n"
4914"\n"
4915"Return a string-valued system configuration variable.");
4916
4917#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004918 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004919
4920static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004921os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004922
4923static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004924os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004925{
4926 PyObject *return_value = NULL;
4927 int name;
4928
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004929 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004930 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004931 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004932 return_value = os_confstr_impl(module, name);
4933
4934exit:
4935 return return_value;
4936}
4937
4938#endif /* defined(HAVE_CONFSTR) */
4939
4940#if defined(HAVE_SYSCONF)
4941
4942PyDoc_STRVAR(os_sysconf__doc__,
4943"sysconf($module, name, /)\n"
4944"--\n"
4945"\n"
4946"Return an integer-valued system configuration variable.");
4947
4948#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004949 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004950
4951static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004952os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004953
4954static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004955os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004956{
4957 PyObject *return_value = NULL;
4958 int name;
4959 long _return_value;
4960
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004961 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004962 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004963 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004964 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004965 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004966 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004967 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004968 return_value = PyLong_FromLong(_return_value);
4969
4970exit:
4971 return return_value;
4972}
4973
4974#endif /* defined(HAVE_SYSCONF) */
4975
4976PyDoc_STRVAR(os_abort__doc__,
4977"abort($module, /)\n"
4978"--\n"
4979"\n"
4980"Abort the interpreter immediately.\n"
4981"\n"
4982"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
4983"on the hosting operating system. This function never returns.");
4984
4985#define OS_ABORT_METHODDEF \
4986 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
4987
4988static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004989os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004990
4991static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004992os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004993{
4994 return os_abort_impl(module);
4995}
4996
4997#if defined(HAVE_GETLOADAVG)
4998
4999PyDoc_STRVAR(os_getloadavg__doc__,
5000"getloadavg($module, /)\n"
5001"--\n"
5002"\n"
5003"Return average recent system load information.\n"
5004"\n"
5005"Return the number of processes in the system run queue averaged over\n"
5006"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5007"Raises OSError if the load average was unobtainable.");
5008
5009#define OS_GETLOADAVG_METHODDEF \
5010 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5011
5012static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005013os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005014
5015static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005016os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005017{
5018 return os_getloadavg_impl(module);
5019}
5020
5021#endif /* defined(HAVE_GETLOADAVG) */
5022
5023PyDoc_STRVAR(os_device_encoding__doc__,
5024"device_encoding($module, /, fd)\n"
5025"--\n"
5026"\n"
5027"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5028"\n"
5029"The file descriptor must be attached to a terminal.\n"
5030"If the device is not a terminal, return None.");
5031
5032#define OS_DEVICE_ENCODING_METHODDEF \
5033 {"device_encoding", (PyCFunction)os_device_encoding, METH_VARARGS|METH_KEYWORDS, os_device_encoding__doc__},
5034
5035static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005036os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005037
5038static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005039os_device_encoding(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005040{
5041 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005042 static const char * const _keywords[] = {"fd", NULL};
5043 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005044 int fd;
5045
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005046 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005047 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005048 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005049 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005050 return_value = os_device_encoding_impl(module, fd);
5051
5052exit:
5053 return return_value;
5054}
5055
5056#if defined(HAVE_SETRESUID)
5057
5058PyDoc_STRVAR(os_setresuid__doc__,
5059"setresuid($module, ruid, euid, suid, /)\n"
5060"--\n"
5061"\n"
5062"Set the current process\'s real, effective, and saved user ids.");
5063
5064#define OS_SETRESUID_METHODDEF \
5065 {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__},
5066
5067static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005068os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005069
5070static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005071os_setresuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005072{
5073 PyObject *return_value = NULL;
5074 uid_t ruid;
5075 uid_t euid;
5076 uid_t suid;
5077
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005078 if (!PyArg_ParseTuple(args, "O&O&O&:setresuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005079 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005080 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005081 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005082 return_value = os_setresuid_impl(module, ruid, euid, suid);
5083
5084exit:
5085 return return_value;
5086}
5087
5088#endif /* defined(HAVE_SETRESUID) */
5089
5090#if defined(HAVE_SETRESGID)
5091
5092PyDoc_STRVAR(os_setresgid__doc__,
5093"setresgid($module, rgid, egid, sgid, /)\n"
5094"--\n"
5095"\n"
5096"Set the current process\'s real, effective, and saved group ids.");
5097
5098#define OS_SETRESGID_METHODDEF \
5099 {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__},
5100
5101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005102os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005103
5104static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005105os_setresgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005106{
5107 PyObject *return_value = NULL;
5108 gid_t rgid;
5109 gid_t egid;
5110 gid_t sgid;
5111
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005112 if (!PyArg_ParseTuple(args, "O&O&O&:setresgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005113 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005114 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005115 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005116 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5117
5118exit:
5119 return return_value;
5120}
5121
5122#endif /* defined(HAVE_SETRESGID) */
5123
5124#if defined(HAVE_GETRESUID)
5125
5126PyDoc_STRVAR(os_getresuid__doc__,
5127"getresuid($module, /)\n"
5128"--\n"
5129"\n"
5130"Return a tuple of the current process\'s real, effective, and saved user ids.");
5131
5132#define OS_GETRESUID_METHODDEF \
5133 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5134
5135static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005136os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005137
5138static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005139os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005140{
5141 return os_getresuid_impl(module);
5142}
5143
5144#endif /* defined(HAVE_GETRESUID) */
5145
5146#if defined(HAVE_GETRESGID)
5147
5148PyDoc_STRVAR(os_getresgid__doc__,
5149"getresgid($module, /)\n"
5150"--\n"
5151"\n"
5152"Return a tuple of the current process\'s real, effective, and saved group ids.");
5153
5154#define OS_GETRESGID_METHODDEF \
5155 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5156
5157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005158os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005159
5160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005161os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005162{
5163 return os_getresgid_impl(module);
5164}
5165
5166#endif /* defined(HAVE_GETRESGID) */
5167
5168#if defined(USE_XATTRS)
5169
5170PyDoc_STRVAR(os_getxattr__doc__,
5171"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5172"--\n"
5173"\n"
5174"Return the value of extended attribute attribute on path.\n"
5175"\n"
5176"path may be either a string or an open file descriptor.\n"
5177"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5178" link, getxattr will examine the symbolic link itself instead of the file\n"
5179" the link points to.");
5180
5181#define OS_GETXATTR_METHODDEF \
5182 {"getxattr", (PyCFunction)os_getxattr, METH_VARARGS|METH_KEYWORDS, os_getxattr__doc__},
5183
5184static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005185os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005186 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005187
5188static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005189os_getxattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005190{
5191 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005192 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5193 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005194 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5195 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5196 int follow_symlinks = 1;
5197
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005198 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005199 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005200 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005201 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005202 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5203
5204exit:
5205 /* Cleanup for path */
5206 path_cleanup(&path);
5207 /* Cleanup for attribute */
5208 path_cleanup(&attribute);
5209
5210 return return_value;
5211}
5212
5213#endif /* defined(USE_XATTRS) */
5214
5215#if defined(USE_XATTRS)
5216
5217PyDoc_STRVAR(os_setxattr__doc__,
5218"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5219" follow_symlinks=True)\n"
5220"--\n"
5221"\n"
5222"Set extended attribute attribute on path to value.\n"
5223"\n"
5224"path may be either a string or an open file descriptor.\n"
5225"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5226" link, setxattr will modify the symbolic link itself instead of the file\n"
5227" the link points to.");
5228
5229#define OS_SETXATTR_METHODDEF \
5230 {"setxattr", (PyCFunction)os_setxattr, METH_VARARGS|METH_KEYWORDS, os_setxattr__doc__},
5231
5232static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005233os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005234 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005235
5236static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005237os_setxattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005238{
5239 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005240 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5241 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005242 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5243 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5244 Py_buffer value = {NULL, NULL};
5245 int flags = 0;
5246 int follow_symlinks = 1;
5247
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005248 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005249 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005250 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005251 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005252 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5253
5254exit:
5255 /* Cleanup for path */
5256 path_cleanup(&path);
5257 /* Cleanup for attribute */
5258 path_cleanup(&attribute);
5259 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005260 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005261 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005262 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005263
5264 return return_value;
5265}
5266
5267#endif /* defined(USE_XATTRS) */
5268
5269#if defined(USE_XATTRS)
5270
5271PyDoc_STRVAR(os_removexattr__doc__,
5272"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5273"--\n"
5274"\n"
5275"Remove extended attribute attribute on path.\n"
5276"\n"
5277"path may be either a string or an open file descriptor.\n"
5278"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5279" link, removexattr will modify the symbolic link itself instead of the file\n"
5280" the link points to.");
5281
5282#define OS_REMOVEXATTR_METHODDEF \
5283 {"removexattr", (PyCFunction)os_removexattr, METH_VARARGS|METH_KEYWORDS, os_removexattr__doc__},
5284
5285static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005286os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005287 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005288
5289static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005290os_removexattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005291{
5292 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005293 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5294 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005295 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5296 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5297 int follow_symlinks = 1;
5298
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005299 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005300 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005301 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005302 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005303 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5304
5305exit:
5306 /* Cleanup for path */
5307 path_cleanup(&path);
5308 /* Cleanup for attribute */
5309 path_cleanup(&attribute);
5310
5311 return return_value;
5312}
5313
5314#endif /* defined(USE_XATTRS) */
5315
5316#if defined(USE_XATTRS)
5317
5318PyDoc_STRVAR(os_listxattr__doc__,
5319"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5320"--\n"
5321"\n"
5322"Return a list of extended attributes on path.\n"
5323"\n"
5324"path may be either None, a string, or an open file descriptor.\n"
5325"if path is None, listxattr will examine the current directory.\n"
5326"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5327" link, listxattr will examine the symbolic link itself instead of the file\n"
5328" the link points to.");
5329
5330#define OS_LISTXATTR_METHODDEF \
5331 {"listxattr", (PyCFunction)os_listxattr, METH_VARARGS|METH_KEYWORDS, os_listxattr__doc__},
5332
5333static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005334os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005335
5336static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005337os_listxattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005338{
5339 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005340 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5341 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005342 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5343 int follow_symlinks = 1;
5344
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005345 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005346 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005347 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005348 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005349 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5350
5351exit:
5352 /* Cleanup for path */
5353 path_cleanup(&path);
5354
5355 return return_value;
5356}
5357
5358#endif /* defined(USE_XATTRS) */
5359
5360PyDoc_STRVAR(os_urandom__doc__,
5361"urandom($module, size, /)\n"
5362"--\n"
5363"\n"
5364"Return a bytes object containing random bytes suitable for cryptographic use.");
5365
5366#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005367 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005368
5369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005370os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005371
5372static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005373os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005374{
5375 PyObject *return_value = NULL;
5376 Py_ssize_t size;
5377
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005378 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005379 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005380 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005381 return_value = os_urandom_impl(module, size);
5382
5383exit:
5384 return return_value;
5385}
5386
5387PyDoc_STRVAR(os_cpu_count__doc__,
5388"cpu_count($module, /)\n"
5389"--\n"
5390"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005391"Return the number of CPUs in the system; return None if indeterminable.\n"
5392"\n"
5393"This number is not equivalent to the number of CPUs the current process can\n"
5394"use. The number of usable CPUs can be obtained with\n"
5395"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005396
5397#define OS_CPU_COUNT_METHODDEF \
5398 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5399
5400static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005401os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005402
5403static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005404os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005405{
5406 return os_cpu_count_impl(module);
5407}
5408
5409PyDoc_STRVAR(os_get_inheritable__doc__,
5410"get_inheritable($module, fd, /)\n"
5411"--\n"
5412"\n"
5413"Get the close-on-exe flag of the specified file descriptor.");
5414
5415#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005416 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005417
5418static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005419os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005420
5421static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005422os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005423{
5424 PyObject *return_value = NULL;
5425 int fd;
5426 int _return_value;
5427
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005428 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005429 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005430 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005431 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005432 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005433 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005435 return_value = PyBool_FromLong((long)_return_value);
5436
5437exit:
5438 return return_value;
5439}
5440
5441PyDoc_STRVAR(os_set_inheritable__doc__,
5442"set_inheritable($module, fd, inheritable, /)\n"
5443"--\n"
5444"\n"
5445"Set the inheritable flag of the specified file descriptor.");
5446
5447#define OS_SET_INHERITABLE_METHODDEF \
5448 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__},
5449
5450static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005451os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005452
5453static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005454os_set_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005455{
5456 PyObject *return_value = NULL;
5457 int fd;
5458 int inheritable;
5459
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005460 if (!PyArg_ParseTuple(args, "ii:set_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005461 &fd, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005462 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005463 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005464 return_value = os_set_inheritable_impl(module, fd, inheritable);
5465
5466exit:
5467 return return_value;
5468}
5469
5470#if defined(MS_WINDOWS)
5471
5472PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5473"get_handle_inheritable($module, handle, /)\n"
5474"--\n"
5475"\n"
5476"Get the close-on-exe flag of the specified file descriptor.");
5477
5478#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005479 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005480
5481static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005482os_get_handle_inheritable_impl(PyObject *module, Py_intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005483
5484static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005485os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005486{
5487 PyObject *return_value = NULL;
5488 Py_intptr_t handle;
5489 int _return_value;
5490
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005491 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005492 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005493 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005494 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005495 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005496 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005497 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005498 return_value = PyBool_FromLong((long)_return_value);
5499
5500exit:
5501 return return_value;
5502}
5503
5504#endif /* defined(MS_WINDOWS) */
5505
5506#if defined(MS_WINDOWS)
5507
5508PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5509"set_handle_inheritable($module, handle, inheritable, /)\n"
5510"--\n"
5511"\n"
5512"Set the inheritable flag of the specified handle.");
5513
5514#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
5515 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__},
5516
5517static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005518os_set_handle_inheritable_impl(PyObject *module, Py_intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005519 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005520
5521static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005522os_set_handle_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005523{
5524 PyObject *return_value = NULL;
5525 Py_intptr_t handle;
5526 int inheritable;
5527
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005528 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005529 &handle, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005530 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005531 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005532 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5533
5534exit:
5535 return return_value;
5536}
5537
5538#endif /* defined(MS_WINDOWS) */
5539
Ethan Furman410ef8e2016-06-04 12:06:26 -07005540PyDoc_STRVAR(os_fspath__doc__,
5541"fspath($module, /, path)\n"
5542"--\n"
5543"\n"
5544"Return the file system path representation of the object.\n"
5545"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005546"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5547"object defines __fspath__(), then return the result of that method. All other\n"
5548"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005549
5550#define OS_FSPATH_METHODDEF \
5551 {"fspath", (PyCFunction)os_fspath, METH_VARARGS|METH_KEYWORDS, os_fspath__doc__},
5552
5553static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005554os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07005555
5556static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005557os_fspath(PyObject *module, PyObject *args, PyObject *kwargs)
Ethan Furman410ef8e2016-06-04 12:06:26 -07005558{
5559 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005560 static const char * const _keywords[] = {"path", NULL};
5561 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07005562 PyObject *path;
5563
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005564 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005565 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07005566 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005567 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07005568 return_value = os_fspath_impl(module, path);
5569
5570exit:
5571 return return_value;
5572}
5573
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005574#ifndef OS_TTYNAME_METHODDEF
5575 #define OS_TTYNAME_METHODDEF
5576#endif /* !defined(OS_TTYNAME_METHODDEF) */
5577
5578#ifndef OS_CTERMID_METHODDEF
5579 #define OS_CTERMID_METHODDEF
5580#endif /* !defined(OS_CTERMID_METHODDEF) */
5581
5582#ifndef OS_FCHDIR_METHODDEF
5583 #define OS_FCHDIR_METHODDEF
5584#endif /* !defined(OS_FCHDIR_METHODDEF) */
5585
5586#ifndef OS_FCHMOD_METHODDEF
5587 #define OS_FCHMOD_METHODDEF
5588#endif /* !defined(OS_FCHMOD_METHODDEF) */
5589
5590#ifndef OS_LCHMOD_METHODDEF
5591 #define OS_LCHMOD_METHODDEF
5592#endif /* !defined(OS_LCHMOD_METHODDEF) */
5593
5594#ifndef OS_CHFLAGS_METHODDEF
5595 #define OS_CHFLAGS_METHODDEF
5596#endif /* !defined(OS_CHFLAGS_METHODDEF) */
5597
5598#ifndef OS_LCHFLAGS_METHODDEF
5599 #define OS_LCHFLAGS_METHODDEF
5600#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
5601
5602#ifndef OS_CHROOT_METHODDEF
5603 #define OS_CHROOT_METHODDEF
5604#endif /* !defined(OS_CHROOT_METHODDEF) */
5605
5606#ifndef OS_FSYNC_METHODDEF
5607 #define OS_FSYNC_METHODDEF
5608#endif /* !defined(OS_FSYNC_METHODDEF) */
5609
5610#ifndef OS_SYNC_METHODDEF
5611 #define OS_SYNC_METHODDEF
5612#endif /* !defined(OS_SYNC_METHODDEF) */
5613
5614#ifndef OS_FDATASYNC_METHODDEF
5615 #define OS_FDATASYNC_METHODDEF
5616#endif /* !defined(OS_FDATASYNC_METHODDEF) */
5617
5618#ifndef OS_CHOWN_METHODDEF
5619 #define OS_CHOWN_METHODDEF
5620#endif /* !defined(OS_CHOWN_METHODDEF) */
5621
5622#ifndef OS_FCHOWN_METHODDEF
5623 #define OS_FCHOWN_METHODDEF
5624#endif /* !defined(OS_FCHOWN_METHODDEF) */
5625
5626#ifndef OS_LCHOWN_METHODDEF
5627 #define OS_LCHOWN_METHODDEF
5628#endif /* !defined(OS_LCHOWN_METHODDEF) */
5629
5630#ifndef OS_LINK_METHODDEF
5631 #define OS_LINK_METHODDEF
5632#endif /* !defined(OS_LINK_METHODDEF) */
5633
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005634#ifndef OS__GETFULLPATHNAME_METHODDEF
5635 #define OS__GETFULLPATHNAME_METHODDEF
5636#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
5637
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005638#ifndef OS__GETFINALPATHNAME_METHODDEF
5639 #define OS__GETFINALPATHNAME_METHODDEF
5640#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
5641
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005642#ifndef OS__ISDIR_METHODDEF
5643 #define OS__ISDIR_METHODDEF
5644#endif /* !defined(OS__ISDIR_METHODDEF) */
5645
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005646#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
5647 #define OS__GETVOLUMEPATHNAME_METHODDEF
5648#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
5649
5650#ifndef OS_NICE_METHODDEF
5651 #define OS_NICE_METHODDEF
5652#endif /* !defined(OS_NICE_METHODDEF) */
5653
5654#ifndef OS_GETPRIORITY_METHODDEF
5655 #define OS_GETPRIORITY_METHODDEF
5656#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
5657
5658#ifndef OS_SETPRIORITY_METHODDEF
5659 #define OS_SETPRIORITY_METHODDEF
5660#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
5661
5662#ifndef OS_SYSTEM_METHODDEF
5663 #define OS_SYSTEM_METHODDEF
5664#endif /* !defined(OS_SYSTEM_METHODDEF) */
5665
5666#ifndef OS_UNAME_METHODDEF
5667 #define OS_UNAME_METHODDEF
5668#endif /* !defined(OS_UNAME_METHODDEF) */
5669
5670#ifndef OS_EXECV_METHODDEF
5671 #define OS_EXECV_METHODDEF
5672#endif /* !defined(OS_EXECV_METHODDEF) */
5673
5674#ifndef OS_EXECVE_METHODDEF
5675 #define OS_EXECVE_METHODDEF
5676#endif /* !defined(OS_EXECVE_METHODDEF) */
5677
5678#ifndef OS_SPAWNV_METHODDEF
5679 #define OS_SPAWNV_METHODDEF
5680#endif /* !defined(OS_SPAWNV_METHODDEF) */
5681
5682#ifndef OS_SPAWNVE_METHODDEF
5683 #define OS_SPAWNVE_METHODDEF
5684#endif /* !defined(OS_SPAWNVE_METHODDEF) */
5685
5686#ifndef OS_FORK1_METHODDEF
5687 #define OS_FORK1_METHODDEF
5688#endif /* !defined(OS_FORK1_METHODDEF) */
5689
5690#ifndef OS_FORK_METHODDEF
5691 #define OS_FORK_METHODDEF
5692#endif /* !defined(OS_FORK_METHODDEF) */
5693
5694#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5695 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5696#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
5697
5698#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5699 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5700#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
5701
5702#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
5703 #define OS_SCHED_GETSCHEDULER_METHODDEF
5704#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
5705
5706#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
5707 #define OS_SCHED_SETSCHEDULER_METHODDEF
5708#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
5709
5710#ifndef OS_SCHED_GETPARAM_METHODDEF
5711 #define OS_SCHED_GETPARAM_METHODDEF
5712#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
5713
5714#ifndef OS_SCHED_SETPARAM_METHODDEF
5715 #define OS_SCHED_SETPARAM_METHODDEF
5716#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
5717
5718#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
5719 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
5720#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
5721
5722#ifndef OS_SCHED_YIELD_METHODDEF
5723 #define OS_SCHED_YIELD_METHODDEF
5724#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
5725
5726#ifndef OS_SCHED_SETAFFINITY_METHODDEF
5727 #define OS_SCHED_SETAFFINITY_METHODDEF
5728#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
5729
5730#ifndef OS_SCHED_GETAFFINITY_METHODDEF
5731 #define OS_SCHED_GETAFFINITY_METHODDEF
5732#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
5733
5734#ifndef OS_OPENPTY_METHODDEF
5735 #define OS_OPENPTY_METHODDEF
5736#endif /* !defined(OS_OPENPTY_METHODDEF) */
5737
5738#ifndef OS_FORKPTY_METHODDEF
5739 #define OS_FORKPTY_METHODDEF
5740#endif /* !defined(OS_FORKPTY_METHODDEF) */
5741
5742#ifndef OS_GETEGID_METHODDEF
5743 #define OS_GETEGID_METHODDEF
5744#endif /* !defined(OS_GETEGID_METHODDEF) */
5745
5746#ifndef OS_GETEUID_METHODDEF
5747 #define OS_GETEUID_METHODDEF
5748#endif /* !defined(OS_GETEUID_METHODDEF) */
5749
5750#ifndef OS_GETGID_METHODDEF
5751 #define OS_GETGID_METHODDEF
5752#endif /* !defined(OS_GETGID_METHODDEF) */
5753
5754#ifndef OS_GETGROUPS_METHODDEF
5755 #define OS_GETGROUPS_METHODDEF
5756#endif /* !defined(OS_GETGROUPS_METHODDEF) */
5757
5758#ifndef OS_GETPGID_METHODDEF
5759 #define OS_GETPGID_METHODDEF
5760#endif /* !defined(OS_GETPGID_METHODDEF) */
5761
5762#ifndef OS_GETPGRP_METHODDEF
5763 #define OS_GETPGRP_METHODDEF
5764#endif /* !defined(OS_GETPGRP_METHODDEF) */
5765
5766#ifndef OS_SETPGRP_METHODDEF
5767 #define OS_SETPGRP_METHODDEF
5768#endif /* !defined(OS_SETPGRP_METHODDEF) */
5769
5770#ifndef OS_GETPPID_METHODDEF
5771 #define OS_GETPPID_METHODDEF
5772#endif /* !defined(OS_GETPPID_METHODDEF) */
5773
5774#ifndef OS_GETLOGIN_METHODDEF
5775 #define OS_GETLOGIN_METHODDEF
5776#endif /* !defined(OS_GETLOGIN_METHODDEF) */
5777
5778#ifndef OS_GETUID_METHODDEF
5779 #define OS_GETUID_METHODDEF
5780#endif /* !defined(OS_GETUID_METHODDEF) */
5781
5782#ifndef OS_KILL_METHODDEF
5783 #define OS_KILL_METHODDEF
5784#endif /* !defined(OS_KILL_METHODDEF) */
5785
5786#ifndef OS_KILLPG_METHODDEF
5787 #define OS_KILLPG_METHODDEF
5788#endif /* !defined(OS_KILLPG_METHODDEF) */
5789
5790#ifndef OS_PLOCK_METHODDEF
5791 #define OS_PLOCK_METHODDEF
5792#endif /* !defined(OS_PLOCK_METHODDEF) */
5793
5794#ifndef OS_SETUID_METHODDEF
5795 #define OS_SETUID_METHODDEF
5796#endif /* !defined(OS_SETUID_METHODDEF) */
5797
5798#ifndef OS_SETEUID_METHODDEF
5799 #define OS_SETEUID_METHODDEF
5800#endif /* !defined(OS_SETEUID_METHODDEF) */
5801
5802#ifndef OS_SETEGID_METHODDEF
5803 #define OS_SETEGID_METHODDEF
5804#endif /* !defined(OS_SETEGID_METHODDEF) */
5805
5806#ifndef OS_SETREUID_METHODDEF
5807 #define OS_SETREUID_METHODDEF
5808#endif /* !defined(OS_SETREUID_METHODDEF) */
5809
5810#ifndef OS_SETREGID_METHODDEF
5811 #define OS_SETREGID_METHODDEF
5812#endif /* !defined(OS_SETREGID_METHODDEF) */
5813
5814#ifndef OS_SETGID_METHODDEF
5815 #define OS_SETGID_METHODDEF
5816#endif /* !defined(OS_SETGID_METHODDEF) */
5817
5818#ifndef OS_SETGROUPS_METHODDEF
5819 #define OS_SETGROUPS_METHODDEF
5820#endif /* !defined(OS_SETGROUPS_METHODDEF) */
5821
5822#ifndef OS_WAIT3_METHODDEF
5823 #define OS_WAIT3_METHODDEF
5824#endif /* !defined(OS_WAIT3_METHODDEF) */
5825
5826#ifndef OS_WAIT4_METHODDEF
5827 #define OS_WAIT4_METHODDEF
5828#endif /* !defined(OS_WAIT4_METHODDEF) */
5829
5830#ifndef OS_WAITID_METHODDEF
5831 #define OS_WAITID_METHODDEF
5832#endif /* !defined(OS_WAITID_METHODDEF) */
5833
5834#ifndef OS_WAITPID_METHODDEF
5835 #define OS_WAITPID_METHODDEF
5836#endif /* !defined(OS_WAITPID_METHODDEF) */
5837
5838#ifndef OS_WAIT_METHODDEF
5839 #define OS_WAIT_METHODDEF
5840#endif /* !defined(OS_WAIT_METHODDEF) */
5841
5842#ifndef OS_SYMLINK_METHODDEF
5843 #define OS_SYMLINK_METHODDEF
5844#endif /* !defined(OS_SYMLINK_METHODDEF) */
5845
5846#ifndef OS_TIMES_METHODDEF
5847 #define OS_TIMES_METHODDEF
5848#endif /* !defined(OS_TIMES_METHODDEF) */
5849
5850#ifndef OS_GETSID_METHODDEF
5851 #define OS_GETSID_METHODDEF
5852#endif /* !defined(OS_GETSID_METHODDEF) */
5853
5854#ifndef OS_SETSID_METHODDEF
5855 #define OS_SETSID_METHODDEF
5856#endif /* !defined(OS_SETSID_METHODDEF) */
5857
5858#ifndef OS_SETPGID_METHODDEF
5859 #define OS_SETPGID_METHODDEF
5860#endif /* !defined(OS_SETPGID_METHODDEF) */
5861
5862#ifndef OS_TCGETPGRP_METHODDEF
5863 #define OS_TCGETPGRP_METHODDEF
5864#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
5865
5866#ifndef OS_TCSETPGRP_METHODDEF
5867 #define OS_TCSETPGRP_METHODDEF
5868#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
5869
5870#ifndef OS_LOCKF_METHODDEF
5871 #define OS_LOCKF_METHODDEF
5872#endif /* !defined(OS_LOCKF_METHODDEF) */
5873
5874#ifndef OS_READV_METHODDEF
5875 #define OS_READV_METHODDEF
5876#endif /* !defined(OS_READV_METHODDEF) */
5877
5878#ifndef OS_PREAD_METHODDEF
5879 #define OS_PREAD_METHODDEF
5880#endif /* !defined(OS_PREAD_METHODDEF) */
5881
5882#ifndef OS_PIPE_METHODDEF
5883 #define OS_PIPE_METHODDEF
5884#endif /* !defined(OS_PIPE_METHODDEF) */
5885
5886#ifndef OS_PIPE2_METHODDEF
5887 #define OS_PIPE2_METHODDEF
5888#endif /* !defined(OS_PIPE2_METHODDEF) */
5889
5890#ifndef OS_WRITEV_METHODDEF
5891 #define OS_WRITEV_METHODDEF
5892#endif /* !defined(OS_WRITEV_METHODDEF) */
5893
5894#ifndef OS_PWRITE_METHODDEF
5895 #define OS_PWRITE_METHODDEF
5896#endif /* !defined(OS_PWRITE_METHODDEF) */
5897
5898#ifndef OS_MKFIFO_METHODDEF
5899 #define OS_MKFIFO_METHODDEF
5900#endif /* !defined(OS_MKFIFO_METHODDEF) */
5901
5902#ifndef OS_MKNOD_METHODDEF
5903 #define OS_MKNOD_METHODDEF
5904#endif /* !defined(OS_MKNOD_METHODDEF) */
5905
5906#ifndef OS_MAJOR_METHODDEF
5907 #define OS_MAJOR_METHODDEF
5908#endif /* !defined(OS_MAJOR_METHODDEF) */
5909
5910#ifndef OS_MINOR_METHODDEF
5911 #define OS_MINOR_METHODDEF
5912#endif /* !defined(OS_MINOR_METHODDEF) */
5913
5914#ifndef OS_MAKEDEV_METHODDEF
5915 #define OS_MAKEDEV_METHODDEF
5916#endif /* !defined(OS_MAKEDEV_METHODDEF) */
5917
5918#ifndef OS_FTRUNCATE_METHODDEF
5919 #define OS_FTRUNCATE_METHODDEF
5920#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
5921
5922#ifndef OS_TRUNCATE_METHODDEF
5923 #define OS_TRUNCATE_METHODDEF
5924#endif /* !defined(OS_TRUNCATE_METHODDEF) */
5925
5926#ifndef OS_POSIX_FALLOCATE_METHODDEF
5927 #define OS_POSIX_FALLOCATE_METHODDEF
5928#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
5929
5930#ifndef OS_POSIX_FADVISE_METHODDEF
5931 #define OS_POSIX_FADVISE_METHODDEF
5932#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
5933
5934#ifndef OS_PUTENV_METHODDEF
5935 #define OS_PUTENV_METHODDEF
5936#endif /* !defined(OS_PUTENV_METHODDEF) */
5937
5938#ifndef OS_UNSETENV_METHODDEF
5939 #define OS_UNSETENV_METHODDEF
5940#endif /* !defined(OS_UNSETENV_METHODDEF) */
5941
5942#ifndef OS_WCOREDUMP_METHODDEF
5943 #define OS_WCOREDUMP_METHODDEF
5944#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
5945
5946#ifndef OS_WIFCONTINUED_METHODDEF
5947 #define OS_WIFCONTINUED_METHODDEF
5948#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
5949
5950#ifndef OS_WIFSTOPPED_METHODDEF
5951 #define OS_WIFSTOPPED_METHODDEF
5952#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
5953
5954#ifndef OS_WIFSIGNALED_METHODDEF
5955 #define OS_WIFSIGNALED_METHODDEF
5956#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
5957
5958#ifndef OS_WIFEXITED_METHODDEF
5959 #define OS_WIFEXITED_METHODDEF
5960#endif /* !defined(OS_WIFEXITED_METHODDEF) */
5961
5962#ifndef OS_WEXITSTATUS_METHODDEF
5963 #define OS_WEXITSTATUS_METHODDEF
5964#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
5965
5966#ifndef OS_WTERMSIG_METHODDEF
5967 #define OS_WTERMSIG_METHODDEF
5968#endif /* !defined(OS_WTERMSIG_METHODDEF) */
5969
5970#ifndef OS_WSTOPSIG_METHODDEF
5971 #define OS_WSTOPSIG_METHODDEF
5972#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
5973
5974#ifndef OS_FSTATVFS_METHODDEF
5975 #define OS_FSTATVFS_METHODDEF
5976#endif /* !defined(OS_FSTATVFS_METHODDEF) */
5977
5978#ifndef OS_STATVFS_METHODDEF
5979 #define OS_STATVFS_METHODDEF
5980#endif /* !defined(OS_STATVFS_METHODDEF) */
5981
5982#ifndef OS__GETDISKUSAGE_METHODDEF
5983 #define OS__GETDISKUSAGE_METHODDEF
5984#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
5985
5986#ifndef OS_FPATHCONF_METHODDEF
5987 #define OS_FPATHCONF_METHODDEF
5988#endif /* !defined(OS_FPATHCONF_METHODDEF) */
5989
5990#ifndef OS_PATHCONF_METHODDEF
5991 #define OS_PATHCONF_METHODDEF
5992#endif /* !defined(OS_PATHCONF_METHODDEF) */
5993
5994#ifndef OS_CONFSTR_METHODDEF
5995 #define OS_CONFSTR_METHODDEF
5996#endif /* !defined(OS_CONFSTR_METHODDEF) */
5997
5998#ifndef OS_SYSCONF_METHODDEF
5999 #define OS_SYSCONF_METHODDEF
6000#endif /* !defined(OS_SYSCONF_METHODDEF) */
6001
6002#ifndef OS_GETLOADAVG_METHODDEF
6003 #define OS_GETLOADAVG_METHODDEF
6004#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6005
6006#ifndef OS_SETRESUID_METHODDEF
6007 #define OS_SETRESUID_METHODDEF
6008#endif /* !defined(OS_SETRESUID_METHODDEF) */
6009
6010#ifndef OS_SETRESGID_METHODDEF
6011 #define OS_SETRESGID_METHODDEF
6012#endif /* !defined(OS_SETRESGID_METHODDEF) */
6013
6014#ifndef OS_GETRESUID_METHODDEF
6015 #define OS_GETRESUID_METHODDEF
6016#endif /* !defined(OS_GETRESUID_METHODDEF) */
6017
6018#ifndef OS_GETRESGID_METHODDEF
6019 #define OS_GETRESGID_METHODDEF
6020#endif /* !defined(OS_GETRESGID_METHODDEF) */
6021
6022#ifndef OS_GETXATTR_METHODDEF
6023 #define OS_GETXATTR_METHODDEF
6024#endif /* !defined(OS_GETXATTR_METHODDEF) */
6025
6026#ifndef OS_SETXATTR_METHODDEF
6027 #define OS_SETXATTR_METHODDEF
6028#endif /* !defined(OS_SETXATTR_METHODDEF) */
6029
6030#ifndef OS_REMOVEXATTR_METHODDEF
6031 #define OS_REMOVEXATTR_METHODDEF
6032#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6033
6034#ifndef OS_LISTXATTR_METHODDEF
6035 #define OS_LISTXATTR_METHODDEF
6036#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6037
6038#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6039 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6040#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6041
6042#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6043 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6044#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006045/*[clinic end generated code: output=97180b6734421a7d input=a9049054013a1b77]*/