/src/cpython/Modules/clinic/posixmodule.c.h
Line | Count | Source |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6 | | # include "pycore_gc.h" // PyGC_Head |
7 | | # include "pycore_runtime.h" // _Py_ID() |
8 | | #endif |
9 | | #include "pycore_abstract.h" // _PyNumber_Index() |
10 | | #include "pycore_fileutils.h" // _Py_Off_t_Converter() |
11 | | #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() |
12 | | #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
13 | | #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() |
14 | | |
15 | | PyDoc_STRVAR(os_stat__doc__, |
16 | | "stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n" |
17 | | "--\n" |
18 | | "\n" |
19 | | "Perform a stat system call on the given path.\n" |
20 | | "\n" |
21 | | " path\n" |
22 | | " Path to be examined; can be string, bytes, a path-like object or\n" |
23 | | " open-file-descriptor int.\n" |
24 | | " dir_fd\n" |
25 | | " If not None, it should be a file descriptor open to a directory,\n" |
26 | | " and path should be a relative string; path will then be relative to\n" |
27 | | " that directory.\n" |
28 | | " follow_symlinks\n" |
29 | | " If False, and the last element of the path is a symbolic link,\n" |
30 | | " stat will examine the symbolic link itself instead of the file\n" |
31 | | " the link points to.\n" |
32 | | "\n" |
33 | | "dir_fd and follow_symlinks may not be implemented\n" |
34 | | " on your platform. If they are unavailable, using them will raise a\n" |
35 | | " NotImplementedError.\n" |
36 | | "\n" |
37 | | "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n" |
38 | | " an open file descriptor."); |
39 | | |
40 | | #define OS_STAT_METHODDEF \ |
41 | | {"stat", _PyCFunction_CAST(os_stat), METH_FASTCALL|METH_KEYWORDS, os_stat__doc__}, |
42 | | |
43 | | static PyObject * |
44 | | os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks); |
45 | | |
46 | | static PyObject * |
47 | | os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
48 | 233k | { |
49 | 233k | PyObject *return_value = NULL; |
50 | 233k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
51 | | |
52 | 233k | #define NUM_KEYWORDS 3 |
53 | 233k | static struct { |
54 | 233k | PyGC_Head _this_is_not_used; |
55 | 233k | PyObject_VAR_HEAD |
56 | 233k | Py_hash_t ob_hash; |
57 | 233k | PyObject *ob_item[NUM_KEYWORDS]; |
58 | 233k | } _kwtuple = { |
59 | 233k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
60 | 233k | .ob_hash = -1, |
61 | 233k | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
62 | 233k | }; |
63 | 233k | #undef NUM_KEYWORDS |
64 | 233k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
65 | | |
66 | | #else // !Py_BUILD_CORE |
67 | | # define KWTUPLE NULL |
68 | | #endif // !Py_BUILD_CORE |
69 | | |
70 | 233k | static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; |
71 | 233k | static _PyArg_Parser _parser = { |
72 | 233k | .keywords = _keywords, |
73 | 233k | .fname = "stat", |
74 | 233k | .kwtuple = KWTUPLE, |
75 | 233k | }; |
76 | 233k | #undef KWTUPLE |
77 | 233k | PyObject *argsbuf[3]; |
78 | 233k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
79 | 233k | path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1); |
80 | 233k | int dir_fd = DEFAULT_DIR_FD; |
81 | 233k | int follow_symlinks = 1; |
82 | | |
83 | 233k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
84 | 233k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
85 | 233k | if (!args) { |
86 | 0 | goto exit; |
87 | 0 | } |
88 | 233k | if (!path_converter(args[0], &path)) { |
89 | 0 | goto exit; |
90 | 0 | } |
91 | 233k | if (!noptargs) { |
92 | 233k | goto skip_optional_kwonly; |
93 | 233k | } |
94 | 0 | if (args[1]) { |
95 | 0 | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
96 | 0 | goto exit; |
97 | 0 | } |
98 | 0 | if (!--noptargs) { |
99 | 0 | goto skip_optional_kwonly; |
100 | 0 | } |
101 | 0 | } |
102 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
103 | 0 | if (follow_symlinks < 0) { |
104 | 0 | goto exit; |
105 | 0 | } |
106 | 233k | skip_optional_kwonly: |
107 | 233k | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
108 | | |
109 | 233k | exit: |
110 | | /* Cleanup for path */ |
111 | 233k | path_cleanup(&path); |
112 | | |
113 | 233k | return return_value; |
114 | 233k | } |
115 | | |
116 | | PyDoc_STRVAR(os_lstat__doc__, |
117 | | "lstat($module, /, path, *, dir_fd=None)\n" |
118 | | "--\n" |
119 | | "\n" |
120 | | "Perform a stat system call on the given path, without following symbolic links.\n" |
121 | | "\n" |
122 | | "Like stat(), but do not follow symbolic links.\n" |
123 | | "Equivalent to stat(path, follow_symlinks=False)."); |
124 | | |
125 | | #define OS_LSTAT_METHODDEF \ |
126 | | {"lstat", _PyCFunction_CAST(os_lstat), METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__}, |
127 | | |
128 | | static PyObject * |
129 | | os_lstat_impl(PyObject *module, path_t *path, int dir_fd); |
130 | | |
131 | | static PyObject * |
132 | | os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
133 | 11.2k | { |
134 | 11.2k | PyObject *return_value = NULL; |
135 | 11.2k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
136 | | |
137 | 11.2k | #define NUM_KEYWORDS 2 |
138 | 11.2k | static struct { |
139 | 11.2k | PyGC_Head _this_is_not_used; |
140 | 11.2k | PyObject_VAR_HEAD |
141 | 11.2k | Py_hash_t ob_hash; |
142 | 11.2k | PyObject *ob_item[NUM_KEYWORDS]; |
143 | 11.2k | } _kwtuple = { |
144 | 11.2k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
145 | 11.2k | .ob_hash = -1, |
146 | 11.2k | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
147 | 11.2k | }; |
148 | 11.2k | #undef NUM_KEYWORDS |
149 | 11.2k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
150 | | |
151 | | #else // !Py_BUILD_CORE |
152 | | # define KWTUPLE NULL |
153 | | #endif // !Py_BUILD_CORE |
154 | | |
155 | 11.2k | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
156 | 11.2k | static _PyArg_Parser _parser = { |
157 | 11.2k | .keywords = _keywords, |
158 | 11.2k | .fname = "lstat", |
159 | 11.2k | .kwtuple = KWTUPLE, |
160 | 11.2k | }; |
161 | 11.2k | #undef KWTUPLE |
162 | 11.2k | PyObject *argsbuf[2]; |
163 | 11.2k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
164 | 11.2k | path_t path = PATH_T_INITIALIZE_P("lstat", "path", 0, 0, 0, 0); |
165 | 11.2k | int dir_fd = DEFAULT_DIR_FD; |
166 | | |
167 | 11.2k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
168 | 11.2k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
169 | 11.2k | if (!args) { |
170 | 0 | goto exit; |
171 | 0 | } |
172 | 11.2k | if (!path_converter(args[0], &path)) { |
173 | 0 | goto exit; |
174 | 0 | } |
175 | 11.2k | if (!noptargs) { |
176 | 3.00k | goto skip_optional_kwonly; |
177 | 3.00k | } |
178 | 8.21k | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
179 | 0 | goto exit; |
180 | 0 | } |
181 | 11.2k | skip_optional_kwonly: |
182 | 11.2k | return_value = os_lstat_impl(module, &path, dir_fd); |
183 | | |
184 | 11.2k | exit: |
185 | | /* Cleanup for path */ |
186 | 11.2k | path_cleanup(&path); |
187 | | |
188 | 11.2k | return return_value; |
189 | 11.2k | } |
190 | | |
191 | | #if defined(HAVE_STATX) |
192 | | |
193 | | PyDoc_STRVAR(os_statx__doc__, |
194 | | "statx($module, /, path, mask, *, flags=0, dir_fd=None,\n" |
195 | | " follow_symlinks=True)\n" |
196 | | "--\n" |
197 | | "\n" |
198 | | "Perform a statx system call on the given path.\n" |
199 | | "\n" |
200 | | " path\n" |
201 | | " Path to be examined; can be string, bytes, a path-like object or\n" |
202 | | " open-file-descriptor int.\n" |
203 | | " mask\n" |
204 | | " A bitmask of STATX_* constants defining the requested information.\n" |
205 | | " flags\n" |
206 | | " A bitmask of AT_NO_AUTOMOUNT and/or AT_STATX_* flags.\n" |
207 | | " dir_fd\n" |
208 | | " If not None, it should be a file descriptor open to a directory,\n" |
209 | | " and path should be a relative string; path will then be relative to\n" |
210 | | " that directory.\n" |
211 | | " follow_symlinks\n" |
212 | | " If False, and the last element of the path is a symbolic link,\n" |
213 | | " statx will examine the symbolic link itself instead of the file\n" |
214 | | " the link points to.\n" |
215 | | "\n" |
216 | | "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n" |
217 | | " an open file descriptor."); |
218 | | |
219 | | #define OS_STATX_METHODDEF \ |
220 | | {"statx", _PyCFunction_CAST(os_statx), METH_FASTCALL|METH_KEYWORDS, os_statx__doc__}, |
221 | | |
222 | | static PyObject * |
223 | | os_statx_impl(PyObject *module, path_t *path, unsigned int mask, int flags, |
224 | | int dir_fd, int follow_symlinks); |
225 | | |
226 | | static PyObject * |
227 | | os_statx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
228 | 0 | { |
229 | 0 | PyObject *return_value = NULL; |
230 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
231 | |
|
232 | 0 | #define NUM_KEYWORDS 5 |
233 | 0 | static struct { |
234 | 0 | PyGC_Head _this_is_not_used; |
235 | 0 | PyObject_VAR_HEAD |
236 | 0 | Py_hash_t ob_hash; |
237 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
238 | 0 | } _kwtuple = { |
239 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
240 | 0 | .ob_hash = -1, |
241 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mask), &_Py_ID(flags), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
242 | 0 | }; |
243 | 0 | #undef NUM_KEYWORDS |
244 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
245 | |
|
246 | | #else // !Py_BUILD_CORE |
247 | | # define KWTUPLE NULL |
248 | | #endif // !Py_BUILD_CORE |
249 | |
|
250 | 0 | static const char * const _keywords[] = {"path", "mask", "flags", "dir_fd", "follow_symlinks", NULL}; |
251 | 0 | static _PyArg_Parser _parser = { |
252 | 0 | .keywords = _keywords, |
253 | 0 | .fname = "statx", |
254 | 0 | .kwtuple = KWTUPLE, |
255 | 0 | }; |
256 | 0 | #undef KWTUPLE |
257 | 0 | PyObject *argsbuf[5]; |
258 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
259 | 0 | path_t path = PATH_T_INITIALIZE_P("statx", "path", 0, 0, 0, 1); |
260 | 0 | unsigned int mask; |
261 | 0 | int flags = 0; |
262 | 0 | int dir_fd = DEFAULT_DIR_FD; |
263 | 0 | int follow_symlinks = 1; |
264 | |
|
265 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
266 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
267 | 0 | if (!args) { |
268 | 0 | goto exit; |
269 | 0 | } |
270 | 0 | if (!path_converter(args[0], &path)) { |
271 | 0 | goto exit; |
272 | 0 | } |
273 | 0 | { |
274 | 0 | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &mask, sizeof(unsigned int), |
275 | 0 | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
276 | 0 | Py_ASNATIVEBYTES_ALLOW_INDEX | |
277 | 0 | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
278 | 0 | if (_bytes < 0) { |
279 | 0 | goto exit; |
280 | 0 | } |
281 | 0 | if ((size_t)_bytes > sizeof(unsigned int)) { |
282 | 0 | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
283 | 0 | "integer value out of range", 1) < 0) |
284 | 0 | { |
285 | 0 | goto exit; |
286 | 0 | } |
287 | 0 | } |
288 | 0 | } |
289 | 0 | if (!noptargs) { |
290 | 0 | goto skip_optional_kwonly; |
291 | 0 | } |
292 | 0 | if (args[2]) { |
293 | 0 | flags = PyLong_AsInt(args[2]); |
294 | 0 | if (flags == -1 && PyErr_Occurred()) { |
295 | 0 | goto exit; |
296 | 0 | } |
297 | 0 | if (!--noptargs) { |
298 | 0 | goto skip_optional_kwonly; |
299 | 0 | } |
300 | 0 | } |
301 | 0 | if (args[3]) { |
302 | 0 | if (!dir_fd_converter(args[3], &dir_fd)) { |
303 | 0 | goto exit; |
304 | 0 | } |
305 | 0 | if (!--noptargs) { |
306 | 0 | goto skip_optional_kwonly; |
307 | 0 | } |
308 | 0 | } |
309 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
310 | 0 | if (follow_symlinks < 0) { |
311 | 0 | goto exit; |
312 | 0 | } |
313 | 0 | skip_optional_kwonly: |
314 | 0 | return_value = os_statx_impl(module, &path, mask, flags, dir_fd, follow_symlinks); |
315 | |
|
316 | 0 | exit: |
317 | | /* Cleanup for path */ |
318 | 0 | path_cleanup(&path); |
319 | |
|
320 | 0 | return return_value; |
321 | 0 | } |
322 | | |
323 | | #endif /* defined(HAVE_STATX) */ |
324 | | |
325 | | PyDoc_STRVAR(os_access__doc__, |
326 | | "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n" |
327 | | " follow_symlinks=True)\n" |
328 | | "--\n" |
329 | | "\n" |
330 | | "Use the real uid/gid to test for access to a path.\n" |
331 | | "\n" |
332 | | " path\n" |
333 | | " Path to be tested; can be string, bytes, or a path-like object.\n" |
334 | | " mode\n" |
335 | | " Operating-system mode bitfield. Can be F_OK to test existence,\n" |
336 | | " or the inclusive-OR of R_OK, W_OK, and X_OK.\n" |
337 | | " dir_fd\n" |
338 | | " If not None, it should be a file descriptor open to a directory,\n" |
339 | | " and path should be relative; path will then be relative to that\n" |
340 | | " directory.\n" |
341 | | " effective_ids\n" |
342 | | " If True, access will use the effective uid/gid instead of\n" |
343 | | " the real uid/gid.\n" |
344 | | " follow_symlinks\n" |
345 | | " If False, and the last element of the path is a symbolic link,\n" |
346 | | " access will examine the symbolic link itself instead of the file\n" |
347 | | " the link points to.\n" |
348 | | "\n" |
349 | | "dir_fd, effective_ids, and follow_symlinks may not be implemented\n" |
350 | | " on your platform. If they are unavailable, using them will raise a\n" |
351 | | " NotImplementedError.\n" |
352 | | "\n" |
353 | | "Note that most operations will use the effective uid/gid, therefore this\n" |
354 | | " routine can be used in a suid/sgid environment to test if the invoking\n" |
355 | | " user has the specified access to the path."); |
356 | | |
357 | | #define OS_ACCESS_METHODDEF \ |
358 | | {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__}, |
359 | | |
360 | | static int |
361 | | os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
362 | | int effective_ids, int follow_symlinks); |
363 | | |
364 | | static PyObject * |
365 | | os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
366 | 0 | { |
367 | 0 | PyObject *return_value = NULL; |
368 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
369 | |
|
370 | 0 | #define NUM_KEYWORDS 5 |
371 | 0 | static struct { |
372 | 0 | PyGC_Head _this_is_not_used; |
373 | 0 | PyObject_VAR_HEAD |
374 | 0 | Py_hash_t ob_hash; |
375 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
376 | 0 | } _kwtuple = { |
377 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
378 | 0 | .ob_hash = -1, |
379 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), }, |
380 | 0 | }; |
381 | 0 | #undef NUM_KEYWORDS |
382 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
383 | |
|
384 | | #else // !Py_BUILD_CORE |
385 | | # define KWTUPLE NULL |
386 | | #endif // !Py_BUILD_CORE |
387 | |
|
388 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL}; |
389 | 0 | static _PyArg_Parser _parser = { |
390 | 0 | .keywords = _keywords, |
391 | 0 | .fname = "access", |
392 | 0 | .kwtuple = KWTUPLE, |
393 | 0 | }; |
394 | 0 | #undef KWTUPLE |
395 | 0 | PyObject *argsbuf[5]; |
396 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
397 | 0 | path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0); |
398 | 0 | int mode; |
399 | 0 | int dir_fd = DEFAULT_DIR_FD; |
400 | 0 | int effective_ids = 0; |
401 | 0 | int follow_symlinks = 1; |
402 | 0 | int _return_value; |
403 | |
|
404 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
405 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
406 | 0 | if (!args) { |
407 | 0 | goto exit; |
408 | 0 | } |
409 | 0 | if (!path_converter(args[0], &path)) { |
410 | 0 | goto exit; |
411 | 0 | } |
412 | 0 | mode = PyLong_AsInt(args[1]); |
413 | 0 | if (mode == -1 && PyErr_Occurred()) { |
414 | 0 | goto exit; |
415 | 0 | } |
416 | 0 | if (!noptargs) { |
417 | 0 | goto skip_optional_kwonly; |
418 | 0 | } |
419 | 0 | if (args[2]) { |
420 | 0 | if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
421 | 0 | goto exit; |
422 | 0 | } |
423 | 0 | if (!--noptargs) { |
424 | 0 | goto skip_optional_kwonly; |
425 | 0 | } |
426 | 0 | } |
427 | 0 | if (args[3]) { |
428 | 0 | effective_ids = PyObject_IsTrue(args[3]); |
429 | 0 | if (effective_ids < 0) { |
430 | 0 | goto exit; |
431 | 0 | } |
432 | 0 | if (!--noptargs) { |
433 | 0 | goto skip_optional_kwonly; |
434 | 0 | } |
435 | 0 | } |
436 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
437 | 0 | if (follow_symlinks < 0) { |
438 | 0 | goto exit; |
439 | 0 | } |
440 | 0 | skip_optional_kwonly: |
441 | 0 | _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks); |
442 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
443 | 0 | goto exit; |
444 | 0 | } |
445 | 0 | return_value = PyBool_FromLong((long)_return_value); |
446 | |
|
447 | 0 | exit: |
448 | | /* Cleanup for path */ |
449 | 0 | path_cleanup(&path); |
450 | |
|
451 | 0 | return return_value; |
452 | 0 | } |
453 | | |
454 | | #if defined(HAVE_TTYNAME_R) |
455 | | |
456 | | PyDoc_STRVAR(os_ttyname__doc__, |
457 | | "ttyname($module, fd, /)\n" |
458 | | "--\n" |
459 | | "\n" |
460 | | "Return the name of the terminal device connected to \'fd\'.\n" |
461 | | "\n" |
462 | | " fd\n" |
463 | | " Integer file descriptor handle."); |
464 | | |
465 | | #define OS_TTYNAME_METHODDEF \ |
466 | | {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__}, |
467 | | |
468 | | static PyObject * |
469 | | os_ttyname_impl(PyObject *module, int fd); |
470 | | |
471 | | static PyObject * |
472 | | os_ttyname(PyObject *module, PyObject *arg) |
473 | 0 | { |
474 | 0 | PyObject *return_value = NULL; |
475 | 0 | int fd; |
476 | |
|
477 | 0 | fd = PyLong_AsInt(arg); |
478 | 0 | if (fd == -1 && PyErr_Occurred()) { |
479 | 0 | goto exit; |
480 | 0 | } |
481 | 0 | return_value = os_ttyname_impl(module, fd); |
482 | |
|
483 | 0 | exit: |
484 | 0 | return return_value; |
485 | 0 | } |
486 | | |
487 | | #endif /* defined(HAVE_TTYNAME_R) */ |
488 | | |
489 | | #if defined(HAVE_CTERMID) |
490 | | |
491 | | PyDoc_STRVAR(os_ctermid__doc__, |
492 | | "ctermid($module, /)\n" |
493 | | "--\n" |
494 | | "\n" |
495 | | "Return the name of the controlling terminal for this process."); |
496 | | |
497 | | #define OS_CTERMID_METHODDEF \ |
498 | | {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, |
499 | | |
500 | | static PyObject * |
501 | | os_ctermid_impl(PyObject *module); |
502 | | |
503 | | static PyObject * |
504 | | os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
505 | 0 | { |
506 | 0 | return os_ctermid_impl(module); |
507 | 0 | } |
508 | | |
509 | | #endif /* defined(HAVE_CTERMID) */ |
510 | | |
511 | | PyDoc_STRVAR(os_chdir__doc__, |
512 | | "chdir($module, /, path)\n" |
513 | | "--\n" |
514 | | "\n" |
515 | | "Change the current working directory to the specified path.\n" |
516 | | "\n" |
517 | | "path may always be specified as a string. On some platforms, path may\n" |
518 | | "also be specified as an open file descriptor. If this functionality is\n" |
519 | | "unavailable, using it raises an exception."); |
520 | | |
521 | | #define OS_CHDIR_METHODDEF \ |
522 | | {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__}, |
523 | | |
524 | | static PyObject * |
525 | | os_chdir_impl(PyObject *module, path_t *path); |
526 | | |
527 | | static PyObject * |
528 | | os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
529 | 0 | { |
530 | 0 | PyObject *return_value = NULL; |
531 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
532 | |
|
533 | 0 | #define NUM_KEYWORDS 1 |
534 | 0 | static struct { |
535 | 0 | PyGC_Head _this_is_not_used; |
536 | 0 | PyObject_VAR_HEAD |
537 | 0 | Py_hash_t ob_hash; |
538 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
539 | 0 | } _kwtuple = { |
540 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
541 | 0 | .ob_hash = -1, |
542 | 0 | .ob_item = { &_Py_ID(path), }, |
543 | 0 | }; |
544 | 0 | #undef NUM_KEYWORDS |
545 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
546 | |
|
547 | | #else // !Py_BUILD_CORE |
548 | | # define KWTUPLE NULL |
549 | | #endif // !Py_BUILD_CORE |
550 | |
|
551 | 0 | static const char * const _keywords[] = {"path", NULL}; |
552 | 0 | static _PyArg_Parser _parser = { |
553 | 0 | .keywords = _keywords, |
554 | 0 | .fname = "chdir", |
555 | 0 | .kwtuple = KWTUPLE, |
556 | 0 | }; |
557 | 0 | #undef KWTUPLE |
558 | 0 | PyObject *argsbuf[1]; |
559 | 0 | path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR); |
560 | |
|
561 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
562 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
563 | 0 | if (!args) { |
564 | 0 | goto exit; |
565 | 0 | } |
566 | 0 | if (!path_converter(args[0], &path)) { |
567 | 0 | goto exit; |
568 | 0 | } |
569 | 0 | return_value = os_chdir_impl(module, &path); |
570 | |
|
571 | 0 | exit: |
572 | | /* Cleanup for path */ |
573 | 0 | path_cleanup(&path); |
574 | |
|
575 | 0 | return return_value; |
576 | 0 | } |
577 | | |
578 | | #if defined(HAVE_FCHDIR) |
579 | | |
580 | | PyDoc_STRVAR(os_fchdir__doc__, |
581 | | "fchdir($module, /, fd)\n" |
582 | | "--\n" |
583 | | "\n" |
584 | | "Change to the directory of the given file descriptor.\n" |
585 | | "\n" |
586 | | "fd must be opened on a directory, not a file.\n" |
587 | | "Equivalent to os.chdir(fd)."); |
588 | | |
589 | | #define OS_FCHDIR_METHODDEF \ |
590 | | {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__}, |
591 | | |
592 | | static PyObject * |
593 | | os_fchdir_impl(PyObject *module, int fd); |
594 | | |
595 | | static PyObject * |
596 | | os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
597 | 0 | { |
598 | 0 | PyObject *return_value = NULL; |
599 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
600 | |
|
601 | 0 | #define NUM_KEYWORDS 1 |
602 | 0 | static struct { |
603 | 0 | PyGC_Head _this_is_not_used; |
604 | 0 | PyObject_VAR_HEAD |
605 | 0 | Py_hash_t ob_hash; |
606 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
607 | 0 | } _kwtuple = { |
608 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
609 | 0 | .ob_hash = -1, |
610 | 0 | .ob_item = { &_Py_ID(fd), }, |
611 | 0 | }; |
612 | 0 | #undef NUM_KEYWORDS |
613 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
614 | |
|
615 | | #else // !Py_BUILD_CORE |
616 | | # define KWTUPLE NULL |
617 | | #endif // !Py_BUILD_CORE |
618 | |
|
619 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
620 | 0 | static _PyArg_Parser _parser = { |
621 | 0 | .keywords = _keywords, |
622 | 0 | .fname = "fchdir", |
623 | 0 | .kwtuple = KWTUPLE, |
624 | 0 | }; |
625 | 0 | #undef KWTUPLE |
626 | 0 | PyObject *argsbuf[1]; |
627 | 0 | int fd; |
628 | |
|
629 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
630 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
631 | 0 | if (!args) { |
632 | 0 | goto exit; |
633 | 0 | } |
634 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
635 | 0 | if (fd < 0) { |
636 | 0 | goto exit; |
637 | 0 | } |
638 | 0 | return_value = os_fchdir_impl(module, fd); |
639 | |
|
640 | 0 | exit: |
641 | 0 | return return_value; |
642 | 0 | } |
643 | | |
644 | | #endif /* defined(HAVE_FCHDIR) */ |
645 | | |
646 | | PyDoc_STRVAR(os_chmod__doc__, |
647 | | "chmod($module, /, path, mode, *, dir_fd=None,\n" |
648 | | " follow_symlinks=(os.name != \'nt\'))\n" |
649 | | "--\n" |
650 | | "\n" |
651 | | "Change the access permissions of a file.\n" |
652 | | "\n" |
653 | | " path\n" |
654 | | " Path to be modified. May always be specified as a str, bytes, or\n" |
655 | | " a path-like object. On some platforms, path may also be specified\n" |
656 | | " as an open file descriptor. If this functionality is unavailable,\n" |
657 | | " using it raises an exception.\n" |
658 | | " mode\n" |
659 | | " Operating-system mode bitfield.\n" |
660 | | " Be careful when using number literals for *mode*. The conventional\n" |
661 | | " UNIX notation for numeric modes uses an octal base, which needs to\n" |
662 | | " be indicated with a ``0o`` prefix in Python.\n" |
663 | | " dir_fd\n" |
664 | | " If not None, it should be a file descriptor open to a directory,\n" |
665 | | " and path should be relative; path will then be relative to that\n" |
666 | | " directory.\n" |
667 | | " follow_symlinks\n" |
668 | | " If False, and the last element of the path is a symbolic link,\n" |
669 | | " chmod will modify the symbolic link itself instead of the file\n" |
670 | | " the link points to.\n" |
671 | | "\n" |
672 | | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
673 | | " an open file descriptor.\n" |
674 | | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
675 | | " If they are unavailable, using them will raise a NotImplementedError."); |
676 | | |
677 | | #define OS_CHMOD_METHODDEF \ |
678 | | {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__}, |
679 | | |
680 | | static PyObject * |
681 | | os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
682 | | int follow_symlinks); |
683 | | |
684 | | static PyObject * |
685 | | os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
686 | 0 | { |
687 | 0 | PyObject *return_value = NULL; |
688 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
689 | |
|
690 | 0 | #define NUM_KEYWORDS 4 |
691 | 0 | static struct { |
692 | 0 | PyGC_Head _this_is_not_used; |
693 | 0 | PyObject_VAR_HEAD |
694 | 0 | Py_hash_t ob_hash; |
695 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
696 | 0 | } _kwtuple = { |
697 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
698 | 0 | .ob_hash = -1, |
699 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
700 | 0 | }; |
701 | 0 | #undef NUM_KEYWORDS |
702 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
703 | |
|
704 | | #else // !Py_BUILD_CORE |
705 | | # define KWTUPLE NULL |
706 | | #endif // !Py_BUILD_CORE |
707 | |
|
708 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL}; |
709 | 0 | static _PyArg_Parser _parser = { |
710 | 0 | .keywords = _keywords, |
711 | 0 | .fname = "chmod", |
712 | 0 | .kwtuple = KWTUPLE, |
713 | 0 | }; |
714 | 0 | #undef KWTUPLE |
715 | 0 | PyObject *argsbuf[4]; |
716 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
717 | 0 | path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD); |
718 | 0 | int mode; |
719 | 0 | int dir_fd = DEFAULT_DIR_FD; |
720 | 0 | int follow_symlinks = CHMOD_DEFAULT_FOLLOW_SYMLINKS; |
721 | |
|
722 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
723 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
724 | 0 | if (!args) { |
725 | 0 | goto exit; |
726 | 0 | } |
727 | 0 | if (!path_converter(args[0], &path)) { |
728 | 0 | goto exit; |
729 | 0 | } |
730 | 0 | mode = PyLong_AsInt(args[1]); |
731 | 0 | if (mode == -1 && PyErr_Occurred()) { |
732 | 0 | goto exit; |
733 | 0 | } |
734 | 0 | if (!noptargs) { |
735 | 0 | goto skip_optional_kwonly; |
736 | 0 | } |
737 | 0 | if (args[2]) { |
738 | 0 | if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
739 | 0 | goto exit; |
740 | 0 | } |
741 | 0 | if (!--noptargs) { |
742 | 0 | goto skip_optional_kwonly; |
743 | 0 | } |
744 | 0 | } |
745 | 0 | follow_symlinks = PyObject_IsTrue(args[3]); |
746 | 0 | if (follow_symlinks < 0) { |
747 | 0 | goto exit; |
748 | 0 | } |
749 | 0 | skip_optional_kwonly: |
750 | 0 | return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); |
751 | |
|
752 | 0 | exit: |
753 | | /* Cleanup for path */ |
754 | 0 | path_cleanup(&path); |
755 | |
|
756 | 0 | return return_value; |
757 | 0 | } |
758 | | |
759 | | #if (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) |
760 | | |
761 | | PyDoc_STRVAR(os_fchmod__doc__, |
762 | | "fchmod($module, /, fd, mode)\n" |
763 | | "--\n" |
764 | | "\n" |
765 | | "Change the access permissions of the file given by file descriptor fd.\n" |
766 | | "\n" |
767 | | " fd\n" |
768 | | " The file descriptor of the file to be modified.\n" |
769 | | " mode\n" |
770 | | " Operating-system mode bitfield.\n" |
771 | | " Be careful when using number literals for *mode*. The conventional\n" |
772 | | " UNIX notation for numeric modes uses an octal base, which needs to\n" |
773 | | " be indicated with a ``0o`` prefix in Python.\n" |
774 | | "\n" |
775 | | "Equivalent to os.chmod(fd, mode)."); |
776 | | |
777 | | #define OS_FCHMOD_METHODDEF \ |
778 | | {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__}, |
779 | | |
780 | | static PyObject * |
781 | | os_fchmod_impl(PyObject *module, int fd, int mode); |
782 | | |
783 | | static PyObject * |
784 | | os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
785 | 0 | { |
786 | 0 | PyObject *return_value = NULL; |
787 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
788 | |
|
789 | 0 | #define NUM_KEYWORDS 2 |
790 | 0 | static struct { |
791 | 0 | PyGC_Head _this_is_not_used; |
792 | 0 | PyObject_VAR_HEAD |
793 | 0 | Py_hash_t ob_hash; |
794 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
795 | 0 | } _kwtuple = { |
796 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
797 | 0 | .ob_hash = -1, |
798 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(mode), }, |
799 | 0 | }; |
800 | 0 | #undef NUM_KEYWORDS |
801 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
802 | |
|
803 | | #else // !Py_BUILD_CORE |
804 | | # define KWTUPLE NULL |
805 | | #endif // !Py_BUILD_CORE |
806 | |
|
807 | 0 | static const char * const _keywords[] = {"fd", "mode", NULL}; |
808 | 0 | static _PyArg_Parser _parser = { |
809 | 0 | .keywords = _keywords, |
810 | 0 | .fname = "fchmod", |
811 | 0 | .kwtuple = KWTUPLE, |
812 | 0 | }; |
813 | 0 | #undef KWTUPLE |
814 | 0 | PyObject *argsbuf[2]; |
815 | 0 | int fd; |
816 | 0 | int mode; |
817 | |
|
818 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
819 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
820 | 0 | if (!args) { |
821 | 0 | goto exit; |
822 | 0 | } |
823 | 0 | fd = PyLong_AsInt(args[0]); |
824 | 0 | if (fd == -1 && PyErr_Occurred()) { |
825 | 0 | goto exit; |
826 | 0 | } |
827 | 0 | mode = PyLong_AsInt(args[1]); |
828 | 0 | if (mode == -1 && PyErr_Occurred()) { |
829 | 0 | goto exit; |
830 | 0 | } |
831 | 0 | return_value = os_fchmod_impl(module, fd, mode); |
832 | |
|
833 | 0 | exit: |
834 | 0 | return return_value; |
835 | 0 | } |
836 | | |
837 | | #endif /* (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) */ |
838 | | |
839 | | #if (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) |
840 | | |
841 | | PyDoc_STRVAR(os_lchmod__doc__, |
842 | | "lchmod($module, /, path, mode)\n" |
843 | | "--\n" |
844 | | "\n" |
845 | | "Change the access permissions of a file, without following symbolic links.\n" |
846 | | "\n" |
847 | | "If path is a symlink, this affects the link itself rather than the\n" |
848 | | "target. Equivalent to chmod(path, mode, follow_symlinks=False)."); |
849 | | |
850 | | #define OS_LCHMOD_METHODDEF \ |
851 | | {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__}, |
852 | | |
853 | | static PyObject * |
854 | | os_lchmod_impl(PyObject *module, path_t *path, int mode); |
855 | | |
856 | | static PyObject * |
857 | | os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
858 | | { |
859 | | PyObject *return_value = NULL; |
860 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
861 | | |
862 | | #define NUM_KEYWORDS 2 |
863 | | static struct { |
864 | | PyGC_Head _this_is_not_used; |
865 | | PyObject_VAR_HEAD |
866 | | Py_hash_t ob_hash; |
867 | | PyObject *ob_item[NUM_KEYWORDS]; |
868 | | } _kwtuple = { |
869 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
870 | | .ob_hash = -1, |
871 | | .ob_item = { &_Py_ID(path), &_Py_ID(mode), }, |
872 | | }; |
873 | | #undef NUM_KEYWORDS |
874 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
875 | | |
876 | | #else // !Py_BUILD_CORE |
877 | | # define KWTUPLE NULL |
878 | | #endif // !Py_BUILD_CORE |
879 | | |
880 | | static const char * const _keywords[] = {"path", "mode", NULL}; |
881 | | static _PyArg_Parser _parser = { |
882 | | .keywords = _keywords, |
883 | | .fname = "lchmod", |
884 | | .kwtuple = KWTUPLE, |
885 | | }; |
886 | | #undef KWTUPLE |
887 | | PyObject *argsbuf[2]; |
888 | | path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0); |
889 | | int mode; |
890 | | |
891 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
892 | | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
893 | | if (!args) { |
894 | | goto exit; |
895 | | } |
896 | | if (!path_converter(args[0], &path)) { |
897 | | goto exit; |
898 | | } |
899 | | mode = PyLong_AsInt(args[1]); |
900 | | if (mode == -1 && PyErr_Occurred()) { |
901 | | goto exit; |
902 | | } |
903 | | return_value = os_lchmod_impl(module, &path, mode); |
904 | | |
905 | | exit: |
906 | | /* Cleanup for path */ |
907 | | path_cleanup(&path); |
908 | | |
909 | | return return_value; |
910 | | } |
911 | | |
912 | | #endif /* (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) */ |
913 | | |
914 | | #if defined(HAVE_CHFLAGS) |
915 | | |
916 | | PyDoc_STRVAR(os_chflags__doc__, |
917 | | "chflags($module, /, path, flags, follow_symlinks=True)\n" |
918 | | "--\n" |
919 | | "\n" |
920 | | "Set file flags.\n" |
921 | | "\n" |
922 | | "If follow_symlinks is False, and the last element of the path is\n" |
923 | | "a symbolic link, chflags() will change flags on the symbolic link itself\n" |
924 | | "instead of the file the link points to.\n" |
925 | | "follow_symlinks may not be implemented on your platform. If it is\n" |
926 | | "unavailable, using it will raise a NotImplementedError."); |
927 | | |
928 | | #define OS_CHFLAGS_METHODDEF \ |
929 | | {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__}, |
930 | | |
931 | | static PyObject * |
932 | | os_chflags_impl(PyObject *module, path_t *path, unsigned long flags, |
933 | | int follow_symlinks); |
934 | | |
935 | | static PyObject * |
936 | | os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
937 | | { |
938 | | PyObject *return_value = NULL; |
939 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
940 | | |
941 | | #define NUM_KEYWORDS 3 |
942 | | static struct { |
943 | | PyGC_Head _this_is_not_used; |
944 | | PyObject_VAR_HEAD |
945 | | Py_hash_t ob_hash; |
946 | | PyObject *ob_item[NUM_KEYWORDS]; |
947 | | } _kwtuple = { |
948 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
949 | | .ob_hash = -1, |
950 | | .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), }, |
951 | | }; |
952 | | #undef NUM_KEYWORDS |
953 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
954 | | |
955 | | #else // !Py_BUILD_CORE |
956 | | # define KWTUPLE NULL |
957 | | #endif // !Py_BUILD_CORE |
958 | | |
959 | | static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL}; |
960 | | static _PyArg_Parser _parser = { |
961 | | .keywords = _keywords, |
962 | | .fname = "chflags", |
963 | | .kwtuple = KWTUPLE, |
964 | | }; |
965 | | #undef KWTUPLE |
966 | | PyObject *argsbuf[3]; |
967 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
968 | | path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0); |
969 | | unsigned long flags; |
970 | | int follow_symlinks = 1; |
971 | | |
972 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
973 | | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
974 | | if (!args) { |
975 | | goto exit; |
976 | | } |
977 | | if (!path_converter(args[0], &path)) { |
978 | | goto exit; |
979 | | } |
980 | | if (!PyIndex_Check(args[1])) { |
981 | | _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]); |
982 | | goto exit; |
983 | | } |
984 | | { |
985 | | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long), |
986 | | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
987 | | Py_ASNATIVEBYTES_ALLOW_INDEX | |
988 | | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
989 | | if (_bytes < 0) { |
990 | | goto exit; |
991 | | } |
992 | | if ((size_t)_bytes > sizeof(unsigned long)) { |
993 | | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
994 | | "integer value out of range", 1) < 0) |
995 | | { |
996 | | goto exit; |
997 | | } |
998 | | } |
999 | | } |
1000 | | if (!noptargs) { |
1001 | | goto skip_optional_pos; |
1002 | | } |
1003 | | follow_symlinks = PyObject_IsTrue(args[2]); |
1004 | | if (follow_symlinks < 0) { |
1005 | | goto exit; |
1006 | | } |
1007 | | skip_optional_pos: |
1008 | | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
1009 | | |
1010 | | exit: |
1011 | | /* Cleanup for path */ |
1012 | | path_cleanup(&path); |
1013 | | |
1014 | | return return_value; |
1015 | | } |
1016 | | |
1017 | | #endif /* defined(HAVE_CHFLAGS) */ |
1018 | | |
1019 | | #if defined(HAVE_LCHFLAGS) |
1020 | | |
1021 | | PyDoc_STRVAR(os_lchflags__doc__, |
1022 | | "lchflags($module, /, path, flags)\n" |
1023 | | "--\n" |
1024 | | "\n" |
1025 | | "Set file flags.\n" |
1026 | | "\n" |
1027 | | "This function will not follow symbolic links.\n" |
1028 | | "Equivalent to chflags(path, flags, follow_symlinks=False)."); |
1029 | | |
1030 | | #define OS_LCHFLAGS_METHODDEF \ |
1031 | | {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__}, |
1032 | | |
1033 | | static PyObject * |
1034 | | os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags); |
1035 | | |
1036 | | static PyObject * |
1037 | | os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1038 | | { |
1039 | | PyObject *return_value = NULL; |
1040 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1041 | | |
1042 | | #define NUM_KEYWORDS 2 |
1043 | | static struct { |
1044 | | PyGC_Head _this_is_not_used; |
1045 | | PyObject_VAR_HEAD |
1046 | | Py_hash_t ob_hash; |
1047 | | PyObject *ob_item[NUM_KEYWORDS]; |
1048 | | } _kwtuple = { |
1049 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1050 | | .ob_hash = -1, |
1051 | | .ob_item = { &_Py_ID(path), &_Py_ID(flags), }, |
1052 | | }; |
1053 | | #undef NUM_KEYWORDS |
1054 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1055 | | |
1056 | | #else // !Py_BUILD_CORE |
1057 | | # define KWTUPLE NULL |
1058 | | #endif // !Py_BUILD_CORE |
1059 | | |
1060 | | static const char * const _keywords[] = {"path", "flags", NULL}; |
1061 | | static _PyArg_Parser _parser = { |
1062 | | .keywords = _keywords, |
1063 | | .fname = "lchflags", |
1064 | | .kwtuple = KWTUPLE, |
1065 | | }; |
1066 | | #undef KWTUPLE |
1067 | | PyObject *argsbuf[2]; |
1068 | | path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0); |
1069 | | unsigned long flags; |
1070 | | |
1071 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1072 | | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1073 | | if (!args) { |
1074 | | goto exit; |
1075 | | } |
1076 | | if (!path_converter(args[0], &path)) { |
1077 | | goto exit; |
1078 | | } |
1079 | | if (!PyIndex_Check(args[1])) { |
1080 | | _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]); |
1081 | | goto exit; |
1082 | | } |
1083 | | { |
1084 | | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long), |
1085 | | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
1086 | | Py_ASNATIVEBYTES_ALLOW_INDEX | |
1087 | | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
1088 | | if (_bytes < 0) { |
1089 | | goto exit; |
1090 | | } |
1091 | | if ((size_t)_bytes > sizeof(unsigned long)) { |
1092 | | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
1093 | | "integer value out of range", 1) < 0) |
1094 | | { |
1095 | | goto exit; |
1096 | | } |
1097 | | } |
1098 | | } |
1099 | | return_value = os_lchflags_impl(module, &path, flags); |
1100 | | |
1101 | | exit: |
1102 | | /* Cleanup for path */ |
1103 | | path_cleanup(&path); |
1104 | | |
1105 | | return return_value; |
1106 | | } |
1107 | | |
1108 | | #endif /* defined(HAVE_LCHFLAGS) */ |
1109 | | |
1110 | | #if defined(HAVE_CHROOT) |
1111 | | |
1112 | | PyDoc_STRVAR(os_chroot__doc__, |
1113 | | "chroot($module, /, path)\n" |
1114 | | "--\n" |
1115 | | "\n" |
1116 | | "Change root directory to path."); |
1117 | | |
1118 | | #define OS_CHROOT_METHODDEF \ |
1119 | | {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__}, |
1120 | | |
1121 | | static PyObject * |
1122 | | os_chroot_impl(PyObject *module, path_t *path); |
1123 | | |
1124 | | static PyObject * |
1125 | | os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1126 | 0 | { |
1127 | 0 | PyObject *return_value = NULL; |
1128 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1129 | |
|
1130 | 0 | #define NUM_KEYWORDS 1 |
1131 | 0 | static struct { |
1132 | 0 | PyGC_Head _this_is_not_used; |
1133 | 0 | PyObject_VAR_HEAD |
1134 | 0 | Py_hash_t ob_hash; |
1135 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1136 | 0 | } _kwtuple = { |
1137 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1138 | 0 | .ob_hash = -1, |
1139 | 0 | .ob_item = { &_Py_ID(path), }, |
1140 | 0 | }; |
1141 | 0 | #undef NUM_KEYWORDS |
1142 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1143 | |
|
1144 | | #else // !Py_BUILD_CORE |
1145 | | # define KWTUPLE NULL |
1146 | | #endif // !Py_BUILD_CORE |
1147 | |
|
1148 | 0 | static const char * const _keywords[] = {"path", NULL}; |
1149 | 0 | static _PyArg_Parser _parser = { |
1150 | 0 | .keywords = _keywords, |
1151 | 0 | .fname = "chroot", |
1152 | 0 | .kwtuple = KWTUPLE, |
1153 | 0 | }; |
1154 | 0 | #undef KWTUPLE |
1155 | 0 | PyObject *argsbuf[1]; |
1156 | 0 | path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0); |
1157 | |
|
1158 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1159 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1160 | 0 | if (!args) { |
1161 | 0 | goto exit; |
1162 | 0 | } |
1163 | 0 | if (!path_converter(args[0], &path)) { |
1164 | 0 | goto exit; |
1165 | 0 | } |
1166 | 0 | return_value = os_chroot_impl(module, &path); |
1167 | |
|
1168 | 0 | exit: |
1169 | | /* Cleanup for path */ |
1170 | 0 | path_cleanup(&path); |
1171 | |
|
1172 | 0 | return return_value; |
1173 | 0 | } |
1174 | | |
1175 | | #endif /* defined(HAVE_CHROOT) */ |
1176 | | |
1177 | | #if defined(HAVE_FSYNC) |
1178 | | |
1179 | | PyDoc_STRVAR(os_fsync__doc__, |
1180 | | "fsync($module, /, fd)\n" |
1181 | | "--\n" |
1182 | | "\n" |
1183 | | "Force write of fd to disk."); |
1184 | | |
1185 | | #define OS_FSYNC_METHODDEF \ |
1186 | | {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__}, |
1187 | | |
1188 | | static PyObject * |
1189 | | os_fsync_impl(PyObject *module, int fd); |
1190 | | |
1191 | | static PyObject * |
1192 | | os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1193 | 0 | { |
1194 | 0 | PyObject *return_value = NULL; |
1195 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1196 | |
|
1197 | 0 | #define NUM_KEYWORDS 1 |
1198 | 0 | static struct { |
1199 | 0 | PyGC_Head _this_is_not_used; |
1200 | 0 | PyObject_VAR_HEAD |
1201 | 0 | Py_hash_t ob_hash; |
1202 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1203 | 0 | } _kwtuple = { |
1204 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1205 | 0 | .ob_hash = -1, |
1206 | 0 | .ob_item = { &_Py_ID(fd), }, |
1207 | 0 | }; |
1208 | 0 | #undef NUM_KEYWORDS |
1209 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1210 | |
|
1211 | | #else // !Py_BUILD_CORE |
1212 | | # define KWTUPLE NULL |
1213 | | #endif // !Py_BUILD_CORE |
1214 | |
|
1215 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
1216 | 0 | static _PyArg_Parser _parser = { |
1217 | 0 | .keywords = _keywords, |
1218 | 0 | .fname = "fsync", |
1219 | 0 | .kwtuple = KWTUPLE, |
1220 | 0 | }; |
1221 | 0 | #undef KWTUPLE |
1222 | 0 | PyObject *argsbuf[1]; |
1223 | 0 | int fd; |
1224 | |
|
1225 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1226 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1227 | 0 | if (!args) { |
1228 | 0 | goto exit; |
1229 | 0 | } |
1230 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
1231 | 0 | if (fd < 0) { |
1232 | 0 | goto exit; |
1233 | 0 | } |
1234 | 0 | return_value = os_fsync_impl(module, fd); |
1235 | |
|
1236 | 0 | exit: |
1237 | 0 | return return_value; |
1238 | 0 | } |
1239 | | |
1240 | | #endif /* defined(HAVE_FSYNC) */ |
1241 | | |
1242 | | #if defined(HAVE_SYNC) |
1243 | | |
1244 | | PyDoc_STRVAR(os_sync__doc__, |
1245 | | "sync($module, /)\n" |
1246 | | "--\n" |
1247 | | "\n" |
1248 | | "Force write of everything to disk."); |
1249 | | |
1250 | | #define OS_SYNC_METHODDEF \ |
1251 | | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
1252 | | |
1253 | | static PyObject * |
1254 | | os_sync_impl(PyObject *module); |
1255 | | |
1256 | | static PyObject * |
1257 | | os_sync(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1258 | 0 | { |
1259 | 0 | return os_sync_impl(module); |
1260 | 0 | } |
1261 | | |
1262 | | #endif /* defined(HAVE_SYNC) */ |
1263 | | |
1264 | | #if defined(HAVE_FDATASYNC) |
1265 | | |
1266 | | PyDoc_STRVAR(os_fdatasync__doc__, |
1267 | | "fdatasync($module, /, fd)\n" |
1268 | | "--\n" |
1269 | | "\n" |
1270 | | "Force write of fd to disk without forcing update of metadata."); |
1271 | | |
1272 | | #define OS_FDATASYNC_METHODDEF \ |
1273 | | {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__}, |
1274 | | |
1275 | | static PyObject * |
1276 | | os_fdatasync_impl(PyObject *module, int fd); |
1277 | | |
1278 | | static PyObject * |
1279 | | os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1280 | 0 | { |
1281 | 0 | PyObject *return_value = NULL; |
1282 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1283 | |
|
1284 | 0 | #define NUM_KEYWORDS 1 |
1285 | 0 | static struct { |
1286 | 0 | PyGC_Head _this_is_not_used; |
1287 | 0 | PyObject_VAR_HEAD |
1288 | 0 | Py_hash_t ob_hash; |
1289 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1290 | 0 | } _kwtuple = { |
1291 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1292 | 0 | .ob_hash = -1, |
1293 | 0 | .ob_item = { &_Py_ID(fd), }, |
1294 | 0 | }; |
1295 | 0 | #undef NUM_KEYWORDS |
1296 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1297 | |
|
1298 | | #else // !Py_BUILD_CORE |
1299 | | # define KWTUPLE NULL |
1300 | | #endif // !Py_BUILD_CORE |
1301 | |
|
1302 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
1303 | 0 | static _PyArg_Parser _parser = { |
1304 | 0 | .keywords = _keywords, |
1305 | 0 | .fname = "fdatasync", |
1306 | 0 | .kwtuple = KWTUPLE, |
1307 | 0 | }; |
1308 | 0 | #undef KWTUPLE |
1309 | 0 | PyObject *argsbuf[1]; |
1310 | 0 | int fd; |
1311 | |
|
1312 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1313 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1314 | 0 | if (!args) { |
1315 | 0 | goto exit; |
1316 | 0 | } |
1317 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
1318 | 0 | if (fd < 0) { |
1319 | 0 | goto exit; |
1320 | 0 | } |
1321 | 0 | return_value = os_fdatasync_impl(module, fd); |
1322 | |
|
1323 | 0 | exit: |
1324 | 0 | return return_value; |
1325 | 0 | } |
1326 | | |
1327 | | #endif /* defined(HAVE_FDATASYNC) */ |
1328 | | |
1329 | | #if defined(HAVE_CHOWN) |
1330 | | |
1331 | | PyDoc_STRVAR(os_chown__doc__, |
1332 | | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
1333 | | "--\n" |
1334 | | "\n" |
1335 | | "Change the owner and group id of path to the numeric uid and gid.\n" |
1336 | | "\n" |
1337 | | " path\n" |
1338 | | " Path to be examined; can be string, bytes, a path-like object, or\n" |
1339 | | " open-file-descriptor int.\n" |
1340 | | " dir_fd\n" |
1341 | | " If not None, it should be a file descriptor open to a directory,\n" |
1342 | | " and path should be relative; path will then be relative to that\n" |
1343 | | " directory.\n" |
1344 | | " follow_symlinks\n" |
1345 | | " If False, and the last element of the path is a symbolic link,\n" |
1346 | | " stat will examine the symbolic link itself instead of the file\n" |
1347 | | " the link points to.\n" |
1348 | | "\n" |
1349 | | "path may always be specified as a string. On some platforms, path may\n" |
1350 | | "also be specified as an open file descriptor. If this functionality is\n" |
1351 | | "unavailable, using it raises an exception.\n" |
1352 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
1353 | | "a directory, and path should be relative; path will then be relative to\n" |
1354 | | "that directory.\n" |
1355 | | "If follow_symlinks is False, and the last element of the path is\n" |
1356 | | "a symbolic link, chown will modify the symbolic link itself instead of\n" |
1357 | | "the file the link points to.\n" |
1358 | | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
1359 | | "an open file descriptor.\n" |
1360 | | "dir_fd and follow_symlinks may not be implemented on your platform. If\n" |
1361 | | "they are unavailable, using them will raise a NotImplementedError."); |
1362 | | |
1363 | | #define OS_CHOWN_METHODDEF \ |
1364 | | {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__}, |
1365 | | |
1366 | | static PyObject * |
1367 | | os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid, |
1368 | | int dir_fd, int follow_symlinks); |
1369 | | |
1370 | | static PyObject * |
1371 | | os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1372 | 0 | { |
1373 | 0 | PyObject *return_value = NULL; |
1374 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1375 | |
|
1376 | 0 | #define NUM_KEYWORDS 5 |
1377 | 0 | static struct { |
1378 | 0 | PyGC_Head _this_is_not_used; |
1379 | 0 | PyObject_VAR_HEAD |
1380 | 0 | Py_hash_t ob_hash; |
1381 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1382 | 0 | } _kwtuple = { |
1383 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1384 | 0 | .ob_hash = -1, |
1385 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
1386 | 0 | }; |
1387 | 0 | #undef NUM_KEYWORDS |
1388 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1389 | |
|
1390 | | #else // !Py_BUILD_CORE |
1391 | | # define KWTUPLE NULL |
1392 | | #endif // !Py_BUILD_CORE |
1393 | |
|
1394 | 0 | static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; |
1395 | 0 | static _PyArg_Parser _parser = { |
1396 | 0 | .keywords = _keywords, |
1397 | 0 | .fname = "chown", |
1398 | 0 | .kwtuple = KWTUPLE, |
1399 | 0 | }; |
1400 | 0 | #undef KWTUPLE |
1401 | 0 | PyObject *argsbuf[5]; |
1402 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
1403 | 0 | path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN); |
1404 | 0 | uid_t uid; |
1405 | 0 | gid_t gid; |
1406 | 0 | int dir_fd = DEFAULT_DIR_FD; |
1407 | 0 | int follow_symlinks = 1; |
1408 | |
|
1409 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1410 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1411 | 0 | if (!args) { |
1412 | 0 | goto exit; |
1413 | 0 | } |
1414 | 0 | if (!path_converter(args[0], &path)) { |
1415 | 0 | goto exit; |
1416 | 0 | } |
1417 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1418 | 0 | goto exit; |
1419 | 0 | } |
1420 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1421 | 0 | goto exit; |
1422 | 0 | } |
1423 | 0 | if (!noptargs) { |
1424 | 0 | goto skip_optional_kwonly; |
1425 | 0 | } |
1426 | 0 | if (args[3]) { |
1427 | 0 | if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
1428 | 0 | goto exit; |
1429 | 0 | } |
1430 | 0 | if (!--noptargs) { |
1431 | 0 | goto skip_optional_kwonly; |
1432 | 0 | } |
1433 | 0 | } |
1434 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
1435 | 0 | if (follow_symlinks < 0) { |
1436 | 0 | goto exit; |
1437 | 0 | } |
1438 | 0 | skip_optional_kwonly: |
1439 | 0 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
1440 | |
|
1441 | 0 | exit: |
1442 | | /* Cleanup for path */ |
1443 | 0 | path_cleanup(&path); |
1444 | |
|
1445 | 0 | return return_value; |
1446 | 0 | } |
1447 | | |
1448 | | #endif /* defined(HAVE_CHOWN) */ |
1449 | | |
1450 | | #if defined(HAVE_FCHOWN) |
1451 | | |
1452 | | PyDoc_STRVAR(os_fchown__doc__, |
1453 | | "fchown($module, /, fd, uid, gid)\n" |
1454 | | "--\n" |
1455 | | "\n" |
1456 | | "Change the owner and group id of the file specified by file descriptor.\n" |
1457 | | "\n" |
1458 | | "Equivalent to os.chown(fd, uid, gid)."); |
1459 | | |
1460 | | #define OS_FCHOWN_METHODDEF \ |
1461 | | {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__}, |
1462 | | |
1463 | | static PyObject * |
1464 | | os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid); |
1465 | | |
1466 | | static PyObject * |
1467 | | os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1468 | 0 | { |
1469 | 0 | PyObject *return_value = NULL; |
1470 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1471 | |
|
1472 | 0 | #define NUM_KEYWORDS 3 |
1473 | 0 | static struct { |
1474 | 0 | PyGC_Head _this_is_not_used; |
1475 | 0 | PyObject_VAR_HEAD |
1476 | 0 | Py_hash_t ob_hash; |
1477 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1478 | 0 | } _kwtuple = { |
1479 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1480 | 0 | .ob_hash = -1, |
1481 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), }, |
1482 | 0 | }; |
1483 | 0 | #undef NUM_KEYWORDS |
1484 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1485 | |
|
1486 | | #else // !Py_BUILD_CORE |
1487 | | # define KWTUPLE NULL |
1488 | | #endif // !Py_BUILD_CORE |
1489 | |
|
1490 | 0 | static const char * const _keywords[] = {"fd", "uid", "gid", NULL}; |
1491 | 0 | static _PyArg_Parser _parser = { |
1492 | 0 | .keywords = _keywords, |
1493 | 0 | .fname = "fchown", |
1494 | 0 | .kwtuple = KWTUPLE, |
1495 | 0 | }; |
1496 | 0 | #undef KWTUPLE |
1497 | 0 | PyObject *argsbuf[3]; |
1498 | 0 | int fd; |
1499 | 0 | uid_t uid; |
1500 | 0 | gid_t gid; |
1501 | |
|
1502 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1503 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1504 | 0 | if (!args) { |
1505 | 0 | goto exit; |
1506 | 0 | } |
1507 | 0 | fd = PyLong_AsInt(args[0]); |
1508 | 0 | if (fd == -1 && PyErr_Occurred()) { |
1509 | 0 | goto exit; |
1510 | 0 | } |
1511 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1512 | 0 | goto exit; |
1513 | 0 | } |
1514 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1515 | 0 | goto exit; |
1516 | 0 | } |
1517 | 0 | return_value = os_fchown_impl(module, fd, uid, gid); |
1518 | |
|
1519 | 0 | exit: |
1520 | 0 | return return_value; |
1521 | 0 | } |
1522 | | |
1523 | | #endif /* defined(HAVE_FCHOWN) */ |
1524 | | |
1525 | | #if defined(HAVE_LCHOWN) |
1526 | | |
1527 | | PyDoc_STRVAR(os_lchown__doc__, |
1528 | | "lchown($module, /, path, uid, gid)\n" |
1529 | | "--\n" |
1530 | | "\n" |
1531 | | "Change the owner and group id of path to the numeric uid and gid.\n" |
1532 | | "\n" |
1533 | | "This function will not follow symbolic links.\n" |
1534 | | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); |
1535 | | |
1536 | | #define OS_LCHOWN_METHODDEF \ |
1537 | | {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__}, |
1538 | | |
1539 | | static PyObject * |
1540 | | os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid); |
1541 | | |
1542 | | static PyObject * |
1543 | | os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1544 | 0 | { |
1545 | 0 | PyObject *return_value = NULL; |
1546 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1547 | |
|
1548 | 0 | #define NUM_KEYWORDS 3 |
1549 | 0 | static struct { |
1550 | 0 | PyGC_Head _this_is_not_used; |
1551 | 0 | PyObject_VAR_HEAD |
1552 | 0 | Py_hash_t ob_hash; |
1553 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1554 | 0 | } _kwtuple = { |
1555 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1556 | 0 | .ob_hash = -1, |
1557 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), }, |
1558 | 0 | }; |
1559 | 0 | #undef NUM_KEYWORDS |
1560 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1561 | |
|
1562 | | #else // !Py_BUILD_CORE |
1563 | | # define KWTUPLE NULL |
1564 | | #endif // !Py_BUILD_CORE |
1565 | |
|
1566 | 0 | static const char * const _keywords[] = {"path", "uid", "gid", NULL}; |
1567 | 0 | static _PyArg_Parser _parser = { |
1568 | 0 | .keywords = _keywords, |
1569 | 0 | .fname = "lchown", |
1570 | 0 | .kwtuple = KWTUPLE, |
1571 | 0 | }; |
1572 | 0 | #undef KWTUPLE |
1573 | 0 | PyObject *argsbuf[3]; |
1574 | 0 | path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0); |
1575 | 0 | uid_t uid; |
1576 | 0 | gid_t gid; |
1577 | |
|
1578 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1579 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1580 | 0 | if (!args) { |
1581 | 0 | goto exit; |
1582 | 0 | } |
1583 | 0 | if (!path_converter(args[0], &path)) { |
1584 | 0 | goto exit; |
1585 | 0 | } |
1586 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1587 | 0 | goto exit; |
1588 | 0 | } |
1589 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1590 | 0 | goto exit; |
1591 | 0 | } |
1592 | 0 | return_value = os_lchown_impl(module, &path, uid, gid); |
1593 | |
|
1594 | 0 | exit: |
1595 | | /* Cleanup for path */ |
1596 | 0 | path_cleanup(&path); |
1597 | |
|
1598 | 0 | return return_value; |
1599 | 0 | } |
1600 | | |
1601 | | #endif /* defined(HAVE_LCHOWN) */ |
1602 | | |
1603 | | PyDoc_STRVAR(os_getcwd__doc__, |
1604 | | "getcwd($module, /)\n" |
1605 | | "--\n" |
1606 | | "\n" |
1607 | | "Return a unicode string representing the current working directory."); |
1608 | | |
1609 | | #define OS_GETCWD_METHODDEF \ |
1610 | | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
1611 | | |
1612 | | static PyObject * |
1613 | | os_getcwd_impl(PyObject *module); |
1614 | | |
1615 | | static PyObject * |
1616 | | os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1617 | 8 | { |
1618 | 8 | return os_getcwd_impl(module); |
1619 | 8 | } |
1620 | | |
1621 | | PyDoc_STRVAR(os_getcwdb__doc__, |
1622 | | "getcwdb($module, /)\n" |
1623 | | "--\n" |
1624 | | "\n" |
1625 | | "Return a bytes string representing the current working directory."); |
1626 | | |
1627 | | #define OS_GETCWDB_METHODDEF \ |
1628 | | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
1629 | | |
1630 | | static PyObject * |
1631 | | os_getcwdb_impl(PyObject *module); |
1632 | | |
1633 | | static PyObject * |
1634 | | os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1635 | 0 | { |
1636 | 0 | return os_getcwdb_impl(module); |
1637 | 0 | } |
1638 | | |
1639 | | #if defined(HAVE_LINK) |
1640 | | |
1641 | | PyDoc_STRVAR(os_link__doc__, |
1642 | | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
1643 | | " follow_symlinks=(os.name != \'nt\'))\n" |
1644 | | "--\n" |
1645 | | "\n" |
1646 | | "Create a hard link to a file.\n" |
1647 | | "\n" |
1648 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
1649 | | "descriptor open to a directory, and the respective path string (src or\n" |
1650 | | "dst) should be relative; the path will then be relative to that\n" |
1651 | | "directory.\n" |
1652 | | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
1653 | | "link, link will create a link to the symbolic link itself instead of the\n" |
1654 | | "file the link points to.\n" |
1655 | | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on\n" |
1656 | | "your platform. If they are unavailable, using them will raise\n" |
1657 | | "a NotImplementedError."); |
1658 | | |
1659 | | #define OS_LINK_METHODDEF \ |
1660 | | {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__}, |
1661 | | |
1662 | | static PyObject * |
1663 | | os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
1664 | | int dst_dir_fd, int follow_symlinks); |
1665 | | |
1666 | | static PyObject * |
1667 | | os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1668 | 0 | { |
1669 | 0 | PyObject *return_value = NULL; |
1670 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1671 | |
|
1672 | 0 | #define NUM_KEYWORDS 5 |
1673 | 0 | static struct { |
1674 | 0 | PyGC_Head _this_is_not_used; |
1675 | 0 | PyObject_VAR_HEAD |
1676 | 0 | Py_hash_t ob_hash; |
1677 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1678 | 0 | } _kwtuple = { |
1679 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1680 | 0 | .ob_hash = -1, |
1681 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), }, |
1682 | 0 | }; |
1683 | 0 | #undef NUM_KEYWORDS |
1684 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1685 | |
|
1686 | | #else // !Py_BUILD_CORE |
1687 | | # define KWTUPLE NULL |
1688 | | #endif // !Py_BUILD_CORE |
1689 | |
|
1690 | 0 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; |
1691 | 0 | static _PyArg_Parser _parser = { |
1692 | 0 | .keywords = _keywords, |
1693 | 0 | .fname = "link", |
1694 | 0 | .kwtuple = KWTUPLE, |
1695 | 0 | }; |
1696 | 0 | #undef KWTUPLE |
1697 | 0 | PyObject *argsbuf[5]; |
1698 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
1699 | 0 | path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0); |
1700 | 0 | path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0); |
1701 | 0 | int src_dir_fd = DEFAULT_DIR_FD; |
1702 | 0 | int dst_dir_fd = DEFAULT_DIR_FD; |
1703 | 0 | int follow_symlinks = -1; |
1704 | |
|
1705 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1706 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1707 | 0 | if (!args) { |
1708 | 0 | goto exit; |
1709 | 0 | } |
1710 | 0 | if (!path_converter(args[0], &src)) { |
1711 | 0 | goto exit; |
1712 | 0 | } |
1713 | 0 | if (!path_converter(args[1], &dst)) { |
1714 | 0 | goto exit; |
1715 | 0 | } |
1716 | 0 | if (!noptargs) { |
1717 | 0 | goto skip_optional_kwonly; |
1718 | 0 | } |
1719 | 0 | if (args[2]) { |
1720 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
1721 | 0 | goto exit; |
1722 | 0 | } |
1723 | 0 | if (!--noptargs) { |
1724 | 0 | goto skip_optional_kwonly; |
1725 | 0 | } |
1726 | 0 | } |
1727 | 0 | if (args[3]) { |
1728 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
1729 | 0 | goto exit; |
1730 | 0 | } |
1731 | 0 | if (!--noptargs) { |
1732 | 0 | goto skip_optional_kwonly; |
1733 | 0 | } |
1734 | 0 | } |
1735 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
1736 | 0 | if (follow_symlinks < 0) { |
1737 | 0 | goto exit; |
1738 | 0 | } |
1739 | 0 | skip_optional_kwonly: |
1740 | 0 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
1741 | |
|
1742 | 0 | exit: |
1743 | | /* Cleanup for src */ |
1744 | 0 | path_cleanup(&src); |
1745 | | /* Cleanup for dst */ |
1746 | 0 | path_cleanup(&dst); |
1747 | |
|
1748 | 0 | return return_value; |
1749 | 0 | } |
1750 | | |
1751 | | #endif /* defined(HAVE_LINK) */ |
1752 | | |
1753 | | PyDoc_STRVAR(os_listdir__doc__, |
1754 | | "listdir($module, /, path=None)\n" |
1755 | | "--\n" |
1756 | | "\n" |
1757 | | "Return a list containing the names of the files in the directory.\n" |
1758 | | "\n" |
1759 | | "path can be specified as either str, bytes, or a path-like object. If\n" |
1760 | | "path is bytes, the filenames returned will also be bytes; in all other\n" |
1761 | | "circumstances the filenames returned will be str.\n" |
1762 | | "If path is None, uses the path=\'.\'.\n" |
1763 | | "On some platforms, path may also be specified as an open file\n" |
1764 | | "descriptor; the file descriptor must refer to a directory. If this\n" |
1765 | | "functionality is unavailable, using it raises NotImplementedError.\n" |
1766 | | "\n" |
1767 | | "The list is in arbitrary order. It does not include the special\n" |
1768 | | "entries \'.\' and \'..\' even if they are present in the directory."); |
1769 | | |
1770 | | #define OS_LISTDIR_METHODDEF \ |
1771 | | {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__}, |
1772 | | |
1773 | | static PyObject * |
1774 | | os_listdir_impl(PyObject *module, path_t *path); |
1775 | | |
1776 | | static PyObject * |
1777 | | os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1778 | 407 | { |
1779 | 407 | PyObject *return_value = NULL; |
1780 | 407 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1781 | | |
1782 | 407 | #define NUM_KEYWORDS 1 |
1783 | 407 | static struct { |
1784 | 407 | PyGC_Head _this_is_not_used; |
1785 | 407 | PyObject_VAR_HEAD |
1786 | 407 | Py_hash_t ob_hash; |
1787 | 407 | PyObject *ob_item[NUM_KEYWORDS]; |
1788 | 407 | } _kwtuple = { |
1789 | 407 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1790 | 407 | .ob_hash = -1, |
1791 | 407 | .ob_item = { &_Py_ID(path), }, |
1792 | 407 | }; |
1793 | 407 | #undef NUM_KEYWORDS |
1794 | 407 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1795 | | |
1796 | | #else // !Py_BUILD_CORE |
1797 | | # define KWTUPLE NULL |
1798 | | #endif // !Py_BUILD_CORE |
1799 | | |
1800 | 407 | static const char * const _keywords[] = {"path", NULL}; |
1801 | 407 | static _PyArg_Parser _parser = { |
1802 | 407 | .keywords = _keywords, |
1803 | 407 | .fname = "listdir", |
1804 | 407 | .kwtuple = KWTUPLE, |
1805 | 407 | }; |
1806 | 407 | #undef KWTUPLE |
1807 | 407 | PyObject *argsbuf[1]; |
1808 | 407 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1809 | 407 | path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
1810 | | |
1811 | 407 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1812 | 407 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1813 | 407 | if (!args) { |
1814 | 0 | goto exit; |
1815 | 0 | } |
1816 | 407 | if (!noptargs) { |
1817 | 0 | goto skip_optional_pos; |
1818 | 0 | } |
1819 | 407 | if (!path_converter(args[0], &path)) { |
1820 | 0 | goto exit; |
1821 | 0 | } |
1822 | 407 | skip_optional_pos: |
1823 | 407 | return_value = os_listdir_impl(module, &path); |
1824 | | |
1825 | 407 | exit: |
1826 | | /* Cleanup for path */ |
1827 | 407 | path_cleanup(&path); |
1828 | | |
1829 | 407 | return return_value; |
1830 | 407 | } |
1831 | | |
1832 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) |
1833 | | |
1834 | | PyDoc_STRVAR(os_listdrives__doc__, |
1835 | | "listdrives($module, /)\n" |
1836 | | "--\n" |
1837 | | "\n" |
1838 | | "Return a list containing the names of drives in the system.\n" |
1839 | | "\n" |
1840 | | "A drive name typically looks like \'C:\\\\\'."); |
1841 | | |
1842 | | #define OS_LISTDRIVES_METHODDEF \ |
1843 | | {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__}, |
1844 | | |
1845 | | static PyObject * |
1846 | | os_listdrives_impl(PyObject *module); |
1847 | | |
1848 | | static PyObject * |
1849 | | os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1850 | | { |
1851 | | return os_listdrives_impl(module); |
1852 | | } |
1853 | | |
1854 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ |
1855 | | |
1856 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) |
1857 | | |
1858 | | PyDoc_STRVAR(os_listvolumes__doc__, |
1859 | | "listvolumes($module, /)\n" |
1860 | | "--\n" |
1861 | | "\n" |
1862 | | "Return a list containing the volumes in the system.\n" |
1863 | | "\n" |
1864 | | "Volumes are typically represented as a GUID path."); |
1865 | | |
1866 | | #define OS_LISTVOLUMES_METHODDEF \ |
1867 | | {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__}, |
1868 | | |
1869 | | static PyObject * |
1870 | | os_listvolumes_impl(PyObject *module); |
1871 | | |
1872 | | static PyObject * |
1873 | | os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1874 | | { |
1875 | | return os_listvolumes_impl(module); |
1876 | | } |
1877 | | |
1878 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ |
1879 | | |
1880 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) |
1881 | | |
1882 | | PyDoc_STRVAR(os_listmounts__doc__, |
1883 | | "listmounts($module, /, volume)\n" |
1884 | | "--\n" |
1885 | | "\n" |
1886 | | "Return a list containing mount points for a particular volume.\n" |
1887 | | "\n" |
1888 | | "\'volume\' should be a GUID path as returned from os.listvolumes."); |
1889 | | |
1890 | | #define OS_LISTMOUNTS_METHODDEF \ |
1891 | | {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__}, |
1892 | | |
1893 | | static PyObject * |
1894 | | os_listmounts_impl(PyObject *module, path_t *volume); |
1895 | | |
1896 | | static PyObject * |
1897 | | os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1898 | | { |
1899 | | PyObject *return_value = NULL; |
1900 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1901 | | |
1902 | | #define NUM_KEYWORDS 1 |
1903 | | static struct { |
1904 | | PyGC_Head _this_is_not_used; |
1905 | | PyObject_VAR_HEAD |
1906 | | Py_hash_t ob_hash; |
1907 | | PyObject *ob_item[NUM_KEYWORDS]; |
1908 | | } _kwtuple = { |
1909 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1910 | | .ob_hash = -1, |
1911 | | .ob_item = { &_Py_ID(volume), }, |
1912 | | }; |
1913 | | #undef NUM_KEYWORDS |
1914 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1915 | | |
1916 | | #else // !Py_BUILD_CORE |
1917 | | # define KWTUPLE NULL |
1918 | | #endif // !Py_BUILD_CORE |
1919 | | |
1920 | | static const char * const _keywords[] = {"volume", NULL}; |
1921 | | static _PyArg_Parser _parser = { |
1922 | | .keywords = _keywords, |
1923 | | .fname = "listmounts", |
1924 | | .kwtuple = KWTUPLE, |
1925 | | }; |
1926 | | #undef KWTUPLE |
1927 | | PyObject *argsbuf[1]; |
1928 | | path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0); |
1929 | | |
1930 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1931 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1932 | | if (!args) { |
1933 | | goto exit; |
1934 | | } |
1935 | | if (!path_converter(args[0], &volume)) { |
1936 | | goto exit; |
1937 | | } |
1938 | | return_value = os_listmounts_impl(module, &volume); |
1939 | | |
1940 | | exit: |
1941 | | /* Cleanup for volume */ |
1942 | | path_cleanup(&volume); |
1943 | | |
1944 | | return return_value; |
1945 | | } |
1946 | | |
1947 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ |
1948 | | |
1949 | | #if defined(MS_WINDOWS) |
1950 | | |
1951 | | PyDoc_STRVAR(os__path_isdevdrive__doc__, |
1952 | | "_path_isdevdrive($module, /, path)\n" |
1953 | | "--\n" |
1954 | | "\n" |
1955 | | "Determines whether the specified path is on a Windows Dev Drive."); |
1956 | | |
1957 | | #define OS__PATH_ISDEVDRIVE_METHODDEF \ |
1958 | | {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__}, |
1959 | | |
1960 | | static PyObject * |
1961 | | os__path_isdevdrive_impl(PyObject *module, path_t *path); |
1962 | | |
1963 | | static PyObject * |
1964 | | os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1965 | | { |
1966 | | PyObject *return_value = NULL; |
1967 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1968 | | |
1969 | | #define NUM_KEYWORDS 1 |
1970 | | static struct { |
1971 | | PyGC_Head _this_is_not_used; |
1972 | | PyObject_VAR_HEAD |
1973 | | Py_hash_t ob_hash; |
1974 | | PyObject *ob_item[NUM_KEYWORDS]; |
1975 | | } _kwtuple = { |
1976 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1977 | | .ob_hash = -1, |
1978 | | .ob_item = { &_Py_ID(path), }, |
1979 | | }; |
1980 | | #undef NUM_KEYWORDS |
1981 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1982 | | |
1983 | | #else // !Py_BUILD_CORE |
1984 | | # define KWTUPLE NULL |
1985 | | #endif // !Py_BUILD_CORE |
1986 | | |
1987 | | static const char * const _keywords[] = {"path", NULL}; |
1988 | | static _PyArg_Parser _parser = { |
1989 | | .keywords = _keywords, |
1990 | | .fname = "_path_isdevdrive", |
1991 | | .kwtuple = KWTUPLE, |
1992 | | }; |
1993 | | #undef KWTUPLE |
1994 | | PyObject *argsbuf[1]; |
1995 | | path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0); |
1996 | | |
1997 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1998 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1999 | | if (!args) { |
2000 | | goto exit; |
2001 | | } |
2002 | | if (!path_converter(args[0], &path)) { |
2003 | | goto exit; |
2004 | | } |
2005 | | return_value = os__path_isdevdrive_impl(module, &path); |
2006 | | |
2007 | | exit: |
2008 | | /* Cleanup for path */ |
2009 | | path_cleanup(&path); |
2010 | | |
2011 | | return return_value; |
2012 | | } |
2013 | | |
2014 | | #endif /* defined(MS_WINDOWS) */ |
2015 | | |
2016 | | #if defined(MS_WINDOWS) |
2017 | | |
2018 | | PyDoc_STRVAR(os__getfullpathname__doc__, |
2019 | | "_getfullpathname($module, path, /)\n" |
2020 | | "--\n" |
2021 | | "\n"); |
2022 | | |
2023 | | #define OS__GETFULLPATHNAME_METHODDEF \ |
2024 | | {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__}, |
2025 | | |
2026 | | static PyObject * |
2027 | | os__getfullpathname_impl(PyObject *module, path_t *path); |
2028 | | |
2029 | | static PyObject * |
2030 | | os__getfullpathname(PyObject *module, PyObject *arg) |
2031 | | { |
2032 | | PyObject *return_value = NULL; |
2033 | | path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0); |
2034 | | |
2035 | | if (!path_converter(arg, &path)) { |
2036 | | goto exit; |
2037 | | } |
2038 | | return_value = os__getfullpathname_impl(module, &path); |
2039 | | |
2040 | | exit: |
2041 | | /* Cleanup for path */ |
2042 | | path_cleanup(&path); |
2043 | | |
2044 | | return return_value; |
2045 | | } |
2046 | | |
2047 | | #endif /* defined(MS_WINDOWS) */ |
2048 | | |
2049 | | #if defined(MS_WINDOWS) |
2050 | | |
2051 | | PyDoc_STRVAR(os__getfinalpathname__doc__, |
2052 | | "_getfinalpathname($module, path, /)\n" |
2053 | | "--\n" |
2054 | | "\n" |
2055 | | "A helper function for samepath on windows."); |
2056 | | |
2057 | | #define OS__GETFINALPATHNAME_METHODDEF \ |
2058 | | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
2059 | | |
2060 | | static PyObject * |
2061 | | os__getfinalpathname_impl(PyObject *module, path_t *path); |
2062 | | |
2063 | | static PyObject * |
2064 | | os__getfinalpathname(PyObject *module, PyObject *arg) |
2065 | | { |
2066 | | PyObject *return_value = NULL; |
2067 | | path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0); |
2068 | | |
2069 | | if (!path_converter(arg, &path)) { |
2070 | | goto exit; |
2071 | | } |
2072 | | return_value = os__getfinalpathname_impl(module, &path); |
2073 | | |
2074 | | exit: |
2075 | | /* Cleanup for path */ |
2076 | | path_cleanup(&path); |
2077 | | |
2078 | | return return_value; |
2079 | | } |
2080 | | |
2081 | | #endif /* defined(MS_WINDOWS) */ |
2082 | | |
2083 | | #if defined(MS_WINDOWS) |
2084 | | |
2085 | | PyDoc_STRVAR(os__findfirstfile__doc__, |
2086 | | "_findfirstfile($module, path, /)\n" |
2087 | | "--\n" |
2088 | | "\n" |
2089 | | "A function to get the real file name without accessing the file in Windows."); |
2090 | | |
2091 | | #define OS__FINDFIRSTFILE_METHODDEF \ |
2092 | | {"_findfirstfile", (PyCFunction)os__findfirstfile, METH_O, os__findfirstfile__doc__}, |
2093 | | |
2094 | | static PyObject * |
2095 | | os__findfirstfile_impl(PyObject *module, path_t *path); |
2096 | | |
2097 | | static PyObject * |
2098 | | os__findfirstfile(PyObject *module, PyObject *arg) |
2099 | | { |
2100 | | PyObject *return_value = NULL; |
2101 | | path_t path = PATH_T_INITIALIZE_P("_findfirstfile", "path", 0, 0, 0, 0); |
2102 | | |
2103 | | if (!path_converter(arg, &path)) { |
2104 | | goto exit; |
2105 | | } |
2106 | | return_value = os__findfirstfile_impl(module, &path); |
2107 | | |
2108 | | exit: |
2109 | | /* Cleanup for path */ |
2110 | | path_cleanup(&path); |
2111 | | |
2112 | | return return_value; |
2113 | | } |
2114 | | |
2115 | | #endif /* defined(MS_WINDOWS) */ |
2116 | | |
2117 | | #if defined(MS_WINDOWS) |
2118 | | |
2119 | | PyDoc_STRVAR(os__getvolumepathname__doc__, |
2120 | | "_getvolumepathname($module, /, path)\n" |
2121 | | "--\n" |
2122 | | "\n" |
2123 | | "A helper function for ismount on Win32."); |
2124 | | |
2125 | | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
2126 | | {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__}, |
2127 | | |
2128 | | static PyObject * |
2129 | | os__getvolumepathname_impl(PyObject *module, path_t *path); |
2130 | | |
2131 | | static PyObject * |
2132 | | os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2133 | | { |
2134 | | PyObject *return_value = NULL; |
2135 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2136 | | |
2137 | | #define NUM_KEYWORDS 1 |
2138 | | static struct { |
2139 | | PyGC_Head _this_is_not_used; |
2140 | | PyObject_VAR_HEAD |
2141 | | Py_hash_t ob_hash; |
2142 | | PyObject *ob_item[NUM_KEYWORDS]; |
2143 | | } _kwtuple = { |
2144 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2145 | | .ob_hash = -1, |
2146 | | .ob_item = { &_Py_ID(path), }, |
2147 | | }; |
2148 | | #undef NUM_KEYWORDS |
2149 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2150 | | |
2151 | | #else // !Py_BUILD_CORE |
2152 | | # define KWTUPLE NULL |
2153 | | #endif // !Py_BUILD_CORE |
2154 | | |
2155 | | static const char * const _keywords[] = {"path", NULL}; |
2156 | | static _PyArg_Parser _parser = { |
2157 | | .keywords = _keywords, |
2158 | | .fname = "_getvolumepathname", |
2159 | | .kwtuple = KWTUPLE, |
2160 | | }; |
2161 | | #undef KWTUPLE |
2162 | | PyObject *argsbuf[1]; |
2163 | | path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0); |
2164 | | |
2165 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2166 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2167 | | if (!args) { |
2168 | | goto exit; |
2169 | | } |
2170 | | if (!path_converter(args[0], &path)) { |
2171 | | goto exit; |
2172 | | } |
2173 | | return_value = os__getvolumepathname_impl(module, &path); |
2174 | | |
2175 | | exit: |
2176 | | /* Cleanup for path */ |
2177 | | path_cleanup(&path); |
2178 | | |
2179 | | return return_value; |
2180 | | } |
2181 | | |
2182 | | #endif /* defined(MS_WINDOWS) */ |
2183 | | |
2184 | | #if defined(MS_WINDOWS) |
2185 | | |
2186 | | PyDoc_STRVAR(os__path_splitroot__doc__, |
2187 | | "_path_splitroot($module, path, /)\n" |
2188 | | "--\n" |
2189 | | "\n" |
2190 | | "Removes everything after the root on Win32."); |
2191 | | |
2192 | | #define OS__PATH_SPLITROOT_METHODDEF \ |
2193 | | {"_path_splitroot", (PyCFunction)os__path_splitroot, METH_O, os__path_splitroot__doc__}, |
2194 | | |
2195 | | static PyObject * |
2196 | | os__path_splitroot_impl(PyObject *module, path_t *path); |
2197 | | |
2198 | | static PyObject * |
2199 | | os__path_splitroot(PyObject *module, PyObject *arg) |
2200 | | { |
2201 | | PyObject *return_value = NULL; |
2202 | | path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0); |
2203 | | |
2204 | | if (!path_converter(arg, &path)) { |
2205 | | goto exit; |
2206 | | } |
2207 | | return_value = os__path_splitroot_impl(module, &path); |
2208 | | |
2209 | | exit: |
2210 | | /* Cleanup for path */ |
2211 | | path_cleanup(&path); |
2212 | | |
2213 | | return return_value; |
2214 | | } |
2215 | | |
2216 | | #endif /* defined(MS_WINDOWS) */ |
2217 | | |
2218 | | #if defined(MS_WINDOWS) |
2219 | | |
2220 | | PyDoc_STRVAR(os__path_exists__doc__, |
2221 | | "_path_exists($module, /, path)\n" |
2222 | | "--\n" |
2223 | | "\n" |
2224 | | "Test whether a path exists. Returns False for broken symbolic links."); |
2225 | | |
2226 | | #define OS__PATH_EXISTS_METHODDEF \ |
2227 | | {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__}, |
2228 | | |
2229 | | static int |
2230 | | os__path_exists_impl(PyObject *module, path_t *path); |
2231 | | |
2232 | | static PyObject * |
2233 | | os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2234 | | { |
2235 | | PyObject *return_value = NULL; |
2236 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2237 | | |
2238 | | #define NUM_KEYWORDS 1 |
2239 | | static struct { |
2240 | | PyGC_Head _this_is_not_used; |
2241 | | PyObject_VAR_HEAD |
2242 | | Py_hash_t ob_hash; |
2243 | | PyObject *ob_item[NUM_KEYWORDS]; |
2244 | | } _kwtuple = { |
2245 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2246 | | .ob_hash = -1, |
2247 | | .ob_item = { &_Py_ID(path), }, |
2248 | | }; |
2249 | | #undef NUM_KEYWORDS |
2250 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2251 | | |
2252 | | #else // !Py_BUILD_CORE |
2253 | | # define KWTUPLE NULL |
2254 | | #endif // !Py_BUILD_CORE |
2255 | | |
2256 | | static const char * const _keywords[] = {"path", NULL}; |
2257 | | static _PyArg_Parser _parser = { |
2258 | | .keywords = _keywords, |
2259 | | .fname = "_path_exists", |
2260 | | .kwtuple = KWTUPLE, |
2261 | | }; |
2262 | | #undef KWTUPLE |
2263 | | PyObject *argsbuf[1]; |
2264 | | path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1); |
2265 | | int _return_value; |
2266 | | |
2267 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2268 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2269 | | if (!args) { |
2270 | | goto exit; |
2271 | | } |
2272 | | if (!path_converter(args[0], &path)) { |
2273 | | goto exit; |
2274 | | } |
2275 | | _return_value = os__path_exists_impl(module, &path); |
2276 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2277 | | goto exit; |
2278 | | } |
2279 | | return_value = PyBool_FromLong((long)_return_value); |
2280 | | |
2281 | | exit: |
2282 | | /* Cleanup for path */ |
2283 | | path_cleanup(&path); |
2284 | | |
2285 | | return return_value; |
2286 | | } |
2287 | | |
2288 | | #endif /* defined(MS_WINDOWS) */ |
2289 | | |
2290 | | #if defined(MS_WINDOWS) |
2291 | | |
2292 | | PyDoc_STRVAR(os__path_lexists__doc__, |
2293 | | "_path_lexists($module, /, path)\n" |
2294 | | "--\n" |
2295 | | "\n" |
2296 | | "Test whether a path exists. Returns True for broken symbolic links."); |
2297 | | |
2298 | | #define OS__PATH_LEXISTS_METHODDEF \ |
2299 | | {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__}, |
2300 | | |
2301 | | static int |
2302 | | os__path_lexists_impl(PyObject *module, path_t *path); |
2303 | | |
2304 | | static PyObject * |
2305 | | os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2306 | | { |
2307 | | PyObject *return_value = NULL; |
2308 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2309 | | |
2310 | | #define NUM_KEYWORDS 1 |
2311 | | static struct { |
2312 | | PyGC_Head _this_is_not_used; |
2313 | | PyObject_VAR_HEAD |
2314 | | Py_hash_t ob_hash; |
2315 | | PyObject *ob_item[NUM_KEYWORDS]; |
2316 | | } _kwtuple = { |
2317 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2318 | | .ob_hash = -1, |
2319 | | .ob_item = { &_Py_ID(path), }, |
2320 | | }; |
2321 | | #undef NUM_KEYWORDS |
2322 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2323 | | |
2324 | | #else // !Py_BUILD_CORE |
2325 | | # define KWTUPLE NULL |
2326 | | #endif // !Py_BUILD_CORE |
2327 | | |
2328 | | static const char * const _keywords[] = {"path", NULL}; |
2329 | | static _PyArg_Parser _parser = { |
2330 | | .keywords = _keywords, |
2331 | | .fname = "_path_lexists", |
2332 | | .kwtuple = KWTUPLE, |
2333 | | }; |
2334 | | #undef KWTUPLE |
2335 | | PyObject *argsbuf[1]; |
2336 | | path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1); |
2337 | | int _return_value; |
2338 | | |
2339 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2340 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2341 | | if (!args) { |
2342 | | goto exit; |
2343 | | } |
2344 | | if (!path_converter(args[0], &path)) { |
2345 | | goto exit; |
2346 | | } |
2347 | | _return_value = os__path_lexists_impl(module, &path); |
2348 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2349 | | goto exit; |
2350 | | } |
2351 | | return_value = PyBool_FromLong((long)_return_value); |
2352 | | |
2353 | | exit: |
2354 | | /* Cleanup for path */ |
2355 | | path_cleanup(&path); |
2356 | | |
2357 | | return return_value; |
2358 | | } |
2359 | | |
2360 | | #endif /* defined(MS_WINDOWS) */ |
2361 | | |
2362 | | #if defined(MS_WINDOWS) |
2363 | | |
2364 | | PyDoc_STRVAR(os__path_isdir__doc__, |
2365 | | "_path_isdir($module, path, /)\n" |
2366 | | "--\n" |
2367 | | "\n" |
2368 | | "Return true if the pathname refers to an existing directory."); |
2369 | | |
2370 | | #define OS__PATH_ISDIR_METHODDEF \ |
2371 | | {"_path_isdir", (PyCFunction)os__path_isdir, METH_O, os__path_isdir__doc__}, |
2372 | | |
2373 | | static int |
2374 | | os__path_isdir_impl(PyObject *module, path_t *path); |
2375 | | |
2376 | | static PyObject * |
2377 | | os__path_isdir(PyObject *module, PyObject *arg) |
2378 | | { |
2379 | | PyObject *return_value = NULL; |
2380 | | path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1); |
2381 | | int _return_value; |
2382 | | |
2383 | | if (!path_converter(arg, &path)) { |
2384 | | goto exit; |
2385 | | } |
2386 | | _return_value = os__path_isdir_impl(module, &path); |
2387 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2388 | | goto exit; |
2389 | | } |
2390 | | return_value = PyBool_FromLong((long)_return_value); |
2391 | | |
2392 | | exit: |
2393 | | /* Cleanup for path */ |
2394 | | path_cleanup(&path); |
2395 | | |
2396 | | return return_value; |
2397 | | } |
2398 | | |
2399 | | #endif /* defined(MS_WINDOWS) */ |
2400 | | |
2401 | | #if defined(MS_WINDOWS) |
2402 | | |
2403 | | PyDoc_STRVAR(os__path_isfile__doc__, |
2404 | | "_path_isfile($module, /, path)\n" |
2405 | | "--\n" |
2406 | | "\n" |
2407 | | "Test whether a path is a regular file"); |
2408 | | |
2409 | | #define OS__PATH_ISFILE_METHODDEF \ |
2410 | | {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__}, |
2411 | | |
2412 | | static int |
2413 | | os__path_isfile_impl(PyObject *module, path_t *path); |
2414 | | |
2415 | | static PyObject * |
2416 | | os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2417 | | { |
2418 | | PyObject *return_value = NULL; |
2419 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2420 | | |
2421 | | #define NUM_KEYWORDS 1 |
2422 | | static struct { |
2423 | | PyGC_Head _this_is_not_used; |
2424 | | PyObject_VAR_HEAD |
2425 | | Py_hash_t ob_hash; |
2426 | | PyObject *ob_item[NUM_KEYWORDS]; |
2427 | | } _kwtuple = { |
2428 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2429 | | .ob_hash = -1, |
2430 | | .ob_item = { &_Py_ID(path), }, |
2431 | | }; |
2432 | | #undef NUM_KEYWORDS |
2433 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2434 | | |
2435 | | #else // !Py_BUILD_CORE |
2436 | | # define KWTUPLE NULL |
2437 | | #endif // !Py_BUILD_CORE |
2438 | | |
2439 | | static const char * const _keywords[] = {"path", NULL}; |
2440 | | static _PyArg_Parser _parser = { |
2441 | | .keywords = _keywords, |
2442 | | .fname = "_path_isfile", |
2443 | | .kwtuple = KWTUPLE, |
2444 | | }; |
2445 | | #undef KWTUPLE |
2446 | | PyObject *argsbuf[1]; |
2447 | | path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1); |
2448 | | int _return_value; |
2449 | | |
2450 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2451 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2452 | | if (!args) { |
2453 | | goto exit; |
2454 | | } |
2455 | | if (!path_converter(args[0], &path)) { |
2456 | | goto exit; |
2457 | | } |
2458 | | _return_value = os__path_isfile_impl(module, &path); |
2459 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2460 | | goto exit; |
2461 | | } |
2462 | | return_value = PyBool_FromLong((long)_return_value); |
2463 | | |
2464 | | exit: |
2465 | | /* Cleanup for path */ |
2466 | | path_cleanup(&path); |
2467 | | |
2468 | | return return_value; |
2469 | | } |
2470 | | |
2471 | | #endif /* defined(MS_WINDOWS) */ |
2472 | | |
2473 | | #if defined(MS_WINDOWS) |
2474 | | |
2475 | | PyDoc_STRVAR(os__path_islink__doc__, |
2476 | | "_path_islink($module, /, path)\n" |
2477 | | "--\n" |
2478 | | "\n" |
2479 | | "Test whether a path is a symbolic link"); |
2480 | | |
2481 | | #define OS__PATH_ISLINK_METHODDEF \ |
2482 | | {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__}, |
2483 | | |
2484 | | static int |
2485 | | os__path_islink_impl(PyObject *module, path_t *path); |
2486 | | |
2487 | | static PyObject * |
2488 | | os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2489 | | { |
2490 | | PyObject *return_value = NULL; |
2491 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2492 | | |
2493 | | #define NUM_KEYWORDS 1 |
2494 | | static struct { |
2495 | | PyGC_Head _this_is_not_used; |
2496 | | PyObject_VAR_HEAD |
2497 | | Py_hash_t ob_hash; |
2498 | | PyObject *ob_item[NUM_KEYWORDS]; |
2499 | | } _kwtuple = { |
2500 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2501 | | .ob_hash = -1, |
2502 | | .ob_item = { &_Py_ID(path), }, |
2503 | | }; |
2504 | | #undef NUM_KEYWORDS |
2505 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2506 | | |
2507 | | #else // !Py_BUILD_CORE |
2508 | | # define KWTUPLE NULL |
2509 | | #endif // !Py_BUILD_CORE |
2510 | | |
2511 | | static const char * const _keywords[] = {"path", NULL}; |
2512 | | static _PyArg_Parser _parser = { |
2513 | | .keywords = _keywords, |
2514 | | .fname = "_path_islink", |
2515 | | .kwtuple = KWTUPLE, |
2516 | | }; |
2517 | | #undef KWTUPLE |
2518 | | PyObject *argsbuf[1]; |
2519 | | path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1); |
2520 | | int _return_value; |
2521 | | |
2522 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2523 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2524 | | if (!args) { |
2525 | | goto exit; |
2526 | | } |
2527 | | if (!path_converter(args[0], &path)) { |
2528 | | goto exit; |
2529 | | } |
2530 | | _return_value = os__path_islink_impl(module, &path); |
2531 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2532 | | goto exit; |
2533 | | } |
2534 | | return_value = PyBool_FromLong((long)_return_value); |
2535 | | |
2536 | | exit: |
2537 | | /* Cleanup for path */ |
2538 | | path_cleanup(&path); |
2539 | | |
2540 | | return return_value; |
2541 | | } |
2542 | | |
2543 | | #endif /* defined(MS_WINDOWS) */ |
2544 | | |
2545 | | #if defined(MS_WINDOWS) |
2546 | | |
2547 | | PyDoc_STRVAR(os__path_isjunction__doc__, |
2548 | | "_path_isjunction($module, /, path)\n" |
2549 | | "--\n" |
2550 | | "\n" |
2551 | | "Test whether a path is a junction"); |
2552 | | |
2553 | | #define OS__PATH_ISJUNCTION_METHODDEF \ |
2554 | | {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__}, |
2555 | | |
2556 | | static int |
2557 | | os__path_isjunction_impl(PyObject *module, path_t *path); |
2558 | | |
2559 | | static PyObject * |
2560 | | os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2561 | | { |
2562 | | PyObject *return_value = NULL; |
2563 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2564 | | |
2565 | | #define NUM_KEYWORDS 1 |
2566 | | static struct { |
2567 | | PyGC_Head _this_is_not_used; |
2568 | | PyObject_VAR_HEAD |
2569 | | Py_hash_t ob_hash; |
2570 | | PyObject *ob_item[NUM_KEYWORDS]; |
2571 | | } _kwtuple = { |
2572 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2573 | | .ob_hash = -1, |
2574 | | .ob_item = { &_Py_ID(path), }, |
2575 | | }; |
2576 | | #undef NUM_KEYWORDS |
2577 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2578 | | |
2579 | | #else // !Py_BUILD_CORE |
2580 | | # define KWTUPLE NULL |
2581 | | #endif // !Py_BUILD_CORE |
2582 | | |
2583 | | static const char * const _keywords[] = {"path", NULL}; |
2584 | | static _PyArg_Parser _parser = { |
2585 | | .keywords = _keywords, |
2586 | | .fname = "_path_isjunction", |
2587 | | .kwtuple = KWTUPLE, |
2588 | | }; |
2589 | | #undef KWTUPLE |
2590 | | PyObject *argsbuf[1]; |
2591 | | path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1); |
2592 | | int _return_value; |
2593 | | |
2594 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2595 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2596 | | if (!args) { |
2597 | | goto exit; |
2598 | | } |
2599 | | if (!path_converter(args[0], &path)) { |
2600 | | goto exit; |
2601 | | } |
2602 | | _return_value = os__path_isjunction_impl(module, &path); |
2603 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2604 | | goto exit; |
2605 | | } |
2606 | | return_value = PyBool_FromLong((long)_return_value); |
2607 | | |
2608 | | exit: |
2609 | | /* Cleanup for path */ |
2610 | | path_cleanup(&path); |
2611 | | |
2612 | | return return_value; |
2613 | | } |
2614 | | |
2615 | | #endif /* defined(MS_WINDOWS) */ |
2616 | | |
2617 | | PyDoc_STRVAR(os__path_splitroot_ex__doc__, |
2618 | | "_path_splitroot_ex($module, path, /)\n" |
2619 | | "--\n" |
2620 | | "\n" |
2621 | | "Split a pathname into drive, root and tail.\n" |
2622 | | "\n" |
2623 | | "The tail contains anything after the root."); |
2624 | | |
2625 | | #define OS__PATH_SPLITROOT_EX_METHODDEF \ |
2626 | | {"_path_splitroot_ex", (PyCFunction)os__path_splitroot_ex, METH_O, os__path_splitroot_ex__doc__}, |
2627 | | |
2628 | | static PyObject * |
2629 | | os__path_splitroot_ex_impl(PyObject *module, path_t *path); |
2630 | | |
2631 | | static PyObject * |
2632 | | os__path_splitroot_ex(PyObject *module, PyObject *arg) |
2633 | 132k | { |
2634 | 132k | PyObject *return_value = NULL; |
2635 | 132k | path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0); |
2636 | | |
2637 | 132k | if (!path_converter(arg, &path)) { |
2638 | 0 | goto exit; |
2639 | 0 | } |
2640 | 132k | return_value = os__path_splitroot_ex_impl(module, &path); |
2641 | | |
2642 | 132k | exit: |
2643 | | /* Cleanup for path */ |
2644 | 132k | path_cleanup(&path); |
2645 | | |
2646 | 132k | return return_value; |
2647 | 132k | } |
2648 | | |
2649 | | PyDoc_STRVAR(os__path_normpath__doc__, |
2650 | | "_path_normpath($module, /, path)\n" |
2651 | | "--\n" |
2652 | | "\n" |
2653 | | "Normalize path, eliminating double slashes, etc."); |
2654 | | |
2655 | | #define OS__PATH_NORMPATH_METHODDEF \ |
2656 | | {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__}, |
2657 | | |
2658 | | static PyObject * |
2659 | | os__path_normpath_impl(PyObject *module, path_t *path); |
2660 | | |
2661 | | static PyObject * |
2662 | | os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2663 | 26.8k | { |
2664 | 26.8k | PyObject *return_value = NULL; |
2665 | 26.8k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2666 | | |
2667 | 26.8k | #define NUM_KEYWORDS 1 |
2668 | 26.8k | static struct { |
2669 | 26.8k | PyGC_Head _this_is_not_used; |
2670 | 26.8k | PyObject_VAR_HEAD |
2671 | 26.8k | Py_hash_t ob_hash; |
2672 | 26.8k | PyObject *ob_item[NUM_KEYWORDS]; |
2673 | 26.8k | } _kwtuple = { |
2674 | 26.8k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2675 | 26.8k | .ob_hash = -1, |
2676 | 26.8k | .ob_item = { &_Py_ID(path), }, |
2677 | 26.8k | }; |
2678 | 26.8k | #undef NUM_KEYWORDS |
2679 | 26.8k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2680 | | |
2681 | | #else // !Py_BUILD_CORE |
2682 | | # define KWTUPLE NULL |
2683 | | #endif // !Py_BUILD_CORE |
2684 | | |
2685 | 26.8k | static const char * const _keywords[] = {"path", NULL}; |
2686 | 26.8k | static _PyArg_Parser _parser = { |
2687 | 26.8k | .keywords = _keywords, |
2688 | 26.8k | .fname = "_path_normpath", |
2689 | 26.8k | .kwtuple = KWTUPLE, |
2690 | 26.8k | }; |
2691 | 26.8k | #undef KWTUPLE |
2692 | 26.8k | PyObject *argsbuf[1]; |
2693 | 26.8k | path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0); |
2694 | | |
2695 | 26.8k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2696 | 26.8k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2697 | 26.8k | if (!args) { |
2698 | 0 | goto exit; |
2699 | 0 | } |
2700 | 26.8k | if (!path_converter(args[0], &path)) { |
2701 | 0 | goto exit; |
2702 | 0 | } |
2703 | 26.8k | return_value = os__path_normpath_impl(module, &path); |
2704 | | |
2705 | 26.8k | exit: |
2706 | | /* Cleanup for path */ |
2707 | 26.8k | path_cleanup(&path); |
2708 | | |
2709 | 26.8k | return return_value; |
2710 | 26.8k | } |
2711 | | |
2712 | | PyDoc_STRVAR(os_mkdir__doc__, |
2713 | | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
2714 | | "--\n" |
2715 | | "\n" |
2716 | | "Create a directory.\n" |
2717 | | "\n" |
2718 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
2719 | | "a directory, and path should be relative; path will then be relative to\n" |
2720 | | "that directory.\n" |
2721 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
2722 | | "using it will raise a NotImplementedError.\n" |
2723 | | "\n" |
2724 | | "The mode argument is ignored on Windows. Where it is used, the current\n" |
2725 | | "umask value is first masked out."); |
2726 | | |
2727 | | #define OS_MKDIR_METHODDEF \ |
2728 | | {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__}, |
2729 | | |
2730 | | static PyObject * |
2731 | | os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
2732 | | |
2733 | | static PyObject * |
2734 | | os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2735 | 91.4k | { |
2736 | 91.4k | PyObject *return_value = NULL; |
2737 | 91.4k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2738 | | |
2739 | 91.4k | #define NUM_KEYWORDS 3 |
2740 | 91.4k | static struct { |
2741 | 91.4k | PyGC_Head _this_is_not_used; |
2742 | 91.4k | PyObject_VAR_HEAD |
2743 | 91.4k | Py_hash_t ob_hash; |
2744 | 91.4k | PyObject *ob_item[NUM_KEYWORDS]; |
2745 | 91.4k | } _kwtuple = { |
2746 | 91.4k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2747 | 91.4k | .ob_hash = -1, |
2748 | 91.4k | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
2749 | 91.4k | }; |
2750 | 91.4k | #undef NUM_KEYWORDS |
2751 | 91.4k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2752 | | |
2753 | | #else // !Py_BUILD_CORE |
2754 | | # define KWTUPLE NULL |
2755 | | #endif // !Py_BUILD_CORE |
2756 | | |
2757 | 91.4k | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
2758 | 91.4k | static _PyArg_Parser _parser = { |
2759 | 91.4k | .keywords = _keywords, |
2760 | 91.4k | .fname = "mkdir", |
2761 | 91.4k | .kwtuple = KWTUPLE, |
2762 | 91.4k | }; |
2763 | 91.4k | #undef KWTUPLE |
2764 | 91.4k | PyObject *argsbuf[3]; |
2765 | 91.4k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
2766 | 91.4k | path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0); |
2767 | 91.4k | int mode = 511; |
2768 | 91.4k | int dir_fd = DEFAULT_DIR_FD; |
2769 | | |
2770 | 91.4k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2771 | 91.4k | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2772 | 91.4k | if (!args) { |
2773 | 0 | goto exit; |
2774 | 0 | } |
2775 | 91.4k | if (!path_converter(args[0], &path)) { |
2776 | 0 | goto exit; |
2777 | 0 | } |
2778 | 91.4k | if (!noptargs) { |
2779 | 756 | goto skip_optional_pos; |
2780 | 756 | } |
2781 | 90.6k | if (args[1]) { |
2782 | 90.6k | mode = PyLong_AsInt(args[1]); |
2783 | 90.6k | if (mode == -1 && PyErr_Occurred()) { |
2784 | 0 | goto exit; |
2785 | 0 | } |
2786 | 90.6k | if (!--noptargs) { |
2787 | 90.6k | goto skip_optional_pos; |
2788 | 90.6k | } |
2789 | 90.6k | } |
2790 | 91.4k | skip_optional_pos: |
2791 | 91.4k | if (!noptargs) { |
2792 | 91.4k | goto skip_optional_kwonly; |
2793 | 91.4k | } |
2794 | 0 | if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
2795 | 0 | goto exit; |
2796 | 0 | } |
2797 | 91.4k | skip_optional_kwonly: |
2798 | 91.4k | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
2799 | | |
2800 | 91.4k | exit: |
2801 | | /* Cleanup for path */ |
2802 | 91.4k | path_cleanup(&path); |
2803 | | |
2804 | 91.4k | return return_value; |
2805 | 91.4k | } |
2806 | | |
2807 | | #if defined(HAVE_NICE) |
2808 | | |
2809 | | PyDoc_STRVAR(os_nice__doc__, |
2810 | | "nice($module, increment, /)\n" |
2811 | | "--\n" |
2812 | | "\n" |
2813 | | "Add increment to the priority of process and return the new priority."); |
2814 | | |
2815 | | #define OS_NICE_METHODDEF \ |
2816 | | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
2817 | | |
2818 | | static PyObject * |
2819 | | os_nice_impl(PyObject *module, int increment); |
2820 | | |
2821 | | static PyObject * |
2822 | | os_nice(PyObject *module, PyObject *arg) |
2823 | 0 | { |
2824 | 0 | PyObject *return_value = NULL; |
2825 | 0 | int increment; |
2826 | |
|
2827 | 0 | increment = PyLong_AsInt(arg); |
2828 | 0 | if (increment == -1 && PyErr_Occurred()) { |
2829 | 0 | goto exit; |
2830 | 0 | } |
2831 | 0 | return_value = os_nice_impl(module, increment); |
2832 | |
|
2833 | 0 | exit: |
2834 | 0 | return return_value; |
2835 | 0 | } |
2836 | | |
2837 | | #endif /* defined(HAVE_NICE) */ |
2838 | | |
2839 | | #if defined(HAVE_GETPRIORITY) |
2840 | | |
2841 | | PyDoc_STRVAR(os_getpriority__doc__, |
2842 | | "getpriority($module, /, which, who)\n" |
2843 | | "--\n" |
2844 | | "\n" |
2845 | | "Return program scheduling priority."); |
2846 | | |
2847 | | #define OS_GETPRIORITY_METHODDEF \ |
2848 | | {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__}, |
2849 | | |
2850 | | static PyObject * |
2851 | | os_getpriority_impl(PyObject *module, int which, int who); |
2852 | | |
2853 | | static PyObject * |
2854 | | os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2855 | 0 | { |
2856 | 0 | PyObject *return_value = NULL; |
2857 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2858 | |
|
2859 | 0 | #define NUM_KEYWORDS 2 |
2860 | 0 | static struct { |
2861 | 0 | PyGC_Head _this_is_not_used; |
2862 | 0 | PyObject_VAR_HEAD |
2863 | 0 | Py_hash_t ob_hash; |
2864 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2865 | 0 | } _kwtuple = { |
2866 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2867 | 0 | .ob_hash = -1, |
2868 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), }, |
2869 | 0 | }; |
2870 | 0 | #undef NUM_KEYWORDS |
2871 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2872 | |
|
2873 | | #else // !Py_BUILD_CORE |
2874 | | # define KWTUPLE NULL |
2875 | | #endif // !Py_BUILD_CORE |
2876 | |
|
2877 | 0 | static const char * const _keywords[] = {"which", "who", NULL}; |
2878 | 0 | static _PyArg_Parser _parser = { |
2879 | 0 | .keywords = _keywords, |
2880 | 0 | .fname = "getpriority", |
2881 | 0 | .kwtuple = KWTUPLE, |
2882 | 0 | }; |
2883 | 0 | #undef KWTUPLE |
2884 | 0 | PyObject *argsbuf[2]; |
2885 | 0 | int which; |
2886 | 0 | int who; |
2887 | |
|
2888 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2889 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2890 | 0 | if (!args) { |
2891 | 0 | goto exit; |
2892 | 0 | } |
2893 | 0 | which = PyLong_AsInt(args[0]); |
2894 | 0 | if (which == -1 && PyErr_Occurred()) { |
2895 | 0 | goto exit; |
2896 | 0 | } |
2897 | 0 | who = PyLong_AsInt(args[1]); |
2898 | 0 | if (who == -1 && PyErr_Occurred()) { |
2899 | 0 | goto exit; |
2900 | 0 | } |
2901 | 0 | return_value = os_getpriority_impl(module, which, who); |
2902 | |
|
2903 | 0 | exit: |
2904 | 0 | return return_value; |
2905 | 0 | } |
2906 | | |
2907 | | #endif /* defined(HAVE_GETPRIORITY) */ |
2908 | | |
2909 | | #if defined(HAVE_SETPRIORITY) |
2910 | | |
2911 | | PyDoc_STRVAR(os_setpriority__doc__, |
2912 | | "setpriority($module, /, which, who, priority)\n" |
2913 | | "--\n" |
2914 | | "\n" |
2915 | | "Set program scheduling priority."); |
2916 | | |
2917 | | #define OS_SETPRIORITY_METHODDEF \ |
2918 | | {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__}, |
2919 | | |
2920 | | static PyObject * |
2921 | | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
2922 | | |
2923 | | static PyObject * |
2924 | | os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2925 | 0 | { |
2926 | 0 | PyObject *return_value = NULL; |
2927 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2928 | |
|
2929 | 0 | #define NUM_KEYWORDS 3 |
2930 | 0 | static struct { |
2931 | 0 | PyGC_Head _this_is_not_used; |
2932 | 0 | PyObject_VAR_HEAD |
2933 | 0 | Py_hash_t ob_hash; |
2934 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2935 | 0 | } _kwtuple = { |
2936 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2937 | 0 | .ob_hash = -1, |
2938 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), }, |
2939 | 0 | }; |
2940 | 0 | #undef NUM_KEYWORDS |
2941 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2942 | |
|
2943 | | #else // !Py_BUILD_CORE |
2944 | | # define KWTUPLE NULL |
2945 | | #endif // !Py_BUILD_CORE |
2946 | |
|
2947 | 0 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
2948 | 0 | static _PyArg_Parser _parser = { |
2949 | 0 | .keywords = _keywords, |
2950 | 0 | .fname = "setpriority", |
2951 | 0 | .kwtuple = KWTUPLE, |
2952 | 0 | }; |
2953 | 0 | #undef KWTUPLE |
2954 | 0 | PyObject *argsbuf[3]; |
2955 | 0 | int which; |
2956 | 0 | int who; |
2957 | 0 | int priority; |
2958 | |
|
2959 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2960 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2961 | 0 | if (!args) { |
2962 | 0 | goto exit; |
2963 | 0 | } |
2964 | 0 | which = PyLong_AsInt(args[0]); |
2965 | 0 | if (which == -1 && PyErr_Occurred()) { |
2966 | 0 | goto exit; |
2967 | 0 | } |
2968 | 0 | who = PyLong_AsInt(args[1]); |
2969 | 0 | if (who == -1 && PyErr_Occurred()) { |
2970 | 0 | goto exit; |
2971 | 0 | } |
2972 | 0 | priority = PyLong_AsInt(args[2]); |
2973 | 0 | if (priority == -1 && PyErr_Occurred()) { |
2974 | 0 | goto exit; |
2975 | 0 | } |
2976 | 0 | return_value = os_setpriority_impl(module, which, who, priority); |
2977 | |
|
2978 | 0 | exit: |
2979 | 0 | return return_value; |
2980 | 0 | } |
2981 | | |
2982 | | #endif /* defined(HAVE_SETPRIORITY) */ |
2983 | | |
2984 | | PyDoc_STRVAR(os_rename__doc__, |
2985 | | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
2986 | | "--\n" |
2987 | | "\n" |
2988 | | "Rename a file or directory.\n" |
2989 | | "\n" |
2990 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
2991 | | "descriptor open to a directory, and the respective path string (src or\n" |
2992 | | "dst) should be relative; the path will then be relative to that\n" |
2993 | | "directory.\n" |
2994 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
2995 | | "If they are unavailable, using them will raise a NotImplementedError."); |
2996 | | |
2997 | | #define OS_RENAME_METHODDEF \ |
2998 | | {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__}, |
2999 | | |
3000 | | static PyObject * |
3001 | | os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
3002 | | int dst_dir_fd); |
3003 | | |
3004 | | static PyObject * |
3005 | | os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3006 | 5 | { |
3007 | 5 | PyObject *return_value = NULL; |
3008 | 5 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3009 | | |
3010 | 5 | #define NUM_KEYWORDS 4 |
3011 | 5 | static struct { |
3012 | 5 | PyGC_Head _this_is_not_used; |
3013 | 5 | PyObject_VAR_HEAD |
3014 | 5 | Py_hash_t ob_hash; |
3015 | 5 | PyObject *ob_item[NUM_KEYWORDS]; |
3016 | 5 | } _kwtuple = { |
3017 | 5 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3018 | 5 | .ob_hash = -1, |
3019 | 5 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
3020 | 5 | }; |
3021 | 5 | #undef NUM_KEYWORDS |
3022 | 5 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3023 | | |
3024 | | #else // !Py_BUILD_CORE |
3025 | | # define KWTUPLE NULL |
3026 | | #endif // !Py_BUILD_CORE |
3027 | | |
3028 | 5 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
3029 | 5 | static _PyArg_Parser _parser = { |
3030 | 5 | .keywords = _keywords, |
3031 | 5 | .fname = "rename", |
3032 | 5 | .kwtuple = KWTUPLE, |
3033 | 5 | }; |
3034 | 5 | #undef KWTUPLE |
3035 | 5 | PyObject *argsbuf[4]; |
3036 | 5 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
3037 | 5 | path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0); |
3038 | 5 | path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0); |
3039 | 5 | int src_dir_fd = DEFAULT_DIR_FD; |
3040 | 5 | int dst_dir_fd = DEFAULT_DIR_FD; |
3041 | | |
3042 | 5 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3043 | 5 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3044 | 5 | if (!args) { |
3045 | 0 | goto exit; |
3046 | 0 | } |
3047 | 5 | if (!path_converter(args[0], &src)) { |
3048 | 0 | goto exit; |
3049 | 0 | } |
3050 | 5 | if (!path_converter(args[1], &dst)) { |
3051 | 0 | goto exit; |
3052 | 0 | } |
3053 | 5 | if (!noptargs) { |
3054 | 5 | goto skip_optional_kwonly; |
3055 | 5 | } |
3056 | 0 | if (args[2]) { |
3057 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
3058 | 0 | goto exit; |
3059 | 0 | } |
3060 | 0 | if (!--noptargs) { |
3061 | 0 | goto skip_optional_kwonly; |
3062 | 0 | } |
3063 | 0 | } |
3064 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
3065 | 0 | goto exit; |
3066 | 0 | } |
3067 | 5 | skip_optional_kwonly: |
3068 | 5 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
3069 | | |
3070 | 5 | exit: |
3071 | | /* Cleanup for src */ |
3072 | 5 | path_cleanup(&src); |
3073 | | /* Cleanup for dst */ |
3074 | 5 | path_cleanup(&dst); |
3075 | | |
3076 | 5 | return return_value; |
3077 | 5 | } |
3078 | | |
3079 | | PyDoc_STRVAR(os_replace__doc__, |
3080 | | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
3081 | | "--\n" |
3082 | | "\n" |
3083 | | "Rename a file or directory, overwriting the destination.\n" |
3084 | | "\n" |
3085 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
3086 | | "descriptor open to a directory, and the respective path string (src or\n" |
3087 | | "dst) should be relative; the path will then be relative to that\n" |
3088 | | "directory.\n" |
3089 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
3090 | | "If they are unavailable, using them will raise a NotImplementedError."); |
3091 | | |
3092 | | #define OS_REPLACE_METHODDEF \ |
3093 | | {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__}, |
3094 | | |
3095 | | static PyObject * |
3096 | | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
3097 | | int dst_dir_fd); |
3098 | | |
3099 | | static PyObject * |
3100 | | os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3101 | 140 | { |
3102 | 140 | PyObject *return_value = NULL; |
3103 | 140 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3104 | | |
3105 | 140 | #define NUM_KEYWORDS 4 |
3106 | 140 | static struct { |
3107 | 140 | PyGC_Head _this_is_not_used; |
3108 | 140 | PyObject_VAR_HEAD |
3109 | 140 | Py_hash_t ob_hash; |
3110 | 140 | PyObject *ob_item[NUM_KEYWORDS]; |
3111 | 140 | } _kwtuple = { |
3112 | 140 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3113 | 140 | .ob_hash = -1, |
3114 | 140 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
3115 | 140 | }; |
3116 | 140 | #undef NUM_KEYWORDS |
3117 | 140 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3118 | | |
3119 | | #else // !Py_BUILD_CORE |
3120 | | # define KWTUPLE NULL |
3121 | | #endif // !Py_BUILD_CORE |
3122 | | |
3123 | 140 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
3124 | 140 | static _PyArg_Parser _parser = { |
3125 | 140 | .keywords = _keywords, |
3126 | 140 | .fname = "replace", |
3127 | 140 | .kwtuple = KWTUPLE, |
3128 | 140 | }; |
3129 | 140 | #undef KWTUPLE |
3130 | 140 | PyObject *argsbuf[4]; |
3131 | 140 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
3132 | 140 | path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0); |
3133 | 140 | path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0); |
3134 | 140 | int src_dir_fd = DEFAULT_DIR_FD; |
3135 | 140 | int dst_dir_fd = DEFAULT_DIR_FD; |
3136 | | |
3137 | 140 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3138 | 140 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3139 | 140 | if (!args) { |
3140 | 0 | goto exit; |
3141 | 0 | } |
3142 | 140 | if (!path_converter(args[0], &src)) { |
3143 | 0 | goto exit; |
3144 | 0 | } |
3145 | 140 | if (!path_converter(args[1], &dst)) { |
3146 | 0 | goto exit; |
3147 | 0 | } |
3148 | 140 | if (!noptargs) { |
3149 | 140 | goto skip_optional_kwonly; |
3150 | 140 | } |
3151 | 0 | if (args[2]) { |
3152 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
3153 | 0 | goto exit; |
3154 | 0 | } |
3155 | 0 | if (!--noptargs) { |
3156 | 0 | goto skip_optional_kwonly; |
3157 | 0 | } |
3158 | 0 | } |
3159 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
3160 | 0 | goto exit; |
3161 | 0 | } |
3162 | 140 | skip_optional_kwonly: |
3163 | 140 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
3164 | | |
3165 | 140 | exit: |
3166 | | /* Cleanup for src */ |
3167 | 140 | path_cleanup(&src); |
3168 | | /* Cleanup for dst */ |
3169 | 140 | path_cleanup(&dst); |
3170 | | |
3171 | 140 | return return_value; |
3172 | 140 | } |
3173 | | |
3174 | | PyDoc_STRVAR(os_rmdir__doc__, |
3175 | | "rmdir($module, /, path, *, dir_fd=None)\n" |
3176 | | "--\n" |
3177 | | "\n" |
3178 | | "Remove a directory.\n" |
3179 | | "\n" |
3180 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
3181 | | "a directory, and path should be relative; path will then be relative\n" |
3182 | | "to that directory.\n" |
3183 | | "dir_fd may not be implemented on your platform.\n" |
3184 | | "If it is unavailable, using it will raise a NotImplementedError."); |
3185 | | |
3186 | | #define OS_RMDIR_METHODDEF \ |
3187 | | {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__}, |
3188 | | |
3189 | | static PyObject * |
3190 | | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
3191 | | |
3192 | | static PyObject * |
3193 | | os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3194 | 91.0k | { |
3195 | 91.0k | PyObject *return_value = NULL; |
3196 | 91.0k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3197 | | |
3198 | 91.0k | #define NUM_KEYWORDS 2 |
3199 | 91.0k | static struct { |
3200 | 91.0k | PyGC_Head _this_is_not_used; |
3201 | 91.0k | PyObject_VAR_HEAD |
3202 | 91.0k | Py_hash_t ob_hash; |
3203 | 91.0k | PyObject *ob_item[NUM_KEYWORDS]; |
3204 | 91.0k | } _kwtuple = { |
3205 | 91.0k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3206 | 91.0k | .ob_hash = -1, |
3207 | 91.0k | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3208 | 91.0k | }; |
3209 | 91.0k | #undef NUM_KEYWORDS |
3210 | 91.0k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3211 | | |
3212 | | #else // !Py_BUILD_CORE |
3213 | | # define KWTUPLE NULL |
3214 | | #endif // !Py_BUILD_CORE |
3215 | | |
3216 | 91.0k | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3217 | 91.0k | static _PyArg_Parser _parser = { |
3218 | 91.0k | .keywords = _keywords, |
3219 | 91.0k | .fname = "rmdir", |
3220 | 91.0k | .kwtuple = KWTUPLE, |
3221 | 91.0k | }; |
3222 | 91.0k | #undef KWTUPLE |
3223 | 91.0k | PyObject *argsbuf[2]; |
3224 | 91.0k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3225 | 91.0k | path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0); |
3226 | 91.0k | int dir_fd = DEFAULT_DIR_FD; |
3227 | | |
3228 | 91.0k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3229 | 91.0k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3230 | 91.0k | if (!args) { |
3231 | 0 | goto exit; |
3232 | 0 | } |
3233 | 91.0k | if (!path_converter(args[0], &path)) { |
3234 | 0 | goto exit; |
3235 | 0 | } |
3236 | 91.0k | if (!noptargs) { |
3237 | 10 | goto skip_optional_kwonly; |
3238 | 10 | } |
3239 | 91.0k | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3240 | 0 | goto exit; |
3241 | 0 | } |
3242 | 91.0k | skip_optional_kwonly: |
3243 | 91.0k | return_value = os_rmdir_impl(module, &path, dir_fd); |
3244 | | |
3245 | 91.0k | exit: |
3246 | | /* Cleanup for path */ |
3247 | 91.0k | path_cleanup(&path); |
3248 | | |
3249 | 91.0k | return return_value; |
3250 | 91.0k | } |
3251 | | |
3252 | | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
3253 | | |
3254 | | PyDoc_STRVAR(os_system__doc__, |
3255 | | "system($module, /, command)\n" |
3256 | | "--\n" |
3257 | | "\n" |
3258 | | "Execute the command in a subshell."); |
3259 | | |
3260 | | #define OS_SYSTEM_METHODDEF \ |
3261 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3262 | | |
3263 | | static long |
3264 | | os_system_impl(PyObject *module, const wchar_t *command); |
3265 | | |
3266 | | static PyObject * |
3267 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3268 | | { |
3269 | | PyObject *return_value = NULL; |
3270 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3271 | | |
3272 | | #define NUM_KEYWORDS 1 |
3273 | | static struct { |
3274 | | PyGC_Head _this_is_not_used; |
3275 | | PyObject_VAR_HEAD |
3276 | | Py_hash_t ob_hash; |
3277 | | PyObject *ob_item[NUM_KEYWORDS]; |
3278 | | } _kwtuple = { |
3279 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3280 | | .ob_hash = -1, |
3281 | | .ob_item = { &_Py_ID(command), }, |
3282 | | }; |
3283 | | #undef NUM_KEYWORDS |
3284 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3285 | | |
3286 | | #else // !Py_BUILD_CORE |
3287 | | # define KWTUPLE NULL |
3288 | | #endif // !Py_BUILD_CORE |
3289 | | |
3290 | | static const char * const _keywords[] = {"command", NULL}; |
3291 | | static _PyArg_Parser _parser = { |
3292 | | .keywords = _keywords, |
3293 | | .fname = "system", |
3294 | | .kwtuple = KWTUPLE, |
3295 | | }; |
3296 | | #undef KWTUPLE |
3297 | | PyObject *argsbuf[1]; |
3298 | | const wchar_t *command = NULL; |
3299 | | long _return_value; |
3300 | | |
3301 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3302 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3303 | | if (!args) { |
3304 | | goto exit; |
3305 | | } |
3306 | | if (!PyUnicode_Check(args[0])) { |
3307 | | _PyArg_BadArgument("system", "argument 'command'", "str", args[0]); |
3308 | | goto exit; |
3309 | | } |
3310 | | command = PyUnicode_AsWideCharString(args[0], NULL); |
3311 | | if (command == NULL) { |
3312 | | goto exit; |
3313 | | } |
3314 | | _return_value = os_system_impl(module, command); |
3315 | | if ((_return_value == -1) && PyErr_Occurred()) { |
3316 | | goto exit; |
3317 | | } |
3318 | | return_value = PyLong_FromLong(_return_value); |
3319 | | |
3320 | | exit: |
3321 | | /* Cleanup for command */ |
3322 | | PyMem_Free((void *)command); |
3323 | | |
3324 | | return return_value; |
3325 | | } |
3326 | | |
3327 | | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
3328 | | |
3329 | | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
3330 | | |
3331 | | PyDoc_STRVAR(os_system__doc__, |
3332 | | "system($module, /, command)\n" |
3333 | | "--\n" |
3334 | | "\n" |
3335 | | "Execute the command in a subshell."); |
3336 | | |
3337 | | #define OS_SYSTEM_METHODDEF \ |
3338 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3339 | | |
3340 | | static long |
3341 | | os_system_impl(PyObject *module, PyObject *command); |
3342 | | |
3343 | | static PyObject * |
3344 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3345 | 0 | { |
3346 | 0 | PyObject *return_value = NULL; |
3347 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3348 | |
|
3349 | 0 | #define NUM_KEYWORDS 1 |
3350 | 0 | static struct { |
3351 | 0 | PyGC_Head _this_is_not_used; |
3352 | 0 | PyObject_VAR_HEAD |
3353 | 0 | Py_hash_t ob_hash; |
3354 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3355 | 0 | } _kwtuple = { |
3356 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3357 | 0 | .ob_hash = -1, |
3358 | 0 | .ob_item = { &_Py_ID(command), }, |
3359 | 0 | }; |
3360 | 0 | #undef NUM_KEYWORDS |
3361 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3362 | |
|
3363 | | #else // !Py_BUILD_CORE |
3364 | | # define KWTUPLE NULL |
3365 | | #endif // !Py_BUILD_CORE |
3366 | |
|
3367 | 0 | static const char * const _keywords[] = {"command", NULL}; |
3368 | 0 | static _PyArg_Parser _parser = { |
3369 | 0 | .keywords = _keywords, |
3370 | 0 | .fname = "system", |
3371 | 0 | .kwtuple = KWTUPLE, |
3372 | 0 | }; |
3373 | 0 | #undef KWTUPLE |
3374 | 0 | PyObject *argsbuf[1]; |
3375 | 0 | PyObject *command = NULL; |
3376 | 0 | long _return_value; |
3377 | |
|
3378 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3379 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3380 | 0 | if (!args) { |
3381 | 0 | goto exit; |
3382 | 0 | } |
3383 | 0 | if (!PyUnicode_FSConverter(args[0], &command)) { |
3384 | 0 | goto exit; |
3385 | 0 | } |
3386 | 0 | _return_value = os_system_impl(module, command); |
3387 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
3388 | 0 | goto exit; |
3389 | 0 | } |
3390 | 0 | return_value = PyLong_FromLong(_return_value); |
3391 | |
|
3392 | 0 | exit: |
3393 | | /* Cleanup for command */ |
3394 | 0 | Py_XDECREF(command); |
3395 | |
|
3396 | 0 | return return_value; |
3397 | 0 | } |
3398 | | |
3399 | | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
3400 | | |
3401 | | #if defined(HAVE_UMASK) |
3402 | | |
3403 | | PyDoc_STRVAR(os_umask__doc__, |
3404 | | "umask($module, mask, /)\n" |
3405 | | "--\n" |
3406 | | "\n" |
3407 | | "Set the current numeric umask and return the previous umask."); |
3408 | | |
3409 | | #define OS_UMASK_METHODDEF \ |
3410 | | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
3411 | | |
3412 | | static PyObject * |
3413 | | os_umask_impl(PyObject *module, int mask); |
3414 | | |
3415 | | static PyObject * |
3416 | | os_umask(PyObject *module, PyObject *arg) |
3417 | 0 | { |
3418 | 0 | PyObject *return_value = NULL; |
3419 | 0 | int mask; |
3420 | |
|
3421 | 0 | mask = PyLong_AsInt(arg); |
3422 | 0 | if (mask == -1 && PyErr_Occurred()) { |
3423 | 0 | goto exit; |
3424 | 0 | } |
3425 | 0 | return_value = os_umask_impl(module, mask); |
3426 | |
|
3427 | 0 | exit: |
3428 | 0 | return return_value; |
3429 | 0 | } |
3430 | | |
3431 | | #endif /* defined(HAVE_UMASK) */ |
3432 | | |
3433 | | PyDoc_STRVAR(os_unlink__doc__, |
3434 | | "unlink($module, /, path, *, dir_fd=None)\n" |
3435 | | "--\n" |
3436 | | "\n" |
3437 | | "Remove a file (same as remove()).\n" |
3438 | | "\n" |
3439 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
3440 | | "a directory, and path should be relative; path will then be relative to\n" |
3441 | | "that directory.\n" |
3442 | | "dir_fd may not be implemented on your platform.\n" |
3443 | | "If it is unavailable, using it will raise a NotImplementedError."); |
3444 | | |
3445 | | #define OS_UNLINK_METHODDEF \ |
3446 | | {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__}, |
3447 | | |
3448 | | static PyObject * |
3449 | | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
3450 | | |
3451 | | static PyObject * |
3452 | | os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3453 | 18.4k | { |
3454 | 18.4k | PyObject *return_value = NULL; |
3455 | 18.4k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3456 | | |
3457 | 18.4k | #define NUM_KEYWORDS 2 |
3458 | 18.4k | static struct { |
3459 | 18.4k | PyGC_Head _this_is_not_used; |
3460 | 18.4k | PyObject_VAR_HEAD |
3461 | 18.4k | Py_hash_t ob_hash; |
3462 | 18.4k | PyObject *ob_item[NUM_KEYWORDS]; |
3463 | 18.4k | } _kwtuple = { |
3464 | 18.4k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3465 | 18.4k | .ob_hash = -1, |
3466 | 18.4k | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3467 | 18.4k | }; |
3468 | 18.4k | #undef NUM_KEYWORDS |
3469 | 18.4k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3470 | | |
3471 | | #else // !Py_BUILD_CORE |
3472 | | # define KWTUPLE NULL |
3473 | | #endif // !Py_BUILD_CORE |
3474 | | |
3475 | 18.4k | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3476 | 18.4k | static _PyArg_Parser _parser = { |
3477 | 18.4k | .keywords = _keywords, |
3478 | 18.4k | .fname = "unlink", |
3479 | 18.4k | .kwtuple = KWTUPLE, |
3480 | 18.4k | }; |
3481 | 18.4k | #undef KWTUPLE |
3482 | 18.4k | PyObject *argsbuf[2]; |
3483 | 18.4k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3484 | 18.4k | path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0); |
3485 | 18.4k | int dir_fd = DEFAULT_DIR_FD; |
3486 | | |
3487 | 18.4k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3488 | 18.4k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3489 | 18.4k | if (!args) { |
3490 | 0 | goto exit; |
3491 | 0 | } |
3492 | 18.4k | if (!path_converter(args[0], &path)) { |
3493 | 0 | goto exit; |
3494 | 0 | } |
3495 | 18.4k | if (!noptargs) { |
3496 | 2 | goto skip_optional_kwonly; |
3497 | 2 | } |
3498 | 18.4k | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3499 | 0 | goto exit; |
3500 | 0 | } |
3501 | 18.4k | skip_optional_kwonly: |
3502 | 18.4k | return_value = os_unlink_impl(module, &path, dir_fd); |
3503 | | |
3504 | 18.4k | exit: |
3505 | | /* Cleanup for path */ |
3506 | 18.4k | path_cleanup(&path); |
3507 | | |
3508 | 18.4k | return return_value; |
3509 | 18.4k | } |
3510 | | |
3511 | | PyDoc_STRVAR(os_remove__doc__, |
3512 | | "remove($module, /, path, *, dir_fd=None)\n" |
3513 | | "--\n" |
3514 | | "\n" |
3515 | | "Remove a file (same as unlink()).\n" |
3516 | | "\n" |
3517 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
3518 | | "a directory, and path should be relative; path will then be relative\n" |
3519 | | "to that directory.\n" |
3520 | | "dir_fd may not be implemented on your platform.\n" |
3521 | | "If it is unavailable, using it will raise a NotImplementedError."); |
3522 | | |
3523 | | #define OS_REMOVE_METHODDEF \ |
3524 | | {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__}, |
3525 | | |
3526 | | static PyObject * |
3527 | | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
3528 | | |
3529 | | static PyObject * |
3530 | | os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3531 | 0 | { |
3532 | 0 | PyObject *return_value = NULL; |
3533 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3534 | |
|
3535 | 0 | #define NUM_KEYWORDS 2 |
3536 | 0 | static struct { |
3537 | 0 | PyGC_Head _this_is_not_used; |
3538 | 0 | PyObject_VAR_HEAD |
3539 | 0 | Py_hash_t ob_hash; |
3540 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3541 | 0 | } _kwtuple = { |
3542 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3543 | 0 | .ob_hash = -1, |
3544 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3545 | 0 | }; |
3546 | 0 | #undef NUM_KEYWORDS |
3547 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3548 | |
|
3549 | | #else // !Py_BUILD_CORE |
3550 | | # define KWTUPLE NULL |
3551 | | #endif // !Py_BUILD_CORE |
3552 | |
|
3553 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3554 | 0 | static _PyArg_Parser _parser = { |
3555 | 0 | .keywords = _keywords, |
3556 | 0 | .fname = "remove", |
3557 | 0 | .kwtuple = KWTUPLE, |
3558 | 0 | }; |
3559 | 0 | #undef KWTUPLE |
3560 | 0 | PyObject *argsbuf[2]; |
3561 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3562 | 0 | path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0); |
3563 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3564 | |
|
3565 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3566 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3567 | 0 | if (!args) { |
3568 | 0 | goto exit; |
3569 | 0 | } |
3570 | 0 | if (!path_converter(args[0], &path)) { |
3571 | 0 | goto exit; |
3572 | 0 | } |
3573 | 0 | if (!noptargs) { |
3574 | 0 | goto skip_optional_kwonly; |
3575 | 0 | } |
3576 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3577 | 0 | goto exit; |
3578 | 0 | } |
3579 | 0 | skip_optional_kwonly: |
3580 | 0 | return_value = os_remove_impl(module, &path, dir_fd); |
3581 | |
|
3582 | 0 | exit: |
3583 | | /* Cleanup for path */ |
3584 | 0 | path_cleanup(&path); |
3585 | |
|
3586 | 0 | return return_value; |
3587 | 0 | } |
3588 | | |
3589 | | #if defined(HAVE_UNAME) |
3590 | | |
3591 | | PyDoc_STRVAR(os_uname__doc__, |
3592 | | "uname($module, /)\n" |
3593 | | "--\n" |
3594 | | "\n" |
3595 | | "Return an object identifying the current operating system.\n" |
3596 | | "\n" |
3597 | | "The object behaves like a named tuple with the following fields:\n" |
3598 | | " (sysname, nodename, release, version, machine)"); |
3599 | | |
3600 | | #define OS_UNAME_METHODDEF \ |
3601 | | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
3602 | | |
3603 | | static PyObject * |
3604 | | os_uname_impl(PyObject *module); |
3605 | | |
3606 | | static PyObject * |
3607 | | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3608 | 4 | { |
3609 | 4 | return os_uname_impl(module); |
3610 | 4 | } |
3611 | | |
3612 | | #endif /* defined(HAVE_UNAME) */ |
3613 | | |
3614 | | PyDoc_STRVAR(os_utime__doc__, |
3615 | | "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n" |
3616 | | " dir_fd=None, follow_symlinks=True)\n" |
3617 | | "--\n" |
3618 | | "\n" |
3619 | | "Set the access and modified time of path.\n" |
3620 | | "\n" |
3621 | | "path may always be specified as a string. On some platforms, path may\n" |
3622 | | "also be specified as an open file descriptor. If this functionality is\n" |
3623 | | "unavailable, using it raises an exception.\n" |
3624 | | "\n" |
3625 | | "If times is not None, it must be a tuple (atime, mtime);\n" |
3626 | | "atime and mtime should be expressed as float seconds since the epoch.\n" |
3627 | | "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n" |
3628 | | "atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
3629 | | "since the epoch.\n" |
3630 | | "If times is None and ns is unspecified, utime uses the current time.\n" |
3631 | | "Specifying tuples for both times and ns is an error.\n" |
3632 | | "\n" |
3633 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
3634 | | "a directory, and path should be relative; path will then be relative to\n" |
3635 | | "that directory.\n" |
3636 | | "If follow_symlinks is False, and the last element of the path is\n" |
3637 | | "a symbolic link, utime will modify the symbolic link itself instead of\n" |
3638 | | "the file the link points to.\n" |
3639 | | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
3640 | | "an open file descriptor.\n" |
3641 | | "dir_fd and follow_symlinks may not be available on your platform.\n" |
3642 | | "If they are unavailable, using them will raise a NotImplementedError."); |
3643 | | |
3644 | | #define OS_UTIME_METHODDEF \ |
3645 | | {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__}, |
3646 | | |
3647 | | static PyObject * |
3648 | | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
3649 | | int dir_fd, int follow_symlinks); |
3650 | | |
3651 | | static PyObject * |
3652 | | os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3653 | 0 | { |
3654 | 0 | PyObject *return_value = NULL; |
3655 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3656 | |
|
3657 | 0 | #define NUM_KEYWORDS 5 |
3658 | 0 | static struct { |
3659 | 0 | PyGC_Head _this_is_not_used; |
3660 | 0 | PyObject_VAR_HEAD |
3661 | 0 | Py_hash_t ob_hash; |
3662 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3663 | 0 | } _kwtuple = { |
3664 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3665 | 0 | .ob_hash = -1, |
3666 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
3667 | 0 | }; |
3668 | 0 | #undef NUM_KEYWORDS |
3669 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3670 | |
|
3671 | | #else // !Py_BUILD_CORE |
3672 | | # define KWTUPLE NULL |
3673 | | #endif // !Py_BUILD_CORE |
3674 | |
|
3675 | 0 | static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
3676 | 0 | static _PyArg_Parser _parser = { |
3677 | 0 | .keywords = _keywords, |
3678 | 0 | .fname = "utime", |
3679 | 0 | .kwtuple = KWTUPLE, |
3680 | 0 | }; |
3681 | 0 | #undef KWTUPLE |
3682 | 0 | PyObject *argsbuf[5]; |
3683 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3684 | 0 | path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD); |
3685 | 0 | PyObject *times = Py_None; |
3686 | 0 | PyObject *ns = NULL; |
3687 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3688 | 0 | int follow_symlinks = 1; |
3689 | |
|
3690 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3691 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3692 | 0 | if (!args) { |
3693 | 0 | goto exit; |
3694 | 0 | } |
3695 | 0 | if (!path_converter(args[0], &path)) { |
3696 | 0 | goto exit; |
3697 | 0 | } |
3698 | 0 | if (!noptargs) { |
3699 | 0 | goto skip_optional_pos; |
3700 | 0 | } |
3701 | 0 | if (args[1]) { |
3702 | 0 | times = args[1]; |
3703 | 0 | if (!--noptargs) { |
3704 | 0 | goto skip_optional_pos; |
3705 | 0 | } |
3706 | 0 | } |
3707 | 0 | skip_optional_pos: |
3708 | 0 | if (!noptargs) { |
3709 | 0 | goto skip_optional_kwonly; |
3710 | 0 | } |
3711 | 0 | if (args[2]) { |
3712 | 0 | ns = args[2]; |
3713 | 0 | if (!--noptargs) { |
3714 | 0 | goto skip_optional_kwonly; |
3715 | 0 | } |
3716 | 0 | } |
3717 | 0 | if (args[3]) { |
3718 | 0 | if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
3719 | 0 | goto exit; |
3720 | 0 | } |
3721 | 0 | if (!--noptargs) { |
3722 | 0 | goto skip_optional_kwonly; |
3723 | 0 | } |
3724 | 0 | } |
3725 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
3726 | 0 | if (follow_symlinks < 0) { |
3727 | 0 | goto exit; |
3728 | 0 | } |
3729 | 0 | skip_optional_kwonly: |
3730 | 0 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
3731 | |
|
3732 | 0 | exit: |
3733 | | /* Cleanup for path */ |
3734 | 0 | path_cleanup(&path); |
3735 | |
|
3736 | 0 | return return_value; |
3737 | 0 | } |
3738 | | |
3739 | | PyDoc_STRVAR(os__exit__doc__, |
3740 | | "_exit($module, /, status)\n" |
3741 | | "--\n" |
3742 | | "\n" |
3743 | | "Exit to the system with specified status, without normal exit processing."); |
3744 | | |
3745 | | #define OS__EXIT_METHODDEF \ |
3746 | | {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__}, |
3747 | | |
3748 | | static PyObject * |
3749 | | os__exit_impl(PyObject *module, int status); |
3750 | | |
3751 | | static PyObject * |
3752 | | os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3753 | 0 | { |
3754 | 0 | PyObject *return_value = NULL; |
3755 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3756 | |
|
3757 | 0 | #define NUM_KEYWORDS 1 |
3758 | 0 | static struct { |
3759 | 0 | PyGC_Head _this_is_not_used; |
3760 | 0 | PyObject_VAR_HEAD |
3761 | 0 | Py_hash_t ob_hash; |
3762 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3763 | 0 | } _kwtuple = { |
3764 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3765 | 0 | .ob_hash = -1, |
3766 | 0 | .ob_item = { &_Py_ID(status), }, |
3767 | 0 | }; |
3768 | 0 | #undef NUM_KEYWORDS |
3769 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3770 | |
|
3771 | | #else // !Py_BUILD_CORE |
3772 | | # define KWTUPLE NULL |
3773 | | #endif // !Py_BUILD_CORE |
3774 | |
|
3775 | 0 | static const char * const _keywords[] = {"status", NULL}; |
3776 | 0 | static _PyArg_Parser _parser = { |
3777 | 0 | .keywords = _keywords, |
3778 | 0 | .fname = "_exit", |
3779 | 0 | .kwtuple = KWTUPLE, |
3780 | 0 | }; |
3781 | 0 | #undef KWTUPLE |
3782 | 0 | PyObject *argsbuf[1]; |
3783 | 0 | int status; |
3784 | |
|
3785 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3786 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3787 | 0 | if (!args) { |
3788 | 0 | goto exit; |
3789 | 0 | } |
3790 | 0 | status = PyLong_AsInt(args[0]); |
3791 | 0 | if (status == -1 && PyErr_Occurred()) { |
3792 | 0 | goto exit; |
3793 | 0 | } |
3794 | 0 | return_value = os__exit_impl(module, status); |
3795 | |
|
3796 | 0 | exit: |
3797 | 0 | return return_value; |
3798 | 0 | } |
3799 | | |
3800 | | #if defined(HAVE_EXECV) |
3801 | | |
3802 | | PyDoc_STRVAR(os_execv__doc__, |
3803 | | "execv($module, path, argv, /)\n" |
3804 | | "--\n" |
3805 | | "\n" |
3806 | | "Execute an executable path with arguments, replacing current process.\n" |
3807 | | "\n" |
3808 | | " path\n" |
3809 | | " Path of executable file.\n" |
3810 | | " argv\n" |
3811 | | " Tuple or list of strings."); |
3812 | | |
3813 | | #define OS_EXECV_METHODDEF \ |
3814 | | {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__}, |
3815 | | |
3816 | | static PyObject * |
3817 | | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
3818 | | |
3819 | | static PyObject * |
3820 | | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3821 | 0 | { |
3822 | 0 | PyObject *return_value = NULL; |
3823 | 0 | path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0); |
3824 | 0 | PyObject *argv; |
3825 | |
|
3826 | 0 | if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { |
3827 | 0 | goto exit; |
3828 | 0 | } |
3829 | 0 | if (!path_converter(args[0], &path)) { |
3830 | 0 | goto exit; |
3831 | 0 | } |
3832 | 0 | argv = args[1]; |
3833 | 0 | return_value = os_execv_impl(module, &path, argv); |
3834 | |
|
3835 | 0 | exit: |
3836 | | /* Cleanup for path */ |
3837 | 0 | path_cleanup(&path); |
3838 | |
|
3839 | 0 | return return_value; |
3840 | 0 | } |
3841 | | |
3842 | | #endif /* defined(HAVE_EXECV) */ |
3843 | | |
3844 | | #if defined(HAVE_EXECV) |
3845 | | |
3846 | | PyDoc_STRVAR(os_execve__doc__, |
3847 | | "execve($module, /, path, argv, env)\n" |
3848 | | "--\n" |
3849 | | "\n" |
3850 | | "Execute an executable path with arguments, replacing current process.\n" |
3851 | | "\n" |
3852 | | " path\n" |
3853 | | " Path of executable file.\n" |
3854 | | " argv\n" |
3855 | | " Tuple or list of strings.\n" |
3856 | | " env\n" |
3857 | | " Dictionary of strings mapping to strings."); |
3858 | | |
3859 | | #define OS_EXECVE_METHODDEF \ |
3860 | | {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__}, |
3861 | | |
3862 | | static PyObject * |
3863 | | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
3864 | | |
3865 | | static PyObject * |
3866 | | os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3867 | 0 | { |
3868 | 0 | PyObject *return_value = NULL; |
3869 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3870 | |
|
3871 | 0 | #define NUM_KEYWORDS 3 |
3872 | 0 | static struct { |
3873 | 0 | PyGC_Head _this_is_not_used; |
3874 | 0 | PyObject_VAR_HEAD |
3875 | 0 | Py_hash_t ob_hash; |
3876 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3877 | 0 | } _kwtuple = { |
3878 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3879 | 0 | .ob_hash = -1, |
3880 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), }, |
3881 | 0 | }; |
3882 | 0 | #undef NUM_KEYWORDS |
3883 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3884 | |
|
3885 | | #else // !Py_BUILD_CORE |
3886 | | # define KWTUPLE NULL |
3887 | | #endif // !Py_BUILD_CORE |
3888 | |
|
3889 | 0 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
3890 | 0 | static _PyArg_Parser _parser = { |
3891 | 0 | .keywords = _keywords, |
3892 | 0 | .fname = "execve", |
3893 | 0 | .kwtuple = KWTUPLE, |
3894 | 0 | }; |
3895 | 0 | #undef KWTUPLE |
3896 | 0 | PyObject *argsbuf[3]; |
3897 | 0 | path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE); |
3898 | 0 | PyObject *argv; |
3899 | 0 | PyObject *env; |
3900 | |
|
3901 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3902 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3903 | 0 | if (!args) { |
3904 | 0 | goto exit; |
3905 | 0 | } |
3906 | 0 | if (!path_converter(args[0], &path)) { |
3907 | 0 | goto exit; |
3908 | 0 | } |
3909 | 0 | argv = args[1]; |
3910 | 0 | env = args[2]; |
3911 | 0 | return_value = os_execve_impl(module, &path, argv, env); |
3912 | |
|
3913 | 0 | exit: |
3914 | | /* Cleanup for path */ |
3915 | 0 | path_cleanup(&path); |
3916 | |
|
3917 | 0 | return return_value; |
3918 | 0 | } |
3919 | | |
3920 | | #endif /* defined(HAVE_EXECV) */ |
3921 | | |
3922 | | #if defined(HAVE_POSIX_SPAWN) |
3923 | | |
3924 | | PyDoc_STRVAR(os_posix_spawn__doc__, |
3925 | | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
3926 | | " setpgroup=None, resetids=False, setsid=False,\n" |
3927 | | " setsigmask=(), setsigdef=(), scheduler=None)\n" |
3928 | | "--\n" |
3929 | | "\n" |
3930 | | "Execute the program specified by path in a new process.\n" |
3931 | | "\n" |
3932 | | " path\n" |
3933 | | " Path of executable file.\n" |
3934 | | " argv\n" |
3935 | | " Tuple or list of strings.\n" |
3936 | | " env\n" |
3937 | | " Dictionary of strings mapping to strings.\n" |
3938 | | " file_actions\n" |
3939 | | " A sequence of file action tuples.\n" |
3940 | | " setpgroup\n" |
3941 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
3942 | | " resetids\n" |
3943 | | " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n" |
3944 | | " setsid\n" |
3945 | | " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP\n" |
3946 | | " will be activated.\n" |
3947 | | " setsigmask\n" |
3948 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
3949 | | " setsigdef\n" |
3950 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
3951 | | " scheduler\n" |
3952 | | " A tuple with the scheduler policy (optional) and parameters."); |
3953 | | |
3954 | | #define OS_POSIX_SPAWN_METHODDEF \ |
3955 | | {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__}, |
3956 | | |
3957 | | static PyObject * |
3958 | | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
3959 | | PyObject *env, PyObject *file_actions, |
3960 | | PyObject *setpgroup, int resetids, int setsid, |
3961 | | PyObject *setsigmask, PyObject *setsigdef, |
3962 | | PyObject *scheduler); |
3963 | | |
3964 | | static PyObject * |
3965 | | os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3966 | 0 | { |
3967 | 0 | PyObject *return_value = NULL; |
3968 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3969 | |
|
3970 | 0 | #define NUM_KEYWORDS 7 |
3971 | 0 | static struct { |
3972 | 0 | PyGC_Head _this_is_not_used; |
3973 | 0 | PyObject_VAR_HEAD |
3974 | 0 | Py_hash_t ob_hash; |
3975 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3976 | 0 | } _kwtuple = { |
3977 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3978 | 0 | .ob_hash = -1, |
3979 | 0 | .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), }, |
3980 | 0 | }; |
3981 | 0 | #undef NUM_KEYWORDS |
3982 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3983 | |
|
3984 | | #else // !Py_BUILD_CORE |
3985 | | # define KWTUPLE NULL |
3986 | | #endif // !Py_BUILD_CORE |
3987 | |
|
3988 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
3989 | 0 | static _PyArg_Parser _parser = { |
3990 | 0 | .keywords = _keywords, |
3991 | 0 | .fname = "posix_spawn", |
3992 | 0 | .kwtuple = KWTUPLE, |
3993 | 0 | }; |
3994 | 0 | #undef KWTUPLE |
3995 | 0 | PyObject *argsbuf[10]; |
3996 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
3997 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0); |
3998 | 0 | PyObject *argv; |
3999 | 0 | PyObject *env; |
4000 | 0 | PyObject *file_actions = NULL; |
4001 | 0 | PyObject *setpgroup = NULL; |
4002 | 0 | int resetids = 0; |
4003 | 0 | int setsid = 0; |
4004 | 0 | PyObject *setsigmask = NULL; |
4005 | 0 | PyObject *setsigdef = NULL; |
4006 | 0 | PyObject *scheduler = NULL; |
4007 | |
|
4008 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4009 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4010 | 0 | if (!args) { |
4011 | 0 | goto exit; |
4012 | 0 | } |
4013 | 0 | if (!path_converter(args[0], &path)) { |
4014 | 0 | goto exit; |
4015 | 0 | } |
4016 | 0 | argv = args[1]; |
4017 | 0 | env = args[2]; |
4018 | 0 | if (!noptargs) { |
4019 | 0 | goto skip_optional_kwonly; |
4020 | 0 | } |
4021 | 0 | if (args[3]) { |
4022 | 0 | file_actions = args[3]; |
4023 | 0 | if (!--noptargs) { |
4024 | 0 | goto skip_optional_kwonly; |
4025 | 0 | } |
4026 | 0 | } |
4027 | 0 | if (args[4]) { |
4028 | 0 | setpgroup = args[4]; |
4029 | 0 | if (!--noptargs) { |
4030 | 0 | goto skip_optional_kwonly; |
4031 | 0 | } |
4032 | 0 | } |
4033 | 0 | if (args[5]) { |
4034 | 0 | resetids = PyObject_IsTrue(args[5]); |
4035 | 0 | if (resetids < 0) { |
4036 | 0 | goto exit; |
4037 | 0 | } |
4038 | 0 | if (!--noptargs) { |
4039 | 0 | goto skip_optional_kwonly; |
4040 | 0 | } |
4041 | 0 | } |
4042 | 0 | if (args[6]) { |
4043 | 0 | setsid = PyObject_IsTrue(args[6]); |
4044 | 0 | if (setsid < 0) { |
4045 | 0 | goto exit; |
4046 | 0 | } |
4047 | 0 | if (!--noptargs) { |
4048 | 0 | goto skip_optional_kwonly; |
4049 | 0 | } |
4050 | 0 | } |
4051 | 0 | if (args[7]) { |
4052 | 0 | setsigmask = args[7]; |
4053 | 0 | if (!--noptargs) { |
4054 | 0 | goto skip_optional_kwonly; |
4055 | 0 | } |
4056 | 0 | } |
4057 | 0 | if (args[8]) { |
4058 | 0 | setsigdef = args[8]; |
4059 | 0 | if (!--noptargs) { |
4060 | 0 | goto skip_optional_kwonly; |
4061 | 0 | } |
4062 | 0 | } |
4063 | 0 | scheduler = args[9]; |
4064 | 0 | skip_optional_kwonly: |
4065 | 0 | return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
4066 | |
|
4067 | 0 | exit: |
4068 | | /* Cleanup for path */ |
4069 | 0 | path_cleanup(&path); |
4070 | |
|
4071 | 0 | return return_value; |
4072 | 0 | } |
4073 | | |
4074 | | #endif /* defined(HAVE_POSIX_SPAWN) */ |
4075 | | |
4076 | | #if defined(HAVE_POSIX_SPAWNP) |
4077 | | |
4078 | | PyDoc_STRVAR(os_posix_spawnp__doc__, |
4079 | | "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n" |
4080 | | " setpgroup=None, resetids=False, setsid=False,\n" |
4081 | | " setsigmask=(), setsigdef=(), scheduler=None)\n" |
4082 | | "--\n" |
4083 | | "\n" |
4084 | | "Execute the program specified by path in a new process.\n" |
4085 | | "\n" |
4086 | | " path\n" |
4087 | | " Path of executable file.\n" |
4088 | | " argv\n" |
4089 | | " Tuple or list of strings.\n" |
4090 | | " env\n" |
4091 | | " Dictionary of strings mapping to strings.\n" |
4092 | | " file_actions\n" |
4093 | | " A sequence of file action tuples.\n" |
4094 | | " setpgroup\n" |
4095 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
4096 | | " resetids\n" |
4097 | | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
4098 | | " setsid\n" |
4099 | | " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP\n" |
4100 | | " will be activated.\n" |
4101 | | " setsigmask\n" |
4102 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
4103 | | " setsigdef\n" |
4104 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
4105 | | " scheduler\n" |
4106 | | " A tuple with the scheduler policy (optional) and parameters."); |
4107 | | |
4108 | | #define OS_POSIX_SPAWNP_METHODDEF \ |
4109 | | {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__}, |
4110 | | |
4111 | | static PyObject * |
4112 | | os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv, |
4113 | | PyObject *env, PyObject *file_actions, |
4114 | | PyObject *setpgroup, int resetids, int setsid, |
4115 | | PyObject *setsigmask, PyObject *setsigdef, |
4116 | | PyObject *scheduler); |
4117 | | |
4118 | | static PyObject * |
4119 | | os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4120 | 0 | { |
4121 | 0 | PyObject *return_value = NULL; |
4122 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4123 | |
|
4124 | 0 | #define NUM_KEYWORDS 7 |
4125 | 0 | static struct { |
4126 | 0 | PyGC_Head _this_is_not_used; |
4127 | 0 | PyObject_VAR_HEAD |
4128 | 0 | Py_hash_t ob_hash; |
4129 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4130 | 0 | } _kwtuple = { |
4131 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4132 | 0 | .ob_hash = -1, |
4133 | 0 | .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), }, |
4134 | 0 | }; |
4135 | 0 | #undef NUM_KEYWORDS |
4136 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4137 | |
|
4138 | | #else // !Py_BUILD_CORE |
4139 | | # define KWTUPLE NULL |
4140 | | #endif // !Py_BUILD_CORE |
4141 | |
|
4142 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
4143 | 0 | static _PyArg_Parser _parser = { |
4144 | 0 | .keywords = _keywords, |
4145 | 0 | .fname = "posix_spawnp", |
4146 | 0 | .kwtuple = KWTUPLE, |
4147 | 0 | }; |
4148 | 0 | #undef KWTUPLE |
4149 | 0 | PyObject *argsbuf[10]; |
4150 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
4151 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0); |
4152 | 0 | PyObject *argv; |
4153 | 0 | PyObject *env; |
4154 | 0 | PyObject *file_actions = NULL; |
4155 | 0 | PyObject *setpgroup = NULL; |
4156 | 0 | int resetids = 0; |
4157 | 0 | int setsid = 0; |
4158 | 0 | PyObject *setsigmask = NULL; |
4159 | 0 | PyObject *setsigdef = NULL; |
4160 | 0 | PyObject *scheduler = NULL; |
4161 | |
|
4162 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4163 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4164 | 0 | if (!args) { |
4165 | 0 | goto exit; |
4166 | 0 | } |
4167 | 0 | if (!path_converter(args[0], &path)) { |
4168 | 0 | goto exit; |
4169 | 0 | } |
4170 | 0 | argv = args[1]; |
4171 | 0 | env = args[2]; |
4172 | 0 | if (!noptargs) { |
4173 | 0 | goto skip_optional_kwonly; |
4174 | 0 | } |
4175 | 0 | if (args[3]) { |
4176 | 0 | file_actions = args[3]; |
4177 | 0 | if (!--noptargs) { |
4178 | 0 | goto skip_optional_kwonly; |
4179 | 0 | } |
4180 | 0 | } |
4181 | 0 | if (args[4]) { |
4182 | 0 | setpgroup = args[4]; |
4183 | 0 | if (!--noptargs) { |
4184 | 0 | goto skip_optional_kwonly; |
4185 | 0 | } |
4186 | 0 | } |
4187 | 0 | if (args[5]) { |
4188 | 0 | resetids = PyObject_IsTrue(args[5]); |
4189 | 0 | if (resetids < 0) { |
4190 | 0 | goto exit; |
4191 | 0 | } |
4192 | 0 | if (!--noptargs) { |
4193 | 0 | goto skip_optional_kwonly; |
4194 | 0 | } |
4195 | 0 | } |
4196 | 0 | if (args[6]) { |
4197 | 0 | setsid = PyObject_IsTrue(args[6]); |
4198 | 0 | if (setsid < 0) { |
4199 | 0 | goto exit; |
4200 | 0 | } |
4201 | 0 | if (!--noptargs) { |
4202 | 0 | goto skip_optional_kwonly; |
4203 | 0 | } |
4204 | 0 | } |
4205 | 0 | if (args[7]) { |
4206 | 0 | setsigmask = args[7]; |
4207 | 0 | if (!--noptargs) { |
4208 | 0 | goto skip_optional_kwonly; |
4209 | 0 | } |
4210 | 0 | } |
4211 | 0 | if (args[8]) { |
4212 | 0 | setsigdef = args[8]; |
4213 | 0 | if (!--noptargs) { |
4214 | 0 | goto skip_optional_kwonly; |
4215 | 0 | } |
4216 | 0 | } |
4217 | 0 | scheduler = args[9]; |
4218 | 0 | skip_optional_kwonly: |
4219 | 0 | return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
4220 | |
|
4221 | 0 | exit: |
4222 | | /* Cleanup for path */ |
4223 | 0 | path_cleanup(&path); |
4224 | |
|
4225 | 0 | return return_value; |
4226 | 0 | } |
4227 | | |
4228 | | #endif /* defined(HAVE_POSIX_SPAWNP) */ |
4229 | | |
4230 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4231 | | |
4232 | | PyDoc_STRVAR(os_spawnv__doc__, |
4233 | | "spawnv($module, mode, path, argv, /)\n" |
4234 | | "--\n" |
4235 | | "\n" |
4236 | | "Execute the program specified by path in a new process.\n" |
4237 | | "\n" |
4238 | | " mode\n" |
4239 | | " Mode of process creation.\n" |
4240 | | " path\n" |
4241 | | " Path of executable file.\n" |
4242 | | " argv\n" |
4243 | | " Tuple or list of strings."); |
4244 | | |
4245 | | #define OS_SPAWNV_METHODDEF \ |
4246 | | {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__}, |
4247 | | |
4248 | | static PyObject * |
4249 | | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
4250 | | |
4251 | | static PyObject * |
4252 | | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4253 | | { |
4254 | | PyObject *return_value = NULL; |
4255 | | int mode; |
4256 | | path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0); |
4257 | | PyObject *argv; |
4258 | | |
4259 | | if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { |
4260 | | goto exit; |
4261 | | } |
4262 | | mode = PyLong_AsInt(args[0]); |
4263 | | if (mode == -1 && PyErr_Occurred()) { |
4264 | | goto exit; |
4265 | | } |
4266 | | if (!path_converter(args[1], &path)) { |
4267 | | goto exit; |
4268 | | } |
4269 | | argv = args[2]; |
4270 | | return_value = os_spawnv_impl(module, mode, &path, argv); |
4271 | | |
4272 | | exit: |
4273 | | /* Cleanup for path */ |
4274 | | path_cleanup(&path); |
4275 | | |
4276 | | return return_value; |
4277 | | } |
4278 | | |
4279 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4280 | | |
4281 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4282 | | |
4283 | | PyDoc_STRVAR(os_spawnve__doc__, |
4284 | | "spawnve($module, mode, path, argv, env, /)\n" |
4285 | | "--\n" |
4286 | | "\n" |
4287 | | "Execute the program specified by path in a new process.\n" |
4288 | | "\n" |
4289 | | " mode\n" |
4290 | | " Mode of process creation.\n" |
4291 | | " path\n" |
4292 | | " Path of executable file.\n" |
4293 | | " argv\n" |
4294 | | " Tuple or list of strings.\n" |
4295 | | " env\n" |
4296 | | " Dictionary of strings mapping to strings."); |
4297 | | |
4298 | | #define OS_SPAWNVE_METHODDEF \ |
4299 | | {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__}, |
4300 | | |
4301 | | static PyObject * |
4302 | | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
4303 | | PyObject *env); |
4304 | | |
4305 | | static PyObject * |
4306 | | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4307 | | { |
4308 | | PyObject *return_value = NULL; |
4309 | | int mode; |
4310 | | path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0); |
4311 | | PyObject *argv; |
4312 | | PyObject *env; |
4313 | | |
4314 | | if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { |
4315 | | goto exit; |
4316 | | } |
4317 | | mode = PyLong_AsInt(args[0]); |
4318 | | if (mode == -1 && PyErr_Occurred()) { |
4319 | | goto exit; |
4320 | | } |
4321 | | if (!path_converter(args[1], &path)) { |
4322 | | goto exit; |
4323 | | } |
4324 | | argv = args[2]; |
4325 | | env = args[3]; |
4326 | | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
4327 | | |
4328 | | exit: |
4329 | | /* Cleanup for path */ |
4330 | | path_cleanup(&path); |
4331 | | |
4332 | | return return_value; |
4333 | | } |
4334 | | |
4335 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4336 | | |
4337 | | #if defined(HAVE_FORK) |
4338 | | |
4339 | | PyDoc_STRVAR(os_register_at_fork__doc__, |
4340 | | "register_at_fork($module, /, *, before=<unrepresentable>,\n" |
4341 | | " after_in_child=<unrepresentable>,\n" |
4342 | | " after_in_parent=<unrepresentable>)\n" |
4343 | | "--\n" |
4344 | | "\n" |
4345 | | "Register callables to be called when forking a new process.\n" |
4346 | | "\n" |
4347 | | " before\n" |
4348 | | " A callable to be called in the parent before the fork() syscall.\n" |
4349 | | " after_in_child\n" |
4350 | | " A callable to be called in the child after fork().\n" |
4351 | | " after_in_parent\n" |
4352 | | " A callable to be called in the parent after fork().\n" |
4353 | | "\n" |
4354 | | "\'before\' callbacks are called in reverse order.\n" |
4355 | | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order."); |
4356 | | |
4357 | | #define OS_REGISTER_AT_FORK_METHODDEF \ |
4358 | | {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__}, |
4359 | | |
4360 | | static PyObject * |
4361 | | os_register_at_fork_impl(PyObject *module, PyObject *before, |
4362 | | PyObject *after_in_child, PyObject *after_in_parent); |
4363 | | |
4364 | | static PyObject * |
4365 | | os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4366 | 20 | { |
4367 | 20 | PyObject *return_value = NULL; |
4368 | 20 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4369 | | |
4370 | 20 | #define NUM_KEYWORDS 3 |
4371 | 20 | static struct { |
4372 | 20 | PyGC_Head _this_is_not_used; |
4373 | 20 | PyObject_VAR_HEAD |
4374 | 20 | Py_hash_t ob_hash; |
4375 | 20 | PyObject *ob_item[NUM_KEYWORDS]; |
4376 | 20 | } _kwtuple = { |
4377 | 20 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4378 | 20 | .ob_hash = -1, |
4379 | 20 | .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), }, |
4380 | 20 | }; |
4381 | 20 | #undef NUM_KEYWORDS |
4382 | 20 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4383 | | |
4384 | | #else // !Py_BUILD_CORE |
4385 | | # define KWTUPLE NULL |
4386 | | #endif // !Py_BUILD_CORE |
4387 | | |
4388 | 20 | static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL}; |
4389 | 20 | static _PyArg_Parser _parser = { |
4390 | 20 | .keywords = _keywords, |
4391 | 20 | .fname = "register_at_fork", |
4392 | 20 | .kwtuple = KWTUPLE, |
4393 | 20 | }; |
4394 | 20 | #undef KWTUPLE |
4395 | 20 | PyObject *argsbuf[3]; |
4396 | 20 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
4397 | 20 | PyObject *before = NULL; |
4398 | 20 | PyObject *after_in_child = NULL; |
4399 | 20 | PyObject *after_in_parent = NULL; |
4400 | | |
4401 | 20 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4402 | 20 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4403 | 20 | if (!args) { |
4404 | 0 | goto exit; |
4405 | 0 | } |
4406 | 20 | if (!noptargs) { |
4407 | 0 | goto skip_optional_kwonly; |
4408 | 0 | } |
4409 | 20 | if (args[0]) { |
4410 | 0 | before = args[0]; |
4411 | 0 | if (!--noptargs) { |
4412 | 0 | goto skip_optional_kwonly; |
4413 | 0 | } |
4414 | 0 | } |
4415 | 20 | if (args[1]) { |
4416 | 20 | after_in_child = args[1]; |
4417 | 20 | if (!--noptargs) { |
4418 | 20 | goto skip_optional_kwonly; |
4419 | 20 | } |
4420 | 20 | } |
4421 | 0 | after_in_parent = args[2]; |
4422 | 20 | skip_optional_kwonly: |
4423 | 20 | return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent); |
4424 | | |
4425 | 20 | exit: |
4426 | 20 | return return_value; |
4427 | 20 | } |
4428 | | |
4429 | | #endif /* defined(HAVE_FORK) */ |
4430 | | |
4431 | | #if defined(HAVE_FORK1) |
4432 | | |
4433 | | PyDoc_STRVAR(os_fork1__doc__, |
4434 | | "fork1($module, /)\n" |
4435 | | "--\n" |
4436 | | "\n" |
4437 | | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
4438 | | "\n" |
4439 | | "Return 0 to child process and PID of child to parent process."); |
4440 | | |
4441 | | #define OS_FORK1_METHODDEF \ |
4442 | | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
4443 | | |
4444 | | static PyObject * |
4445 | | os_fork1_impl(PyObject *module); |
4446 | | |
4447 | | static PyObject * |
4448 | | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4449 | | { |
4450 | | return os_fork1_impl(module); |
4451 | | } |
4452 | | |
4453 | | #endif /* defined(HAVE_FORK1) */ |
4454 | | |
4455 | | #if defined(HAVE_FORK) |
4456 | | |
4457 | | PyDoc_STRVAR(os_fork__doc__, |
4458 | | "fork($module, /)\n" |
4459 | | "--\n" |
4460 | | "\n" |
4461 | | "Fork a child process.\n" |
4462 | | "\n" |
4463 | | "Return 0 to child process and PID of child to parent process."); |
4464 | | |
4465 | | #define OS_FORK_METHODDEF \ |
4466 | | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
4467 | | |
4468 | | static PyObject * |
4469 | | os_fork_impl(PyObject *module); |
4470 | | |
4471 | | static PyObject * |
4472 | | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4473 | 0 | { |
4474 | 0 | return os_fork_impl(module); |
4475 | 0 | } |
4476 | | |
4477 | | #endif /* defined(HAVE_FORK) */ |
4478 | | |
4479 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4480 | | |
4481 | | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
4482 | | "sched_get_priority_max($module, /, policy)\n" |
4483 | | "--\n" |
4484 | | "\n" |
4485 | | "Get the maximum scheduling priority for policy."); |
4486 | | |
4487 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
4488 | | {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__}, |
4489 | | |
4490 | | static PyObject * |
4491 | | os_sched_get_priority_max_impl(PyObject *module, int policy); |
4492 | | |
4493 | | static PyObject * |
4494 | | os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4495 | 0 | { |
4496 | 0 | PyObject *return_value = NULL; |
4497 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4498 | |
|
4499 | 0 | #define NUM_KEYWORDS 1 |
4500 | 0 | static struct { |
4501 | 0 | PyGC_Head _this_is_not_used; |
4502 | 0 | PyObject_VAR_HEAD |
4503 | 0 | Py_hash_t ob_hash; |
4504 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4505 | 0 | } _kwtuple = { |
4506 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4507 | 0 | .ob_hash = -1, |
4508 | 0 | .ob_item = { &_Py_ID(policy), }, |
4509 | 0 | }; |
4510 | 0 | #undef NUM_KEYWORDS |
4511 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4512 | |
|
4513 | | #else // !Py_BUILD_CORE |
4514 | | # define KWTUPLE NULL |
4515 | | #endif // !Py_BUILD_CORE |
4516 | |
|
4517 | 0 | static const char * const _keywords[] = {"policy", NULL}; |
4518 | 0 | static _PyArg_Parser _parser = { |
4519 | 0 | .keywords = _keywords, |
4520 | 0 | .fname = "sched_get_priority_max", |
4521 | 0 | .kwtuple = KWTUPLE, |
4522 | 0 | }; |
4523 | 0 | #undef KWTUPLE |
4524 | 0 | PyObject *argsbuf[1]; |
4525 | 0 | int policy; |
4526 | |
|
4527 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4528 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4529 | 0 | if (!args) { |
4530 | 0 | goto exit; |
4531 | 0 | } |
4532 | 0 | policy = PyLong_AsInt(args[0]); |
4533 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4534 | 0 | goto exit; |
4535 | 0 | } |
4536 | 0 | return_value = os_sched_get_priority_max_impl(module, policy); |
4537 | |
|
4538 | 0 | exit: |
4539 | 0 | return return_value; |
4540 | 0 | } |
4541 | | |
4542 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4543 | | |
4544 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4545 | | |
4546 | | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
4547 | | "sched_get_priority_min($module, /, policy)\n" |
4548 | | "--\n" |
4549 | | "\n" |
4550 | | "Get the minimum scheduling priority for policy."); |
4551 | | |
4552 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
4553 | | {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__}, |
4554 | | |
4555 | | static PyObject * |
4556 | | os_sched_get_priority_min_impl(PyObject *module, int policy); |
4557 | | |
4558 | | static PyObject * |
4559 | | os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4560 | 0 | { |
4561 | 0 | PyObject *return_value = NULL; |
4562 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4563 | |
|
4564 | 0 | #define NUM_KEYWORDS 1 |
4565 | 0 | static struct { |
4566 | 0 | PyGC_Head _this_is_not_used; |
4567 | 0 | PyObject_VAR_HEAD |
4568 | 0 | Py_hash_t ob_hash; |
4569 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4570 | 0 | } _kwtuple = { |
4571 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4572 | 0 | .ob_hash = -1, |
4573 | 0 | .ob_item = { &_Py_ID(policy), }, |
4574 | 0 | }; |
4575 | 0 | #undef NUM_KEYWORDS |
4576 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4577 | |
|
4578 | | #else // !Py_BUILD_CORE |
4579 | | # define KWTUPLE NULL |
4580 | | #endif // !Py_BUILD_CORE |
4581 | |
|
4582 | 0 | static const char * const _keywords[] = {"policy", NULL}; |
4583 | 0 | static _PyArg_Parser _parser = { |
4584 | 0 | .keywords = _keywords, |
4585 | 0 | .fname = "sched_get_priority_min", |
4586 | 0 | .kwtuple = KWTUPLE, |
4587 | 0 | }; |
4588 | 0 | #undef KWTUPLE |
4589 | 0 | PyObject *argsbuf[1]; |
4590 | 0 | int policy; |
4591 | |
|
4592 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4593 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4594 | 0 | if (!args) { |
4595 | 0 | goto exit; |
4596 | 0 | } |
4597 | 0 | policy = PyLong_AsInt(args[0]); |
4598 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4599 | 0 | goto exit; |
4600 | 0 | } |
4601 | 0 | return_value = os_sched_get_priority_min_impl(module, policy); |
4602 | |
|
4603 | 0 | exit: |
4604 | 0 | return return_value; |
4605 | 0 | } |
4606 | | |
4607 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4608 | | |
4609 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4610 | | |
4611 | | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
4612 | | "sched_getscheduler($module, pid, /)\n" |
4613 | | "--\n" |
4614 | | "\n" |
4615 | | "Get the scheduling policy for the process identified by pid.\n" |
4616 | | "\n" |
4617 | | "Passing 0 for pid returns the scheduling policy for the calling process."); |
4618 | | |
4619 | | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
4620 | | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
4621 | | |
4622 | | static PyObject * |
4623 | | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
4624 | | |
4625 | | static PyObject * |
4626 | | os_sched_getscheduler(PyObject *module, PyObject *arg) |
4627 | 0 | { |
4628 | 0 | PyObject *return_value = NULL; |
4629 | 0 | pid_t pid; |
4630 | |
|
4631 | 0 | pid = PyLong_AsPid(arg); |
4632 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4633 | 0 | goto exit; |
4634 | 0 | } |
4635 | 0 | return_value = os_sched_getscheduler_impl(module, pid); |
4636 | |
|
4637 | 0 | exit: |
4638 | 0 | return return_value; |
4639 | 0 | } |
4640 | | |
4641 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4642 | | |
4643 | | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) |
4644 | | |
4645 | | PyDoc_STRVAR(os_sched_param__doc__, |
4646 | | "sched_param(sched_priority)\n" |
4647 | | "--\n" |
4648 | | "\n" |
4649 | | "Currently has only one field: sched_priority\n" |
4650 | | "\n" |
4651 | | " sched_priority\n" |
4652 | | " A scheduling parameter."); |
4653 | | |
4654 | | static PyObject * |
4655 | | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
4656 | | |
4657 | | static PyObject * |
4658 | | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
4659 | 0 | { |
4660 | 0 | PyObject *return_value = NULL; |
4661 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4662 | |
|
4663 | 0 | #define NUM_KEYWORDS 1 |
4664 | 0 | static struct { |
4665 | 0 | PyGC_Head _this_is_not_used; |
4666 | 0 | PyObject_VAR_HEAD |
4667 | 0 | Py_hash_t ob_hash; |
4668 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4669 | 0 | } _kwtuple = { |
4670 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4671 | 0 | .ob_hash = -1, |
4672 | 0 | .ob_item = { &_Py_ID(sched_priority), }, |
4673 | 0 | }; |
4674 | 0 | #undef NUM_KEYWORDS |
4675 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4676 | |
|
4677 | | #else // !Py_BUILD_CORE |
4678 | | # define KWTUPLE NULL |
4679 | | #endif // !Py_BUILD_CORE |
4680 | |
|
4681 | 0 | static const char * const _keywords[] = {"sched_priority", NULL}; |
4682 | 0 | static _PyArg_Parser _parser = { |
4683 | 0 | .keywords = _keywords, |
4684 | 0 | .fname = "sched_param", |
4685 | 0 | .kwtuple = KWTUPLE, |
4686 | 0 | }; |
4687 | 0 | #undef KWTUPLE |
4688 | 0 | PyObject *argsbuf[1]; |
4689 | 0 | PyObject * const *fastargs; |
4690 | 0 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
4691 | 0 | PyObject *sched_priority; |
4692 | |
|
4693 | 0 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
4694 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4695 | 0 | if (!fastargs) { |
4696 | 0 | goto exit; |
4697 | 0 | } |
4698 | 0 | sched_priority = fastargs[0]; |
4699 | 0 | return_value = os_sched_param_impl(type, sched_priority); |
4700 | |
|
4701 | 0 | exit: |
4702 | 0 | return return_value; |
4703 | 0 | } |
4704 | | |
4705 | | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */ |
4706 | | |
4707 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4708 | | |
4709 | | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
4710 | | "sched_setscheduler($module, pid, policy, param, /)\n" |
4711 | | "--\n" |
4712 | | "\n" |
4713 | | "Set the scheduling policy for the process identified by pid.\n" |
4714 | | "\n" |
4715 | | "If pid is 0, the calling process is changed.\n" |
4716 | | "param is an instance of sched_param."); |
4717 | | |
4718 | | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
4719 | | {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__}, |
4720 | | |
4721 | | static PyObject * |
4722 | | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
4723 | | PyObject *param_obj); |
4724 | | |
4725 | | static PyObject * |
4726 | | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4727 | 0 | { |
4728 | 0 | PyObject *return_value = NULL; |
4729 | 0 | pid_t pid; |
4730 | 0 | int policy; |
4731 | 0 | PyObject *param_obj; |
4732 | |
|
4733 | 0 | if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) { |
4734 | 0 | goto exit; |
4735 | 0 | } |
4736 | 0 | pid = PyLong_AsPid(args[0]); |
4737 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4738 | 0 | goto exit; |
4739 | 0 | } |
4740 | 0 | policy = PyLong_AsInt(args[1]); |
4741 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4742 | 0 | goto exit; |
4743 | 0 | } |
4744 | 0 | param_obj = args[2]; |
4745 | 0 | return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj); |
4746 | |
|
4747 | 0 | exit: |
4748 | 0 | return return_value; |
4749 | 0 | } |
4750 | | |
4751 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4752 | | |
4753 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4754 | | |
4755 | | PyDoc_STRVAR(os_sched_getparam__doc__, |
4756 | | "sched_getparam($module, pid, /)\n" |
4757 | | "--\n" |
4758 | | "\n" |
4759 | | "Returns scheduling parameters for the process identified by pid.\n" |
4760 | | "\n" |
4761 | | "If pid is 0, returns parameters for the calling process.\n" |
4762 | | "Return value is an instance of sched_param."); |
4763 | | |
4764 | | #define OS_SCHED_GETPARAM_METHODDEF \ |
4765 | | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
4766 | | |
4767 | | static PyObject * |
4768 | | os_sched_getparam_impl(PyObject *module, pid_t pid); |
4769 | | |
4770 | | static PyObject * |
4771 | | os_sched_getparam(PyObject *module, PyObject *arg) |
4772 | 0 | { |
4773 | 0 | PyObject *return_value = NULL; |
4774 | 0 | pid_t pid; |
4775 | |
|
4776 | 0 | pid = PyLong_AsPid(arg); |
4777 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4778 | 0 | goto exit; |
4779 | 0 | } |
4780 | 0 | return_value = os_sched_getparam_impl(module, pid); |
4781 | |
|
4782 | 0 | exit: |
4783 | 0 | return return_value; |
4784 | 0 | } |
4785 | | |
4786 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4787 | | |
4788 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4789 | | |
4790 | | PyDoc_STRVAR(os_sched_setparam__doc__, |
4791 | | "sched_setparam($module, pid, param, /)\n" |
4792 | | "--\n" |
4793 | | "\n" |
4794 | | "Set scheduling parameters for the process identified by pid.\n" |
4795 | | "\n" |
4796 | | "If pid is 0, sets parameters for the calling process.\n" |
4797 | | "param should be an instance of sched_param."); |
4798 | | |
4799 | | #define OS_SCHED_SETPARAM_METHODDEF \ |
4800 | | {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__}, |
4801 | | |
4802 | | static PyObject * |
4803 | | os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj); |
4804 | | |
4805 | | static PyObject * |
4806 | | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4807 | 0 | { |
4808 | 0 | PyObject *return_value = NULL; |
4809 | 0 | pid_t pid; |
4810 | 0 | PyObject *param_obj; |
4811 | |
|
4812 | 0 | if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) { |
4813 | 0 | goto exit; |
4814 | 0 | } |
4815 | 0 | pid = PyLong_AsPid(args[0]); |
4816 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4817 | 0 | goto exit; |
4818 | 0 | } |
4819 | 0 | param_obj = args[1]; |
4820 | 0 | return_value = os_sched_setparam_impl(module, pid, param_obj); |
4821 | |
|
4822 | 0 | exit: |
4823 | 0 | return return_value; |
4824 | 0 | } |
4825 | | |
4826 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4827 | | |
4828 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
4829 | | |
4830 | | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
4831 | | "sched_rr_get_interval($module, pid, /)\n" |
4832 | | "--\n" |
4833 | | "\n" |
4834 | | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
4835 | | "\n" |
4836 | | "Value returned is a float."); |
4837 | | |
4838 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
4839 | | {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__}, |
4840 | | |
4841 | | static double |
4842 | | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
4843 | | |
4844 | | static PyObject * |
4845 | | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
4846 | 0 | { |
4847 | 0 | PyObject *return_value = NULL; |
4848 | 0 | pid_t pid; |
4849 | 0 | double _return_value; |
4850 | |
|
4851 | 0 | pid = PyLong_AsPid(arg); |
4852 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4853 | 0 | goto exit; |
4854 | 0 | } |
4855 | 0 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
4856 | 0 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
4857 | 0 | goto exit; |
4858 | 0 | } |
4859 | 0 | return_value = PyFloat_FromDouble(_return_value); |
4860 | |
|
4861 | 0 | exit: |
4862 | 0 | return return_value; |
4863 | 0 | } |
4864 | | |
4865 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
4866 | | |
4867 | | #if defined(HAVE_SCHED_H) |
4868 | | |
4869 | | PyDoc_STRVAR(os_sched_yield__doc__, |
4870 | | "sched_yield($module, /)\n" |
4871 | | "--\n" |
4872 | | "\n" |
4873 | | "Voluntarily relinquish the CPU."); |
4874 | | |
4875 | | #define OS_SCHED_YIELD_METHODDEF \ |
4876 | | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
4877 | | |
4878 | | static PyObject * |
4879 | | os_sched_yield_impl(PyObject *module); |
4880 | | |
4881 | | static PyObject * |
4882 | | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4883 | 0 | { |
4884 | 0 | return os_sched_yield_impl(module); |
4885 | 0 | } |
4886 | | |
4887 | | #endif /* defined(HAVE_SCHED_H) */ |
4888 | | |
4889 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4890 | | |
4891 | | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
4892 | | "sched_setaffinity($module, pid, mask, /)\n" |
4893 | | "--\n" |
4894 | | "\n" |
4895 | | "Set the CPU affinity of the process identified by pid to mask.\n" |
4896 | | "\n" |
4897 | | "mask should be an iterable of integers identifying CPUs."); |
4898 | | |
4899 | | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
4900 | | {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__}, |
4901 | | |
4902 | | static PyObject * |
4903 | | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
4904 | | |
4905 | | static PyObject * |
4906 | | os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4907 | 0 | { |
4908 | 0 | PyObject *return_value = NULL; |
4909 | 0 | pid_t pid; |
4910 | 0 | PyObject *mask; |
4911 | |
|
4912 | 0 | if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) { |
4913 | 0 | goto exit; |
4914 | 0 | } |
4915 | 0 | pid = PyLong_AsPid(args[0]); |
4916 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4917 | 0 | goto exit; |
4918 | 0 | } |
4919 | 0 | mask = args[1]; |
4920 | 0 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
4921 | |
|
4922 | 0 | exit: |
4923 | 0 | return return_value; |
4924 | 0 | } |
4925 | | |
4926 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4927 | | |
4928 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4929 | | |
4930 | | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
4931 | | "sched_getaffinity($module, pid, /)\n" |
4932 | | "--\n" |
4933 | | "\n" |
4934 | | "Return the affinity of the process identified by pid (or the current process if zero).\n" |
4935 | | "\n" |
4936 | | "The affinity is returned as a set of CPU identifiers."); |
4937 | | |
4938 | | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
4939 | | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
4940 | | |
4941 | | static PyObject * |
4942 | | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
4943 | | |
4944 | | static PyObject * |
4945 | | os_sched_getaffinity(PyObject *module, PyObject *arg) |
4946 | 0 | { |
4947 | 0 | PyObject *return_value = NULL; |
4948 | 0 | pid_t pid; |
4949 | |
|
4950 | 0 | pid = PyLong_AsPid(arg); |
4951 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4952 | 0 | goto exit; |
4953 | 0 | } |
4954 | 0 | return_value = os_sched_getaffinity_impl(module, pid); |
4955 | |
|
4956 | 0 | exit: |
4957 | 0 | return return_value; |
4958 | 0 | } |
4959 | | |
4960 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4961 | | |
4962 | | #if defined(HAVE_POSIX_OPENPT) |
4963 | | |
4964 | | PyDoc_STRVAR(os_posix_openpt__doc__, |
4965 | | "posix_openpt($module, oflag, /)\n" |
4966 | | "--\n" |
4967 | | "\n" |
4968 | | "Open and return a file descriptor for a master pseudo-terminal device.\n" |
4969 | | "\n" |
4970 | | "Performs a posix_openpt() C function call. The oflag argument is used to\n" |
4971 | | "set file status flags and file access modes as specified in the manual\n" |
4972 | | "page of posix_openpt() of your system."); |
4973 | | |
4974 | | #define OS_POSIX_OPENPT_METHODDEF \ |
4975 | | {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__}, |
4976 | | |
4977 | | static int |
4978 | | os_posix_openpt_impl(PyObject *module, int oflag); |
4979 | | |
4980 | | static PyObject * |
4981 | | os_posix_openpt(PyObject *module, PyObject *arg) |
4982 | 0 | { |
4983 | 0 | PyObject *return_value = NULL; |
4984 | 0 | int oflag; |
4985 | 0 | int _return_value; |
4986 | |
|
4987 | 0 | oflag = PyLong_AsInt(arg); |
4988 | 0 | if (oflag == -1 && PyErr_Occurred()) { |
4989 | 0 | goto exit; |
4990 | 0 | } |
4991 | 0 | _return_value = os_posix_openpt_impl(module, oflag); |
4992 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
4993 | 0 | goto exit; |
4994 | 0 | } |
4995 | 0 | return_value = PyLong_FromLong((long)_return_value); |
4996 | |
|
4997 | 0 | exit: |
4998 | 0 | return return_value; |
4999 | 0 | } |
5000 | | |
5001 | | #endif /* defined(HAVE_POSIX_OPENPT) */ |
5002 | | |
5003 | | #if defined(HAVE_GRANTPT) |
5004 | | |
5005 | | PyDoc_STRVAR(os_grantpt__doc__, |
5006 | | "grantpt($module, fd, /)\n" |
5007 | | "--\n" |
5008 | | "\n" |
5009 | | "Grant access to the slave pseudo-terminal device.\n" |
5010 | | "\n" |
5011 | | " fd\n" |
5012 | | " File descriptor of a master pseudo-terminal device.\n" |
5013 | | "\n" |
5014 | | "Performs a grantpt() C function call."); |
5015 | | |
5016 | | #define OS_GRANTPT_METHODDEF \ |
5017 | | {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__}, |
5018 | | |
5019 | | static PyObject * |
5020 | | os_grantpt_impl(PyObject *module, int fd); |
5021 | | |
5022 | | static PyObject * |
5023 | | os_grantpt(PyObject *module, PyObject *arg) |
5024 | 0 | { |
5025 | 0 | PyObject *return_value = NULL; |
5026 | 0 | int fd; |
5027 | |
|
5028 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5029 | 0 | if (fd < 0) { |
5030 | 0 | goto exit; |
5031 | 0 | } |
5032 | 0 | return_value = os_grantpt_impl(module, fd); |
5033 | |
|
5034 | 0 | exit: |
5035 | 0 | return return_value; |
5036 | 0 | } |
5037 | | |
5038 | | #endif /* defined(HAVE_GRANTPT) */ |
5039 | | |
5040 | | #if defined(HAVE_UNLOCKPT) |
5041 | | |
5042 | | PyDoc_STRVAR(os_unlockpt__doc__, |
5043 | | "unlockpt($module, fd, /)\n" |
5044 | | "--\n" |
5045 | | "\n" |
5046 | | "Unlock a pseudo-terminal master/slave pair.\n" |
5047 | | "\n" |
5048 | | " fd\n" |
5049 | | " File descriptor of a master pseudo-terminal device.\n" |
5050 | | "\n" |
5051 | | "Performs an unlockpt() C function call."); |
5052 | | |
5053 | | #define OS_UNLOCKPT_METHODDEF \ |
5054 | | {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__}, |
5055 | | |
5056 | | static PyObject * |
5057 | | os_unlockpt_impl(PyObject *module, int fd); |
5058 | | |
5059 | | static PyObject * |
5060 | | os_unlockpt(PyObject *module, PyObject *arg) |
5061 | 0 | { |
5062 | 0 | PyObject *return_value = NULL; |
5063 | 0 | int fd; |
5064 | |
|
5065 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5066 | 0 | if (fd < 0) { |
5067 | 0 | goto exit; |
5068 | 0 | } |
5069 | 0 | return_value = os_unlockpt_impl(module, fd); |
5070 | |
|
5071 | 0 | exit: |
5072 | 0 | return return_value; |
5073 | 0 | } |
5074 | | |
5075 | | #endif /* defined(HAVE_UNLOCKPT) */ |
5076 | | |
5077 | | #if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) |
5078 | | |
5079 | | PyDoc_STRVAR(os_ptsname__doc__, |
5080 | | "ptsname($module, fd, /)\n" |
5081 | | "--\n" |
5082 | | "\n" |
5083 | | "Return the name of the slave pseudo-terminal device.\n" |
5084 | | "\n" |
5085 | | " fd\n" |
5086 | | " File descriptor of a master pseudo-terminal device.\n" |
5087 | | "\n" |
5088 | | "If the ptsname_r() C function is available, it is called;\n" |
5089 | | "otherwise, performs a ptsname() C function call."); |
5090 | | |
5091 | | #define OS_PTSNAME_METHODDEF \ |
5092 | | {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__}, |
5093 | | |
5094 | | static PyObject * |
5095 | | os_ptsname_impl(PyObject *module, int fd); |
5096 | | |
5097 | | static PyObject * |
5098 | | os_ptsname(PyObject *module, PyObject *arg) |
5099 | 0 | { |
5100 | 0 | PyObject *return_value = NULL; |
5101 | 0 | int fd; |
5102 | |
|
5103 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5104 | 0 | if (fd < 0) { |
5105 | 0 | goto exit; |
5106 | 0 | } |
5107 | 0 | return_value = os_ptsname_impl(module, fd); |
5108 | |
|
5109 | 0 | exit: |
5110 | 0 | return return_value; |
5111 | 0 | } |
5112 | | |
5113 | | #endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */ |
5114 | | |
5115 | | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
5116 | | |
5117 | | PyDoc_STRVAR(os_openpty__doc__, |
5118 | | "openpty($module, /)\n" |
5119 | | "--\n" |
5120 | | "\n" |
5121 | | "Open a pseudo-terminal.\n" |
5122 | | "\n" |
5123 | | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
5124 | | "for both the master and slave ends."); |
5125 | | |
5126 | | #define OS_OPENPTY_METHODDEF \ |
5127 | | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
5128 | | |
5129 | | static PyObject * |
5130 | | os_openpty_impl(PyObject *module); |
5131 | | |
5132 | | static PyObject * |
5133 | | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5134 | 0 | { |
5135 | 0 | return os_openpty_impl(module); |
5136 | 0 | } |
5137 | | |
5138 | | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
5139 | | |
5140 | | #if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) |
5141 | | |
5142 | | PyDoc_STRVAR(os_login_tty__doc__, |
5143 | | "login_tty($module, fd, /)\n" |
5144 | | "--\n" |
5145 | | "\n" |
5146 | | "Prepare the tty of which fd is a file descriptor for a new login session.\n" |
5147 | | "\n" |
5148 | | "Make the calling process a session leader; make the tty the\n" |
5149 | | "controlling tty, the stdin, the stdout, and the stderr of the\n" |
5150 | | "calling process; close fd."); |
5151 | | |
5152 | | #define OS_LOGIN_TTY_METHODDEF \ |
5153 | | {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, |
5154 | | |
5155 | | static PyObject * |
5156 | | os_login_tty_impl(PyObject *module, int fd); |
5157 | | |
5158 | | static PyObject * |
5159 | | os_login_tty(PyObject *module, PyObject *arg) |
5160 | 0 | { |
5161 | 0 | PyObject *return_value = NULL; |
5162 | 0 | int fd; |
5163 | |
|
5164 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5165 | 0 | if (fd < 0) { |
5166 | 0 | goto exit; |
5167 | 0 | } |
5168 | 0 | return_value = os_login_tty_impl(module, fd); |
5169 | |
|
5170 | 0 | exit: |
5171 | 0 | return return_value; |
5172 | 0 | } |
5173 | | |
5174 | | #endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ |
5175 | | |
5176 | | #if defined(HAVE_FORKPTY) |
5177 | | |
5178 | | PyDoc_STRVAR(os_forkpty__doc__, |
5179 | | "forkpty($module, /)\n" |
5180 | | "--\n" |
5181 | | "\n" |
5182 | | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
5183 | | "\n" |
5184 | | "Returns a tuple of (pid, master_fd).\n" |
5185 | | "Like fork(), return pid of 0 to the child process,\n" |
5186 | | "and pid of child to the parent process.\n" |
5187 | | "To both, return fd of newly opened pseudo-terminal.\n" |
5188 | | "The master_fd is non-inheritable."); |
5189 | | |
5190 | | #define OS_FORKPTY_METHODDEF \ |
5191 | | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
5192 | | |
5193 | | static PyObject * |
5194 | | os_forkpty_impl(PyObject *module); |
5195 | | |
5196 | | static PyObject * |
5197 | | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5198 | 0 | { |
5199 | 0 | return os_forkpty_impl(module); |
5200 | 0 | } |
5201 | | |
5202 | | #endif /* defined(HAVE_FORKPTY) */ |
5203 | | |
5204 | | #if defined(HAVE_GETEGID) |
5205 | | |
5206 | | PyDoc_STRVAR(os_getegid__doc__, |
5207 | | "getegid($module, /)\n" |
5208 | | "--\n" |
5209 | | "\n" |
5210 | | "Return the current process\'s effective group id."); |
5211 | | |
5212 | | #define OS_GETEGID_METHODDEF \ |
5213 | | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
5214 | | |
5215 | | static PyObject * |
5216 | | os_getegid_impl(PyObject *module); |
5217 | | |
5218 | | static PyObject * |
5219 | | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5220 | 37 | { |
5221 | 37 | return os_getegid_impl(module); |
5222 | 37 | } |
5223 | | |
5224 | | #endif /* defined(HAVE_GETEGID) */ |
5225 | | |
5226 | | #if defined(HAVE_GETEUID) |
5227 | | |
5228 | | PyDoc_STRVAR(os_geteuid__doc__, |
5229 | | "geteuid($module, /)\n" |
5230 | | "--\n" |
5231 | | "\n" |
5232 | | "Return the current process\'s effective user id."); |
5233 | | |
5234 | | #define OS_GETEUID_METHODDEF \ |
5235 | | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
5236 | | |
5237 | | static PyObject * |
5238 | | os_geteuid_impl(PyObject *module); |
5239 | | |
5240 | | static PyObject * |
5241 | | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5242 | 37 | { |
5243 | 37 | return os_geteuid_impl(module); |
5244 | 37 | } |
5245 | | |
5246 | | #endif /* defined(HAVE_GETEUID) */ |
5247 | | |
5248 | | #if defined(HAVE_GETGID) |
5249 | | |
5250 | | PyDoc_STRVAR(os_getgid__doc__, |
5251 | | "getgid($module, /)\n" |
5252 | | "--\n" |
5253 | | "\n" |
5254 | | "Return the current process\'s group id."); |
5255 | | |
5256 | | #define OS_GETGID_METHODDEF \ |
5257 | | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
5258 | | |
5259 | | static PyObject * |
5260 | | os_getgid_impl(PyObject *module); |
5261 | | |
5262 | | static PyObject * |
5263 | | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5264 | 37 | { |
5265 | 37 | return os_getgid_impl(module); |
5266 | 37 | } |
5267 | | |
5268 | | #endif /* defined(HAVE_GETGID) */ |
5269 | | |
5270 | | #if defined(HAVE_GETPID) |
5271 | | |
5272 | | PyDoc_STRVAR(os_getpid__doc__, |
5273 | | "getpid($module, /)\n" |
5274 | | "--\n" |
5275 | | "\n" |
5276 | | "Return the current process id."); |
5277 | | |
5278 | | #define OS_GETPID_METHODDEF \ |
5279 | | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
5280 | | |
5281 | | static PyObject * |
5282 | | os_getpid_impl(PyObject *module); |
5283 | | |
5284 | | static PyObject * |
5285 | | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5286 | 4.12k | { |
5287 | 4.12k | return os_getpid_impl(module); |
5288 | 4.12k | } |
5289 | | |
5290 | | #endif /* defined(HAVE_GETPID) */ |
5291 | | |
5292 | | #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__) |
5293 | | |
5294 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5295 | | "getgrouplist($module, user, group, /)\n" |
5296 | | "--\n" |
5297 | | "\n" |
5298 | | "Returns a list of groups to which a user belongs.\n" |
5299 | | "\n" |
5300 | | " user\n" |
5301 | | " username to lookup\n" |
5302 | | " group\n" |
5303 | | " base group id of the user"); |
5304 | | |
5305 | | #define OS_GETGROUPLIST_METHODDEF \ |
5306 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5307 | | |
5308 | | static PyObject * |
5309 | | os_getgrouplist_impl(PyObject *module, const char *user, int basegid); |
5310 | | |
5311 | | static PyObject * |
5312 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5313 | | { |
5314 | | PyObject *return_value = NULL; |
5315 | | const char *user; |
5316 | | int basegid; |
5317 | | |
5318 | | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5319 | | goto exit; |
5320 | | } |
5321 | | if (!PyUnicode_Check(args[0])) { |
5322 | | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5323 | | goto exit; |
5324 | | } |
5325 | | user = _PyUnicode_AsUTF8NoNUL(args[0]); |
5326 | | if (user == NULL) { |
5327 | | goto exit; |
5328 | | } |
5329 | | basegid = PyLong_AsInt(args[1]); |
5330 | | if (basegid == -1 && PyErr_Occurred()) { |
5331 | | goto exit; |
5332 | | } |
5333 | | return_value = os_getgrouplist_impl(module, user, basegid); |
5334 | | |
5335 | | exit: |
5336 | | return return_value; |
5337 | | } |
5338 | | |
5339 | | #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */ |
5340 | | |
5341 | | #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) |
5342 | | |
5343 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5344 | | "getgrouplist($module, user, group, /)\n" |
5345 | | "--\n" |
5346 | | "\n" |
5347 | | "Returns a list of groups to which a user belongs.\n" |
5348 | | "\n" |
5349 | | " user\n" |
5350 | | " username to lookup\n" |
5351 | | " group\n" |
5352 | | " base group id of the user"); |
5353 | | |
5354 | | #define OS_GETGROUPLIST_METHODDEF \ |
5355 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5356 | | |
5357 | | static PyObject * |
5358 | | os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid); |
5359 | | |
5360 | | static PyObject * |
5361 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5362 | 0 | { |
5363 | 0 | PyObject *return_value = NULL; |
5364 | 0 | const char *user; |
5365 | 0 | gid_t basegid; |
5366 | |
|
5367 | 0 | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5368 | 0 | goto exit; |
5369 | 0 | } |
5370 | 0 | if (!PyUnicode_Check(args[0])) { |
5371 | 0 | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5372 | 0 | goto exit; |
5373 | 0 | } |
5374 | 0 | user = _PyUnicode_AsUTF8NoNUL(args[0]); |
5375 | 0 | if (user == NULL) { |
5376 | 0 | goto exit; |
5377 | 0 | } |
5378 | 0 | if (!_Py_Gid_Converter(args[1], &basegid)) { |
5379 | 0 | goto exit; |
5380 | 0 | } |
5381 | 0 | return_value = os_getgrouplist_impl(module, user, basegid); |
5382 | |
|
5383 | 0 | exit: |
5384 | 0 | return return_value; |
5385 | 0 | } |
5386 | | |
5387 | | #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */ |
5388 | | |
5389 | | #if defined(HAVE_GETGROUPS) |
5390 | | |
5391 | | PyDoc_STRVAR(os_getgroups__doc__, |
5392 | | "getgroups($module, /)\n" |
5393 | | "--\n" |
5394 | | "\n" |
5395 | | "Return list of supplemental group IDs for the process."); |
5396 | | |
5397 | | #define OS_GETGROUPS_METHODDEF \ |
5398 | | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
5399 | | |
5400 | | static PyObject * |
5401 | | os_getgroups_impl(PyObject *module); |
5402 | | |
5403 | | static PyObject * |
5404 | | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5405 | 0 | { |
5406 | 0 | return os_getgroups_impl(module); |
5407 | 0 | } |
5408 | | |
5409 | | #endif /* defined(HAVE_GETGROUPS) */ |
5410 | | |
5411 | | #if defined(HAVE_INITGROUPS) && defined(__APPLE__) |
5412 | | |
5413 | | PyDoc_STRVAR(os_initgroups__doc__, |
5414 | | "initgroups($module, username, gid, /)\n" |
5415 | | "--\n" |
5416 | | "\n" |
5417 | | "Initialize the group access list.\n" |
5418 | | "\n" |
5419 | | "Call the system initgroups() to initialize the group access list with\n" |
5420 | | "all of the groups of which the specified username is a member, plus the\n" |
5421 | | "specified group id."); |
5422 | | |
5423 | | #define OS_INITGROUPS_METHODDEF \ |
5424 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5425 | | |
5426 | | static PyObject * |
5427 | | os_initgroups_impl(PyObject *module, PyObject *oname, int gid); |
5428 | | |
5429 | | static PyObject * |
5430 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5431 | | { |
5432 | | PyObject *return_value = NULL; |
5433 | | PyObject *oname = NULL; |
5434 | | int gid; |
5435 | | |
5436 | | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5437 | | goto exit; |
5438 | | } |
5439 | | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5440 | | goto exit; |
5441 | | } |
5442 | | gid = PyLong_AsInt(args[1]); |
5443 | | if (gid == -1 && PyErr_Occurred()) { |
5444 | | goto exit; |
5445 | | } |
5446 | | return_value = os_initgroups_impl(module, oname, gid); |
5447 | | |
5448 | | exit: |
5449 | | /* Cleanup for oname */ |
5450 | | Py_XDECREF(oname); |
5451 | | |
5452 | | return return_value; |
5453 | | } |
5454 | | |
5455 | | #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */ |
5456 | | |
5457 | | #if defined(HAVE_INITGROUPS) && !defined(__APPLE__) |
5458 | | |
5459 | | PyDoc_STRVAR(os_initgroups__doc__, |
5460 | | "initgroups($module, username, gid, /)\n" |
5461 | | "--\n" |
5462 | | "\n" |
5463 | | "Initialize the group access list.\n" |
5464 | | "\n" |
5465 | | "Call the system initgroups() to initialize the group access list with\n" |
5466 | | "all of the groups of which the specified username is a member, plus the\n" |
5467 | | "specified group id."); |
5468 | | |
5469 | | #define OS_INITGROUPS_METHODDEF \ |
5470 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5471 | | |
5472 | | static PyObject * |
5473 | | os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid); |
5474 | | |
5475 | | static PyObject * |
5476 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5477 | 0 | { |
5478 | 0 | PyObject *return_value = NULL; |
5479 | 0 | PyObject *oname = NULL; |
5480 | 0 | gid_t gid; |
5481 | |
|
5482 | 0 | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5483 | 0 | goto exit; |
5484 | 0 | } |
5485 | 0 | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5486 | 0 | goto exit; |
5487 | 0 | } |
5488 | 0 | if (!_Py_Gid_Converter(args[1], &gid)) { |
5489 | 0 | goto exit; |
5490 | 0 | } |
5491 | 0 | return_value = os_initgroups_impl(module, oname, gid); |
5492 | |
|
5493 | 0 | exit: |
5494 | | /* Cleanup for oname */ |
5495 | 0 | Py_XDECREF(oname); |
5496 | |
|
5497 | 0 | return return_value; |
5498 | 0 | } |
5499 | | |
5500 | | #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */ |
5501 | | |
5502 | | #if defined(HAVE_GETPGID) |
5503 | | |
5504 | | PyDoc_STRVAR(os_getpgid__doc__, |
5505 | | "getpgid($module, /, pid)\n" |
5506 | | "--\n" |
5507 | | "\n" |
5508 | | "Call the system call getpgid(), and return the result."); |
5509 | | |
5510 | | #define OS_GETPGID_METHODDEF \ |
5511 | | {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__}, |
5512 | | |
5513 | | static PyObject * |
5514 | | os_getpgid_impl(PyObject *module, pid_t pid); |
5515 | | |
5516 | | static PyObject * |
5517 | | os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5518 | 0 | { |
5519 | 0 | PyObject *return_value = NULL; |
5520 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
5521 | |
|
5522 | 0 | #define NUM_KEYWORDS 1 |
5523 | 0 | static struct { |
5524 | 0 | PyGC_Head _this_is_not_used; |
5525 | 0 | PyObject_VAR_HEAD |
5526 | 0 | Py_hash_t ob_hash; |
5527 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
5528 | 0 | } _kwtuple = { |
5529 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
5530 | 0 | .ob_hash = -1, |
5531 | 0 | .ob_item = { &_Py_ID(pid), }, |
5532 | 0 | }; |
5533 | 0 | #undef NUM_KEYWORDS |
5534 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
5535 | |
|
5536 | | #else // !Py_BUILD_CORE |
5537 | | # define KWTUPLE NULL |
5538 | | #endif // !Py_BUILD_CORE |
5539 | |
|
5540 | 0 | static const char * const _keywords[] = {"pid", NULL}; |
5541 | 0 | static _PyArg_Parser _parser = { |
5542 | 0 | .keywords = _keywords, |
5543 | 0 | .fname = "getpgid", |
5544 | 0 | .kwtuple = KWTUPLE, |
5545 | 0 | }; |
5546 | 0 | #undef KWTUPLE |
5547 | 0 | PyObject *argsbuf[1]; |
5548 | 0 | pid_t pid; |
5549 | |
|
5550 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
5551 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
5552 | 0 | if (!args) { |
5553 | 0 | goto exit; |
5554 | 0 | } |
5555 | 0 | pid = PyLong_AsPid(args[0]); |
5556 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5557 | 0 | goto exit; |
5558 | 0 | } |
5559 | 0 | return_value = os_getpgid_impl(module, pid); |
5560 | |
|
5561 | 0 | exit: |
5562 | 0 | return return_value; |
5563 | 0 | } |
5564 | | |
5565 | | #endif /* defined(HAVE_GETPGID) */ |
5566 | | |
5567 | | #if defined(HAVE_GETPGRP) |
5568 | | |
5569 | | PyDoc_STRVAR(os_getpgrp__doc__, |
5570 | | "getpgrp($module, /)\n" |
5571 | | "--\n" |
5572 | | "\n" |
5573 | | "Return the current process group id."); |
5574 | | |
5575 | | #define OS_GETPGRP_METHODDEF \ |
5576 | | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
5577 | | |
5578 | | static PyObject * |
5579 | | os_getpgrp_impl(PyObject *module); |
5580 | | |
5581 | | static PyObject * |
5582 | | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5583 | 0 | { |
5584 | 0 | return os_getpgrp_impl(module); |
5585 | 0 | } |
5586 | | |
5587 | | #endif /* defined(HAVE_GETPGRP) */ |
5588 | | |
5589 | | #if defined(HAVE_SETPGRP) |
5590 | | |
5591 | | PyDoc_STRVAR(os_setpgrp__doc__, |
5592 | | "setpgrp($module, /)\n" |
5593 | | "--\n" |
5594 | | "\n" |
5595 | | "Make the current process the leader of its process group."); |
5596 | | |
5597 | | #define OS_SETPGRP_METHODDEF \ |
5598 | | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
5599 | | |
5600 | | static PyObject * |
5601 | | os_setpgrp_impl(PyObject *module); |
5602 | | |
5603 | | static PyObject * |
5604 | | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5605 | 0 | { |
5606 | 0 | return os_setpgrp_impl(module); |
5607 | 0 | } |
5608 | | |
5609 | | #endif /* defined(HAVE_SETPGRP) */ |
5610 | | |
5611 | | #if defined(HAVE_GETPPID) |
5612 | | |
5613 | | PyDoc_STRVAR(os_getppid__doc__, |
5614 | | "getppid($module, /)\n" |
5615 | | "--\n" |
5616 | | "\n" |
5617 | | "Return the parent\'s process id.\n" |
5618 | | "\n" |
5619 | | "If the parent process has already exited, Windows machines will still\n" |
5620 | | "return its id; others systems will return the id of the \'init\' proces\n" |
5621 | | "(1)."); |
5622 | | |
5623 | | #define OS_GETPPID_METHODDEF \ |
5624 | | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
5625 | | |
5626 | | static PyObject * |
5627 | | os_getppid_impl(PyObject *module); |
5628 | | |
5629 | | static PyObject * |
5630 | | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5631 | 0 | { |
5632 | 0 | return os_getppid_impl(module); |
5633 | 0 | } |
5634 | | |
5635 | | #endif /* defined(HAVE_GETPPID) */ |
5636 | | |
5637 | | #if defined(HAVE_GETLOGIN) |
5638 | | |
5639 | | PyDoc_STRVAR(os_getlogin__doc__, |
5640 | | "getlogin($module, /)\n" |
5641 | | "--\n" |
5642 | | "\n" |
5643 | | "Return the actual login name."); |
5644 | | |
5645 | | #define OS_GETLOGIN_METHODDEF \ |
5646 | | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
5647 | | |
5648 | | static PyObject * |
5649 | | os_getlogin_impl(PyObject *module); |
5650 | | |
5651 | | static PyObject * |
5652 | | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5653 | 0 | { |
5654 | 0 | return os_getlogin_impl(module); |
5655 | 0 | } |
5656 | | |
5657 | | #endif /* defined(HAVE_GETLOGIN) */ |
5658 | | |
5659 | | #if defined(HAVE_GETUID) |
5660 | | |
5661 | | PyDoc_STRVAR(os_getuid__doc__, |
5662 | | "getuid($module, /)\n" |
5663 | | "--\n" |
5664 | | "\n" |
5665 | | "Return the current process\'s user id."); |
5666 | | |
5667 | | #define OS_GETUID_METHODDEF \ |
5668 | | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
5669 | | |
5670 | | static PyObject * |
5671 | | os_getuid_impl(PyObject *module); |
5672 | | |
5673 | | static PyObject * |
5674 | | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5675 | 37 | { |
5676 | 37 | return os_getuid_impl(module); |
5677 | 37 | } |
5678 | | |
5679 | | #endif /* defined(HAVE_GETUID) */ |
5680 | | |
5681 | | #if defined(HAVE_KILL) |
5682 | | |
5683 | | PyDoc_STRVAR(os_kill__doc__, |
5684 | | "kill($module, pid, signal, /)\n" |
5685 | | "--\n" |
5686 | | "\n" |
5687 | | "Kill a process with a signal."); |
5688 | | |
5689 | | #define OS_KILL_METHODDEF \ |
5690 | | {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__}, |
5691 | | |
5692 | | static PyObject * |
5693 | | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
5694 | | |
5695 | | static PyObject * |
5696 | | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5697 | 0 | { |
5698 | 0 | PyObject *return_value = NULL; |
5699 | 0 | pid_t pid; |
5700 | 0 | Py_ssize_t signal; |
5701 | |
|
5702 | 0 | if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) { |
5703 | 0 | goto exit; |
5704 | 0 | } |
5705 | 0 | pid = PyLong_AsPid(args[0]); |
5706 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5707 | 0 | goto exit; |
5708 | 0 | } |
5709 | 0 | { |
5710 | 0 | Py_ssize_t ival = -1; |
5711 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
5712 | 0 | if (iobj != NULL) { |
5713 | 0 | ival = PyLong_AsSsize_t(iobj); |
5714 | 0 | Py_DECREF(iobj); |
5715 | 0 | } |
5716 | 0 | if (ival == -1 && PyErr_Occurred()) { |
5717 | 0 | goto exit; |
5718 | 0 | } |
5719 | 0 | signal = ival; |
5720 | 0 | } |
5721 | 0 | return_value = os_kill_impl(module, pid, signal); |
5722 | |
|
5723 | 0 | exit: |
5724 | 0 | return return_value; |
5725 | 0 | } |
5726 | | |
5727 | | #endif /* defined(HAVE_KILL) */ |
5728 | | |
5729 | | #if defined(HAVE_KILLPG) |
5730 | | |
5731 | | PyDoc_STRVAR(os_killpg__doc__, |
5732 | | "killpg($module, pgid, signal, /)\n" |
5733 | | "--\n" |
5734 | | "\n" |
5735 | | "Kill a process group with a signal."); |
5736 | | |
5737 | | #define OS_KILLPG_METHODDEF \ |
5738 | | {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__}, |
5739 | | |
5740 | | static PyObject * |
5741 | | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
5742 | | |
5743 | | static PyObject * |
5744 | | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5745 | 0 | { |
5746 | 0 | PyObject *return_value = NULL; |
5747 | 0 | pid_t pgid; |
5748 | 0 | int signal; |
5749 | |
|
5750 | 0 | if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) { |
5751 | 0 | goto exit; |
5752 | 0 | } |
5753 | 0 | pgid = PyLong_AsPid(args[0]); |
5754 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
5755 | 0 | goto exit; |
5756 | 0 | } |
5757 | 0 | signal = PyLong_AsInt(args[1]); |
5758 | 0 | if (signal == -1 && PyErr_Occurred()) { |
5759 | 0 | goto exit; |
5760 | 0 | } |
5761 | 0 | return_value = os_killpg_impl(module, pgid, signal); |
5762 | |
|
5763 | 0 | exit: |
5764 | 0 | return return_value; |
5765 | 0 | } |
5766 | | |
5767 | | #endif /* defined(HAVE_KILLPG) */ |
5768 | | |
5769 | | #if defined(HAVE_PLOCK) |
5770 | | |
5771 | | PyDoc_STRVAR(os_plock__doc__, |
5772 | | "plock($module, op, /)\n" |
5773 | | "--\n" |
5774 | | "\n" |
5775 | | "Lock program segments into memory.\");"); |
5776 | | |
5777 | | #define OS_PLOCK_METHODDEF \ |
5778 | | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
5779 | | |
5780 | | static PyObject * |
5781 | | os_plock_impl(PyObject *module, int op); |
5782 | | |
5783 | | static PyObject * |
5784 | | os_plock(PyObject *module, PyObject *arg) |
5785 | | { |
5786 | | PyObject *return_value = NULL; |
5787 | | int op; |
5788 | | |
5789 | | op = PyLong_AsInt(arg); |
5790 | | if (op == -1 && PyErr_Occurred()) { |
5791 | | goto exit; |
5792 | | } |
5793 | | return_value = os_plock_impl(module, op); |
5794 | | |
5795 | | exit: |
5796 | | return return_value; |
5797 | | } |
5798 | | |
5799 | | #endif /* defined(HAVE_PLOCK) */ |
5800 | | |
5801 | | #if defined(HAVE_SETUID) |
5802 | | |
5803 | | PyDoc_STRVAR(os_setuid__doc__, |
5804 | | "setuid($module, uid, /)\n" |
5805 | | "--\n" |
5806 | | "\n" |
5807 | | "Set the current process\'s user id."); |
5808 | | |
5809 | | #define OS_SETUID_METHODDEF \ |
5810 | | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
5811 | | |
5812 | | static PyObject * |
5813 | | os_setuid_impl(PyObject *module, uid_t uid); |
5814 | | |
5815 | | static PyObject * |
5816 | | os_setuid(PyObject *module, PyObject *arg) |
5817 | 0 | { |
5818 | 0 | PyObject *return_value = NULL; |
5819 | 0 | uid_t uid; |
5820 | |
|
5821 | 0 | if (!_Py_Uid_Converter(arg, &uid)) { |
5822 | 0 | goto exit; |
5823 | 0 | } |
5824 | 0 | return_value = os_setuid_impl(module, uid); |
5825 | |
|
5826 | 0 | exit: |
5827 | 0 | return return_value; |
5828 | 0 | } |
5829 | | |
5830 | | #endif /* defined(HAVE_SETUID) */ |
5831 | | |
5832 | | #if defined(HAVE_SETEUID) |
5833 | | |
5834 | | PyDoc_STRVAR(os_seteuid__doc__, |
5835 | | "seteuid($module, euid, /)\n" |
5836 | | "--\n" |
5837 | | "\n" |
5838 | | "Set the current process\'s effective user id."); |
5839 | | |
5840 | | #define OS_SETEUID_METHODDEF \ |
5841 | | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
5842 | | |
5843 | | static PyObject * |
5844 | | os_seteuid_impl(PyObject *module, uid_t euid); |
5845 | | |
5846 | | static PyObject * |
5847 | | os_seteuid(PyObject *module, PyObject *arg) |
5848 | 0 | { |
5849 | 0 | PyObject *return_value = NULL; |
5850 | 0 | uid_t euid; |
5851 | |
|
5852 | 0 | if (!_Py_Uid_Converter(arg, &euid)) { |
5853 | 0 | goto exit; |
5854 | 0 | } |
5855 | 0 | return_value = os_seteuid_impl(module, euid); |
5856 | |
|
5857 | 0 | exit: |
5858 | 0 | return return_value; |
5859 | 0 | } |
5860 | | |
5861 | | #endif /* defined(HAVE_SETEUID) */ |
5862 | | |
5863 | | #if defined(HAVE_SETEGID) |
5864 | | |
5865 | | PyDoc_STRVAR(os_setegid__doc__, |
5866 | | "setegid($module, egid, /)\n" |
5867 | | "--\n" |
5868 | | "\n" |
5869 | | "Set the current process\'s effective group id."); |
5870 | | |
5871 | | #define OS_SETEGID_METHODDEF \ |
5872 | | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
5873 | | |
5874 | | static PyObject * |
5875 | | os_setegid_impl(PyObject *module, gid_t egid); |
5876 | | |
5877 | | static PyObject * |
5878 | | os_setegid(PyObject *module, PyObject *arg) |
5879 | 0 | { |
5880 | 0 | PyObject *return_value = NULL; |
5881 | 0 | gid_t egid; |
5882 | |
|
5883 | 0 | if (!_Py_Gid_Converter(arg, &egid)) { |
5884 | 0 | goto exit; |
5885 | 0 | } |
5886 | 0 | return_value = os_setegid_impl(module, egid); |
5887 | |
|
5888 | 0 | exit: |
5889 | 0 | return return_value; |
5890 | 0 | } |
5891 | | |
5892 | | #endif /* defined(HAVE_SETEGID) */ |
5893 | | |
5894 | | #if defined(HAVE_SETREUID) |
5895 | | |
5896 | | PyDoc_STRVAR(os_setreuid__doc__, |
5897 | | "setreuid($module, ruid, euid, /)\n" |
5898 | | "--\n" |
5899 | | "\n" |
5900 | | "Set the current process\'s real and effective user ids."); |
5901 | | |
5902 | | #define OS_SETREUID_METHODDEF \ |
5903 | | {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__}, |
5904 | | |
5905 | | static PyObject * |
5906 | | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
5907 | | |
5908 | | static PyObject * |
5909 | | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5910 | 0 | { |
5911 | 0 | PyObject *return_value = NULL; |
5912 | 0 | uid_t ruid; |
5913 | 0 | uid_t euid; |
5914 | |
|
5915 | 0 | if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { |
5916 | 0 | goto exit; |
5917 | 0 | } |
5918 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
5919 | 0 | goto exit; |
5920 | 0 | } |
5921 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
5922 | 0 | goto exit; |
5923 | 0 | } |
5924 | 0 | return_value = os_setreuid_impl(module, ruid, euid); |
5925 | |
|
5926 | 0 | exit: |
5927 | 0 | return return_value; |
5928 | 0 | } |
5929 | | |
5930 | | #endif /* defined(HAVE_SETREUID) */ |
5931 | | |
5932 | | #if defined(HAVE_SETREGID) |
5933 | | |
5934 | | PyDoc_STRVAR(os_setregid__doc__, |
5935 | | "setregid($module, rgid, egid, /)\n" |
5936 | | "--\n" |
5937 | | "\n" |
5938 | | "Set the current process\'s real and effective group ids."); |
5939 | | |
5940 | | #define OS_SETREGID_METHODDEF \ |
5941 | | {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__}, |
5942 | | |
5943 | | static PyObject * |
5944 | | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
5945 | | |
5946 | | static PyObject * |
5947 | | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5948 | 0 | { |
5949 | 0 | PyObject *return_value = NULL; |
5950 | 0 | gid_t rgid; |
5951 | 0 | gid_t egid; |
5952 | |
|
5953 | 0 | if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { |
5954 | 0 | goto exit; |
5955 | 0 | } |
5956 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
5957 | 0 | goto exit; |
5958 | 0 | } |
5959 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
5960 | 0 | goto exit; |
5961 | 0 | } |
5962 | 0 | return_value = os_setregid_impl(module, rgid, egid); |
5963 | |
|
5964 | 0 | exit: |
5965 | 0 | return return_value; |
5966 | 0 | } |
5967 | | |
5968 | | #endif /* defined(HAVE_SETREGID) */ |
5969 | | |
5970 | | #if defined(HAVE_SETGID) |
5971 | | |
5972 | | PyDoc_STRVAR(os_setgid__doc__, |
5973 | | "setgid($module, gid, /)\n" |
5974 | | "--\n" |
5975 | | "\n" |
5976 | | "Set the current process\'s group id."); |
5977 | | |
5978 | | #define OS_SETGID_METHODDEF \ |
5979 | | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
5980 | | |
5981 | | static PyObject * |
5982 | | os_setgid_impl(PyObject *module, gid_t gid); |
5983 | | |
5984 | | static PyObject * |
5985 | | os_setgid(PyObject *module, PyObject *arg) |
5986 | 0 | { |
5987 | 0 | PyObject *return_value = NULL; |
5988 | 0 | gid_t gid; |
5989 | |
|
5990 | 0 | if (!_Py_Gid_Converter(arg, &gid)) { |
5991 | 0 | goto exit; |
5992 | 0 | } |
5993 | 0 | return_value = os_setgid_impl(module, gid); |
5994 | |
|
5995 | 0 | exit: |
5996 | 0 | return return_value; |
5997 | 0 | } |
5998 | | |
5999 | | #endif /* defined(HAVE_SETGID) */ |
6000 | | |
6001 | | #if defined(HAVE_SETGROUPS) |
6002 | | |
6003 | | PyDoc_STRVAR(os_setgroups__doc__, |
6004 | | "setgroups($module, groups, /)\n" |
6005 | | "--\n" |
6006 | | "\n" |
6007 | | "Set the groups of the current process to list."); |
6008 | | |
6009 | | #define OS_SETGROUPS_METHODDEF \ |
6010 | | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
6011 | | |
6012 | | #endif /* defined(HAVE_SETGROUPS) */ |
6013 | | |
6014 | | #if defined(HAVE_WAIT3) |
6015 | | |
6016 | | PyDoc_STRVAR(os_wait3__doc__, |
6017 | | "wait3($module, /, options)\n" |
6018 | | "--\n" |
6019 | | "\n" |
6020 | | "Wait for completion of a child process.\n" |
6021 | | "\n" |
6022 | | "Returns a tuple of information about the child process:\n" |
6023 | | " (pid, status, rusage)"); |
6024 | | |
6025 | | #define OS_WAIT3_METHODDEF \ |
6026 | | {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__}, |
6027 | | |
6028 | | static PyObject * |
6029 | | os_wait3_impl(PyObject *module, int options); |
6030 | | |
6031 | | static PyObject * |
6032 | | os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6033 | 0 | { |
6034 | 0 | PyObject *return_value = NULL; |
6035 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6036 | |
|
6037 | 0 | #define NUM_KEYWORDS 1 |
6038 | 0 | static struct { |
6039 | 0 | PyGC_Head _this_is_not_used; |
6040 | 0 | PyObject_VAR_HEAD |
6041 | 0 | Py_hash_t ob_hash; |
6042 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6043 | 0 | } _kwtuple = { |
6044 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6045 | 0 | .ob_hash = -1, |
6046 | 0 | .ob_item = { &_Py_ID(options), }, |
6047 | 0 | }; |
6048 | 0 | #undef NUM_KEYWORDS |
6049 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6050 | |
|
6051 | | #else // !Py_BUILD_CORE |
6052 | | # define KWTUPLE NULL |
6053 | | #endif // !Py_BUILD_CORE |
6054 | |
|
6055 | 0 | static const char * const _keywords[] = {"options", NULL}; |
6056 | 0 | static _PyArg_Parser _parser = { |
6057 | 0 | .keywords = _keywords, |
6058 | 0 | .fname = "wait3", |
6059 | 0 | .kwtuple = KWTUPLE, |
6060 | 0 | }; |
6061 | 0 | #undef KWTUPLE |
6062 | 0 | PyObject *argsbuf[1]; |
6063 | 0 | int options; |
6064 | |
|
6065 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6066 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6067 | 0 | if (!args) { |
6068 | 0 | goto exit; |
6069 | 0 | } |
6070 | 0 | options = PyLong_AsInt(args[0]); |
6071 | 0 | if (options == -1 && PyErr_Occurred()) { |
6072 | 0 | goto exit; |
6073 | 0 | } |
6074 | 0 | return_value = os_wait3_impl(module, options); |
6075 | |
|
6076 | 0 | exit: |
6077 | 0 | return return_value; |
6078 | 0 | } |
6079 | | |
6080 | | #endif /* defined(HAVE_WAIT3) */ |
6081 | | |
6082 | | #if defined(HAVE_WAIT4) |
6083 | | |
6084 | | PyDoc_STRVAR(os_wait4__doc__, |
6085 | | "wait4($module, /, pid, options)\n" |
6086 | | "--\n" |
6087 | | "\n" |
6088 | | "Wait for completion of a specific child process.\n" |
6089 | | "\n" |
6090 | | "Returns a tuple of information about the child process:\n" |
6091 | | " (pid, status, rusage)"); |
6092 | | |
6093 | | #define OS_WAIT4_METHODDEF \ |
6094 | | {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__}, |
6095 | | |
6096 | | static PyObject * |
6097 | | os_wait4_impl(PyObject *module, pid_t pid, int options); |
6098 | | |
6099 | | static PyObject * |
6100 | | os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6101 | 0 | { |
6102 | 0 | PyObject *return_value = NULL; |
6103 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6104 | |
|
6105 | 0 | #define NUM_KEYWORDS 2 |
6106 | 0 | static struct { |
6107 | 0 | PyGC_Head _this_is_not_used; |
6108 | 0 | PyObject_VAR_HEAD |
6109 | 0 | Py_hash_t ob_hash; |
6110 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6111 | 0 | } _kwtuple = { |
6112 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6113 | 0 | .ob_hash = -1, |
6114 | 0 | .ob_item = { &_Py_ID(pid), &_Py_ID(options), }, |
6115 | 0 | }; |
6116 | 0 | #undef NUM_KEYWORDS |
6117 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6118 | |
|
6119 | | #else // !Py_BUILD_CORE |
6120 | | # define KWTUPLE NULL |
6121 | | #endif // !Py_BUILD_CORE |
6122 | |
|
6123 | 0 | static const char * const _keywords[] = {"pid", "options", NULL}; |
6124 | 0 | static _PyArg_Parser _parser = { |
6125 | 0 | .keywords = _keywords, |
6126 | 0 | .fname = "wait4", |
6127 | 0 | .kwtuple = KWTUPLE, |
6128 | 0 | }; |
6129 | 0 | #undef KWTUPLE |
6130 | 0 | PyObject *argsbuf[2]; |
6131 | 0 | pid_t pid; |
6132 | 0 | int options; |
6133 | |
|
6134 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6135 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6136 | 0 | if (!args) { |
6137 | 0 | goto exit; |
6138 | 0 | } |
6139 | 0 | pid = PyLong_AsPid(args[0]); |
6140 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6141 | 0 | goto exit; |
6142 | 0 | } |
6143 | 0 | options = PyLong_AsInt(args[1]); |
6144 | 0 | if (options == -1 && PyErr_Occurred()) { |
6145 | 0 | goto exit; |
6146 | 0 | } |
6147 | 0 | return_value = os_wait4_impl(module, pid, options); |
6148 | |
|
6149 | 0 | exit: |
6150 | 0 | return return_value; |
6151 | 0 | } |
6152 | | |
6153 | | #endif /* defined(HAVE_WAIT4) */ |
6154 | | |
6155 | | #if defined(HAVE_WAITID) |
6156 | | |
6157 | | PyDoc_STRVAR(os_waitid__doc__, |
6158 | | "waitid($module, idtype, id, options, /)\n" |
6159 | | "--\n" |
6160 | | "\n" |
6161 | | "Returns the result of waiting for a process or processes.\n" |
6162 | | "\n" |
6163 | | " idtype\n" |
6164 | | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
6165 | | " id\n" |
6166 | | " The id to wait on.\n" |
6167 | | " options\n" |
6168 | | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
6169 | | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
6170 | | "\n" |
6171 | | "Returns either waitid_result or None if WNOHANG is specified and there\n" |
6172 | | "are no children in a waitable state."); |
6173 | | |
6174 | | #define OS_WAITID_METHODDEF \ |
6175 | | {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__}, |
6176 | | |
6177 | | static PyObject * |
6178 | | os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options); |
6179 | | |
6180 | | static PyObject * |
6181 | | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6182 | 0 | { |
6183 | 0 | PyObject *return_value = NULL; |
6184 | 0 | idtype_t idtype; |
6185 | 0 | id_t id; |
6186 | 0 | int options; |
6187 | |
|
6188 | 0 | if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) { |
6189 | 0 | goto exit; |
6190 | 0 | } |
6191 | 0 | if (!idtype_t_converter(args[0], &idtype)) { |
6192 | 0 | goto exit; |
6193 | 0 | } |
6194 | 0 | id = (id_t)PyLong_AsPid(args[1]); |
6195 | 0 | if (id == (id_t)(-1) && PyErr_Occurred()) { |
6196 | 0 | goto exit; |
6197 | 0 | } |
6198 | 0 | options = PyLong_AsInt(args[2]); |
6199 | 0 | if (options == -1 && PyErr_Occurred()) { |
6200 | 0 | goto exit; |
6201 | 0 | } |
6202 | 0 | return_value = os_waitid_impl(module, idtype, id, options); |
6203 | |
|
6204 | 0 | exit: |
6205 | 0 | return return_value; |
6206 | 0 | } |
6207 | | |
6208 | | #endif /* defined(HAVE_WAITID) */ |
6209 | | |
6210 | | #if defined(HAVE_WAITPID) |
6211 | | |
6212 | | PyDoc_STRVAR(os_waitpid__doc__, |
6213 | | "waitpid($module, pid, options, /)\n" |
6214 | | "--\n" |
6215 | | "\n" |
6216 | | "Wait for completion of a given child process.\n" |
6217 | | "\n" |
6218 | | "Returns a tuple of information regarding the child process:\n" |
6219 | | " (pid, status)\n" |
6220 | | "\n" |
6221 | | "The options argument is ignored on Windows."); |
6222 | | |
6223 | | #define OS_WAITPID_METHODDEF \ |
6224 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6225 | | |
6226 | | static PyObject * |
6227 | | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
6228 | | |
6229 | | static PyObject * |
6230 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6231 | 0 | { |
6232 | 0 | PyObject *return_value = NULL; |
6233 | 0 | pid_t pid; |
6234 | 0 | int options; |
6235 | |
|
6236 | 0 | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6237 | 0 | goto exit; |
6238 | 0 | } |
6239 | 0 | pid = PyLong_AsPid(args[0]); |
6240 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6241 | 0 | goto exit; |
6242 | 0 | } |
6243 | 0 | options = PyLong_AsInt(args[1]); |
6244 | 0 | if (options == -1 && PyErr_Occurred()) { |
6245 | 0 | goto exit; |
6246 | 0 | } |
6247 | 0 | return_value = os_waitpid_impl(module, pid, options); |
6248 | |
|
6249 | 0 | exit: |
6250 | 0 | return return_value; |
6251 | 0 | } |
6252 | | |
6253 | | #endif /* defined(HAVE_WAITPID) */ |
6254 | | |
6255 | | #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) |
6256 | | |
6257 | | PyDoc_STRVAR(os_waitpid__doc__, |
6258 | | "waitpid($module, pid, options, /)\n" |
6259 | | "--\n" |
6260 | | "\n" |
6261 | | "Wait for completion of a given process.\n" |
6262 | | "\n" |
6263 | | "Returns a tuple of information regarding the process:\n" |
6264 | | " (pid, status << 8)\n" |
6265 | | "\n" |
6266 | | "The options argument is ignored on Windows."); |
6267 | | |
6268 | | #define OS_WAITPID_METHODDEF \ |
6269 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6270 | | |
6271 | | static PyObject * |
6272 | | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
6273 | | |
6274 | | static PyObject * |
6275 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6276 | | { |
6277 | | PyObject *return_value = NULL; |
6278 | | intptr_t pid; |
6279 | | int options; |
6280 | | |
6281 | | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6282 | | goto exit; |
6283 | | } |
6284 | | pid = (intptr_t)PyLong_AsVoidPtr(args[0]); |
6285 | | if (!pid && PyErr_Occurred()) { |
6286 | | goto exit; |
6287 | | } |
6288 | | options = PyLong_AsInt(args[1]); |
6289 | | if (options == -1 && PyErr_Occurred()) { |
6290 | | goto exit; |
6291 | | } |
6292 | | return_value = os_waitpid_impl(module, pid, options); |
6293 | | |
6294 | | exit: |
6295 | | return return_value; |
6296 | | } |
6297 | | |
6298 | | #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */ |
6299 | | |
6300 | | #if defined(HAVE_WAIT) |
6301 | | |
6302 | | PyDoc_STRVAR(os_wait__doc__, |
6303 | | "wait($module, /)\n" |
6304 | | "--\n" |
6305 | | "\n" |
6306 | | "Wait for completion of a child process.\n" |
6307 | | "\n" |
6308 | | "Returns a tuple of information about the child process:\n" |
6309 | | " (pid, status)"); |
6310 | | |
6311 | | #define OS_WAIT_METHODDEF \ |
6312 | | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
6313 | | |
6314 | | static PyObject * |
6315 | | os_wait_impl(PyObject *module); |
6316 | | |
6317 | | static PyObject * |
6318 | | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6319 | 0 | { |
6320 | 0 | return os_wait_impl(module); |
6321 | 0 | } |
6322 | | |
6323 | | #endif /* defined(HAVE_WAIT) */ |
6324 | | |
6325 | | #if (defined(HAVE_PIDFD_OPEN) || (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))) |
6326 | | |
6327 | | PyDoc_STRVAR(os_pidfd_open__doc__, |
6328 | | "pidfd_open($module, /, pid, flags=0)\n" |
6329 | | "--\n" |
6330 | | "\n" |
6331 | | "Return a file descriptor referring to the process *pid*.\n" |
6332 | | "\n" |
6333 | | "The descriptor can be used to perform process management without races\n" |
6334 | | "and signals."); |
6335 | | |
6336 | | #define OS_PIDFD_OPEN_METHODDEF \ |
6337 | | {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__}, |
6338 | | |
6339 | | static PyObject * |
6340 | | os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags); |
6341 | | |
6342 | | static PyObject * |
6343 | | os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6344 | 4 | { |
6345 | 4 | PyObject *return_value = NULL; |
6346 | 4 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6347 | | |
6348 | 4 | #define NUM_KEYWORDS 2 |
6349 | 4 | static struct { |
6350 | 4 | PyGC_Head _this_is_not_used; |
6351 | 4 | PyObject_VAR_HEAD |
6352 | 4 | Py_hash_t ob_hash; |
6353 | 4 | PyObject *ob_item[NUM_KEYWORDS]; |
6354 | 4 | } _kwtuple = { |
6355 | 4 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6356 | 4 | .ob_hash = -1, |
6357 | 4 | .ob_item = { &_Py_ID(pid), &_Py_ID(flags), }, |
6358 | 4 | }; |
6359 | 4 | #undef NUM_KEYWORDS |
6360 | 4 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6361 | | |
6362 | | #else // !Py_BUILD_CORE |
6363 | | # define KWTUPLE NULL |
6364 | | #endif // !Py_BUILD_CORE |
6365 | | |
6366 | 4 | static const char * const _keywords[] = {"pid", "flags", NULL}; |
6367 | 4 | static _PyArg_Parser _parser = { |
6368 | 4 | .keywords = _keywords, |
6369 | 4 | .fname = "pidfd_open", |
6370 | 4 | .kwtuple = KWTUPLE, |
6371 | 4 | }; |
6372 | 4 | #undef KWTUPLE |
6373 | 4 | PyObject *argsbuf[2]; |
6374 | 4 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6375 | 4 | pid_t pid; |
6376 | 4 | unsigned int flags = 0; |
6377 | | |
6378 | 4 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6379 | 4 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6380 | 4 | if (!args) { |
6381 | 0 | goto exit; |
6382 | 0 | } |
6383 | 4 | pid = PyLong_AsPid(args[0]); |
6384 | 4 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6385 | 0 | goto exit; |
6386 | 0 | } |
6387 | 4 | if (!noptargs) { |
6388 | 0 | goto skip_optional_pos; |
6389 | 0 | } |
6390 | 4 | if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) { |
6391 | 0 | goto exit; |
6392 | 0 | } |
6393 | 4 | skip_optional_pos: |
6394 | 4 | return_value = os_pidfd_open_impl(module, pid, flags); |
6395 | | |
6396 | 4 | exit: |
6397 | 4 | return return_value; |
6398 | 4 | } |
6399 | | |
6400 | | #endif /* (defined(HAVE_PIDFD_OPEN) || (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))) */ |
6401 | | |
6402 | | #if (defined(HAVE_PIDFD_GETFD) || (defined(__linux__) && defined(__NR_pidfd_getfd) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))) |
6403 | | |
6404 | | PyDoc_STRVAR(os_pidfd_getfd__doc__, |
6405 | | "pidfd_getfd($module, /, pidfd, targetfd, *, flags=0)\n" |
6406 | | "--\n" |
6407 | | "\n" |
6408 | | "Duplicate a file descriptor from the process referred to by *pidfd*.\n" |
6409 | | "\n" |
6410 | | " pidfd\n" |
6411 | | " A process file descriptor.\n" |
6412 | | " targetfd\n" |
6413 | | " The file descriptor to duplicate from the target process.\n" |
6414 | | " flags\n" |
6415 | | " Reserved, must be 0."); |
6416 | | |
6417 | | #define OS_PIDFD_GETFD_METHODDEF \ |
6418 | | {"pidfd_getfd", _PyCFunction_CAST(os_pidfd_getfd), METH_FASTCALL|METH_KEYWORDS, os_pidfd_getfd__doc__}, |
6419 | | |
6420 | | static PyObject * |
6421 | | os_pidfd_getfd_impl(PyObject *module, int pidfd, int targetfd, |
6422 | | unsigned int flags); |
6423 | | |
6424 | | static PyObject * |
6425 | | os_pidfd_getfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6426 | | { |
6427 | | PyObject *return_value = NULL; |
6428 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6429 | | |
6430 | | #define NUM_KEYWORDS 3 |
6431 | | static struct { |
6432 | | PyGC_Head _this_is_not_used; |
6433 | | PyObject_VAR_HEAD |
6434 | | Py_hash_t ob_hash; |
6435 | | PyObject *ob_item[NUM_KEYWORDS]; |
6436 | | } _kwtuple = { |
6437 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6438 | | .ob_hash = -1, |
6439 | | .ob_item = { &_Py_ID(pidfd), &_Py_ID(targetfd), &_Py_ID(flags), }, |
6440 | | }; |
6441 | | #undef NUM_KEYWORDS |
6442 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6443 | | |
6444 | | #else // !Py_BUILD_CORE |
6445 | | # define KWTUPLE NULL |
6446 | | #endif // !Py_BUILD_CORE |
6447 | | |
6448 | | static const char * const _keywords[] = {"pidfd", "targetfd", "flags", NULL}; |
6449 | | static _PyArg_Parser _parser = { |
6450 | | .keywords = _keywords, |
6451 | | .fname = "pidfd_getfd", |
6452 | | .kwtuple = KWTUPLE, |
6453 | | }; |
6454 | | #undef KWTUPLE |
6455 | | PyObject *argsbuf[3]; |
6456 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
6457 | | int pidfd; |
6458 | | int targetfd; |
6459 | | unsigned int flags = 0; |
6460 | | |
6461 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6462 | | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6463 | | if (!args) { |
6464 | | goto exit; |
6465 | | } |
6466 | | pidfd = PyLong_AsInt(args[0]); |
6467 | | if (pidfd == -1 && PyErr_Occurred()) { |
6468 | | goto exit; |
6469 | | } |
6470 | | targetfd = PyLong_AsInt(args[1]); |
6471 | | if (targetfd == -1 && PyErr_Occurred()) { |
6472 | | goto exit; |
6473 | | } |
6474 | | if (!noptargs) { |
6475 | | goto skip_optional_kwonly; |
6476 | | } |
6477 | | if (!_PyLong_UnsignedInt_Converter(args[2], &flags)) { |
6478 | | goto exit; |
6479 | | } |
6480 | | skip_optional_kwonly: |
6481 | | return_value = os_pidfd_getfd_impl(module, pidfd, targetfd, flags); |
6482 | | |
6483 | | exit: |
6484 | | return return_value; |
6485 | | } |
6486 | | |
6487 | | #endif /* (defined(HAVE_PIDFD_GETFD) || (defined(__linux__) && defined(__NR_pidfd_getfd) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))) */ |
6488 | | |
6489 | | #if defined(HAVE_SETNS) |
6490 | | |
6491 | | PyDoc_STRVAR(os_setns__doc__, |
6492 | | "setns($module, /, fd, nstype=0)\n" |
6493 | | "--\n" |
6494 | | "\n" |
6495 | | "Move the calling thread into different namespaces.\n" |
6496 | | "\n" |
6497 | | " fd\n" |
6498 | | " A file descriptor to a namespace.\n" |
6499 | | " nstype\n" |
6500 | | " Type of namespace."); |
6501 | | |
6502 | | #define OS_SETNS_METHODDEF \ |
6503 | | {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__}, |
6504 | | |
6505 | | static PyObject * |
6506 | | os_setns_impl(PyObject *module, int fd, int nstype); |
6507 | | |
6508 | | static PyObject * |
6509 | | os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6510 | 0 | { |
6511 | 0 | PyObject *return_value = NULL; |
6512 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6513 | |
|
6514 | 0 | #define NUM_KEYWORDS 2 |
6515 | 0 | static struct { |
6516 | 0 | PyGC_Head _this_is_not_used; |
6517 | 0 | PyObject_VAR_HEAD |
6518 | 0 | Py_hash_t ob_hash; |
6519 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6520 | 0 | } _kwtuple = { |
6521 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6522 | 0 | .ob_hash = -1, |
6523 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), }, |
6524 | 0 | }; |
6525 | 0 | #undef NUM_KEYWORDS |
6526 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6527 | |
|
6528 | | #else // !Py_BUILD_CORE |
6529 | | # define KWTUPLE NULL |
6530 | | #endif // !Py_BUILD_CORE |
6531 | |
|
6532 | 0 | static const char * const _keywords[] = {"fd", "nstype", NULL}; |
6533 | 0 | static _PyArg_Parser _parser = { |
6534 | 0 | .keywords = _keywords, |
6535 | 0 | .fname = "setns", |
6536 | 0 | .kwtuple = KWTUPLE, |
6537 | 0 | }; |
6538 | 0 | #undef KWTUPLE |
6539 | 0 | PyObject *argsbuf[2]; |
6540 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6541 | 0 | int fd; |
6542 | 0 | int nstype = 0; |
6543 | |
|
6544 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6545 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6546 | 0 | if (!args) { |
6547 | 0 | goto exit; |
6548 | 0 | } |
6549 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6550 | 0 | if (fd < 0) { |
6551 | 0 | goto exit; |
6552 | 0 | } |
6553 | 0 | if (!noptargs) { |
6554 | 0 | goto skip_optional_pos; |
6555 | 0 | } |
6556 | 0 | nstype = PyLong_AsInt(args[1]); |
6557 | 0 | if (nstype == -1 && PyErr_Occurred()) { |
6558 | 0 | goto exit; |
6559 | 0 | } |
6560 | 0 | skip_optional_pos: |
6561 | 0 | return_value = os_setns_impl(module, fd, nstype); |
6562 | |
|
6563 | 0 | exit: |
6564 | 0 | return return_value; |
6565 | 0 | } |
6566 | | |
6567 | | #endif /* defined(HAVE_SETNS) */ |
6568 | | |
6569 | | #if defined(HAVE_UNSHARE) |
6570 | | |
6571 | | PyDoc_STRVAR(os_unshare__doc__, |
6572 | | "unshare($module, /, flags)\n" |
6573 | | "--\n" |
6574 | | "\n" |
6575 | | "Disassociate parts of a process (or thread) execution context.\n" |
6576 | | "\n" |
6577 | | " flags\n" |
6578 | | " Namespaces to be unshared."); |
6579 | | |
6580 | | #define OS_UNSHARE_METHODDEF \ |
6581 | | {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__}, |
6582 | | |
6583 | | static PyObject * |
6584 | | os_unshare_impl(PyObject *module, int flags); |
6585 | | |
6586 | | static PyObject * |
6587 | | os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6588 | 0 | { |
6589 | 0 | PyObject *return_value = NULL; |
6590 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6591 | |
|
6592 | 0 | #define NUM_KEYWORDS 1 |
6593 | 0 | static struct { |
6594 | 0 | PyGC_Head _this_is_not_used; |
6595 | 0 | PyObject_VAR_HEAD |
6596 | 0 | Py_hash_t ob_hash; |
6597 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6598 | 0 | } _kwtuple = { |
6599 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6600 | 0 | .ob_hash = -1, |
6601 | 0 | .ob_item = { &_Py_ID(flags), }, |
6602 | 0 | }; |
6603 | 0 | #undef NUM_KEYWORDS |
6604 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6605 | |
|
6606 | | #else // !Py_BUILD_CORE |
6607 | | # define KWTUPLE NULL |
6608 | | #endif // !Py_BUILD_CORE |
6609 | |
|
6610 | 0 | static const char * const _keywords[] = {"flags", NULL}; |
6611 | 0 | static _PyArg_Parser _parser = { |
6612 | 0 | .keywords = _keywords, |
6613 | 0 | .fname = "unshare", |
6614 | 0 | .kwtuple = KWTUPLE, |
6615 | 0 | }; |
6616 | 0 | #undef KWTUPLE |
6617 | 0 | PyObject *argsbuf[1]; |
6618 | 0 | int flags; |
6619 | |
|
6620 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6621 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6622 | 0 | if (!args) { |
6623 | 0 | goto exit; |
6624 | 0 | } |
6625 | 0 | flags = PyLong_AsInt(args[0]); |
6626 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6627 | 0 | goto exit; |
6628 | 0 | } |
6629 | 0 | return_value = os_unshare_impl(module, flags); |
6630 | |
|
6631 | 0 | exit: |
6632 | 0 | return return_value; |
6633 | 0 | } |
6634 | | |
6635 | | #endif /* defined(HAVE_UNSHARE) */ |
6636 | | |
6637 | | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
6638 | | |
6639 | | PyDoc_STRVAR(os_readlink__doc__, |
6640 | | "readlink($module, /, path, *, dir_fd=None)\n" |
6641 | | "--\n" |
6642 | | "\n" |
6643 | | "Return a string representing the path to which the symbolic link points.\n" |
6644 | | "\n" |
6645 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
6646 | | "a directory, and path should be relative; path will then be relative to\n" |
6647 | | "that directory.\n" |
6648 | | "\n" |
6649 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
6650 | | "using it will raise a NotImplementedError.\n" |
6651 | | "\n" |
6652 | | "On Linux, Android, macOS and iOS, path may be a file descriptor\n" |
6653 | | "referring to a symlink. If it is, dir_fd must be None."); |
6654 | | |
6655 | | #define OS_READLINK_METHODDEF \ |
6656 | | {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__}, |
6657 | | |
6658 | | static PyObject * |
6659 | | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
6660 | | |
6661 | | static PyObject * |
6662 | | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6663 | 6 | { |
6664 | 6 | PyObject *return_value = NULL; |
6665 | 6 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6666 | | |
6667 | 6 | #define NUM_KEYWORDS 2 |
6668 | 6 | static struct { |
6669 | 6 | PyGC_Head _this_is_not_used; |
6670 | 6 | PyObject_VAR_HEAD |
6671 | 6 | Py_hash_t ob_hash; |
6672 | 6 | PyObject *ob_item[NUM_KEYWORDS]; |
6673 | 6 | } _kwtuple = { |
6674 | 6 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6675 | 6 | .ob_hash = -1, |
6676 | 6 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
6677 | 6 | }; |
6678 | 6 | #undef NUM_KEYWORDS |
6679 | 6 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6680 | | |
6681 | | #else // !Py_BUILD_CORE |
6682 | | # define KWTUPLE NULL |
6683 | | #endif // !Py_BUILD_CORE |
6684 | | |
6685 | 6 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
6686 | 6 | static _PyArg_Parser _parser = { |
6687 | 6 | .keywords = _keywords, |
6688 | 6 | .fname = "readlink", |
6689 | 6 | .kwtuple = KWTUPLE, |
6690 | 6 | }; |
6691 | 6 | #undef KWTUPLE |
6692 | 6 | PyObject *argsbuf[2]; |
6693 | 6 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6694 | 6 | path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 1); |
6695 | 6 | int dir_fd = DEFAULT_DIR_FD; |
6696 | | |
6697 | 6 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6698 | 6 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6699 | 6 | if (!args) { |
6700 | 0 | goto exit; |
6701 | 0 | } |
6702 | 6 | if (!path_converter(args[0], &path)) { |
6703 | 0 | goto exit; |
6704 | 0 | } |
6705 | 6 | if (!noptargs) { |
6706 | 6 | goto skip_optional_kwonly; |
6707 | 6 | } |
6708 | 0 | if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
6709 | 0 | goto exit; |
6710 | 0 | } |
6711 | 6 | skip_optional_kwonly: |
6712 | 6 | return_value = os_readlink_impl(module, &path, dir_fd); |
6713 | | |
6714 | 6 | exit: |
6715 | | /* Cleanup for path */ |
6716 | 6 | path_cleanup(&path); |
6717 | | |
6718 | 6 | return return_value; |
6719 | 6 | } |
6720 | | |
6721 | | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
6722 | | |
6723 | | #if defined(HAVE_SYMLINK) |
6724 | | |
6725 | | PyDoc_STRVAR(os_symlink__doc__, |
6726 | | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
6727 | | "--\n" |
6728 | | "\n" |
6729 | | "Create a symbolic link pointing to src named dst.\n" |
6730 | | "\n" |
6731 | | "target_is_directory is required on Windows if the target is to be\n" |
6732 | | "interpreted as a directory. (On Windows, symlink requires Windows 6.0\n" |
6733 | | "or greater, and raises a NotImplementedError otherwise.)\n" |
6734 | | "target_is_directory is ignored on non-Windows platforms.\n" |
6735 | | "\n" |
6736 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
6737 | | "a directory, and path should be relative; path will then be relative\n" |
6738 | | "to that directory.\n" |
6739 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
6740 | | "using it will raise a NotImplementedError."); |
6741 | | |
6742 | | #define OS_SYMLINK_METHODDEF \ |
6743 | | {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__}, |
6744 | | |
6745 | | static PyObject * |
6746 | | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
6747 | | int target_is_directory, int dir_fd); |
6748 | | |
6749 | | static PyObject * |
6750 | | os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6751 | 0 | { |
6752 | 0 | PyObject *return_value = NULL; |
6753 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6754 | |
|
6755 | 0 | #define NUM_KEYWORDS 4 |
6756 | 0 | static struct { |
6757 | 0 | PyGC_Head _this_is_not_used; |
6758 | 0 | PyObject_VAR_HEAD |
6759 | 0 | Py_hash_t ob_hash; |
6760 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6761 | 0 | } _kwtuple = { |
6762 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6763 | 0 | .ob_hash = -1, |
6764 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), }, |
6765 | 0 | }; |
6766 | 0 | #undef NUM_KEYWORDS |
6767 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6768 | |
|
6769 | | #else // !Py_BUILD_CORE |
6770 | | # define KWTUPLE NULL |
6771 | | #endif // !Py_BUILD_CORE |
6772 | |
|
6773 | 0 | static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
6774 | 0 | static _PyArg_Parser _parser = { |
6775 | 0 | .keywords = _keywords, |
6776 | 0 | .fname = "symlink", |
6777 | 0 | .kwtuple = KWTUPLE, |
6778 | 0 | }; |
6779 | 0 | #undef KWTUPLE |
6780 | 0 | PyObject *argsbuf[4]; |
6781 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
6782 | 0 | path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0); |
6783 | 0 | path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0); |
6784 | 0 | int target_is_directory = 0; |
6785 | 0 | int dir_fd = DEFAULT_DIR_FD; |
6786 | |
|
6787 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6788 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6789 | 0 | if (!args) { |
6790 | 0 | goto exit; |
6791 | 0 | } |
6792 | 0 | if (!path_converter(args[0], &src)) { |
6793 | 0 | goto exit; |
6794 | 0 | } |
6795 | 0 | if (!path_converter(args[1], &dst)) { |
6796 | 0 | goto exit; |
6797 | 0 | } |
6798 | 0 | if (!noptargs) { |
6799 | 0 | goto skip_optional_pos; |
6800 | 0 | } |
6801 | 0 | if (args[2]) { |
6802 | 0 | target_is_directory = PyObject_IsTrue(args[2]); |
6803 | 0 | if (target_is_directory < 0) { |
6804 | 0 | goto exit; |
6805 | 0 | } |
6806 | 0 | if (!--noptargs) { |
6807 | 0 | goto skip_optional_pos; |
6808 | 0 | } |
6809 | 0 | } |
6810 | 0 | skip_optional_pos: |
6811 | 0 | if (!noptargs) { |
6812 | 0 | goto skip_optional_kwonly; |
6813 | 0 | } |
6814 | 0 | if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
6815 | 0 | goto exit; |
6816 | 0 | } |
6817 | 0 | skip_optional_kwonly: |
6818 | 0 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
6819 | |
|
6820 | 0 | exit: |
6821 | | /* Cleanup for src */ |
6822 | 0 | path_cleanup(&src); |
6823 | | /* Cleanup for dst */ |
6824 | 0 | path_cleanup(&dst); |
6825 | |
|
6826 | 0 | return return_value; |
6827 | 0 | } |
6828 | | |
6829 | | #endif /* defined(HAVE_SYMLINK) */ |
6830 | | |
6831 | | PyDoc_STRVAR(os_times__doc__, |
6832 | | "times($module, /)\n" |
6833 | | "--\n" |
6834 | | "\n" |
6835 | | "Return a collection containing process timing information.\n" |
6836 | | "\n" |
6837 | | "The object returned behaves like a named tuple with these fields:\n" |
6838 | | " (utime, stime, cutime, cstime, elapsed_time)\n" |
6839 | | "All fields are floating-point numbers."); |
6840 | | |
6841 | | #define OS_TIMES_METHODDEF \ |
6842 | | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
6843 | | |
6844 | | static PyObject * |
6845 | | os_times_impl(PyObject *module); |
6846 | | |
6847 | | static PyObject * |
6848 | | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6849 | 0 | { |
6850 | 0 | return os_times_impl(module); |
6851 | 0 | } |
6852 | | |
6853 | | #if defined(HAVE_TIMERFD_CREATE) |
6854 | | |
6855 | | PyDoc_STRVAR(os_timerfd_create__doc__, |
6856 | | "timerfd_create($module, clockid, /, *, flags=0)\n" |
6857 | | "--\n" |
6858 | | "\n" |
6859 | | "Create and return a timer file descriptor.\n" |
6860 | | "\n" |
6861 | | " clockid\n" |
6862 | | " A valid clock ID constant as timer file descriptor.\n" |
6863 | | "\n" |
6864 | | " time.CLOCK_REALTIME\n" |
6865 | | " time.CLOCK_MONOTONIC\n" |
6866 | | " time.CLOCK_BOOTTIME\n" |
6867 | | " flags\n" |
6868 | | " 0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n" |
6869 | | "\n" |
6870 | | " os.TFD_NONBLOCK\n" |
6871 | | " If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n" |
6872 | | " If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n" |
6873 | | "\n" |
6874 | | " os.TFD_CLOEXEC\n" |
6875 | | " If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag"); |
6876 | | |
6877 | | #define OS_TIMERFD_CREATE_METHODDEF \ |
6878 | | {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__}, |
6879 | | |
6880 | | static PyObject * |
6881 | | os_timerfd_create_impl(PyObject *module, int clockid, int flags); |
6882 | | |
6883 | | static PyObject * |
6884 | | os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6885 | 0 | { |
6886 | 0 | PyObject *return_value = NULL; |
6887 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6888 | |
|
6889 | 0 | #define NUM_KEYWORDS 1 |
6890 | 0 | static struct { |
6891 | 0 | PyGC_Head _this_is_not_used; |
6892 | 0 | PyObject_VAR_HEAD |
6893 | 0 | Py_hash_t ob_hash; |
6894 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6895 | 0 | } _kwtuple = { |
6896 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6897 | 0 | .ob_hash = -1, |
6898 | 0 | .ob_item = { &_Py_ID(flags), }, |
6899 | 0 | }; |
6900 | 0 | #undef NUM_KEYWORDS |
6901 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6902 | |
|
6903 | | #else // !Py_BUILD_CORE |
6904 | | # define KWTUPLE NULL |
6905 | | #endif // !Py_BUILD_CORE |
6906 | |
|
6907 | 0 | static const char * const _keywords[] = {"", "flags", NULL}; |
6908 | 0 | static _PyArg_Parser _parser = { |
6909 | 0 | .keywords = _keywords, |
6910 | 0 | .fname = "timerfd_create", |
6911 | 0 | .kwtuple = KWTUPLE, |
6912 | 0 | }; |
6913 | 0 | #undef KWTUPLE |
6914 | 0 | PyObject *argsbuf[2]; |
6915 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6916 | 0 | int clockid; |
6917 | 0 | int flags = 0; |
6918 | |
|
6919 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6920 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6921 | 0 | if (!args) { |
6922 | 0 | goto exit; |
6923 | 0 | } |
6924 | 0 | clockid = PyLong_AsInt(args[0]); |
6925 | 0 | if (clockid == -1 && PyErr_Occurred()) { |
6926 | 0 | goto exit; |
6927 | 0 | } |
6928 | 0 | if (!noptargs) { |
6929 | 0 | goto skip_optional_kwonly; |
6930 | 0 | } |
6931 | 0 | flags = PyLong_AsInt(args[1]); |
6932 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6933 | 0 | goto exit; |
6934 | 0 | } |
6935 | 0 | skip_optional_kwonly: |
6936 | 0 | return_value = os_timerfd_create_impl(module, clockid, flags); |
6937 | |
|
6938 | 0 | exit: |
6939 | 0 | return return_value; |
6940 | 0 | } |
6941 | | |
6942 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6943 | | |
6944 | | #if defined(HAVE_TIMERFD_CREATE) |
6945 | | |
6946 | | PyDoc_STRVAR(os_timerfd_settime__doc__, |
6947 | | "timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n" |
6948 | | "--\n" |
6949 | | "\n" |
6950 | | "Alter a timer file descriptor\'s internal timer in seconds.\n" |
6951 | | "\n" |
6952 | | " fd\n" |
6953 | | " A timer file descriptor.\n" |
6954 | | " flags\n" |
6955 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
6956 | | " initial\n" |
6957 | | " The initial expiration time, in seconds.\n" |
6958 | | " interval\n" |
6959 | | " The timer\'s interval, in seconds."); |
6960 | | |
6961 | | #define OS_TIMERFD_SETTIME_METHODDEF \ |
6962 | | {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__}, |
6963 | | |
6964 | | static PyObject * |
6965 | | os_timerfd_settime_impl(PyObject *module, int fd, int flags, |
6966 | | double initial_double, double interval_double); |
6967 | | |
6968 | | static PyObject * |
6969 | | os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6970 | 0 | { |
6971 | 0 | PyObject *return_value = NULL; |
6972 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6973 | |
|
6974 | 0 | #define NUM_KEYWORDS 3 |
6975 | 0 | static struct { |
6976 | 0 | PyGC_Head _this_is_not_used; |
6977 | 0 | PyObject_VAR_HEAD |
6978 | 0 | Py_hash_t ob_hash; |
6979 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6980 | 0 | } _kwtuple = { |
6981 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6982 | 0 | .ob_hash = -1, |
6983 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
6984 | 0 | }; |
6985 | 0 | #undef NUM_KEYWORDS |
6986 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6987 | |
|
6988 | | #else // !Py_BUILD_CORE |
6989 | | # define KWTUPLE NULL |
6990 | | #endif // !Py_BUILD_CORE |
6991 | |
|
6992 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
6993 | 0 | static _PyArg_Parser _parser = { |
6994 | 0 | .keywords = _keywords, |
6995 | 0 | .fname = "timerfd_settime", |
6996 | 0 | .kwtuple = KWTUPLE, |
6997 | 0 | }; |
6998 | 0 | #undef KWTUPLE |
6999 | 0 | PyObject *argsbuf[4]; |
7000 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
7001 | 0 | int fd; |
7002 | 0 | int flags = 0; |
7003 | 0 | double initial_double = 0.0; |
7004 | 0 | double interval_double = 0.0; |
7005 | |
|
7006 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7007 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7008 | 0 | if (!args) { |
7009 | 0 | goto exit; |
7010 | 0 | } |
7011 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
7012 | 0 | if (fd < 0) { |
7013 | 0 | goto exit; |
7014 | 0 | } |
7015 | 0 | if (!noptargs) { |
7016 | 0 | goto skip_optional_kwonly; |
7017 | 0 | } |
7018 | 0 | if (args[1]) { |
7019 | 0 | flags = PyLong_AsInt(args[1]); |
7020 | 0 | if (flags == -1 && PyErr_Occurred()) { |
7021 | 0 | goto exit; |
7022 | 0 | } |
7023 | 0 | if (!--noptargs) { |
7024 | 0 | goto skip_optional_kwonly; |
7025 | 0 | } |
7026 | 0 | } |
7027 | 0 | if (args[2]) { |
7028 | 0 | if (PyFloat_CheckExact(args[2])) { |
7029 | 0 | initial_double = PyFloat_AS_DOUBLE(args[2]); |
7030 | 0 | } |
7031 | 0 | else |
7032 | 0 | { |
7033 | 0 | initial_double = PyFloat_AsDouble(args[2]); |
7034 | 0 | if (initial_double == -1.0 && PyErr_Occurred()) { |
7035 | 0 | goto exit; |
7036 | 0 | } |
7037 | 0 | } |
7038 | 0 | if (!--noptargs) { |
7039 | 0 | goto skip_optional_kwonly; |
7040 | 0 | } |
7041 | 0 | } |
7042 | 0 | if (PyFloat_CheckExact(args[3])) { |
7043 | 0 | interval_double = PyFloat_AS_DOUBLE(args[3]); |
7044 | 0 | } |
7045 | 0 | else |
7046 | 0 | { |
7047 | 0 | interval_double = PyFloat_AsDouble(args[3]); |
7048 | 0 | if (interval_double == -1.0 && PyErr_Occurred()) { |
7049 | 0 | goto exit; |
7050 | 0 | } |
7051 | 0 | } |
7052 | 0 | skip_optional_kwonly: |
7053 | 0 | return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double); |
7054 | |
|
7055 | 0 | exit: |
7056 | 0 | return return_value; |
7057 | 0 | } |
7058 | | |
7059 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7060 | | |
7061 | | #if defined(HAVE_TIMERFD_CREATE) |
7062 | | |
7063 | | PyDoc_STRVAR(os_timerfd_settime_ns__doc__, |
7064 | | "timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n" |
7065 | | "--\n" |
7066 | | "\n" |
7067 | | "Alter a timer file descriptor\'s internal timer in nanoseconds.\n" |
7068 | | "\n" |
7069 | | " fd\n" |
7070 | | " A timer file descriptor.\n" |
7071 | | " flags\n" |
7072 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
7073 | | " initial\n" |
7074 | | " initial expiration timing in nanoseconds.\n" |
7075 | | " interval\n" |
7076 | | " interval for the timer in nanoseconds."); |
7077 | | |
7078 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF \ |
7079 | | {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__}, |
7080 | | |
7081 | | static PyObject * |
7082 | | os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags, |
7083 | | long long initial, long long interval); |
7084 | | |
7085 | | static PyObject * |
7086 | | os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7087 | 0 | { |
7088 | 0 | PyObject *return_value = NULL; |
7089 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7090 | |
|
7091 | 0 | #define NUM_KEYWORDS 3 |
7092 | 0 | static struct { |
7093 | 0 | PyGC_Head _this_is_not_used; |
7094 | 0 | PyObject_VAR_HEAD |
7095 | 0 | Py_hash_t ob_hash; |
7096 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7097 | 0 | } _kwtuple = { |
7098 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7099 | 0 | .ob_hash = -1, |
7100 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
7101 | 0 | }; |
7102 | 0 | #undef NUM_KEYWORDS |
7103 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7104 | |
|
7105 | | #else // !Py_BUILD_CORE |
7106 | | # define KWTUPLE NULL |
7107 | | #endif // !Py_BUILD_CORE |
7108 | |
|
7109 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
7110 | 0 | static _PyArg_Parser _parser = { |
7111 | 0 | .keywords = _keywords, |
7112 | 0 | .fname = "timerfd_settime_ns", |
7113 | 0 | .kwtuple = KWTUPLE, |
7114 | 0 | }; |
7115 | 0 | #undef KWTUPLE |
7116 | 0 | PyObject *argsbuf[4]; |
7117 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
7118 | 0 | int fd; |
7119 | 0 | int flags = 0; |
7120 | 0 | long long initial = 0; |
7121 | 0 | long long interval = 0; |
7122 | |
|
7123 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7124 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7125 | 0 | if (!args) { |
7126 | 0 | goto exit; |
7127 | 0 | } |
7128 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
7129 | 0 | if (fd < 0) { |
7130 | 0 | goto exit; |
7131 | 0 | } |
7132 | 0 | if (!noptargs) { |
7133 | 0 | goto skip_optional_kwonly; |
7134 | 0 | } |
7135 | 0 | if (args[1]) { |
7136 | 0 | flags = PyLong_AsInt(args[1]); |
7137 | 0 | if (flags == -1 && PyErr_Occurred()) { |
7138 | 0 | goto exit; |
7139 | 0 | } |
7140 | 0 | if (!--noptargs) { |
7141 | 0 | goto skip_optional_kwonly; |
7142 | 0 | } |
7143 | 0 | } |
7144 | 0 | if (args[2]) { |
7145 | 0 | initial = PyLong_AsLongLong(args[2]); |
7146 | 0 | if (initial == -1 && PyErr_Occurred()) { |
7147 | 0 | goto exit; |
7148 | 0 | } |
7149 | 0 | if (!--noptargs) { |
7150 | 0 | goto skip_optional_kwonly; |
7151 | 0 | } |
7152 | 0 | } |
7153 | 0 | interval = PyLong_AsLongLong(args[3]); |
7154 | 0 | if (interval == -1 && PyErr_Occurred()) { |
7155 | 0 | goto exit; |
7156 | 0 | } |
7157 | 0 | skip_optional_kwonly: |
7158 | 0 | return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval); |
7159 | |
|
7160 | 0 | exit: |
7161 | 0 | return return_value; |
7162 | 0 | } |
7163 | | |
7164 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7165 | | |
7166 | | #if defined(HAVE_TIMERFD_CREATE) |
7167 | | |
7168 | | PyDoc_STRVAR(os_timerfd_gettime__doc__, |
7169 | | "timerfd_gettime($module, fd, /)\n" |
7170 | | "--\n" |
7171 | | "\n" |
7172 | | "Return a tuple of a timer file descriptor\'s (next expiration, interval) in float seconds.\n" |
7173 | | "\n" |
7174 | | " fd\n" |
7175 | | " A timer file descriptor."); |
7176 | | |
7177 | | #define OS_TIMERFD_GETTIME_METHODDEF \ |
7178 | | {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__}, |
7179 | | |
7180 | | static PyObject * |
7181 | | os_timerfd_gettime_impl(PyObject *module, int fd); |
7182 | | |
7183 | | static PyObject * |
7184 | | os_timerfd_gettime(PyObject *module, PyObject *arg) |
7185 | 0 | { |
7186 | 0 | PyObject *return_value = NULL; |
7187 | 0 | int fd; |
7188 | |
|
7189 | 0 | fd = PyObject_AsFileDescriptor(arg); |
7190 | 0 | if (fd < 0) { |
7191 | 0 | goto exit; |
7192 | 0 | } |
7193 | 0 | return_value = os_timerfd_gettime_impl(module, fd); |
7194 | |
|
7195 | 0 | exit: |
7196 | 0 | return return_value; |
7197 | 0 | } |
7198 | | |
7199 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7200 | | |
7201 | | #if defined(HAVE_TIMERFD_CREATE) |
7202 | | |
7203 | | PyDoc_STRVAR(os_timerfd_gettime_ns__doc__, |
7204 | | "timerfd_gettime_ns($module, fd, /)\n" |
7205 | | "--\n" |
7206 | | "\n" |
7207 | | "Return a tuple of a timer file descriptor\'s (next expiration, interval) in nanoseconds.\n" |
7208 | | "\n" |
7209 | | " fd\n" |
7210 | | " A timer file descriptor."); |
7211 | | |
7212 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF \ |
7213 | | {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__}, |
7214 | | |
7215 | | static PyObject * |
7216 | | os_timerfd_gettime_ns_impl(PyObject *module, int fd); |
7217 | | |
7218 | | static PyObject * |
7219 | | os_timerfd_gettime_ns(PyObject *module, PyObject *arg) |
7220 | 0 | { |
7221 | 0 | PyObject *return_value = NULL; |
7222 | 0 | int fd; |
7223 | |
|
7224 | 0 | fd = PyObject_AsFileDescriptor(arg); |
7225 | 0 | if (fd < 0) { |
7226 | 0 | goto exit; |
7227 | 0 | } |
7228 | 0 | return_value = os_timerfd_gettime_ns_impl(module, fd); |
7229 | |
|
7230 | 0 | exit: |
7231 | 0 | return return_value; |
7232 | 0 | } |
7233 | | |
7234 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7235 | | |
7236 | | #if defined(HAVE_GETSID) |
7237 | | |
7238 | | PyDoc_STRVAR(os_getsid__doc__, |
7239 | | "getsid($module, pid, /)\n" |
7240 | | "--\n" |
7241 | | "\n" |
7242 | | "Call the system call getsid(pid) and return the result."); |
7243 | | |
7244 | | #define OS_GETSID_METHODDEF \ |
7245 | | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
7246 | | |
7247 | | static PyObject * |
7248 | | os_getsid_impl(PyObject *module, pid_t pid); |
7249 | | |
7250 | | static PyObject * |
7251 | | os_getsid(PyObject *module, PyObject *arg) |
7252 | 0 | { |
7253 | 0 | PyObject *return_value = NULL; |
7254 | 0 | pid_t pid; |
7255 | |
|
7256 | 0 | pid = PyLong_AsPid(arg); |
7257 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7258 | 0 | goto exit; |
7259 | 0 | } |
7260 | 0 | return_value = os_getsid_impl(module, pid); |
7261 | |
|
7262 | 0 | exit: |
7263 | 0 | return return_value; |
7264 | 0 | } |
7265 | | |
7266 | | #endif /* defined(HAVE_GETSID) */ |
7267 | | |
7268 | | #if defined(HAVE_SETSID) |
7269 | | |
7270 | | PyDoc_STRVAR(os_setsid__doc__, |
7271 | | "setsid($module, /)\n" |
7272 | | "--\n" |
7273 | | "\n" |
7274 | | "Call the system call setsid()."); |
7275 | | |
7276 | | #define OS_SETSID_METHODDEF \ |
7277 | | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
7278 | | |
7279 | | static PyObject * |
7280 | | os_setsid_impl(PyObject *module); |
7281 | | |
7282 | | static PyObject * |
7283 | | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
7284 | 0 | { |
7285 | 0 | return os_setsid_impl(module); |
7286 | 0 | } |
7287 | | |
7288 | | #endif /* defined(HAVE_SETSID) */ |
7289 | | |
7290 | | #if defined(HAVE_SETPGID) |
7291 | | |
7292 | | PyDoc_STRVAR(os_setpgid__doc__, |
7293 | | "setpgid($module, pid, pgrp, /)\n" |
7294 | | "--\n" |
7295 | | "\n" |
7296 | | "Call the system call setpgid(pid, pgrp)."); |
7297 | | |
7298 | | #define OS_SETPGID_METHODDEF \ |
7299 | | {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__}, |
7300 | | |
7301 | | static PyObject * |
7302 | | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
7303 | | |
7304 | | static PyObject * |
7305 | | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7306 | 0 | { |
7307 | 0 | PyObject *return_value = NULL; |
7308 | 0 | pid_t pid; |
7309 | 0 | pid_t pgrp; |
7310 | |
|
7311 | 0 | if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) { |
7312 | 0 | goto exit; |
7313 | 0 | } |
7314 | 0 | pid = PyLong_AsPid(args[0]); |
7315 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7316 | 0 | goto exit; |
7317 | 0 | } |
7318 | 0 | pgrp = PyLong_AsPid(args[1]); |
7319 | 0 | if (pgrp == (pid_t)(-1) && PyErr_Occurred()) { |
7320 | 0 | goto exit; |
7321 | 0 | } |
7322 | 0 | return_value = os_setpgid_impl(module, pid, pgrp); |
7323 | |
|
7324 | 0 | exit: |
7325 | 0 | return return_value; |
7326 | 0 | } |
7327 | | |
7328 | | #endif /* defined(HAVE_SETPGID) */ |
7329 | | |
7330 | | #if defined(HAVE_TCGETPGRP) |
7331 | | |
7332 | | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
7333 | | "tcgetpgrp($module, fd, /)\n" |
7334 | | "--\n" |
7335 | | "\n" |
7336 | | "Return the process group associated with the terminal specified by fd."); |
7337 | | |
7338 | | #define OS_TCGETPGRP_METHODDEF \ |
7339 | | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
7340 | | |
7341 | | static PyObject * |
7342 | | os_tcgetpgrp_impl(PyObject *module, int fd); |
7343 | | |
7344 | | static PyObject * |
7345 | | os_tcgetpgrp(PyObject *module, PyObject *arg) |
7346 | 0 | { |
7347 | 0 | PyObject *return_value = NULL; |
7348 | 0 | int fd; |
7349 | |
|
7350 | 0 | fd = PyLong_AsInt(arg); |
7351 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7352 | 0 | goto exit; |
7353 | 0 | } |
7354 | 0 | return_value = os_tcgetpgrp_impl(module, fd); |
7355 | |
|
7356 | 0 | exit: |
7357 | 0 | return return_value; |
7358 | 0 | } |
7359 | | |
7360 | | #endif /* defined(HAVE_TCGETPGRP) */ |
7361 | | |
7362 | | #if defined(HAVE_TCSETPGRP) |
7363 | | |
7364 | | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
7365 | | "tcsetpgrp($module, fd, pgid, /)\n" |
7366 | | "--\n" |
7367 | | "\n" |
7368 | | "Set the process group associated with the terminal specified by fd."); |
7369 | | |
7370 | | #define OS_TCSETPGRP_METHODDEF \ |
7371 | | {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__}, |
7372 | | |
7373 | | static PyObject * |
7374 | | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
7375 | | |
7376 | | static PyObject * |
7377 | | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7378 | 0 | { |
7379 | 0 | PyObject *return_value = NULL; |
7380 | 0 | int fd; |
7381 | 0 | pid_t pgid; |
7382 | |
|
7383 | 0 | if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) { |
7384 | 0 | goto exit; |
7385 | 0 | } |
7386 | 0 | fd = PyLong_AsInt(args[0]); |
7387 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7388 | 0 | goto exit; |
7389 | 0 | } |
7390 | 0 | pgid = PyLong_AsPid(args[1]); |
7391 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
7392 | 0 | goto exit; |
7393 | 0 | } |
7394 | 0 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
7395 | |
|
7396 | 0 | exit: |
7397 | 0 | return return_value; |
7398 | 0 | } |
7399 | | |
7400 | | #endif /* defined(HAVE_TCSETPGRP) */ |
7401 | | |
7402 | | PyDoc_STRVAR(os_open__doc__, |
7403 | | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
7404 | | "--\n" |
7405 | | "\n" |
7406 | | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
7407 | | "\n" |
7408 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
7409 | | "a directory, and path should be relative; path will then be relative to\n" |
7410 | | "that directory.\n" |
7411 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
7412 | | "using it will raise a NotImplementedError."); |
7413 | | |
7414 | | #define OS_OPEN_METHODDEF \ |
7415 | | {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__}, |
7416 | | |
7417 | | static int |
7418 | | os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd); |
7419 | | |
7420 | | static PyObject * |
7421 | | os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7422 | 91.2k | { |
7423 | 91.2k | PyObject *return_value = NULL; |
7424 | 91.2k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7425 | | |
7426 | 91.2k | #define NUM_KEYWORDS 4 |
7427 | 91.2k | static struct { |
7428 | 91.2k | PyGC_Head _this_is_not_used; |
7429 | 91.2k | PyObject_VAR_HEAD |
7430 | 91.2k | Py_hash_t ob_hash; |
7431 | 91.2k | PyObject *ob_item[NUM_KEYWORDS]; |
7432 | 91.2k | } _kwtuple = { |
7433 | 91.2k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7434 | 91.2k | .ob_hash = -1, |
7435 | 91.2k | .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
7436 | 91.2k | }; |
7437 | 91.2k | #undef NUM_KEYWORDS |
7438 | 91.2k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7439 | | |
7440 | | #else // !Py_BUILD_CORE |
7441 | | # define KWTUPLE NULL |
7442 | | #endif // !Py_BUILD_CORE |
7443 | | |
7444 | 91.2k | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
7445 | 91.2k | static _PyArg_Parser _parser = { |
7446 | 91.2k | .keywords = _keywords, |
7447 | 91.2k | .fname = "open", |
7448 | 91.2k | .kwtuple = KWTUPLE, |
7449 | 91.2k | }; |
7450 | 91.2k | #undef KWTUPLE |
7451 | 91.2k | PyObject *argsbuf[4]; |
7452 | 91.2k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7453 | 91.2k | path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0); |
7454 | 91.2k | int flags; |
7455 | 91.2k | int mode = 511; |
7456 | 91.2k | int dir_fd = DEFAULT_DIR_FD; |
7457 | 91.2k | int _return_value; |
7458 | | |
7459 | 91.2k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7460 | 91.2k | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7461 | 91.2k | if (!args) { |
7462 | 0 | goto exit; |
7463 | 0 | } |
7464 | 91.2k | if (!path_converter(args[0], &path)) { |
7465 | 0 | goto exit; |
7466 | 0 | } |
7467 | 91.2k | flags = PyLong_AsInt(args[1]); |
7468 | 91.2k | if (flags == -1 && PyErr_Occurred()) { |
7469 | 0 | goto exit; |
7470 | 0 | } |
7471 | 91.2k | if (!noptargs) { |
7472 | 0 | goto skip_optional_pos; |
7473 | 0 | } |
7474 | 91.2k | if (args[2]) { |
7475 | 147 | mode = PyLong_AsInt(args[2]); |
7476 | 147 | if (mode == -1 && PyErr_Occurred()) { |
7477 | 0 | goto exit; |
7478 | 0 | } |
7479 | 147 | if (!--noptargs) { |
7480 | 147 | goto skip_optional_pos; |
7481 | 147 | } |
7482 | 147 | } |
7483 | 91.2k | skip_optional_pos: |
7484 | 91.2k | if (!noptargs) { |
7485 | 147 | goto skip_optional_kwonly; |
7486 | 147 | } |
7487 | 91.0k | if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
7488 | 0 | goto exit; |
7489 | 0 | } |
7490 | 91.2k | skip_optional_kwonly: |
7491 | 91.2k | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
7492 | 91.2k | if ((_return_value == -1) && PyErr_Occurred()) { |
7493 | 0 | goto exit; |
7494 | 0 | } |
7495 | 91.2k | return_value = PyLong_FromLong((long)_return_value); |
7496 | | |
7497 | 91.2k | exit: |
7498 | | /* Cleanup for path */ |
7499 | 91.2k | path_cleanup(&path); |
7500 | | |
7501 | 91.2k | return return_value; |
7502 | 91.2k | } |
7503 | | |
7504 | | PyDoc_STRVAR(os_close__doc__, |
7505 | | "close($module, /, fd)\n" |
7506 | | "--\n" |
7507 | | "\n" |
7508 | | "Close a file descriptor."); |
7509 | | |
7510 | | #define OS_CLOSE_METHODDEF \ |
7511 | | {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__}, |
7512 | | |
7513 | | static PyObject * |
7514 | | os_close_impl(PyObject *module, int fd); |
7515 | | |
7516 | | static PyObject * |
7517 | | os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7518 | 91.0k | { |
7519 | 91.0k | PyObject *return_value = NULL; |
7520 | 91.0k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7521 | | |
7522 | 91.0k | #define NUM_KEYWORDS 1 |
7523 | 91.0k | static struct { |
7524 | 91.0k | PyGC_Head _this_is_not_used; |
7525 | 91.0k | PyObject_VAR_HEAD |
7526 | 91.0k | Py_hash_t ob_hash; |
7527 | 91.0k | PyObject *ob_item[NUM_KEYWORDS]; |
7528 | 91.0k | } _kwtuple = { |
7529 | 91.0k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7530 | 91.0k | .ob_hash = -1, |
7531 | 91.0k | .ob_item = { &_Py_ID(fd), }, |
7532 | 91.0k | }; |
7533 | 91.0k | #undef NUM_KEYWORDS |
7534 | 91.0k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7535 | | |
7536 | | #else // !Py_BUILD_CORE |
7537 | | # define KWTUPLE NULL |
7538 | | #endif // !Py_BUILD_CORE |
7539 | | |
7540 | 91.0k | static const char * const _keywords[] = {"fd", NULL}; |
7541 | 91.0k | static _PyArg_Parser _parser = { |
7542 | 91.0k | .keywords = _keywords, |
7543 | 91.0k | .fname = "close", |
7544 | 91.0k | .kwtuple = KWTUPLE, |
7545 | 91.0k | }; |
7546 | 91.0k | #undef KWTUPLE |
7547 | 91.0k | PyObject *argsbuf[1]; |
7548 | 91.0k | int fd; |
7549 | | |
7550 | 91.0k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7551 | 91.0k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7552 | 91.0k | if (!args) { |
7553 | 0 | goto exit; |
7554 | 0 | } |
7555 | 91.0k | fd = PyLong_AsInt(args[0]); |
7556 | 91.0k | if (fd == -1 && PyErr_Occurred()) { |
7557 | 0 | goto exit; |
7558 | 0 | } |
7559 | 91.0k | return_value = os_close_impl(module, fd); |
7560 | | |
7561 | 91.0k | exit: |
7562 | 91.0k | return return_value; |
7563 | 91.0k | } |
7564 | | |
7565 | | PyDoc_STRVAR(os_closerange__doc__, |
7566 | | "closerange($module, fd_low, fd_high, /)\n" |
7567 | | "--\n" |
7568 | | "\n" |
7569 | | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
7570 | | |
7571 | | #define OS_CLOSERANGE_METHODDEF \ |
7572 | | {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__}, |
7573 | | |
7574 | | static PyObject * |
7575 | | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
7576 | | |
7577 | | static PyObject * |
7578 | | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7579 | 0 | { |
7580 | 0 | PyObject *return_value = NULL; |
7581 | 0 | int fd_low; |
7582 | 0 | int fd_high; |
7583 | |
|
7584 | 0 | if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { |
7585 | 0 | goto exit; |
7586 | 0 | } |
7587 | 0 | fd_low = PyLong_AsInt(args[0]); |
7588 | 0 | if (fd_low == -1 && PyErr_Occurred()) { |
7589 | 0 | goto exit; |
7590 | 0 | } |
7591 | 0 | fd_high = PyLong_AsInt(args[1]); |
7592 | 0 | if (fd_high == -1 && PyErr_Occurred()) { |
7593 | 0 | goto exit; |
7594 | 0 | } |
7595 | 0 | return_value = os_closerange_impl(module, fd_low, fd_high); |
7596 | |
|
7597 | 0 | exit: |
7598 | 0 | return return_value; |
7599 | 0 | } |
7600 | | |
7601 | | PyDoc_STRVAR(os_dup__doc__, |
7602 | | "dup($module, fd, /)\n" |
7603 | | "--\n" |
7604 | | "\n" |
7605 | | "Return a duplicate of a file descriptor."); |
7606 | | |
7607 | | #define OS_DUP_METHODDEF \ |
7608 | | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
7609 | | |
7610 | | static int |
7611 | | os_dup_impl(PyObject *module, int fd); |
7612 | | |
7613 | | static PyObject * |
7614 | | os_dup(PyObject *module, PyObject *arg) |
7615 | 0 | { |
7616 | 0 | PyObject *return_value = NULL; |
7617 | 0 | int fd; |
7618 | 0 | int _return_value; |
7619 | |
|
7620 | 0 | fd = PyLong_AsInt(arg); |
7621 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7622 | 0 | goto exit; |
7623 | 0 | } |
7624 | 0 | _return_value = os_dup_impl(module, fd); |
7625 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7626 | 0 | goto exit; |
7627 | 0 | } |
7628 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7629 | |
|
7630 | 0 | exit: |
7631 | 0 | return return_value; |
7632 | 0 | } |
7633 | | |
7634 | | #if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) |
7635 | | |
7636 | | PyDoc_STRVAR(os_dup2__doc__, |
7637 | | "dup2($module, /, fd, fd2, inheritable=True)\n" |
7638 | | "--\n" |
7639 | | "\n" |
7640 | | "Duplicate file descriptor."); |
7641 | | |
7642 | | #define OS_DUP2_METHODDEF \ |
7643 | | {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__}, |
7644 | | |
7645 | | static int |
7646 | | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
7647 | | |
7648 | | static PyObject * |
7649 | | os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7650 | 0 | { |
7651 | 0 | PyObject *return_value = NULL; |
7652 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7653 | |
|
7654 | 0 | #define NUM_KEYWORDS 3 |
7655 | 0 | static struct { |
7656 | 0 | PyGC_Head _this_is_not_used; |
7657 | 0 | PyObject_VAR_HEAD |
7658 | 0 | Py_hash_t ob_hash; |
7659 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7660 | 0 | } _kwtuple = { |
7661 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7662 | 0 | .ob_hash = -1, |
7663 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), }, |
7664 | 0 | }; |
7665 | 0 | #undef NUM_KEYWORDS |
7666 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7667 | |
|
7668 | | #else // !Py_BUILD_CORE |
7669 | | # define KWTUPLE NULL |
7670 | | #endif // !Py_BUILD_CORE |
7671 | |
|
7672 | 0 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
7673 | 0 | static _PyArg_Parser _parser = { |
7674 | 0 | .keywords = _keywords, |
7675 | 0 | .fname = "dup2", |
7676 | 0 | .kwtuple = KWTUPLE, |
7677 | 0 | }; |
7678 | 0 | #undef KWTUPLE |
7679 | 0 | PyObject *argsbuf[3]; |
7680 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7681 | 0 | int fd; |
7682 | 0 | int fd2; |
7683 | 0 | int inheritable = 1; |
7684 | 0 | int _return_value; |
7685 | |
|
7686 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7687 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7688 | 0 | if (!args) { |
7689 | 0 | goto exit; |
7690 | 0 | } |
7691 | 0 | fd = PyLong_AsInt(args[0]); |
7692 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7693 | 0 | goto exit; |
7694 | 0 | } |
7695 | 0 | fd2 = PyLong_AsInt(args[1]); |
7696 | 0 | if (fd2 == -1 && PyErr_Occurred()) { |
7697 | 0 | goto exit; |
7698 | 0 | } |
7699 | 0 | if (!noptargs) { |
7700 | 0 | goto skip_optional_pos; |
7701 | 0 | } |
7702 | 0 | inheritable = PyObject_IsTrue(args[2]); |
7703 | 0 | if (inheritable < 0) { |
7704 | 0 | goto exit; |
7705 | 0 | } |
7706 | 0 | skip_optional_pos: |
7707 | 0 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
7708 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7709 | 0 | goto exit; |
7710 | 0 | } |
7711 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7712 | |
|
7713 | 0 | exit: |
7714 | 0 | return return_value; |
7715 | 0 | } |
7716 | | |
7717 | | #endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */ |
7718 | | |
7719 | | #if defined(HAVE_LOCKF) |
7720 | | |
7721 | | PyDoc_STRVAR(os_lockf__doc__, |
7722 | | "lockf($module, fd, command, length, /)\n" |
7723 | | "--\n" |
7724 | | "\n" |
7725 | | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
7726 | | "\n" |
7727 | | " fd\n" |
7728 | | " An open file descriptor.\n" |
7729 | | " command\n" |
7730 | | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
7731 | | " length\n" |
7732 | | " The number of bytes to lock, starting at the current position."); |
7733 | | |
7734 | | #define OS_LOCKF_METHODDEF \ |
7735 | | {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__}, |
7736 | | |
7737 | | static PyObject * |
7738 | | os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length); |
7739 | | |
7740 | | static PyObject * |
7741 | | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7742 | 0 | { |
7743 | 0 | PyObject *return_value = NULL; |
7744 | 0 | int fd; |
7745 | 0 | int command; |
7746 | 0 | Py_off_t length; |
7747 | |
|
7748 | 0 | if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { |
7749 | 0 | goto exit; |
7750 | 0 | } |
7751 | 0 | fd = PyLong_AsInt(args[0]); |
7752 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7753 | 0 | goto exit; |
7754 | 0 | } |
7755 | 0 | command = PyLong_AsInt(args[1]); |
7756 | 0 | if (command == -1 && PyErr_Occurred()) { |
7757 | 0 | goto exit; |
7758 | 0 | } |
7759 | 0 | if (!_Py_Off_t_Converter(args[2], &length)) { |
7760 | 0 | goto exit; |
7761 | 0 | } |
7762 | 0 | return_value = os_lockf_impl(module, fd, command, length); |
7763 | |
|
7764 | 0 | exit: |
7765 | 0 | return return_value; |
7766 | 0 | } |
7767 | | |
7768 | | #endif /* defined(HAVE_LOCKF) */ |
7769 | | |
7770 | | PyDoc_STRVAR(os_lseek__doc__, |
7771 | | "lseek($module, fd, position, whence, /)\n" |
7772 | | "--\n" |
7773 | | "\n" |
7774 | | "Set the position of a file descriptor. Return the new position.\n" |
7775 | | "\n" |
7776 | | " fd\n" |
7777 | | " An open file descriptor, as returned by os.open().\n" |
7778 | | " position\n" |
7779 | | " Position, interpreted relative to \'whence\'.\n" |
7780 | | " whence\n" |
7781 | | " The relative position to seek from. Valid values are:\n" |
7782 | | " - SEEK_SET: seek from the start of the file.\n" |
7783 | | " - SEEK_CUR: seek from the current file position.\n" |
7784 | | " - SEEK_END: seek from the end of the file.\n" |
7785 | | "\n" |
7786 | | "The return value is the number of bytes relative to the beginning of\n" |
7787 | | "the file."); |
7788 | | |
7789 | | #define OS_LSEEK_METHODDEF \ |
7790 | | {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__}, |
7791 | | |
7792 | | static Py_off_t |
7793 | | os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how); |
7794 | | |
7795 | | static PyObject * |
7796 | | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7797 | 0 | { |
7798 | 0 | PyObject *return_value = NULL; |
7799 | 0 | int fd; |
7800 | 0 | Py_off_t position; |
7801 | 0 | int how; |
7802 | 0 | Py_off_t _return_value; |
7803 | |
|
7804 | 0 | if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { |
7805 | 0 | goto exit; |
7806 | 0 | } |
7807 | 0 | fd = PyLong_AsInt(args[0]); |
7808 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7809 | 0 | goto exit; |
7810 | 0 | } |
7811 | 0 | if (!_Py_Off_t_Converter(args[1], &position)) { |
7812 | 0 | goto exit; |
7813 | 0 | } |
7814 | 0 | how = PyLong_AsInt(args[2]); |
7815 | 0 | if (how == -1 && PyErr_Occurred()) { |
7816 | 0 | goto exit; |
7817 | 0 | } |
7818 | 0 | _return_value = os_lseek_impl(module, fd, position, how); |
7819 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7820 | 0 | goto exit; |
7821 | 0 | } |
7822 | 0 | return_value = PyLong_FromPy_off_t(_return_value); |
7823 | |
|
7824 | 0 | exit: |
7825 | 0 | return return_value; |
7826 | 0 | } |
7827 | | |
7828 | | PyDoc_STRVAR(os_read__doc__, |
7829 | | "read($module, fd, length, /)\n" |
7830 | | "--\n" |
7831 | | "\n" |
7832 | | "Read from a file descriptor. Returns a bytes object."); |
7833 | | |
7834 | | #define OS_READ_METHODDEF \ |
7835 | | {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__}, |
7836 | | |
7837 | | static PyObject * |
7838 | | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
7839 | | |
7840 | | static PyObject * |
7841 | | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7842 | 0 | { |
7843 | 0 | PyObject *return_value = NULL; |
7844 | 0 | int fd; |
7845 | 0 | Py_ssize_t length; |
7846 | |
|
7847 | 0 | if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { |
7848 | 0 | goto exit; |
7849 | 0 | } |
7850 | 0 | fd = PyLong_AsInt(args[0]); |
7851 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7852 | 0 | goto exit; |
7853 | 0 | } |
7854 | 0 | { |
7855 | 0 | Py_ssize_t ival = -1; |
7856 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
7857 | 0 | if (iobj != NULL) { |
7858 | 0 | ival = PyLong_AsSsize_t(iobj); |
7859 | 0 | Py_DECREF(iobj); |
7860 | 0 | } |
7861 | 0 | if (ival == -1 && PyErr_Occurred()) { |
7862 | 0 | goto exit; |
7863 | 0 | } |
7864 | 0 | length = ival; |
7865 | 0 | } |
7866 | 0 | return_value = os_read_impl(module, fd, length); |
7867 | |
|
7868 | 0 | exit: |
7869 | 0 | return return_value; |
7870 | 0 | } |
7871 | | |
7872 | | PyDoc_STRVAR(os_readinto__doc__, |
7873 | | "readinto($module, fd, buffer, /)\n" |
7874 | | "--\n" |
7875 | | "\n" |
7876 | | "Read into a buffer object from a file descriptor.\n" |
7877 | | "\n" |
7878 | | "The buffer should be mutable and bytes-like. On success, returns the\n" |
7879 | | "number of bytes read. Less bytes may be read than the size of the\n" |
7880 | | "buffer. The underlying system call will be retried when interrupted by\n" |
7881 | | "a signal, unless the signal handler raises an exception. Other errors\n" |
7882 | | "will not be retried and an error will be raised.\n" |
7883 | | "\n" |
7884 | | "Returns 0 if *fd* is at end of file or if the provided *buffer* has\n" |
7885 | | "length 0 (which can be used to check for errors without reading data).\n" |
7886 | | "Never returns negative."); |
7887 | | |
7888 | | #define OS_READINTO_METHODDEF \ |
7889 | | {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__}, |
7890 | | |
7891 | | static Py_ssize_t |
7892 | | os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer); |
7893 | | |
7894 | | static PyObject * |
7895 | | os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7896 | 0 | { |
7897 | 0 | PyObject *return_value = NULL; |
7898 | 0 | int fd; |
7899 | 0 | Py_buffer buffer = {NULL, NULL}; |
7900 | 0 | Py_ssize_t _return_value; |
7901 | |
|
7902 | 0 | if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) { |
7903 | 0 | goto exit; |
7904 | 0 | } |
7905 | 0 | fd = PyLong_AsInt(args[0]); |
7906 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7907 | 0 | goto exit; |
7908 | 0 | } |
7909 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) { |
7910 | 0 | _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]); |
7911 | 0 | goto exit; |
7912 | 0 | } |
7913 | 0 | _return_value = os_readinto_impl(module, fd, &buffer); |
7914 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7915 | 0 | goto exit; |
7916 | 0 | } |
7917 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7918 | |
|
7919 | 0 | exit: |
7920 | | /* Cleanup for buffer */ |
7921 | 0 | if (buffer.obj) { |
7922 | 0 | PyBuffer_Release(&buffer); |
7923 | 0 | } |
7924 | |
|
7925 | 0 | return return_value; |
7926 | 0 | } |
7927 | | |
7928 | | #if defined(HAVE_READV) |
7929 | | |
7930 | | PyDoc_STRVAR(os_readv__doc__, |
7931 | | "readv($module, fd, buffers, /)\n" |
7932 | | "--\n" |
7933 | | "\n" |
7934 | | "Read from a file descriptor fd into an iterable of buffers.\n" |
7935 | | "\n" |
7936 | | "The buffers should be mutable buffers accepting bytes.\n" |
7937 | | "readv will transfer data into each buffer until it is full\n" |
7938 | | "and then move on to the next buffer in the sequence to hold\n" |
7939 | | "the rest of the data.\n" |
7940 | | "\n" |
7941 | | "readv returns the total number of bytes read,\n" |
7942 | | "which may be less than the total capacity of all the buffers."); |
7943 | | |
7944 | | #define OS_READV_METHODDEF \ |
7945 | | {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__}, |
7946 | | |
7947 | | static Py_ssize_t |
7948 | | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
7949 | | |
7950 | | static PyObject * |
7951 | | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7952 | 0 | { |
7953 | 0 | PyObject *return_value = NULL; |
7954 | 0 | int fd; |
7955 | 0 | PyObject *buffers; |
7956 | 0 | Py_ssize_t _return_value; |
7957 | |
|
7958 | 0 | if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { |
7959 | 0 | goto exit; |
7960 | 0 | } |
7961 | 0 | fd = PyLong_AsInt(args[0]); |
7962 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7963 | 0 | goto exit; |
7964 | 0 | } |
7965 | 0 | buffers = args[1]; |
7966 | 0 | _return_value = os_readv_impl(module, fd, buffers); |
7967 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7968 | 0 | goto exit; |
7969 | 0 | } |
7970 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7971 | |
|
7972 | 0 | exit: |
7973 | 0 | return return_value; |
7974 | 0 | } |
7975 | | |
7976 | | #endif /* defined(HAVE_READV) */ |
7977 | | |
7978 | | #if defined(HAVE_PREAD) |
7979 | | |
7980 | | PyDoc_STRVAR(os_pread__doc__, |
7981 | | "pread($module, fd, length, offset, /)\n" |
7982 | | "--\n" |
7983 | | "\n" |
7984 | | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
7985 | | "\n" |
7986 | | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
7987 | | "the beginning of the file. The file offset remains unchanged."); |
7988 | | |
7989 | | #define OS_PREAD_METHODDEF \ |
7990 | | {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__}, |
7991 | | |
7992 | | static PyObject * |
7993 | | os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset); |
7994 | | |
7995 | | static PyObject * |
7996 | | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7997 | 0 | { |
7998 | 0 | PyObject *return_value = NULL; |
7999 | 0 | int fd; |
8000 | 0 | Py_ssize_t length; |
8001 | 0 | Py_off_t offset; |
8002 | |
|
8003 | 0 | if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { |
8004 | 0 | goto exit; |
8005 | 0 | } |
8006 | 0 | fd = PyLong_AsInt(args[0]); |
8007 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8008 | 0 | goto exit; |
8009 | 0 | } |
8010 | 0 | { |
8011 | 0 | Py_ssize_t ival = -1; |
8012 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
8013 | 0 | if (iobj != NULL) { |
8014 | 0 | ival = PyLong_AsSsize_t(iobj); |
8015 | 0 | Py_DECREF(iobj); |
8016 | 0 | } |
8017 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8018 | 0 | goto exit; |
8019 | 0 | } |
8020 | 0 | length = ival; |
8021 | 0 | } |
8022 | 0 | if (!_Py_Off_t_Converter(args[2], &offset)) { |
8023 | 0 | goto exit; |
8024 | 0 | } |
8025 | 0 | return_value = os_pread_impl(module, fd, length, offset); |
8026 | |
|
8027 | 0 | exit: |
8028 | 0 | return return_value; |
8029 | 0 | } |
8030 | | |
8031 | | #endif /* defined(HAVE_PREAD) */ |
8032 | | |
8033 | | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
8034 | | |
8035 | | PyDoc_STRVAR(os_preadv__doc__, |
8036 | | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
8037 | | "--\n" |
8038 | | "\n" |
8039 | | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
8040 | | "\n" |
8041 | | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
8042 | | "transfer data into each buffer until it is full and then move on to the\n" |
8043 | | "next buffer in the sequence to hold the rest of the data. Its fourth\n" |
8044 | | "argument, specifies the file offset at which the input operation is to\n" |
8045 | | "be performed. It will return the total number of bytes read (which can\n" |
8046 | | "be less than the total capacity of all the objects).\n" |
8047 | | "\n" |
8048 | | "The flags argument contains a bitwise OR of zero or more of the\n" |
8049 | | "following flags:\n" |
8050 | | "\n" |
8051 | | "- RWF_HIPRI\n" |
8052 | | "- RWF_NOWAIT\n" |
8053 | | "- RWF_DONTCACHE\n" |
8054 | | "\n" |
8055 | | "Using non-zero flags requires Linux 4.6 or newer."); |
8056 | | |
8057 | | #define OS_PREADV_METHODDEF \ |
8058 | | {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__}, |
8059 | | |
8060 | | static Py_ssize_t |
8061 | | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
8062 | | int flags); |
8063 | | |
8064 | | static PyObject * |
8065 | | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8066 | 0 | { |
8067 | 0 | PyObject *return_value = NULL; |
8068 | 0 | int fd; |
8069 | 0 | PyObject *buffers; |
8070 | 0 | Py_off_t offset; |
8071 | 0 | int flags = 0; |
8072 | 0 | Py_ssize_t _return_value; |
8073 | |
|
8074 | 0 | if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { |
8075 | 0 | goto exit; |
8076 | 0 | } |
8077 | 0 | fd = PyLong_AsInt(args[0]); |
8078 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8079 | 0 | goto exit; |
8080 | 0 | } |
8081 | 0 | buffers = args[1]; |
8082 | 0 | if (!_Py_Off_t_Converter(args[2], &offset)) { |
8083 | 0 | goto exit; |
8084 | 0 | } |
8085 | 0 | if (nargs < 4) { |
8086 | 0 | goto skip_optional; |
8087 | 0 | } |
8088 | 0 | flags = PyLong_AsInt(args[3]); |
8089 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8090 | 0 | goto exit; |
8091 | 0 | } |
8092 | 0 | skip_optional: |
8093 | 0 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
8094 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8095 | 0 | goto exit; |
8096 | 0 | } |
8097 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8098 | |
|
8099 | 0 | exit: |
8100 | 0 | return return_value; |
8101 | 0 | } |
8102 | | |
8103 | | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
8104 | | |
8105 | | PyDoc_STRVAR(os_write__doc__, |
8106 | | "write($module, fd, data, /)\n" |
8107 | | "--\n" |
8108 | | "\n" |
8109 | | "Write a bytes object to a file descriptor."); |
8110 | | |
8111 | | #define OS_WRITE_METHODDEF \ |
8112 | | {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__}, |
8113 | | |
8114 | | static Py_ssize_t |
8115 | | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
8116 | | |
8117 | | static PyObject * |
8118 | | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8119 | 2 | { |
8120 | 2 | PyObject *return_value = NULL; |
8121 | 2 | int fd; |
8122 | 2 | Py_buffer data = {NULL, NULL}; |
8123 | 2 | Py_ssize_t _return_value; |
8124 | | |
8125 | 2 | if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { |
8126 | 0 | goto exit; |
8127 | 0 | } |
8128 | 2 | fd = PyLong_AsInt(args[0]); |
8129 | 2 | if (fd == -1 && PyErr_Occurred()) { |
8130 | 0 | goto exit; |
8131 | 0 | } |
8132 | 2 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
8133 | 0 | goto exit; |
8134 | 0 | } |
8135 | 2 | _return_value = os_write_impl(module, fd, &data); |
8136 | 2 | if ((_return_value == -1) && PyErr_Occurred()) { |
8137 | 0 | goto exit; |
8138 | 0 | } |
8139 | 2 | return_value = PyLong_FromSsize_t(_return_value); |
8140 | | |
8141 | 2 | exit: |
8142 | | /* Cleanup for data */ |
8143 | 2 | if (data.obj) { |
8144 | 2 | PyBuffer_Release(&data); |
8145 | 2 | } |
8146 | | |
8147 | 2 | return return_value; |
8148 | 2 | } |
8149 | | |
8150 | | #if defined(HAVE_SENDFILE) && defined(__APPLE__) |
8151 | | |
8152 | | PyDoc_STRVAR(os_sendfile__doc__, |
8153 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
8154 | | " trailers=(), flags=0)\n" |
8155 | | "--\n" |
8156 | | "\n" |
8157 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8158 | | |
8159 | | #define OS_SENDFILE_METHODDEF \ |
8160 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8161 | | |
8162 | | static PyObject * |
8163 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
8164 | | Py_off_t sbytes, PyObject *headers, PyObject *trailers, |
8165 | | int flags); |
8166 | | |
8167 | | static PyObject * |
8168 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8169 | | { |
8170 | | PyObject *return_value = NULL; |
8171 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8172 | | |
8173 | | #define NUM_KEYWORDS 7 |
8174 | | static struct { |
8175 | | PyGC_Head _this_is_not_used; |
8176 | | PyObject_VAR_HEAD |
8177 | | Py_hash_t ob_hash; |
8178 | | PyObject *ob_item[NUM_KEYWORDS]; |
8179 | | } _kwtuple = { |
8180 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8181 | | .ob_hash = -1, |
8182 | | .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), }, |
8183 | | }; |
8184 | | #undef NUM_KEYWORDS |
8185 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8186 | | |
8187 | | #else // !Py_BUILD_CORE |
8188 | | # define KWTUPLE NULL |
8189 | | #endif // !Py_BUILD_CORE |
8190 | | |
8191 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
8192 | | static _PyArg_Parser _parser = { |
8193 | | .keywords = _keywords, |
8194 | | .fname = "sendfile", |
8195 | | .kwtuple = KWTUPLE, |
8196 | | }; |
8197 | | #undef KWTUPLE |
8198 | | PyObject *argsbuf[7]; |
8199 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
8200 | | int out_fd; |
8201 | | int in_fd; |
8202 | | Py_off_t offset; |
8203 | | Py_off_t sbytes; |
8204 | | PyObject *headers = NULL; |
8205 | | PyObject *trailers = NULL; |
8206 | | int flags = 0; |
8207 | | |
8208 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8209 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8210 | | if (!args) { |
8211 | | goto exit; |
8212 | | } |
8213 | | out_fd = PyLong_AsInt(args[0]); |
8214 | | if (out_fd == -1 && PyErr_Occurred()) { |
8215 | | goto exit; |
8216 | | } |
8217 | | in_fd = PyLong_AsInt(args[1]); |
8218 | | if (in_fd == -1 && PyErr_Occurred()) { |
8219 | | goto exit; |
8220 | | } |
8221 | | if (!_Py_Off_t_Converter(args[2], &offset)) { |
8222 | | goto exit; |
8223 | | } |
8224 | | if (!_Py_Off_t_Converter(args[3], &sbytes)) { |
8225 | | goto exit; |
8226 | | } |
8227 | | if (!noptargs) { |
8228 | | goto skip_optional_pos; |
8229 | | } |
8230 | | if (args[4]) { |
8231 | | headers = args[4]; |
8232 | | if (!--noptargs) { |
8233 | | goto skip_optional_pos; |
8234 | | } |
8235 | | } |
8236 | | if (args[5]) { |
8237 | | trailers = args[5]; |
8238 | | if (!--noptargs) { |
8239 | | goto skip_optional_pos; |
8240 | | } |
8241 | | } |
8242 | | flags = PyLong_AsInt(args[6]); |
8243 | | if (flags == -1 && PyErr_Occurred()) { |
8244 | | goto exit; |
8245 | | } |
8246 | | skip_optional_pos: |
8247 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags); |
8248 | | |
8249 | | exit: |
8250 | | return return_value; |
8251 | | } |
8252 | | |
8253 | | #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */ |
8254 | | |
8255 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) |
8256 | | |
8257 | | PyDoc_STRVAR(os_sendfile__doc__, |
8258 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
8259 | | " trailers=(), flags=0)\n" |
8260 | | "--\n" |
8261 | | "\n" |
8262 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8263 | | |
8264 | | #define OS_SENDFILE_METHODDEF \ |
8265 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8266 | | |
8267 | | static PyObject * |
8268 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
8269 | | Py_ssize_t count, PyObject *headers, PyObject *trailers, |
8270 | | int flags); |
8271 | | |
8272 | | static PyObject * |
8273 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8274 | | { |
8275 | | PyObject *return_value = NULL; |
8276 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8277 | | |
8278 | | #define NUM_KEYWORDS 7 |
8279 | | static struct { |
8280 | | PyGC_Head _this_is_not_used; |
8281 | | PyObject_VAR_HEAD |
8282 | | Py_hash_t ob_hash; |
8283 | | PyObject *ob_item[NUM_KEYWORDS]; |
8284 | | } _kwtuple = { |
8285 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8286 | | .ob_hash = -1, |
8287 | | .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), }, |
8288 | | }; |
8289 | | #undef NUM_KEYWORDS |
8290 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8291 | | |
8292 | | #else // !Py_BUILD_CORE |
8293 | | # define KWTUPLE NULL |
8294 | | #endif // !Py_BUILD_CORE |
8295 | | |
8296 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
8297 | | static _PyArg_Parser _parser = { |
8298 | | .keywords = _keywords, |
8299 | | .fname = "sendfile", |
8300 | | .kwtuple = KWTUPLE, |
8301 | | }; |
8302 | | #undef KWTUPLE |
8303 | | PyObject *argsbuf[7]; |
8304 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
8305 | | int out_fd; |
8306 | | int in_fd; |
8307 | | Py_off_t offset; |
8308 | | Py_ssize_t count; |
8309 | | PyObject *headers = NULL; |
8310 | | PyObject *trailers = NULL; |
8311 | | int flags = 0; |
8312 | | |
8313 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8314 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8315 | | if (!args) { |
8316 | | goto exit; |
8317 | | } |
8318 | | out_fd = PyLong_AsInt(args[0]); |
8319 | | if (out_fd == -1 && PyErr_Occurred()) { |
8320 | | goto exit; |
8321 | | } |
8322 | | in_fd = PyLong_AsInt(args[1]); |
8323 | | if (in_fd == -1 && PyErr_Occurred()) { |
8324 | | goto exit; |
8325 | | } |
8326 | | if (!_Py_Off_t_Converter(args[2], &offset)) { |
8327 | | goto exit; |
8328 | | } |
8329 | | { |
8330 | | Py_ssize_t ival = -1; |
8331 | | PyObject *iobj = _PyNumber_Index(args[3]); |
8332 | | if (iobj != NULL) { |
8333 | | ival = PyLong_AsSsize_t(iobj); |
8334 | | Py_DECREF(iobj); |
8335 | | } |
8336 | | if (ival == -1 && PyErr_Occurred()) { |
8337 | | goto exit; |
8338 | | } |
8339 | | count = ival; |
8340 | | if (count < 0) { |
8341 | | PyErr_SetString(PyExc_ValueError, |
8342 | | "count cannot be negative"); |
8343 | | goto exit; |
8344 | | } |
8345 | | } |
8346 | | if (!noptargs) { |
8347 | | goto skip_optional_pos; |
8348 | | } |
8349 | | if (args[4]) { |
8350 | | headers = args[4]; |
8351 | | if (!--noptargs) { |
8352 | | goto skip_optional_pos; |
8353 | | } |
8354 | | } |
8355 | | if (args[5]) { |
8356 | | trailers = args[5]; |
8357 | | if (!--noptargs) { |
8358 | | goto skip_optional_pos; |
8359 | | } |
8360 | | } |
8361 | | flags = PyLong_AsInt(args[6]); |
8362 | | if (flags == -1 && PyErr_Occurred()) { |
8363 | | goto exit; |
8364 | | } |
8365 | | skip_optional_pos: |
8366 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags); |
8367 | | |
8368 | | exit: |
8369 | | return return_value; |
8370 | | } |
8371 | | |
8372 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8373 | | |
8374 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) |
8375 | | |
8376 | | PyDoc_STRVAR(os_sendfile__doc__, |
8377 | | "sendfile($module, /, out_fd, in_fd, offset, count)\n" |
8378 | | "--\n" |
8379 | | "\n" |
8380 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8381 | | |
8382 | | #define OS_SENDFILE_METHODDEF \ |
8383 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8384 | | |
8385 | | static PyObject * |
8386 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj, |
8387 | | Py_ssize_t count); |
8388 | | |
8389 | | static PyObject * |
8390 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8391 | 0 | { |
8392 | 0 | PyObject *return_value = NULL; |
8393 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8394 | |
|
8395 | 0 | #define NUM_KEYWORDS 4 |
8396 | 0 | static struct { |
8397 | 0 | PyGC_Head _this_is_not_used; |
8398 | 0 | PyObject_VAR_HEAD |
8399 | 0 | Py_hash_t ob_hash; |
8400 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8401 | 0 | } _kwtuple = { |
8402 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8403 | 0 | .ob_hash = -1, |
8404 | 0 | .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), }, |
8405 | 0 | }; |
8406 | 0 | #undef NUM_KEYWORDS |
8407 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8408 | |
|
8409 | | #else // !Py_BUILD_CORE |
8410 | | # define KWTUPLE NULL |
8411 | | #endif // !Py_BUILD_CORE |
8412 | |
|
8413 | 0 | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL}; |
8414 | 0 | static _PyArg_Parser _parser = { |
8415 | 0 | .keywords = _keywords, |
8416 | 0 | .fname = "sendfile", |
8417 | 0 | .kwtuple = KWTUPLE, |
8418 | 0 | }; |
8419 | 0 | #undef KWTUPLE |
8420 | 0 | PyObject *argsbuf[4]; |
8421 | 0 | int out_fd; |
8422 | 0 | int in_fd; |
8423 | 0 | PyObject *offobj; |
8424 | 0 | Py_ssize_t count; |
8425 | |
|
8426 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8427 | 0 | /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8428 | 0 | if (!args) { |
8429 | 0 | goto exit; |
8430 | 0 | } |
8431 | 0 | out_fd = PyLong_AsInt(args[0]); |
8432 | 0 | if (out_fd == -1 && PyErr_Occurred()) { |
8433 | 0 | goto exit; |
8434 | 0 | } |
8435 | 0 | in_fd = PyLong_AsInt(args[1]); |
8436 | 0 | if (in_fd == -1 && PyErr_Occurred()) { |
8437 | 0 | goto exit; |
8438 | 0 | } |
8439 | 0 | offobj = args[2]; |
8440 | 0 | { |
8441 | 0 | Py_ssize_t ival = -1; |
8442 | 0 | PyObject *iobj = _PyNumber_Index(args[3]); |
8443 | 0 | if (iobj != NULL) { |
8444 | 0 | ival = PyLong_AsSsize_t(iobj); |
8445 | 0 | Py_DECREF(iobj); |
8446 | 0 | } |
8447 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8448 | 0 | goto exit; |
8449 | 0 | } |
8450 | 0 | count = ival; |
8451 | 0 | if (count < 0) { |
8452 | 0 | PyErr_SetString(PyExc_ValueError, |
8453 | 0 | "count cannot be negative"); |
8454 | 0 | goto exit; |
8455 | 0 | } |
8456 | 0 | } |
8457 | 0 | return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); |
8458 | |
|
8459 | 0 | exit: |
8460 | 0 | return return_value; |
8461 | 0 | } |
8462 | | |
8463 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8464 | | |
8465 | | #if defined(__APPLE__) |
8466 | | |
8467 | | PyDoc_STRVAR(os__fcopyfile__doc__, |
8468 | | "_fcopyfile($module, in_fd, out_fd, flags, /)\n" |
8469 | | "--\n" |
8470 | | "\n" |
8471 | | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); |
8472 | | |
8473 | | #define OS__FCOPYFILE_METHODDEF \ |
8474 | | {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__}, |
8475 | | |
8476 | | static PyObject * |
8477 | | os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags); |
8478 | | |
8479 | | static PyObject * |
8480 | | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8481 | | { |
8482 | | PyObject *return_value = NULL; |
8483 | | int in_fd; |
8484 | | int out_fd; |
8485 | | int flags; |
8486 | | |
8487 | | if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { |
8488 | | goto exit; |
8489 | | } |
8490 | | in_fd = PyLong_AsInt(args[0]); |
8491 | | if (in_fd == -1 && PyErr_Occurred()) { |
8492 | | goto exit; |
8493 | | } |
8494 | | out_fd = PyLong_AsInt(args[1]); |
8495 | | if (out_fd == -1 && PyErr_Occurred()) { |
8496 | | goto exit; |
8497 | | } |
8498 | | flags = PyLong_AsInt(args[2]); |
8499 | | if (flags == -1 && PyErr_Occurred()) { |
8500 | | goto exit; |
8501 | | } |
8502 | | return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags); |
8503 | | |
8504 | | exit: |
8505 | | return return_value; |
8506 | | } |
8507 | | |
8508 | | #endif /* defined(__APPLE__) */ |
8509 | | |
8510 | | PyDoc_STRVAR(os_fstat__doc__, |
8511 | | "fstat($module, /, fd)\n" |
8512 | | "--\n" |
8513 | | "\n" |
8514 | | "Perform a stat system call on the given file descriptor.\n" |
8515 | | "\n" |
8516 | | "Like stat(), but for an open file descriptor.\n" |
8517 | | "Equivalent to os.stat(fd)."); |
8518 | | |
8519 | | #define OS_FSTAT_METHODDEF \ |
8520 | | {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__}, |
8521 | | |
8522 | | static PyObject * |
8523 | | os_fstat_impl(PyObject *module, int fd); |
8524 | | |
8525 | | static PyObject * |
8526 | | os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8527 | 91.0k | { |
8528 | 91.0k | PyObject *return_value = NULL; |
8529 | 91.0k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8530 | | |
8531 | 91.0k | #define NUM_KEYWORDS 1 |
8532 | 91.0k | static struct { |
8533 | 91.0k | PyGC_Head _this_is_not_used; |
8534 | 91.0k | PyObject_VAR_HEAD |
8535 | 91.0k | Py_hash_t ob_hash; |
8536 | 91.0k | PyObject *ob_item[NUM_KEYWORDS]; |
8537 | 91.0k | } _kwtuple = { |
8538 | 91.0k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8539 | 91.0k | .ob_hash = -1, |
8540 | 91.0k | .ob_item = { &_Py_ID(fd), }, |
8541 | 91.0k | }; |
8542 | 91.0k | #undef NUM_KEYWORDS |
8543 | 91.0k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8544 | | |
8545 | | #else // !Py_BUILD_CORE |
8546 | | # define KWTUPLE NULL |
8547 | | #endif // !Py_BUILD_CORE |
8548 | | |
8549 | 91.0k | static const char * const _keywords[] = {"fd", NULL}; |
8550 | 91.0k | static _PyArg_Parser _parser = { |
8551 | 91.0k | .keywords = _keywords, |
8552 | 91.0k | .fname = "fstat", |
8553 | 91.0k | .kwtuple = KWTUPLE, |
8554 | 91.0k | }; |
8555 | 91.0k | #undef KWTUPLE |
8556 | 91.0k | PyObject *argsbuf[1]; |
8557 | 91.0k | int fd; |
8558 | | |
8559 | 91.0k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8560 | 91.0k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8561 | 91.0k | if (!args) { |
8562 | 0 | goto exit; |
8563 | 0 | } |
8564 | 91.0k | fd = PyLong_AsInt(args[0]); |
8565 | 91.0k | if (fd == -1 && PyErr_Occurred()) { |
8566 | 0 | goto exit; |
8567 | 0 | } |
8568 | 91.0k | return_value = os_fstat_impl(module, fd); |
8569 | | |
8570 | 91.0k | exit: |
8571 | 91.0k | return return_value; |
8572 | 91.0k | } |
8573 | | |
8574 | | PyDoc_STRVAR(os_isatty__doc__, |
8575 | | "isatty($module, fd, /)\n" |
8576 | | "--\n" |
8577 | | "\n" |
8578 | | "Return True if the fd is connected to a terminal.\n" |
8579 | | "\n" |
8580 | | "Return True if the file descriptor is an open file descriptor\n" |
8581 | | "connected to the slave end of a terminal."); |
8582 | | |
8583 | | #define OS_ISATTY_METHODDEF \ |
8584 | | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
8585 | | |
8586 | | static int |
8587 | | os_isatty_impl(PyObject *module, int fd); |
8588 | | |
8589 | | static PyObject * |
8590 | | os_isatty(PyObject *module, PyObject *arg) |
8591 | 0 | { |
8592 | 0 | PyObject *return_value = NULL; |
8593 | 0 | int fd; |
8594 | 0 | int _return_value; |
8595 | |
|
8596 | 0 | fd = PyLong_AsInt(arg); |
8597 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8598 | 0 | goto exit; |
8599 | 0 | } |
8600 | 0 | _return_value = os_isatty_impl(module, fd); |
8601 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8602 | 0 | goto exit; |
8603 | 0 | } |
8604 | 0 | return_value = PyBool_FromLong((long)_return_value); |
8605 | |
|
8606 | 0 | exit: |
8607 | 0 | return return_value; |
8608 | 0 | } |
8609 | | |
8610 | | #if defined(HAVE_PIPE) |
8611 | | |
8612 | | PyDoc_STRVAR(os_pipe__doc__, |
8613 | | "pipe($module, /)\n" |
8614 | | "--\n" |
8615 | | "\n" |
8616 | | "Create a pipe.\n" |
8617 | | "\n" |
8618 | | "Returns a tuple of two file descriptors:\n" |
8619 | | " (read_fd, write_fd)"); |
8620 | | |
8621 | | #define OS_PIPE_METHODDEF \ |
8622 | | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
8623 | | |
8624 | | static PyObject * |
8625 | | os_pipe_impl(PyObject *module); |
8626 | | |
8627 | | static PyObject * |
8628 | | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
8629 | 0 | { |
8630 | 0 | return os_pipe_impl(module); |
8631 | 0 | } |
8632 | | |
8633 | | #endif /* defined(HAVE_PIPE) */ |
8634 | | |
8635 | | #if defined(HAVE_PIPE2) |
8636 | | |
8637 | | PyDoc_STRVAR(os_pipe2__doc__, |
8638 | | "pipe2($module, flags, /)\n" |
8639 | | "--\n" |
8640 | | "\n" |
8641 | | "Create a pipe with flags set atomically.\n" |
8642 | | "\n" |
8643 | | "Returns a tuple of two file descriptors:\n" |
8644 | | " (read_fd, write_fd)\n" |
8645 | | "\n" |
8646 | | "flags can be constructed by ORing together one or more of these values:\n" |
8647 | | "O_NONBLOCK, O_CLOEXEC."); |
8648 | | |
8649 | | #define OS_PIPE2_METHODDEF \ |
8650 | | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
8651 | | |
8652 | | static PyObject * |
8653 | | os_pipe2_impl(PyObject *module, int flags); |
8654 | | |
8655 | | static PyObject * |
8656 | | os_pipe2(PyObject *module, PyObject *arg) |
8657 | 0 | { |
8658 | 0 | PyObject *return_value = NULL; |
8659 | 0 | int flags; |
8660 | |
|
8661 | 0 | flags = PyLong_AsInt(arg); |
8662 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8663 | 0 | goto exit; |
8664 | 0 | } |
8665 | 0 | return_value = os_pipe2_impl(module, flags); |
8666 | |
|
8667 | 0 | exit: |
8668 | 0 | return return_value; |
8669 | 0 | } |
8670 | | |
8671 | | #endif /* defined(HAVE_PIPE2) */ |
8672 | | |
8673 | | #if defined(HAVE_WRITEV) |
8674 | | |
8675 | | PyDoc_STRVAR(os_writev__doc__, |
8676 | | "writev($module, fd, buffers, /)\n" |
8677 | | "--\n" |
8678 | | "\n" |
8679 | | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
8680 | | "\n" |
8681 | | "Returns the total number of bytes written.\n" |
8682 | | "buffers must be a sequence of bytes-like objects."); |
8683 | | |
8684 | | #define OS_WRITEV_METHODDEF \ |
8685 | | {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__}, |
8686 | | |
8687 | | static Py_ssize_t |
8688 | | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
8689 | | |
8690 | | static PyObject * |
8691 | | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8692 | 0 | { |
8693 | 0 | PyObject *return_value = NULL; |
8694 | 0 | int fd; |
8695 | 0 | PyObject *buffers; |
8696 | 0 | Py_ssize_t _return_value; |
8697 | |
|
8698 | 0 | if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { |
8699 | 0 | goto exit; |
8700 | 0 | } |
8701 | 0 | fd = PyLong_AsInt(args[0]); |
8702 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8703 | 0 | goto exit; |
8704 | 0 | } |
8705 | 0 | buffers = args[1]; |
8706 | 0 | _return_value = os_writev_impl(module, fd, buffers); |
8707 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8708 | 0 | goto exit; |
8709 | 0 | } |
8710 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8711 | |
|
8712 | 0 | exit: |
8713 | 0 | return return_value; |
8714 | 0 | } |
8715 | | |
8716 | | #endif /* defined(HAVE_WRITEV) */ |
8717 | | |
8718 | | #if defined(HAVE_PWRITE) |
8719 | | |
8720 | | PyDoc_STRVAR(os_pwrite__doc__, |
8721 | | "pwrite($module, fd, buffer, offset, /)\n" |
8722 | | "--\n" |
8723 | | "\n" |
8724 | | "Write bytes to a file descriptor starting at a particular offset.\n" |
8725 | | "\n" |
8726 | | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
8727 | | "the file. Returns the number of bytes written. Does not change the\n" |
8728 | | "current file offset."); |
8729 | | |
8730 | | #define OS_PWRITE_METHODDEF \ |
8731 | | {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__}, |
8732 | | |
8733 | | static Py_ssize_t |
8734 | | os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset); |
8735 | | |
8736 | | static PyObject * |
8737 | | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8738 | 0 | { |
8739 | 0 | PyObject *return_value = NULL; |
8740 | 0 | int fd; |
8741 | 0 | Py_buffer buffer = {NULL, NULL}; |
8742 | 0 | Py_off_t offset; |
8743 | 0 | Py_ssize_t _return_value; |
8744 | |
|
8745 | 0 | if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { |
8746 | 0 | goto exit; |
8747 | 0 | } |
8748 | 0 | fd = PyLong_AsInt(args[0]); |
8749 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8750 | 0 | goto exit; |
8751 | 0 | } |
8752 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
8753 | 0 | goto exit; |
8754 | 0 | } |
8755 | 0 | if (!_Py_Off_t_Converter(args[2], &offset)) { |
8756 | 0 | goto exit; |
8757 | 0 | } |
8758 | 0 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
8759 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8760 | 0 | goto exit; |
8761 | 0 | } |
8762 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8763 | |
|
8764 | 0 | exit: |
8765 | | /* Cleanup for buffer */ |
8766 | 0 | if (buffer.obj) { |
8767 | 0 | PyBuffer_Release(&buffer); |
8768 | 0 | } |
8769 | |
|
8770 | 0 | return return_value; |
8771 | 0 | } |
8772 | | |
8773 | | #endif /* defined(HAVE_PWRITE) */ |
8774 | | |
8775 | | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
8776 | | |
8777 | | PyDoc_STRVAR(os_pwritev__doc__, |
8778 | | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
8779 | | "--\n" |
8780 | | "\n" |
8781 | | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
8782 | | "\n" |
8783 | | "Combines the functionality of writev() and pwrite(). All buffers must be\n" |
8784 | | "a sequence of bytes-like objects. Buffers are processed in array order.\n" |
8785 | | "Entire contents of first buffer is written before proceeding to second,\n" |
8786 | | "and so on. The operating system may set a limit (sysconf() value\n" |
8787 | | "SC_IOV_MAX) on the number of buffers that can be used.\n" |
8788 | | "This function writes the contents of each object to the file descriptor\n" |
8789 | | "and returns the total number of bytes written.\n" |
8790 | | "\n" |
8791 | | "The flags argument contains a bitwise OR of zero or more of the\n" |
8792 | | "following flags:\n" |
8793 | | "\n" |
8794 | | "- RWF_DSYNC\n" |
8795 | | "- RWF_SYNC\n" |
8796 | | "- RWF_APPEND\n" |
8797 | | "- RWF_DONTCACHE\n" |
8798 | | "- RWF_ATOMIC\n" |
8799 | | "- RWF_NOSIGNAL\n" |
8800 | | "\n" |
8801 | | "Using non-zero flags requires Linux 4.7 or newer."); |
8802 | | |
8803 | | #define OS_PWRITEV_METHODDEF \ |
8804 | | {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__}, |
8805 | | |
8806 | | static Py_ssize_t |
8807 | | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
8808 | | int flags); |
8809 | | |
8810 | | static PyObject * |
8811 | | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8812 | 0 | { |
8813 | 0 | PyObject *return_value = NULL; |
8814 | 0 | int fd; |
8815 | 0 | PyObject *buffers; |
8816 | 0 | Py_off_t offset; |
8817 | 0 | int flags = 0; |
8818 | 0 | Py_ssize_t _return_value; |
8819 | |
|
8820 | 0 | if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { |
8821 | 0 | goto exit; |
8822 | 0 | } |
8823 | 0 | fd = PyLong_AsInt(args[0]); |
8824 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8825 | 0 | goto exit; |
8826 | 0 | } |
8827 | 0 | buffers = args[1]; |
8828 | 0 | if (!_Py_Off_t_Converter(args[2], &offset)) { |
8829 | 0 | goto exit; |
8830 | 0 | } |
8831 | 0 | if (nargs < 4) { |
8832 | 0 | goto skip_optional; |
8833 | 0 | } |
8834 | 0 | flags = PyLong_AsInt(args[3]); |
8835 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8836 | 0 | goto exit; |
8837 | 0 | } |
8838 | 0 | skip_optional: |
8839 | 0 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
8840 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8841 | 0 | goto exit; |
8842 | 0 | } |
8843 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8844 | |
|
8845 | 0 | exit: |
8846 | 0 | return return_value; |
8847 | 0 | } |
8848 | | |
8849 | | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
8850 | | |
8851 | | #if defined(_Py_HAVE_COPY_FILE_RANGE) |
8852 | | |
8853 | | PyDoc_STRVAR(os_copy_file_range__doc__, |
8854 | | "copy_file_range($module, /, src, dst, count, offset_src=None,\n" |
8855 | | " offset_dst=None)\n" |
8856 | | "--\n" |
8857 | | "\n" |
8858 | | "Copy count bytes from one file descriptor to another.\n" |
8859 | | "\n" |
8860 | | " src\n" |
8861 | | " Source file descriptor.\n" |
8862 | | " dst\n" |
8863 | | " Destination file descriptor.\n" |
8864 | | " count\n" |
8865 | | " Number of bytes to copy.\n" |
8866 | | " offset_src\n" |
8867 | | " Starting offset in src.\n" |
8868 | | " offset_dst\n" |
8869 | | " Starting offset in dst.\n" |
8870 | | "\n" |
8871 | | "If offset_src is None, then src is read from the current position;\n" |
8872 | | "respectively for offset_dst."); |
8873 | | |
8874 | | #define OS_COPY_FILE_RANGE_METHODDEF \ |
8875 | | {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__}, |
8876 | | |
8877 | | static PyObject * |
8878 | | os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
8879 | | PyObject *offset_src, PyObject *offset_dst); |
8880 | | |
8881 | | static PyObject * |
8882 | | os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8883 | 0 | { |
8884 | 0 | PyObject *return_value = NULL; |
8885 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8886 | |
|
8887 | 0 | #define NUM_KEYWORDS 5 |
8888 | 0 | static struct { |
8889 | 0 | PyGC_Head _this_is_not_used; |
8890 | 0 | PyObject_VAR_HEAD |
8891 | 0 | Py_hash_t ob_hash; |
8892 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8893 | 0 | } _kwtuple = { |
8894 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8895 | 0 | .ob_hash = -1, |
8896 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), }, |
8897 | 0 | }; |
8898 | 0 | #undef NUM_KEYWORDS |
8899 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8900 | |
|
8901 | | #else // !Py_BUILD_CORE |
8902 | | # define KWTUPLE NULL |
8903 | | #endif // !Py_BUILD_CORE |
8904 | |
|
8905 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL}; |
8906 | 0 | static _PyArg_Parser _parser = { |
8907 | 0 | .keywords = _keywords, |
8908 | 0 | .fname = "copy_file_range", |
8909 | 0 | .kwtuple = KWTUPLE, |
8910 | 0 | }; |
8911 | 0 | #undef KWTUPLE |
8912 | 0 | PyObject *argsbuf[5]; |
8913 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
8914 | 0 | int src; |
8915 | 0 | int dst; |
8916 | 0 | Py_ssize_t count; |
8917 | 0 | PyObject *offset_src = Py_None; |
8918 | 0 | PyObject *offset_dst = Py_None; |
8919 | |
|
8920 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8921 | 0 | /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8922 | 0 | if (!args) { |
8923 | 0 | goto exit; |
8924 | 0 | } |
8925 | 0 | src = PyLong_AsInt(args[0]); |
8926 | 0 | if (src == -1 && PyErr_Occurred()) { |
8927 | 0 | goto exit; |
8928 | 0 | } |
8929 | 0 | dst = PyLong_AsInt(args[1]); |
8930 | 0 | if (dst == -1 && PyErr_Occurred()) { |
8931 | 0 | goto exit; |
8932 | 0 | } |
8933 | 0 | { |
8934 | 0 | Py_ssize_t ival = -1; |
8935 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
8936 | 0 | if (iobj != NULL) { |
8937 | 0 | ival = PyLong_AsSsize_t(iobj); |
8938 | 0 | Py_DECREF(iobj); |
8939 | 0 | } |
8940 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8941 | 0 | goto exit; |
8942 | 0 | } |
8943 | 0 | count = ival; |
8944 | 0 | if (count < 0) { |
8945 | 0 | PyErr_SetString(PyExc_ValueError, |
8946 | 0 | "count cannot be negative"); |
8947 | 0 | goto exit; |
8948 | 0 | } |
8949 | 0 | } |
8950 | 0 | if (!noptargs) { |
8951 | 0 | goto skip_optional_pos; |
8952 | 0 | } |
8953 | 0 | if (args[3]) { |
8954 | 0 | offset_src = args[3]; |
8955 | 0 | if (!--noptargs) { |
8956 | 0 | goto skip_optional_pos; |
8957 | 0 | } |
8958 | 0 | } |
8959 | 0 | offset_dst = args[4]; |
8960 | 0 | skip_optional_pos: |
8961 | 0 | return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst); |
8962 | |
|
8963 | 0 | exit: |
8964 | 0 | return return_value; |
8965 | 0 | } |
8966 | | |
8967 | | #endif /* defined(_Py_HAVE_COPY_FILE_RANGE) */ |
8968 | | |
8969 | | #if ((defined(HAVE_SPLICE) && !defined(_AIX))) |
8970 | | |
8971 | | PyDoc_STRVAR(os_splice__doc__, |
8972 | | "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n" |
8973 | | " flags=0)\n" |
8974 | | "--\n" |
8975 | | "\n" |
8976 | | "Transfer count bytes from one pipe to a descriptor or vice versa.\n" |
8977 | | "\n" |
8978 | | " src\n" |
8979 | | " Source file descriptor.\n" |
8980 | | " dst\n" |
8981 | | " Destination file descriptor.\n" |
8982 | | " count\n" |
8983 | | " Number of bytes to copy.\n" |
8984 | | " offset_src\n" |
8985 | | " Starting offset in src.\n" |
8986 | | " offset_dst\n" |
8987 | | " Starting offset in dst.\n" |
8988 | | " flags\n" |
8989 | | " Flags to modify the semantics of the call.\n" |
8990 | | "\n" |
8991 | | "If offset_src is None, then src is read from the current position;\n" |
8992 | | "respectively for offset_dst. The offset associated to the file\n" |
8993 | | "descriptor that refers to a pipe must be None."); |
8994 | | |
8995 | | #define OS_SPLICE_METHODDEF \ |
8996 | | {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__}, |
8997 | | |
8998 | | static PyObject * |
8999 | | os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
9000 | | PyObject *offset_src, PyObject *offset_dst, |
9001 | | unsigned int flags); |
9002 | | |
9003 | | static PyObject * |
9004 | | os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9005 | 0 | { |
9006 | 0 | PyObject *return_value = NULL; |
9007 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9008 | |
|
9009 | 0 | #define NUM_KEYWORDS 6 |
9010 | 0 | static struct { |
9011 | 0 | PyGC_Head _this_is_not_used; |
9012 | 0 | PyObject_VAR_HEAD |
9013 | 0 | Py_hash_t ob_hash; |
9014 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9015 | 0 | } _kwtuple = { |
9016 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9017 | 0 | .ob_hash = -1, |
9018 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), }, |
9019 | 0 | }; |
9020 | 0 | #undef NUM_KEYWORDS |
9021 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9022 | |
|
9023 | | #else // !Py_BUILD_CORE |
9024 | | # define KWTUPLE NULL |
9025 | | #endif // !Py_BUILD_CORE |
9026 | |
|
9027 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL}; |
9028 | 0 | static _PyArg_Parser _parser = { |
9029 | 0 | .keywords = _keywords, |
9030 | 0 | .fname = "splice", |
9031 | 0 | .kwtuple = KWTUPLE, |
9032 | 0 | }; |
9033 | 0 | #undef KWTUPLE |
9034 | 0 | PyObject *argsbuf[6]; |
9035 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
9036 | 0 | int src; |
9037 | 0 | int dst; |
9038 | 0 | Py_ssize_t count; |
9039 | 0 | PyObject *offset_src = Py_None; |
9040 | 0 | PyObject *offset_dst = Py_None; |
9041 | 0 | unsigned int flags = 0; |
9042 | |
|
9043 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9044 | 0 | /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9045 | 0 | if (!args) { |
9046 | 0 | goto exit; |
9047 | 0 | } |
9048 | 0 | src = PyLong_AsInt(args[0]); |
9049 | 0 | if (src == -1 && PyErr_Occurred()) { |
9050 | 0 | goto exit; |
9051 | 0 | } |
9052 | 0 | dst = PyLong_AsInt(args[1]); |
9053 | 0 | if (dst == -1 && PyErr_Occurred()) { |
9054 | 0 | goto exit; |
9055 | 0 | } |
9056 | 0 | { |
9057 | 0 | Py_ssize_t ival = -1; |
9058 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
9059 | 0 | if (iobj != NULL) { |
9060 | 0 | ival = PyLong_AsSsize_t(iobj); |
9061 | 0 | Py_DECREF(iobj); |
9062 | 0 | } |
9063 | 0 | if (ival == -1 && PyErr_Occurred()) { |
9064 | 0 | goto exit; |
9065 | 0 | } |
9066 | 0 | count = ival; |
9067 | 0 | if (count < 0) { |
9068 | 0 | PyErr_SetString(PyExc_ValueError, |
9069 | 0 | "count cannot be negative"); |
9070 | 0 | goto exit; |
9071 | 0 | } |
9072 | 0 | } |
9073 | 0 | if (!noptargs) { |
9074 | 0 | goto skip_optional_pos; |
9075 | 0 | } |
9076 | 0 | if (args[3]) { |
9077 | 0 | offset_src = args[3]; |
9078 | 0 | if (!--noptargs) { |
9079 | 0 | goto skip_optional_pos; |
9080 | 0 | } |
9081 | 0 | } |
9082 | 0 | if (args[4]) { |
9083 | 0 | offset_dst = args[4]; |
9084 | 0 | if (!--noptargs) { |
9085 | 0 | goto skip_optional_pos; |
9086 | 0 | } |
9087 | 0 | } |
9088 | 0 | if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) { |
9089 | 0 | goto exit; |
9090 | 0 | } |
9091 | 0 | skip_optional_pos: |
9092 | 0 | return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags); |
9093 | |
|
9094 | 0 | exit: |
9095 | 0 | return return_value; |
9096 | 0 | } |
9097 | | |
9098 | | #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */ |
9099 | | |
9100 | | #if defined(HAVE_MKFIFO) |
9101 | | |
9102 | | PyDoc_STRVAR(os_mkfifo__doc__, |
9103 | | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
9104 | | "--\n" |
9105 | | "\n" |
9106 | | "Create a \"fifo\" (a POSIX named pipe).\n" |
9107 | | "\n" |
9108 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
9109 | | "a directory, and path should be relative; path will then be relative to\n" |
9110 | | "that directory.\n" |
9111 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
9112 | | "using it will raise a NotImplementedError."); |
9113 | | |
9114 | | #define OS_MKFIFO_METHODDEF \ |
9115 | | {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__}, |
9116 | | |
9117 | | static PyObject * |
9118 | | os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
9119 | | |
9120 | | static PyObject * |
9121 | | os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9122 | 0 | { |
9123 | 0 | PyObject *return_value = NULL; |
9124 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9125 | |
|
9126 | 0 | #define NUM_KEYWORDS 3 |
9127 | 0 | static struct { |
9128 | 0 | PyGC_Head _this_is_not_used; |
9129 | 0 | PyObject_VAR_HEAD |
9130 | 0 | Py_hash_t ob_hash; |
9131 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9132 | 0 | } _kwtuple = { |
9133 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9134 | 0 | .ob_hash = -1, |
9135 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
9136 | 0 | }; |
9137 | 0 | #undef NUM_KEYWORDS |
9138 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9139 | |
|
9140 | | #else // !Py_BUILD_CORE |
9141 | | # define KWTUPLE NULL |
9142 | | #endif // !Py_BUILD_CORE |
9143 | |
|
9144 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
9145 | 0 | static _PyArg_Parser _parser = { |
9146 | 0 | .keywords = _keywords, |
9147 | 0 | .fname = "mkfifo", |
9148 | 0 | .kwtuple = KWTUPLE, |
9149 | 0 | }; |
9150 | 0 | #undef KWTUPLE |
9151 | 0 | PyObject *argsbuf[3]; |
9152 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
9153 | 0 | path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0); |
9154 | 0 | int mode = 438; |
9155 | 0 | int dir_fd = DEFAULT_DIR_FD; |
9156 | |
|
9157 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9158 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9159 | 0 | if (!args) { |
9160 | 0 | goto exit; |
9161 | 0 | } |
9162 | 0 | if (!path_converter(args[0], &path)) { |
9163 | 0 | goto exit; |
9164 | 0 | } |
9165 | 0 | if (!noptargs) { |
9166 | 0 | goto skip_optional_pos; |
9167 | 0 | } |
9168 | 0 | if (args[1]) { |
9169 | 0 | mode = PyLong_AsInt(args[1]); |
9170 | 0 | if (mode == -1 && PyErr_Occurred()) { |
9171 | 0 | goto exit; |
9172 | 0 | } |
9173 | 0 | if (!--noptargs) { |
9174 | 0 | goto skip_optional_pos; |
9175 | 0 | } |
9176 | 0 | } |
9177 | 0 | skip_optional_pos: |
9178 | 0 | if (!noptargs) { |
9179 | 0 | goto skip_optional_kwonly; |
9180 | 0 | } |
9181 | 0 | if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
9182 | 0 | goto exit; |
9183 | 0 | } |
9184 | 0 | skip_optional_kwonly: |
9185 | 0 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
9186 | |
|
9187 | 0 | exit: |
9188 | | /* Cleanup for path */ |
9189 | 0 | path_cleanup(&path); |
9190 | |
|
9191 | 0 | return return_value; |
9192 | 0 | } |
9193 | | |
9194 | | #endif /* defined(HAVE_MKFIFO) */ |
9195 | | |
9196 | | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
9197 | | |
9198 | | PyDoc_STRVAR(os_mknod__doc__, |
9199 | | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
9200 | | "--\n" |
9201 | | "\n" |
9202 | | "Create a node in the file system.\n" |
9203 | | "\n" |
9204 | | "Create a node in the file system (file, device special file or named\n" |
9205 | | "pipe) at path. mode specifies both the permissions to use and the\n" |
9206 | | "type of node to be created, being combined (bitwise OR) with one of\n" |
9207 | | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set\n" |
9208 | | "on mode, device defines the newly created device special file (probably\n" |
9209 | | "using os.makedev()). Otherwise device is ignored.\n" |
9210 | | "\n" |
9211 | | "If dir_fd is not None, it should be a file descriptor open to\n" |
9212 | | "a directory, and path should be relative; path will then be relative\n" |
9213 | | "to that directory.\n" |
9214 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
9215 | | "using it will raise a NotImplementedError."); |
9216 | | |
9217 | | #define OS_MKNOD_METHODDEF \ |
9218 | | {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__}, |
9219 | | |
9220 | | static PyObject * |
9221 | | os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device, |
9222 | | int dir_fd); |
9223 | | |
9224 | | static PyObject * |
9225 | | os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9226 | 0 | { |
9227 | 0 | PyObject *return_value = NULL; |
9228 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9229 | |
|
9230 | 0 | #define NUM_KEYWORDS 4 |
9231 | 0 | static struct { |
9232 | 0 | PyGC_Head _this_is_not_used; |
9233 | 0 | PyObject_VAR_HEAD |
9234 | 0 | Py_hash_t ob_hash; |
9235 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9236 | 0 | } _kwtuple = { |
9237 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9238 | 0 | .ob_hash = -1, |
9239 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), }, |
9240 | 0 | }; |
9241 | 0 | #undef NUM_KEYWORDS |
9242 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9243 | |
|
9244 | | #else // !Py_BUILD_CORE |
9245 | | # define KWTUPLE NULL |
9246 | | #endif // !Py_BUILD_CORE |
9247 | |
|
9248 | 0 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
9249 | 0 | static _PyArg_Parser _parser = { |
9250 | 0 | .keywords = _keywords, |
9251 | 0 | .fname = "mknod", |
9252 | 0 | .kwtuple = KWTUPLE, |
9253 | 0 | }; |
9254 | 0 | #undef KWTUPLE |
9255 | 0 | PyObject *argsbuf[4]; |
9256 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
9257 | 0 | path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0); |
9258 | 0 | int mode = 384; |
9259 | 0 | dev_t device = 0; |
9260 | 0 | int dir_fd = DEFAULT_DIR_FD; |
9261 | |
|
9262 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9263 | 0 | /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9264 | 0 | if (!args) { |
9265 | 0 | goto exit; |
9266 | 0 | } |
9267 | 0 | if (!path_converter(args[0], &path)) { |
9268 | 0 | goto exit; |
9269 | 0 | } |
9270 | 0 | if (!noptargs) { |
9271 | 0 | goto skip_optional_pos; |
9272 | 0 | } |
9273 | 0 | if (args[1]) { |
9274 | 0 | mode = PyLong_AsInt(args[1]); |
9275 | 0 | if (mode == -1 && PyErr_Occurred()) { |
9276 | 0 | goto exit; |
9277 | 0 | } |
9278 | 0 | if (!--noptargs) { |
9279 | 0 | goto skip_optional_pos; |
9280 | 0 | } |
9281 | 0 | } |
9282 | 0 | if (args[2]) { |
9283 | 0 | if (!_Py_Dev_Converter(args[2], &device)) { |
9284 | 0 | goto exit; |
9285 | 0 | } |
9286 | 0 | if (!--noptargs) { |
9287 | 0 | goto skip_optional_pos; |
9288 | 0 | } |
9289 | 0 | } |
9290 | 0 | skip_optional_pos: |
9291 | 0 | if (!noptargs) { |
9292 | 0 | goto skip_optional_kwonly; |
9293 | 0 | } |
9294 | 0 | if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
9295 | 0 | goto exit; |
9296 | 0 | } |
9297 | 0 | skip_optional_kwonly: |
9298 | 0 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
9299 | |
|
9300 | 0 | exit: |
9301 | | /* Cleanup for path */ |
9302 | 0 | path_cleanup(&path); |
9303 | |
|
9304 | 0 | return return_value; |
9305 | 0 | } |
9306 | | |
9307 | | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
9308 | | |
9309 | | #if defined(HAVE_DEVICE_MACROS) |
9310 | | |
9311 | | PyDoc_STRVAR(os_major__doc__, |
9312 | | "major($module, device, /)\n" |
9313 | | "--\n" |
9314 | | "\n" |
9315 | | "Extracts a device major number from a raw device number."); |
9316 | | |
9317 | | #define OS_MAJOR_METHODDEF \ |
9318 | | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
9319 | | |
9320 | | static PyObject * |
9321 | | os_major_impl(PyObject *module, dev_t device); |
9322 | | |
9323 | | static PyObject * |
9324 | | os_major(PyObject *module, PyObject *arg) |
9325 | 0 | { |
9326 | 0 | PyObject *return_value = NULL; |
9327 | 0 | dev_t device; |
9328 | |
|
9329 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9330 | 0 | goto exit; |
9331 | 0 | } |
9332 | 0 | return_value = os_major_impl(module, device); |
9333 | |
|
9334 | 0 | exit: |
9335 | 0 | return return_value; |
9336 | 0 | } |
9337 | | |
9338 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9339 | | |
9340 | | #if defined(HAVE_DEVICE_MACROS) |
9341 | | |
9342 | | PyDoc_STRVAR(os_minor__doc__, |
9343 | | "minor($module, device, /)\n" |
9344 | | "--\n" |
9345 | | "\n" |
9346 | | "Extracts a device minor number from a raw device number."); |
9347 | | |
9348 | | #define OS_MINOR_METHODDEF \ |
9349 | | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
9350 | | |
9351 | | static PyObject * |
9352 | | os_minor_impl(PyObject *module, dev_t device); |
9353 | | |
9354 | | static PyObject * |
9355 | | os_minor(PyObject *module, PyObject *arg) |
9356 | 0 | { |
9357 | 0 | PyObject *return_value = NULL; |
9358 | 0 | dev_t device; |
9359 | |
|
9360 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9361 | 0 | goto exit; |
9362 | 0 | } |
9363 | 0 | return_value = os_minor_impl(module, device); |
9364 | |
|
9365 | 0 | exit: |
9366 | 0 | return return_value; |
9367 | 0 | } |
9368 | | |
9369 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9370 | | |
9371 | | #if defined(HAVE_DEVICE_MACROS) |
9372 | | |
9373 | | PyDoc_STRVAR(os_makedev__doc__, |
9374 | | "makedev($module, major, minor, /)\n" |
9375 | | "--\n" |
9376 | | "\n" |
9377 | | "Composes a raw device number from the major and minor device numbers."); |
9378 | | |
9379 | | #define OS_MAKEDEV_METHODDEF \ |
9380 | | {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__}, |
9381 | | |
9382 | | static dev_t |
9383 | | os_makedev_impl(PyObject *module, dev_t major, dev_t minor); |
9384 | | |
9385 | | static PyObject * |
9386 | | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9387 | 0 | { |
9388 | 0 | PyObject *return_value = NULL; |
9389 | 0 | dev_t major; |
9390 | 0 | dev_t minor; |
9391 | 0 | dev_t _return_value; |
9392 | |
|
9393 | 0 | if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { |
9394 | 0 | goto exit; |
9395 | 0 | } |
9396 | 0 | if (!_Py_Dev_Converter(args[0], &major)) { |
9397 | 0 | goto exit; |
9398 | 0 | } |
9399 | 0 | if (!_Py_Dev_Converter(args[1], &minor)) { |
9400 | 0 | goto exit; |
9401 | 0 | } |
9402 | 0 | _return_value = os_makedev_impl(module, major, minor); |
9403 | 0 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
9404 | 0 | goto exit; |
9405 | 0 | } |
9406 | 0 | return_value = _PyLong_FromDev(_return_value); |
9407 | |
|
9408 | 0 | exit: |
9409 | 0 | return return_value; |
9410 | 0 | } |
9411 | | |
9412 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9413 | | |
9414 | | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
9415 | | |
9416 | | PyDoc_STRVAR(os_ftruncate__doc__, |
9417 | | "ftruncate($module, fd, length, /)\n" |
9418 | | "--\n" |
9419 | | "\n" |
9420 | | "Truncate a file, specified by file descriptor, to a specific length."); |
9421 | | |
9422 | | #define OS_FTRUNCATE_METHODDEF \ |
9423 | | {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__}, |
9424 | | |
9425 | | static PyObject * |
9426 | | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
9427 | | |
9428 | | static PyObject * |
9429 | | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9430 | 0 | { |
9431 | 0 | PyObject *return_value = NULL; |
9432 | 0 | int fd; |
9433 | 0 | Py_off_t length; |
9434 | |
|
9435 | 0 | if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { |
9436 | 0 | goto exit; |
9437 | 0 | } |
9438 | 0 | fd = PyLong_AsInt(args[0]); |
9439 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9440 | 0 | goto exit; |
9441 | 0 | } |
9442 | 0 | if (!_Py_Off_t_Converter(args[1], &length)) { |
9443 | 0 | goto exit; |
9444 | 0 | } |
9445 | 0 | return_value = os_ftruncate_impl(module, fd, length); |
9446 | |
|
9447 | 0 | exit: |
9448 | 0 | return return_value; |
9449 | 0 | } |
9450 | | |
9451 | | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
9452 | | |
9453 | | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
9454 | | |
9455 | | PyDoc_STRVAR(os_truncate__doc__, |
9456 | | "truncate($module, /, path, length)\n" |
9457 | | "--\n" |
9458 | | "\n" |
9459 | | "Truncate a file, specified by path, to a specific length.\n" |
9460 | | "\n" |
9461 | | "On some platforms, path may also be specified as an open file\n" |
9462 | | "descriptor. If this functionality is unavailable, using it raises\n" |
9463 | | "an exception."); |
9464 | | |
9465 | | #define OS_TRUNCATE_METHODDEF \ |
9466 | | {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__}, |
9467 | | |
9468 | | static PyObject * |
9469 | | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
9470 | | |
9471 | | static PyObject * |
9472 | | os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9473 | 0 | { |
9474 | 0 | PyObject *return_value = NULL; |
9475 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9476 | |
|
9477 | 0 | #define NUM_KEYWORDS 2 |
9478 | 0 | static struct { |
9479 | 0 | PyGC_Head _this_is_not_used; |
9480 | 0 | PyObject_VAR_HEAD |
9481 | 0 | Py_hash_t ob_hash; |
9482 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9483 | 0 | } _kwtuple = { |
9484 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9485 | 0 | .ob_hash = -1, |
9486 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(length), }, |
9487 | 0 | }; |
9488 | 0 | #undef NUM_KEYWORDS |
9489 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9490 | |
|
9491 | | #else // !Py_BUILD_CORE |
9492 | | # define KWTUPLE NULL |
9493 | | #endif // !Py_BUILD_CORE |
9494 | |
|
9495 | 0 | static const char * const _keywords[] = {"path", "length", NULL}; |
9496 | 0 | static _PyArg_Parser _parser = { |
9497 | 0 | .keywords = _keywords, |
9498 | 0 | .fname = "truncate", |
9499 | 0 | .kwtuple = KWTUPLE, |
9500 | 0 | }; |
9501 | 0 | #undef KWTUPLE |
9502 | 0 | PyObject *argsbuf[2]; |
9503 | 0 | path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE); |
9504 | 0 | Py_off_t length; |
9505 | |
|
9506 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9507 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9508 | 0 | if (!args) { |
9509 | 0 | goto exit; |
9510 | 0 | } |
9511 | 0 | if (!path_converter(args[0], &path)) { |
9512 | 0 | goto exit; |
9513 | 0 | } |
9514 | 0 | if (!_Py_Off_t_Converter(args[1], &length)) { |
9515 | 0 | goto exit; |
9516 | 0 | } |
9517 | 0 | return_value = os_truncate_impl(module, &path, length); |
9518 | |
|
9519 | 0 | exit: |
9520 | | /* Cleanup for path */ |
9521 | 0 | path_cleanup(&path); |
9522 | |
|
9523 | 0 | return return_value; |
9524 | 0 | } |
9525 | | |
9526 | | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
9527 | | |
9528 | | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(__wasi__)) |
9529 | | |
9530 | | PyDoc_STRVAR(os_posix_fallocate__doc__, |
9531 | | "posix_fallocate($module, fd, offset, length, /)\n" |
9532 | | "--\n" |
9533 | | "\n" |
9534 | | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
9535 | | "\n" |
9536 | | "Ensure that the file specified by fd encompasses a range of bytes\n" |
9537 | | "starting at offset bytes from the beginning and continuing for length\n" |
9538 | | "bytes."); |
9539 | | |
9540 | | #define OS_POSIX_FALLOCATE_METHODDEF \ |
9541 | | {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__}, |
9542 | | |
9543 | | static PyObject * |
9544 | | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
9545 | | Py_off_t length); |
9546 | | |
9547 | | static PyObject * |
9548 | | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9549 | 0 | { |
9550 | 0 | PyObject *return_value = NULL; |
9551 | 0 | int fd; |
9552 | 0 | Py_off_t offset; |
9553 | 0 | Py_off_t length; |
9554 | |
|
9555 | 0 | if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { |
9556 | 0 | goto exit; |
9557 | 0 | } |
9558 | 0 | fd = PyLong_AsInt(args[0]); |
9559 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9560 | 0 | goto exit; |
9561 | 0 | } |
9562 | 0 | if (!_Py_Off_t_Converter(args[1], &offset)) { |
9563 | 0 | goto exit; |
9564 | 0 | } |
9565 | 0 | if (!_Py_Off_t_Converter(args[2], &length)) { |
9566 | 0 | goto exit; |
9567 | 0 | } |
9568 | 0 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
9569 | |
|
9570 | 0 | exit: |
9571 | 0 | return return_value; |
9572 | 0 | } |
9573 | | |
9574 | | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(__wasi__)) */ |
9575 | | |
9576 | | #if defined(HAVE_POSIX_FADVISE) |
9577 | | |
9578 | | PyDoc_STRVAR(os_posix_fadvise__doc__, |
9579 | | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
9580 | | "--\n" |
9581 | | "\n" |
9582 | | "Announce an intention to access data in a specific pattern.\n" |
9583 | | "\n" |
9584 | | "Announce an intention to access data in a specific pattern, thus\n" |
9585 | | "allowing the kernel to make optimizations.\n" |
9586 | | "The advice applies to the region of the file specified by fd starting at\n" |
9587 | | "offset and continuing for length bytes.\n" |
9588 | | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
9589 | | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
9590 | | "POSIX_FADV_DONTNEED."); |
9591 | | |
9592 | | #define OS_POSIX_FADVISE_METHODDEF \ |
9593 | | {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__}, |
9594 | | |
9595 | | static PyObject * |
9596 | | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
9597 | | Py_off_t length, int advice); |
9598 | | |
9599 | | static PyObject * |
9600 | | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9601 | 0 | { |
9602 | 0 | PyObject *return_value = NULL; |
9603 | 0 | int fd; |
9604 | 0 | Py_off_t offset; |
9605 | 0 | Py_off_t length; |
9606 | 0 | int advice; |
9607 | |
|
9608 | 0 | if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { |
9609 | 0 | goto exit; |
9610 | 0 | } |
9611 | 0 | fd = PyLong_AsInt(args[0]); |
9612 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9613 | 0 | goto exit; |
9614 | 0 | } |
9615 | 0 | if (!_Py_Off_t_Converter(args[1], &offset)) { |
9616 | 0 | goto exit; |
9617 | 0 | } |
9618 | 0 | if (!_Py_Off_t_Converter(args[2], &length)) { |
9619 | 0 | goto exit; |
9620 | 0 | } |
9621 | 0 | advice = PyLong_AsInt(args[3]); |
9622 | 0 | if (advice == -1 && PyErr_Occurred()) { |
9623 | 0 | goto exit; |
9624 | 0 | } |
9625 | 0 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
9626 | |
|
9627 | 0 | exit: |
9628 | 0 | return return_value; |
9629 | 0 | } |
9630 | | |
9631 | | #endif /* defined(HAVE_POSIX_FADVISE) */ |
9632 | | |
9633 | | #if defined(MS_WINDOWS) |
9634 | | |
9635 | | PyDoc_STRVAR(os_putenv__doc__, |
9636 | | "putenv($module, name, value, /)\n" |
9637 | | "--\n" |
9638 | | "\n" |
9639 | | "Change or add an environment variable."); |
9640 | | |
9641 | | #define OS_PUTENV_METHODDEF \ |
9642 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9643 | | |
9644 | | static PyObject * |
9645 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9646 | | |
9647 | | static PyObject * |
9648 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9649 | | { |
9650 | | PyObject *return_value = NULL; |
9651 | | PyObject *name; |
9652 | | PyObject *value; |
9653 | | |
9654 | | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9655 | | goto exit; |
9656 | | } |
9657 | | if (!PyUnicode_Check(args[0])) { |
9658 | | _PyArg_BadArgument("putenv", "argument 1", "str", args[0]); |
9659 | | goto exit; |
9660 | | } |
9661 | | name = args[0]; |
9662 | | if (!PyUnicode_Check(args[1])) { |
9663 | | _PyArg_BadArgument("putenv", "argument 2", "str", args[1]); |
9664 | | goto exit; |
9665 | | } |
9666 | | value = args[1]; |
9667 | | return_value = os_putenv_impl(module, name, value); |
9668 | | |
9669 | | exit: |
9670 | | return return_value; |
9671 | | } |
9672 | | |
9673 | | #endif /* defined(MS_WINDOWS) */ |
9674 | | |
9675 | | #if !defined(MS_WINDOWS) |
9676 | | |
9677 | | PyDoc_STRVAR(os_putenv__doc__, |
9678 | | "putenv($module, name, value, /)\n" |
9679 | | "--\n" |
9680 | | "\n" |
9681 | | "Change or add an environment variable."); |
9682 | | |
9683 | | #define OS_PUTENV_METHODDEF \ |
9684 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9685 | | |
9686 | | static PyObject * |
9687 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9688 | | |
9689 | | static PyObject * |
9690 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9691 | 0 | { |
9692 | 0 | PyObject *return_value = NULL; |
9693 | 0 | PyObject *name = NULL; |
9694 | 0 | PyObject *value = NULL; |
9695 | |
|
9696 | 0 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9697 | 0 | goto exit; |
9698 | 0 | } |
9699 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
9700 | 0 | goto exit; |
9701 | 0 | } |
9702 | 0 | if (!PyUnicode_FSConverter(args[1], &value)) { |
9703 | 0 | goto exit; |
9704 | 0 | } |
9705 | 0 | return_value = os_putenv_impl(module, name, value); |
9706 | |
|
9707 | 0 | exit: |
9708 | | /* Cleanup for name */ |
9709 | 0 | Py_XDECREF(name); |
9710 | | /* Cleanup for value */ |
9711 | 0 | Py_XDECREF(value); |
9712 | |
|
9713 | 0 | return return_value; |
9714 | 0 | } |
9715 | | |
9716 | | #endif /* !defined(MS_WINDOWS) */ |
9717 | | |
9718 | | #if defined(MS_WINDOWS) |
9719 | | |
9720 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9721 | | "unsetenv($module, name, /)\n" |
9722 | | "--\n" |
9723 | | "\n" |
9724 | | "Delete an environment variable."); |
9725 | | |
9726 | | #define OS_UNSETENV_METHODDEF \ |
9727 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9728 | | |
9729 | | static PyObject * |
9730 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9731 | | |
9732 | | static PyObject * |
9733 | | os_unsetenv(PyObject *module, PyObject *arg) |
9734 | | { |
9735 | | PyObject *return_value = NULL; |
9736 | | PyObject *name; |
9737 | | |
9738 | | if (!PyUnicode_Check(arg)) { |
9739 | | _PyArg_BadArgument("unsetenv", "argument", "str", arg); |
9740 | | goto exit; |
9741 | | } |
9742 | | name = arg; |
9743 | | return_value = os_unsetenv_impl(module, name); |
9744 | | |
9745 | | exit: |
9746 | | return return_value; |
9747 | | } |
9748 | | |
9749 | | #endif /* defined(MS_WINDOWS) */ |
9750 | | |
9751 | | #if !defined(MS_WINDOWS) |
9752 | | |
9753 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9754 | | "unsetenv($module, name, /)\n" |
9755 | | "--\n" |
9756 | | "\n" |
9757 | | "Delete an environment variable."); |
9758 | | |
9759 | | #define OS_UNSETENV_METHODDEF \ |
9760 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9761 | | |
9762 | | static PyObject * |
9763 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9764 | | |
9765 | | static PyObject * |
9766 | | os_unsetenv(PyObject *module, PyObject *arg) |
9767 | 0 | { |
9768 | 0 | PyObject *return_value = NULL; |
9769 | 0 | PyObject *name = NULL; |
9770 | |
|
9771 | 0 | if (!PyUnicode_FSConverter(arg, &name)) { |
9772 | 0 | goto exit; |
9773 | 0 | } |
9774 | 0 | return_value = os_unsetenv_impl(module, name); |
9775 | |
|
9776 | 0 | exit: |
9777 | | /* Cleanup for name */ |
9778 | 0 | Py_XDECREF(name); |
9779 | |
|
9780 | 0 | return return_value; |
9781 | 0 | } |
9782 | | |
9783 | | #endif /* !defined(MS_WINDOWS) */ |
9784 | | |
9785 | | #if defined(HAVE_CLEARENV) |
9786 | | |
9787 | | PyDoc_STRVAR(os__clearenv__doc__, |
9788 | | "_clearenv($module, /)\n" |
9789 | | "--\n" |
9790 | | "\n"); |
9791 | | |
9792 | | #define OS__CLEARENV_METHODDEF \ |
9793 | | {"_clearenv", (PyCFunction)os__clearenv, METH_NOARGS, os__clearenv__doc__}, |
9794 | | |
9795 | | static PyObject * |
9796 | | os__clearenv_impl(PyObject *module); |
9797 | | |
9798 | | static PyObject * |
9799 | | os__clearenv(PyObject *module, PyObject *Py_UNUSED(ignored)) |
9800 | 0 | { |
9801 | 0 | return os__clearenv_impl(module); |
9802 | 0 | } |
9803 | | |
9804 | | #endif /* defined(HAVE_CLEARENV) */ |
9805 | | |
9806 | | PyDoc_STRVAR(os_strerror__doc__, |
9807 | | "strerror($module, code, /)\n" |
9808 | | "--\n" |
9809 | | "\n" |
9810 | | "Translate an error code to a message string."); |
9811 | | |
9812 | | #define OS_STRERROR_METHODDEF \ |
9813 | | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
9814 | | |
9815 | | static PyObject * |
9816 | | os_strerror_impl(PyObject *module, int code); |
9817 | | |
9818 | | static PyObject * |
9819 | | os_strerror(PyObject *module, PyObject *arg) |
9820 | 0 | { |
9821 | 0 | PyObject *return_value = NULL; |
9822 | 0 | int code; |
9823 | |
|
9824 | 0 | code = PyLong_AsInt(arg); |
9825 | 0 | if (code == -1 && PyErr_Occurred()) { |
9826 | 0 | goto exit; |
9827 | 0 | } |
9828 | 0 | return_value = os_strerror_impl(module, code); |
9829 | |
|
9830 | 0 | exit: |
9831 | 0 | return return_value; |
9832 | 0 | } |
9833 | | |
9834 | | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
9835 | | |
9836 | | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
9837 | | "WCOREDUMP($module, status, /)\n" |
9838 | | "--\n" |
9839 | | "\n" |
9840 | | "Return True if the process returning status was dumped to a core file."); |
9841 | | |
9842 | | #define OS_WCOREDUMP_METHODDEF \ |
9843 | | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
9844 | | |
9845 | | static int |
9846 | | os_WCOREDUMP_impl(PyObject *module, int status); |
9847 | | |
9848 | | static PyObject * |
9849 | | os_WCOREDUMP(PyObject *module, PyObject *arg) |
9850 | 0 | { |
9851 | 0 | PyObject *return_value = NULL; |
9852 | 0 | int status; |
9853 | 0 | int _return_value; |
9854 | |
|
9855 | 0 | status = PyLong_AsInt(arg); |
9856 | 0 | if (status == -1 && PyErr_Occurred()) { |
9857 | 0 | goto exit; |
9858 | 0 | } |
9859 | 0 | _return_value = os_WCOREDUMP_impl(module, status); |
9860 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9861 | 0 | goto exit; |
9862 | 0 | } |
9863 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9864 | |
|
9865 | 0 | exit: |
9866 | 0 | return return_value; |
9867 | 0 | } |
9868 | | |
9869 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
9870 | | |
9871 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
9872 | | |
9873 | | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
9874 | | "WIFCONTINUED($module, /, status)\n" |
9875 | | "--\n" |
9876 | | "\n" |
9877 | | "Return True if a particular process was continued from a job control stop.\n" |
9878 | | "\n" |
9879 | | "Return True if the process returning status was continued from a\n" |
9880 | | "job control stop."); |
9881 | | |
9882 | | #define OS_WIFCONTINUED_METHODDEF \ |
9883 | | {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__}, |
9884 | | |
9885 | | static int |
9886 | | os_WIFCONTINUED_impl(PyObject *module, int status); |
9887 | | |
9888 | | static PyObject * |
9889 | | os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9890 | 0 | { |
9891 | 0 | PyObject *return_value = NULL; |
9892 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9893 | |
|
9894 | 0 | #define NUM_KEYWORDS 1 |
9895 | 0 | static struct { |
9896 | 0 | PyGC_Head _this_is_not_used; |
9897 | 0 | PyObject_VAR_HEAD |
9898 | 0 | Py_hash_t ob_hash; |
9899 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9900 | 0 | } _kwtuple = { |
9901 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9902 | 0 | .ob_hash = -1, |
9903 | 0 | .ob_item = { &_Py_ID(status), }, |
9904 | 0 | }; |
9905 | 0 | #undef NUM_KEYWORDS |
9906 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9907 | |
|
9908 | | #else // !Py_BUILD_CORE |
9909 | | # define KWTUPLE NULL |
9910 | | #endif // !Py_BUILD_CORE |
9911 | |
|
9912 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9913 | 0 | static _PyArg_Parser _parser = { |
9914 | 0 | .keywords = _keywords, |
9915 | 0 | .fname = "WIFCONTINUED", |
9916 | 0 | .kwtuple = KWTUPLE, |
9917 | 0 | }; |
9918 | 0 | #undef KWTUPLE |
9919 | 0 | PyObject *argsbuf[1]; |
9920 | 0 | int status; |
9921 | 0 | int _return_value; |
9922 | |
|
9923 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9924 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9925 | 0 | if (!args) { |
9926 | 0 | goto exit; |
9927 | 0 | } |
9928 | 0 | status = PyLong_AsInt(args[0]); |
9929 | 0 | if (status == -1 && PyErr_Occurred()) { |
9930 | 0 | goto exit; |
9931 | 0 | } |
9932 | 0 | _return_value = os_WIFCONTINUED_impl(module, status); |
9933 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9934 | 0 | goto exit; |
9935 | 0 | } |
9936 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9937 | |
|
9938 | 0 | exit: |
9939 | 0 | return return_value; |
9940 | 0 | } |
9941 | | |
9942 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
9943 | | |
9944 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
9945 | | |
9946 | | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
9947 | | "WIFSTOPPED($module, /, status)\n" |
9948 | | "--\n" |
9949 | | "\n" |
9950 | | "Return True if the process returning status was stopped."); |
9951 | | |
9952 | | #define OS_WIFSTOPPED_METHODDEF \ |
9953 | | {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__}, |
9954 | | |
9955 | | static int |
9956 | | os_WIFSTOPPED_impl(PyObject *module, int status); |
9957 | | |
9958 | | static PyObject * |
9959 | | os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9960 | 0 | { |
9961 | 0 | PyObject *return_value = NULL; |
9962 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9963 | |
|
9964 | 0 | #define NUM_KEYWORDS 1 |
9965 | 0 | static struct { |
9966 | 0 | PyGC_Head _this_is_not_used; |
9967 | 0 | PyObject_VAR_HEAD |
9968 | 0 | Py_hash_t ob_hash; |
9969 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9970 | 0 | } _kwtuple = { |
9971 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9972 | 0 | .ob_hash = -1, |
9973 | 0 | .ob_item = { &_Py_ID(status), }, |
9974 | 0 | }; |
9975 | 0 | #undef NUM_KEYWORDS |
9976 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9977 | |
|
9978 | | #else // !Py_BUILD_CORE |
9979 | | # define KWTUPLE NULL |
9980 | | #endif // !Py_BUILD_CORE |
9981 | |
|
9982 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9983 | 0 | static _PyArg_Parser _parser = { |
9984 | 0 | .keywords = _keywords, |
9985 | 0 | .fname = "WIFSTOPPED", |
9986 | 0 | .kwtuple = KWTUPLE, |
9987 | 0 | }; |
9988 | 0 | #undef KWTUPLE |
9989 | 0 | PyObject *argsbuf[1]; |
9990 | 0 | int status; |
9991 | 0 | int _return_value; |
9992 | |
|
9993 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9994 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9995 | 0 | if (!args) { |
9996 | 0 | goto exit; |
9997 | 0 | } |
9998 | 0 | status = PyLong_AsInt(args[0]); |
9999 | 0 | if (status == -1 && PyErr_Occurred()) { |
10000 | 0 | goto exit; |
10001 | 0 | } |
10002 | 0 | _return_value = os_WIFSTOPPED_impl(module, status); |
10003 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10004 | 0 | goto exit; |
10005 | 0 | } |
10006 | 0 | return_value = PyBool_FromLong((long)_return_value); |
10007 | |
|
10008 | 0 | exit: |
10009 | 0 | return return_value; |
10010 | 0 | } |
10011 | | |
10012 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
10013 | | |
10014 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
10015 | | |
10016 | | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
10017 | | "WIFSIGNALED($module, /, status)\n" |
10018 | | "--\n" |
10019 | | "\n" |
10020 | | "Return True if the process returning status was terminated by a signal."); |
10021 | | |
10022 | | #define OS_WIFSIGNALED_METHODDEF \ |
10023 | | {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__}, |
10024 | | |
10025 | | static int |
10026 | | os_WIFSIGNALED_impl(PyObject *module, int status); |
10027 | | |
10028 | | static PyObject * |
10029 | | os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10030 | 0 | { |
10031 | 0 | PyObject *return_value = NULL; |
10032 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10033 | |
|
10034 | 0 | #define NUM_KEYWORDS 1 |
10035 | 0 | static struct { |
10036 | 0 | PyGC_Head _this_is_not_used; |
10037 | 0 | PyObject_VAR_HEAD |
10038 | 0 | Py_hash_t ob_hash; |
10039 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10040 | 0 | } _kwtuple = { |
10041 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10042 | 0 | .ob_hash = -1, |
10043 | 0 | .ob_item = { &_Py_ID(status), }, |
10044 | 0 | }; |
10045 | 0 | #undef NUM_KEYWORDS |
10046 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10047 | |
|
10048 | | #else // !Py_BUILD_CORE |
10049 | | # define KWTUPLE NULL |
10050 | | #endif // !Py_BUILD_CORE |
10051 | |
|
10052 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10053 | 0 | static _PyArg_Parser _parser = { |
10054 | 0 | .keywords = _keywords, |
10055 | 0 | .fname = "WIFSIGNALED", |
10056 | 0 | .kwtuple = KWTUPLE, |
10057 | 0 | }; |
10058 | 0 | #undef KWTUPLE |
10059 | 0 | PyObject *argsbuf[1]; |
10060 | 0 | int status; |
10061 | 0 | int _return_value; |
10062 | |
|
10063 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10064 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10065 | 0 | if (!args) { |
10066 | 0 | goto exit; |
10067 | 0 | } |
10068 | 0 | status = PyLong_AsInt(args[0]); |
10069 | 0 | if (status == -1 && PyErr_Occurred()) { |
10070 | 0 | goto exit; |
10071 | 0 | } |
10072 | 0 | _return_value = os_WIFSIGNALED_impl(module, status); |
10073 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10074 | 0 | goto exit; |
10075 | 0 | } |
10076 | 0 | return_value = PyBool_FromLong((long)_return_value); |
10077 | |
|
10078 | 0 | exit: |
10079 | 0 | return return_value; |
10080 | 0 | } |
10081 | | |
10082 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
10083 | | |
10084 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
10085 | | |
10086 | | PyDoc_STRVAR(os_WIFEXITED__doc__, |
10087 | | "WIFEXITED($module, /, status)\n" |
10088 | | "--\n" |
10089 | | "\n" |
10090 | | "Return True if the process returning status exited via the exit() system call."); |
10091 | | |
10092 | | #define OS_WIFEXITED_METHODDEF \ |
10093 | | {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__}, |
10094 | | |
10095 | | static int |
10096 | | os_WIFEXITED_impl(PyObject *module, int status); |
10097 | | |
10098 | | static PyObject * |
10099 | | os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10100 | 0 | { |
10101 | 0 | PyObject *return_value = NULL; |
10102 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10103 | |
|
10104 | 0 | #define NUM_KEYWORDS 1 |
10105 | 0 | static struct { |
10106 | 0 | PyGC_Head _this_is_not_used; |
10107 | 0 | PyObject_VAR_HEAD |
10108 | 0 | Py_hash_t ob_hash; |
10109 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10110 | 0 | } _kwtuple = { |
10111 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10112 | 0 | .ob_hash = -1, |
10113 | 0 | .ob_item = { &_Py_ID(status), }, |
10114 | 0 | }; |
10115 | 0 | #undef NUM_KEYWORDS |
10116 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10117 | |
|
10118 | | #else // !Py_BUILD_CORE |
10119 | | # define KWTUPLE NULL |
10120 | | #endif // !Py_BUILD_CORE |
10121 | |
|
10122 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10123 | 0 | static _PyArg_Parser _parser = { |
10124 | 0 | .keywords = _keywords, |
10125 | 0 | .fname = "WIFEXITED", |
10126 | 0 | .kwtuple = KWTUPLE, |
10127 | 0 | }; |
10128 | 0 | #undef KWTUPLE |
10129 | 0 | PyObject *argsbuf[1]; |
10130 | 0 | int status; |
10131 | 0 | int _return_value; |
10132 | |
|
10133 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10134 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10135 | 0 | if (!args) { |
10136 | 0 | goto exit; |
10137 | 0 | } |
10138 | 0 | status = PyLong_AsInt(args[0]); |
10139 | 0 | if (status == -1 && PyErr_Occurred()) { |
10140 | 0 | goto exit; |
10141 | 0 | } |
10142 | 0 | _return_value = os_WIFEXITED_impl(module, status); |
10143 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10144 | 0 | goto exit; |
10145 | 0 | } |
10146 | 0 | return_value = PyBool_FromLong((long)_return_value); |
10147 | |
|
10148 | 0 | exit: |
10149 | 0 | return return_value; |
10150 | 0 | } |
10151 | | |
10152 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
10153 | | |
10154 | | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
10155 | | |
10156 | | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
10157 | | "WEXITSTATUS($module, /, status)\n" |
10158 | | "--\n" |
10159 | | "\n" |
10160 | | "Return the process return code from status."); |
10161 | | |
10162 | | #define OS_WEXITSTATUS_METHODDEF \ |
10163 | | {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__}, |
10164 | | |
10165 | | static int |
10166 | | os_WEXITSTATUS_impl(PyObject *module, int status); |
10167 | | |
10168 | | static PyObject * |
10169 | | os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10170 | 0 | { |
10171 | 0 | PyObject *return_value = NULL; |
10172 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10173 | |
|
10174 | 0 | #define NUM_KEYWORDS 1 |
10175 | 0 | static struct { |
10176 | 0 | PyGC_Head _this_is_not_used; |
10177 | 0 | PyObject_VAR_HEAD |
10178 | 0 | Py_hash_t ob_hash; |
10179 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10180 | 0 | } _kwtuple = { |
10181 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10182 | 0 | .ob_hash = -1, |
10183 | 0 | .ob_item = { &_Py_ID(status), }, |
10184 | 0 | }; |
10185 | 0 | #undef NUM_KEYWORDS |
10186 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10187 | |
|
10188 | | #else // !Py_BUILD_CORE |
10189 | | # define KWTUPLE NULL |
10190 | | #endif // !Py_BUILD_CORE |
10191 | |
|
10192 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10193 | 0 | static _PyArg_Parser _parser = { |
10194 | 0 | .keywords = _keywords, |
10195 | 0 | .fname = "WEXITSTATUS", |
10196 | 0 | .kwtuple = KWTUPLE, |
10197 | 0 | }; |
10198 | 0 | #undef KWTUPLE |
10199 | 0 | PyObject *argsbuf[1]; |
10200 | 0 | int status; |
10201 | 0 | int _return_value; |
10202 | |
|
10203 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10204 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10205 | 0 | if (!args) { |
10206 | 0 | goto exit; |
10207 | 0 | } |
10208 | 0 | status = PyLong_AsInt(args[0]); |
10209 | 0 | if (status == -1 && PyErr_Occurred()) { |
10210 | 0 | goto exit; |
10211 | 0 | } |
10212 | 0 | _return_value = os_WEXITSTATUS_impl(module, status); |
10213 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10214 | 0 | goto exit; |
10215 | 0 | } |
10216 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10217 | |
|
10218 | 0 | exit: |
10219 | 0 | return return_value; |
10220 | 0 | } |
10221 | | |
10222 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
10223 | | |
10224 | | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
10225 | | |
10226 | | PyDoc_STRVAR(os_WTERMSIG__doc__, |
10227 | | "WTERMSIG($module, /, status)\n" |
10228 | | "--\n" |
10229 | | "\n" |
10230 | | "Return the signal that terminated the process that provided the status value."); |
10231 | | |
10232 | | #define OS_WTERMSIG_METHODDEF \ |
10233 | | {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__}, |
10234 | | |
10235 | | static int |
10236 | | os_WTERMSIG_impl(PyObject *module, int status); |
10237 | | |
10238 | | static PyObject * |
10239 | | os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10240 | 0 | { |
10241 | 0 | PyObject *return_value = NULL; |
10242 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10243 | |
|
10244 | 0 | #define NUM_KEYWORDS 1 |
10245 | 0 | static struct { |
10246 | 0 | PyGC_Head _this_is_not_used; |
10247 | 0 | PyObject_VAR_HEAD |
10248 | 0 | Py_hash_t ob_hash; |
10249 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10250 | 0 | } _kwtuple = { |
10251 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10252 | 0 | .ob_hash = -1, |
10253 | 0 | .ob_item = { &_Py_ID(status), }, |
10254 | 0 | }; |
10255 | 0 | #undef NUM_KEYWORDS |
10256 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10257 | |
|
10258 | | #else // !Py_BUILD_CORE |
10259 | | # define KWTUPLE NULL |
10260 | | #endif // !Py_BUILD_CORE |
10261 | |
|
10262 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10263 | 0 | static _PyArg_Parser _parser = { |
10264 | 0 | .keywords = _keywords, |
10265 | 0 | .fname = "WTERMSIG", |
10266 | 0 | .kwtuple = KWTUPLE, |
10267 | 0 | }; |
10268 | 0 | #undef KWTUPLE |
10269 | 0 | PyObject *argsbuf[1]; |
10270 | 0 | int status; |
10271 | 0 | int _return_value; |
10272 | |
|
10273 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10274 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10275 | 0 | if (!args) { |
10276 | 0 | goto exit; |
10277 | 0 | } |
10278 | 0 | status = PyLong_AsInt(args[0]); |
10279 | 0 | if (status == -1 && PyErr_Occurred()) { |
10280 | 0 | goto exit; |
10281 | 0 | } |
10282 | 0 | _return_value = os_WTERMSIG_impl(module, status); |
10283 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10284 | 0 | goto exit; |
10285 | 0 | } |
10286 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10287 | |
|
10288 | 0 | exit: |
10289 | 0 | return return_value; |
10290 | 0 | } |
10291 | | |
10292 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
10293 | | |
10294 | | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
10295 | | |
10296 | | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
10297 | | "WSTOPSIG($module, /, status)\n" |
10298 | | "--\n" |
10299 | | "\n" |
10300 | | "Return the signal that stopped the process that provided the status value."); |
10301 | | |
10302 | | #define OS_WSTOPSIG_METHODDEF \ |
10303 | | {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__}, |
10304 | | |
10305 | | static int |
10306 | | os_WSTOPSIG_impl(PyObject *module, int status); |
10307 | | |
10308 | | static PyObject * |
10309 | | os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10310 | 0 | { |
10311 | 0 | PyObject *return_value = NULL; |
10312 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10313 | |
|
10314 | 0 | #define NUM_KEYWORDS 1 |
10315 | 0 | static struct { |
10316 | 0 | PyGC_Head _this_is_not_used; |
10317 | 0 | PyObject_VAR_HEAD |
10318 | 0 | Py_hash_t ob_hash; |
10319 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10320 | 0 | } _kwtuple = { |
10321 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10322 | 0 | .ob_hash = -1, |
10323 | 0 | .ob_item = { &_Py_ID(status), }, |
10324 | 0 | }; |
10325 | 0 | #undef NUM_KEYWORDS |
10326 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10327 | |
|
10328 | | #else // !Py_BUILD_CORE |
10329 | | # define KWTUPLE NULL |
10330 | | #endif // !Py_BUILD_CORE |
10331 | |
|
10332 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10333 | 0 | static _PyArg_Parser _parser = { |
10334 | 0 | .keywords = _keywords, |
10335 | 0 | .fname = "WSTOPSIG", |
10336 | 0 | .kwtuple = KWTUPLE, |
10337 | 0 | }; |
10338 | 0 | #undef KWTUPLE |
10339 | 0 | PyObject *argsbuf[1]; |
10340 | 0 | int status; |
10341 | 0 | int _return_value; |
10342 | |
|
10343 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10344 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10345 | 0 | if (!args) { |
10346 | 0 | goto exit; |
10347 | 0 | } |
10348 | 0 | status = PyLong_AsInt(args[0]); |
10349 | 0 | if (status == -1 && PyErr_Occurred()) { |
10350 | 0 | goto exit; |
10351 | 0 | } |
10352 | 0 | _return_value = os_WSTOPSIG_impl(module, status); |
10353 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10354 | 0 | goto exit; |
10355 | 0 | } |
10356 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10357 | |
|
10358 | 0 | exit: |
10359 | 0 | return return_value; |
10360 | 0 | } |
10361 | | |
10362 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
10363 | | |
10364 | | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10365 | | |
10366 | | PyDoc_STRVAR(os_fstatvfs__doc__, |
10367 | | "fstatvfs($module, fd, /)\n" |
10368 | | "--\n" |
10369 | | "\n" |
10370 | | "Perform an fstatvfs system call on the given fd.\n" |
10371 | | "\n" |
10372 | | "Equivalent to statvfs(fd)."); |
10373 | | |
10374 | | #define OS_FSTATVFS_METHODDEF \ |
10375 | | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
10376 | | |
10377 | | static PyObject * |
10378 | | os_fstatvfs_impl(PyObject *module, int fd); |
10379 | | |
10380 | | static PyObject * |
10381 | | os_fstatvfs(PyObject *module, PyObject *arg) |
10382 | 0 | { |
10383 | 0 | PyObject *return_value = NULL; |
10384 | 0 | int fd; |
10385 | |
|
10386 | 0 | fd = PyLong_AsInt(arg); |
10387 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10388 | 0 | goto exit; |
10389 | 0 | } |
10390 | 0 | return_value = os_fstatvfs_impl(module, fd); |
10391 | |
|
10392 | 0 | exit: |
10393 | 0 | return return_value; |
10394 | 0 | } |
10395 | | |
10396 | | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10397 | | |
10398 | | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10399 | | |
10400 | | PyDoc_STRVAR(os_statvfs__doc__, |
10401 | | "statvfs($module, /, path)\n" |
10402 | | "--\n" |
10403 | | "\n" |
10404 | | "Perform a statvfs system call on the given path.\n" |
10405 | | "\n" |
10406 | | "path may always be specified as a string.\n" |
10407 | | "On some platforms, path may also be specified as an open file\n" |
10408 | | "descriptor. If this functionality is unavailable, using it raises\n" |
10409 | | "an exception."); |
10410 | | |
10411 | | #define OS_STATVFS_METHODDEF \ |
10412 | | {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__}, |
10413 | | |
10414 | | static PyObject * |
10415 | | os_statvfs_impl(PyObject *module, path_t *path); |
10416 | | |
10417 | | static PyObject * |
10418 | | os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10419 | 0 | { |
10420 | 0 | PyObject *return_value = NULL; |
10421 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10422 | |
|
10423 | 0 | #define NUM_KEYWORDS 1 |
10424 | 0 | static struct { |
10425 | 0 | PyGC_Head _this_is_not_used; |
10426 | 0 | PyObject_VAR_HEAD |
10427 | 0 | Py_hash_t ob_hash; |
10428 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10429 | 0 | } _kwtuple = { |
10430 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10431 | 0 | .ob_hash = -1, |
10432 | 0 | .ob_item = { &_Py_ID(path), }, |
10433 | 0 | }; |
10434 | 0 | #undef NUM_KEYWORDS |
10435 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10436 | |
|
10437 | | #else // !Py_BUILD_CORE |
10438 | | # define KWTUPLE NULL |
10439 | | #endif // !Py_BUILD_CORE |
10440 | |
|
10441 | 0 | static const char * const _keywords[] = {"path", NULL}; |
10442 | 0 | static _PyArg_Parser _parser = { |
10443 | 0 | .keywords = _keywords, |
10444 | 0 | .fname = "statvfs", |
10445 | 0 | .kwtuple = KWTUPLE, |
10446 | 0 | }; |
10447 | 0 | #undef KWTUPLE |
10448 | 0 | PyObject *argsbuf[1]; |
10449 | 0 | path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS); |
10450 | |
|
10451 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10452 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10453 | 0 | if (!args) { |
10454 | 0 | goto exit; |
10455 | 0 | } |
10456 | 0 | if (!path_converter(args[0], &path)) { |
10457 | 0 | goto exit; |
10458 | 0 | } |
10459 | 0 | return_value = os_statvfs_impl(module, &path); |
10460 | |
|
10461 | 0 | exit: |
10462 | | /* Cleanup for path */ |
10463 | 0 | path_cleanup(&path); |
10464 | |
|
10465 | 0 | return return_value; |
10466 | 0 | } |
10467 | | |
10468 | | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10469 | | |
10470 | | #if defined(MS_WINDOWS) |
10471 | | |
10472 | | PyDoc_STRVAR(os__getdiskusage__doc__, |
10473 | | "_getdiskusage($module, /, path)\n" |
10474 | | "--\n" |
10475 | | "\n" |
10476 | | "Return disk usage statistics about the given path as a (total, free) tuple."); |
10477 | | |
10478 | | #define OS__GETDISKUSAGE_METHODDEF \ |
10479 | | {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__}, |
10480 | | |
10481 | | static PyObject * |
10482 | | os__getdiskusage_impl(PyObject *module, path_t *path); |
10483 | | |
10484 | | static PyObject * |
10485 | | os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10486 | | { |
10487 | | PyObject *return_value = NULL; |
10488 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10489 | | |
10490 | | #define NUM_KEYWORDS 1 |
10491 | | static struct { |
10492 | | PyGC_Head _this_is_not_used; |
10493 | | PyObject_VAR_HEAD |
10494 | | Py_hash_t ob_hash; |
10495 | | PyObject *ob_item[NUM_KEYWORDS]; |
10496 | | } _kwtuple = { |
10497 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10498 | | .ob_hash = -1, |
10499 | | .ob_item = { &_Py_ID(path), }, |
10500 | | }; |
10501 | | #undef NUM_KEYWORDS |
10502 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10503 | | |
10504 | | #else // !Py_BUILD_CORE |
10505 | | # define KWTUPLE NULL |
10506 | | #endif // !Py_BUILD_CORE |
10507 | | |
10508 | | static const char * const _keywords[] = {"path", NULL}; |
10509 | | static _PyArg_Parser _parser = { |
10510 | | .keywords = _keywords, |
10511 | | .fname = "_getdiskusage", |
10512 | | .kwtuple = KWTUPLE, |
10513 | | }; |
10514 | | #undef KWTUPLE |
10515 | | PyObject *argsbuf[1]; |
10516 | | path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0); |
10517 | | |
10518 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10519 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10520 | | if (!args) { |
10521 | | goto exit; |
10522 | | } |
10523 | | if (!path_converter(args[0], &path)) { |
10524 | | goto exit; |
10525 | | } |
10526 | | return_value = os__getdiskusage_impl(module, &path); |
10527 | | |
10528 | | exit: |
10529 | | /* Cleanup for path */ |
10530 | | path_cleanup(&path); |
10531 | | |
10532 | | return return_value; |
10533 | | } |
10534 | | |
10535 | | #endif /* defined(MS_WINDOWS) */ |
10536 | | |
10537 | | #if defined(HAVE_FPATHCONF) |
10538 | | |
10539 | | PyDoc_STRVAR(os_fpathconf__doc__, |
10540 | | "fpathconf($module, fd, name, /)\n" |
10541 | | "--\n" |
10542 | | "\n" |
10543 | | "Return the configuration limit name for the file descriptor fd.\n" |
10544 | | "\n" |
10545 | | "If there is no limit, return -1."); |
10546 | | |
10547 | | #define OS_FPATHCONF_METHODDEF \ |
10548 | | {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__}, |
10549 | | |
10550 | | static long |
10551 | | os_fpathconf_impl(PyObject *module, int fd, int name); |
10552 | | |
10553 | | static PyObject * |
10554 | | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10555 | 0 | { |
10556 | 0 | PyObject *return_value = NULL; |
10557 | 0 | int fd; |
10558 | 0 | int name; |
10559 | 0 | long _return_value; |
10560 | |
|
10561 | 0 | if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { |
10562 | 0 | goto exit; |
10563 | 0 | } |
10564 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
10565 | 0 | if (fd < 0) { |
10566 | 0 | goto exit; |
10567 | 0 | } |
10568 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10569 | 0 | goto exit; |
10570 | 0 | } |
10571 | 0 | _return_value = os_fpathconf_impl(module, fd, name); |
10572 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10573 | 0 | goto exit; |
10574 | 0 | } |
10575 | 0 | return_value = PyLong_FromLong(_return_value); |
10576 | |
|
10577 | 0 | exit: |
10578 | 0 | return return_value; |
10579 | 0 | } |
10580 | | |
10581 | | #endif /* defined(HAVE_FPATHCONF) */ |
10582 | | |
10583 | | #if defined(HAVE_PATHCONF) |
10584 | | |
10585 | | PyDoc_STRVAR(os_pathconf__doc__, |
10586 | | "pathconf($module, /, path, name)\n" |
10587 | | "--\n" |
10588 | | "\n" |
10589 | | "Return the configuration limit name for the file or directory path.\n" |
10590 | | "\n" |
10591 | | "If there is no limit, return -1.\n" |
10592 | | "On some platforms, path may also be specified as an open file\n" |
10593 | | "descriptor. If this functionality is unavailable, using it raises\n" |
10594 | | "an exception."); |
10595 | | |
10596 | | #define OS_PATHCONF_METHODDEF \ |
10597 | | {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__}, |
10598 | | |
10599 | | static long |
10600 | | os_pathconf_impl(PyObject *module, path_t *path, int name); |
10601 | | |
10602 | | static PyObject * |
10603 | | os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10604 | 0 | { |
10605 | 0 | PyObject *return_value = NULL; |
10606 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10607 | |
|
10608 | 0 | #define NUM_KEYWORDS 2 |
10609 | 0 | static struct { |
10610 | 0 | PyGC_Head _this_is_not_used; |
10611 | 0 | PyObject_VAR_HEAD |
10612 | 0 | Py_hash_t ob_hash; |
10613 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10614 | 0 | } _kwtuple = { |
10615 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10616 | 0 | .ob_hash = -1, |
10617 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(name), }, |
10618 | 0 | }; |
10619 | 0 | #undef NUM_KEYWORDS |
10620 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10621 | |
|
10622 | | #else // !Py_BUILD_CORE |
10623 | | # define KWTUPLE NULL |
10624 | | #endif // !Py_BUILD_CORE |
10625 | |
|
10626 | 0 | static const char * const _keywords[] = {"path", "name", NULL}; |
10627 | 0 | static _PyArg_Parser _parser = { |
10628 | 0 | .keywords = _keywords, |
10629 | 0 | .fname = "pathconf", |
10630 | 0 | .kwtuple = KWTUPLE, |
10631 | 0 | }; |
10632 | 0 | #undef KWTUPLE |
10633 | 0 | PyObject *argsbuf[2]; |
10634 | 0 | path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF); |
10635 | 0 | int name; |
10636 | 0 | long _return_value; |
10637 | |
|
10638 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10639 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10640 | 0 | if (!args) { |
10641 | 0 | goto exit; |
10642 | 0 | } |
10643 | 0 | if (!path_converter(args[0], &path)) { |
10644 | 0 | goto exit; |
10645 | 0 | } |
10646 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10647 | 0 | goto exit; |
10648 | 0 | } |
10649 | 0 | _return_value = os_pathconf_impl(module, &path, name); |
10650 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10651 | 0 | goto exit; |
10652 | 0 | } |
10653 | 0 | return_value = PyLong_FromLong(_return_value); |
10654 | |
|
10655 | 0 | exit: |
10656 | | /* Cleanup for path */ |
10657 | 0 | path_cleanup(&path); |
10658 | |
|
10659 | 0 | return return_value; |
10660 | 0 | } |
10661 | | |
10662 | | #endif /* defined(HAVE_PATHCONF) */ |
10663 | | |
10664 | | #if defined(HAVE_CONFSTR) |
10665 | | |
10666 | | PyDoc_STRVAR(os_confstr__doc__, |
10667 | | "confstr($module, name, /)\n" |
10668 | | "--\n" |
10669 | | "\n" |
10670 | | "Return a string-valued system configuration variable."); |
10671 | | |
10672 | | #define OS_CONFSTR_METHODDEF \ |
10673 | | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
10674 | | |
10675 | | static PyObject * |
10676 | | os_confstr_impl(PyObject *module, int name); |
10677 | | |
10678 | | static PyObject * |
10679 | | os_confstr(PyObject *module, PyObject *arg) |
10680 | 4 | { |
10681 | 4 | PyObject *return_value = NULL; |
10682 | 4 | int name; |
10683 | | |
10684 | 4 | if (!conv_confname(module, arg, &name, "confstr_names")) { |
10685 | 0 | goto exit; |
10686 | 0 | } |
10687 | 4 | return_value = os_confstr_impl(module, name); |
10688 | | |
10689 | 4 | exit: |
10690 | 4 | return return_value; |
10691 | 4 | } |
10692 | | |
10693 | | #endif /* defined(HAVE_CONFSTR) */ |
10694 | | |
10695 | | #if defined(HAVE_SYSCONF) |
10696 | | |
10697 | | PyDoc_STRVAR(os_sysconf__doc__, |
10698 | | "sysconf($module, name, /)\n" |
10699 | | "--\n" |
10700 | | "\n" |
10701 | | "Return an integer-valued system configuration variable."); |
10702 | | |
10703 | | #define OS_SYSCONF_METHODDEF \ |
10704 | | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
10705 | | |
10706 | | static long |
10707 | | os_sysconf_impl(PyObject *module, int name); |
10708 | | |
10709 | | static PyObject * |
10710 | | os_sysconf(PyObject *module, PyObject *arg) |
10711 | 0 | { |
10712 | 0 | PyObject *return_value = NULL; |
10713 | 0 | int name; |
10714 | 0 | long _return_value; |
10715 | |
|
10716 | 0 | if (!conv_confname(module, arg, &name, "sysconf_names")) { |
10717 | 0 | goto exit; |
10718 | 0 | } |
10719 | 0 | _return_value = os_sysconf_impl(module, name); |
10720 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10721 | 0 | goto exit; |
10722 | 0 | } |
10723 | 0 | return_value = PyLong_FromLong(_return_value); |
10724 | |
|
10725 | 0 | exit: |
10726 | 0 | return return_value; |
10727 | 0 | } |
10728 | | |
10729 | | #endif /* defined(HAVE_SYSCONF) */ |
10730 | | |
10731 | | PyDoc_STRVAR(os_abort__doc__, |
10732 | | "abort($module, /)\n" |
10733 | | "--\n" |
10734 | | "\n" |
10735 | | "Abort the interpreter immediately.\n" |
10736 | | "\n" |
10737 | | "This function \'dumps core\' or otherwise fails in the hardest way\n" |
10738 | | "possible on the hosting operating system. This function never returns."); |
10739 | | |
10740 | | #define OS_ABORT_METHODDEF \ |
10741 | | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
10742 | | |
10743 | | static PyObject * |
10744 | | os_abort_impl(PyObject *module); |
10745 | | |
10746 | | static PyObject * |
10747 | | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10748 | 0 | { |
10749 | 0 | return os_abort_impl(module); |
10750 | 0 | } |
10751 | | |
10752 | | #if defined(MS_WINDOWS) |
10753 | | |
10754 | | PyDoc_STRVAR(os_startfile__doc__, |
10755 | | "startfile($module, /, filepath, operation=<unrepresentable>,\n" |
10756 | | " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n" |
10757 | | "--\n" |
10758 | | "\n" |
10759 | | "Start a file with its associated application.\n" |
10760 | | "\n" |
10761 | | "When \"operation\" is not specified or \"open\", this acts like\n" |
10762 | | "double-clicking the file in Explorer, or giving the file name as an\n" |
10763 | | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
10764 | | "application (if any) its extension is associated.\n" |
10765 | | "When another \"operation\" is given, it specifies what should be done with\n" |
10766 | | "the file. A typical operation is \"print\".\n" |
10767 | | "\n" |
10768 | | "\"arguments\" is passed to the application, but should be omitted if the\n" |
10769 | | "file is a document.\n" |
10770 | | "\n" |
10771 | | "\"cwd\" is the working directory for the operation. If \"filepath\" is\n" |
10772 | | "relative, it will be resolved against this directory. This argument\n" |
10773 | | "should usually be an absolute path.\n" |
10774 | | "\n" |
10775 | | "\"show_cmd\" can be used to override the recommended visibility option.\n" |
10776 | | "See the Windows ShellExecute documentation for values.\n" |
10777 | | "\n" |
10778 | | "startfile returns as soon as the associated application is launched.\n" |
10779 | | "There is no option to wait for the application to close, and no way\n" |
10780 | | "to retrieve the application\'s exit status.\n" |
10781 | | "\n" |
10782 | | "The filepath is relative to the current directory. If you want to use\n" |
10783 | | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
10784 | | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
10785 | | |
10786 | | #define OS_STARTFILE_METHODDEF \ |
10787 | | {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__}, |
10788 | | |
10789 | | static PyObject * |
10790 | | os_startfile_impl(PyObject *module, path_t *filepath, |
10791 | | const wchar_t *operation, const wchar_t *arguments, |
10792 | | path_t *cwd, int show_cmd); |
10793 | | |
10794 | | static PyObject * |
10795 | | os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10796 | | { |
10797 | | PyObject *return_value = NULL; |
10798 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10799 | | |
10800 | | #define NUM_KEYWORDS 5 |
10801 | | static struct { |
10802 | | PyGC_Head _this_is_not_used; |
10803 | | PyObject_VAR_HEAD |
10804 | | Py_hash_t ob_hash; |
10805 | | PyObject *ob_item[NUM_KEYWORDS]; |
10806 | | } _kwtuple = { |
10807 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10808 | | .ob_hash = -1, |
10809 | | .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), }, |
10810 | | }; |
10811 | | #undef NUM_KEYWORDS |
10812 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10813 | | |
10814 | | #else // !Py_BUILD_CORE |
10815 | | # define KWTUPLE NULL |
10816 | | #endif // !Py_BUILD_CORE |
10817 | | |
10818 | | static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL}; |
10819 | | static _PyArg_Parser _parser = { |
10820 | | .keywords = _keywords, |
10821 | | .fname = "startfile", |
10822 | | .kwtuple = KWTUPLE, |
10823 | | }; |
10824 | | #undef KWTUPLE |
10825 | | PyObject *argsbuf[5]; |
10826 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
10827 | | path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0); |
10828 | | const wchar_t *operation = NULL; |
10829 | | const wchar_t *arguments = NULL; |
10830 | | path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0); |
10831 | | int show_cmd = 1; |
10832 | | |
10833 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10834 | | /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10835 | | if (!args) { |
10836 | | goto exit; |
10837 | | } |
10838 | | if (!path_converter(args[0], &filepath)) { |
10839 | | goto exit; |
10840 | | } |
10841 | | if (!noptargs) { |
10842 | | goto skip_optional_pos; |
10843 | | } |
10844 | | if (args[1]) { |
10845 | | if (!PyUnicode_Check(args[1])) { |
10846 | | _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]); |
10847 | | goto exit; |
10848 | | } |
10849 | | operation = PyUnicode_AsWideCharString(args[1], NULL); |
10850 | | if (operation == NULL) { |
10851 | | goto exit; |
10852 | | } |
10853 | | if (!--noptargs) { |
10854 | | goto skip_optional_pos; |
10855 | | } |
10856 | | } |
10857 | | if (args[2]) { |
10858 | | if (!PyUnicode_Check(args[2])) { |
10859 | | _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]); |
10860 | | goto exit; |
10861 | | } |
10862 | | arguments = PyUnicode_AsWideCharString(args[2], NULL); |
10863 | | if (arguments == NULL) { |
10864 | | goto exit; |
10865 | | } |
10866 | | if (!--noptargs) { |
10867 | | goto skip_optional_pos; |
10868 | | } |
10869 | | } |
10870 | | if (args[3]) { |
10871 | | if (!path_converter(args[3], &cwd)) { |
10872 | | goto exit; |
10873 | | } |
10874 | | if (!--noptargs) { |
10875 | | goto skip_optional_pos; |
10876 | | } |
10877 | | } |
10878 | | show_cmd = PyLong_AsInt(args[4]); |
10879 | | if (show_cmd == -1 && PyErr_Occurred()) { |
10880 | | goto exit; |
10881 | | } |
10882 | | skip_optional_pos: |
10883 | | return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd); |
10884 | | |
10885 | | exit: |
10886 | | /* Cleanup for filepath */ |
10887 | | path_cleanup(&filepath); |
10888 | | /* Cleanup for operation */ |
10889 | | PyMem_Free((void *)operation); |
10890 | | /* Cleanup for arguments */ |
10891 | | PyMem_Free((void *)arguments); |
10892 | | /* Cleanup for cwd */ |
10893 | | path_cleanup(&cwd); |
10894 | | |
10895 | | return return_value; |
10896 | | } |
10897 | | |
10898 | | #endif /* defined(MS_WINDOWS) */ |
10899 | | |
10900 | | #if defined(HAVE_GETLOADAVG) |
10901 | | |
10902 | | PyDoc_STRVAR(os_getloadavg__doc__, |
10903 | | "getloadavg($module, /)\n" |
10904 | | "--\n" |
10905 | | "\n" |
10906 | | "Return average recent system load information.\n" |
10907 | | "\n" |
10908 | | "Return the number of processes in the system run queue averaged over\n" |
10909 | | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
10910 | | "Raises OSError if the load average was unobtainable."); |
10911 | | |
10912 | | #define OS_GETLOADAVG_METHODDEF \ |
10913 | | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
10914 | | |
10915 | | static PyObject * |
10916 | | os_getloadavg_impl(PyObject *module); |
10917 | | |
10918 | | static PyObject * |
10919 | | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10920 | 0 | { |
10921 | 0 | return os_getloadavg_impl(module); |
10922 | 0 | } |
10923 | | |
10924 | | #endif /* defined(HAVE_GETLOADAVG) */ |
10925 | | |
10926 | | PyDoc_STRVAR(os_device_encoding__doc__, |
10927 | | "device_encoding($module, /, fd)\n" |
10928 | | "--\n" |
10929 | | "\n" |
10930 | | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
10931 | | "\n" |
10932 | | "The file descriptor must be attached to a terminal.\n" |
10933 | | "If the device is not a terminal, return None."); |
10934 | | |
10935 | | #define OS_DEVICE_ENCODING_METHODDEF \ |
10936 | | {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__}, |
10937 | | |
10938 | | static PyObject * |
10939 | | os_device_encoding_impl(PyObject *module, int fd); |
10940 | | |
10941 | | static PyObject * |
10942 | | os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10943 | 0 | { |
10944 | 0 | PyObject *return_value = NULL; |
10945 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10946 | |
|
10947 | 0 | #define NUM_KEYWORDS 1 |
10948 | 0 | static struct { |
10949 | 0 | PyGC_Head _this_is_not_used; |
10950 | 0 | PyObject_VAR_HEAD |
10951 | 0 | Py_hash_t ob_hash; |
10952 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10953 | 0 | } _kwtuple = { |
10954 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10955 | 0 | .ob_hash = -1, |
10956 | 0 | .ob_item = { &_Py_ID(fd), }, |
10957 | 0 | }; |
10958 | 0 | #undef NUM_KEYWORDS |
10959 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10960 | |
|
10961 | | #else // !Py_BUILD_CORE |
10962 | | # define KWTUPLE NULL |
10963 | | #endif // !Py_BUILD_CORE |
10964 | |
|
10965 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
10966 | 0 | static _PyArg_Parser _parser = { |
10967 | 0 | .keywords = _keywords, |
10968 | 0 | .fname = "device_encoding", |
10969 | 0 | .kwtuple = KWTUPLE, |
10970 | 0 | }; |
10971 | 0 | #undef KWTUPLE |
10972 | 0 | PyObject *argsbuf[1]; |
10973 | 0 | int fd; |
10974 | |
|
10975 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10976 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10977 | 0 | if (!args) { |
10978 | 0 | goto exit; |
10979 | 0 | } |
10980 | 0 | fd = PyLong_AsInt(args[0]); |
10981 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10982 | 0 | goto exit; |
10983 | 0 | } |
10984 | 0 | return_value = os_device_encoding_impl(module, fd); |
10985 | |
|
10986 | 0 | exit: |
10987 | 0 | return return_value; |
10988 | 0 | } |
10989 | | |
10990 | | #if defined(HAVE_SETRESUID) |
10991 | | |
10992 | | PyDoc_STRVAR(os_setresuid__doc__, |
10993 | | "setresuid($module, ruid, euid, suid, /)\n" |
10994 | | "--\n" |
10995 | | "\n" |
10996 | | "Set the current process\'s real, effective, and saved user ids."); |
10997 | | |
10998 | | #define OS_SETRESUID_METHODDEF \ |
10999 | | {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__}, |
11000 | | |
11001 | | static PyObject * |
11002 | | os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid); |
11003 | | |
11004 | | static PyObject * |
11005 | | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11006 | 0 | { |
11007 | 0 | PyObject *return_value = NULL; |
11008 | 0 | uid_t ruid; |
11009 | 0 | uid_t euid; |
11010 | 0 | uid_t suid; |
11011 | |
|
11012 | 0 | if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { |
11013 | 0 | goto exit; |
11014 | 0 | } |
11015 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
11016 | 0 | goto exit; |
11017 | 0 | } |
11018 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
11019 | 0 | goto exit; |
11020 | 0 | } |
11021 | 0 | if (!_Py_Uid_Converter(args[2], &suid)) { |
11022 | 0 | goto exit; |
11023 | 0 | } |
11024 | 0 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
11025 | |
|
11026 | 0 | exit: |
11027 | 0 | return return_value; |
11028 | 0 | } |
11029 | | |
11030 | | #endif /* defined(HAVE_SETRESUID) */ |
11031 | | |
11032 | | #if defined(HAVE_SETRESGID) |
11033 | | |
11034 | | PyDoc_STRVAR(os_setresgid__doc__, |
11035 | | "setresgid($module, rgid, egid, sgid, /)\n" |
11036 | | "--\n" |
11037 | | "\n" |
11038 | | "Set the current process\'s real, effective, and saved group ids."); |
11039 | | |
11040 | | #define OS_SETRESGID_METHODDEF \ |
11041 | | {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__}, |
11042 | | |
11043 | | static PyObject * |
11044 | | os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid); |
11045 | | |
11046 | | static PyObject * |
11047 | | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11048 | 0 | { |
11049 | 0 | PyObject *return_value = NULL; |
11050 | 0 | gid_t rgid; |
11051 | 0 | gid_t egid; |
11052 | 0 | gid_t sgid; |
11053 | |
|
11054 | 0 | if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { |
11055 | 0 | goto exit; |
11056 | 0 | } |
11057 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
11058 | 0 | goto exit; |
11059 | 0 | } |
11060 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
11061 | 0 | goto exit; |
11062 | 0 | } |
11063 | 0 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
11064 | 0 | goto exit; |
11065 | 0 | } |
11066 | 0 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
11067 | |
|
11068 | 0 | exit: |
11069 | 0 | return return_value; |
11070 | 0 | } |
11071 | | |
11072 | | #endif /* defined(HAVE_SETRESGID) */ |
11073 | | |
11074 | | #if defined(HAVE_GETRESUID) |
11075 | | |
11076 | | PyDoc_STRVAR(os_getresuid__doc__, |
11077 | | "getresuid($module, /)\n" |
11078 | | "--\n" |
11079 | | "\n" |
11080 | | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
11081 | | |
11082 | | #define OS_GETRESUID_METHODDEF \ |
11083 | | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
11084 | | |
11085 | | static PyObject * |
11086 | | os_getresuid_impl(PyObject *module); |
11087 | | |
11088 | | static PyObject * |
11089 | | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
11090 | 0 | { |
11091 | 0 | return os_getresuid_impl(module); |
11092 | 0 | } |
11093 | | |
11094 | | #endif /* defined(HAVE_GETRESUID) */ |
11095 | | |
11096 | | #if defined(HAVE_GETRESGID) |
11097 | | |
11098 | | PyDoc_STRVAR(os_getresgid__doc__, |
11099 | | "getresgid($module, /)\n" |
11100 | | "--\n" |
11101 | | "\n" |
11102 | | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
11103 | | |
11104 | | #define OS_GETRESGID_METHODDEF \ |
11105 | | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
11106 | | |
11107 | | static PyObject * |
11108 | | os_getresgid_impl(PyObject *module); |
11109 | | |
11110 | | static PyObject * |
11111 | | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
11112 | 0 | { |
11113 | 0 | return os_getresgid_impl(module); |
11114 | 0 | } |
11115 | | |
11116 | | #endif /* defined(HAVE_GETRESGID) */ |
11117 | | |
11118 | | #if defined(USE_XATTRS) |
11119 | | |
11120 | | PyDoc_STRVAR(os_getxattr__doc__, |
11121 | | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
11122 | | "--\n" |
11123 | | "\n" |
11124 | | "Return the value of extended attribute attribute on path.\n" |
11125 | | "\n" |
11126 | | "path may be either a string, a path-like object, or an open file\n" |
11127 | | "descriptor.\n" |
11128 | | "If follow_symlinks is False, and the last element of the path is\n" |
11129 | | "a symbolic link, getxattr will examine the symbolic link itself\n" |
11130 | | "instead of the file the link points to."); |
11131 | | |
11132 | | #define OS_GETXATTR_METHODDEF \ |
11133 | | {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__}, |
11134 | | |
11135 | | static PyObject * |
11136 | | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11137 | | int follow_symlinks); |
11138 | | |
11139 | | static PyObject * |
11140 | | os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11141 | 0 | { |
11142 | 0 | PyObject *return_value = NULL; |
11143 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11144 | |
|
11145 | 0 | #define NUM_KEYWORDS 3 |
11146 | 0 | static struct { |
11147 | 0 | PyGC_Head _this_is_not_used; |
11148 | 0 | PyObject_VAR_HEAD |
11149 | 0 | Py_hash_t ob_hash; |
11150 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11151 | 0 | } _kwtuple = { |
11152 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11153 | 0 | .ob_hash = -1, |
11154 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
11155 | 0 | }; |
11156 | 0 | #undef NUM_KEYWORDS |
11157 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11158 | |
|
11159 | | #else // !Py_BUILD_CORE |
11160 | | # define KWTUPLE NULL |
11161 | | #endif // !Py_BUILD_CORE |
11162 | |
|
11163 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
11164 | 0 | static _PyArg_Parser _parser = { |
11165 | 0 | .keywords = _keywords, |
11166 | 0 | .fname = "getxattr", |
11167 | 0 | .kwtuple = KWTUPLE, |
11168 | 0 | }; |
11169 | 0 | #undef KWTUPLE |
11170 | 0 | PyObject *argsbuf[3]; |
11171 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
11172 | 0 | path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1); |
11173 | 0 | path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0); |
11174 | 0 | int follow_symlinks = 1; |
11175 | |
|
11176 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11177 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11178 | 0 | if (!args) { |
11179 | 0 | goto exit; |
11180 | 0 | } |
11181 | 0 | if (!path_converter(args[0], &path)) { |
11182 | 0 | goto exit; |
11183 | 0 | } |
11184 | 0 | if (!path_converter(args[1], &attribute)) { |
11185 | 0 | goto exit; |
11186 | 0 | } |
11187 | 0 | if (!noptargs) { |
11188 | 0 | goto skip_optional_kwonly; |
11189 | 0 | } |
11190 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
11191 | 0 | if (follow_symlinks < 0) { |
11192 | 0 | goto exit; |
11193 | 0 | } |
11194 | 0 | skip_optional_kwonly: |
11195 | 0 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
11196 | |
|
11197 | 0 | exit: |
11198 | | /* Cleanup for path */ |
11199 | 0 | path_cleanup(&path); |
11200 | | /* Cleanup for attribute */ |
11201 | 0 | path_cleanup(&attribute); |
11202 | |
|
11203 | 0 | return return_value; |
11204 | 0 | } |
11205 | | |
11206 | | #endif /* defined(USE_XATTRS) */ |
11207 | | |
11208 | | #if defined(USE_XATTRS) |
11209 | | |
11210 | | PyDoc_STRVAR(os_setxattr__doc__, |
11211 | | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
11212 | | " follow_symlinks=True)\n" |
11213 | | "--\n" |
11214 | | "\n" |
11215 | | "Set extended attribute attribute on path to value.\n" |
11216 | | "\n" |
11217 | | "path may be either a string, a path-like object, or an open file\n" |
11218 | | "descriptor.\n" |
11219 | | "If follow_symlinks is False, and the last element of the path is\n" |
11220 | | "a symbolic link, setxattr will modify the symbolic link itself instead\n" |
11221 | | "of the file the link points to."); |
11222 | | |
11223 | | #define OS_SETXATTR_METHODDEF \ |
11224 | | {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__}, |
11225 | | |
11226 | | static PyObject * |
11227 | | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11228 | | Py_buffer *value, int flags, int follow_symlinks); |
11229 | | |
11230 | | static PyObject * |
11231 | | os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11232 | 0 | { |
11233 | 0 | PyObject *return_value = NULL; |
11234 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11235 | |
|
11236 | 0 | #define NUM_KEYWORDS 5 |
11237 | 0 | static struct { |
11238 | 0 | PyGC_Head _this_is_not_used; |
11239 | 0 | PyObject_VAR_HEAD |
11240 | 0 | Py_hash_t ob_hash; |
11241 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11242 | 0 | } _kwtuple = { |
11243 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11244 | 0 | .ob_hash = -1, |
11245 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), }, |
11246 | 0 | }; |
11247 | 0 | #undef NUM_KEYWORDS |
11248 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11249 | |
|
11250 | | #else // !Py_BUILD_CORE |
11251 | | # define KWTUPLE NULL |
11252 | | #endif // !Py_BUILD_CORE |
11253 | |
|
11254 | 0 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
11255 | 0 | static _PyArg_Parser _parser = { |
11256 | 0 | .keywords = _keywords, |
11257 | 0 | .fname = "setxattr", |
11258 | 0 | .kwtuple = KWTUPLE, |
11259 | 0 | }; |
11260 | 0 | #undef KWTUPLE |
11261 | 0 | PyObject *argsbuf[5]; |
11262 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
11263 | 0 | path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1); |
11264 | 0 | path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0); |
11265 | 0 | Py_buffer value = {NULL, NULL}; |
11266 | 0 | int flags = 0; |
11267 | 0 | int follow_symlinks = 1; |
11268 | |
|
11269 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11270 | 0 | /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11271 | 0 | if (!args) { |
11272 | 0 | goto exit; |
11273 | 0 | } |
11274 | 0 | if (!path_converter(args[0], &path)) { |
11275 | 0 | goto exit; |
11276 | 0 | } |
11277 | 0 | if (!path_converter(args[1], &attribute)) { |
11278 | 0 | goto exit; |
11279 | 0 | } |
11280 | 0 | if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) { |
11281 | 0 | goto exit; |
11282 | 0 | } |
11283 | 0 | if (!noptargs) { |
11284 | 0 | goto skip_optional_pos; |
11285 | 0 | } |
11286 | 0 | if (args[3]) { |
11287 | 0 | flags = PyLong_AsInt(args[3]); |
11288 | 0 | if (flags == -1 && PyErr_Occurred()) { |
11289 | 0 | goto exit; |
11290 | 0 | } |
11291 | 0 | if (!--noptargs) { |
11292 | 0 | goto skip_optional_pos; |
11293 | 0 | } |
11294 | 0 | } |
11295 | 0 | skip_optional_pos: |
11296 | 0 | if (!noptargs) { |
11297 | 0 | goto skip_optional_kwonly; |
11298 | 0 | } |
11299 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
11300 | 0 | if (follow_symlinks < 0) { |
11301 | 0 | goto exit; |
11302 | 0 | } |
11303 | 0 | skip_optional_kwonly: |
11304 | 0 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
11305 | |
|
11306 | 0 | exit: |
11307 | | /* Cleanup for path */ |
11308 | 0 | path_cleanup(&path); |
11309 | | /* Cleanup for attribute */ |
11310 | 0 | path_cleanup(&attribute); |
11311 | | /* Cleanup for value */ |
11312 | 0 | if (value.obj) { |
11313 | 0 | PyBuffer_Release(&value); |
11314 | 0 | } |
11315 | |
|
11316 | 0 | return return_value; |
11317 | 0 | } |
11318 | | |
11319 | | #endif /* defined(USE_XATTRS) */ |
11320 | | |
11321 | | #if defined(USE_XATTRS) |
11322 | | |
11323 | | PyDoc_STRVAR(os_removexattr__doc__, |
11324 | | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
11325 | | "--\n" |
11326 | | "\n" |
11327 | | "Remove extended attribute attribute on path.\n" |
11328 | | "\n" |
11329 | | "path may be either a string, a path-like object, or an open file\n" |
11330 | | "descriptor.\n" |
11331 | | "If follow_symlinks is False, and the last element of the path is\n" |
11332 | | "a symbolic link, removexattr will modify the symbolic link itself\n" |
11333 | | "instead of the file the link points to."); |
11334 | | |
11335 | | #define OS_REMOVEXATTR_METHODDEF \ |
11336 | | {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__}, |
11337 | | |
11338 | | static PyObject * |
11339 | | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11340 | | int follow_symlinks); |
11341 | | |
11342 | | static PyObject * |
11343 | | os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11344 | 0 | { |
11345 | 0 | PyObject *return_value = NULL; |
11346 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11347 | |
|
11348 | 0 | #define NUM_KEYWORDS 3 |
11349 | 0 | static struct { |
11350 | 0 | PyGC_Head _this_is_not_used; |
11351 | 0 | PyObject_VAR_HEAD |
11352 | 0 | Py_hash_t ob_hash; |
11353 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11354 | 0 | } _kwtuple = { |
11355 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11356 | 0 | .ob_hash = -1, |
11357 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
11358 | 0 | }; |
11359 | 0 | #undef NUM_KEYWORDS |
11360 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11361 | |
|
11362 | | #else // !Py_BUILD_CORE |
11363 | | # define KWTUPLE NULL |
11364 | | #endif // !Py_BUILD_CORE |
11365 | |
|
11366 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
11367 | 0 | static _PyArg_Parser _parser = { |
11368 | 0 | .keywords = _keywords, |
11369 | 0 | .fname = "removexattr", |
11370 | 0 | .kwtuple = KWTUPLE, |
11371 | 0 | }; |
11372 | 0 | #undef KWTUPLE |
11373 | 0 | PyObject *argsbuf[3]; |
11374 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
11375 | 0 | path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1); |
11376 | 0 | path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0); |
11377 | 0 | int follow_symlinks = 1; |
11378 | |
|
11379 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11380 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11381 | 0 | if (!args) { |
11382 | 0 | goto exit; |
11383 | 0 | } |
11384 | 0 | if (!path_converter(args[0], &path)) { |
11385 | 0 | goto exit; |
11386 | 0 | } |
11387 | 0 | if (!path_converter(args[1], &attribute)) { |
11388 | 0 | goto exit; |
11389 | 0 | } |
11390 | 0 | if (!noptargs) { |
11391 | 0 | goto skip_optional_kwonly; |
11392 | 0 | } |
11393 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
11394 | 0 | if (follow_symlinks < 0) { |
11395 | 0 | goto exit; |
11396 | 0 | } |
11397 | 0 | skip_optional_kwonly: |
11398 | 0 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
11399 | |
|
11400 | 0 | exit: |
11401 | | /* Cleanup for path */ |
11402 | 0 | path_cleanup(&path); |
11403 | | /* Cleanup for attribute */ |
11404 | 0 | path_cleanup(&attribute); |
11405 | |
|
11406 | 0 | return return_value; |
11407 | 0 | } |
11408 | | |
11409 | | #endif /* defined(USE_XATTRS) */ |
11410 | | |
11411 | | #if defined(USE_XATTRS) |
11412 | | |
11413 | | PyDoc_STRVAR(os_listxattr__doc__, |
11414 | | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
11415 | | "--\n" |
11416 | | "\n" |
11417 | | "Return a list of extended attributes on path.\n" |
11418 | | "\n" |
11419 | | "path may be either None, a string, a path-like object, or an open file\n" |
11420 | | "descriptor. If path is None, listxattr will examine the current\n" |
11421 | | "directory.\n" |
11422 | | "If follow_symlinks is False, and the last element of the path is\n" |
11423 | | "a symbolic link, listxattr will examine the symbolic link itself instead\n" |
11424 | | "of the file the link points to."); |
11425 | | |
11426 | | #define OS_LISTXATTR_METHODDEF \ |
11427 | | {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__}, |
11428 | | |
11429 | | static PyObject * |
11430 | | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
11431 | | |
11432 | | static PyObject * |
11433 | | os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11434 | 0 | { |
11435 | 0 | PyObject *return_value = NULL; |
11436 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11437 | |
|
11438 | 0 | #define NUM_KEYWORDS 2 |
11439 | 0 | static struct { |
11440 | 0 | PyGC_Head _this_is_not_used; |
11441 | 0 | PyObject_VAR_HEAD |
11442 | 0 | Py_hash_t ob_hash; |
11443 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11444 | 0 | } _kwtuple = { |
11445 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11446 | 0 | .ob_hash = -1, |
11447 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), }, |
11448 | 0 | }; |
11449 | 0 | #undef NUM_KEYWORDS |
11450 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11451 | |
|
11452 | | #else // !Py_BUILD_CORE |
11453 | | # define KWTUPLE NULL |
11454 | | #endif // !Py_BUILD_CORE |
11455 | |
|
11456 | 0 | static const char * const _keywords[] = {"path", "follow_symlinks", NULL}; |
11457 | 0 | static _PyArg_Parser _parser = { |
11458 | 0 | .keywords = _keywords, |
11459 | 0 | .fname = "listxattr", |
11460 | 0 | .kwtuple = KWTUPLE, |
11461 | 0 | }; |
11462 | 0 | #undef KWTUPLE |
11463 | 0 | PyObject *argsbuf[2]; |
11464 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
11465 | 0 | path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1); |
11466 | 0 | int follow_symlinks = 1; |
11467 | |
|
11468 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11469 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11470 | 0 | if (!args) { |
11471 | 0 | goto exit; |
11472 | 0 | } |
11473 | 0 | if (!noptargs) { |
11474 | 0 | goto skip_optional_pos; |
11475 | 0 | } |
11476 | 0 | if (args[0]) { |
11477 | 0 | if (!path_converter(args[0], &path)) { |
11478 | 0 | goto exit; |
11479 | 0 | } |
11480 | 0 | if (!--noptargs) { |
11481 | 0 | goto skip_optional_pos; |
11482 | 0 | } |
11483 | 0 | } |
11484 | 0 | skip_optional_pos: |
11485 | 0 | if (!noptargs) { |
11486 | 0 | goto skip_optional_kwonly; |
11487 | 0 | } |
11488 | 0 | follow_symlinks = PyObject_IsTrue(args[1]); |
11489 | 0 | if (follow_symlinks < 0) { |
11490 | 0 | goto exit; |
11491 | 0 | } |
11492 | 0 | skip_optional_kwonly: |
11493 | 0 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
11494 | |
|
11495 | 0 | exit: |
11496 | | /* Cleanup for path */ |
11497 | 0 | path_cleanup(&path); |
11498 | |
|
11499 | 0 | return return_value; |
11500 | 0 | } |
11501 | | |
11502 | | #endif /* defined(USE_XATTRS) */ |
11503 | | |
11504 | | PyDoc_STRVAR(os_urandom__doc__, |
11505 | | "urandom($module, size, /)\n" |
11506 | | "--\n" |
11507 | | "\n" |
11508 | | "Return a bytes object containing random bytes suitable for cryptographic use."); |
11509 | | |
11510 | | #define OS_URANDOM_METHODDEF \ |
11511 | | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
11512 | | |
11513 | | static PyObject * |
11514 | | os_urandom_impl(PyObject *module, Py_ssize_t size); |
11515 | | |
11516 | | static PyObject * |
11517 | | os_urandom(PyObject *module, PyObject *arg) |
11518 | 0 | { |
11519 | 0 | PyObject *return_value = NULL; |
11520 | 0 | Py_ssize_t size; |
11521 | |
|
11522 | 0 | { |
11523 | 0 | Py_ssize_t ival = -1; |
11524 | 0 | PyObject *iobj = _PyNumber_Index(arg); |
11525 | 0 | if (iobj != NULL) { |
11526 | 0 | ival = PyLong_AsSsize_t(iobj); |
11527 | 0 | Py_DECREF(iobj); |
11528 | 0 | } |
11529 | 0 | if (ival == -1 && PyErr_Occurred()) { |
11530 | 0 | goto exit; |
11531 | 0 | } |
11532 | 0 | size = ival; |
11533 | 0 | if (size < 0) { |
11534 | 0 | PyErr_SetString(PyExc_ValueError, |
11535 | 0 | "size cannot be negative"); |
11536 | 0 | goto exit; |
11537 | 0 | } |
11538 | 0 | } |
11539 | 0 | return_value = os_urandom_impl(module, size); |
11540 | |
|
11541 | 0 | exit: |
11542 | 0 | return return_value; |
11543 | 0 | } |
11544 | | |
11545 | | #if defined(_Py_HAVE_MEMFD_CREATE) |
11546 | | |
11547 | | PyDoc_STRVAR(os_memfd_create__doc__, |
11548 | | "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n" |
11549 | | "--\n" |
11550 | | "\n"); |
11551 | | |
11552 | | #define OS_MEMFD_CREATE_METHODDEF \ |
11553 | | {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__}, |
11554 | | |
11555 | | static PyObject * |
11556 | | os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags); |
11557 | | |
11558 | | static PyObject * |
11559 | | os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11560 | 0 | { |
11561 | 0 | PyObject *return_value = NULL; |
11562 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11563 | |
|
11564 | 0 | #define NUM_KEYWORDS 2 |
11565 | 0 | static struct { |
11566 | 0 | PyGC_Head _this_is_not_used; |
11567 | 0 | PyObject_VAR_HEAD |
11568 | 0 | Py_hash_t ob_hash; |
11569 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11570 | 0 | } _kwtuple = { |
11571 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11572 | 0 | .ob_hash = -1, |
11573 | 0 | .ob_item = { &_Py_ID(name), &_Py_ID(flags), }, |
11574 | 0 | }; |
11575 | 0 | #undef NUM_KEYWORDS |
11576 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11577 | |
|
11578 | | #else // !Py_BUILD_CORE |
11579 | | # define KWTUPLE NULL |
11580 | | #endif // !Py_BUILD_CORE |
11581 | |
|
11582 | 0 | static const char * const _keywords[] = {"name", "flags", NULL}; |
11583 | 0 | static _PyArg_Parser _parser = { |
11584 | 0 | .keywords = _keywords, |
11585 | 0 | .fname = "memfd_create", |
11586 | 0 | .kwtuple = KWTUPLE, |
11587 | 0 | }; |
11588 | 0 | #undef KWTUPLE |
11589 | 0 | PyObject *argsbuf[2]; |
11590 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11591 | 0 | PyObject *name = NULL; |
11592 | 0 | unsigned int flags = MFD_CLOEXEC; |
11593 | |
|
11594 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11595 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11596 | 0 | if (!args) { |
11597 | 0 | goto exit; |
11598 | 0 | } |
11599 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
11600 | 0 | goto exit; |
11601 | 0 | } |
11602 | 0 | if (!noptargs) { |
11603 | 0 | goto skip_optional_pos; |
11604 | 0 | } |
11605 | 0 | { |
11606 | 0 | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned int), |
11607 | 0 | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
11608 | 0 | Py_ASNATIVEBYTES_ALLOW_INDEX | |
11609 | 0 | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
11610 | 0 | if (_bytes < 0) { |
11611 | 0 | goto exit; |
11612 | 0 | } |
11613 | 0 | if ((size_t)_bytes > sizeof(unsigned int)) { |
11614 | 0 | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
11615 | 0 | "integer value out of range", 1) < 0) |
11616 | 0 | { |
11617 | 0 | goto exit; |
11618 | 0 | } |
11619 | 0 | } |
11620 | 0 | } |
11621 | 0 | skip_optional_pos: |
11622 | 0 | return_value = os_memfd_create_impl(module, name, flags); |
11623 | |
|
11624 | 0 | exit: |
11625 | | /* Cleanup for name */ |
11626 | 0 | Py_XDECREF(name); |
11627 | |
|
11628 | 0 | return return_value; |
11629 | 0 | } |
11630 | | |
11631 | | #endif /* defined(_Py_HAVE_MEMFD_CREATE) */ |
11632 | | |
11633 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11634 | | |
11635 | | PyDoc_STRVAR(os_eventfd__doc__, |
11636 | | "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n" |
11637 | | "--\n" |
11638 | | "\n" |
11639 | | "Creates and returns an event notification file descriptor."); |
11640 | | |
11641 | | #define OS_EVENTFD_METHODDEF \ |
11642 | | {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__}, |
11643 | | |
11644 | | static PyObject * |
11645 | | os_eventfd_impl(PyObject *module, unsigned int initval, int flags); |
11646 | | |
11647 | | static PyObject * |
11648 | | os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11649 | 0 | { |
11650 | 0 | PyObject *return_value = NULL; |
11651 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11652 | |
|
11653 | 0 | #define NUM_KEYWORDS 2 |
11654 | 0 | static struct { |
11655 | 0 | PyGC_Head _this_is_not_used; |
11656 | 0 | PyObject_VAR_HEAD |
11657 | 0 | Py_hash_t ob_hash; |
11658 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11659 | 0 | } _kwtuple = { |
11660 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11661 | 0 | .ob_hash = -1, |
11662 | 0 | .ob_item = { &_Py_ID(initval), &_Py_ID(flags), }, |
11663 | 0 | }; |
11664 | 0 | #undef NUM_KEYWORDS |
11665 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11666 | |
|
11667 | | #else // !Py_BUILD_CORE |
11668 | | # define KWTUPLE NULL |
11669 | | #endif // !Py_BUILD_CORE |
11670 | |
|
11671 | 0 | static const char * const _keywords[] = {"initval", "flags", NULL}; |
11672 | 0 | static _PyArg_Parser _parser = { |
11673 | 0 | .keywords = _keywords, |
11674 | 0 | .fname = "eventfd", |
11675 | 0 | .kwtuple = KWTUPLE, |
11676 | 0 | }; |
11677 | 0 | #undef KWTUPLE |
11678 | 0 | PyObject *argsbuf[2]; |
11679 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11680 | 0 | unsigned int initval; |
11681 | 0 | int flags = EFD_CLOEXEC; |
11682 | |
|
11683 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11684 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11685 | 0 | if (!args) { |
11686 | 0 | goto exit; |
11687 | 0 | } |
11688 | 0 | if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) { |
11689 | 0 | goto exit; |
11690 | 0 | } |
11691 | 0 | if (!noptargs) { |
11692 | 0 | goto skip_optional_pos; |
11693 | 0 | } |
11694 | 0 | flags = PyLong_AsInt(args[1]); |
11695 | 0 | if (flags == -1 && PyErr_Occurred()) { |
11696 | 0 | goto exit; |
11697 | 0 | } |
11698 | 0 | skip_optional_pos: |
11699 | 0 | return_value = os_eventfd_impl(module, initval, flags); |
11700 | |
|
11701 | 0 | exit: |
11702 | 0 | return return_value; |
11703 | 0 | } |
11704 | | |
11705 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11706 | | |
11707 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11708 | | |
11709 | | PyDoc_STRVAR(os_eventfd_read__doc__, |
11710 | | "eventfd_read($module, /, fd)\n" |
11711 | | "--\n" |
11712 | | "\n" |
11713 | | "Read eventfd value"); |
11714 | | |
11715 | | #define OS_EVENTFD_READ_METHODDEF \ |
11716 | | {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__}, |
11717 | | |
11718 | | static PyObject * |
11719 | | os_eventfd_read_impl(PyObject *module, int fd); |
11720 | | |
11721 | | static PyObject * |
11722 | | os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11723 | 0 | { |
11724 | 0 | PyObject *return_value = NULL; |
11725 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11726 | |
|
11727 | 0 | #define NUM_KEYWORDS 1 |
11728 | 0 | static struct { |
11729 | 0 | PyGC_Head _this_is_not_used; |
11730 | 0 | PyObject_VAR_HEAD |
11731 | 0 | Py_hash_t ob_hash; |
11732 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11733 | 0 | } _kwtuple = { |
11734 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11735 | 0 | .ob_hash = -1, |
11736 | 0 | .ob_item = { &_Py_ID(fd), }, |
11737 | 0 | }; |
11738 | 0 | #undef NUM_KEYWORDS |
11739 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11740 | |
|
11741 | | #else // !Py_BUILD_CORE |
11742 | | # define KWTUPLE NULL |
11743 | | #endif // !Py_BUILD_CORE |
11744 | |
|
11745 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
11746 | 0 | static _PyArg_Parser _parser = { |
11747 | 0 | .keywords = _keywords, |
11748 | 0 | .fname = "eventfd_read", |
11749 | 0 | .kwtuple = KWTUPLE, |
11750 | 0 | }; |
11751 | 0 | #undef KWTUPLE |
11752 | 0 | PyObject *argsbuf[1]; |
11753 | 0 | int fd; |
11754 | |
|
11755 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11756 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11757 | 0 | if (!args) { |
11758 | 0 | goto exit; |
11759 | 0 | } |
11760 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11761 | 0 | if (fd < 0) { |
11762 | 0 | goto exit; |
11763 | 0 | } |
11764 | 0 | return_value = os_eventfd_read_impl(module, fd); |
11765 | |
|
11766 | 0 | exit: |
11767 | 0 | return return_value; |
11768 | 0 | } |
11769 | | |
11770 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11771 | | |
11772 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11773 | | |
11774 | | PyDoc_STRVAR(os_eventfd_write__doc__, |
11775 | | "eventfd_write($module, /, fd, value)\n" |
11776 | | "--\n" |
11777 | | "\n" |
11778 | | "Write eventfd value."); |
11779 | | |
11780 | | #define OS_EVENTFD_WRITE_METHODDEF \ |
11781 | | {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__}, |
11782 | | |
11783 | | static PyObject * |
11784 | | os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value); |
11785 | | |
11786 | | static PyObject * |
11787 | | os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11788 | 0 | { |
11789 | 0 | PyObject *return_value = NULL; |
11790 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11791 | |
|
11792 | 0 | #define NUM_KEYWORDS 2 |
11793 | 0 | static struct { |
11794 | 0 | PyGC_Head _this_is_not_used; |
11795 | 0 | PyObject_VAR_HEAD |
11796 | 0 | Py_hash_t ob_hash; |
11797 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11798 | 0 | } _kwtuple = { |
11799 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11800 | 0 | .ob_hash = -1, |
11801 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(value), }, |
11802 | 0 | }; |
11803 | 0 | #undef NUM_KEYWORDS |
11804 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11805 | |
|
11806 | | #else // !Py_BUILD_CORE |
11807 | | # define KWTUPLE NULL |
11808 | | #endif // !Py_BUILD_CORE |
11809 | |
|
11810 | 0 | static const char * const _keywords[] = {"fd", "value", NULL}; |
11811 | 0 | static _PyArg_Parser _parser = { |
11812 | 0 | .keywords = _keywords, |
11813 | 0 | .fname = "eventfd_write", |
11814 | 0 | .kwtuple = KWTUPLE, |
11815 | 0 | }; |
11816 | 0 | #undef KWTUPLE |
11817 | 0 | PyObject *argsbuf[2]; |
11818 | 0 | int fd; |
11819 | 0 | unsigned long long value; |
11820 | |
|
11821 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11822 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11823 | 0 | if (!args) { |
11824 | 0 | goto exit; |
11825 | 0 | } |
11826 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11827 | 0 | if (fd < 0) { |
11828 | 0 | goto exit; |
11829 | 0 | } |
11830 | 0 | if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) { |
11831 | 0 | goto exit; |
11832 | 0 | } |
11833 | 0 | return_value = os_eventfd_write_impl(module, fd, value); |
11834 | |
|
11835 | 0 | exit: |
11836 | 0 | return return_value; |
11837 | 0 | } |
11838 | | |
11839 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11840 | | |
11841 | | #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) |
11842 | | |
11843 | | PyDoc_STRVAR(os_get_terminal_size__doc__, |
11844 | | "get_terminal_size($module, fd=<unrepresentable>, /)\n" |
11845 | | "--\n" |
11846 | | "\n" |
11847 | | "Return the size of the terminal window as (columns, lines).\n" |
11848 | | "\n" |
11849 | | "The optional argument fd (default standard output) specifies\n" |
11850 | | "which file descriptor should be queried.\n" |
11851 | | "\n" |
11852 | | "If the file descriptor is not connected to a terminal, an OSError\n" |
11853 | | "is thrown.\n" |
11854 | | "\n" |
11855 | | "This function will only be defined if an implementation is\n" |
11856 | | "available for this system.\n" |
11857 | | "\n" |
11858 | | "shutil.get_terminal_size is the high-level function which should\n" |
11859 | | "normally be used, os.get_terminal_size is the low-level implementation."); |
11860 | | |
11861 | | #define OS_GET_TERMINAL_SIZE_METHODDEF \ |
11862 | | {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__}, |
11863 | | |
11864 | | static PyObject * |
11865 | | os_get_terminal_size_impl(PyObject *module, int fd); |
11866 | | |
11867 | | static PyObject * |
11868 | | os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11869 | 0 | { |
11870 | 0 | PyObject *return_value = NULL; |
11871 | 0 | int fd = fileno(stdout); |
11872 | |
|
11873 | 0 | if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) { |
11874 | 0 | goto exit; |
11875 | 0 | } |
11876 | 0 | if (nargs < 1) { |
11877 | 0 | goto skip_optional; |
11878 | 0 | } |
11879 | 0 | fd = PyLong_AsInt(args[0]); |
11880 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11881 | 0 | goto exit; |
11882 | 0 | } |
11883 | 0 | skip_optional: |
11884 | 0 | return_value = os_get_terminal_size_impl(module, fd); |
11885 | |
|
11886 | 0 | exit: |
11887 | 0 | return return_value; |
11888 | 0 | } |
11889 | | |
11890 | | #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */ |
11891 | | |
11892 | | PyDoc_STRVAR(os_cpu_count__doc__, |
11893 | | "cpu_count($module, /)\n" |
11894 | | "--\n" |
11895 | | "\n" |
11896 | | "Return the number of logical CPUs in the system.\n" |
11897 | | "\n" |
11898 | | "Return None if indeterminable."); |
11899 | | |
11900 | | #define OS_CPU_COUNT_METHODDEF \ |
11901 | | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
11902 | | |
11903 | | static PyObject * |
11904 | | os_cpu_count_impl(PyObject *module); |
11905 | | |
11906 | | static PyObject * |
11907 | | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
11908 | 0 | { |
11909 | 0 | return os_cpu_count_impl(module); |
11910 | 0 | } |
11911 | | |
11912 | | PyDoc_STRVAR(os_get_inheritable__doc__, |
11913 | | "get_inheritable($module, fd, /)\n" |
11914 | | "--\n" |
11915 | | "\n" |
11916 | | "Get the close-on-exe flag of the specified file descriptor."); |
11917 | | |
11918 | | #define OS_GET_INHERITABLE_METHODDEF \ |
11919 | | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
11920 | | |
11921 | | static int |
11922 | | os_get_inheritable_impl(PyObject *module, int fd); |
11923 | | |
11924 | | static PyObject * |
11925 | | os_get_inheritable(PyObject *module, PyObject *arg) |
11926 | 0 | { |
11927 | 0 | PyObject *return_value = NULL; |
11928 | 0 | int fd; |
11929 | 0 | int _return_value; |
11930 | |
|
11931 | 0 | fd = PyLong_AsInt(arg); |
11932 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11933 | 0 | goto exit; |
11934 | 0 | } |
11935 | 0 | _return_value = os_get_inheritable_impl(module, fd); |
11936 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11937 | 0 | goto exit; |
11938 | 0 | } |
11939 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11940 | |
|
11941 | 0 | exit: |
11942 | 0 | return return_value; |
11943 | 0 | } |
11944 | | |
11945 | | PyDoc_STRVAR(os_set_inheritable__doc__, |
11946 | | "set_inheritable($module, fd, inheritable, /)\n" |
11947 | | "--\n" |
11948 | | "\n" |
11949 | | "Set the inheritable flag of the specified file descriptor."); |
11950 | | |
11951 | | #define OS_SET_INHERITABLE_METHODDEF \ |
11952 | | {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__}, |
11953 | | |
11954 | | static PyObject * |
11955 | | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
11956 | | |
11957 | | static PyObject * |
11958 | | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11959 | 0 | { |
11960 | 0 | PyObject *return_value = NULL; |
11961 | 0 | int fd; |
11962 | 0 | int inheritable; |
11963 | |
|
11964 | 0 | if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { |
11965 | 0 | goto exit; |
11966 | 0 | } |
11967 | 0 | fd = PyLong_AsInt(args[0]); |
11968 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11969 | 0 | goto exit; |
11970 | 0 | } |
11971 | 0 | inheritable = PyLong_AsInt(args[1]); |
11972 | 0 | if (inheritable == -1 && PyErr_Occurred()) { |
11973 | 0 | goto exit; |
11974 | 0 | } |
11975 | 0 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
11976 | |
|
11977 | 0 | exit: |
11978 | 0 | return return_value; |
11979 | 0 | } |
11980 | | |
11981 | | #if defined(MS_WINDOWS) |
11982 | | |
11983 | | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
11984 | | "get_handle_inheritable($module, handle, /)\n" |
11985 | | "--\n" |
11986 | | "\n" |
11987 | | "Get the close-on-exe flag of the specified file descriptor."); |
11988 | | |
11989 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
11990 | | {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__}, |
11991 | | |
11992 | | static int |
11993 | | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
11994 | | |
11995 | | static PyObject * |
11996 | | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
11997 | | { |
11998 | | PyObject *return_value = NULL; |
11999 | | intptr_t handle; |
12000 | | int _return_value; |
12001 | | |
12002 | | handle = (intptr_t)PyLong_AsVoidPtr(arg); |
12003 | | if (!handle && PyErr_Occurred()) { |
12004 | | goto exit; |
12005 | | } |
12006 | | _return_value = os_get_handle_inheritable_impl(module, handle); |
12007 | | if ((_return_value == -1) && PyErr_Occurred()) { |
12008 | | goto exit; |
12009 | | } |
12010 | | return_value = PyBool_FromLong((long)_return_value); |
12011 | | |
12012 | | exit: |
12013 | | return return_value; |
12014 | | } |
12015 | | |
12016 | | #endif /* defined(MS_WINDOWS) */ |
12017 | | |
12018 | | #if defined(MS_WINDOWS) |
12019 | | |
12020 | | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
12021 | | "set_handle_inheritable($module, handle, inheritable, /)\n" |
12022 | | "--\n" |
12023 | | "\n" |
12024 | | "Set the inheritable flag of the specified handle."); |
12025 | | |
12026 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
12027 | | {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__}, |
12028 | | |
12029 | | static PyObject * |
12030 | | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
12031 | | int inheritable); |
12032 | | |
12033 | | static PyObject * |
12034 | | os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
12035 | | { |
12036 | | PyObject *return_value = NULL; |
12037 | | intptr_t handle; |
12038 | | int inheritable; |
12039 | | |
12040 | | if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) { |
12041 | | goto exit; |
12042 | | } |
12043 | | handle = (intptr_t)PyLong_AsVoidPtr(args[0]); |
12044 | | if (!handle && PyErr_Occurred()) { |
12045 | | goto exit; |
12046 | | } |
12047 | | inheritable = PyObject_IsTrue(args[1]); |
12048 | | if (inheritable < 0) { |
12049 | | goto exit; |
12050 | | } |
12051 | | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
12052 | | |
12053 | | exit: |
12054 | | return return_value; |
12055 | | } |
12056 | | |
12057 | | #endif /* defined(MS_WINDOWS) */ |
12058 | | |
12059 | | PyDoc_STRVAR(os_get_blocking__doc__, |
12060 | | "get_blocking($module, fd, /)\n" |
12061 | | "--\n" |
12062 | | "\n" |
12063 | | "Get the blocking mode of the file descriptor.\n" |
12064 | | "\n" |
12065 | | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared."); |
12066 | | |
12067 | | #define OS_GET_BLOCKING_METHODDEF \ |
12068 | | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
12069 | | |
12070 | | static int |
12071 | | os_get_blocking_impl(PyObject *module, int fd); |
12072 | | |
12073 | | static PyObject * |
12074 | | os_get_blocking(PyObject *module, PyObject *arg) |
12075 | 0 | { |
12076 | 0 | PyObject *return_value = NULL; |
12077 | 0 | int fd; |
12078 | 0 | int _return_value; |
12079 | |
|
12080 | 0 | fd = PyLong_AsInt(arg); |
12081 | 0 | if (fd == -1 && PyErr_Occurred()) { |
12082 | 0 | goto exit; |
12083 | 0 | } |
12084 | 0 | _return_value = os_get_blocking_impl(module, fd); |
12085 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12086 | 0 | goto exit; |
12087 | 0 | } |
12088 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12089 | |
|
12090 | 0 | exit: |
12091 | 0 | return return_value; |
12092 | 0 | } |
12093 | | |
12094 | | PyDoc_STRVAR(os_set_blocking__doc__, |
12095 | | "set_blocking($module, fd, blocking, /)\n" |
12096 | | "--\n" |
12097 | | "\n" |
12098 | | "Set the blocking mode of the specified file descriptor.\n" |
12099 | | "\n" |
12100 | | "Set the O_NONBLOCK flag if blocking is False,\n" |
12101 | | "clear the O_NONBLOCK flag otherwise."); |
12102 | | |
12103 | | #define OS_SET_BLOCKING_METHODDEF \ |
12104 | | {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__}, |
12105 | | |
12106 | | static PyObject * |
12107 | | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
12108 | | |
12109 | | static PyObject * |
12110 | | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
12111 | 0 | { |
12112 | 0 | PyObject *return_value = NULL; |
12113 | 0 | int fd; |
12114 | 0 | int blocking; |
12115 | |
|
12116 | 0 | if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { |
12117 | 0 | goto exit; |
12118 | 0 | } |
12119 | 0 | fd = PyLong_AsInt(args[0]); |
12120 | 0 | if (fd == -1 && PyErr_Occurred()) { |
12121 | 0 | goto exit; |
12122 | 0 | } |
12123 | 0 | blocking = PyObject_IsTrue(args[1]); |
12124 | 0 | if (blocking < 0) { |
12125 | 0 | goto exit; |
12126 | 0 | } |
12127 | 0 | return_value = os_set_blocking_impl(module, fd, blocking); |
12128 | |
|
12129 | 0 | exit: |
12130 | 0 | return return_value; |
12131 | 0 | } |
12132 | | |
12133 | | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
12134 | | "is_symlink($self, /)\n" |
12135 | | "--\n" |
12136 | | "\n" |
12137 | | "Return True if the entry is a symbolic link; cached per entry."); |
12138 | | |
12139 | | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
12140 | | {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__}, |
12141 | | |
12142 | | static int |
12143 | | os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class); |
12144 | | |
12145 | | static PyObject * |
12146 | | os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12147 | 0 | { |
12148 | 0 | PyObject *return_value = NULL; |
12149 | 0 | int _return_value; |
12150 | |
|
12151 | 0 | if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
12152 | 0 | PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments"); |
12153 | 0 | goto exit; |
12154 | 0 | } |
12155 | 0 | _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class); |
12156 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12157 | 0 | goto exit; |
12158 | 0 | } |
12159 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12160 | |
|
12161 | 0 | exit: |
12162 | 0 | return return_value; |
12163 | 0 | } |
12164 | | |
12165 | | PyDoc_STRVAR(os_DirEntry_is_junction__doc__, |
12166 | | "is_junction($self, /)\n" |
12167 | | "--\n" |
12168 | | "\n" |
12169 | | "Return True if the entry is a junction; cached per entry."); |
12170 | | |
12171 | | #define OS_DIRENTRY_IS_JUNCTION_METHODDEF \ |
12172 | | {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__}, |
12173 | | |
12174 | | static int |
12175 | | os_DirEntry_is_junction_impl(DirEntry *self); |
12176 | | |
12177 | | static PyObject * |
12178 | | os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12179 | 0 | { |
12180 | 0 | PyObject *return_value = NULL; |
12181 | 0 | int _return_value; |
12182 | |
|
12183 | 0 | _return_value = os_DirEntry_is_junction_impl((DirEntry *)self); |
12184 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12185 | 0 | goto exit; |
12186 | 0 | } |
12187 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12188 | |
|
12189 | 0 | exit: |
12190 | 0 | return return_value; |
12191 | 0 | } |
12192 | | |
12193 | | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
12194 | | "stat($self, /, *, follow_symlinks=True)\n" |
12195 | | "--\n" |
12196 | | "\n" |
12197 | | "Return stat_result object for the entry; cached per entry."); |
12198 | | |
12199 | | #define OS_DIRENTRY_STAT_METHODDEF \ |
12200 | | {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__}, |
12201 | | |
12202 | | static PyObject * |
12203 | | os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class, |
12204 | | int follow_symlinks); |
12205 | | |
12206 | | static PyObject * |
12207 | | os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12208 | 86.9k | { |
12209 | 86.9k | PyObject *return_value = NULL; |
12210 | 86.9k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12211 | | |
12212 | 86.9k | #define NUM_KEYWORDS 1 |
12213 | 86.9k | static struct { |
12214 | 86.9k | PyGC_Head _this_is_not_used; |
12215 | 86.9k | PyObject_VAR_HEAD |
12216 | 86.9k | Py_hash_t ob_hash; |
12217 | 86.9k | PyObject *ob_item[NUM_KEYWORDS]; |
12218 | 86.9k | } _kwtuple = { |
12219 | 86.9k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12220 | 86.9k | .ob_hash = -1, |
12221 | 86.9k | .ob_item = { &_Py_ID(follow_symlinks), }, |
12222 | 86.9k | }; |
12223 | 86.9k | #undef NUM_KEYWORDS |
12224 | 86.9k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12225 | | |
12226 | | #else // !Py_BUILD_CORE |
12227 | | # define KWTUPLE NULL |
12228 | | #endif // !Py_BUILD_CORE |
12229 | | |
12230 | 86.9k | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12231 | 86.9k | static _PyArg_Parser _parser = { |
12232 | 86.9k | .keywords = _keywords, |
12233 | 86.9k | .fname = "stat", |
12234 | 86.9k | .kwtuple = KWTUPLE, |
12235 | 86.9k | }; |
12236 | 86.9k | #undef KWTUPLE |
12237 | 86.9k | PyObject *argsbuf[1]; |
12238 | 86.9k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12239 | 86.9k | int follow_symlinks = 1; |
12240 | | |
12241 | 86.9k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12242 | 86.9k | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12243 | 86.9k | if (!args) { |
12244 | 0 | goto exit; |
12245 | 0 | } |
12246 | 86.9k | if (!noptargs) { |
12247 | 0 | goto skip_optional_kwonly; |
12248 | 0 | } |
12249 | 86.9k | follow_symlinks = PyObject_IsTrue(args[0]); |
12250 | 86.9k | if (follow_symlinks < 0) { |
12251 | 0 | goto exit; |
12252 | 0 | } |
12253 | 86.9k | skip_optional_kwonly: |
12254 | 86.9k | return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks); |
12255 | | |
12256 | 86.9k | exit: |
12257 | 86.9k | return return_value; |
12258 | 86.9k | } |
12259 | | |
12260 | | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
12261 | | "is_dir($self, /, *, follow_symlinks=True)\n" |
12262 | | "--\n" |
12263 | | "\n" |
12264 | | "Return True if the entry is a directory; cached per entry."); |
12265 | | |
12266 | | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
12267 | | {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__}, |
12268 | | |
12269 | | static int |
12270 | | os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class, |
12271 | | int follow_symlinks); |
12272 | | |
12273 | | static PyObject * |
12274 | | os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12275 | 105k | { |
12276 | 105k | PyObject *return_value = NULL; |
12277 | 105k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12278 | | |
12279 | 105k | #define NUM_KEYWORDS 1 |
12280 | 105k | static struct { |
12281 | 105k | PyGC_Head _this_is_not_used; |
12282 | 105k | PyObject_VAR_HEAD |
12283 | 105k | Py_hash_t ob_hash; |
12284 | 105k | PyObject *ob_item[NUM_KEYWORDS]; |
12285 | 105k | } _kwtuple = { |
12286 | 105k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12287 | 105k | .ob_hash = -1, |
12288 | 105k | .ob_item = { &_Py_ID(follow_symlinks), }, |
12289 | 105k | }; |
12290 | 105k | #undef NUM_KEYWORDS |
12291 | 105k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12292 | | |
12293 | | #else // !Py_BUILD_CORE |
12294 | | # define KWTUPLE NULL |
12295 | | #endif // !Py_BUILD_CORE |
12296 | | |
12297 | 105k | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12298 | 105k | static _PyArg_Parser _parser = { |
12299 | 105k | .keywords = _keywords, |
12300 | 105k | .fname = "is_dir", |
12301 | 105k | .kwtuple = KWTUPLE, |
12302 | 105k | }; |
12303 | 105k | #undef KWTUPLE |
12304 | 105k | PyObject *argsbuf[1]; |
12305 | 105k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12306 | 105k | int follow_symlinks = 1; |
12307 | 105k | int _return_value; |
12308 | | |
12309 | 105k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12310 | 105k | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12311 | 105k | if (!args) { |
12312 | 0 | goto exit; |
12313 | 0 | } |
12314 | 105k | if (!noptargs) { |
12315 | 0 | goto skip_optional_kwonly; |
12316 | 0 | } |
12317 | 105k | follow_symlinks = PyObject_IsTrue(args[0]); |
12318 | 105k | if (follow_symlinks < 0) { |
12319 | 0 | goto exit; |
12320 | 0 | } |
12321 | 105k | skip_optional_kwonly: |
12322 | 105k | _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks); |
12323 | 105k | if ((_return_value == -1) && PyErr_Occurred()) { |
12324 | 0 | goto exit; |
12325 | 0 | } |
12326 | 105k | return_value = PyBool_FromLong((long)_return_value); |
12327 | | |
12328 | 105k | exit: |
12329 | 105k | return return_value; |
12330 | 105k | } |
12331 | | |
12332 | | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
12333 | | "is_file($self, /, *, follow_symlinks=True)\n" |
12334 | | "--\n" |
12335 | | "\n" |
12336 | | "Return True if the entry is a file; cached per entry."); |
12337 | | |
12338 | | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
12339 | | {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__}, |
12340 | | |
12341 | | static int |
12342 | | os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class, |
12343 | | int follow_symlinks); |
12344 | | |
12345 | | static PyObject * |
12346 | | os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12347 | 0 | { |
12348 | 0 | PyObject *return_value = NULL; |
12349 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12350 | |
|
12351 | 0 | #define NUM_KEYWORDS 1 |
12352 | 0 | static struct { |
12353 | 0 | PyGC_Head _this_is_not_used; |
12354 | 0 | PyObject_VAR_HEAD |
12355 | 0 | Py_hash_t ob_hash; |
12356 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12357 | 0 | } _kwtuple = { |
12358 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12359 | 0 | .ob_hash = -1, |
12360 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12361 | 0 | }; |
12362 | 0 | #undef NUM_KEYWORDS |
12363 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12364 | |
|
12365 | | #else // !Py_BUILD_CORE |
12366 | | # define KWTUPLE NULL |
12367 | | #endif // !Py_BUILD_CORE |
12368 | |
|
12369 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12370 | 0 | static _PyArg_Parser _parser = { |
12371 | 0 | .keywords = _keywords, |
12372 | 0 | .fname = "is_file", |
12373 | 0 | .kwtuple = KWTUPLE, |
12374 | 0 | }; |
12375 | 0 | #undef KWTUPLE |
12376 | 0 | PyObject *argsbuf[1]; |
12377 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12378 | 0 | int follow_symlinks = 1; |
12379 | 0 | int _return_value; |
12380 | |
|
12381 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12382 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12383 | 0 | if (!args) { |
12384 | 0 | goto exit; |
12385 | 0 | } |
12386 | 0 | if (!noptargs) { |
12387 | 0 | goto skip_optional_kwonly; |
12388 | 0 | } |
12389 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12390 | 0 | if (follow_symlinks < 0) { |
12391 | 0 | goto exit; |
12392 | 0 | } |
12393 | 0 | skip_optional_kwonly: |
12394 | 0 | _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks); |
12395 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12396 | 0 | goto exit; |
12397 | 0 | } |
12398 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12399 | |
|
12400 | 0 | exit: |
12401 | 0 | return return_value; |
12402 | 0 | } |
12403 | | |
12404 | | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
12405 | | "inode($self, /)\n" |
12406 | | "--\n" |
12407 | | "\n" |
12408 | | "Return inode of the entry; cached per entry."); |
12409 | | |
12410 | | #define OS_DIRENTRY_INODE_METHODDEF \ |
12411 | | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
12412 | | |
12413 | | static PyObject * |
12414 | | os_DirEntry_inode_impl(DirEntry *self); |
12415 | | |
12416 | | static PyObject * |
12417 | | os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12418 | 0 | { |
12419 | 0 | return os_DirEntry_inode_impl((DirEntry *)self); |
12420 | 0 | } |
12421 | | |
12422 | | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
12423 | | "__fspath__($self, /)\n" |
12424 | | "--\n" |
12425 | | "\n" |
12426 | | "Returns the path for the entry."); |
12427 | | |
12428 | | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
12429 | | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
12430 | | |
12431 | | static PyObject * |
12432 | | os_DirEntry___fspath___impl(DirEntry *self); |
12433 | | |
12434 | | static PyObject * |
12435 | | os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12436 | 0 | { |
12437 | 0 | return os_DirEntry___fspath___impl((DirEntry *)self); |
12438 | 0 | } |
12439 | | |
12440 | | PyDoc_STRVAR(os_ScandirIterator___exit____doc__, |
12441 | | "__exit__($self, /, *exc_info)\n" |
12442 | | "--\n" |
12443 | | "\n" |
12444 | | "Close the scandir iterator."); |
12445 | | |
12446 | | #define OS_SCANDIRITERATOR___EXIT___METHODDEF \ |
12447 | | {"__exit__", _PyCFunction_CAST(os_ScandirIterator___exit__), METH_FASTCALL, os_ScandirIterator___exit____doc__}, |
12448 | | |
12449 | | static PyObject * |
12450 | | os_ScandirIterator___exit___impl(PyObject *self, PyObject * const *exc_info, |
12451 | | Py_ssize_t exc_info_length); |
12452 | | |
12453 | | static PyObject * |
12454 | | os_ScandirIterator___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
12455 | 91.0k | { |
12456 | 91.0k | PyObject *return_value = NULL; |
12457 | 91.0k | PyObject * const *exc_info; |
12458 | 91.0k | Py_ssize_t exc_info_length; |
12459 | | |
12460 | 91.0k | exc_info = args; |
12461 | 91.0k | exc_info_length = nargs; |
12462 | 91.0k | return_value = os_ScandirIterator___exit___impl(self, exc_info, exc_info_length); |
12463 | | |
12464 | 91.0k | return return_value; |
12465 | 91.0k | } |
12466 | | |
12467 | | PyDoc_STRVAR(os_scandir__doc__, |
12468 | | "scandir($module, /, path=None)\n" |
12469 | | "--\n" |
12470 | | "\n" |
12471 | | "Return an iterator of DirEntry objects for given path.\n" |
12472 | | "\n" |
12473 | | "path can be specified as either str, bytes, or a path-like object. If\n" |
12474 | | "path is bytes, the names of yielded DirEntry objects will also be bytes;\n" |
12475 | | "in all other circumstances they will be str.\n" |
12476 | | "\n" |
12477 | | "If path is None, uses the path=\'.\'."); |
12478 | | |
12479 | | #define OS_SCANDIR_METHODDEF \ |
12480 | | {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__}, |
12481 | | |
12482 | | static PyObject * |
12483 | | os_scandir_impl(PyObject *module, path_t *path); |
12484 | | |
12485 | | static PyObject * |
12486 | | os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12487 | 91.0k | { |
12488 | 91.0k | PyObject *return_value = NULL; |
12489 | 91.0k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12490 | | |
12491 | 91.0k | #define NUM_KEYWORDS 1 |
12492 | 91.0k | static struct { |
12493 | 91.0k | PyGC_Head _this_is_not_used; |
12494 | 91.0k | PyObject_VAR_HEAD |
12495 | 91.0k | Py_hash_t ob_hash; |
12496 | 91.0k | PyObject *ob_item[NUM_KEYWORDS]; |
12497 | 91.0k | } _kwtuple = { |
12498 | 91.0k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12499 | 91.0k | .ob_hash = -1, |
12500 | 91.0k | .ob_item = { &_Py_ID(path), }, |
12501 | 91.0k | }; |
12502 | 91.0k | #undef NUM_KEYWORDS |
12503 | 91.0k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12504 | | |
12505 | | #else // !Py_BUILD_CORE |
12506 | | # define KWTUPLE NULL |
12507 | | #endif // !Py_BUILD_CORE |
12508 | | |
12509 | 91.0k | static const char * const _keywords[] = {"path", NULL}; |
12510 | 91.0k | static _PyArg_Parser _parser = { |
12511 | 91.0k | .keywords = _keywords, |
12512 | 91.0k | .fname = "scandir", |
12513 | 91.0k | .kwtuple = KWTUPLE, |
12514 | 91.0k | }; |
12515 | 91.0k | #undef KWTUPLE |
12516 | 91.0k | PyObject *argsbuf[1]; |
12517 | 91.0k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12518 | 91.0k | path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
12519 | | |
12520 | 91.0k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12521 | 91.0k | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12522 | 91.0k | if (!args) { |
12523 | 0 | goto exit; |
12524 | 0 | } |
12525 | 91.0k | if (!noptargs) { |
12526 | 0 | goto skip_optional_pos; |
12527 | 0 | } |
12528 | 91.0k | if (!path_converter(args[0], &path)) { |
12529 | 0 | goto exit; |
12530 | 0 | } |
12531 | 91.0k | skip_optional_pos: |
12532 | 91.0k | return_value = os_scandir_impl(module, &path); |
12533 | | |
12534 | 91.0k | exit: |
12535 | | /* Cleanup for path */ |
12536 | 91.0k | path_cleanup(&path); |
12537 | | |
12538 | 91.0k | return return_value; |
12539 | 91.0k | } |
12540 | | |
12541 | | PyDoc_STRVAR(os_fspath__doc__, |
12542 | | "fspath($module, /, path)\n" |
12543 | | "--\n" |
12544 | | "\n" |
12545 | | "Return the file system path representation of the object.\n" |
12546 | | "\n" |
12547 | | "If the object is str or bytes, then allow it to pass through as-is. If\n" |
12548 | | "the object defines __fspath__(), then return the result of that method.\n" |
12549 | | "All other types raise a TypeError."); |
12550 | | |
12551 | | #define OS_FSPATH_METHODDEF \ |
12552 | | {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__}, |
12553 | | |
12554 | | static PyObject * |
12555 | | os_fspath_impl(PyObject *module, PyObject *path); |
12556 | | |
12557 | | static PyObject * |
12558 | | os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12559 | 675k | { |
12560 | 675k | PyObject *return_value = NULL; |
12561 | 675k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12562 | | |
12563 | 675k | #define NUM_KEYWORDS 1 |
12564 | 675k | static struct { |
12565 | 675k | PyGC_Head _this_is_not_used; |
12566 | 675k | PyObject_VAR_HEAD |
12567 | 675k | Py_hash_t ob_hash; |
12568 | 675k | PyObject *ob_item[NUM_KEYWORDS]; |
12569 | 675k | } _kwtuple = { |
12570 | 675k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12571 | 675k | .ob_hash = -1, |
12572 | 675k | .ob_item = { &_Py_ID(path), }, |
12573 | 675k | }; |
12574 | 675k | #undef NUM_KEYWORDS |
12575 | 675k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12576 | | |
12577 | | #else // !Py_BUILD_CORE |
12578 | | # define KWTUPLE NULL |
12579 | | #endif // !Py_BUILD_CORE |
12580 | | |
12581 | 675k | static const char * const _keywords[] = {"path", NULL}; |
12582 | 675k | static _PyArg_Parser _parser = { |
12583 | 675k | .keywords = _keywords, |
12584 | 675k | .fname = "fspath", |
12585 | 675k | .kwtuple = KWTUPLE, |
12586 | 675k | }; |
12587 | 675k | #undef KWTUPLE |
12588 | 675k | PyObject *argsbuf[1]; |
12589 | 675k | PyObject *path; |
12590 | | |
12591 | 675k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12592 | 675k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12593 | 675k | if (!args) { |
12594 | 0 | goto exit; |
12595 | 0 | } |
12596 | 675k | path = args[0]; |
12597 | 675k | return_value = os_fspath_impl(module, path); |
12598 | | |
12599 | 675k | exit: |
12600 | 675k | return return_value; |
12601 | 675k | } |
12602 | | |
12603 | | #if (defined(HAVE_GETRANDOM) || defined(HAVE_GETRANDOM_SYSCALL)) |
12604 | | |
12605 | | PyDoc_STRVAR(os_getrandom__doc__, |
12606 | | "getrandom($module, /, size, flags=0)\n" |
12607 | | "--\n" |
12608 | | "\n" |
12609 | | "Obtain a series of random bytes."); |
12610 | | |
12611 | | #define OS_GETRANDOM_METHODDEF \ |
12612 | | {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__}, |
12613 | | |
12614 | | static PyObject * |
12615 | | os_getrandom_impl(PyObject *module, Py_ssize_t size, unsigned int flags); |
12616 | | |
12617 | | static PyObject * |
12618 | | os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12619 | 0 | { |
12620 | 0 | PyObject *return_value = NULL; |
12621 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12622 | |
|
12623 | 0 | #define NUM_KEYWORDS 2 |
12624 | 0 | static struct { |
12625 | 0 | PyGC_Head _this_is_not_used; |
12626 | 0 | PyObject_VAR_HEAD |
12627 | 0 | Py_hash_t ob_hash; |
12628 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12629 | 0 | } _kwtuple = { |
12630 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12631 | 0 | .ob_hash = -1, |
12632 | 0 | .ob_item = { &_Py_ID(size), &_Py_ID(flags), }, |
12633 | 0 | }; |
12634 | 0 | #undef NUM_KEYWORDS |
12635 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12636 | |
|
12637 | | #else // !Py_BUILD_CORE |
12638 | | # define KWTUPLE NULL |
12639 | | #endif // !Py_BUILD_CORE |
12640 | |
|
12641 | 0 | static const char * const _keywords[] = {"size", "flags", NULL}; |
12642 | 0 | static _PyArg_Parser _parser = { |
12643 | 0 | .keywords = _keywords, |
12644 | 0 | .fname = "getrandom", |
12645 | 0 | .kwtuple = KWTUPLE, |
12646 | 0 | }; |
12647 | 0 | #undef KWTUPLE |
12648 | 0 | PyObject *argsbuf[2]; |
12649 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
12650 | 0 | Py_ssize_t size; |
12651 | 0 | unsigned int flags = 0; |
12652 | |
|
12653 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12654 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12655 | 0 | if (!args) { |
12656 | 0 | goto exit; |
12657 | 0 | } |
12658 | 0 | { |
12659 | 0 | Py_ssize_t ival = -1; |
12660 | 0 | PyObject *iobj = _PyNumber_Index(args[0]); |
12661 | 0 | if (iobj != NULL) { |
12662 | 0 | ival = PyLong_AsSsize_t(iobj); |
12663 | 0 | Py_DECREF(iobj); |
12664 | 0 | } |
12665 | 0 | if (ival == -1 && PyErr_Occurred()) { |
12666 | 0 | goto exit; |
12667 | 0 | } |
12668 | 0 | size = ival; |
12669 | 0 | } |
12670 | 0 | if (!noptargs) { |
12671 | 0 | goto skip_optional_pos; |
12672 | 0 | } |
12673 | 0 | { |
12674 | 0 | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned int), |
12675 | 0 | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
12676 | 0 | Py_ASNATIVEBYTES_ALLOW_INDEX | |
12677 | 0 | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
12678 | 0 | if (_bytes < 0) { |
12679 | 0 | goto exit; |
12680 | 0 | } |
12681 | 0 | if ((size_t)_bytes > sizeof(unsigned int)) { |
12682 | 0 | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
12683 | 0 | "integer value out of range", 1) < 0) |
12684 | 0 | { |
12685 | 0 | goto exit; |
12686 | 0 | } |
12687 | 0 | } |
12688 | 0 | } |
12689 | 0 | skip_optional_pos: |
12690 | 0 | return_value = os_getrandom_impl(module, size, flags); |
12691 | |
|
12692 | 0 | exit: |
12693 | 0 | return return_value; |
12694 | 0 | } |
12695 | | |
12696 | | #endif /* (defined(HAVE_GETRANDOM) || defined(HAVE_GETRANDOM_SYSCALL)) */ |
12697 | | |
12698 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12699 | | |
12700 | | PyDoc_STRVAR(os__add_dll_directory__doc__, |
12701 | | "_add_dll_directory($module, /, path)\n" |
12702 | | "--\n" |
12703 | | "\n" |
12704 | | "Add a path to the DLL search path.\n" |
12705 | | "\n" |
12706 | | "This search path is used when resolving dependencies for imported\n" |
12707 | | "extension modules (the module itself is resolved through sys.path),\n" |
12708 | | "and also by ctypes.\n" |
12709 | | "\n" |
12710 | | "Returns an opaque value that may be passed to os.remove_dll_directory\n" |
12711 | | "to remove this directory from the search path."); |
12712 | | |
12713 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF \ |
12714 | | {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__}, |
12715 | | |
12716 | | static PyObject * |
12717 | | os__add_dll_directory_impl(PyObject *module, path_t *path); |
12718 | | |
12719 | | static PyObject * |
12720 | | os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12721 | | { |
12722 | | PyObject *return_value = NULL; |
12723 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12724 | | |
12725 | | #define NUM_KEYWORDS 1 |
12726 | | static struct { |
12727 | | PyGC_Head _this_is_not_used; |
12728 | | PyObject_VAR_HEAD |
12729 | | Py_hash_t ob_hash; |
12730 | | PyObject *ob_item[NUM_KEYWORDS]; |
12731 | | } _kwtuple = { |
12732 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12733 | | .ob_hash = -1, |
12734 | | .ob_item = { &_Py_ID(path), }, |
12735 | | }; |
12736 | | #undef NUM_KEYWORDS |
12737 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12738 | | |
12739 | | #else // !Py_BUILD_CORE |
12740 | | # define KWTUPLE NULL |
12741 | | #endif // !Py_BUILD_CORE |
12742 | | |
12743 | | static const char * const _keywords[] = {"path", NULL}; |
12744 | | static _PyArg_Parser _parser = { |
12745 | | .keywords = _keywords, |
12746 | | .fname = "_add_dll_directory", |
12747 | | .kwtuple = KWTUPLE, |
12748 | | }; |
12749 | | #undef KWTUPLE |
12750 | | PyObject *argsbuf[1]; |
12751 | | path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0); |
12752 | | |
12753 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12754 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12755 | | if (!args) { |
12756 | | goto exit; |
12757 | | } |
12758 | | if (!path_converter(args[0], &path)) { |
12759 | | goto exit; |
12760 | | } |
12761 | | return_value = os__add_dll_directory_impl(module, &path); |
12762 | | |
12763 | | exit: |
12764 | | /* Cleanup for path */ |
12765 | | path_cleanup(&path); |
12766 | | |
12767 | | return return_value; |
12768 | | } |
12769 | | |
12770 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12771 | | |
12772 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12773 | | |
12774 | | PyDoc_STRVAR(os__remove_dll_directory__doc__, |
12775 | | "_remove_dll_directory($module, /, cookie)\n" |
12776 | | "--\n" |
12777 | | "\n" |
12778 | | "Removes a path from the DLL search path.\n" |
12779 | | "\n" |
12780 | | "The parameter is an opaque value that was returned from\n" |
12781 | | "os.add_dll_directory. You can only remove directories that you added\n" |
12782 | | "yourself."); |
12783 | | |
12784 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \ |
12785 | | {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__}, |
12786 | | |
12787 | | static PyObject * |
12788 | | os__remove_dll_directory_impl(PyObject *module, PyObject *cookie); |
12789 | | |
12790 | | static PyObject * |
12791 | | os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12792 | | { |
12793 | | PyObject *return_value = NULL; |
12794 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12795 | | |
12796 | | #define NUM_KEYWORDS 1 |
12797 | | static struct { |
12798 | | PyGC_Head _this_is_not_used; |
12799 | | PyObject_VAR_HEAD |
12800 | | Py_hash_t ob_hash; |
12801 | | PyObject *ob_item[NUM_KEYWORDS]; |
12802 | | } _kwtuple = { |
12803 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12804 | | .ob_hash = -1, |
12805 | | .ob_item = { &_Py_ID(cookie), }, |
12806 | | }; |
12807 | | #undef NUM_KEYWORDS |
12808 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12809 | | |
12810 | | #else // !Py_BUILD_CORE |
12811 | | # define KWTUPLE NULL |
12812 | | #endif // !Py_BUILD_CORE |
12813 | | |
12814 | | static const char * const _keywords[] = {"cookie", NULL}; |
12815 | | static _PyArg_Parser _parser = { |
12816 | | .keywords = _keywords, |
12817 | | .fname = "_remove_dll_directory", |
12818 | | .kwtuple = KWTUPLE, |
12819 | | }; |
12820 | | #undef KWTUPLE |
12821 | | PyObject *argsbuf[1]; |
12822 | | PyObject *cookie; |
12823 | | |
12824 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12825 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12826 | | if (!args) { |
12827 | | goto exit; |
12828 | | } |
12829 | | cookie = args[0]; |
12830 | | return_value = os__remove_dll_directory_impl(module, cookie); |
12831 | | |
12832 | | exit: |
12833 | | return return_value; |
12834 | | } |
12835 | | |
12836 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12837 | | |
12838 | | #if (defined(WIFEXITED) || defined(MS_WINDOWS)) |
12839 | | |
12840 | | PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__, |
12841 | | "waitstatus_to_exitcode($module, /, status)\n" |
12842 | | "--\n" |
12843 | | "\n" |
12844 | | "Convert a wait status to an exit code.\n" |
12845 | | "\n" |
12846 | | "On Unix:\n" |
12847 | | "\n" |
12848 | | "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n" |
12849 | | "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n" |
12850 | | "* Otherwise, raise a ValueError.\n" |
12851 | | "\n" |
12852 | | "On Windows, return status shifted right by 8 bits.\n" |
12853 | | "\n" |
12854 | | "On Unix, if the process is being traced or if waitpid() was called with\n" |
12855 | | "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is\n" |
12856 | | "true. This function must not be called if WIFSTOPPED(status) is true."); |
12857 | | |
12858 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \ |
12859 | | {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__}, |
12860 | | |
12861 | | static PyObject * |
12862 | | os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj); |
12863 | | |
12864 | | static PyObject * |
12865 | | os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12866 | 0 | { |
12867 | 0 | PyObject *return_value = NULL; |
12868 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12869 | |
|
12870 | 0 | #define NUM_KEYWORDS 1 |
12871 | 0 | static struct { |
12872 | 0 | PyGC_Head _this_is_not_used; |
12873 | 0 | PyObject_VAR_HEAD |
12874 | 0 | Py_hash_t ob_hash; |
12875 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12876 | 0 | } _kwtuple = { |
12877 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12878 | 0 | .ob_hash = -1, |
12879 | 0 | .ob_item = { &_Py_ID(status), }, |
12880 | 0 | }; |
12881 | 0 | #undef NUM_KEYWORDS |
12882 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12883 | |
|
12884 | | #else // !Py_BUILD_CORE |
12885 | | # define KWTUPLE NULL |
12886 | | #endif // !Py_BUILD_CORE |
12887 | |
|
12888 | 0 | static const char * const _keywords[] = {"status", NULL}; |
12889 | 0 | static _PyArg_Parser _parser = { |
12890 | 0 | .keywords = _keywords, |
12891 | 0 | .fname = "waitstatus_to_exitcode", |
12892 | 0 | .kwtuple = KWTUPLE, |
12893 | 0 | }; |
12894 | 0 | #undef KWTUPLE |
12895 | 0 | PyObject *argsbuf[1]; |
12896 | 0 | PyObject *status_obj; |
12897 | |
|
12898 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12899 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12900 | 0 | if (!args) { |
12901 | 0 | goto exit; |
12902 | 0 | } |
12903 | 0 | status_obj = args[0]; |
12904 | 0 | return_value = os_waitstatus_to_exitcode_impl(module, status_obj); |
12905 | |
|
12906 | 0 | exit: |
12907 | 0 | return return_value; |
12908 | 0 | } |
12909 | | |
12910 | | #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */ |
12911 | | |
12912 | | #if defined(MS_WINDOWS) |
12913 | | |
12914 | | PyDoc_STRVAR(os__supports_virtual_terminal__doc__, |
12915 | | "_supports_virtual_terminal($module, /)\n" |
12916 | | "--\n" |
12917 | | "\n" |
12918 | | "Checks if virtual terminal is supported in windows"); |
12919 | | |
12920 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF \ |
12921 | | {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__}, |
12922 | | |
12923 | | static PyObject * |
12924 | | os__supports_virtual_terminal_impl(PyObject *module); |
12925 | | |
12926 | | static PyObject * |
12927 | | os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12928 | | { |
12929 | | return os__supports_virtual_terminal_impl(module); |
12930 | | } |
12931 | | |
12932 | | #endif /* defined(MS_WINDOWS) */ |
12933 | | |
12934 | | PyDoc_STRVAR(os__inputhook__doc__, |
12935 | | "_inputhook($module, /)\n" |
12936 | | "--\n" |
12937 | | "\n" |
12938 | | "Calls PyOS_InputHook dropping the GIL first"); |
12939 | | |
12940 | | #define OS__INPUTHOOK_METHODDEF \ |
12941 | | {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__}, |
12942 | | |
12943 | | static PyObject * |
12944 | | os__inputhook_impl(PyObject *module); |
12945 | | |
12946 | | static PyObject * |
12947 | | os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12948 | 0 | { |
12949 | 0 | return os__inputhook_impl(module); |
12950 | 0 | } |
12951 | | |
12952 | | PyDoc_STRVAR(os__is_inputhook_installed__doc__, |
12953 | | "_is_inputhook_installed($module, /)\n" |
12954 | | "--\n" |
12955 | | "\n" |
12956 | | "Checks if PyOS_InputHook is set"); |
12957 | | |
12958 | | #define OS__IS_INPUTHOOK_INSTALLED_METHODDEF \ |
12959 | | {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__}, |
12960 | | |
12961 | | static PyObject * |
12962 | | os__is_inputhook_installed_impl(PyObject *module); |
12963 | | |
12964 | | static PyObject * |
12965 | | os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12966 | 0 | { |
12967 | 0 | return os__is_inputhook_installed_impl(module); |
12968 | 0 | } |
12969 | | |
12970 | | PyDoc_STRVAR(os__create_environ__doc__, |
12971 | | "_create_environ($module, /)\n" |
12972 | | "--\n" |
12973 | | "\n" |
12974 | | "Create the environment dictionary."); |
12975 | | |
12976 | | #define OS__CREATE_ENVIRON_METHODDEF \ |
12977 | | {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__}, |
12978 | | |
12979 | | static PyObject * |
12980 | | os__create_environ_impl(PyObject *module); |
12981 | | |
12982 | | static PyObject * |
12983 | | os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12984 | 0 | { |
12985 | 0 | return os__create_environ_impl(module); |
12986 | 0 | } |
12987 | | |
12988 | | #if defined(__EMSCRIPTEN__) |
12989 | | |
12990 | | PyDoc_STRVAR(os__emscripten_debugger__doc__, |
12991 | | "_emscripten_debugger($module, /)\n" |
12992 | | "--\n" |
12993 | | "\n" |
12994 | | "Create a breakpoint for the JavaScript debugger. Emscripten only."); |
12995 | | |
12996 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF \ |
12997 | | {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__}, |
12998 | | |
12999 | | static PyObject * |
13000 | | os__emscripten_debugger_impl(PyObject *module); |
13001 | | |
13002 | | static PyObject * |
13003 | | os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored)) |
13004 | | { |
13005 | | return os__emscripten_debugger_impl(module); |
13006 | | } |
13007 | | |
13008 | | #endif /* defined(__EMSCRIPTEN__) */ |
13009 | | |
13010 | | #if defined(__EMSCRIPTEN__) |
13011 | | |
13012 | | PyDoc_STRVAR(os__emscripten_log__doc__, |
13013 | | "_emscripten_log($module, /, arg)\n" |
13014 | | "--\n" |
13015 | | "\n" |
13016 | | "Log something to the JS console. Emscripten only."); |
13017 | | |
13018 | | #define OS__EMSCRIPTEN_LOG_METHODDEF \ |
13019 | | {"_emscripten_log", _PyCFunction_CAST(os__emscripten_log), METH_FASTCALL|METH_KEYWORDS, os__emscripten_log__doc__}, |
13020 | | |
13021 | | static PyObject * |
13022 | | os__emscripten_log_impl(PyObject *module, const char *arg); |
13023 | | |
13024 | | static PyObject * |
13025 | | os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
13026 | | { |
13027 | | PyObject *return_value = NULL; |
13028 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
13029 | | |
13030 | | #define NUM_KEYWORDS 1 |
13031 | | static struct { |
13032 | | PyGC_Head _this_is_not_used; |
13033 | | PyObject_VAR_HEAD |
13034 | | Py_hash_t ob_hash; |
13035 | | PyObject *ob_item[NUM_KEYWORDS]; |
13036 | | } _kwtuple = { |
13037 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
13038 | | .ob_hash = -1, |
13039 | | .ob_item = { &_Py_ID(arg), }, |
13040 | | }; |
13041 | | #undef NUM_KEYWORDS |
13042 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
13043 | | |
13044 | | #else // !Py_BUILD_CORE |
13045 | | # define KWTUPLE NULL |
13046 | | #endif // !Py_BUILD_CORE |
13047 | | |
13048 | | static const char * const _keywords[] = {"arg", NULL}; |
13049 | | static _PyArg_Parser _parser = { |
13050 | | .keywords = _keywords, |
13051 | | .fname = "_emscripten_log", |
13052 | | .kwtuple = KWTUPLE, |
13053 | | }; |
13054 | | #undef KWTUPLE |
13055 | | PyObject *argsbuf[1]; |
13056 | | const char *arg; |
13057 | | |
13058 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
13059 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
13060 | | if (!args) { |
13061 | | goto exit; |
13062 | | } |
13063 | | if (!PyUnicode_Check(args[0])) { |
13064 | | _PyArg_BadArgument("_emscripten_log", "argument 'arg'", "str", args[0]); |
13065 | | goto exit; |
13066 | | } |
13067 | | arg = _PyUnicode_AsUTF8NoNUL(args[0]); |
13068 | | if (arg == NULL) { |
13069 | | goto exit; |
13070 | | } |
13071 | | return_value = os__emscripten_log_impl(module, arg); |
13072 | | |
13073 | | exit: |
13074 | | return return_value; |
13075 | | } |
13076 | | |
13077 | | #endif /* defined(__EMSCRIPTEN__) */ |
13078 | | |
13079 | | #ifndef OS_STATX_METHODDEF |
13080 | | #define OS_STATX_METHODDEF |
13081 | | #endif /* !defined(OS_STATX_METHODDEF) */ |
13082 | | |
13083 | | #ifndef OS_TTYNAME_METHODDEF |
13084 | | #define OS_TTYNAME_METHODDEF |
13085 | | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
13086 | | |
13087 | | #ifndef OS_CTERMID_METHODDEF |
13088 | | #define OS_CTERMID_METHODDEF |
13089 | | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
13090 | | |
13091 | | #ifndef OS_FCHDIR_METHODDEF |
13092 | | #define OS_FCHDIR_METHODDEF |
13093 | | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
13094 | | |
13095 | | #ifndef OS_FCHMOD_METHODDEF |
13096 | | #define OS_FCHMOD_METHODDEF |
13097 | | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
13098 | | |
13099 | | #ifndef OS_LCHMOD_METHODDEF |
13100 | | #define OS_LCHMOD_METHODDEF |
13101 | | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
13102 | | |
13103 | | #ifndef OS_CHFLAGS_METHODDEF |
13104 | | #define OS_CHFLAGS_METHODDEF |
13105 | | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
13106 | | |
13107 | | #ifndef OS_LCHFLAGS_METHODDEF |
13108 | | #define OS_LCHFLAGS_METHODDEF |
13109 | | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
13110 | | |
13111 | | #ifndef OS_CHROOT_METHODDEF |
13112 | | #define OS_CHROOT_METHODDEF |
13113 | | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
13114 | | |
13115 | | #ifndef OS_FSYNC_METHODDEF |
13116 | | #define OS_FSYNC_METHODDEF |
13117 | | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
13118 | | |
13119 | | #ifndef OS_SYNC_METHODDEF |
13120 | | #define OS_SYNC_METHODDEF |
13121 | | #endif /* !defined(OS_SYNC_METHODDEF) */ |
13122 | | |
13123 | | #ifndef OS_FDATASYNC_METHODDEF |
13124 | | #define OS_FDATASYNC_METHODDEF |
13125 | | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
13126 | | |
13127 | | #ifndef OS_CHOWN_METHODDEF |
13128 | | #define OS_CHOWN_METHODDEF |
13129 | | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
13130 | | |
13131 | | #ifndef OS_FCHOWN_METHODDEF |
13132 | | #define OS_FCHOWN_METHODDEF |
13133 | | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
13134 | | |
13135 | | #ifndef OS_LCHOWN_METHODDEF |
13136 | | #define OS_LCHOWN_METHODDEF |
13137 | | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
13138 | | |
13139 | | #ifndef OS_LINK_METHODDEF |
13140 | | #define OS_LINK_METHODDEF |
13141 | | #endif /* !defined(OS_LINK_METHODDEF) */ |
13142 | | |
13143 | | #ifndef OS_LISTDRIVES_METHODDEF |
13144 | | #define OS_LISTDRIVES_METHODDEF |
13145 | | #endif /* !defined(OS_LISTDRIVES_METHODDEF) */ |
13146 | | |
13147 | | #ifndef OS_LISTVOLUMES_METHODDEF |
13148 | | #define OS_LISTVOLUMES_METHODDEF |
13149 | | #endif /* !defined(OS_LISTVOLUMES_METHODDEF) */ |
13150 | | |
13151 | | #ifndef OS_LISTMOUNTS_METHODDEF |
13152 | | #define OS_LISTMOUNTS_METHODDEF |
13153 | | #endif /* !defined(OS_LISTMOUNTS_METHODDEF) */ |
13154 | | |
13155 | | #ifndef OS__PATH_ISDEVDRIVE_METHODDEF |
13156 | | #define OS__PATH_ISDEVDRIVE_METHODDEF |
13157 | | #endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */ |
13158 | | |
13159 | | #ifndef OS__GETFULLPATHNAME_METHODDEF |
13160 | | #define OS__GETFULLPATHNAME_METHODDEF |
13161 | | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
13162 | | |
13163 | | #ifndef OS__GETFINALPATHNAME_METHODDEF |
13164 | | #define OS__GETFINALPATHNAME_METHODDEF |
13165 | | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
13166 | | |
13167 | | #ifndef OS__FINDFIRSTFILE_METHODDEF |
13168 | | #define OS__FINDFIRSTFILE_METHODDEF |
13169 | | #endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */ |
13170 | | |
13171 | | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
13172 | | #define OS__GETVOLUMEPATHNAME_METHODDEF |
13173 | | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
13174 | | |
13175 | | #ifndef OS__PATH_SPLITROOT_METHODDEF |
13176 | | #define OS__PATH_SPLITROOT_METHODDEF |
13177 | | #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */ |
13178 | | |
13179 | | #ifndef OS__PATH_EXISTS_METHODDEF |
13180 | | #define OS__PATH_EXISTS_METHODDEF |
13181 | | #endif /* !defined(OS__PATH_EXISTS_METHODDEF) */ |
13182 | | |
13183 | | #ifndef OS__PATH_LEXISTS_METHODDEF |
13184 | | #define OS__PATH_LEXISTS_METHODDEF |
13185 | | #endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */ |
13186 | | |
13187 | | #ifndef OS__PATH_ISDIR_METHODDEF |
13188 | | #define OS__PATH_ISDIR_METHODDEF |
13189 | | #endif /* !defined(OS__PATH_ISDIR_METHODDEF) */ |
13190 | | |
13191 | | #ifndef OS__PATH_ISFILE_METHODDEF |
13192 | | #define OS__PATH_ISFILE_METHODDEF |
13193 | | #endif /* !defined(OS__PATH_ISFILE_METHODDEF) */ |
13194 | | |
13195 | | #ifndef OS__PATH_ISLINK_METHODDEF |
13196 | | #define OS__PATH_ISLINK_METHODDEF |
13197 | | #endif /* !defined(OS__PATH_ISLINK_METHODDEF) */ |
13198 | | |
13199 | | #ifndef OS__PATH_ISJUNCTION_METHODDEF |
13200 | | #define OS__PATH_ISJUNCTION_METHODDEF |
13201 | | #endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */ |
13202 | | |
13203 | | #ifndef OS_NICE_METHODDEF |
13204 | | #define OS_NICE_METHODDEF |
13205 | | #endif /* !defined(OS_NICE_METHODDEF) */ |
13206 | | |
13207 | | #ifndef OS_GETPRIORITY_METHODDEF |
13208 | | #define OS_GETPRIORITY_METHODDEF |
13209 | | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
13210 | | |
13211 | | #ifndef OS_SETPRIORITY_METHODDEF |
13212 | | #define OS_SETPRIORITY_METHODDEF |
13213 | | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
13214 | | |
13215 | | #ifndef OS_SYSTEM_METHODDEF |
13216 | | #define OS_SYSTEM_METHODDEF |
13217 | | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
13218 | | |
13219 | | #ifndef OS_UMASK_METHODDEF |
13220 | | #define OS_UMASK_METHODDEF |
13221 | | #endif /* !defined(OS_UMASK_METHODDEF) */ |
13222 | | |
13223 | | #ifndef OS_UNAME_METHODDEF |
13224 | | #define OS_UNAME_METHODDEF |
13225 | | #endif /* !defined(OS_UNAME_METHODDEF) */ |
13226 | | |
13227 | | #ifndef OS_EXECV_METHODDEF |
13228 | | #define OS_EXECV_METHODDEF |
13229 | | #endif /* !defined(OS_EXECV_METHODDEF) */ |
13230 | | |
13231 | | #ifndef OS_EXECVE_METHODDEF |
13232 | | #define OS_EXECVE_METHODDEF |
13233 | | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
13234 | | |
13235 | | #ifndef OS_POSIX_SPAWN_METHODDEF |
13236 | | #define OS_POSIX_SPAWN_METHODDEF |
13237 | | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
13238 | | |
13239 | | #ifndef OS_POSIX_SPAWNP_METHODDEF |
13240 | | #define OS_POSIX_SPAWNP_METHODDEF |
13241 | | #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */ |
13242 | | |
13243 | | #ifndef OS_SPAWNV_METHODDEF |
13244 | | #define OS_SPAWNV_METHODDEF |
13245 | | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
13246 | | |
13247 | | #ifndef OS_SPAWNVE_METHODDEF |
13248 | | #define OS_SPAWNVE_METHODDEF |
13249 | | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
13250 | | |
13251 | | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
13252 | | #define OS_REGISTER_AT_FORK_METHODDEF |
13253 | | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
13254 | | |
13255 | | #ifndef OS_FORK1_METHODDEF |
13256 | | #define OS_FORK1_METHODDEF |
13257 | | #endif /* !defined(OS_FORK1_METHODDEF) */ |
13258 | | |
13259 | | #ifndef OS_FORK_METHODDEF |
13260 | | #define OS_FORK_METHODDEF |
13261 | | #endif /* !defined(OS_FORK_METHODDEF) */ |
13262 | | |
13263 | | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
13264 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
13265 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
13266 | | |
13267 | | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
13268 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
13269 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
13270 | | |
13271 | | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
13272 | | #define OS_SCHED_GETSCHEDULER_METHODDEF |
13273 | | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
13274 | | |
13275 | | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
13276 | | #define OS_SCHED_SETSCHEDULER_METHODDEF |
13277 | | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
13278 | | |
13279 | | #ifndef OS_SCHED_GETPARAM_METHODDEF |
13280 | | #define OS_SCHED_GETPARAM_METHODDEF |
13281 | | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
13282 | | |
13283 | | #ifndef OS_SCHED_SETPARAM_METHODDEF |
13284 | | #define OS_SCHED_SETPARAM_METHODDEF |
13285 | | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
13286 | | |
13287 | | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
13288 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
13289 | | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
13290 | | |
13291 | | #ifndef OS_SCHED_YIELD_METHODDEF |
13292 | | #define OS_SCHED_YIELD_METHODDEF |
13293 | | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
13294 | | |
13295 | | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
13296 | | #define OS_SCHED_SETAFFINITY_METHODDEF |
13297 | | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
13298 | | |
13299 | | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
13300 | | #define OS_SCHED_GETAFFINITY_METHODDEF |
13301 | | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
13302 | | |
13303 | | #ifndef OS_POSIX_OPENPT_METHODDEF |
13304 | | #define OS_POSIX_OPENPT_METHODDEF |
13305 | | #endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */ |
13306 | | |
13307 | | #ifndef OS_GRANTPT_METHODDEF |
13308 | | #define OS_GRANTPT_METHODDEF |
13309 | | #endif /* !defined(OS_GRANTPT_METHODDEF) */ |
13310 | | |
13311 | | #ifndef OS_UNLOCKPT_METHODDEF |
13312 | | #define OS_UNLOCKPT_METHODDEF |
13313 | | #endif /* !defined(OS_UNLOCKPT_METHODDEF) */ |
13314 | | |
13315 | | #ifndef OS_PTSNAME_METHODDEF |
13316 | | #define OS_PTSNAME_METHODDEF |
13317 | | #endif /* !defined(OS_PTSNAME_METHODDEF) */ |
13318 | | |
13319 | | #ifndef OS_OPENPTY_METHODDEF |
13320 | | #define OS_OPENPTY_METHODDEF |
13321 | | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
13322 | | |
13323 | | #ifndef OS_LOGIN_TTY_METHODDEF |
13324 | | #define OS_LOGIN_TTY_METHODDEF |
13325 | | #endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ |
13326 | | |
13327 | | #ifndef OS_FORKPTY_METHODDEF |
13328 | | #define OS_FORKPTY_METHODDEF |
13329 | | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
13330 | | |
13331 | | #ifndef OS_GETEGID_METHODDEF |
13332 | | #define OS_GETEGID_METHODDEF |
13333 | | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
13334 | | |
13335 | | #ifndef OS_GETEUID_METHODDEF |
13336 | | #define OS_GETEUID_METHODDEF |
13337 | | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
13338 | | |
13339 | | #ifndef OS_GETGID_METHODDEF |
13340 | | #define OS_GETGID_METHODDEF |
13341 | | #endif /* !defined(OS_GETGID_METHODDEF) */ |
13342 | | |
13343 | | #ifndef OS_GETPID_METHODDEF |
13344 | | #define OS_GETPID_METHODDEF |
13345 | | #endif /* !defined(OS_GETPID_METHODDEF) */ |
13346 | | |
13347 | | #ifndef OS_GETGROUPLIST_METHODDEF |
13348 | | #define OS_GETGROUPLIST_METHODDEF |
13349 | | #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */ |
13350 | | |
13351 | | #ifndef OS_GETGROUPS_METHODDEF |
13352 | | #define OS_GETGROUPS_METHODDEF |
13353 | | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
13354 | | |
13355 | | #ifndef OS_INITGROUPS_METHODDEF |
13356 | | #define OS_INITGROUPS_METHODDEF |
13357 | | #endif /* !defined(OS_INITGROUPS_METHODDEF) */ |
13358 | | |
13359 | | #ifndef OS_GETPGID_METHODDEF |
13360 | | #define OS_GETPGID_METHODDEF |
13361 | | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
13362 | | |
13363 | | #ifndef OS_GETPGRP_METHODDEF |
13364 | | #define OS_GETPGRP_METHODDEF |
13365 | | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
13366 | | |
13367 | | #ifndef OS_SETPGRP_METHODDEF |
13368 | | #define OS_SETPGRP_METHODDEF |
13369 | | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
13370 | | |
13371 | | #ifndef OS_GETPPID_METHODDEF |
13372 | | #define OS_GETPPID_METHODDEF |
13373 | | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
13374 | | |
13375 | | #ifndef OS_GETLOGIN_METHODDEF |
13376 | | #define OS_GETLOGIN_METHODDEF |
13377 | | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
13378 | | |
13379 | | #ifndef OS_GETUID_METHODDEF |
13380 | | #define OS_GETUID_METHODDEF |
13381 | | #endif /* !defined(OS_GETUID_METHODDEF) */ |
13382 | | |
13383 | | #ifndef OS_KILL_METHODDEF |
13384 | | #define OS_KILL_METHODDEF |
13385 | | #endif /* !defined(OS_KILL_METHODDEF) */ |
13386 | | |
13387 | | #ifndef OS_KILLPG_METHODDEF |
13388 | | #define OS_KILLPG_METHODDEF |
13389 | | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
13390 | | |
13391 | | #ifndef OS_PLOCK_METHODDEF |
13392 | | #define OS_PLOCK_METHODDEF |
13393 | | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
13394 | | |
13395 | | #ifndef OS_SETUID_METHODDEF |
13396 | | #define OS_SETUID_METHODDEF |
13397 | | #endif /* !defined(OS_SETUID_METHODDEF) */ |
13398 | | |
13399 | | #ifndef OS_SETEUID_METHODDEF |
13400 | | #define OS_SETEUID_METHODDEF |
13401 | | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
13402 | | |
13403 | | #ifndef OS_SETEGID_METHODDEF |
13404 | | #define OS_SETEGID_METHODDEF |
13405 | | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
13406 | | |
13407 | | #ifndef OS_SETREUID_METHODDEF |
13408 | | #define OS_SETREUID_METHODDEF |
13409 | | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
13410 | | |
13411 | | #ifndef OS_SETREGID_METHODDEF |
13412 | | #define OS_SETREGID_METHODDEF |
13413 | | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
13414 | | |
13415 | | #ifndef OS_SETGID_METHODDEF |
13416 | | #define OS_SETGID_METHODDEF |
13417 | | #endif /* !defined(OS_SETGID_METHODDEF) */ |
13418 | | |
13419 | | #ifndef OS_SETGROUPS_METHODDEF |
13420 | | #define OS_SETGROUPS_METHODDEF |
13421 | | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
13422 | | |
13423 | | #ifndef OS_WAIT3_METHODDEF |
13424 | | #define OS_WAIT3_METHODDEF |
13425 | | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
13426 | | |
13427 | | #ifndef OS_WAIT4_METHODDEF |
13428 | | #define OS_WAIT4_METHODDEF |
13429 | | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
13430 | | |
13431 | | #ifndef OS_WAITID_METHODDEF |
13432 | | #define OS_WAITID_METHODDEF |
13433 | | #endif /* !defined(OS_WAITID_METHODDEF) */ |
13434 | | |
13435 | | #ifndef OS_WAITPID_METHODDEF |
13436 | | #define OS_WAITPID_METHODDEF |
13437 | | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
13438 | | |
13439 | | #ifndef OS_WAIT_METHODDEF |
13440 | | #define OS_WAIT_METHODDEF |
13441 | | #endif /* !defined(OS_WAIT_METHODDEF) */ |
13442 | | |
13443 | | #ifndef OS_PIDFD_OPEN_METHODDEF |
13444 | | #define OS_PIDFD_OPEN_METHODDEF |
13445 | | #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */ |
13446 | | |
13447 | | #ifndef OS_PIDFD_GETFD_METHODDEF |
13448 | | #define OS_PIDFD_GETFD_METHODDEF |
13449 | | #endif /* !defined(OS_PIDFD_GETFD_METHODDEF) */ |
13450 | | |
13451 | | #ifndef OS_SETNS_METHODDEF |
13452 | | #define OS_SETNS_METHODDEF |
13453 | | #endif /* !defined(OS_SETNS_METHODDEF) */ |
13454 | | |
13455 | | #ifndef OS_UNSHARE_METHODDEF |
13456 | | #define OS_UNSHARE_METHODDEF |
13457 | | #endif /* !defined(OS_UNSHARE_METHODDEF) */ |
13458 | | |
13459 | | #ifndef OS_READLINK_METHODDEF |
13460 | | #define OS_READLINK_METHODDEF |
13461 | | #endif /* !defined(OS_READLINK_METHODDEF) */ |
13462 | | |
13463 | | #ifndef OS_SYMLINK_METHODDEF |
13464 | | #define OS_SYMLINK_METHODDEF |
13465 | | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
13466 | | |
13467 | | #ifndef OS_TIMERFD_CREATE_METHODDEF |
13468 | | #define OS_TIMERFD_CREATE_METHODDEF |
13469 | | #endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */ |
13470 | | |
13471 | | #ifndef OS_TIMERFD_SETTIME_METHODDEF |
13472 | | #define OS_TIMERFD_SETTIME_METHODDEF |
13473 | | #endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */ |
13474 | | |
13475 | | #ifndef OS_TIMERFD_SETTIME_NS_METHODDEF |
13476 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF |
13477 | | #endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */ |
13478 | | |
13479 | | #ifndef OS_TIMERFD_GETTIME_METHODDEF |
13480 | | #define OS_TIMERFD_GETTIME_METHODDEF |
13481 | | #endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */ |
13482 | | |
13483 | | #ifndef OS_TIMERFD_GETTIME_NS_METHODDEF |
13484 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF |
13485 | | #endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */ |
13486 | | |
13487 | | #ifndef OS_GETSID_METHODDEF |
13488 | | #define OS_GETSID_METHODDEF |
13489 | | #endif /* !defined(OS_GETSID_METHODDEF) */ |
13490 | | |
13491 | | #ifndef OS_SETSID_METHODDEF |
13492 | | #define OS_SETSID_METHODDEF |
13493 | | #endif /* !defined(OS_SETSID_METHODDEF) */ |
13494 | | |
13495 | | #ifndef OS_SETPGID_METHODDEF |
13496 | | #define OS_SETPGID_METHODDEF |
13497 | | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
13498 | | |
13499 | | #ifndef OS_TCGETPGRP_METHODDEF |
13500 | | #define OS_TCGETPGRP_METHODDEF |
13501 | | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
13502 | | |
13503 | | #ifndef OS_TCSETPGRP_METHODDEF |
13504 | | #define OS_TCSETPGRP_METHODDEF |
13505 | | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
13506 | | |
13507 | | #ifndef OS_DUP2_METHODDEF |
13508 | | #define OS_DUP2_METHODDEF |
13509 | | #endif /* !defined(OS_DUP2_METHODDEF) */ |
13510 | | |
13511 | | #ifndef OS_LOCKF_METHODDEF |
13512 | | #define OS_LOCKF_METHODDEF |
13513 | | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
13514 | | |
13515 | | #ifndef OS_READV_METHODDEF |
13516 | | #define OS_READV_METHODDEF |
13517 | | #endif /* !defined(OS_READV_METHODDEF) */ |
13518 | | |
13519 | | #ifndef OS_PREAD_METHODDEF |
13520 | | #define OS_PREAD_METHODDEF |
13521 | | #endif /* !defined(OS_PREAD_METHODDEF) */ |
13522 | | |
13523 | | #ifndef OS_PREADV_METHODDEF |
13524 | | #define OS_PREADV_METHODDEF |
13525 | | #endif /* !defined(OS_PREADV_METHODDEF) */ |
13526 | | |
13527 | | #ifndef OS_SENDFILE_METHODDEF |
13528 | | #define OS_SENDFILE_METHODDEF |
13529 | | #endif /* !defined(OS_SENDFILE_METHODDEF) */ |
13530 | | |
13531 | | #ifndef OS__FCOPYFILE_METHODDEF |
13532 | | #define OS__FCOPYFILE_METHODDEF |
13533 | | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
13534 | | |
13535 | | #ifndef OS_PIPE_METHODDEF |
13536 | | #define OS_PIPE_METHODDEF |
13537 | | #endif /* !defined(OS_PIPE_METHODDEF) */ |
13538 | | |
13539 | | #ifndef OS_PIPE2_METHODDEF |
13540 | | #define OS_PIPE2_METHODDEF |
13541 | | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
13542 | | |
13543 | | #ifndef OS_WRITEV_METHODDEF |
13544 | | #define OS_WRITEV_METHODDEF |
13545 | | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
13546 | | |
13547 | | #ifndef OS_PWRITE_METHODDEF |
13548 | | #define OS_PWRITE_METHODDEF |
13549 | | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
13550 | | |
13551 | | #ifndef OS_PWRITEV_METHODDEF |
13552 | | #define OS_PWRITEV_METHODDEF |
13553 | | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
13554 | | |
13555 | | #ifndef OS_COPY_FILE_RANGE_METHODDEF |
13556 | | #define OS_COPY_FILE_RANGE_METHODDEF |
13557 | | #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */ |
13558 | | |
13559 | | #ifndef OS_SPLICE_METHODDEF |
13560 | | #define OS_SPLICE_METHODDEF |
13561 | | #endif /* !defined(OS_SPLICE_METHODDEF) */ |
13562 | | |
13563 | | #ifndef OS_MKFIFO_METHODDEF |
13564 | | #define OS_MKFIFO_METHODDEF |
13565 | | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
13566 | | |
13567 | | #ifndef OS_MKNOD_METHODDEF |
13568 | | #define OS_MKNOD_METHODDEF |
13569 | | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
13570 | | |
13571 | | #ifndef OS_MAJOR_METHODDEF |
13572 | | #define OS_MAJOR_METHODDEF |
13573 | | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
13574 | | |
13575 | | #ifndef OS_MINOR_METHODDEF |
13576 | | #define OS_MINOR_METHODDEF |
13577 | | #endif /* !defined(OS_MINOR_METHODDEF) */ |
13578 | | |
13579 | | #ifndef OS_MAKEDEV_METHODDEF |
13580 | | #define OS_MAKEDEV_METHODDEF |
13581 | | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
13582 | | |
13583 | | #ifndef OS_FTRUNCATE_METHODDEF |
13584 | | #define OS_FTRUNCATE_METHODDEF |
13585 | | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
13586 | | |
13587 | | #ifndef OS_TRUNCATE_METHODDEF |
13588 | | #define OS_TRUNCATE_METHODDEF |
13589 | | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
13590 | | |
13591 | | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
13592 | | #define OS_POSIX_FALLOCATE_METHODDEF |
13593 | | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
13594 | | |
13595 | | #ifndef OS_POSIX_FADVISE_METHODDEF |
13596 | | #define OS_POSIX_FADVISE_METHODDEF |
13597 | | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
13598 | | |
13599 | | #ifndef OS_PUTENV_METHODDEF |
13600 | | #define OS_PUTENV_METHODDEF |
13601 | | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
13602 | | |
13603 | | #ifndef OS_UNSETENV_METHODDEF |
13604 | | #define OS_UNSETENV_METHODDEF |
13605 | | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
13606 | | |
13607 | | #ifndef OS__CLEARENV_METHODDEF |
13608 | | #define OS__CLEARENV_METHODDEF |
13609 | | #endif /* !defined(OS__CLEARENV_METHODDEF) */ |
13610 | | |
13611 | | #ifndef OS_WCOREDUMP_METHODDEF |
13612 | | #define OS_WCOREDUMP_METHODDEF |
13613 | | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
13614 | | |
13615 | | #ifndef OS_WIFCONTINUED_METHODDEF |
13616 | | #define OS_WIFCONTINUED_METHODDEF |
13617 | | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
13618 | | |
13619 | | #ifndef OS_WIFSTOPPED_METHODDEF |
13620 | | #define OS_WIFSTOPPED_METHODDEF |
13621 | | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
13622 | | |
13623 | | #ifndef OS_WIFSIGNALED_METHODDEF |
13624 | | #define OS_WIFSIGNALED_METHODDEF |
13625 | | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
13626 | | |
13627 | | #ifndef OS_WIFEXITED_METHODDEF |
13628 | | #define OS_WIFEXITED_METHODDEF |
13629 | | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
13630 | | |
13631 | | #ifndef OS_WEXITSTATUS_METHODDEF |
13632 | | #define OS_WEXITSTATUS_METHODDEF |
13633 | | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
13634 | | |
13635 | | #ifndef OS_WTERMSIG_METHODDEF |
13636 | | #define OS_WTERMSIG_METHODDEF |
13637 | | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
13638 | | |
13639 | | #ifndef OS_WSTOPSIG_METHODDEF |
13640 | | #define OS_WSTOPSIG_METHODDEF |
13641 | | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
13642 | | |
13643 | | #ifndef OS_FSTATVFS_METHODDEF |
13644 | | #define OS_FSTATVFS_METHODDEF |
13645 | | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
13646 | | |
13647 | | #ifndef OS_STATVFS_METHODDEF |
13648 | | #define OS_STATVFS_METHODDEF |
13649 | | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
13650 | | |
13651 | | #ifndef OS__GETDISKUSAGE_METHODDEF |
13652 | | #define OS__GETDISKUSAGE_METHODDEF |
13653 | | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
13654 | | |
13655 | | #ifndef OS_FPATHCONF_METHODDEF |
13656 | | #define OS_FPATHCONF_METHODDEF |
13657 | | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
13658 | | |
13659 | | #ifndef OS_PATHCONF_METHODDEF |
13660 | | #define OS_PATHCONF_METHODDEF |
13661 | | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
13662 | | |
13663 | | #ifndef OS_CONFSTR_METHODDEF |
13664 | | #define OS_CONFSTR_METHODDEF |
13665 | | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
13666 | | |
13667 | | #ifndef OS_SYSCONF_METHODDEF |
13668 | | #define OS_SYSCONF_METHODDEF |
13669 | | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
13670 | | |
13671 | | #ifndef OS_STARTFILE_METHODDEF |
13672 | | #define OS_STARTFILE_METHODDEF |
13673 | | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
13674 | | |
13675 | | #ifndef OS_GETLOADAVG_METHODDEF |
13676 | | #define OS_GETLOADAVG_METHODDEF |
13677 | | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
13678 | | |
13679 | | #ifndef OS_SETRESUID_METHODDEF |
13680 | | #define OS_SETRESUID_METHODDEF |
13681 | | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
13682 | | |
13683 | | #ifndef OS_SETRESGID_METHODDEF |
13684 | | #define OS_SETRESGID_METHODDEF |
13685 | | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
13686 | | |
13687 | | #ifndef OS_GETRESUID_METHODDEF |
13688 | | #define OS_GETRESUID_METHODDEF |
13689 | | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
13690 | | |
13691 | | #ifndef OS_GETRESGID_METHODDEF |
13692 | | #define OS_GETRESGID_METHODDEF |
13693 | | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
13694 | | |
13695 | | #ifndef OS_GETXATTR_METHODDEF |
13696 | | #define OS_GETXATTR_METHODDEF |
13697 | | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
13698 | | |
13699 | | #ifndef OS_SETXATTR_METHODDEF |
13700 | | #define OS_SETXATTR_METHODDEF |
13701 | | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
13702 | | |
13703 | | #ifndef OS_REMOVEXATTR_METHODDEF |
13704 | | #define OS_REMOVEXATTR_METHODDEF |
13705 | | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
13706 | | |
13707 | | #ifndef OS_LISTXATTR_METHODDEF |
13708 | | #define OS_LISTXATTR_METHODDEF |
13709 | | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
13710 | | |
13711 | | #ifndef OS_MEMFD_CREATE_METHODDEF |
13712 | | #define OS_MEMFD_CREATE_METHODDEF |
13713 | | #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */ |
13714 | | |
13715 | | #ifndef OS_EVENTFD_METHODDEF |
13716 | | #define OS_EVENTFD_METHODDEF |
13717 | | #endif /* !defined(OS_EVENTFD_METHODDEF) */ |
13718 | | |
13719 | | #ifndef OS_EVENTFD_READ_METHODDEF |
13720 | | #define OS_EVENTFD_READ_METHODDEF |
13721 | | #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */ |
13722 | | |
13723 | | #ifndef OS_EVENTFD_WRITE_METHODDEF |
13724 | | #define OS_EVENTFD_WRITE_METHODDEF |
13725 | | #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */ |
13726 | | |
13727 | | #ifndef OS_GET_TERMINAL_SIZE_METHODDEF |
13728 | | #define OS_GET_TERMINAL_SIZE_METHODDEF |
13729 | | #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */ |
13730 | | |
13731 | | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
13732 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
13733 | | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
13734 | | |
13735 | | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
13736 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
13737 | | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
13738 | | |
13739 | | #ifndef OS_GETRANDOM_METHODDEF |
13740 | | #define OS_GETRANDOM_METHODDEF |
13741 | | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
13742 | | |
13743 | | #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF |
13744 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF |
13745 | | #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */ |
13746 | | |
13747 | | #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13748 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13749 | | #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */ |
13750 | | |
13751 | | #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13752 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13753 | | #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ |
13754 | | |
13755 | | #ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13756 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13757 | | #endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */ |
13758 | | |
13759 | | #ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13760 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13761 | | #endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */ |
13762 | | |
13763 | | #ifndef OS__EMSCRIPTEN_LOG_METHODDEF |
13764 | | #define OS__EMSCRIPTEN_LOG_METHODDEF |
13765 | | #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ |
13766 | | /*[clinic end generated code: output=8bf88a95035a0188 input=a9049054013a1b77]*/ |