/src/cpython/Modules/clinic/posixmodule.c.h
Line | Count | Source (jump to first uncovered line) |
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_long.h" // _PyLong_UnsignedInt_Converter() |
11 | | #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
12 | | |
13 | | PyDoc_STRVAR(os_stat__doc__, |
14 | | "stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n" |
15 | | "--\n" |
16 | | "\n" |
17 | | "Perform a stat system call on the given path.\n" |
18 | | "\n" |
19 | | " path\n" |
20 | | " Path to be examined; can be string, bytes, a path-like object or\n" |
21 | | " open-file-descriptor int.\n" |
22 | | " dir_fd\n" |
23 | | " If not None, it should be a file descriptor open to a directory,\n" |
24 | | " and path should be a relative string; path will then be relative to\n" |
25 | | " that directory.\n" |
26 | | " follow_symlinks\n" |
27 | | " If False, and the last element of the path is a symbolic link,\n" |
28 | | " stat will examine the symbolic link itself instead of the file\n" |
29 | | " the link points to.\n" |
30 | | "\n" |
31 | | "dir_fd and follow_symlinks may not be implemented\n" |
32 | | " on your platform. If they are unavailable, using them will raise a\n" |
33 | | " NotImplementedError.\n" |
34 | | "\n" |
35 | | "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n" |
36 | | " an open file descriptor."); |
37 | | |
38 | | #define OS_STAT_METHODDEF \ |
39 | | {"stat", _PyCFunction_CAST(os_stat), METH_FASTCALL|METH_KEYWORDS, os_stat__doc__}, |
40 | | |
41 | | static PyObject * |
42 | | os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks); |
43 | | |
44 | | static PyObject * |
45 | | os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
46 | 5.00k | { |
47 | 5.00k | PyObject *return_value = NULL; |
48 | 5.00k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
49 | | |
50 | 5.00k | #define NUM_KEYWORDS 3 |
51 | 5.00k | static struct { |
52 | 5.00k | PyGC_Head _this_is_not_used; |
53 | 5.00k | PyObject_VAR_HEAD |
54 | 5.00k | Py_hash_t ob_hash; |
55 | 5.00k | PyObject *ob_item[NUM_KEYWORDS]; |
56 | 5.00k | } _kwtuple = { |
57 | 5.00k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
58 | 5.00k | .ob_hash = -1, |
59 | 5.00k | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
60 | 5.00k | }; |
61 | 5.00k | #undef NUM_KEYWORDS |
62 | 5.00k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
63 | | |
64 | | #else // !Py_BUILD_CORE |
65 | | # define KWTUPLE NULL |
66 | | #endif // !Py_BUILD_CORE |
67 | | |
68 | 5.00k | static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; |
69 | 5.00k | static _PyArg_Parser _parser = { |
70 | 5.00k | .keywords = _keywords, |
71 | 5.00k | .fname = "stat", |
72 | 5.00k | .kwtuple = KWTUPLE, |
73 | 5.00k | }; |
74 | 5.00k | #undef KWTUPLE |
75 | 5.00k | PyObject *argsbuf[3]; |
76 | 5.00k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
77 | 5.00k | path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1); |
78 | 5.00k | int dir_fd = DEFAULT_DIR_FD; |
79 | 5.00k | int follow_symlinks = 1; |
80 | | |
81 | 5.00k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
82 | 5.00k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
83 | 5.00k | if (!args) { |
84 | 0 | goto exit; |
85 | 0 | } |
86 | 5.00k | if (!path_converter(args[0], &path)) { |
87 | 0 | goto exit; |
88 | 0 | } |
89 | 5.00k | if (!noptargs) { |
90 | 5.00k | goto skip_optional_kwonly; |
91 | 5.00k | } |
92 | 0 | if (args[1]) { |
93 | 0 | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
94 | 0 | goto exit; |
95 | 0 | } |
96 | 0 | if (!--noptargs) { |
97 | 0 | goto skip_optional_kwonly; |
98 | 0 | } |
99 | 0 | } |
100 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
101 | 0 | if (follow_symlinks < 0) { |
102 | 0 | goto exit; |
103 | 0 | } |
104 | 5.00k | skip_optional_kwonly: |
105 | 5.00k | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
106 | | |
107 | 5.00k | exit: |
108 | | /* Cleanup for path */ |
109 | 5.00k | path_cleanup(&path); |
110 | | |
111 | 5.00k | return return_value; |
112 | 5.00k | } |
113 | | |
114 | | PyDoc_STRVAR(os_lstat__doc__, |
115 | | "lstat($module, /, path, *, dir_fd=None)\n" |
116 | | "--\n" |
117 | | "\n" |
118 | | "Perform a stat system call on the given path, without following symbolic links.\n" |
119 | | "\n" |
120 | | "Like stat(), but do not follow symbolic links.\n" |
121 | | "Equivalent to stat(path, follow_symlinks=False)."); |
122 | | |
123 | | #define OS_LSTAT_METHODDEF \ |
124 | | {"lstat", _PyCFunction_CAST(os_lstat), METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__}, |
125 | | |
126 | | static PyObject * |
127 | | os_lstat_impl(PyObject *module, path_t *path, int dir_fd); |
128 | | |
129 | | static PyObject * |
130 | | os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
131 | 0 | { |
132 | 0 | PyObject *return_value = NULL; |
133 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
134 | |
|
135 | 0 | #define NUM_KEYWORDS 2 |
136 | 0 | static struct { |
137 | 0 | PyGC_Head _this_is_not_used; |
138 | 0 | PyObject_VAR_HEAD |
139 | 0 | Py_hash_t ob_hash; |
140 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
141 | 0 | } _kwtuple = { |
142 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
143 | 0 | .ob_hash = -1, |
144 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
145 | 0 | }; |
146 | 0 | #undef NUM_KEYWORDS |
147 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
148 | |
|
149 | | #else // !Py_BUILD_CORE |
150 | | # define KWTUPLE NULL |
151 | | #endif // !Py_BUILD_CORE |
152 | |
|
153 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
154 | 0 | static _PyArg_Parser _parser = { |
155 | 0 | .keywords = _keywords, |
156 | 0 | .fname = "lstat", |
157 | 0 | .kwtuple = KWTUPLE, |
158 | 0 | }; |
159 | 0 | #undef KWTUPLE |
160 | 0 | PyObject *argsbuf[2]; |
161 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
162 | 0 | path_t path = PATH_T_INITIALIZE_P("lstat", "path", 0, 0, 0, 0); |
163 | 0 | int dir_fd = DEFAULT_DIR_FD; |
164 | |
|
165 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
166 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
167 | 0 | if (!args) { |
168 | 0 | goto exit; |
169 | 0 | } |
170 | 0 | if (!path_converter(args[0], &path)) { |
171 | 0 | goto exit; |
172 | 0 | } |
173 | 0 | if (!noptargs) { |
174 | 0 | goto skip_optional_kwonly; |
175 | 0 | } |
176 | 0 | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
177 | 0 | goto exit; |
178 | 0 | } |
179 | 0 | skip_optional_kwonly: |
180 | 0 | return_value = os_lstat_impl(module, &path, dir_fd); |
181 | |
|
182 | 0 | exit: |
183 | | /* Cleanup for path */ |
184 | 0 | path_cleanup(&path); |
185 | |
|
186 | 0 | return return_value; |
187 | 0 | } |
188 | | |
189 | | PyDoc_STRVAR(os_access__doc__, |
190 | | "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n" |
191 | | " follow_symlinks=True)\n" |
192 | | "--\n" |
193 | | "\n" |
194 | | "Use the real uid/gid to test for access to a path.\n" |
195 | | "\n" |
196 | | " path\n" |
197 | | " Path to be tested; can be string, bytes, or a path-like object.\n" |
198 | | " mode\n" |
199 | | " Operating-system mode bitfield. Can be F_OK to test existence,\n" |
200 | | " or the inclusive-OR of R_OK, W_OK, and X_OK.\n" |
201 | | " dir_fd\n" |
202 | | " If not None, it should be a file descriptor open to a directory,\n" |
203 | | " and path should be relative; path will then be relative to that\n" |
204 | | " directory.\n" |
205 | | " effective_ids\n" |
206 | | " If True, access will use the effective uid/gid instead of\n" |
207 | | " the real uid/gid.\n" |
208 | | " follow_symlinks\n" |
209 | | " If False, and the last element of the path is a symbolic link,\n" |
210 | | " access will examine the symbolic link itself instead of the file\n" |
211 | | " the link points to.\n" |
212 | | "\n" |
213 | | "dir_fd, effective_ids, and follow_symlinks may not be implemented\n" |
214 | | " on your platform. If they are unavailable, using them will raise a\n" |
215 | | " NotImplementedError.\n" |
216 | | "\n" |
217 | | "Note that most operations will use the effective uid/gid, therefore this\n" |
218 | | " routine can be used in a suid/sgid environment to test if the invoking\n" |
219 | | " user has the specified access to the path."); |
220 | | |
221 | | #define OS_ACCESS_METHODDEF \ |
222 | | {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__}, |
223 | | |
224 | | static int |
225 | | os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
226 | | int effective_ids, int follow_symlinks); |
227 | | |
228 | | static PyObject * |
229 | | os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
230 | 0 | { |
231 | 0 | PyObject *return_value = NULL; |
232 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
233 | |
|
234 | 0 | #define NUM_KEYWORDS 5 |
235 | 0 | static struct { |
236 | 0 | PyGC_Head _this_is_not_used; |
237 | 0 | PyObject_VAR_HEAD |
238 | 0 | Py_hash_t ob_hash; |
239 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
240 | 0 | } _kwtuple = { |
241 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
242 | 0 | .ob_hash = -1, |
243 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), }, |
244 | 0 | }; |
245 | 0 | #undef NUM_KEYWORDS |
246 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
247 | |
|
248 | | #else // !Py_BUILD_CORE |
249 | | # define KWTUPLE NULL |
250 | | #endif // !Py_BUILD_CORE |
251 | |
|
252 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL}; |
253 | 0 | static _PyArg_Parser _parser = { |
254 | 0 | .keywords = _keywords, |
255 | 0 | .fname = "access", |
256 | 0 | .kwtuple = KWTUPLE, |
257 | 0 | }; |
258 | 0 | #undef KWTUPLE |
259 | 0 | PyObject *argsbuf[5]; |
260 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
261 | 0 | path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0); |
262 | 0 | int mode; |
263 | 0 | int dir_fd = DEFAULT_DIR_FD; |
264 | 0 | int effective_ids = 0; |
265 | 0 | int follow_symlinks = 1; |
266 | 0 | int _return_value; |
267 | |
|
268 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
269 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
270 | 0 | if (!args) { |
271 | 0 | goto exit; |
272 | 0 | } |
273 | 0 | if (!path_converter(args[0], &path)) { |
274 | 0 | goto exit; |
275 | 0 | } |
276 | 0 | mode = PyLong_AsInt(args[1]); |
277 | 0 | if (mode == -1 && PyErr_Occurred()) { |
278 | 0 | goto exit; |
279 | 0 | } |
280 | 0 | if (!noptargs) { |
281 | 0 | goto skip_optional_kwonly; |
282 | 0 | } |
283 | 0 | if (args[2]) { |
284 | 0 | if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
285 | 0 | goto exit; |
286 | 0 | } |
287 | 0 | if (!--noptargs) { |
288 | 0 | goto skip_optional_kwonly; |
289 | 0 | } |
290 | 0 | } |
291 | 0 | if (args[3]) { |
292 | 0 | effective_ids = PyObject_IsTrue(args[3]); |
293 | 0 | if (effective_ids < 0) { |
294 | 0 | goto exit; |
295 | 0 | } |
296 | 0 | if (!--noptargs) { |
297 | 0 | goto skip_optional_kwonly; |
298 | 0 | } |
299 | 0 | } |
300 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
301 | 0 | if (follow_symlinks < 0) { |
302 | 0 | goto exit; |
303 | 0 | } |
304 | 0 | skip_optional_kwonly: |
305 | 0 | _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks); |
306 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
307 | 0 | goto exit; |
308 | 0 | } |
309 | 0 | return_value = PyBool_FromLong((long)_return_value); |
310 | |
|
311 | 0 | exit: |
312 | | /* Cleanup for path */ |
313 | 0 | path_cleanup(&path); |
314 | |
|
315 | 0 | return return_value; |
316 | 0 | } |
317 | | |
318 | | #if defined(HAVE_TTYNAME_R) |
319 | | |
320 | | PyDoc_STRVAR(os_ttyname__doc__, |
321 | | "ttyname($module, fd, /)\n" |
322 | | "--\n" |
323 | | "\n" |
324 | | "Return the name of the terminal device connected to \'fd\'.\n" |
325 | | "\n" |
326 | | " fd\n" |
327 | | " Integer file descriptor handle."); |
328 | | |
329 | | #define OS_TTYNAME_METHODDEF \ |
330 | | {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__}, |
331 | | |
332 | | static PyObject * |
333 | | os_ttyname_impl(PyObject *module, int fd); |
334 | | |
335 | | static PyObject * |
336 | | os_ttyname(PyObject *module, PyObject *arg) |
337 | 0 | { |
338 | 0 | PyObject *return_value = NULL; |
339 | 0 | int fd; |
340 | |
|
341 | 0 | fd = PyLong_AsInt(arg); |
342 | 0 | if (fd == -1 && PyErr_Occurred()) { |
343 | 0 | goto exit; |
344 | 0 | } |
345 | 0 | return_value = os_ttyname_impl(module, fd); |
346 | |
|
347 | 0 | exit: |
348 | 0 | return return_value; |
349 | 0 | } |
350 | | |
351 | | #endif /* defined(HAVE_TTYNAME_R) */ |
352 | | |
353 | | #if defined(HAVE_CTERMID) |
354 | | |
355 | | PyDoc_STRVAR(os_ctermid__doc__, |
356 | | "ctermid($module, /)\n" |
357 | | "--\n" |
358 | | "\n" |
359 | | "Return the name of the controlling terminal for this process."); |
360 | | |
361 | | #define OS_CTERMID_METHODDEF \ |
362 | | {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, |
363 | | |
364 | | static PyObject * |
365 | | os_ctermid_impl(PyObject *module); |
366 | | |
367 | | static PyObject * |
368 | | os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
369 | 0 | { |
370 | 0 | return os_ctermid_impl(module); |
371 | 0 | } |
372 | | |
373 | | #endif /* defined(HAVE_CTERMID) */ |
374 | | |
375 | | PyDoc_STRVAR(os_chdir__doc__, |
376 | | "chdir($module, /, path)\n" |
377 | | "--\n" |
378 | | "\n" |
379 | | "Change the current working directory to the specified path.\n" |
380 | | "\n" |
381 | | "path may always be specified as a string.\n" |
382 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
383 | | "If this functionality is unavailable, using it raises an exception."); |
384 | | |
385 | | #define OS_CHDIR_METHODDEF \ |
386 | | {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__}, |
387 | | |
388 | | static PyObject * |
389 | | os_chdir_impl(PyObject *module, path_t *path); |
390 | | |
391 | | static PyObject * |
392 | | os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
393 | 0 | { |
394 | 0 | PyObject *return_value = NULL; |
395 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
396 | |
|
397 | 0 | #define NUM_KEYWORDS 1 |
398 | 0 | static struct { |
399 | 0 | PyGC_Head _this_is_not_used; |
400 | 0 | PyObject_VAR_HEAD |
401 | 0 | Py_hash_t ob_hash; |
402 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
403 | 0 | } _kwtuple = { |
404 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
405 | 0 | .ob_hash = -1, |
406 | 0 | .ob_item = { &_Py_ID(path), }, |
407 | 0 | }; |
408 | 0 | #undef NUM_KEYWORDS |
409 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
410 | |
|
411 | | #else // !Py_BUILD_CORE |
412 | | # define KWTUPLE NULL |
413 | | #endif // !Py_BUILD_CORE |
414 | |
|
415 | 0 | static const char * const _keywords[] = {"path", NULL}; |
416 | 0 | static _PyArg_Parser _parser = { |
417 | 0 | .keywords = _keywords, |
418 | 0 | .fname = "chdir", |
419 | 0 | .kwtuple = KWTUPLE, |
420 | 0 | }; |
421 | 0 | #undef KWTUPLE |
422 | 0 | PyObject *argsbuf[1]; |
423 | 0 | path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR); |
424 | |
|
425 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
426 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
427 | 0 | if (!args) { |
428 | 0 | goto exit; |
429 | 0 | } |
430 | 0 | if (!path_converter(args[0], &path)) { |
431 | 0 | goto exit; |
432 | 0 | } |
433 | 0 | return_value = os_chdir_impl(module, &path); |
434 | |
|
435 | 0 | exit: |
436 | | /* Cleanup for path */ |
437 | 0 | path_cleanup(&path); |
438 | |
|
439 | 0 | return return_value; |
440 | 0 | } |
441 | | |
442 | | #if defined(HAVE_FCHDIR) |
443 | | |
444 | | PyDoc_STRVAR(os_fchdir__doc__, |
445 | | "fchdir($module, /, fd)\n" |
446 | | "--\n" |
447 | | "\n" |
448 | | "Change to the directory of the given file descriptor.\n" |
449 | | "\n" |
450 | | "fd must be opened on a directory, not a file.\n" |
451 | | "Equivalent to os.chdir(fd)."); |
452 | | |
453 | | #define OS_FCHDIR_METHODDEF \ |
454 | | {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__}, |
455 | | |
456 | | static PyObject * |
457 | | os_fchdir_impl(PyObject *module, int fd); |
458 | | |
459 | | static PyObject * |
460 | | os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
461 | 0 | { |
462 | 0 | PyObject *return_value = NULL; |
463 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
464 | |
|
465 | 0 | #define NUM_KEYWORDS 1 |
466 | 0 | static struct { |
467 | 0 | PyGC_Head _this_is_not_used; |
468 | 0 | PyObject_VAR_HEAD |
469 | 0 | Py_hash_t ob_hash; |
470 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
471 | 0 | } _kwtuple = { |
472 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
473 | 0 | .ob_hash = -1, |
474 | 0 | .ob_item = { &_Py_ID(fd), }, |
475 | 0 | }; |
476 | 0 | #undef NUM_KEYWORDS |
477 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
478 | |
|
479 | | #else // !Py_BUILD_CORE |
480 | | # define KWTUPLE NULL |
481 | | #endif // !Py_BUILD_CORE |
482 | |
|
483 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
484 | 0 | static _PyArg_Parser _parser = { |
485 | 0 | .keywords = _keywords, |
486 | 0 | .fname = "fchdir", |
487 | 0 | .kwtuple = KWTUPLE, |
488 | 0 | }; |
489 | 0 | #undef KWTUPLE |
490 | 0 | PyObject *argsbuf[1]; |
491 | 0 | int fd; |
492 | |
|
493 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
494 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
495 | 0 | if (!args) { |
496 | 0 | goto exit; |
497 | 0 | } |
498 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
499 | 0 | if (fd < 0) { |
500 | 0 | goto exit; |
501 | 0 | } |
502 | 0 | return_value = os_fchdir_impl(module, fd); |
503 | |
|
504 | 0 | exit: |
505 | 0 | return return_value; |
506 | 0 | } |
507 | | |
508 | | #endif /* defined(HAVE_FCHDIR) */ |
509 | | |
510 | | PyDoc_STRVAR(os_chmod__doc__, |
511 | | "chmod($module, /, path, mode, *, dir_fd=None,\n" |
512 | | " follow_symlinks=(os.name != \'nt\'))\n" |
513 | | "--\n" |
514 | | "\n" |
515 | | "Change the access permissions of a file.\n" |
516 | | "\n" |
517 | | " path\n" |
518 | | " Path to be modified. May always be specified as a str, bytes, or a path-like object.\n" |
519 | | " On some platforms, path may also be specified as an open file descriptor.\n" |
520 | | " If this functionality is unavailable, using it raises an exception.\n" |
521 | | " mode\n" |
522 | | " Operating-system mode bitfield.\n" |
523 | | " Be careful when using number literals for *mode*. The conventional UNIX notation for\n" |
524 | | " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n" |
525 | | " Python.\n" |
526 | | " dir_fd\n" |
527 | | " If not None, it should be a file descriptor open to a directory,\n" |
528 | | " and path should be relative; path will then be relative to that\n" |
529 | | " directory.\n" |
530 | | " follow_symlinks\n" |
531 | | " If False, and the last element of the path is a symbolic link,\n" |
532 | | " chmod will modify the symbolic link itself instead of the file\n" |
533 | | " the link points to.\n" |
534 | | "\n" |
535 | | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
536 | | " an open file descriptor.\n" |
537 | | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
538 | | " If they are unavailable, using them will raise a NotImplementedError."); |
539 | | |
540 | | #define OS_CHMOD_METHODDEF \ |
541 | | {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__}, |
542 | | |
543 | | static PyObject * |
544 | | os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
545 | | int follow_symlinks); |
546 | | |
547 | | static PyObject * |
548 | | os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
549 | 0 | { |
550 | 0 | PyObject *return_value = NULL; |
551 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
552 | |
|
553 | 0 | #define NUM_KEYWORDS 4 |
554 | 0 | static struct { |
555 | 0 | PyGC_Head _this_is_not_used; |
556 | 0 | PyObject_VAR_HEAD |
557 | 0 | Py_hash_t ob_hash; |
558 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
559 | 0 | } _kwtuple = { |
560 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
561 | 0 | .ob_hash = -1, |
562 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
563 | 0 | }; |
564 | 0 | #undef NUM_KEYWORDS |
565 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
566 | |
|
567 | | #else // !Py_BUILD_CORE |
568 | | # define KWTUPLE NULL |
569 | | #endif // !Py_BUILD_CORE |
570 | |
|
571 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL}; |
572 | 0 | static _PyArg_Parser _parser = { |
573 | 0 | .keywords = _keywords, |
574 | 0 | .fname = "chmod", |
575 | 0 | .kwtuple = KWTUPLE, |
576 | 0 | }; |
577 | 0 | #undef KWTUPLE |
578 | 0 | PyObject *argsbuf[4]; |
579 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
580 | 0 | path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD); |
581 | 0 | int mode; |
582 | 0 | int dir_fd = DEFAULT_DIR_FD; |
583 | 0 | int follow_symlinks = CHMOD_DEFAULT_FOLLOW_SYMLINKS; |
584 | |
|
585 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
586 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
587 | 0 | if (!args) { |
588 | 0 | goto exit; |
589 | 0 | } |
590 | 0 | if (!path_converter(args[0], &path)) { |
591 | 0 | goto exit; |
592 | 0 | } |
593 | 0 | mode = PyLong_AsInt(args[1]); |
594 | 0 | if (mode == -1 && PyErr_Occurred()) { |
595 | 0 | goto exit; |
596 | 0 | } |
597 | 0 | if (!noptargs) { |
598 | 0 | goto skip_optional_kwonly; |
599 | 0 | } |
600 | 0 | if (args[2]) { |
601 | 0 | if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
602 | 0 | goto exit; |
603 | 0 | } |
604 | 0 | if (!--noptargs) { |
605 | 0 | goto skip_optional_kwonly; |
606 | 0 | } |
607 | 0 | } |
608 | 0 | follow_symlinks = PyObject_IsTrue(args[3]); |
609 | 0 | if (follow_symlinks < 0) { |
610 | 0 | goto exit; |
611 | 0 | } |
612 | 0 | skip_optional_kwonly: |
613 | 0 | return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); |
614 | |
|
615 | 0 | exit: |
616 | | /* Cleanup for path */ |
617 | 0 | path_cleanup(&path); |
618 | |
|
619 | 0 | return return_value; |
620 | 0 | } |
621 | | |
622 | | #if (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) |
623 | | |
624 | | PyDoc_STRVAR(os_fchmod__doc__, |
625 | | "fchmod($module, /, fd, mode)\n" |
626 | | "--\n" |
627 | | "\n" |
628 | | "Change the access permissions of the file given by file descriptor fd.\n" |
629 | | "\n" |
630 | | " fd\n" |
631 | | " The file descriptor of the file to be modified.\n" |
632 | | " mode\n" |
633 | | " Operating-system mode bitfield.\n" |
634 | | " Be careful when using number literals for *mode*. The conventional UNIX notation for\n" |
635 | | " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n" |
636 | | " Python.\n" |
637 | | "\n" |
638 | | "Equivalent to os.chmod(fd, mode)."); |
639 | | |
640 | | #define OS_FCHMOD_METHODDEF \ |
641 | | {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__}, |
642 | | |
643 | | static PyObject * |
644 | | os_fchmod_impl(PyObject *module, int fd, int mode); |
645 | | |
646 | | static PyObject * |
647 | | os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
648 | 0 | { |
649 | 0 | PyObject *return_value = NULL; |
650 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
651 | |
|
652 | 0 | #define NUM_KEYWORDS 2 |
653 | 0 | static struct { |
654 | 0 | PyGC_Head _this_is_not_used; |
655 | 0 | PyObject_VAR_HEAD |
656 | 0 | Py_hash_t ob_hash; |
657 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
658 | 0 | } _kwtuple = { |
659 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
660 | 0 | .ob_hash = -1, |
661 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(mode), }, |
662 | 0 | }; |
663 | 0 | #undef NUM_KEYWORDS |
664 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
665 | |
|
666 | | #else // !Py_BUILD_CORE |
667 | | # define KWTUPLE NULL |
668 | | #endif // !Py_BUILD_CORE |
669 | |
|
670 | 0 | static const char * const _keywords[] = {"fd", "mode", NULL}; |
671 | 0 | static _PyArg_Parser _parser = { |
672 | 0 | .keywords = _keywords, |
673 | 0 | .fname = "fchmod", |
674 | 0 | .kwtuple = KWTUPLE, |
675 | 0 | }; |
676 | 0 | #undef KWTUPLE |
677 | 0 | PyObject *argsbuf[2]; |
678 | 0 | int fd; |
679 | 0 | int mode; |
680 | |
|
681 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
682 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
683 | 0 | if (!args) { |
684 | 0 | goto exit; |
685 | 0 | } |
686 | 0 | fd = PyLong_AsInt(args[0]); |
687 | 0 | if (fd == -1 && PyErr_Occurred()) { |
688 | 0 | goto exit; |
689 | 0 | } |
690 | 0 | mode = PyLong_AsInt(args[1]); |
691 | 0 | if (mode == -1 && PyErr_Occurred()) { |
692 | 0 | goto exit; |
693 | 0 | } |
694 | 0 | return_value = os_fchmod_impl(module, fd, mode); |
695 | |
|
696 | 0 | exit: |
697 | 0 | return return_value; |
698 | 0 | } |
699 | | |
700 | | #endif /* (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) */ |
701 | | |
702 | | #if (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) |
703 | | |
704 | | PyDoc_STRVAR(os_lchmod__doc__, |
705 | | "lchmod($module, /, path, mode)\n" |
706 | | "--\n" |
707 | | "\n" |
708 | | "Change the access permissions of a file, without following symbolic links.\n" |
709 | | "\n" |
710 | | "If path is a symlink, this affects the link itself rather than the target.\n" |
711 | | "Equivalent to chmod(path, mode, follow_symlinks=False).\""); |
712 | | |
713 | | #define OS_LCHMOD_METHODDEF \ |
714 | | {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__}, |
715 | | |
716 | | static PyObject * |
717 | | os_lchmod_impl(PyObject *module, path_t *path, int mode); |
718 | | |
719 | | static PyObject * |
720 | | os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
721 | | { |
722 | | PyObject *return_value = NULL; |
723 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
724 | | |
725 | | #define NUM_KEYWORDS 2 |
726 | | static struct { |
727 | | PyGC_Head _this_is_not_used; |
728 | | PyObject_VAR_HEAD |
729 | | Py_hash_t ob_hash; |
730 | | PyObject *ob_item[NUM_KEYWORDS]; |
731 | | } _kwtuple = { |
732 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
733 | | .ob_hash = -1, |
734 | | .ob_item = { &_Py_ID(path), &_Py_ID(mode), }, |
735 | | }; |
736 | | #undef NUM_KEYWORDS |
737 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
738 | | |
739 | | #else // !Py_BUILD_CORE |
740 | | # define KWTUPLE NULL |
741 | | #endif // !Py_BUILD_CORE |
742 | | |
743 | | static const char * const _keywords[] = {"path", "mode", NULL}; |
744 | | static _PyArg_Parser _parser = { |
745 | | .keywords = _keywords, |
746 | | .fname = "lchmod", |
747 | | .kwtuple = KWTUPLE, |
748 | | }; |
749 | | #undef KWTUPLE |
750 | | PyObject *argsbuf[2]; |
751 | | path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0); |
752 | | int mode; |
753 | | |
754 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
755 | | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
756 | | if (!args) { |
757 | | goto exit; |
758 | | } |
759 | | if (!path_converter(args[0], &path)) { |
760 | | goto exit; |
761 | | } |
762 | | mode = PyLong_AsInt(args[1]); |
763 | | if (mode == -1 && PyErr_Occurred()) { |
764 | | goto exit; |
765 | | } |
766 | | return_value = os_lchmod_impl(module, &path, mode); |
767 | | |
768 | | exit: |
769 | | /* Cleanup for path */ |
770 | | path_cleanup(&path); |
771 | | |
772 | | return return_value; |
773 | | } |
774 | | |
775 | | #endif /* (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) */ |
776 | | |
777 | | #if defined(HAVE_CHFLAGS) |
778 | | |
779 | | PyDoc_STRVAR(os_chflags__doc__, |
780 | | "chflags($module, /, path, flags, follow_symlinks=True)\n" |
781 | | "--\n" |
782 | | "\n" |
783 | | "Set file flags.\n" |
784 | | "\n" |
785 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
786 | | " link, chflags will change flags on the symbolic link itself instead of the\n" |
787 | | " file the link points to.\n" |
788 | | "follow_symlinks may not be implemented on your platform. If it is\n" |
789 | | "unavailable, using it will raise a NotImplementedError."); |
790 | | |
791 | | #define OS_CHFLAGS_METHODDEF \ |
792 | | {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__}, |
793 | | |
794 | | static PyObject * |
795 | | os_chflags_impl(PyObject *module, path_t *path, unsigned long flags, |
796 | | int follow_symlinks); |
797 | | |
798 | | static PyObject * |
799 | | os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
800 | | { |
801 | | PyObject *return_value = NULL; |
802 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
803 | | |
804 | | #define NUM_KEYWORDS 3 |
805 | | static struct { |
806 | | PyGC_Head _this_is_not_used; |
807 | | PyObject_VAR_HEAD |
808 | | Py_hash_t ob_hash; |
809 | | PyObject *ob_item[NUM_KEYWORDS]; |
810 | | } _kwtuple = { |
811 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
812 | | .ob_hash = -1, |
813 | | .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), }, |
814 | | }; |
815 | | #undef NUM_KEYWORDS |
816 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
817 | | |
818 | | #else // !Py_BUILD_CORE |
819 | | # define KWTUPLE NULL |
820 | | #endif // !Py_BUILD_CORE |
821 | | |
822 | | static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL}; |
823 | | static _PyArg_Parser _parser = { |
824 | | .keywords = _keywords, |
825 | | .fname = "chflags", |
826 | | .kwtuple = KWTUPLE, |
827 | | }; |
828 | | #undef KWTUPLE |
829 | | PyObject *argsbuf[3]; |
830 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
831 | | path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0); |
832 | | unsigned long flags; |
833 | | int follow_symlinks = 1; |
834 | | |
835 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
836 | | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
837 | | if (!args) { |
838 | | goto exit; |
839 | | } |
840 | | if (!path_converter(args[0], &path)) { |
841 | | goto exit; |
842 | | } |
843 | | if (!PyIndex_Check(args[1])) { |
844 | | _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]); |
845 | | goto exit; |
846 | | } |
847 | | { |
848 | | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long), |
849 | | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
850 | | Py_ASNATIVEBYTES_ALLOW_INDEX | |
851 | | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
852 | | if (_bytes < 0) { |
853 | | goto exit; |
854 | | } |
855 | | if ((size_t)_bytes > sizeof(unsigned long)) { |
856 | | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
857 | | "integer value out of range", 1) < 0) |
858 | | { |
859 | | goto exit; |
860 | | } |
861 | | } |
862 | | } |
863 | | if (!noptargs) { |
864 | | goto skip_optional_pos; |
865 | | } |
866 | | follow_symlinks = PyObject_IsTrue(args[2]); |
867 | | if (follow_symlinks < 0) { |
868 | | goto exit; |
869 | | } |
870 | | skip_optional_pos: |
871 | | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
872 | | |
873 | | exit: |
874 | | /* Cleanup for path */ |
875 | | path_cleanup(&path); |
876 | | |
877 | | return return_value; |
878 | | } |
879 | | |
880 | | #endif /* defined(HAVE_CHFLAGS) */ |
881 | | |
882 | | #if defined(HAVE_LCHFLAGS) |
883 | | |
884 | | PyDoc_STRVAR(os_lchflags__doc__, |
885 | | "lchflags($module, /, path, flags)\n" |
886 | | "--\n" |
887 | | "\n" |
888 | | "Set file flags.\n" |
889 | | "\n" |
890 | | "This function will not follow symbolic links.\n" |
891 | | "Equivalent to chflags(path, flags, follow_symlinks=False)."); |
892 | | |
893 | | #define OS_LCHFLAGS_METHODDEF \ |
894 | | {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__}, |
895 | | |
896 | | static PyObject * |
897 | | os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags); |
898 | | |
899 | | static PyObject * |
900 | | os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
901 | | { |
902 | | PyObject *return_value = NULL; |
903 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
904 | | |
905 | | #define NUM_KEYWORDS 2 |
906 | | static struct { |
907 | | PyGC_Head _this_is_not_used; |
908 | | PyObject_VAR_HEAD |
909 | | Py_hash_t ob_hash; |
910 | | PyObject *ob_item[NUM_KEYWORDS]; |
911 | | } _kwtuple = { |
912 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
913 | | .ob_hash = -1, |
914 | | .ob_item = { &_Py_ID(path), &_Py_ID(flags), }, |
915 | | }; |
916 | | #undef NUM_KEYWORDS |
917 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
918 | | |
919 | | #else // !Py_BUILD_CORE |
920 | | # define KWTUPLE NULL |
921 | | #endif // !Py_BUILD_CORE |
922 | | |
923 | | static const char * const _keywords[] = {"path", "flags", NULL}; |
924 | | static _PyArg_Parser _parser = { |
925 | | .keywords = _keywords, |
926 | | .fname = "lchflags", |
927 | | .kwtuple = KWTUPLE, |
928 | | }; |
929 | | #undef KWTUPLE |
930 | | PyObject *argsbuf[2]; |
931 | | path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0); |
932 | | unsigned long flags; |
933 | | |
934 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
935 | | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
936 | | if (!args) { |
937 | | goto exit; |
938 | | } |
939 | | if (!path_converter(args[0], &path)) { |
940 | | goto exit; |
941 | | } |
942 | | if (!PyIndex_Check(args[1])) { |
943 | | _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]); |
944 | | goto exit; |
945 | | } |
946 | | { |
947 | | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long), |
948 | | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
949 | | Py_ASNATIVEBYTES_ALLOW_INDEX | |
950 | | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
951 | | if (_bytes < 0) { |
952 | | goto exit; |
953 | | } |
954 | | if ((size_t)_bytes > sizeof(unsigned long)) { |
955 | | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
956 | | "integer value out of range", 1) < 0) |
957 | | { |
958 | | goto exit; |
959 | | } |
960 | | } |
961 | | } |
962 | | return_value = os_lchflags_impl(module, &path, flags); |
963 | | |
964 | | exit: |
965 | | /* Cleanup for path */ |
966 | | path_cleanup(&path); |
967 | | |
968 | | return return_value; |
969 | | } |
970 | | |
971 | | #endif /* defined(HAVE_LCHFLAGS) */ |
972 | | |
973 | | #if defined(HAVE_CHROOT) |
974 | | |
975 | | PyDoc_STRVAR(os_chroot__doc__, |
976 | | "chroot($module, /, path)\n" |
977 | | "--\n" |
978 | | "\n" |
979 | | "Change root directory to path."); |
980 | | |
981 | | #define OS_CHROOT_METHODDEF \ |
982 | | {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__}, |
983 | | |
984 | | static PyObject * |
985 | | os_chroot_impl(PyObject *module, path_t *path); |
986 | | |
987 | | static PyObject * |
988 | | os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
989 | 0 | { |
990 | 0 | PyObject *return_value = NULL; |
991 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
992 | |
|
993 | 0 | #define NUM_KEYWORDS 1 |
994 | 0 | static struct { |
995 | 0 | PyGC_Head _this_is_not_used; |
996 | 0 | PyObject_VAR_HEAD |
997 | 0 | Py_hash_t ob_hash; |
998 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
999 | 0 | } _kwtuple = { |
1000 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1001 | 0 | .ob_hash = -1, |
1002 | 0 | .ob_item = { &_Py_ID(path), }, |
1003 | 0 | }; |
1004 | 0 | #undef NUM_KEYWORDS |
1005 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1006 | |
|
1007 | | #else // !Py_BUILD_CORE |
1008 | | # define KWTUPLE NULL |
1009 | | #endif // !Py_BUILD_CORE |
1010 | |
|
1011 | 0 | static const char * const _keywords[] = {"path", NULL}; |
1012 | 0 | static _PyArg_Parser _parser = { |
1013 | 0 | .keywords = _keywords, |
1014 | 0 | .fname = "chroot", |
1015 | 0 | .kwtuple = KWTUPLE, |
1016 | 0 | }; |
1017 | 0 | #undef KWTUPLE |
1018 | 0 | PyObject *argsbuf[1]; |
1019 | 0 | path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0); |
1020 | |
|
1021 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1022 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1023 | 0 | if (!args) { |
1024 | 0 | goto exit; |
1025 | 0 | } |
1026 | 0 | if (!path_converter(args[0], &path)) { |
1027 | 0 | goto exit; |
1028 | 0 | } |
1029 | 0 | return_value = os_chroot_impl(module, &path); |
1030 | |
|
1031 | 0 | exit: |
1032 | | /* Cleanup for path */ |
1033 | 0 | path_cleanup(&path); |
1034 | |
|
1035 | 0 | return return_value; |
1036 | 0 | } |
1037 | | |
1038 | | #endif /* defined(HAVE_CHROOT) */ |
1039 | | |
1040 | | #if defined(HAVE_FSYNC) |
1041 | | |
1042 | | PyDoc_STRVAR(os_fsync__doc__, |
1043 | | "fsync($module, /, fd)\n" |
1044 | | "--\n" |
1045 | | "\n" |
1046 | | "Force write of fd to disk."); |
1047 | | |
1048 | | #define OS_FSYNC_METHODDEF \ |
1049 | | {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__}, |
1050 | | |
1051 | | static PyObject * |
1052 | | os_fsync_impl(PyObject *module, int fd); |
1053 | | |
1054 | | static PyObject * |
1055 | | os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1056 | 0 | { |
1057 | 0 | PyObject *return_value = NULL; |
1058 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1059 | |
|
1060 | 0 | #define NUM_KEYWORDS 1 |
1061 | 0 | static struct { |
1062 | 0 | PyGC_Head _this_is_not_used; |
1063 | 0 | PyObject_VAR_HEAD |
1064 | 0 | Py_hash_t ob_hash; |
1065 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1066 | 0 | } _kwtuple = { |
1067 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1068 | 0 | .ob_hash = -1, |
1069 | 0 | .ob_item = { &_Py_ID(fd), }, |
1070 | 0 | }; |
1071 | 0 | #undef NUM_KEYWORDS |
1072 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1073 | |
|
1074 | | #else // !Py_BUILD_CORE |
1075 | | # define KWTUPLE NULL |
1076 | | #endif // !Py_BUILD_CORE |
1077 | |
|
1078 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
1079 | 0 | static _PyArg_Parser _parser = { |
1080 | 0 | .keywords = _keywords, |
1081 | 0 | .fname = "fsync", |
1082 | 0 | .kwtuple = KWTUPLE, |
1083 | 0 | }; |
1084 | 0 | #undef KWTUPLE |
1085 | 0 | PyObject *argsbuf[1]; |
1086 | 0 | int fd; |
1087 | |
|
1088 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1089 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1090 | 0 | if (!args) { |
1091 | 0 | goto exit; |
1092 | 0 | } |
1093 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
1094 | 0 | if (fd < 0) { |
1095 | 0 | goto exit; |
1096 | 0 | } |
1097 | 0 | return_value = os_fsync_impl(module, fd); |
1098 | |
|
1099 | 0 | exit: |
1100 | 0 | return return_value; |
1101 | 0 | } |
1102 | | |
1103 | | #endif /* defined(HAVE_FSYNC) */ |
1104 | | |
1105 | | #if defined(HAVE_SYNC) |
1106 | | |
1107 | | PyDoc_STRVAR(os_sync__doc__, |
1108 | | "sync($module, /)\n" |
1109 | | "--\n" |
1110 | | "\n" |
1111 | | "Force write of everything to disk."); |
1112 | | |
1113 | | #define OS_SYNC_METHODDEF \ |
1114 | | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
1115 | | |
1116 | | static PyObject * |
1117 | | os_sync_impl(PyObject *module); |
1118 | | |
1119 | | static PyObject * |
1120 | | os_sync(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1121 | 0 | { |
1122 | 0 | return os_sync_impl(module); |
1123 | 0 | } |
1124 | | |
1125 | | #endif /* defined(HAVE_SYNC) */ |
1126 | | |
1127 | | #if defined(HAVE_FDATASYNC) |
1128 | | |
1129 | | PyDoc_STRVAR(os_fdatasync__doc__, |
1130 | | "fdatasync($module, /, fd)\n" |
1131 | | "--\n" |
1132 | | "\n" |
1133 | | "Force write of fd to disk without forcing update of metadata."); |
1134 | | |
1135 | | #define OS_FDATASYNC_METHODDEF \ |
1136 | | {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__}, |
1137 | | |
1138 | | static PyObject * |
1139 | | os_fdatasync_impl(PyObject *module, int fd); |
1140 | | |
1141 | | static PyObject * |
1142 | | os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1143 | 0 | { |
1144 | 0 | PyObject *return_value = NULL; |
1145 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1146 | |
|
1147 | 0 | #define NUM_KEYWORDS 1 |
1148 | 0 | static struct { |
1149 | 0 | PyGC_Head _this_is_not_used; |
1150 | 0 | PyObject_VAR_HEAD |
1151 | 0 | Py_hash_t ob_hash; |
1152 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1153 | 0 | } _kwtuple = { |
1154 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1155 | 0 | .ob_hash = -1, |
1156 | 0 | .ob_item = { &_Py_ID(fd), }, |
1157 | 0 | }; |
1158 | 0 | #undef NUM_KEYWORDS |
1159 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1160 | |
|
1161 | | #else // !Py_BUILD_CORE |
1162 | | # define KWTUPLE NULL |
1163 | | #endif // !Py_BUILD_CORE |
1164 | |
|
1165 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
1166 | 0 | static _PyArg_Parser _parser = { |
1167 | 0 | .keywords = _keywords, |
1168 | 0 | .fname = "fdatasync", |
1169 | 0 | .kwtuple = KWTUPLE, |
1170 | 0 | }; |
1171 | 0 | #undef KWTUPLE |
1172 | 0 | PyObject *argsbuf[1]; |
1173 | 0 | int fd; |
1174 | |
|
1175 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1176 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1177 | 0 | if (!args) { |
1178 | 0 | goto exit; |
1179 | 0 | } |
1180 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
1181 | 0 | if (fd < 0) { |
1182 | 0 | goto exit; |
1183 | 0 | } |
1184 | 0 | return_value = os_fdatasync_impl(module, fd); |
1185 | |
|
1186 | 0 | exit: |
1187 | 0 | return return_value; |
1188 | 0 | } |
1189 | | |
1190 | | #endif /* defined(HAVE_FDATASYNC) */ |
1191 | | |
1192 | | #if defined(HAVE_CHOWN) |
1193 | | |
1194 | | PyDoc_STRVAR(os_chown__doc__, |
1195 | | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
1196 | | "--\n" |
1197 | | "\n" |
1198 | | "Change the owner and group id of path to the numeric uid and gid.\\\n" |
1199 | | "\n" |
1200 | | " path\n" |
1201 | | " Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n" |
1202 | | " dir_fd\n" |
1203 | | " If not None, it should be a file descriptor open to a directory,\n" |
1204 | | " and path should be relative; path will then be relative to that\n" |
1205 | | " directory.\n" |
1206 | | " follow_symlinks\n" |
1207 | | " If False, and the last element of the path is a symbolic link,\n" |
1208 | | " stat will examine the symbolic link itself instead of the file\n" |
1209 | | " the link points to.\n" |
1210 | | "\n" |
1211 | | "path may always be specified as a string.\n" |
1212 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
1213 | | " If this functionality is unavailable, using it raises an exception.\n" |
1214 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
1215 | | " and path should be relative; path will then be relative to that directory.\n" |
1216 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
1217 | | " link, chown will modify the symbolic link itself instead of the file the\n" |
1218 | | " link points to.\n" |
1219 | | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
1220 | | " an open file descriptor.\n" |
1221 | | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
1222 | | " If they are unavailable, using them will raise a NotImplementedError."); |
1223 | | |
1224 | | #define OS_CHOWN_METHODDEF \ |
1225 | | {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__}, |
1226 | | |
1227 | | static PyObject * |
1228 | | os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid, |
1229 | | int dir_fd, int follow_symlinks); |
1230 | | |
1231 | | static PyObject * |
1232 | | os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1233 | 0 | { |
1234 | 0 | PyObject *return_value = NULL; |
1235 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1236 | |
|
1237 | 0 | #define NUM_KEYWORDS 5 |
1238 | 0 | static struct { |
1239 | 0 | PyGC_Head _this_is_not_used; |
1240 | 0 | PyObject_VAR_HEAD |
1241 | 0 | Py_hash_t ob_hash; |
1242 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1243 | 0 | } _kwtuple = { |
1244 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1245 | 0 | .ob_hash = -1, |
1246 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
1247 | 0 | }; |
1248 | 0 | #undef NUM_KEYWORDS |
1249 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1250 | |
|
1251 | | #else // !Py_BUILD_CORE |
1252 | | # define KWTUPLE NULL |
1253 | | #endif // !Py_BUILD_CORE |
1254 | |
|
1255 | 0 | static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; |
1256 | 0 | static _PyArg_Parser _parser = { |
1257 | 0 | .keywords = _keywords, |
1258 | 0 | .fname = "chown", |
1259 | 0 | .kwtuple = KWTUPLE, |
1260 | 0 | }; |
1261 | 0 | #undef KWTUPLE |
1262 | 0 | PyObject *argsbuf[5]; |
1263 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
1264 | 0 | path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN); |
1265 | 0 | uid_t uid; |
1266 | 0 | gid_t gid; |
1267 | 0 | int dir_fd = DEFAULT_DIR_FD; |
1268 | 0 | int follow_symlinks = 1; |
1269 | |
|
1270 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1271 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1272 | 0 | if (!args) { |
1273 | 0 | goto exit; |
1274 | 0 | } |
1275 | 0 | if (!path_converter(args[0], &path)) { |
1276 | 0 | goto exit; |
1277 | 0 | } |
1278 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1279 | 0 | goto exit; |
1280 | 0 | } |
1281 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1282 | 0 | goto exit; |
1283 | 0 | } |
1284 | 0 | if (!noptargs) { |
1285 | 0 | goto skip_optional_kwonly; |
1286 | 0 | } |
1287 | 0 | if (args[3]) { |
1288 | 0 | if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
1289 | 0 | goto exit; |
1290 | 0 | } |
1291 | 0 | if (!--noptargs) { |
1292 | 0 | goto skip_optional_kwonly; |
1293 | 0 | } |
1294 | 0 | } |
1295 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
1296 | 0 | if (follow_symlinks < 0) { |
1297 | 0 | goto exit; |
1298 | 0 | } |
1299 | 0 | skip_optional_kwonly: |
1300 | 0 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
1301 | |
|
1302 | 0 | exit: |
1303 | | /* Cleanup for path */ |
1304 | 0 | path_cleanup(&path); |
1305 | |
|
1306 | 0 | return return_value; |
1307 | 0 | } |
1308 | | |
1309 | | #endif /* defined(HAVE_CHOWN) */ |
1310 | | |
1311 | | #if defined(HAVE_FCHOWN) |
1312 | | |
1313 | | PyDoc_STRVAR(os_fchown__doc__, |
1314 | | "fchown($module, /, fd, uid, gid)\n" |
1315 | | "--\n" |
1316 | | "\n" |
1317 | | "Change the owner and group id of the file specified by file descriptor.\n" |
1318 | | "\n" |
1319 | | "Equivalent to os.chown(fd, uid, gid)."); |
1320 | | |
1321 | | #define OS_FCHOWN_METHODDEF \ |
1322 | | {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__}, |
1323 | | |
1324 | | static PyObject * |
1325 | | os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid); |
1326 | | |
1327 | | static PyObject * |
1328 | | os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1329 | 0 | { |
1330 | 0 | PyObject *return_value = NULL; |
1331 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1332 | |
|
1333 | 0 | #define NUM_KEYWORDS 3 |
1334 | 0 | static struct { |
1335 | 0 | PyGC_Head _this_is_not_used; |
1336 | 0 | PyObject_VAR_HEAD |
1337 | 0 | Py_hash_t ob_hash; |
1338 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1339 | 0 | } _kwtuple = { |
1340 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1341 | 0 | .ob_hash = -1, |
1342 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), }, |
1343 | 0 | }; |
1344 | 0 | #undef NUM_KEYWORDS |
1345 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1346 | |
|
1347 | | #else // !Py_BUILD_CORE |
1348 | | # define KWTUPLE NULL |
1349 | | #endif // !Py_BUILD_CORE |
1350 | |
|
1351 | 0 | static const char * const _keywords[] = {"fd", "uid", "gid", NULL}; |
1352 | 0 | static _PyArg_Parser _parser = { |
1353 | 0 | .keywords = _keywords, |
1354 | 0 | .fname = "fchown", |
1355 | 0 | .kwtuple = KWTUPLE, |
1356 | 0 | }; |
1357 | 0 | #undef KWTUPLE |
1358 | 0 | PyObject *argsbuf[3]; |
1359 | 0 | int fd; |
1360 | 0 | uid_t uid; |
1361 | 0 | gid_t gid; |
1362 | |
|
1363 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1364 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1365 | 0 | if (!args) { |
1366 | 0 | goto exit; |
1367 | 0 | } |
1368 | 0 | fd = PyLong_AsInt(args[0]); |
1369 | 0 | if (fd == -1 && PyErr_Occurred()) { |
1370 | 0 | goto exit; |
1371 | 0 | } |
1372 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1373 | 0 | goto exit; |
1374 | 0 | } |
1375 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1376 | 0 | goto exit; |
1377 | 0 | } |
1378 | 0 | return_value = os_fchown_impl(module, fd, uid, gid); |
1379 | |
|
1380 | 0 | exit: |
1381 | 0 | return return_value; |
1382 | 0 | } |
1383 | | |
1384 | | #endif /* defined(HAVE_FCHOWN) */ |
1385 | | |
1386 | | #if defined(HAVE_LCHOWN) |
1387 | | |
1388 | | PyDoc_STRVAR(os_lchown__doc__, |
1389 | | "lchown($module, /, path, uid, gid)\n" |
1390 | | "--\n" |
1391 | | "\n" |
1392 | | "Change the owner and group id of path to the numeric uid and gid.\n" |
1393 | | "\n" |
1394 | | "This function will not follow symbolic links.\n" |
1395 | | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); |
1396 | | |
1397 | | #define OS_LCHOWN_METHODDEF \ |
1398 | | {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__}, |
1399 | | |
1400 | | static PyObject * |
1401 | | os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid); |
1402 | | |
1403 | | static PyObject * |
1404 | | os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1405 | 0 | { |
1406 | 0 | PyObject *return_value = NULL; |
1407 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1408 | |
|
1409 | 0 | #define NUM_KEYWORDS 3 |
1410 | 0 | static struct { |
1411 | 0 | PyGC_Head _this_is_not_used; |
1412 | 0 | PyObject_VAR_HEAD |
1413 | 0 | Py_hash_t ob_hash; |
1414 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1415 | 0 | } _kwtuple = { |
1416 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1417 | 0 | .ob_hash = -1, |
1418 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), }, |
1419 | 0 | }; |
1420 | 0 | #undef NUM_KEYWORDS |
1421 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1422 | |
|
1423 | | #else // !Py_BUILD_CORE |
1424 | | # define KWTUPLE NULL |
1425 | | #endif // !Py_BUILD_CORE |
1426 | |
|
1427 | 0 | static const char * const _keywords[] = {"path", "uid", "gid", NULL}; |
1428 | 0 | static _PyArg_Parser _parser = { |
1429 | 0 | .keywords = _keywords, |
1430 | 0 | .fname = "lchown", |
1431 | 0 | .kwtuple = KWTUPLE, |
1432 | 0 | }; |
1433 | 0 | #undef KWTUPLE |
1434 | 0 | PyObject *argsbuf[3]; |
1435 | 0 | path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0); |
1436 | 0 | uid_t uid; |
1437 | 0 | gid_t gid; |
1438 | |
|
1439 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1440 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1441 | 0 | if (!args) { |
1442 | 0 | goto exit; |
1443 | 0 | } |
1444 | 0 | if (!path_converter(args[0], &path)) { |
1445 | 0 | goto exit; |
1446 | 0 | } |
1447 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1448 | 0 | goto exit; |
1449 | 0 | } |
1450 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1451 | 0 | goto exit; |
1452 | 0 | } |
1453 | 0 | return_value = os_lchown_impl(module, &path, uid, gid); |
1454 | |
|
1455 | 0 | exit: |
1456 | | /* Cleanup for path */ |
1457 | 0 | path_cleanup(&path); |
1458 | |
|
1459 | 0 | return return_value; |
1460 | 0 | } |
1461 | | |
1462 | | #endif /* defined(HAVE_LCHOWN) */ |
1463 | | |
1464 | | PyDoc_STRVAR(os_getcwd__doc__, |
1465 | | "getcwd($module, /)\n" |
1466 | | "--\n" |
1467 | | "\n" |
1468 | | "Return a unicode string representing the current working directory."); |
1469 | | |
1470 | | #define OS_GETCWD_METHODDEF \ |
1471 | | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
1472 | | |
1473 | | static PyObject * |
1474 | | os_getcwd_impl(PyObject *module); |
1475 | | |
1476 | | static PyObject * |
1477 | | os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1478 | 0 | { |
1479 | 0 | return os_getcwd_impl(module); |
1480 | 0 | } |
1481 | | |
1482 | | PyDoc_STRVAR(os_getcwdb__doc__, |
1483 | | "getcwdb($module, /)\n" |
1484 | | "--\n" |
1485 | | "\n" |
1486 | | "Return a bytes string representing the current working directory."); |
1487 | | |
1488 | | #define OS_GETCWDB_METHODDEF \ |
1489 | | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
1490 | | |
1491 | | static PyObject * |
1492 | | os_getcwdb_impl(PyObject *module); |
1493 | | |
1494 | | static PyObject * |
1495 | | os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1496 | 0 | { |
1497 | 0 | return os_getcwdb_impl(module); |
1498 | 0 | } |
1499 | | |
1500 | | #if defined(HAVE_LINK) |
1501 | | |
1502 | | PyDoc_STRVAR(os_link__doc__, |
1503 | | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
1504 | | " follow_symlinks=(os.name != \'nt\'))\n" |
1505 | | "--\n" |
1506 | | "\n" |
1507 | | "Create a hard link to a file.\n" |
1508 | | "\n" |
1509 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
1510 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
1511 | | " should be relative; the path will then be relative to that directory.\n" |
1512 | | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
1513 | | " link, link will create a link to the symbolic link itself instead of the\n" |
1514 | | " file the link points to.\n" |
1515 | | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" |
1516 | | " platform. If they are unavailable, using them will raise a\n" |
1517 | | " NotImplementedError."); |
1518 | | |
1519 | | #define OS_LINK_METHODDEF \ |
1520 | | {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__}, |
1521 | | |
1522 | | static PyObject * |
1523 | | os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
1524 | | int dst_dir_fd, int follow_symlinks); |
1525 | | |
1526 | | static PyObject * |
1527 | | os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1528 | 0 | { |
1529 | 0 | PyObject *return_value = NULL; |
1530 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1531 | |
|
1532 | 0 | #define NUM_KEYWORDS 5 |
1533 | 0 | static struct { |
1534 | 0 | PyGC_Head _this_is_not_used; |
1535 | 0 | PyObject_VAR_HEAD |
1536 | 0 | Py_hash_t ob_hash; |
1537 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1538 | 0 | } _kwtuple = { |
1539 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1540 | 0 | .ob_hash = -1, |
1541 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), }, |
1542 | 0 | }; |
1543 | 0 | #undef NUM_KEYWORDS |
1544 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1545 | |
|
1546 | | #else // !Py_BUILD_CORE |
1547 | | # define KWTUPLE NULL |
1548 | | #endif // !Py_BUILD_CORE |
1549 | |
|
1550 | 0 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; |
1551 | 0 | static _PyArg_Parser _parser = { |
1552 | 0 | .keywords = _keywords, |
1553 | 0 | .fname = "link", |
1554 | 0 | .kwtuple = KWTUPLE, |
1555 | 0 | }; |
1556 | 0 | #undef KWTUPLE |
1557 | 0 | PyObject *argsbuf[5]; |
1558 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
1559 | 0 | path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0); |
1560 | 0 | path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0); |
1561 | 0 | int src_dir_fd = DEFAULT_DIR_FD; |
1562 | 0 | int dst_dir_fd = DEFAULT_DIR_FD; |
1563 | 0 | int follow_symlinks = -1; |
1564 | |
|
1565 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1566 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1567 | 0 | if (!args) { |
1568 | 0 | goto exit; |
1569 | 0 | } |
1570 | 0 | if (!path_converter(args[0], &src)) { |
1571 | 0 | goto exit; |
1572 | 0 | } |
1573 | 0 | if (!path_converter(args[1], &dst)) { |
1574 | 0 | goto exit; |
1575 | 0 | } |
1576 | 0 | if (!noptargs) { |
1577 | 0 | goto skip_optional_kwonly; |
1578 | 0 | } |
1579 | 0 | if (args[2]) { |
1580 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
1581 | 0 | goto exit; |
1582 | 0 | } |
1583 | 0 | if (!--noptargs) { |
1584 | 0 | goto skip_optional_kwonly; |
1585 | 0 | } |
1586 | 0 | } |
1587 | 0 | if (args[3]) { |
1588 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
1589 | 0 | goto exit; |
1590 | 0 | } |
1591 | 0 | if (!--noptargs) { |
1592 | 0 | goto skip_optional_kwonly; |
1593 | 0 | } |
1594 | 0 | } |
1595 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
1596 | 0 | if (follow_symlinks < 0) { |
1597 | 0 | goto exit; |
1598 | 0 | } |
1599 | 0 | skip_optional_kwonly: |
1600 | 0 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
1601 | |
|
1602 | 0 | exit: |
1603 | | /* Cleanup for src */ |
1604 | 0 | path_cleanup(&src); |
1605 | | /* Cleanup for dst */ |
1606 | 0 | path_cleanup(&dst); |
1607 | |
|
1608 | 0 | return return_value; |
1609 | 0 | } |
1610 | | |
1611 | | #endif /* defined(HAVE_LINK) */ |
1612 | | |
1613 | | PyDoc_STRVAR(os_listdir__doc__, |
1614 | | "listdir($module, /, path=None)\n" |
1615 | | "--\n" |
1616 | | "\n" |
1617 | | "Return a list containing the names of the files in the directory.\n" |
1618 | | "\n" |
1619 | | "path can be specified as either str, bytes, or a path-like object. If path is bytes,\n" |
1620 | | " the filenames returned will also be bytes; in all other circumstances\n" |
1621 | | " the filenames returned will be str.\n" |
1622 | | "If path is None, uses the path=\'.\'.\n" |
1623 | | "On some platforms, path may also be specified as an open file descriptor;\\\n" |
1624 | | " the file descriptor must refer to a directory.\n" |
1625 | | " If this functionality is unavailable, using it raises NotImplementedError.\n" |
1626 | | "\n" |
1627 | | "The list is in arbitrary order. It does not include the special\n" |
1628 | | "entries \'.\' and \'..\' even if they are present in the directory."); |
1629 | | |
1630 | | #define OS_LISTDIR_METHODDEF \ |
1631 | | {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__}, |
1632 | | |
1633 | | static PyObject * |
1634 | | os_listdir_impl(PyObject *module, path_t *path); |
1635 | | |
1636 | | static PyObject * |
1637 | | os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1638 | 120 | { |
1639 | 120 | PyObject *return_value = NULL; |
1640 | 120 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1641 | | |
1642 | 120 | #define NUM_KEYWORDS 1 |
1643 | 120 | static struct { |
1644 | 120 | PyGC_Head _this_is_not_used; |
1645 | 120 | PyObject_VAR_HEAD |
1646 | 120 | Py_hash_t ob_hash; |
1647 | 120 | PyObject *ob_item[NUM_KEYWORDS]; |
1648 | 120 | } _kwtuple = { |
1649 | 120 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1650 | 120 | .ob_hash = -1, |
1651 | 120 | .ob_item = { &_Py_ID(path), }, |
1652 | 120 | }; |
1653 | 120 | #undef NUM_KEYWORDS |
1654 | 120 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1655 | | |
1656 | | #else // !Py_BUILD_CORE |
1657 | | # define KWTUPLE NULL |
1658 | | #endif // !Py_BUILD_CORE |
1659 | | |
1660 | 120 | static const char * const _keywords[] = {"path", NULL}; |
1661 | 120 | static _PyArg_Parser _parser = { |
1662 | 120 | .keywords = _keywords, |
1663 | 120 | .fname = "listdir", |
1664 | 120 | .kwtuple = KWTUPLE, |
1665 | 120 | }; |
1666 | 120 | #undef KWTUPLE |
1667 | 120 | PyObject *argsbuf[1]; |
1668 | 120 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1669 | 120 | path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
1670 | | |
1671 | 120 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1672 | 120 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1673 | 120 | if (!args) { |
1674 | 0 | goto exit; |
1675 | 0 | } |
1676 | 120 | if (!noptargs) { |
1677 | 0 | goto skip_optional_pos; |
1678 | 0 | } |
1679 | 120 | if (!path_converter(args[0], &path)) { |
1680 | 0 | goto exit; |
1681 | 0 | } |
1682 | 120 | skip_optional_pos: |
1683 | 120 | return_value = os_listdir_impl(module, &path); |
1684 | | |
1685 | 120 | exit: |
1686 | | /* Cleanup for path */ |
1687 | 120 | path_cleanup(&path); |
1688 | | |
1689 | 120 | return return_value; |
1690 | 120 | } |
1691 | | |
1692 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) |
1693 | | |
1694 | | PyDoc_STRVAR(os_listdrives__doc__, |
1695 | | "listdrives($module, /)\n" |
1696 | | "--\n" |
1697 | | "\n" |
1698 | | "Return a list containing the names of drives in the system.\n" |
1699 | | "\n" |
1700 | | "A drive name typically looks like \'C:\\\\\'."); |
1701 | | |
1702 | | #define OS_LISTDRIVES_METHODDEF \ |
1703 | | {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__}, |
1704 | | |
1705 | | static PyObject * |
1706 | | os_listdrives_impl(PyObject *module); |
1707 | | |
1708 | | static PyObject * |
1709 | | os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1710 | | { |
1711 | | return os_listdrives_impl(module); |
1712 | | } |
1713 | | |
1714 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ |
1715 | | |
1716 | | #if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
1717 | | |
1718 | | PyDoc_STRVAR(os_listvolumes__doc__, |
1719 | | "listvolumes($module, /)\n" |
1720 | | "--\n" |
1721 | | "\n" |
1722 | | "Return a list containing the volumes in the system.\n" |
1723 | | "\n" |
1724 | | "Volumes are typically represented as a GUID path."); |
1725 | | |
1726 | | #define OS_LISTVOLUMES_METHODDEF \ |
1727 | | {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__}, |
1728 | | |
1729 | | static PyObject * |
1730 | | os_listvolumes_impl(PyObject *module); |
1731 | | |
1732 | | static PyObject * |
1733 | | os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1734 | | { |
1735 | | return os_listvolumes_impl(module); |
1736 | | } |
1737 | | |
1738 | | #endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
1739 | | |
1740 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) |
1741 | | |
1742 | | PyDoc_STRVAR(os_listmounts__doc__, |
1743 | | "listmounts($module, /, volume)\n" |
1744 | | "--\n" |
1745 | | "\n" |
1746 | | "Return a list containing mount points for a particular volume.\n" |
1747 | | "\n" |
1748 | | "\'volume\' should be a GUID path as returned from os.listvolumes."); |
1749 | | |
1750 | | #define OS_LISTMOUNTS_METHODDEF \ |
1751 | | {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__}, |
1752 | | |
1753 | | static PyObject * |
1754 | | os_listmounts_impl(PyObject *module, path_t *volume); |
1755 | | |
1756 | | static PyObject * |
1757 | | os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1758 | | { |
1759 | | PyObject *return_value = NULL; |
1760 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1761 | | |
1762 | | #define NUM_KEYWORDS 1 |
1763 | | static struct { |
1764 | | PyGC_Head _this_is_not_used; |
1765 | | PyObject_VAR_HEAD |
1766 | | Py_hash_t ob_hash; |
1767 | | PyObject *ob_item[NUM_KEYWORDS]; |
1768 | | } _kwtuple = { |
1769 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1770 | | .ob_hash = -1, |
1771 | | .ob_item = { &_Py_ID(volume), }, |
1772 | | }; |
1773 | | #undef NUM_KEYWORDS |
1774 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1775 | | |
1776 | | #else // !Py_BUILD_CORE |
1777 | | # define KWTUPLE NULL |
1778 | | #endif // !Py_BUILD_CORE |
1779 | | |
1780 | | static const char * const _keywords[] = {"volume", NULL}; |
1781 | | static _PyArg_Parser _parser = { |
1782 | | .keywords = _keywords, |
1783 | | .fname = "listmounts", |
1784 | | .kwtuple = KWTUPLE, |
1785 | | }; |
1786 | | #undef KWTUPLE |
1787 | | PyObject *argsbuf[1]; |
1788 | | path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0); |
1789 | | |
1790 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1791 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1792 | | if (!args) { |
1793 | | goto exit; |
1794 | | } |
1795 | | if (!path_converter(args[0], &volume)) { |
1796 | | goto exit; |
1797 | | } |
1798 | | return_value = os_listmounts_impl(module, &volume); |
1799 | | |
1800 | | exit: |
1801 | | /* Cleanup for volume */ |
1802 | | path_cleanup(&volume); |
1803 | | |
1804 | | return return_value; |
1805 | | } |
1806 | | |
1807 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ |
1808 | | |
1809 | | #if defined(MS_WINDOWS) |
1810 | | |
1811 | | PyDoc_STRVAR(os__path_isdevdrive__doc__, |
1812 | | "_path_isdevdrive($module, /, path)\n" |
1813 | | "--\n" |
1814 | | "\n" |
1815 | | "Determines whether the specified path is on a Windows Dev Drive."); |
1816 | | |
1817 | | #define OS__PATH_ISDEVDRIVE_METHODDEF \ |
1818 | | {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__}, |
1819 | | |
1820 | | static PyObject * |
1821 | | os__path_isdevdrive_impl(PyObject *module, path_t *path); |
1822 | | |
1823 | | static PyObject * |
1824 | | os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1825 | | { |
1826 | | PyObject *return_value = NULL; |
1827 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1828 | | |
1829 | | #define NUM_KEYWORDS 1 |
1830 | | static struct { |
1831 | | PyGC_Head _this_is_not_used; |
1832 | | PyObject_VAR_HEAD |
1833 | | Py_hash_t ob_hash; |
1834 | | PyObject *ob_item[NUM_KEYWORDS]; |
1835 | | } _kwtuple = { |
1836 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1837 | | .ob_hash = -1, |
1838 | | .ob_item = { &_Py_ID(path), }, |
1839 | | }; |
1840 | | #undef NUM_KEYWORDS |
1841 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1842 | | |
1843 | | #else // !Py_BUILD_CORE |
1844 | | # define KWTUPLE NULL |
1845 | | #endif // !Py_BUILD_CORE |
1846 | | |
1847 | | static const char * const _keywords[] = {"path", NULL}; |
1848 | | static _PyArg_Parser _parser = { |
1849 | | .keywords = _keywords, |
1850 | | .fname = "_path_isdevdrive", |
1851 | | .kwtuple = KWTUPLE, |
1852 | | }; |
1853 | | #undef KWTUPLE |
1854 | | PyObject *argsbuf[1]; |
1855 | | path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0); |
1856 | | |
1857 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1858 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1859 | | if (!args) { |
1860 | | goto exit; |
1861 | | } |
1862 | | if (!path_converter(args[0], &path)) { |
1863 | | goto exit; |
1864 | | } |
1865 | | return_value = os__path_isdevdrive_impl(module, &path); |
1866 | | |
1867 | | exit: |
1868 | | /* Cleanup for path */ |
1869 | | path_cleanup(&path); |
1870 | | |
1871 | | return return_value; |
1872 | | } |
1873 | | |
1874 | | #endif /* defined(MS_WINDOWS) */ |
1875 | | |
1876 | | #if defined(MS_WINDOWS) |
1877 | | |
1878 | | PyDoc_STRVAR(os__getfullpathname__doc__, |
1879 | | "_getfullpathname($module, path, /)\n" |
1880 | | "--\n" |
1881 | | "\n"); |
1882 | | |
1883 | | #define OS__GETFULLPATHNAME_METHODDEF \ |
1884 | | {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__}, |
1885 | | |
1886 | | static PyObject * |
1887 | | os__getfullpathname_impl(PyObject *module, path_t *path); |
1888 | | |
1889 | | static PyObject * |
1890 | | os__getfullpathname(PyObject *module, PyObject *arg) |
1891 | | { |
1892 | | PyObject *return_value = NULL; |
1893 | | path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0); |
1894 | | |
1895 | | if (!path_converter(arg, &path)) { |
1896 | | goto exit; |
1897 | | } |
1898 | | return_value = os__getfullpathname_impl(module, &path); |
1899 | | |
1900 | | exit: |
1901 | | /* Cleanup for path */ |
1902 | | path_cleanup(&path); |
1903 | | |
1904 | | return return_value; |
1905 | | } |
1906 | | |
1907 | | #endif /* defined(MS_WINDOWS) */ |
1908 | | |
1909 | | #if defined(MS_WINDOWS) |
1910 | | |
1911 | | PyDoc_STRVAR(os__getfinalpathname__doc__, |
1912 | | "_getfinalpathname($module, path, /)\n" |
1913 | | "--\n" |
1914 | | "\n" |
1915 | | "A helper function for samepath on windows."); |
1916 | | |
1917 | | #define OS__GETFINALPATHNAME_METHODDEF \ |
1918 | | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
1919 | | |
1920 | | static PyObject * |
1921 | | os__getfinalpathname_impl(PyObject *module, path_t *path); |
1922 | | |
1923 | | static PyObject * |
1924 | | os__getfinalpathname(PyObject *module, PyObject *arg) |
1925 | | { |
1926 | | PyObject *return_value = NULL; |
1927 | | path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0); |
1928 | | |
1929 | | if (!path_converter(arg, &path)) { |
1930 | | goto exit; |
1931 | | } |
1932 | | return_value = os__getfinalpathname_impl(module, &path); |
1933 | | |
1934 | | exit: |
1935 | | /* Cleanup for path */ |
1936 | | path_cleanup(&path); |
1937 | | |
1938 | | return return_value; |
1939 | | } |
1940 | | |
1941 | | #endif /* defined(MS_WINDOWS) */ |
1942 | | |
1943 | | #if defined(MS_WINDOWS) |
1944 | | |
1945 | | PyDoc_STRVAR(os__findfirstfile__doc__, |
1946 | | "_findfirstfile($module, path, /)\n" |
1947 | | "--\n" |
1948 | | "\n" |
1949 | | "A function to get the real file name without accessing the file in Windows."); |
1950 | | |
1951 | | #define OS__FINDFIRSTFILE_METHODDEF \ |
1952 | | {"_findfirstfile", (PyCFunction)os__findfirstfile, METH_O, os__findfirstfile__doc__}, |
1953 | | |
1954 | | static PyObject * |
1955 | | os__findfirstfile_impl(PyObject *module, path_t *path); |
1956 | | |
1957 | | static PyObject * |
1958 | | os__findfirstfile(PyObject *module, PyObject *arg) |
1959 | | { |
1960 | | PyObject *return_value = NULL; |
1961 | | path_t path = PATH_T_INITIALIZE_P("_findfirstfile", "path", 0, 0, 0, 0); |
1962 | | |
1963 | | if (!path_converter(arg, &path)) { |
1964 | | goto exit; |
1965 | | } |
1966 | | return_value = os__findfirstfile_impl(module, &path); |
1967 | | |
1968 | | exit: |
1969 | | /* Cleanup for path */ |
1970 | | path_cleanup(&path); |
1971 | | |
1972 | | return return_value; |
1973 | | } |
1974 | | |
1975 | | #endif /* defined(MS_WINDOWS) */ |
1976 | | |
1977 | | #if defined(MS_WINDOWS) |
1978 | | |
1979 | | PyDoc_STRVAR(os__getvolumepathname__doc__, |
1980 | | "_getvolumepathname($module, /, path)\n" |
1981 | | "--\n" |
1982 | | "\n" |
1983 | | "A helper function for ismount on Win32."); |
1984 | | |
1985 | | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
1986 | | {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__}, |
1987 | | |
1988 | | static PyObject * |
1989 | | os__getvolumepathname_impl(PyObject *module, path_t *path); |
1990 | | |
1991 | | static PyObject * |
1992 | | os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1993 | | { |
1994 | | PyObject *return_value = NULL; |
1995 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1996 | | |
1997 | | #define NUM_KEYWORDS 1 |
1998 | | static struct { |
1999 | | PyGC_Head _this_is_not_used; |
2000 | | PyObject_VAR_HEAD |
2001 | | Py_hash_t ob_hash; |
2002 | | PyObject *ob_item[NUM_KEYWORDS]; |
2003 | | } _kwtuple = { |
2004 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2005 | | .ob_hash = -1, |
2006 | | .ob_item = { &_Py_ID(path), }, |
2007 | | }; |
2008 | | #undef NUM_KEYWORDS |
2009 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2010 | | |
2011 | | #else // !Py_BUILD_CORE |
2012 | | # define KWTUPLE NULL |
2013 | | #endif // !Py_BUILD_CORE |
2014 | | |
2015 | | static const char * const _keywords[] = {"path", NULL}; |
2016 | | static _PyArg_Parser _parser = { |
2017 | | .keywords = _keywords, |
2018 | | .fname = "_getvolumepathname", |
2019 | | .kwtuple = KWTUPLE, |
2020 | | }; |
2021 | | #undef KWTUPLE |
2022 | | PyObject *argsbuf[1]; |
2023 | | path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0); |
2024 | | |
2025 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2026 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2027 | | if (!args) { |
2028 | | goto exit; |
2029 | | } |
2030 | | if (!path_converter(args[0], &path)) { |
2031 | | goto exit; |
2032 | | } |
2033 | | return_value = os__getvolumepathname_impl(module, &path); |
2034 | | |
2035 | | exit: |
2036 | | /* Cleanup for path */ |
2037 | | path_cleanup(&path); |
2038 | | |
2039 | | return return_value; |
2040 | | } |
2041 | | |
2042 | | #endif /* defined(MS_WINDOWS) */ |
2043 | | |
2044 | | #if defined(MS_WINDOWS) |
2045 | | |
2046 | | PyDoc_STRVAR(os__path_splitroot__doc__, |
2047 | | "_path_splitroot($module, path, /)\n" |
2048 | | "--\n" |
2049 | | "\n" |
2050 | | "Removes everything after the root on Win32."); |
2051 | | |
2052 | | #define OS__PATH_SPLITROOT_METHODDEF \ |
2053 | | {"_path_splitroot", (PyCFunction)os__path_splitroot, METH_O, os__path_splitroot__doc__}, |
2054 | | |
2055 | | static PyObject * |
2056 | | os__path_splitroot_impl(PyObject *module, path_t *path); |
2057 | | |
2058 | | static PyObject * |
2059 | | os__path_splitroot(PyObject *module, PyObject *arg) |
2060 | | { |
2061 | | PyObject *return_value = NULL; |
2062 | | path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0); |
2063 | | |
2064 | | if (!path_converter(arg, &path)) { |
2065 | | goto exit; |
2066 | | } |
2067 | | return_value = os__path_splitroot_impl(module, &path); |
2068 | | |
2069 | | exit: |
2070 | | /* Cleanup for path */ |
2071 | | path_cleanup(&path); |
2072 | | |
2073 | | return return_value; |
2074 | | } |
2075 | | |
2076 | | #endif /* defined(MS_WINDOWS) */ |
2077 | | |
2078 | | #if defined(MS_WINDOWS) |
2079 | | |
2080 | | PyDoc_STRVAR(os__path_exists__doc__, |
2081 | | "_path_exists($module, /, path)\n" |
2082 | | "--\n" |
2083 | | "\n" |
2084 | | "Test whether a path exists. Returns False for broken symbolic links."); |
2085 | | |
2086 | | #define OS__PATH_EXISTS_METHODDEF \ |
2087 | | {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__}, |
2088 | | |
2089 | | static int |
2090 | | os__path_exists_impl(PyObject *module, path_t *path); |
2091 | | |
2092 | | static PyObject * |
2093 | | os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2094 | | { |
2095 | | PyObject *return_value = NULL; |
2096 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2097 | | |
2098 | | #define NUM_KEYWORDS 1 |
2099 | | static struct { |
2100 | | PyGC_Head _this_is_not_used; |
2101 | | PyObject_VAR_HEAD |
2102 | | Py_hash_t ob_hash; |
2103 | | PyObject *ob_item[NUM_KEYWORDS]; |
2104 | | } _kwtuple = { |
2105 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2106 | | .ob_hash = -1, |
2107 | | .ob_item = { &_Py_ID(path), }, |
2108 | | }; |
2109 | | #undef NUM_KEYWORDS |
2110 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2111 | | |
2112 | | #else // !Py_BUILD_CORE |
2113 | | # define KWTUPLE NULL |
2114 | | #endif // !Py_BUILD_CORE |
2115 | | |
2116 | | static const char * const _keywords[] = {"path", NULL}; |
2117 | | static _PyArg_Parser _parser = { |
2118 | | .keywords = _keywords, |
2119 | | .fname = "_path_exists", |
2120 | | .kwtuple = KWTUPLE, |
2121 | | }; |
2122 | | #undef KWTUPLE |
2123 | | PyObject *argsbuf[1]; |
2124 | | path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1); |
2125 | | int _return_value; |
2126 | | |
2127 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2128 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2129 | | if (!args) { |
2130 | | goto exit; |
2131 | | } |
2132 | | if (!path_converter(args[0], &path)) { |
2133 | | goto exit; |
2134 | | } |
2135 | | _return_value = os__path_exists_impl(module, &path); |
2136 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2137 | | goto exit; |
2138 | | } |
2139 | | return_value = PyBool_FromLong((long)_return_value); |
2140 | | |
2141 | | exit: |
2142 | | /* Cleanup for path */ |
2143 | | path_cleanup(&path); |
2144 | | |
2145 | | return return_value; |
2146 | | } |
2147 | | |
2148 | | #endif /* defined(MS_WINDOWS) */ |
2149 | | |
2150 | | #if defined(MS_WINDOWS) |
2151 | | |
2152 | | PyDoc_STRVAR(os__path_lexists__doc__, |
2153 | | "_path_lexists($module, /, path)\n" |
2154 | | "--\n" |
2155 | | "\n" |
2156 | | "Test whether a path exists. Returns True for broken symbolic links."); |
2157 | | |
2158 | | #define OS__PATH_LEXISTS_METHODDEF \ |
2159 | | {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__}, |
2160 | | |
2161 | | static int |
2162 | | os__path_lexists_impl(PyObject *module, path_t *path); |
2163 | | |
2164 | | static PyObject * |
2165 | | os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2166 | | { |
2167 | | PyObject *return_value = NULL; |
2168 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2169 | | |
2170 | | #define NUM_KEYWORDS 1 |
2171 | | static struct { |
2172 | | PyGC_Head _this_is_not_used; |
2173 | | PyObject_VAR_HEAD |
2174 | | Py_hash_t ob_hash; |
2175 | | PyObject *ob_item[NUM_KEYWORDS]; |
2176 | | } _kwtuple = { |
2177 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2178 | | .ob_hash = -1, |
2179 | | .ob_item = { &_Py_ID(path), }, |
2180 | | }; |
2181 | | #undef NUM_KEYWORDS |
2182 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2183 | | |
2184 | | #else // !Py_BUILD_CORE |
2185 | | # define KWTUPLE NULL |
2186 | | #endif // !Py_BUILD_CORE |
2187 | | |
2188 | | static const char * const _keywords[] = {"path", NULL}; |
2189 | | static _PyArg_Parser _parser = { |
2190 | | .keywords = _keywords, |
2191 | | .fname = "_path_lexists", |
2192 | | .kwtuple = KWTUPLE, |
2193 | | }; |
2194 | | #undef KWTUPLE |
2195 | | PyObject *argsbuf[1]; |
2196 | | path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1); |
2197 | | int _return_value; |
2198 | | |
2199 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2200 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2201 | | if (!args) { |
2202 | | goto exit; |
2203 | | } |
2204 | | if (!path_converter(args[0], &path)) { |
2205 | | goto exit; |
2206 | | } |
2207 | | _return_value = os__path_lexists_impl(module, &path); |
2208 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2209 | | goto exit; |
2210 | | } |
2211 | | return_value = PyBool_FromLong((long)_return_value); |
2212 | | |
2213 | | exit: |
2214 | | /* Cleanup for path */ |
2215 | | path_cleanup(&path); |
2216 | | |
2217 | | return return_value; |
2218 | | } |
2219 | | |
2220 | | #endif /* defined(MS_WINDOWS) */ |
2221 | | |
2222 | | #if defined(MS_WINDOWS) |
2223 | | |
2224 | | PyDoc_STRVAR(os__path_isdir__doc__, |
2225 | | "_path_isdir($module, path, /)\n" |
2226 | | "--\n" |
2227 | | "\n" |
2228 | | "Return true if the pathname refers to an existing directory."); |
2229 | | |
2230 | | #define OS__PATH_ISDIR_METHODDEF \ |
2231 | | {"_path_isdir", (PyCFunction)os__path_isdir, METH_O, os__path_isdir__doc__}, |
2232 | | |
2233 | | static int |
2234 | | os__path_isdir_impl(PyObject *module, path_t *path); |
2235 | | |
2236 | | static PyObject * |
2237 | | os__path_isdir(PyObject *module, PyObject *arg) |
2238 | | { |
2239 | | PyObject *return_value = NULL; |
2240 | | path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1); |
2241 | | int _return_value; |
2242 | | |
2243 | | if (!path_converter(arg, &path)) { |
2244 | | goto exit; |
2245 | | } |
2246 | | _return_value = os__path_isdir_impl(module, &path); |
2247 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2248 | | goto exit; |
2249 | | } |
2250 | | return_value = PyBool_FromLong((long)_return_value); |
2251 | | |
2252 | | exit: |
2253 | | /* Cleanup for path */ |
2254 | | path_cleanup(&path); |
2255 | | |
2256 | | return return_value; |
2257 | | } |
2258 | | |
2259 | | #endif /* defined(MS_WINDOWS) */ |
2260 | | |
2261 | | #if defined(MS_WINDOWS) |
2262 | | |
2263 | | PyDoc_STRVAR(os__path_isfile__doc__, |
2264 | | "_path_isfile($module, /, path)\n" |
2265 | | "--\n" |
2266 | | "\n" |
2267 | | "Test whether a path is a regular file"); |
2268 | | |
2269 | | #define OS__PATH_ISFILE_METHODDEF \ |
2270 | | {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__}, |
2271 | | |
2272 | | static int |
2273 | | os__path_isfile_impl(PyObject *module, path_t *path); |
2274 | | |
2275 | | static PyObject * |
2276 | | os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2277 | | { |
2278 | | PyObject *return_value = NULL; |
2279 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2280 | | |
2281 | | #define NUM_KEYWORDS 1 |
2282 | | static struct { |
2283 | | PyGC_Head _this_is_not_used; |
2284 | | PyObject_VAR_HEAD |
2285 | | Py_hash_t ob_hash; |
2286 | | PyObject *ob_item[NUM_KEYWORDS]; |
2287 | | } _kwtuple = { |
2288 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2289 | | .ob_hash = -1, |
2290 | | .ob_item = { &_Py_ID(path), }, |
2291 | | }; |
2292 | | #undef NUM_KEYWORDS |
2293 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2294 | | |
2295 | | #else // !Py_BUILD_CORE |
2296 | | # define KWTUPLE NULL |
2297 | | #endif // !Py_BUILD_CORE |
2298 | | |
2299 | | static const char * const _keywords[] = {"path", NULL}; |
2300 | | static _PyArg_Parser _parser = { |
2301 | | .keywords = _keywords, |
2302 | | .fname = "_path_isfile", |
2303 | | .kwtuple = KWTUPLE, |
2304 | | }; |
2305 | | #undef KWTUPLE |
2306 | | PyObject *argsbuf[1]; |
2307 | | path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1); |
2308 | | int _return_value; |
2309 | | |
2310 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2311 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2312 | | if (!args) { |
2313 | | goto exit; |
2314 | | } |
2315 | | if (!path_converter(args[0], &path)) { |
2316 | | goto exit; |
2317 | | } |
2318 | | _return_value = os__path_isfile_impl(module, &path); |
2319 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2320 | | goto exit; |
2321 | | } |
2322 | | return_value = PyBool_FromLong((long)_return_value); |
2323 | | |
2324 | | exit: |
2325 | | /* Cleanup for path */ |
2326 | | path_cleanup(&path); |
2327 | | |
2328 | | return return_value; |
2329 | | } |
2330 | | |
2331 | | #endif /* defined(MS_WINDOWS) */ |
2332 | | |
2333 | | #if defined(MS_WINDOWS) |
2334 | | |
2335 | | PyDoc_STRVAR(os__path_islink__doc__, |
2336 | | "_path_islink($module, /, path)\n" |
2337 | | "--\n" |
2338 | | "\n" |
2339 | | "Test whether a path is a symbolic link"); |
2340 | | |
2341 | | #define OS__PATH_ISLINK_METHODDEF \ |
2342 | | {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__}, |
2343 | | |
2344 | | static int |
2345 | | os__path_islink_impl(PyObject *module, path_t *path); |
2346 | | |
2347 | | static PyObject * |
2348 | | os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2349 | | { |
2350 | | PyObject *return_value = NULL; |
2351 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2352 | | |
2353 | | #define NUM_KEYWORDS 1 |
2354 | | static struct { |
2355 | | PyGC_Head _this_is_not_used; |
2356 | | PyObject_VAR_HEAD |
2357 | | Py_hash_t ob_hash; |
2358 | | PyObject *ob_item[NUM_KEYWORDS]; |
2359 | | } _kwtuple = { |
2360 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2361 | | .ob_hash = -1, |
2362 | | .ob_item = { &_Py_ID(path), }, |
2363 | | }; |
2364 | | #undef NUM_KEYWORDS |
2365 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2366 | | |
2367 | | #else // !Py_BUILD_CORE |
2368 | | # define KWTUPLE NULL |
2369 | | #endif // !Py_BUILD_CORE |
2370 | | |
2371 | | static const char * const _keywords[] = {"path", NULL}; |
2372 | | static _PyArg_Parser _parser = { |
2373 | | .keywords = _keywords, |
2374 | | .fname = "_path_islink", |
2375 | | .kwtuple = KWTUPLE, |
2376 | | }; |
2377 | | #undef KWTUPLE |
2378 | | PyObject *argsbuf[1]; |
2379 | | path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1); |
2380 | | int _return_value; |
2381 | | |
2382 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2383 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2384 | | if (!args) { |
2385 | | goto exit; |
2386 | | } |
2387 | | if (!path_converter(args[0], &path)) { |
2388 | | goto exit; |
2389 | | } |
2390 | | _return_value = os__path_islink_impl(module, &path); |
2391 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2392 | | goto exit; |
2393 | | } |
2394 | | return_value = PyBool_FromLong((long)_return_value); |
2395 | | |
2396 | | exit: |
2397 | | /* Cleanup for path */ |
2398 | | path_cleanup(&path); |
2399 | | |
2400 | | return return_value; |
2401 | | } |
2402 | | |
2403 | | #endif /* defined(MS_WINDOWS) */ |
2404 | | |
2405 | | #if defined(MS_WINDOWS) |
2406 | | |
2407 | | PyDoc_STRVAR(os__path_isjunction__doc__, |
2408 | | "_path_isjunction($module, /, path)\n" |
2409 | | "--\n" |
2410 | | "\n" |
2411 | | "Test whether a path is a junction"); |
2412 | | |
2413 | | #define OS__PATH_ISJUNCTION_METHODDEF \ |
2414 | | {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__}, |
2415 | | |
2416 | | static int |
2417 | | os__path_isjunction_impl(PyObject *module, path_t *path); |
2418 | | |
2419 | | static PyObject * |
2420 | | os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2421 | | { |
2422 | | PyObject *return_value = NULL; |
2423 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2424 | | |
2425 | | #define NUM_KEYWORDS 1 |
2426 | | static struct { |
2427 | | PyGC_Head _this_is_not_used; |
2428 | | PyObject_VAR_HEAD |
2429 | | Py_hash_t ob_hash; |
2430 | | PyObject *ob_item[NUM_KEYWORDS]; |
2431 | | } _kwtuple = { |
2432 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2433 | | .ob_hash = -1, |
2434 | | .ob_item = { &_Py_ID(path), }, |
2435 | | }; |
2436 | | #undef NUM_KEYWORDS |
2437 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2438 | | |
2439 | | #else // !Py_BUILD_CORE |
2440 | | # define KWTUPLE NULL |
2441 | | #endif // !Py_BUILD_CORE |
2442 | | |
2443 | | static const char * const _keywords[] = {"path", NULL}; |
2444 | | static _PyArg_Parser _parser = { |
2445 | | .keywords = _keywords, |
2446 | | .fname = "_path_isjunction", |
2447 | | .kwtuple = KWTUPLE, |
2448 | | }; |
2449 | | #undef KWTUPLE |
2450 | | PyObject *argsbuf[1]; |
2451 | | path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1); |
2452 | | int _return_value; |
2453 | | |
2454 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2455 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2456 | | if (!args) { |
2457 | | goto exit; |
2458 | | } |
2459 | | if (!path_converter(args[0], &path)) { |
2460 | | goto exit; |
2461 | | } |
2462 | | _return_value = os__path_isjunction_impl(module, &path); |
2463 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2464 | | goto exit; |
2465 | | } |
2466 | | return_value = PyBool_FromLong((long)_return_value); |
2467 | | |
2468 | | exit: |
2469 | | /* Cleanup for path */ |
2470 | | path_cleanup(&path); |
2471 | | |
2472 | | return return_value; |
2473 | | } |
2474 | | |
2475 | | #endif /* defined(MS_WINDOWS) */ |
2476 | | |
2477 | | PyDoc_STRVAR(os__path_splitroot_ex__doc__, |
2478 | | "_path_splitroot_ex($module, path, /)\n" |
2479 | | "--\n" |
2480 | | "\n" |
2481 | | "Split a pathname into drive, root and tail.\n" |
2482 | | "\n" |
2483 | | "The tail contains anything after the root."); |
2484 | | |
2485 | | #define OS__PATH_SPLITROOT_EX_METHODDEF \ |
2486 | | {"_path_splitroot_ex", (PyCFunction)os__path_splitroot_ex, METH_O, os__path_splitroot_ex__doc__}, |
2487 | | |
2488 | | static PyObject * |
2489 | | os__path_splitroot_ex_impl(PyObject *module, path_t *path); |
2490 | | |
2491 | | static PyObject * |
2492 | | os__path_splitroot_ex(PyObject *module, PyObject *arg) |
2493 | 0 | { |
2494 | 0 | PyObject *return_value = NULL; |
2495 | 0 | path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0); |
2496 | |
|
2497 | 0 | if (!path_converter(arg, &path)) { |
2498 | 0 | goto exit; |
2499 | 0 | } |
2500 | 0 | return_value = os__path_splitroot_ex_impl(module, &path); |
2501 | |
|
2502 | 0 | exit: |
2503 | | /* Cleanup for path */ |
2504 | 0 | path_cleanup(&path); |
2505 | |
|
2506 | 0 | return return_value; |
2507 | 0 | } |
2508 | | |
2509 | | PyDoc_STRVAR(os__path_normpath__doc__, |
2510 | | "_path_normpath($module, /, path)\n" |
2511 | | "--\n" |
2512 | | "\n" |
2513 | | "Normalize path, eliminating double slashes, etc."); |
2514 | | |
2515 | | #define OS__PATH_NORMPATH_METHODDEF \ |
2516 | | {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__}, |
2517 | | |
2518 | | static PyObject * |
2519 | | os__path_normpath_impl(PyObject *module, path_t *path); |
2520 | | |
2521 | | static PyObject * |
2522 | | os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2523 | 80 | { |
2524 | 80 | PyObject *return_value = NULL; |
2525 | 80 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2526 | | |
2527 | 80 | #define NUM_KEYWORDS 1 |
2528 | 80 | static struct { |
2529 | 80 | PyGC_Head _this_is_not_used; |
2530 | 80 | PyObject_VAR_HEAD |
2531 | 80 | Py_hash_t ob_hash; |
2532 | 80 | PyObject *ob_item[NUM_KEYWORDS]; |
2533 | 80 | } _kwtuple = { |
2534 | 80 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2535 | 80 | .ob_hash = -1, |
2536 | 80 | .ob_item = { &_Py_ID(path), }, |
2537 | 80 | }; |
2538 | 80 | #undef NUM_KEYWORDS |
2539 | 80 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2540 | | |
2541 | | #else // !Py_BUILD_CORE |
2542 | | # define KWTUPLE NULL |
2543 | | #endif // !Py_BUILD_CORE |
2544 | | |
2545 | 80 | static const char * const _keywords[] = {"path", NULL}; |
2546 | 80 | static _PyArg_Parser _parser = { |
2547 | 80 | .keywords = _keywords, |
2548 | 80 | .fname = "_path_normpath", |
2549 | 80 | .kwtuple = KWTUPLE, |
2550 | 80 | }; |
2551 | 80 | #undef KWTUPLE |
2552 | 80 | PyObject *argsbuf[1]; |
2553 | 80 | path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0); |
2554 | | |
2555 | 80 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2556 | 80 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2557 | 80 | if (!args) { |
2558 | 0 | goto exit; |
2559 | 0 | } |
2560 | 80 | if (!path_converter(args[0], &path)) { |
2561 | 0 | goto exit; |
2562 | 0 | } |
2563 | 80 | return_value = os__path_normpath_impl(module, &path); |
2564 | | |
2565 | 80 | exit: |
2566 | | /* Cleanup for path */ |
2567 | 80 | path_cleanup(&path); |
2568 | | |
2569 | 80 | return return_value; |
2570 | 80 | } |
2571 | | |
2572 | | PyDoc_STRVAR(os_mkdir__doc__, |
2573 | | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
2574 | | "--\n" |
2575 | | "\n" |
2576 | | "Create a directory.\n" |
2577 | | "\n" |
2578 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
2579 | | " and path should be relative; path will then be relative to that directory.\n" |
2580 | | "dir_fd may not be implemented on your platform.\n" |
2581 | | " If it is unavailable, using it will raise a NotImplementedError.\n" |
2582 | | "\n" |
2583 | | "The mode argument is ignored on Windows. Where it is used, the current umask\n" |
2584 | | "value is first masked out."); |
2585 | | |
2586 | | #define OS_MKDIR_METHODDEF \ |
2587 | | {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__}, |
2588 | | |
2589 | | static PyObject * |
2590 | | os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
2591 | | |
2592 | | static PyObject * |
2593 | | os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2594 | 0 | { |
2595 | 0 | PyObject *return_value = NULL; |
2596 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2597 | |
|
2598 | 0 | #define NUM_KEYWORDS 3 |
2599 | 0 | static struct { |
2600 | 0 | PyGC_Head _this_is_not_used; |
2601 | 0 | PyObject_VAR_HEAD |
2602 | 0 | Py_hash_t ob_hash; |
2603 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2604 | 0 | } _kwtuple = { |
2605 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2606 | 0 | .ob_hash = -1, |
2607 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
2608 | 0 | }; |
2609 | 0 | #undef NUM_KEYWORDS |
2610 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2611 | |
|
2612 | | #else // !Py_BUILD_CORE |
2613 | | # define KWTUPLE NULL |
2614 | | #endif // !Py_BUILD_CORE |
2615 | |
|
2616 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
2617 | 0 | static _PyArg_Parser _parser = { |
2618 | 0 | .keywords = _keywords, |
2619 | 0 | .fname = "mkdir", |
2620 | 0 | .kwtuple = KWTUPLE, |
2621 | 0 | }; |
2622 | 0 | #undef KWTUPLE |
2623 | 0 | PyObject *argsbuf[3]; |
2624 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
2625 | 0 | path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0); |
2626 | 0 | int mode = 511; |
2627 | 0 | int dir_fd = DEFAULT_DIR_FD; |
2628 | |
|
2629 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2630 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2631 | 0 | if (!args) { |
2632 | 0 | goto exit; |
2633 | 0 | } |
2634 | 0 | if (!path_converter(args[0], &path)) { |
2635 | 0 | goto exit; |
2636 | 0 | } |
2637 | 0 | if (!noptargs) { |
2638 | 0 | goto skip_optional_pos; |
2639 | 0 | } |
2640 | 0 | if (args[1]) { |
2641 | 0 | mode = PyLong_AsInt(args[1]); |
2642 | 0 | if (mode == -1 && PyErr_Occurred()) { |
2643 | 0 | goto exit; |
2644 | 0 | } |
2645 | 0 | if (!--noptargs) { |
2646 | 0 | goto skip_optional_pos; |
2647 | 0 | } |
2648 | 0 | } |
2649 | 0 | skip_optional_pos: |
2650 | 0 | if (!noptargs) { |
2651 | 0 | goto skip_optional_kwonly; |
2652 | 0 | } |
2653 | 0 | if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
2654 | 0 | goto exit; |
2655 | 0 | } |
2656 | 0 | skip_optional_kwonly: |
2657 | 0 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
2658 | |
|
2659 | 0 | exit: |
2660 | | /* Cleanup for path */ |
2661 | 0 | path_cleanup(&path); |
2662 | |
|
2663 | 0 | return return_value; |
2664 | 0 | } |
2665 | | |
2666 | | #if defined(HAVE_NICE) |
2667 | | |
2668 | | PyDoc_STRVAR(os_nice__doc__, |
2669 | | "nice($module, increment, /)\n" |
2670 | | "--\n" |
2671 | | "\n" |
2672 | | "Add increment to the priority of process and return the new priority."); |
2673 | | |
2674 | | #define OS_NICE_METHODDEF \ |
2675 | | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
2676 | | |
2677 | | static PyObject * |
2678 | | os_nice_impl(PyObject *module, int increment); |
2679 | | |
2680 | | static PyObject * |
2681 | | os_nice(PyObject *module, PyObject *arg) |
2682 | 0 | { |
2683 | 0 | PyObject *return_value = NULL; |
2684 | 0 | int increment; |
2685 | |
|
2686 | 0 | increment = PyLong_AsInt(arg); |
2687 | 0 | if (increment == -1 && PyErr_Occurred()) { |
2688 | 0 | goto exit; |
2689 | 0 | } |
2690 | 0 | return_value = os_nice_impl(module, increment); |
2691 | |
|
2692 | 0 | exit: |
2693 | 0 | return return_value; |
2694 | 0 | } |
2695 | | |
2696 | | #endif /* defined(HAVE_NICE) */ |
2697 | | |
2698 | | #if defined(HAVE_GETPRIORITY) |
2699 | | |
2700 | | PyDoc_STRVAR(os_getpriority__doc__, |
2701 | | "getpriority($module, /, which, who)\n" |
2702 | | "--\n" |
2703 | | "\n" |
2704 | | "Return program scheduling priority."); |
2705 | | |
2706 | | #define OS_GETPRIORITY_METHODDEF \ |
2707 | | {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__}, |
2708 | | |
2709 | | static PyObject * |
2710 | | os_getpriority_impl(PyObject *module, int which, int who); |
2711 | | |
2712 | | static PyObject * |
2713 | | os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2714 | 0 | { |
2715 | 0 | PyObject *return_value = NULL; |
2716 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2717 | |
|
2718 | 0 | #define NUM_KEYWORDS 2 |
2719 | 0 | static struct { |
2720 | 0 | PyGC_Head _this_is_not_used; |
2721 | 0 | PyObject_VAR_HEAD |
2722 | 0 | Py_hash_t ob_hash; |
2723 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2724 | 0 | } _kwtuple = { |
2725 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2726 | 0 | .ob_hash = -1, |
2727 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), }, |
2728 | 0 | }; |
2729 | 0 | #undef NUM_KEYWORDS |
2730 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2731 | |
|
2732 | | #else // !Py_BUILD_CORE |
2733 | | # define KWTUPLE NULL |
2734 | | #endif // !Py_BUILD_CORE |
2735 | |
|
2736 | 0 | static const char * const _keywords[] = {"which", "who", NULL}; |
2737 | 0 | static _PyArg_Parser _parser = { |
2738 | 0 | .keywords = _keywords, |
2739 | 0 | .fname = "getpriority", |
2740 | 0 | .kwtuple = KWTUPLE, |
2741 | 0 | }; |
2742 | 0 | #undef KWTUPLE |
2743 | 0 | PyObject *argsbuf[2]; |
2744 | 0 | int which; |
2745 | 0 | int who; |
2746 | |
|
2747 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2748 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2749 | 0 | if (!args) { |
2750 | 0 | goto exit; |
2751 | 0 | } |
2752 | 0 | which = PyLong_AsInt(args[0]); |
2753 | 0 | if (which == -1 && PyErr_Occurred()) { |
2754 | 0 | goto exit; |
2755 | 0 | } |
2756 | 0 | who = PyLong_AsInt(args[1]); |
2757 | 0 | if (who == -1 && PyErr_Occurred()) { |
2758 | 0 | goto exit; |
2759 | 0 | } |
2760 | 0 | return_value = os_getpriority_impl(module, which, who); |
2761 | |
|
2762 | 0 | exit: |
2763 | 0 | return return_value; |
2764 | 0 | } |
2765 | | |
2766 | | #endif /* defined(HAVE_GETPRIORITY) */ |
2767 | | |
2768 | | #if defined(HAVE_SETPRIORITY) |
2769 | | |
2770 | | PyDoc_STRVAR(os_setpriority__doc__, |
2771 | | "setpriority($module, /, which, who, priority)\n" |
2772 | | "--\n" |
2773 | | "\n" |
2774 | | "Set program scheduling priority."); |
2775 | | |
2776 | | #define OS_SETPRIORITY_METHODDEF \ |
2777 | | {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__}, |
2778 | | |
2779 | | static PyObject * |
2780 | | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
2781 | | |
2782 | | static PyObject * |
2783 | | os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2784 | 0 | { |
2785 | 0 | PyObject *return_value = NULL; |
2786 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2787 | |
|
2788 | 0 | #define NUM_KEYWORDS 3 |
2789 | 0 | static struct { |
2790 | 0 | PyGC_Head _this_is_not_used; |
2791 | 0 | PyObject_VAR_HEAD |
2792 | 0 | Py_hash_t ob_hash; |
2793 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2794 | 0 | } _kwtuple = { |
2795 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2796 | 0 | .ob_hash = -1, |
2797 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), }, |
2798 | 0 | }; |
2799 | 0 | #undef NUM_KEYWORDS |
2800 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2801 | |
|
2802 | | #else // !Py_BUILD_CORE |
2803 | | # define KWTUPLE NULL |
2804 | | #endif // !Py_BUILD_CORE |
2805 | |
|
2806 | 0 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
2807 | 0 | static _PyArg_Parser _parser = { |
2808 | 0 | .keywords = _keywords, |
2809 | 0 | .fname = "setpriority", |
2810 | 0 | .kwtuple = KWTUPLE, |
2811 | 0 | }; |
2812 | 0 | #undef KWTUPLE |
2813 | 0 | PyObject *argsbuf[3]; |
2814 | 0 | int which; |
2815 | 0 | int who; |
2816 | 0 | int priority; |
2817 | |
|
2818 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2819 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2820 | 0 | if (!args) { |
2821 | 0 | goto exit; |
2822 | 0 | } |
2823 | 0 | which = PyLong_AsInt(args[0]); |
2824 | 0 | if (which == -1 && PyErr_Occurred()) { |
2825 | 0 | goto exit; |
2826 | 0 | } |
2827 | 0 | who = PyLong_AsInt(args[1]); |
2828 | 0 | if (who == -1 && PyErr_Occurred()) { |
2829 | 0 | goto exit; |
2830 | 0 | } |
2831 | 0 | priority = PyLong_AsInt(args[2]); |
2832 | 0 | if (priority == -1 && PyErr_Occurred()) { |
2833 | 0 | goto exit; |
2834 | 0 | } |
2835 | 0 | return_value = os_setpriority_impl(module, which, who, priority); |
2836 | |
|
2837 | 0 | exit: |
2838 | 0 | return return_value; |
2839 | 0 | } |
2840 | | |
2841 | | #endif /* defined(HAVE_SETPRIORITY) */ |
2842 | | |
2843 | | PyDoc_STRVAR(os_rename__doc__, |
2844 | | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
2845 | | "--\n" |
2846 | | "\n" |
2847 | | "Rename a file or directory.\n" |
2848 | | "\n" |
2849 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
2850 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
2851 | | " should be relative; the path will then be relative to that directory.\n" |
2852 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
2853 | | " If they are unavailable, using them will raise a NotImplementedError."); |
2854 | | |
2855 | | #define OS_RENAME_METHODDEF \ |
2856 | | {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__}, |
2857 | | |
2858 | | static PyObject * |
2859 | | os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
2860 | | int dst_dir_fd); |
2861 | | |
2862 | | static PyObject * |
2863 | | os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2864 | 0 | { |
2865 | 0 | PyObject *return_value = NULL; |
2866 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2867 | |
|
2868 | 0 | #define NUM_KEYWORDS 4 |
2869 | 0 | static struct { |
2870 | 0 | PyGC_Head _this_is_not_used; |
2871 | 0 | PyObject_VAR_HEAD |
2872 | 0 | Py_hash_t ob_hash; |
2873 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2874 | 0 | } _kwtuple = { |
2875 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2876 | 0 | .ob_hash = -1, |
2877 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
2878 | 0 | }; |
2879 | 0 | #undef NUM_KEYWORDS |
2880 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2881 | |
|
2882 | | #else // !Py_BUILD_CORE |
2883 | | # define KWTUPLE NULL |
2884 | | #endif // !Py_BUILD_CORE |
2885 | |
|
2886 | 0 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
2887 | 0 | static _PyArg_Parser _parser = { |
2888 | 0 | .keywords = _keywords, |
2889 | 0 | .fname = "rename", |
2890 | 0 | .kwtuple = KWTUPLE, |
2891 | 0 | }; |
2892 | 0 | #undef KWTUPLE |
2893 | 0 | PyObject *argsbuf[4]; |
2894 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
2895 | 0 | path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0); |
2896 | 0 | path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0); |
2897 | 0 | int src_dir_fd = DEFAULT_DIR_FD; |
2898 | 0 | int dst_dir_fd = DEFAULT_DIR_FD; |
2899 | |
|
2900 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2901 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2902 | 0 | if (!args) { |
2903 | 0 | goto exit; |
2904 | 0 | } |
2905 | 0 | if (!path_converter(args[0], &src)) { |
2906 | 0 | goto exit; |
2907 | 0 | } |
2908 | 0 | if (!path_converter(args[1], &dst)) { |
2909 | 0 | goto exit; |
2910 | 0 | } |
2911 | 0 | if (!noptargs) { |
2912 | 0 | goto skip_optional_kwonly; |
2913 | 0 | } |
2914 | 0 | if (args[2]) { |
2915 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
2916 | 0 | goto exit; |
2917 | 0 | } |
2918 | 0 | if (!--noptargs) { |
2919 | 0 | goto skip_optional_kwonly; |
2920 | 0 | } |
2921 | 0 | } |
2922 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
2923 | 0 | goto exit; |
2924 | 0 | } |
2925 | 0 | skip_optional_kwonly: |
2926 | 0 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
2927 | |
|
2928 | 0 | exit: |
2929 | | /* Cleanup for src */ |
2930 | 0 | path_cleanup(&src); |
2931 | | /* Cleanup for dst */ |
2932 | 0 | path_cleanup(&dst); |
2933 | |
|
2934 | 0 | return return_value; |
2935 | 0 | } |
2936 | | |
2937 | | PyDoc_STRVAR(os_replace__doc__, |
2938 | | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
2939 | | "--\n" |
2940 | | "\n" |
2941 | | "Rename a file or directory, overwriting the destination.\n" |
2942 | | "\n" |
2943 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
2944 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
2945 | | " should be relative; the path will then be relative to that directory.\n" |
2946 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
2947 | | " If they are unavailable, using them will raise a NotImplementedError."); |
2948 | | |
2949 | | #define OS_REPLACE_METHODDEF \ |
2950 | | {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__}, |
2951 | | |
2952 | | static PyObject * |
2953 | | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
2954 | | int dst_dir_fd); |
2955 | | |
2956 | | static PyObject * |
2957 | | os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2958 | 236 | { |
2959 | 236 | PyObject *return_value = NULL; |
2960 | 236 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2961 | | |
2962 | 236 | #define NUM_KEYWORDS 4 |
2963 | 236 | static struct { |
2964 | 236 | PyGC_Head _this_is_not_used; |
2965 | 236 | PyObject_VAR_HEAD |
2966 | 236 | Py_hash_t ob_hash; |
2967 | 236 | PyObject *ob_item[NUM_KEYWORDS]; |
2968 | 236 | } _kwtuple = { |
2969 | 236 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2970 | 236 | .ob_hash = -1, |
2971 | 236 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
2972 | 236 | }; |
2973 | 236 | #undef NUM_KEYWORDS |
2974 | 236 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2975 | | |
2976 | | #else // !Py_BUILD_CORE |
2977 | | # define KWTUPLE NULL |
2978 | | #endif // !Py_BUILD_CORE |
2979 | | |
2980 | 236 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
2981 | 236 | static _PyArg_Parser _parser = { |
2982 | 236 | .keywords = _keywords, |
2983 | 236 | .fname = "replace", |
2984 | 236 | .kwtuple = KWTUPLE, |
2985 | 236 | }; |
2986 | 236 | #undef KWTUPLE |
2987 | 236 | PyObject *argsbuf[4]; |
2988 | 236 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
2989 | 236 | path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0); |
2990 | 236 | path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0); |
2991 | 236 | int src_dir_fd = DEFAULT_DIR_FD; |
2992 | 236 | int dst_dir_fd = DEFAULT_DIR_FD; |
2993 | | |
2994 | 236 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2995 | 236 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2996 | 236 | if (!args) { |
2997 | 0 | goto exit; |
2998 | 0 | } |
2999 | 236 | if (!path_converter(args[0], &src)) { |
3000 | 0 | goto exit; |
3001 | 0 | } |
3002 | 236 | if (!path_converter(args[1], &dst)) { |
3003 | 0 | goto exit; |
3004 | 0 | } |
3005 | 236 | if (!noptargs) { |
3006 | 236 | goto skip_optional_kwonly; |
3007 | 236 | } |
3008 | 0 | if (args[2]) { |
3009 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
3010 | 0 | goto exit; |
3011 | 0 | } |
3012 | 0 | if (!--noptargs) { |
3013 | 0 | goto skip_optional_kwonly; |
3014 | 0 | } |
3015 | 0 | } |
3016 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
3017 | 0 | goto exit; |
3018 | 0 | } |
3019 | 236 | skip_optional_kwonly: |
3020 | 236 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
3021 | | |
3022 | 236 | exit: |
3023 | | /* Cleanup for src */ |
3024 | 236 | path_cleanup(&src); |
3025 | | /* Cleanup for dst */ |
3026 | 236 | path_cleanup(&dst); |
3027 | | |
3028 | 236 | return return_value; |
3029 | 236 | } |
3030 | | |
3031 | | PyDoc_STRVAR(os_rmdir__doc__, |
3032 | | "rmdir($module, /, path, *, dir_fd=None)\n" |
3033 | | "--\n" |
3034 | | "\n" |
3035 | | "Remove a directory.\n" |
3036 | | "\n" |
3037 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3038 | | " and path should be relative; path will then be relative to that directory.\n" |
3039 | | "dir_fd may not be implemented on your platform.\n" |
3040 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3041 | | |
3042 | | #define OS_RMDIR_METHODDEF \ |
3043 | | {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__}, |
3044 | | |
3045 | | static PyObject * |
3046 | | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
3047 | | |
3048 | | static PyObject * |
3049 | | os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3050 | 0 | { |
3051 | 0 | PyObject *return_value = NULL; |
3052 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3053 | |
|
3054 | 0 | #define NUM_KEYWORDS 2 |
3055 | 0 | static struct { |
3056 | 0 | PyGC_Head _this_is_not_used; |
3057 | 0 | PyObject_VAR_HEAD |
3058 | 0 | Py_hash_t ob_hash; |
3059 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3060 | 0 | } _kwtuple = { |
3061 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3062 | 0 | .ob_hash = -1, |
3063 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3064 | 0 | }; |
3065 | 0 | #undef NUM_KEYWORDS |
3066 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3067 | |
|
3068 | | #else // !Py_BUILD_CORE |
3069 | | # define KWTUPLE NULL |
3070 | | #endif // !Py_BUILD_CORE |
3071 | |
|
3072 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3073 | 0 | static _PyArg_Parser _parser = { |
3074 | 0 | .keywords = _keywords, |
3075 | 0 | .fname = "rmdir", |
3076 | 0 | .kwtuple = KWTUPLE, |
3077 | 0 | }; |
3078 | 0 | #undef KWTUPLE |
3079 | 0 | PyObject *argsbuf[2]; |
3080 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3081 | 0 | path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0); |
3082 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3083 | |
|
3084 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3085 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3086 | 0 | if (!args) { |
3087 | 0 | goto exit; |
3088 | 0 | } |
3089 | 0 | if (!path_converter(args[0], &path)) { |
3090 | 0 | goto exit; |
3091 | 0 | } |
3092 | 0 | if (!noptargs) { |
3093 | 0 | goto skip_optional_kwonly; |
3094 | 0 | } |
3095 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3096 | 0 | goto exit; |
3097 | 0 | } |
3098 | 0 | skip_optional_kwonly: |
3099 | 0 | return_value = os_rmdir_impl(module, &path, dir_fd); |
3100 | |
|
3101 | 0 | exit: |
3102 | | /* Cleanup for path */ |
3103 | 0 | path_cleanup(&path); |
3104 | |
|
3105 | 0 | return return_value; |
3106 | 0 | } |
3107 | | |
3108 | | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
3109 | | |
3110 | | PyDoc_STRVAR(os_system__doc__, |
3111 | | "system($module, /, command)\n" |
3112 | | "--\n" |
3113 | | "\n" |
3114 | | "Execute the command in a subshell."); |
3115 | | |
3116 | | #define OS_SYSTEM_METHODDEF \ |
3117 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3118 | | |
3119 | | static long |
3120 | | os_system_impl(PyObject *module, const wchar_t *command); |
3121 | | |
3122 | | static PyObject * |
3123 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3124 | | { |
3125 | | PyObject *return_value = NULL; |
3126 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3127 | | |
3128 | | #define NUM_KEYWORDS 1 |
3129 | | static struct { |
3130 | | PyGC_Head _this_is_not_used; |
3131 | | PyObject_VAR_HEAD |
3132 | | Py_hash_t ob_hash; |
3133 | | PyObject *ob_item[NUM_KEYWORDS]; |
3134 | | } _kwtuple = { |
3135 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3136 | | .ob_hash = -1, |
3137 | | .ob_item = { &_Py_ID(command), }, |
3138 | | }; |
3139 | | #undef NUM_KEYWORDS |
3140 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3141 | | |
3142 | | #else // !Py_BUILD_CORE |
3143 | | # define KWTUPLE NULL |
3144 | | #endif // !Py_BUILD_CORE |
3145 | | |
3146 | | static const char * const _keywords[] = {"command", NULL}; |
3147 | | static _PyArg_Parser _parser = { |
3148 | | .keywords = _keywords, |
3149 | | .fname = "system", |
3150 | | .kwtuple = KWTUPLE, |
3151 | | }; |
3152 | | #undef KWTUPLE |
3153 | | PyObject *argsbuf[1]; |
3154 | | const wchar_t *command = NULL; |
3155 | | long _return_value; |
3156 | | |
3157 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3158 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3159 | | if (!args) { |
3160 | | goto exit; |
3161 | | } |
3162 | | if (!PyUnicode_Check(args[0])) { |
3163 | | _PyArg_BadArgument("system", "argument 'command'", "str", args[0]); |
3164 | | goto exit; |
3165 | | } |
3166 | | command = PyUnicode_AsWideCharString(args[0], NULL); |
3167 | | if (command == NULL) { |
3168 | | goto exit; |
3169 | | } |
3170 | | _return_value = os_system_impl(module, command); |
3171 | | if ((_return_value == -1) && PyErr_Occurred()) { |
3172 | | goto exit; |
3173 | | } |
3174 | | return_value = PyLong_FromLong(_return_value); |
3175 | | |
3176 | | exit: |
3177 | | /* Cleanup for command */ |
3178 | | PyMem_Free((void *)command); |
3179 | | |
3180 | | return return_value; |
3181 | | } |
3182 | | |
3183 | | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
3184 | | |
3185 | | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
3186 | | |
3187 | | PyDoc_STRVAR(os_system__doc__, |
3188 | | "system($module, /, command)\n" |
3189 | | "--\n" |
3190 | | "\n" |
3191 | | "Execute the command in a subshell."); |
3192 | | |
3193 | | #define OS_SYSTEM_METHODDEF \ |
3194 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3195 | | |
3196 | | static long |
3197 | | os_system_impl(PyObject *module, PyObject *command); |
3198 | | |
3199 | | static PyObject * |
3200 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3201 | 0 | { |
3202 | 0 | PyObject *return_value = NULL; |
3203 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3204 | |
|
3205 | 0 | #define NUM_KEYWORDS 1 |
3206 | 0 | static struct { |
3207 | 0 | PyGC_Head _this_is_not_used; |
3208 | 0 | PyObject_VAR_HEAD |
3209 | 0 | Py_hash_t ob_hash; |
3210 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3211 | 0 | } _kwtuple = { |
3212 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3213 | 0 | .ob_hash = -1, |
3214 | 0 | .ob_item = { &_Py_ID(command), }, |
3215 | 0 | }; |
3216 | 0 | #undef NUM_KEYWORDS |
3217 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3218 | |
|
3219 | | #else // !Py_BUILD_CORE |
3220 | | # define KWTUPLE NULL |
3221 | | #endif // !Py_BUILD_CORE |
3222 | |
|
3223 | 0 | static const char * const _keywords[] = {"command", NULL}; |
3224 | 0 | static _PyArg_Parser _parser = { |
3225 | 0 | .keywords = _keywords, |
3226 | 0 | .fname = "system", |
3227 | 0 | .kwtuple = KWTUPLE, |
3228 | 0 | }; |
3229 | 0 | #undef KWTUPLE |
3230 | 0 | PyObject *argsbuf[1]; |
3231 | 0 | PyObject *command = NULL; |
3232 | 0 | long _return_value; |
3233 | |
|
3234 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3235 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3236 | 0 | if (!args) { |
3237 | 0 | goto exit; |
3238 | 0 | } |
3239 | 0 | if (!PyUnicode_FSConverter(args[0], &command)) { |
3240 | 0 | goto exit; |
3241 | 0 | } |
3242 | 0 | _return_value = os_system_impl(module, command); |
3243 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
3244 | 0 | goto exit; |
3245 | 0 | } |
3246 | 0 | return_value = PyLong_FromLong(_return_value); |
3247 | |
|
3248 | 0 | exit: |
3249 | | /* Cleanup for command */ |
3250 | 0 | Py_XDECREF(command); |
3251 | |
|
3252 | 0 | return return_value; |
3253 | 0 | } |
3254 | | |
3255 | | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
3256 | | |
3257 | | #if defined(HAVE_UMASK) |
3258 | | |
3259 | | PyDoc_STRVAR(os_umask__doc__, |
3260 | | "umask($module, mask, /)\n" |
3261 | | "--\n" |
3262 | | "\n" |
3263 | | "Set the current numeric umask and return the previous umask."); |
3264 | | |
3265 | | #define OS_UMASK_METHODDEF \ |
3266 | | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
3267 | | |
3268 | | static PyObject * |
3269 | | os_umask_impl(PyObject *module, int mask); |
3270 | | |
3271 | | static PyObject * |
3272 | | os_umask(PyObject *module, PyObject *arg) |
3273 | 0 | { |
3274 | 0 | PyObject *return_value = NULL; |
3275 | 0 | int mask; |
3276 | |
|
3277 | 0 | mask = PyLong_AsInt(arg); |
3278 | 0 | if (mask == -1 && PyErr_Occurred()) { |
3279 | 0 | goto exit; |
3280 | 0 | } |
3281 | 0 | return_value = os_umask_impl(module, mask); |
3282 | |
|
3283 | 0 | exit: |
3284 | 0 | return return_value; |
3285 | 0 | } |
3286 | | |
3287 | | #endif /* defined(HAVE_UMASK) */ |
3288 | | |
3289 | | PyDoc_STRVAR(os_unlink__doc__, |
3290 | | "unlink($module, /, path, *, dir_fd=None)\n" |
3291 | | "--\n" |
3292 | | "\n" |
3293 | | "Remove a file (same as remove()).\n" |
3294 | | "\n" |
3295 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3296 | | " and path should be relative; path will then be relative to that directory.\n" |
3297 | | "dir_fd may not be implemented on your platform.\n" |
3298 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3299 | | |
3300 | | #define OS_UNLINK_METHODDEF \ |
3301 | | {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__}, |
3302 | | |
3303 | | static PyObject * |
3304 | | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
3305 | | |
3306 | | static PyObject * |
3307 | | os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3308 | 0 | { |
3309 | 0 | PyObject *return_value = NULL; |
3310 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3311 | |
|
3312 | 0 | #define NUM_KEYWORDS 2 |
3313 | 0 | static struct { |
3314 | 0 | PyGC_Head _this_is_not_used; |
3315 | 0 | PyObject_VAR_HEAD |
3316 | 0 | Py_hash_t ob_hash; |
3317 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3318 | 0 | } _kwtuple = { |
3319 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3320 | 0 | .ob_hash = -1, |
3321 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3322 | 0 | }; |
3323 | 0 | #undef NUM_KEYWORDS |
3324 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3325 | |
|
3326 | | #else // !Py_BUILD_CORE |
3327 | | # define KWTUPLE NULL |
3328 | | #endif // !Py_BUILD_CORE |
3329 | |
|
3330 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3331 | 0 | static _PyArg_Parser _parser = { |
3332 | 0 | .keywords = _keywords, |
3333 | 0 | .fname = "unlink", |
3334 | 0 | .kwtuple = KWTUPLE, |
3335 | 0 | }; |
3336 | 0 | #undef KWTUPLE |
3337 | 0 | PyObject *argsbuf[2]; |
3338 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3339 | 0 | path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0); |
3340 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3341 | |
|
3342 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3343 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3344 | 0 | if (!args) { |
3345 | 0 | goto exit; |
3346 | 0 | } |
3347 | 0 | if (!path_converter(args[0], &path)) { |
3348 | 0 | goto exit; |
3349 | 0 | } |
3350 | 0 | if (!noptargs) { |
3351 | 0 | goto skip_optional_kwonly; |
3352 | 0 | } |
3353 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3354 | 0 | goto exit; |
3355 | 0 | } |
3356 | 0 | skip_optional_kwonly: |
3357 | 0 | return_value = os_unlink_impl(module, &path, dir_fd); |
3358 | |
|
3359 | 0 | exit: |
3360 | | /* Cleanup for path */ |
3361 | 0 | path_cleanup(&path); |
3362 | |
|
3363 | 0 | return return_value; |
3364 | 0 | } |
3365 | | |
3366 | | PyDoc_STRVAR(os_remove__doc__, |
3367 | | "remove($module, /, path, *, dir_fd=None)\n" |
3368 | | "--\n" |
3369 | | "\n" |
3370 | | "Remove a file (same as unlink()).\n" |
3371 | | "\n" |
3372 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3373 | | " and path should be relative; path will then be relative to that directory.\n" |
3374 | | "dir_fd may not be implemented on your platform.\n" |
3375 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3376 | | |
3377 | | #define OS_REMOVE_METHODDEF \ |
3378 | | {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__}, |
3379 | | |
3380 | | static PyObject * |
3381 | | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
3382 | | |
3383 | | static PyObject * |
3384 | | os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3385 | 0 | { |
3386 | 0 | PyObject *return_value = NULL; |
3387 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3388 | |
|
3389 | 0 | #define NUM_KEYWORDS 2 |
3390 | 0 | static struct { |
3391 | 0 | PyGC_Head _this_is_not_used; |
3392 | 0 | PyObject_VAR_HEAD |
3393 | 0 | Py_hash_t ob_hash; |
3394 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3395 | 0 | } _kwtuple = { |
3396 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3397 | 0 | .ob_hash = -1, |
3398 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3399 | 0 | }; |
3400 | 0 | #undef NUM_KEYWORDS |
3401 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3402 | |
|
3403 | | #else // !Py_BUILD_CORE |
3404 | | # define KWTUPLE NULL |
3405 | | #endif // !Py_BUILD_CORE |
3406 | |
|
3407 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3408 | 0 | static _PyArg_Parser _parser = { |
3409 | 0 | .keywords = _keywords, |
3410 | 0 | .fname = "remove", |
3411 | 0 | .kwtuple = KWTUPLE, |
3412 | 0 | }; |
3413 | 0 | #undef KWTUPLE |
3414 | 0 | PyObject *argsbuf[2]; |
3415 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3416 | 0 | path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0); |
3417 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3418 | |
|
3419 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3420 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3421 | 0 | if (!args) { |
3422 | 0 | goto exit; |
3423 | 0 | } |
3424 | 0 | if (!path_converter(args[0], &path)) { |
3425 | 0 | goto exit; |
3426 | 0 | } |
3427 | 0 | if (!noptargs) { |
3428 | 0 | goto skip_optional_kwonly; |
3429 | 0 | } |
3430 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3431 | 0 | goto exit; |
3432 | 0 | } |
3433 | 0 | skip_optional_kwonly: |
3434 | 0 | return_value = os_remove_impl(module, &path, dir_fd); |
3435 | |
|
3436 | 0 | exit: |
3437 | | /* Cleanup for path */ |
3438 | 0 | path_cleanup(&path); |
3439 | |
|
3440 | 0 | return return_value; |
3441 | 0 | } |
3442 | | |
3443 | | #if defined(HAVE_UNAME) |
3444 | | |
3445 | | PyDoc_STRVAR(os_uname__doc__, |
3446 | | "uname($module, /)\n" |
3447 | | "--\n" |
3448 | | "\n" |
3449 | | "Return an object identifying the current operating system.\n" |
3450 | | "\n" |
3451 | | "The object behaves like a named tuple with the following fields:\n" |
3452 | | " (sysname, nodename, release, version, machine)"); |
3453 | | |
3454 | | #define OS_UNAME_METHODDEF \ |
3455 | | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
3456 | | |
3457 | | static PyObject * |
3458 | | os_uname_impl(PyObject *module); |
3459 | | |
3460 | | static PyObject * |
3461 | | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3462 | 0 | { |
3463 | 0 | return os_uname_impl(module); |
3464 | 0 | } |
3465 | | |
3466 | | #endif /* defined(HAVE_UNAME) */ |
3467 | | |
3468 | | PyDoc_STRVAR(os_utime__doc__, |
3469 | | "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n" |
3470 | | " dir_fd=None, follow_symlinks=True)\n" |
3471 | | "--\n" |
3472 | | "\n" |
3473 | | "Set the access and modified time of path.\n" |
3474 | | "\n" |
3475 | | "path may always be specified as a string.\n" |
3476 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
3477 | | " If this functionality is unavailable, using it raises an exception.\n" |
3478 | | "\n" |
3479 | | "If times is not None, it must be a tuple (atime, mtime);\n" |
3480 | | " atime and mtime should be expressed as float seconds since the epoch.\n" |
3481 | | "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n" |
3482 | | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
3483 | | " since the epoch.\n" |
3484 | | "If times is None and ns is unspecified, utime uses the current time.\n" |
3485 | | "Specifying tuples for both times and ns is an error.\n" |
3486 | | "\n" |
3487 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3488 | | " and path should be relative; path will then be relative to that directory.\n" |
3489 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
3490 | | " link, utime will modify the symbolic link itself instead of the file the\n" |
3491 | | " link points to.\n" |
3492 | | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
3493 | | " as an open file descriptor.\n" |
3494 | | "dir_fd and follow_symlinks may not be available on your platform.\n" |
3495 | | " If they are unavailable, using them will raise a NotImplementedError."); |
3496 | | |
3497 | | #define OS_UTIME_METHODDEF \ |
3498 | | {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__}, |
3499 | | |
3500 | | static PyObject * |
3501 | | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
3502 | | int dir_fd, int follow_symlinks); |
3503 | | |
3504 | | static PyObject * |
3505 | | os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3506 | 0 | { |
3507 | 0 | PyObject *return_value = NULL; |
3508 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3509 | |
|
3510 | 0 | #define NUM_KEYWORDS 5 |
3511 | 0 | static struct { |
3512 | 0 | PyGC_Head _this_is_not_used; |
3513 | 0 | PyObject_VAR_HEAD |
3514 | 0 | Py_hash_t ob_hash; |
3515 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3516 | 0 | } _kwtuple = { |
3517 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3518 | 0 | .ob_hash = -1, |
3519 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
3520 | 0 | }; |
3521 | 0 | #undef NUM_KEYWORDS |
3522 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3523 | |
|
3524 | | #else // !Py_BUILD_CORE |
3525 | | # define KWTUPLE NULL |
3526 | | #endif // !Py_BUILD_CORE |
3527 | |
|
3528 | 0 | static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
3529 | 0 | static _PyArg_Parser _parser = { |
3530 | 0 | .keywords = _keywords, |
3531 | 0 | .fname = "utime", |
3532 | 0 | .kwtuple = KWTUPLE, |
3533 | 0 | }; |
3534 | 0 | #undef KWTUPLE |
3535 | 0 | PyObject *argsbuf[5]; |
3536 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3537 | 0 | path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD); |
3538 | 0 | PyObject *times = Py_None; |
3539 | 0 | PyObject *ns = NULL; |
3540 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3541 | 0 | int follow_symlinks = 1; |
3542 | |
|
3543 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3544 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3545 | 0 | if (!args) { |
3546 | 0 | goto exit; |
3547 | 0 | } |
3548 | 0 | if (!path_converter(args[0], &path)) { |
3549 | 0 | goto exit; |
3550 | 0 | } |
3551 | 0 | if (!noptargs) { |
3552 | 0 | goto skip_optional_pos; |
3553 | 0 | } |
3554 | 0 | if (args[1]) { |
3555 | 0 | times = args[1]; |
3556 | 0 | if (!--noptargs) { |
3557 | 0 | goto skip_optional_pos; |
3558 | 0 | } |
3559 | 0 | } |
3560 | 0 | skip_optional_pos: |
3561 | 0 | if (!noptargs) { |
3562 | 0 | goto skip_optional_kwonly; |
3563 | 0 | } |
3564 | 0 | if (args[2]) { |
3565 | 0 | ns = args[2]; |
3566 | 0 | if (!--noptargs) { |
3567 | 0 | goto skip_optional_kwonly; |
3568 | 0 | } |
3569 | 0 | } |
3570 | 0 | if (args[3]) { |
3571 | 0 | if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
3572 | 0 | goto exit; |
3573 | 0 | } |
3574 | 0 | if (!--noptargs) { |
3575 | 0 | goto skip_optional_kwonly; |
3576 | 0 | } |
3577 | 0 | } |
3578 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
3579 | 0 | if (follow_symlinks < 0) { |
3580 | 0 | goto exit; |
3581 | 0 | } |
3582 | 0 | skip_optional_kwonly: |
3583 | 0 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
3584 | |
|
3585 | 0 | exit: |
3586 | | /* Cleanup for path */ |
3587 | 0 | path_cleanup(&path); |
3588 | |
|
3589 | 0 | return return_value; |
3590 | 0 | } |
3591 | | |
3592 | | PyDoc_STRVAR(os__exit__doc__, |
3593 | | "_exit($module, /, status)\n" |
3594 | | "--\n" |
3595 | | "\n" |
3596 | | "Exit to the system with specified status, without normal exit processing."); |
3597 | | |
3598 | | #define OS__EXIT_METHODDEF \ |
3599 | | {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__}, |
3600 | | |
3601 | | static PyObject * |
3602 | | os__exit_impl(PyObject *module, int status); |
3603 | | |
3604 | | static PyObject * |
3605 | | os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3606 | 0 | { |
3607 | 0 | PyObject *return_value = NULL; |
3608 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3609 | |
|
3610 | 0 | #define NUM_KEYWORDS 1 |
3611 | 0 | static struct { |
3612 | 0 | PyGC_Head _this_is_not_used; |
3613 | 0 | PyObject_VAR_HEAD |
3614 | 0 | Py_hash_t ob_hash; |
3615 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3616 | 0 | } _kwtuple = { |
3617 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3618 | 0 | .ob_hash = -1, |
3619 | 0 | .ob_item = { &_Py_ID(status), }, |
3620 | 0 | }; |
3621 | 0 | #undef NUM_KEYWORDS |
3622 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3623 | |
|
3624 | | #else // !Py_BUILD_CORE |
3625 | | # define KWTUPLE NULL |
3626 | | #endif // !Py_BUILD_CORE |
3627 | |
|
3628 | 0 | static const char * const _keywords[] = {"status", NULL}; |
3629 | 0 | static _PyArg_Parser _parser = { |
3630 | 0 | .keywords = _keywords, |
3631 | 0 | .fname = "_exit", |
3632 | 0 | .kwtuple = KWTUPLE, |
3633 | 0 | }; |
3634 | 0 | #undef KWTUPLE |
3635 | 0 | PyObject *argsbuf[1]; |
3636 | 0 | int status; |
3637 | |
|
3638 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3639 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3640 | 0 | if (!args) { |
3641 | 0 | goto exit; |
3642 | 0 | } |
3643 | 0 | status = PyLong_AsInt(args[0]); |
3644 | 0 | if (status == -1 && PyErr_Occurred()) { |
3645 | 0 | goto exit; |
3646 | 0 | } |
3647 | 0 | return_value = os__exit_impl(module, status); |
3648 | |
|
3649 | 0 | exit: |
3650 | 0 | return return_value; |
3651 | 0 | } |
3652 | | |
3653 | | #if defined(HAVE_EXECV) |
3654 | | |
3655 | | PyDoc_STRVAR(os_execv__doc__, |
3656 | | "execv($module, path, argv, /)\n" |
3657 | | "--\n" |
3658 | | "\n" |
3659 | | "Execute an executable path with arguments, replacing current process.\n" |
3660 | | "\n" |
3661 | | " path\n" |
3662 | | " Path of executable file.\n" |
3663 | | " argv\n" |
3664 | | " Tuple or list of strings."); |
3665 | | |
3666 | | #define OS_EXECV_METHODDEF \ |
3667 | | {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__}, |
3668 | | |
3669 | | static PyObject * |
3670 | | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
3671 | | |
3672 | | static PyObject * |
3673 | | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3674 | 0 | { |
3675 | 0 | PyObject *return_value = NULL; |
3676 | 0 | path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0); |
3677 | 0 | PyObject *argv; |
3678 | |
|
3679 | 0 | if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { |
3680 | 0 | goto exit; |
3681 | 0 | } |
3682 | 0 | if (!path_converter(args[0], &path)) { |
3683 | 0 | goto exit; |
3684 | 0 | } |
3685 | 0 | argv = args[1]; |
3686 | 0 | return_value = os_execv_impl(module, &path, argv); |
3687 | |
|
3688 | 0 | exit: |
3689 | | /* Cleanup for path */ |
3690 | 0 | path_cleanup(&path); |
3691 | |
|
3692 | 0 | return return_value; |
3693 | 0 | } |
3694 | | |
3695 | | #endif /* defined(HAVE_EXECV) */ |
3696 | | |
3697 | | #if defined(HAVE_EXECV) |
3698 | | |
3699 | | PyDoc_STRVAR(os_execve__doc__, |
3700 | | "execve($module, /, path, argv, env)\n" |
3701 | | "--\n" |
3702 | | "\n" |
3703 | | "Execute an executable path with arguments, replacing current process.\n" |
3704 | | "\n" |
3705 | | " path\n" |
3706 | | " Path of executable file.\n" |
3707 | | " argv\n" |
3708 | | " Tuple or list of strings.\n" |
3709 | | " env\n" |
3710 | | " Dictionary of strings mapping to strings."); |
3711 | | |
3712 | | #define OS_EXECVE_METHODDEF \ |
3713 | | {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__}, |
3714 | | |
3715 | | static PyObject * |
3716 | | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
3717 | | |
3718 | | static PyObject * |
3719 | | os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3720 | 0 | { |
3721 | 0 | PyObject *return_value = NULL; |
3722 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3723 | |
|
3724 | 0 | #define NUM_KEYWORDS 3 |
3725 | 0 | static struct { |
3726 | 0 | PyGC_Head _this_is_not_used; |
3727 | 0 | PyObject_VAR_HEAD |
3728 | 0 | Py_hash_t ob_hash; |
3729 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3730 | 0 | } _kwtuple = { |
3731 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3732 | 0 | .ob_hash = -1, |
3733 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), }, |
3734 | 0 | }; |
3735 | 0 | #undef NUM_KEYWORDS |
3736 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3737 | |
|
3738 | | #else // !Py_BUILD_CORE |
3739 | | # define KWTUPLE NULL |
3740 | | #endif // !Py_BUILD_CORE |
3741 | |
|
3742 | 0 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
3743 | 0 | static _PyArg_Parser _parser = { |
3744 | 0 | .keywords = _keywords, |
3745 | 0 | .fname = "execve", |
3746 | 0 | .kwtuple = KWTUPLE, |
3747 | 0 | }; |
3748 | 0 | #undef KWTUPLE |
3749 | 0 | PyObject *argsbuf[3]; |
3750 | 0 | path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE); |
3751 | 0 | PyObject *argv; |
3752 | 0 | PyObject *env; |
3753 | |
|
3754 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3755 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3756 | 0 | if (!args) { |
3757 | 0 | goto exit; |
3758 | 0 | } |
3759 | 0 | if (!path_converter(args[0], &path)) { |
3760 | 0 | goto exit; |
3761 | 0 | } |
3762 | 0 | argv = args[1]; |
3763 | 0 | env = args[2]; |
3764 | 0 | return_value = os_execve_impl(module, &path, argv, env); |
3765 | |
|
3766 | 0 | exit: |
3767 | | /* Cleanup for path */ |
3768 | 0 | path_cleanup(&path); |
3769 | |
|
3770 | 0 | return return_value; |
3771 | 0 | } |
3772 | | |
3773 | | #endif /* defined(HAVE_EXECV) */ |
3774 | | |
3775 | | #if defined(HAVE_POSIX_SPAWN) |
3776 | | |
3777 | | PyDoc_STRVAR(os_posix_spawn__doc__, |
3778 | | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
3779 | | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
3780 | | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
3781 | | "--\n" |
3782 | | "\n" |
3783 | | "Execute the program specified by path in a new process.\n" |
3784 | | "\n" |
3785 | | " path\n" |
3786 | | " Path of executable file.\n" |
3787 | | " argv\n" |
3788 | | " Tuple or list of strings.\n" |
3789 | | " env\n" |
3790 | | " Dictionary of strings mapping to strings.\n" |
3791 | | " file_actions\n" |
3792 | | " A sequence of file action tuples.\n" |
3793 | | " setpgroup\n" |
3794 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
3795 | | " resetids\n" |
3796 | | " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n" |
3797 | | " setsid\n" |
3798 | | " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
3799 | | " setsigmask\n" |
3800 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
3801 | | " setsigdef\n" |
3802 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
3803 | | " scheduler\n" |
3804 | | " A tuple with the scheduler policy (optional) and parameters."); |
3805 | | |
3806 | | #define OS_POSIX_SPAWN_METHODDEF \ |
3807 | | {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__}, |
3808 | | |
3809 | | static PyObject * |
3810 | | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
3811 | | PyObject *env, PyObject *file_actions, |
3812 | | PyObject *setpgroup, int resetids, int setsid, |
3813 | | PyObject *setsigmask, PyObject *setsigdef, |
3814 | | PyObject *scheduler); |
3815 | | |
3816 | | static PyObject * |
3817 | | os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3818 | 0 | { |
3819 | 0 | PyObject *return_value = NULL; |
3820 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3821 | |
|
3822 | 0 | #define NUM_KEYWORDS 7 |
3823 | 0 | static struct { |
3824 | 0 | PyGC_Head _this_is_not_used; |
3825 | 0 | PyObject_VAR_HEAD |
3826 | 0 | Py_hash_t ob_hash; |
3827 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3828 | 0 | } _kwtuple = { |
3829 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3830 | 0 | .ob_hash = -1, |
3831 | 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), }, |
3832 | 0 | }; |
3833 | 0 | #undef NUM_KEYWORDS |
3834 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3835 | |
|
3836 | | #else // !Py_BUILD_CORE |
3837 | | # define KWTUPLE NULL |
3838 | | #endif // !Py_BUILD_CORE |
3839 | |
|
3840 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
3841 | 0 | static _PyArg_Parser _parser = { |
3842 | 0 | .keywords = _keywords, |
3843 | 0 | .fname = "posix_spawn", |
3844 | 0 | .kwtuple = KWTUPLE, |
3845 | 0 | }; |
3846 | 0 | #undef KWTUPLE |
3847 | 0 | PyObject *argsbuf[10]; |
3848 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
3849 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0); |
3850 | 0 | PyObject *argv; |
3851 | 0 | PyObject *env; |
3852 | 0 | PyObject *file_actions = NULL; |
3853 | 0 | PyObject *setpgroup = NULL; |
3854 | 0 | int resetids = 0; |
3855 | 0 | int setsid = 0; |
3856 | 0 | PyObject *setsigmask = NULL; |
3857 | 0 | PyObject *setsigdef = NULL; |
3858 | 0 | PyObject *scheduler = NULL; |
3859 | |
|
3860 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3861 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3862 | 0 | if (!args) { |
3863 | 0 | goto exit; |
3864 | 0 | } |
3865 | 0 | if (!path_converter(args[0], &path)) { |
3866 | 0 | goto exit; |
3867 | 0 | } |
3868 | 0 | argv = args[1]; |
3869 | 0 | env = args[2]; |
3870 | 0 | if (!noptargs) { |
3871 | 0 | goto skip_optional_kwonly; |
3872 | 0 | } |
3873 | 0 | if (args[3]) { |
3874 | 0 | file_actions = args[3]; |
3875 | 0 | if (!--noptargs) { |
3876 | 0 | goto skip_optional_kwonly; |
3877 | 0 | } |
3878 | 0 | } |
3879 | 0 | if (args[4]) { |
3880 | 0 | setpgroup = args[4]; |
3881 | 0 | if (!--noptargs) { |
3882 | 0 | goto skip_optional_kwonly; |
3883 | 0 | } |
3884 | 0 | } |
3885 | 0 | if (args[5]) { |
3886 | 0 | resetids = PyObject_IsTrue(args[5]); |
3887 | 0 | if (resetids < 0) { |
3888 | 0 | goto exit; |
3889 | 0 | } |
3890 | 0 | if (!--noptargs) { |
3891 | 0 | goto skip_optional_kwonly; |
3892 | 0 | } |
3893 | 0 | } |
3894 | 0 | if (args[6]) { |
3895 | 0 | setsid = PyObject_IsTrue(args[6]); |
3896 | 0 | if (setsid < 0) { |
3897 | 0 | goto exit; |
3898 | 0 | } |
3899 | 0 | if (!--noptargs) { |
3900 | 0 | goto skip_optional_kwonly; |
3901 | 0 | } |
3902 | 0 | } |
3903 | 0 | if (args[7]) { |
3904 | 0 | setsigmask = args[7]; |
3905 | 0 | if (!--noptargs) { |
3906 | 0 | goto skip_optional_kwonly; |
3907 | 0 | } |
3908 | 0 | } |
3909 | 0 | if (args[8]) { |
3910 | 0 | setsigdef = args[8]; |
3911 | 0 | if (!--noptargs) { |
3912 | 0 | goto skip_optional_kwonly; |
3913 | 0 | } |
3914 | 0 | } |
3915 | 0 | scheduler = args[9]; |
3916 | 0 | skip_optional_kwonly: |
3917 | 0 | return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
3918 | |
|
3919 | 0 | exit: |
3920 | | /* Cleanup for path */ |
3921 | 0 | path_cleanup(&path); |
3922 | |
|
3923 | 0 | return return_value; |
3924 | 0 | } |
3925 | | |
3926 | | #endif /* defined(HAVE_POSIX_SPAWN) */ |
3927 | | |
3928 | | #if defined(HAVE_POSIX_SPAWNP) |
3929 | | |
3930 | | PyDoc_STRVAR(os_posix_spawnp__doc__, |
3931 | | "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n" |
3932 | | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
3933 | | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
3934 | | "--\n" |
3935 | | "\n" |
3936 | | "Execute the program specified by path in a new process.\n" |
3937 | | "\n" |
3938 | | " path\n" |
3939 | | " Path of executable file.\n" |
3940 | | " argv\n" |
3941 | | " Tuple or list of strings.\n" |
3942 | | " env\n" |
3943 | | " Dictionary of strings mapping to strings.\n" |
3944 | | " file_actions\n" |
3945 | | " A sequence of file action tuples.\n" |
3946 | | " setpgroup\n" |
3947 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
3948 | | " resetids\n" |
3949 | | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
3950 | | " setsid\n" |
3951 | | " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
3952 | | " setsigmask\n" |
3953 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
3954 | | " setsigdef\n" |
3955 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
3956 | | " scheduler\n" |
3957 | | " A tuple with the scheduler policy (optional) and parameters."); |
3958 | | |
3959 | | #define OS_POSIX_SPAWNP_METHODDEF \ |
3960 | | {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__}, |
3961 | | |
3962 | | static PyObject * |
3963 | | os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv, |
3964 | | PyObject *env, PyObject *file_actions, |
3965 | | PyObject *setpgroup, int resetids, int setsid, |
3966 | | PyObject *setsigmask, PyObject *setsigdef, |
3967 | | PyObject *scheduler); |
3968 | | |
3969 | | static PyObject * |
3970 | | os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3971 | 0 | { |
3972 | 0 | PyObject *return_value = NULL; |
3973 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3974 | |
|
3975 | 0 | #define NUM_KEYWORDS 7 |
3976 | 0 | static struct { |
3977 | 0 | PyGC_Head _this_is_not_used; |
3978 | 0 | PyObject_VAR_HEAD |
3979 | 0 | Py_hash_t ob_hash; |
3980 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3981 | 0 | } _kwtuple = { |
3982 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3983 | 0 | .ob_hash = -1, |
3984 | 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), }, |
3985 | 0 | }; |
3986 | 0 | #undef NUM_KEYWORDS |
3987 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3988 | |
|
3989 | | #else // !Py_BUILD_CORE |
3990 | | # define KWTUPLE NULL |
3991 | | #endif // !Py_BUILD_CORE |
3992 | |
|
3993 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
3994 | 0 | static _PyArg_Parser _parser = { |
3995 | 0 | .keywords = _keywords, |
3996 | 0 | .fname = "posix_spawnp", |
3997 | 0 | .kwtuple = KWTUPLE, |
3998 | 0 | }; |
3999 | 0 | #undef KWTUPLE |
4000 | 0 | PyObject *argsbuf[10]; |
4001 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
4002 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0); |
4003 | 0 | PyObject *argv; |
4004 | 0 | PyObject *env; |
4005 | 0 | PyObject *file_actions = NULL; |
4006 | 0 | PyObject *setpgroup = NULL; |
4007 | 0 | int resetids = 0; |
4008 | 0 | int setsid = 0; |
4009 | 0 | PyObject *setsigmask = NULL; |
4010 | 0 | PyObject *setsigdef = NULL; |
4011 | 0 | PyObject *scheduler = NULL; |
4012 | |
|
4013 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4014 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4015 | 0 | if (!args) { |
4016 | 0 | goto exit; |
4017 | 0 | } |
4018 | 0 | if (!path_converter(args[0], &path)) { |
4019 | 0 | goto exit; |
4020 | 0 | } |
4021 | 0 | argv = args[1]; |
4022 | 0 | env = args[2]; |
4023 | 0 | if (!noptargs) { |
4024 | 0 | goto skip_optional_kwonly; |
4025 | 0 | } |
4026 | 0 | if (args[3]) { |
4027 | 0 | file_actions = args[3]; |
4028 | 0 | if (!--noptargs) { |
4029 | 0 | goto skip_optional_kwonly; |
4030 | 0 | } |
4031 | 0 | } |
4032 | 0 | if (args[4]) { |
4033 | 0 | setpgroup = args[4]; |
4034 | 0 | if (!--noptargs) { |
4035 | 0 | goto skip_optional_kwonly; |
4036 | 0 | } |
4037 | 0 | } |
4038 | 0 | if (args[5]) { |
4039 | 0 | resetids = PyObject_IsTrue(args[5]); |
4040 | 0 | if (resetids < 0) { |
4041 | 0 | goto exit; |
4042 | 0 | } |
4043 | 0 | if (!--noptargs) { |
4044 | 0 | goto skip_optional_kwonly; |
4045 | 0 | } |
4046 | 0 | } |
4047 | 0 | if (args[6]) { |
4048 | 0 | setsid = PyObject_IsTrue(args[6]); |
4049 | 0 | if (setsid < 0) { |
4050 | 0 | goto exit; |
4051 | 0 | } |
4052 | 0 | if (!--noptargs) { |
4053 | 0 | goto skip_optional_kwonly; |
4054 | 0 | } |
4055 | 0 | } |
4056 | 0 | if (args[7]) { |
4057 | 0 | setsigmask = args[7]; |
4058 | 0 | if (!--noptargs) { |
4059 | 0 | goto skip_optional_kwonly; |
4060 | 0 | } |
4061 | 0 | } |
4062 | 0 | if (args[8]) { |
4063 | 0 | setsigdef = args[8]; |
4064 | 0 | if (!--noptargs) { |
4065 | 0 | goto skip_optional_kwonly; |
4066 | 0 | } |
4067 | 0 | } |
4068 | 0 | scheduler = args[9]; |
4069 | 0 | skip_optional_kwonly: |
4070 | 0 | return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
4071 | |
|
4072 | 0 | exit: |
4073 | | /* Cleanup for path */ |
4074 | 0 | path_cleanup(&path); |
4075 | |
|
4076 | 0 | return return_value; |
4077 | 0 | } |
4078 | | |
4079 | | #endif /* defined(HAVE_POSIX_SPAWNP) */ |
4080 | | |
4081 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4082 | | |
4083 | | PyDoc_STRVAR(os_spawnv__doc__, |
4084 | | "spawnv($module, mode, path, argv, /)\n" |
4085 | | "--\n" |
4086 | | "\n" |
4087 | | "Execute the program specified by path in a new process.\n" |
4088 | | "\n" |
4089 | | " mode\n" |
4090 | | " Mode of process creation.\n" |
4091 | | " path\n" |
4092 | | " Path of executable file.\n" |
4093 | | " argv\n" |
4094 | | " Tuple or list of strings."); |
4095 | | |
4096 | | #define OS_SPAWNV_METHODDEF \ |
4097 | | {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__}, |
4098 | | |
4099 | | static PyObject * |
4100 | | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
4101 | | |
4102 | | static PyObject * |
4103 | | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4104 | | { |
4105 | | PyObject *return_value = NULL; |
4106 | | int mode; |
4107 | | path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0); |
4108 | | PyObject *argv; |
4109 | | |
4110 | | if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { |
4111 | | goto exit; |
4112 | | } |
4113 | | mode = PyLong_AsInt(args[0]); |
4114 | | if (mode == -1 && PyErr_Occurred()) { |
4115 | | goto exit; |
4116 | | } |
4117 | | if (!path_converter(args[1], &path)) { |
4118 | | goto exit; |
4119 | | } |
4120 | | argv = args[2]; |
4121 | | return_value = os_spawnv_impl(module, mode, &path, argv); |
4122 | | |
4123 | | exit: |
4124 | | /* Cleanup for path */ |
4125 | | path_cleanup(&path); |
4126 | | |
4127 | | return return_value; |
4128 | | } |
4129 | | |
4130 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4131 | | |
4132 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4133 | | |
4134 | | PyDoc_STRVAR(os_spawnve__doc__, |
4135 | | "spawnve($module, mode, path, argv, env, /)\n" |
4136 | | "--\n" |
4137 | | "\n" |
4138 | | "Execute the program specified by path in a new process.\n" |
4139 | | "\n" |
4140 | | " mode\n" |
4141 | | " Mode of process creation.\n" |
4142 | | " path\n" |
4143 | | " Path of executable file.\n" |
4144 | | " argv\n" |
4145 | | " Tuple or list of strings.\n" |
4146 | | " env\n" |
4147 | | " Dictionary of strings mapping to strings."); |
4148 | | |
4149 | | #define OS_SPAWNVE_METHODDEF \ |
4150 | | {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__}, |
4151 | | |
4152 | | static PyObject * |
4153 | | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
4154 | | PyObject *env); |
4155 | | |
4156 | | static PyObject * |
4157 | | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4158 | | { |
4159 | | PyObject *return_value = NULL; |
4160 | | int mode; |
4161 | | path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0); |
4162 | | PyObject *argv; |
4163 | | PyObject *env; |
4164 | | |
4165 | | if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { |
4166 | | goto exit; |
4167 | | } |
4168 | | mode = PyLong_AsInt(args[0]); |
4169 | | if (mode == -1 && PyErr_Occurred()) { |
4170 | | goto exit; |
4171 | | } |
4172 | | if (!path_converter(args[1], &path)) { |
4173 | | goto exit; |
4174 | | } |
4175 | | argv = args[2]; |
4176 | | env = args[3]; |
4177 | | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
4178 | | |
4179 | | exit: |
4180 | | /* Cleanup for path */ |
4181 | | path_cleanup(&path); |
4182 | | |
4183 | | return return_value; |
4184 | | } |
4185 | | |
4186 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4187 | | |
4188 | | #if defined(HAVE_FORK) |
4189 | | |
4190 | | PyDoc_STRVAR(os_register_at_fork__doc__, |
4191 | | "register_at_fork($module, /, *, before=<unrepresentable>,\n" |
4192 | | " after_in_child=<unrepresentable>,\n" |
4193 | | " after_in_parent=<unrepresentable>)\n" |
4194 | | "--\n" |
4195 | | "\n" |
4196 | | "Register callables to be called when forking a new process.\n" |
4197 | | "\n" |
4198 | | " before\n" |
4199 | | " A callable to be called in the parent before the fork() syscall.\n" |
4200 | | " after_in_child\n" |
4201 | | " A callable to be called in the child after fork().\n" |
4202 | | " after_in_parent\n" |
4203 | | " A callable to be called in the parent after fork().\n" |
4204 | | "\n" |
4205 | | "\'before\' callbacks are called in reverse order.\n" |
4206 | | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order."); |
4207 | | |
4208 | | #define OS_REGISTER_AT_FORK_METHODDEF \ |
4209 | | {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__}, |
4210 | | |
4211 | | static PyObject * |
4212 | | os_register_at_fork_impl(PyObject *module, PyObject *before, |
4213 | | PyObject *after_in_child, PyObject *after_in_parent); |
4214 | | |
4215 | | static PyObject * |
4216 | | os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4217 | 2 | { |
4218 | 2 | PyObject *return_value = NULL; |
4219 | 2 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4220 | | |
4221 | 2 | #define NUM_KEYWORDS 3 |
4222 | 2 | static struct { |
4223 | 2 | PyGC_Head _this_is_not_used; |
4224 | 2 | PyObject_VAR_HEAD |
4225 | 2 | Py_hash_t ob_hash; |
4226 | 2 | PyObject *ob_item[NUM_KEYWORDS]; |
4227 | 2 | } _kwtuple = { |
4228 | 2 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4229 | 2 | .ob_hash = -1, |
4230 | 2 | .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), }, |
4231 | 2 | }; |
4232 | 2 | #undef NUM_KEYWORDS |
4233 | 2 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4234 | | |
4235 | | #else // !Py_BUILD_CORE |
4236 | | # define KWTUPLE NULL |
4237 | | #endif // !Py_BUILD_CORE |
4238 | | |
4239 | 2 | static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL}; |
4240 | 2 | static _PyArg_Parser _parser = { |
4241 | 2 | .keywords = _keywords, |
4242 | 2 | .fname = "register_at_fork", |
4243 | 2 | .kwtuple = KWTUPLE, |
4244 | 2 | }; |
4245 | 2 | #undef KWTUPLE |
4246 | 2 | PyObject *argsbuf[3]; |
4247 | 2 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
4248 | 2 | PyObject *before = NULL; |
4249 | 2 | PyObject *after_in_child = NULL; |
4250 | 2 | PyObject *after_in_parent = NULL; |
4251 | | |
4252 | 2 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4253 | 2 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4254 | 2 | if (!args) { |
4255 | 0 | goto exit; |
4256 | 0 | } |
4257 | 2 | if (!noptargs) { |
4258 | 0 | goto skip_optional_kwonly; |
4259 | 0 | } |
4260 | 2 | if (args[0]) { |
4261 | 0 | before = args[0]; |
4262 | 0 | if (!--noptargs) { |
4263 | 0 | goto skip_optional_kwonly; |
4264 | 0 | } |
4265 | 0 | } |
4266 | 2 | if (args[1]) { |
4267 | 2 | after_in_child = args[1]; |
4268 | 2 | if (!--noptargs) { |
4269 | 2 | goto skip_optional_kwonly; |
4270 | 2 | } |
4271 | 2 | } |
4272 | 0 | after_in_parent = args[2]; |
4273 | 2 | skip_optional_kwonly: |
4274 | 2 | return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent); |
4275 | | |
4276 | 2 | exit: |
4277 | 2 | return return_value; |
4278 | 2 | } |
4279 | | |
4280 | | #endif /* defined(HAVE_FORK) */ |
4281 | | |
4282 | | #if defined(HAVE_FORK1) |
4283 | | |
4284 | | PyDoc_STRVAR(os_fork1__doc__, |
4285 | | "fork1($module, /)\n" |
4286 | | "--\n" |
4287 | | "\n" |
4288 | | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
4289 | | "\n" |
4290 | | "Return 0 to child process and PID of child to parent process."); |
4291 | | |
4292 | | #define OS_FORK1_METHODDEF \ |
4293 | | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
4294 | | |
4295 | | static PyObject * |
4296 | | os_fork1_impl(PyObject *module); |
4297 | | |
4298 | | static PyObject * |
4299 | | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4300 | | { |
4301 | | return os_fork1_impl(module); |
4302 | | } |
4303 | | |
4304 | | #endif /* defined(HAVE_FORK1) */ |
4305 | | |
4306 | | #if defined(HAVE_FORK) |
4307 | | |
4308 | | PyDoc_STRVAR(os_fork__doc__, |
4309 | | "fork($module, /)\n" |
4310 | | "--\n" |
4311 | | "\n" |
4312 | | "Fork a child process.\n" |
4313 | | "\n" |
4314 | | "Return 0 to child process and PID of child to parent process."); |
4315 | | |
4316 | | #define OS_FORK_METHODDEF \ |
4317 | | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
4318 | | |
4319 | | static PyObject * |
4320 | | os_fork_impl(PyObject *module); |
4321 | | |
4322 | | static PyObject * |
4323 | | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4324 | 0 | { |
4325 | 0 | return os_fork_impl(module); |
4326 | 0 | } |
4327 | | |
4328 | | #endif /* defined(HAVE_FORK) */ |
4329 | | |
4330 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4331 | | |
4332 | | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
4333 | | "sched_get_priority_max($module, /, policy)\n" |
4334 | | "--\n" |
4335 | | "\n" |
4336 | | "Get the maximum scheduling priority for policy."); |
4337 | | |
4338 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
4339 | | {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__}, |
4340 | | |
4341 | | static PyObject * |
4342 | | os_sched_get_priority_max_impl(PyObject *module, int policy); |
4343 | | |
4344 | | static PyObject * |
4345 | | os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4346 | 0 | { |
4347 | 0 | PyObject *return_value = NULL; |
4348 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4349 | |
|
4350 | 0 | #define NUM_KEYWORDS 1 |
4351 | 0 | static struct { |
4352 | 0 | PyGC_Head _this_is_not_used; |
4353 | 0 | PyObject_VAR_HEAD |
4354 | 0 | Py_hash_t ob_hash; |
4355 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4356 | 0 | } _kwtuple = { |
4357 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4358 | 0 | .ob_hash = -1, |
4359 | 0 | .ob_item = { &_Py_ID(policy), }, |
4360 | 0 | }; |
4361 | 0 | #undef NUM_KEYWORDS |
4362 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4363 | |
|
4364 | | #else // !Py_BUILD_CORE |
4365 | | # define KWTUPLE NULL |
4366 | | #endif // !Py_BUILD_CORE |
4367 | |
|
4368 | 0 | static const char * const _keywords[] = {"policy", NULL}; |
4369 | 0 | static _PyArg_Parser _parser = { |
4370 | 0 | .keywords = _keywords, |
4371 | 0 | .fname = "sched_get_priority_max", |
4372 | 0 | .kwtuple = KWTUPLE, |
4373 | 0 | }; |
4374 | 0 | #undef KWTUPLE |
4375 | 0 | PyObject *argsbuf[1]; |
4376 | 0 | int policy; |
4377 | |
|
4378 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4379 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4380 | 0 | if (!args) { |
4381 | 0 | goto exit; |
4382 | 0 | } |
4383 | 0 | policy = PyLong_AsInt(args[0]); |
4384 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4385 | 0 | goto exit; |
4386 | 0 | } |
4387 | 0 | return_value = os_sched_get_priority_max_impl(module, policy); |
4388 | |
|
4389 | 0 | exit: |
4390 | 0 | return return_value; |
4391 | 0 | } |
4392 | | |
4393 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4394 | | |
4395 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4396 | | |
4397 | | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
4398 | | "sched_get_priority_min($module, /, policy)\n" |
4399 | | "--\n" |
4400 | | "\n" |
4401 | | "Get the minimum scheduling priority for policy."); |
4402 | | |
4403 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
4404 | | {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__}, |
4405 | | |
4406 | | static PyObject * |
4407 | | os_sched_get_priority_min_impl(PyObject *module, int policy); |
4408 | | |
4409 | | static PyObject * |
4410 | | os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4411 | 0 | { |
4412 | 0 | PyObject *return_value = NULL; |
4413 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4414 | |
|
4415 | 0 | #define NUM_KEYWORDS 1 |
4416 | 0 | static struct { |
4417 | 0 | PyGC_Head _this_is_not_used; |
4418 | 0 | PyObject_VAR_HEAD |
4419 | 0 | Py_hash_t ob_hash; |
4420 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4421 | 0 | } _kwtuple = { |
4422 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4423 | 0 | .ob_hash = -1, |
4424 | 0 | .ob_item = { &_Py_ID(policy), }, |
4425 | 0 | }; |
4426 | 0 | #undef NUM_KEYWORDS |
4427 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4428 | |
|
4429 | | #else // !Py_BUILD_CORE |
4430 | | # define KWTUPLE NULL |
4431 | | #endif // !Py_BUILD_CORE |
4432 | |
|
4433 | 0 | static const char * const _keywords[] = {"policy", NULL}; |
4434 | 0 | static _PyArg_Parser _parser = { |
4435 | 0 | .keywords = _keywords, |
4436 | 0 | .fname = "sched_get_priority_min", |
4437 | 0 | .kwtuple = KWTUPLE, |
4438 | 0 | }; |
4439 | 0 | #undef KWTUPLE |
4440 | 0 | PyObject *argsbuf[1]; |
4441 | 0 | int policy; |
4442 | |
|
4443 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4444 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4445 | 0 | if (!args) { |
4446 | 0 | goto exit; |
4447 | 0 | } |
4448 | 0 | policy = PyLong_AsInt(args[0]); |
4449 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4450 | 0 | goto exit; |
4451 | 0 | } |
4452 | 0 | return_value = os_sched_get_priority_min_impl(module, policy); |
4453 | |
|
4454 | 0 | exit: |
4455 | 0 | return return_value; |
4456 | 0 | } |
4457 | | |
4458 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4459 | | |
4460 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4461 | | |
4462 | | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
4463 | | "sched_getscheduler($module, pid, /)\n" |
4464 | | "--\n" |
4465 | | "\n" |
4466 | | "Get the scheduling policy for the process identified by pid.\n" |
4467 | | "\n" |
4468 | | "Passing 0 for pid returns the scheduling policy for the calling process."); |
4469 | | |
4470 | | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
4471 | | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
4472 | | |
4473 | | static PyObject * |
4474 | | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
4475 | | |
4476 | | static PyObject * |
4477 | | os_sched_getscheduler(PyObject *module, PyObject *arg) |
4478 | 0 | { |
4479 | 0 | PyObject *return_value = NULL; |
4480 | 0 | pid_t pid; |
4481 | |
|
4482 | 0 | pid = PyLong_AsPid(arg); |
4483 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4484 | 0 | goto exit; |
4485 | 0 | } |
4486 | 0 | return_value = os_sched_getscheduler_impl(module, pid); |
4487 | |
|
4488 | 0 | exit: |
4489 | 0 | return return_value; |
4490 | 0 | } |
4491 | | |
4492 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4493 | | |
4494 | | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) |
4495 | | |
4496 | | PyDoc_STRVAR(os_sched_param__doc__, |
4497 | | "sched_param(sched_priority)\n" |
4498 | | "--\n" |
4499 | | "\n" |
4500 | | "Currently has only one field: sched_priority\n" |
4501 | | "\n" |
4502 | | " sched_priority\n" |
4503 | | " A scheduling parameter."); |
4504 | | |
4505 | | static PyObject * |
4506 | | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
4507 | | |
4508 | | static PyObject * |
4509 | | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
4510 | 0 | { |
4511 | 0 | PyObject *return_value = NULL; |
4512 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4513 | |
|
4514 | 0 | #define NUM_KEYWORDS 1 |
4515 | 0 | static struct { |
4516 | 0 | PyGC_Head _this_is_not_used; |
4517 | 0 | PyObject_VAR_HEAD |
4518 | 0 | Py_hash_t ob_hash; |
4519 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4520 | 0 | } _kwtuple = { |
4521 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4522 | 0 | .ob_hash = -1, |
4523 | 0 | .ob_item = { &_Py_ID(sched_priority), }, |
4524 | 0 | }; |
4525 | 0 | #undef NUM_KEYWORDS |
4526 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4527 | |
|
4528 | | #else // !Py_BUILD_CORE |
4529 | | # define KWTUPLE NULL |
4530 | | #endif // !Py_BUILD_CORE |
4531 | |
|
4532 | 0 | static const char * const _keywords[] = {"sched_priority", NULL}; |
4533 | 0 | static _PyArg_Parser _parser = { |
4534 | 0 | .keywords = _keywords, |
4535 | 0 | .fname = "sched_param", |
4536 | 0 | .kwtuple = KWTUPLE, |
4537 | 0 | }; |
4538 | 0 | #undef KWTUPLE |
4539 | 0 | PyObject *argsbuf[1]; |
4540 | 0 | PyObject * const *fastargs; |
4541 | 0 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
4542 | 0 | PyObject *sched_priority; |
4543 | |
|
4544 | 0 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
4545 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4546 | 0 | if (!fastargs) { |
4547 | 0 | goto exit; |
4548 | 0 | } |
4549 | 0 | sched_priority = fastargs[0]; |
4550 | 0 | return_value = os_sched_param_impl(type, sched_priority); |
4551 | |
|
4552 | 0 | exit: |
4553 | 0 | return return_value; |
4554 | 0 | } |
4555 | | |
4556 | | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */ |
4557 | | |
4558 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4559 | | |
4560 | | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
4561 | | "sched_setscheduler($module, pid, policy, param, /)\n" |
4562 | | "--\n" |
4563 | | "\n" |
4564 | | "Set the scheduling policy for the process identified by pid.\n" |
4565 | | "\n" |
4566 | | "If pid is 0, the calling process is changed.\n" |
4567 | | "param is an instance of sched_param."); |
4568 | | |
4569 | | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
4570 | | {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__}, |
4571 | | |
4572 | | static PyObject * |
4573 | | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
4574 | | PyObject *param_obj); |
4575 | | |
4576 | | static PyObject * |
4577 | | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4578 | 0 | { |
4579 | 0 | PyObject *return_value = NULL; |
4580 | 0 | pid_t pid; |
4581 | 0 | int policy; |
4582 | 0 | PyObject *param_obj; |
4583 | |
|
4584 | 0 | if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) { |
4585 | 0 | goto exit; |
4586 | 0 | } |
4587 | 0 | pid = PyLong_AsPid(args[0]); |
4588 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4589 | 0 | goto exit; |
4590 | 0 | } |
4591 | 0 | policy = PyLong_AsInt(args[1]); |
4592 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4593 | 0 | goto exit; |
4594 | 0 | } |
4595 | 0 | param_obj = args[2]; |
4596 | 0 | return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj); |
4597 | |
|
4598 | 0 | exit: |
4599 | 0 | return return_value; |
4600 | 0 | } |
4601 | | |
4602 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4603 | | |
4604 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4605 | | |
4606 | | PyDoc_STRVAR(os_sched_getparam__doc__, |
4607 | | "sched_getparam($module, pid, /)\n" |
4608 | | "--\n" |
4609 | | "\n" |
4610 | | "Returns scheduling parameters for the process identified by pid.\n" |
4611 | | "\n" |
4612 | | "If pid is 0, returns parameters for the calling process.\n" |
4613 | | "Return value is an instance of sched_param."); |
4614 | | |
4615 | | #define OS_SCHED_GETPARAM_METHODDEF \ |
4616 | | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
4617 | | |
4618 | | static PyObject * |
4619 | | os_sched_getparam_impl(PyObject *module, pid_t pid); |
4620 | | |
4621 | | static PyObject * |
4622 | | os_sched_getparam(PyObject *module, PyObject *arg) |
4623 | 0 | { |
4624 | 0 | PyObject *return_value = NULL; |
4625 | 0 | pid_t pid; |
4626 | |
|
4627 | 0 | pid = PyLong_AsPid(arg); |
4628 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4629 | 0 | goto exit; |
4630 | 0 | } |
4631 | 0 | return_value = os_sched_getparam_impl(module, pid); |
4632 | |
|
4633 | 0 | exit: |
4634 | 0 | return return_value; |
4635 | 0 | } |
4636 | | |
4637 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4638 | | |
4639 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4640 | | |
4641 | | PyDoc_STRVAR(os_sched_setparam__doc__, |
4642 | | "sched_setparam($module, pid, param, /)\n" |
4643 | | "--\n" |
4644 | | "\n" |
4645 | | "Set scheduling parameters for the process identified by pid.\n" |
4646 | | "\n" |
4647 | | "If pid is 0, sets parameters for the calling process.\n" |
4648 | | "param should be an instance of sched_param."); |
4649 | | |
4650 | | #define OS_SCHED_SETPARAM_METHODDEF \ |
4651 | | {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__}, |
4652 | | |
4653 | | static PyObject * |
4654 | | os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj); |
4655 | | |
4656 | | static PyObject * |
4657 | | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4658 | 0 | { |
4659 | 0 | PyObject *return_value = NULL; |
4660 | 0 | pid_t pid; |
4661 | 0 | PyObject *param_obj; |
4662 | |
|
4663 | 0 | if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) { |
4664 | 0 | goto exit; |
4665 | 0 | } |
4666 | 0 | pid = PyLong_AsPid(args[0]); |
4667 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4668 | 0 | goto exit; |
4669 | 0 | } |
4670 | 0 | param_obj = args[1]; |
4671 | 0 | return_value = os_sched_setparam_impl(module, pid, param_obj); |
4672 | |
|
4673 | 0 | exit: |
4674 | 0 | return return_value; |
4675 | 0 | } |
4676 | | |
4677 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4678 | | |
4679 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
4680 | | |
4681 | | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
4682 | | "sched_rr_get_interval($module, pid, /)\n" |
4683 | | "--\n" |
4684 | | "\n" |
4685 | | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
4686 | | "\n" |
4687 | | "Value returned is a float."); |
4688 | | |
4689 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
4690 | | {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__}, |
4691 | | |
4692 | | static double |
4693 | | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
4694 | | |
4695 | | static PyObject * |
4696 | | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
4697 | 0 | { |
4698 | 0 | PyObject *return_value = NULL; |
4699 | 0 | pid_t pid; |
4700 | 0 | double _return_value; |
4701 | |
|
4702 | 0 | pid = PyLong_AsPid(arg); |
4703 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4704 | 0 | goto exit; |
4705 | 0 | } |
4706 | 0 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
4707 | 0 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
4708 | 0 | goto exit; |
4709 | 0 | } |
4710 | 0 | return_value = PyFloat_FromDouble(_return_value); |
4711 | |
|
4712 | 0 | exit: |
4713 | 0 | return return_value; |
4714 | 0 | } |
4715 | | |
4716 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
4717 | | |
4718 | | #if defined(HAVE_SCHED_H) |
4719 | | |
4720 | | PyDoc_STRVAR(os_sched_yield__doc__, |
4721 | | "sched_yield($module, /)\n" |
4722 | | "--\n" |
4723 | | "\n" |
4724 | | "Voluntarily relinquish the CPU."); |
4725 | | |
4726 | | #define OS_SCHED_YIELD_METHODDEF \ |
4727 | | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
4728 | | |
4729 | | static PyObject * |
4730 | | os_sched_yield_impl(PyObject *module); |
4731 | | |
4732 | | static PyObject * |
4733 | | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4734 | 0 | { |
4735 | 0 | return os_sched_yield_impl(module); |
4736 | 0 | } |
4737 | | |
4738 | | #endif /* defined(HAVE_SCHED_H) */ |
4739 | | |
4740 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4741 | | |
4742 | | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
4743 | | "sched_setaffinity($module, pid, mask, /)\n" |
4744 | | "--\n" |
4745 | | "\n" |
4746 | | "Set the CPU affinity of the process identified by pid to mask.\n" |
4747 | | "\n" |
4748 | | "mask should be an iterable of integers identifying CPUs."); |
4749 | | |
4750 | | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
4751 | | {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__}, |
4752 | | |
4753 | | static PyObject * |
4754 | | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
4755 | | |
4756 | | static PyObject * |
4757 | | os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4758 | 0 | { |
4759 | 0 | PyObject *return_value = NULL; |
4760 | 0 | pid_t pid; |
4761 | 0 | PyObject *mask; |
4762 | |
|
4763 | 0 | if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) { |
4764 | 0 | goto exit; |
4765 | 0 | } |
4766 | 0 | pid = PyLong_AsPid(args[0]); |
4767 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4768 | 0 | goto exit; |
4769 | 0 | } |
4770 | 0 | mask = args[1]; |
4771 | 0 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
4772 | |
|
4773 | 0 | exit: |
4774 | 0 | return return_value; |
4775 | 0 | } |
4776 | | |
4777 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4778 | | |
4779 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4780 | | |
4781 | | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
4782 | | "sched_getaffinity($module, pid, /)\n" |
4783 | | "--\n" |
4784 | | "\n" |
4785 | | "Return the affinity of the process identified by pid (or the current process if zero).\n" |
4786 | | "\n" |
4787 | | "The affinity is returned as a set of CPU identifiers."); |
4788 | | |
4789 | | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
4790 | | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
4791 | | |
4792 | | static PyObject * |
4793 | | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
4794 | | |
4795 | | static PyObject * |
4796 | | os_sched_getaffinity(PyObject *module, PyObject *arg) |
4797 | 0 | { |
4798 | 0 | PyObject *return_value = NULL; |
4799 | 0 | pid_t pid; |
4800 | |
|
4801 | 0 | pid = PyLong_AsPid(arg); |
4802 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4803 | 0 | goto exit; |
4804 | 0 | } |
4805 | 0 | return_value = os_sched_getaffinity_impl(module, pid); |
4806 | |
|
4807 | 0 | exit: |
4808 | 0 | return return_value; |
4809 | 0 | } |
4810 | | |
4811 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4812 | | |
4813 | | #if defined(HAVE_POSIX_OPENPT) |
4814 | | |
4815 | | PyDoc_STRVAR(os_posix_openpt__doc__, |
4816 | | "posix_openpt($module, oflag, /)\n" |
4817 | | "--\n" |
4818 | | "\n" |
4819 | | "Open and return a file descriptor for a master pseudo-terminal device.\n" |
4820 | | "\n" |
4821 | | "Performs a posix_openpt() C function call. The oflag argument is used to\n" |
4822 | | "set file status flags and file access modes as specified in the manual page\n" |
4823 | | "of posix_openpt() of your system."); |
4824 | | |
4825 | | #define OS_POSIX_OPENPT_METHODDEF \ |
4826 | | {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__}, |
4827 | | |
4828 | | static int |
4829 | | os_posix_openpt_impl(PyObject *module, int oflag); |
4830 | | |
4831 | | static PyObject * |
4832 | | os_posix_openpt(PyObject *module, PyObject *arg) |
4833 | 0 | { |
4834 | 0 | PyObject *return_value = NULL; |
4835 | 0 | int oflag; |
4836 | 0 | int _return_value; |
4837 | |
|
4838 | 0 | oflag = PyLong_AsInt(arg); |
4839 | 0 | if (oflag == -1 && PyErr_Occurred()) { |
4840 | 0 | goto exit; |
4841 | 0 | } |
4842 | 0 | _return_value = os_posix_openpt_impl(module, oflag); |
4843 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
4844 | 0 | goto exit; |
4845 | 0 | } |
4846 | 0 | return_value = PyLong_FromLong((long)_return_value); |
4847 | |
|
4848 | 0 | exit: |
4849 | 0 | return return_value; |
4850 | 0 | } |
4851 | | |
4852 | | #endif /* defined(HAVE_POSIX_OPENPT) */ |
4853 | | |
4854 | | #if defined(HAVE_GRANTPT) |
4855 | | |
4856 | | PyDoc_STRVAR(os_grantpt__doc__, |
4857 | | "grantpt($module, fd, /)\n" |
4858 | | "--\n" |
4859 | | "\n" |
4860 | | "Grant access to the slave pseudo-terminal device.\n" |
4861 | | "\n" |
4862 | | " fd\n" |
4863 | | " File descriptor of a master pseudo-terminal device.\n" |
4864 | | "\n" |
4865 | | "Performs a grantpt() C function call."); |
4866 | | |
4867 | | #define OS_GRANTPT_METHODDEF \ |
4868 | | {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__}, |
4869 | | |
4870 | | static PyObject * |
4871 | | os_grantpt_impl(PyObject *module, int fd); |
4872 | | |
4873 | | static PyObject * |
4874 | | os_grantpt(PyObject *module, PyObject *arg) |
4875 | 0 | { |
4876 | 0 | PyObject *return_value = NULL; |
4877 | 0 | int fd; |
4878 | |
|
4879 | 0 | fd = PyObject_AsFileDescriptor(arg); |
4880 | 0 | if (fd < 0) { |
4881 | 0 | goto exit; |
4882 | 0 | } |
4883 | 0 | return_value = os_grantpt_impl(module, fd); |
4884 | |
|
4885 | 0 | exit: |
4886 | 0 | return return_value; |
4887 | 0 | } |
4888 | | |
4889 | | #endif /* defined(HAVE_GRANTPT) */ |
4890 | | |
4891 | | #if defined(HAVE_UNLOCKPT) |
4892 | | |
4893 | | PyDoc_STRVAR(os_unlockpt__doc__, |
4894 | | "unlockpt($module, fd, /)\n" |
4895 | | "--\n" |
4896 | | "\n" |
4897 | | "Unlock a pseudo-terminal master/slave pair.\n" |
4898 | | "\n" |
4899 | | " fd\n" |
4900 | | " File descriptor of a master pseudo-terminal device.\n" |
4901 | | "\n" |
4902 | | "Performs an unlockpt() C function call."); |
4903 | | |
4904 | | #define OS_UNLOCKPT_METHODDEF \ |
4905 | | {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__}, |
4906 | | |
4907 | | static PyObject * |
4908 | | os_unlockpt_impl(PyObject *module, int fd); |
4909 | | |
4910 | | static PyObject * |
4911 | | os_unlockpt(PyObject *module, PyObject *arg) |
4912 | 0 | { |
4913 | 0 | PyObject *return_value = NULL; |
4914 | 0 | int fd; |
4915 | |
|
4916 | 0 | fd = PyObject_AsFileDescriptor(arg); |
4917 | 0 | if (fd < 0) { |
4918 | 0 | goto exit; |
4919 | 0 | } |
4920 | 0 | return_value = os_unlockpt_impl(module, fd); |
4921 | |
|
4922 | 0 | exit: |
4923 | 0 | return return_value; |
4924 | 0 | } |
4925 | | |
4926 | | #endif /* defined(HAVE_UNLOCKPT) */ |
4927 | | |
4928 | | #if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) |
4929 | | |
4930 | | PyDoc_STRVAR(os_ptsname__doc__, |
4931 | | "ptsname($module, fd, /)\n" |
4932 | | "--\n" |
4933 | | "\n" |
4934 | | "Return the name of the slave pseudo-terminal device.\n" |
4935 | | "\n" |
4936 | | " fd\n" |
4937 | | " File descriptor of a master pseudo-terminal device.\n" |
4938 | | "\n" |
4939 | | "If the ptsname_r() C function is available, it is called;\n" |
4940 | | "otherwise, performs a ptsname() C function call."); |
4941 | | |
4942 | | #define OS_PTSNAME_METHODDEF \ |
4943 | | {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__}, |
4944 | | |
4945 | | static PyObject * |
4946 | | os_ptsname_impl(PyObject *module, int fd); |
4947 | | |
4948 | | static PyObject * |
4949 | | os_ptsname(PyObject *module, PyObject *arg) |
4950 | 0 | { |
4951 | 0 | PyObject *return_value = NULL; |
4952 | 0 | int fd; |
4953 | |
|
4954 | 0 | fd = PyObject_AsFileDescriptor(arg); |
4955 | 0 | if (fd < 0) { |
4956 | 0 | goto exit; |
4957 | 0 | } |
4958 | 0 | return_value = os_ptsname_impl(module, fd); |
4959 | |
|
4960 | 0 | exit: |
4961 | 0 | return return_value; |
4962 | 0 | } |
4963 | | |
4964 | | #endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */ |
4965 | | |
4966 | | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
4967 | | |
4968 | | PyDoc_STRVAR(os_openpty__doc__, |
4969 | | "openpty($module, /)\n" |
4970 | | "--\n" |
4971 | | "\n" |
4972 | | "Open a pseudo-terminal.\n" |
4973 | | "\n" |
4974 | | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
4975 | | "for both the master and slave ends."); |
4976 | | |
4977 | | #define OS_OPENPTY_METHODDEF \ |
4978 | | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
4979 | | |
4980 | | static PyObject * |
4981 | | os_openpty_impl(PyObject *module); |
4982 | | |
4983 | | static PyObject * |
4984 | | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4985 | 0 | { |
4986 | 0 | return os_openpty_impl(module); |
4987 | 0 | } |
4988 | | |
4989 | | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
4990 | | |
4991 | | #if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) |
4992 | | |
4993 | | PyDoc_STRVAR(os_login_tty__doc__, |
4994 | | "login_tty($module, fd, /)\n" |
4995 | | "--\n" |
4996 | | "\n" |
4997 | | "Prepare the tty of which fd is a file descriptor for a new login session.\n" |
4998 | | "\n" |
4999 | | "Make the calling process a session leader; make the tty the\n" |
5000 | | "controlling tty, the stdin, the stdout, and the stderr of the\n" |
5001 | | "calling process; close fd."); |
5002 | | |
5003 | | #define OS_LOGIN_TTY_METHODDEF \ |
5004 | | {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, |
5005 | | |
5006 | | static PyObject * |
5007 | | os_login_tty_impl(PyObject *module, int fd); |
5008 | | |
5009 | | static PyObject * |
5010 | | os_login_tty(PyObject *module, PyObject *arg) |
5011 | 0 | { |
5012 | 0 | PyObject *return_value = NULL; |
5013 | 0 | int fd; |
5014 | |
|
5015 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5016 | 0 | if (fd < 0) { |
5017 | 0 | goto exit; |
5018 | 0 | } |
5019 | 0 | return_value = os_login_tty_impl(module, fd); |
5020 | |
|
5021 | 0 | exit: |
5022 | 0 | return return_value; |
5023 | 0 | } |
5024 | | |
5025 | | #endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ |
5026 | | |
5027 | | #if defined(HAVE_FORKPTY) |
5028 | | |
5029 | | PyDoc_STRVAR(os_forkpty__doc__, |
5030 | | "forkpty($module, /)\n" |
5031 | | "--\n" |
5032 | | "\n" |
5033 | | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
5034 | | "\n" |
5035 | | "Returns a tuple of (pid, master_fd).\n" |
5036 | | "Like fork(), return pid of 0 to the child process,\n" |
5037 | | "and pid of child to the parent process.\n" |
5038 | | "To both, return fd of newly opened pseudo-terminal."); |
5039 | | |
5040 | | #define OS_FORKPTY_METHODDEF \ |
5041 | | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
5042 | | |
5043 | | static PyObject * |
5044 | | os_forkpty_impl(PyObject *module); |
5045 | | |
5046 | | static PyObject * |
5047 | | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5048 | 0 | { |
5049 | 0 | return os_forkpty_impl(module); |
5050 | 0 | } |
5051 | | |
5052 | | #endif /* defined(HAVE_FORKPTY) */ |
5053 | | |
5054 | | #if defined(HAVE_GETEGID) |
5055 | | |
5056 | | PyDoc_STRVAR(os_getegid__doc__, |
5057 | | "getegid($module, /)\n" |
5058 | | "--\n" |
5059 | | "\n" |
5060 | | "Return the current process\'s effective group id."); |
5061 | | |
5062 | | #define OS_GETEGID_METHODDEF \ |
5063 | | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
5064 | | |
5065 | | static PyObject * |
5066 | | os_getegid_impl(PyObject *module); |
5067 | | |
5068 | | static PyObject * |
5069 | | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5070 | 16 | { |
5071 | 16 | return os_getegid_impl(module); |
5072 | 16 | } |
5073 | | |
5074 | | #endif /* defined(HAVE_GETEGID) */ |
5075 | | |
5076 | | #if defined(HAVE_GETEUID) |
5077 | | |
5078 | | PyDoc_STRVAR(os_geteuid__doc__, |
5079 | | "geteuid($module, /)\n" |
5080 | | "--\n" |
5081 | | "\n" |
5082 | | "Return the current process\'s effective user id."); |
5083 | | |
5084 | | #define OS_GETEUID_METHODDEF \ |
5085 | | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
5086 | | |
5087 | | static PyObject * |
5088 | | os_geteuid_impl(PyObject *module); |
5089 | | |
5090 | | static PyObject * |
5091 | | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5092 | 16 | { |
5093 | 16 | return os_geteuid_impl(module); |
5094 | 16 | } |
5095 | | |
5096 | | #endif /* defined(HAVE_GETEUID) */ |
5097 | | |
5098 | | #if defined(HAVE_GETGID) |
5099 | | |
5100 | | PyDoc_STRVAR(os_getgid__doc__, |
5101 | | "getgid($module, /)\n" |
5102 | | "--\n" |
5103 | | "\n" |
5104 | | "Return the current process\'s group id."); |
5105 | | |
5106 | | #define OS_GETGID_METHODDEF \ |
5107 | | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
5108 | | |
5109 | | static PyObject * |
5110 | | os_getgid_impl(PyObject *module); |
5111 | | |
5112 | | static PyObject * |
5113 | | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5114 | 16 | { |
5115 | 16 | return os_getgid_impl(module); |
5116 | 16 | } |
5117 | | |
5118 | | #endif /* defined(HAVE_GETGID) */ |
5119 | | |
5120 | | #if defined(HAVE_GETPID) |
5121 | | |
5122 | | PyDoc_STRVAR(os_getpid__doc__, |
5123 | | "getpid($module, /)\n" |
5124 | | "--\n" |
5125 | | "\n" |
5126 | | "Return the current process id."); |
5127 | | |
5128 | | #define OS_GETPID_METHODDEF \ |
5129 | | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
5130 | | |
5131 | | static PyObject * |
5132 | | os_getpid_impl(PyObject *module); |
5133 | | |
5134 | | static PyObject * |
5135 | | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5136 | 0 | { |
5137 | 0 | return os_getpid_impl(module); |
5138 | 0 | } |
5139 | | |
5140 | | #endif /* defined(HAVE_GETPID) */ |
5141 | | |
5142 | | #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__) |
5143 | | |
5144 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5145 | | "getgrouplist($module, user, group, /)\n" |
5146 | | "--\n" |
5147 | | "\n" |
5148 | | "Returns a list of groups to which a user belongs.\n" |
5149 | | "\n" |
5150 | | " user\n" |
5151 | | " username to lookup\n" |
5152 | | " group\n" |
5153 | | " base group id of the user"); |
5154 | | |
5155 | | #define OS_GETGROUPLIST_METHODDEF \ |
5156 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5157 | | |
5158 | | static PyObject * |
5159 | | os_getgrouplist_impl(PyObject *module, const char *user, int basegid); |
5160 | | |
5161 | | static PyObject * |
5162 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5163 | | { |
5164 | | PyObject *return_value = NULL; |
5165 | | const char *user; |
5166 | | int basegid; |
5167 | | |
5168 | | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5169 | | goto exit; |
5170 | | } |
5171 | | if (!PyUnicode_Check(args[0])) { |
5172 | | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5173 | | goto exit; |
5174 | | } |
5175 | | Py_ssize_t user_length; |
5176 | | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
5177 | | if (user == NULL) { |
5178 | | goto exit; |
5179 | | } |
5180 | | if (strlen(user) != (size_t)user_length) { |
5181 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
5182 | | goto exit; |
5183 | | } |
5184 | | basegid = PyLong_AsInt(args[1]); |
5185 | | if (basegid == -1 && PyErr_Occurred()) { |
5186 | | goto exit; |
5187 | | } |
5188 | | return_value = os_getgrouplist_impl(module, user, basegid); |
5189 | | |
5190 | | exit: |
5191 | | return return_value; |
5192 | | } |
5193 | | |
5194 | | #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */ |
5195 | | |
5196 | | #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) |
5197 | | |
5198 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5199 | | "getgrouplist($module, user, group, /)\n" |
5200 | | "--\n" |
5201 | | "\n" |
5202 | | "Returns a list of groups to which a user belongs.\n" |
5203 | | "\n" |
5204 | | " user\n" |
5205 | | " username to lookup\n" |
5206 | | " group\n" |
5207 | | " base group id of the user"); |
5208 | | |
5209 | | #define OS_GETGROUPLIST_METHODDEF \ |
5210 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5211 | | |
5212 | | static PyObject * |
5213 | | os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid); |
5214 | | |
5215 | | static PyObject * |
5216 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5217 | 0 | { |
5218 | 0 | PyObject *return_value = NULL; |
5219 | 0 | const char *user; |
5220 | 0 | gid_t basegid; |
5221 | |
|
5222 | 0 | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5223 | 0 | goto exit; |
5224 | 0 | } |
5225 | 0 | if (!PyUnicode_Check(args[0])) { |
5226 | 0 | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5227 | 0 | goto exit; |
5228 | 0 | } |
5229 | 0 | Py_ssize_t user_length; |
5230 | 0 | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
5231 | 0 | if (user == NULL) { |
5232 | 0 | goto exit; |
5233 | 0 | } |
5234 | 0 | if (strlen(user) != (size_t)user_length) { |
5235 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
5236 | 0 | goto exit; |
5237 | 0 | } |
5238 | 0 | if (!_Py_Gid_Converter(args[1], &basegid)) { |
5239 | 0 | goto exit; |
5240 | 0 | } |
5241 | 0 | return_value = os_getgrouplist_impl(module, user, basegid); |
5242 | |
|
5243 | 0 | exit: |
5244 | 0 | return return_value; |
5245 | 0 | } |
5246 | | |
5247 | | #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */ |
5248 | | |
5249 | | #if defined(HAVE_GETGROUPS) |
5250 | | |
5251 | | PyDoc_STRVAR(os_getgroups__doc__, |
5252 | | "getgroups($module, /)\n" |
5253 | | "--\n" |
5254 | | "\n" |
5255 | | "Return list of supplemental group IDs for the process."); |
5256 | | |
5257 | | #define OS_GETGROUPS_METHODDEF \ |
5258 | | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
5259 | | |
5260 | | static PyObject * |
5261 | | os_getgroups_impl(PyObject *module); |
5262 | | |
5263 | | static PyObject * |
5264 | | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5265 | 0 | { |
5266 | 0 | return os_getgroups_impl(module); |
5267 | 0 | } |
5268 | | |
5269 | | #endif /* defined(HAVE_GETGROUPS) */ |
5270 | | |
5271 | | #if defined(HAVE_INITGROUPS) && defined(__APPLE__) |
5272 | | |
5273 | | PyDoc_STRVAR(os_initgroups__doc__, |
5274 | | "initgroups($module, username, gid, /)\n" |
5275 | | "--\n" |
5276 | | "\n" |
5277 | | "Initialize the group access list.\n" |
5278 | | "\n" |
5279 | | "Call the system initgroups() to initialize the group access list with all of\n" |
5280 | | "the groups of which the specified username is a member, plus the specified\n" |
5281 | | "group id."); |
5282 | | |
5283 | | #define OS_INITGROUPS_METHODDEF \ |
5284 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5285 | | |
5286 | | static PyObject * |
5287 | | os_initgroups_impl(PyObject *module, PyObject *oname, int gid); |
5288 | | |
5289 | | static PyObject * |
5290 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5291 | | { |
5292 | | PyObject *return_value = NULL; |
5293 | | PyObject *oname = NULL; |
5294 | | int gid; |
5295 | | |
5296 | | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5297 | | goto exit; |
5298 | | } |
5299 | | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5300 | | goto exit; |
5301 | | } |
5302 | | gid = PyLong_AsInt(args[1]); |
5303 | | if (gid == -1 && PyErr_Occurred()) { |
5304 | | goto exit; |
5305 | | } |
5306 | | return_value = os_initgroups_impl(module, oname, gid); |
5307 | | |
5308 | | exit: |
5309 | | /* Cleanup for oname */ |
5310 | | Py_XDECREF(oname); |
5311 | | |
5312 | | return return_value; |
5313 | | } |
5314 | | |
5315 | | #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */ |
5316 | | |
5317 | | #if defined(HAVE_INITGROUPS) && !defined(__APPLE__) |
5318 | | |
5319 | | PyDoc_STRVAR(os_initgroups__doc__, |
5320 | | "initgroups($module, username, gid, /)\n" |
5321 | | "--\n" |
5322 | | "\n" |
5323 | | "Initialize the group access list.\n" |
5324 | | "\n" |
5325 | | "Call the system initgroups() to initialize the group access list with all of\n" |
5326 | | "the groups of which the specified username is a member, plus the specified\n" |
5327 | | "group id."); |
5328 | | |
5329 | | #define OS_INITGROUPS_METHODDEF \ |
5330 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5331 | | |
5332 | | static PyObject * |
5333 | | os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid); |
5334 | | |
5335 | | static PyObject * |
5336 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5337 | 0 | { |
5338 | 0 | PyObject *return_value = NULL; |
5339 | 0 | PyObject *oname = NULL; |
5340 | 0 | gid_t gid; |
5341 | |
|
5342 | 0 | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5343 | 0 | goto exit; |
5344 | 0 | } |
5345 | 0 | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5346 | 0 | goto exit; |
5347 | 0 | } |
5348 | 0 | if (!_Py_Gid_Converter(args[1], &gid)) { |
5349 | 0 | goto exit; |
5350 | 0 | } |
5351 | 0 | return_value = os_initgroups_impl(module, oname, gid); |
5352 | |
|
5353 | 0 | exit: |
5354 | | /* Cleanup for oname */ |
5355 | 0 | Py_XDECREF(oname); |
5356 | |
|
5357 | 0 | return return_value; |
5358 | 0 | } |
5359 | | |
5360 | | #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */ |
5361 | | |
5362 | | #if defined(HAVE_GETPGID) |
5363 | | |
5364 | | PyDoc_STRVAR(os_getpgid__doc__, |
5365 | | "getpgid($module, /, pid)\n" |
5366 | | "--\n" |
5367 | | "\n" |
5368 | | "Call the system call getpgid(), and return the result."); |
5369 | | |
5370 | | #define OS_GETPGID_METHODDEF \ |
5371 | | {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__}, |
5372 | | |
5373 | | static PyObject * |
5374 | | os_getpgid_impl(PyObject *module, pid_t pid); |
5375 | | |
5376 | | static PyObject * |
5377 | | os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5378 | 0 | { |
5379 | 0 | PyObject *return_value = NULL; |
5380 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
5381 | |
|
5382 | 0 | #define NUM_KEYWORDS 1 |
5383 | 0 | static struct { |
5384 | 0 | PyGC_Head _this_is_not_used; |
5385 | 0 | PyObject_VAR_HEAD |
5386 | 0 | Py_hash_t ob_hash; |
5387 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
5388 | 0 | } _kwtuple = { |
5389 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
5390 | 0 | .ob_hash = -1, |
5391 | 0 | .ob_item = { &_Py_ID(pid), }, |
5392 | 0 | }; |
5393 | 0 | #undef NUM_KEYWORDS |
5394 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
5395 | |
|
5396 | | #else // !Py_BUILD_CORE |
5397 | | # define KWTUPLE NULL |
5398 | | #endif // !Py_BUILD_CORE |
5399 | |
|
5400 | 0 | static const char * const _keywords[] = {"pid", NULL}; |
5401 | 0 | static _PyArg_Parser _parser = { |
5402 | 0 | .keywords = _keywords, |
5403 | 0 | .fname = "getpgid", |
5404 | 0 | .kwtuple = KWTUPLE, |
5405 | 0 | }; |
5406 | 0 | #undef KWTUPLE |
5407 | 0 | PyObject *argsbuf[1]; |
5408 | 0 | pid_t pid; |
5409 | |
|
5410 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
5411 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
5412 | 0 | if (!args) { |
5413 | 0 | goto exit; |
5414 | 0 | } |
5415 | 0 | pid = PyLong_AsPid(args[0]); |
5416 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5417 | 0 | goto exit; |
5418 | 0 | } |
5419 | 0 | return_value = os_getpgid_impl(module, pid); |
5420 | |
|
5421 | 0 | exit: |
5422 | 0 | return return_value; |
5423 | 0 | } |
5424 | | |
5425 | | #endif /* defined(HAVE_GETPGID) */ |
5426 | | |
5427 | | #if defined(HAVE_GETPGRP) |
5428 | | |
5429 | | PyDoc_STRVAR(os_getpgrp__doc__, |
5430 | | "getpgrp($module, /)\n" |
5431 | | "--\n" |
5432 | | "\n" |
5433 | | "Return the current process group id."); |
5434 | | |
5435 | | #define OS_GETPGRP_METHODDEF \ |
5436 | | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
5437 | | |
5438 | | static PyObject * |
5439 | | os_getpgrp_impl(PyObject *module); |
5440 | | |
5441 | | static PyObject * |
5442 | | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5443 | 0 | { |
5444 | 0 | return os_getpgrp_impl(module); |
5445 | 0 | } |
5446 | | |
5447 | | #endif /* defined(HAVE_GETPGRP) */ |
5448 | | |
5449 | | #if defined(HAVE_SETPGRP) |
5450 | | |
5451 | | PyDoc_STRVAR(os_setpgrp__doc__, |
5452 | | "setpgrp($module, /)\n" |
5453 | | "--\n" |
5454 | | "\n" |
5455 | | "Make the current process the leader of its process group."); |
5456 | | |
5457 | | #define OS_SETPGRP_METHODDEF \ |
5458 | | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
5459 | | |
5460 | | static PyObject * |
5461 | | os_setpgrp_impl(PyObject *module); |
5462 | | |
5463 | | static PyObject * |
5464 | | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5465 | 0 | { |
5466 | 0 | return os_setpgrp_impl(module); |
5467 | 0 | } |
5468 | | |
5469 | | #endif /* defined(HAVE_SETPGRP) */ |
5470 | | |
5471 | | #if defined(HAVE_GETPPID) |
5472 | | |
5473 | | PyDoc_STRVAR(os_getppid__doc__, |
5474 | | "getppid($module, /)\n" |
5475 | | "--\n" |
5476 | | "\n" |
5477 | | "Return the parent\'s process id.\n" |
5478 | | "\n" |
5479 | | "If the parent process has already exited, Windows machines will still\n" |
5480 | | "return its id; others systems will return the id of the \'init\' process (1)."); |
5481 | | |
5482 | | #define OS_GETPPID_METHODDEF \ |
5483 | | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
5484 | | |
5485 | | static PyObject * |
5486 | | os_getppid_impl(PyObject *module); |
5487 | | |
5488 | | static PyObject * |
5489 | | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5490 | 0 | { |
5491 | 0 | return os_getppid_impl(module); |
5492 | 0 | } |
5493 | | |
5494 | | #endif /* defined(HAVE_GETPPID) */ |
5495 | | |
5496 | | #if defined(HAVE_GETLOGIN) |
5497 | | |
5498 | | PyDoc_STRVAR(os_getlogin__doc__, |
5499 | | "getlogin($module, /)\n" |
5500 | | "--\n" |
5501 | | "\n" |
5502 | | "Return the actual login name."); |
5503 | | |
5504 | | #define OS_GETLOGIN_METHODDEF \ |
5505 | | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
5506 | | |
5507 | | static PyObject * |
5508 | | os_getlogin_impl(PyObject *module); |
5509 | | |
5510 | | static PyObject * |
5511 | | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5512 | 0 | { |
5513 | 0 | return os_getlogin_impl(module); |
5514 | 0 | } |
5515 | | |
5516 | | #endif /* defined(HAVE_GETLOGIN) */ |
5517 | | |
5518 | | #if defined(HAVE_GETUID) |
5519 | | |
5520 | | PyDoc_STRVAR(os_getuid__doc__, |
5521 | | "getuid($module, /)\n" |
5522 | | "--\n" |
5523 | | "\n" |
5524 | | "Return the current process\'s user id."); |
5525 | | |
5526 | | #define OS_GETUID_METHODDEF \ |
5527 | | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
5528 | | |
5529 | | static PyObject * |
5530 | | os_getuid_impl(PyObject *module); |
5531 | | |
5532 | | static PyObject * |
5533 | | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5534 | 16 | { |
5535 | 16 | return os_getuid_impl(module); |
5536 | 16 | } |
5537 | | |
5538 | | #endif /* defined(HAVE_GETUID) */ |
5539 | | |
5540 | | #if defined(HAVE_KILL) |
5541 | | |
5542 | | PyDoc_STRVAR(os_kill__doc__, |
5543 | | "kill($module, pid, signal, /)\n" |
5544 | | "--\n" |
5545 | | "\n" |
5546 | | "Kill a process with a signal."); |
5547 | | |
5548 | | #define OS_KILL_METHODDEF \ |
5549 | | {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__}, |
5550 | | |
5551 | | static PyObject * |
5552 | | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
5553 | | |
5554 | | static PyObject * |
5555 | | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5556 | 0 | { |
5557 | 0 | PyObject *return_value = NULL; |
5558 | 0 | pid_t pid; |
5559 | 0 | Py_ssize_t signal; |
5560 | |
|
5561 | 0 | if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) { |
5562 | 0 | goto exit; |
5563 | 0 | } |
5564 | 0 | pid = PyLong_AsPid(args[0]); |
5565 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5566 | 0 | goto exit; |
5567 | 0 | } |
5568 | 0 | { |
5569 | 0 | Py_ssize_t ival = -1; |
5570 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
5571 | 0 | if (iobj != NULL) { |
5572 | 0 | ival = PyLong_AsSsize_t(iobj); |
5573 | 0 | Py_DECREF(iobj); |
5574 | 0 | } |
5575 | 0 | if (ival == -1 && PyErr_Occurred()) { |
5576 | 0 | goto exit; |
5577 | 0 | } |
5578 | 0 | signal = ival; |
5579 | 0 | } |
5580 | 0 | return_value = os_kill_impl(module, pid, signal); |
5581 | |
|
5582 | 0 | exit: |
5583 | 0 | return return_value; |
5584 | 0 | } |
5585 | | |
5586 | | #endif /* defined(HAVE_KILL) */ |
5587 | | |
5588 | | #if defined(HAVE_KILLPG) |
5589 | | |
5590 | | PyDoc_STRVAR(os_killpg__doc__, |
5591 | | "killpg($module, pgid, signal, /)\n" |
5592 | | "--\n" |
5593 | | "\n" |
5594 | | "Kill a process group with a signal."); |
5595 | | |
5596 | | #define OS_KILLPG_METHODDEF \ |
5597 | | {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__}, |
5598 | | |
5599 | | static PyObject * |
5600 | | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
5601 | | |
5602 | | static PyObject * |
5603 | | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5604 | 0 | { |
5605 | 0 | PyObject *return_value = NULL; |
5606 | 0 | pid_t pgid; |
5607 | 0 | int signal; |
5608 | |
|
5609 | 0 | if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) { |
5610 | 0 | goto exit; |
5611 | 0 | } |
5612 | 0 | pgid = PyLong_AsPid(args[0]); |
5613 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
5614 | 0 | goto exit; |
5615 | 0 | } |
5616 | 0 | signal = PyLong_AsInt(args[1]); |
5617 | 0 | if (signal == -1 && PyErr_Occurred()) { |
5618 | 0 | goto exit; |
5619 | 0 | } |
5620 | 0 | return_value = os_killpg_impl(module, pgid, signal); |
5621 | |
|
5622 | 0 | exit: |
5623 | 0 | return return_value; |
5624 | 0 | } |
5625 | | |
5626 | | #endif /* defined(HAVE_KILLPG) */ |
5627 | | |
5628 | | #if defined(HAVE_PLOCK) |
5629 | | |
5630 | | PyDoc_STRVAR(os_plock__doc__, |
5631 | | "plock($module, op, /)\n" |
5632 | | "--\n" |
5633 | | "\n" |
5634 | | "Lock program segments into memory.\");"); |
5635 | | |
5636 | | #define OS_PLOCK_METHODDEF \ |
5637 | | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
5638 | | |
5639 | | static PyObject * |
5640 | | os_plock_impl(PyObject *module, int op); |
5641 | | |
5642 | | static PyObject * |
5643 | | os_plock(PyObject *module, PyObject *arg) |
5644 | | { |
5645 | | PyObject *return_value = NULL; |
5646 | | int op; |
5647 | | |
5648 | | op = PyLong_AsInt(arg); |
5649 | | if (op == -1 && PyErr_Occurred()) { |
5650 | | goto exit; |
5651 | | } |
5652 | | return_value = os_plock_impl(module, op); |
5653 | | |
5654 | | exit: |
5655 | | return return_value; |
5656 | | } |
5657 | | |
5658 | | #endif /* defined(HAVE_PLOCK) */ |
5659 | | |
5660 | | #if defined(HAVE_SETUID) |
5661 | | |
5662 | | PyDoc_STRVAR(os_setuid__doc__, |
5663 | | "setuid($module, uid, /)\n" |
5664 | | "--\n" |
5665 | | "\n" |
5666 | | "Set the current process\'s user id."); |
5667 | | |
5668 | | #define OS_SETUID_METHODDEF \ |
5669 | | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
5670 | | |
5671 | | static PyObject * |
5672 | | os_setuid_impl(PyObject *module, uid_t uid); |
5673 | | |
5674 | | static PyObject * |
5675 | | os_setuid(PyObject *module, PyObject *arg) |
5676 | 0 | { |
5677 | 0 | PyObject *return_value = NULL; |
5678 | 0 | uid_t uid; |
5679 | |
|
5680 | 0 | if (!_Py_Uid_Converter(arg, &uid)) { |
5681 | 0 | goto exit; |
5682 | 0 | } |
5683 | 0 | return_value = os_setuid_impl(module, uid); |
5684 | |
|
5685 | 0 | exit: |
5686 | 0 | return return_value; |
5687 | 0 | } |
5688 | | |
5689 | | #endif /* defined(HAVE_SETUID) */ |
5690 | | |
5691 | | #if defined(HAVE_SETEUID) |
5692 | | |
5693 | | PyDoc_STRVAR(os_seteuid__doc__, |
5694 | | "seteuid($module, euid, /)\n" |
5695 | | "--\n" |
5696 | | "\n" |
5697 | | "Set the current process\'s effective user id."); |
5698 | | |
5699 | | #define OS_SETEUID_METHODDEF \ |
5700 | | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
5701 | | |
5702 | | static PyObject * |
5703 | | os_seteuid_impl(PyObject *module, uid_t euid); |
5704 | | |
5705 | | static PyObject * |
5706 | | os_seteuid(PyObject *module, PyObject *arg) |
5707 | 0 | { |
5708 | 0 | PyObject *return_value = NULL; |
5709 | 0 | uid_t euid; |
5710 | |
|
5711 | 0 | if (!_Py_Uid_Converter(arg, &euid)) { |
5712 | 0 | goto exit; |
5713 | 0 | } |
5714 | 0 | return_value = os_seteuid_impl(module, euid); |
5715 | |
|
5716 | 0 | exit: |
5717 | 0 | return return_value; |
5718 | 0 | } |
5719 | | |
5720 | | #endif /* defined(HAVE_SETEUID) */ |
5721 | | |
5722 | | #if defined(HAVE_SETEGID) |
5723 | | |
5724 | | PyDoc_STRVAR(os_setegid__doc__, |
5725 | | "setegid($module, egid, /)\n" |
5726 | | "--\n" |
5727 | | "\n" |
5728 | | "Set the current process\'s effective group id."); |
5729 | | |
5730 | | #define OS_SETEGID_METHODDEF \ |
5731 | | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
5732 | | |
5733 | | static PyObject * |
5734 | | os_setegid_impl(PyObject *module, gid_t egid); |
5735 | | |
5736 | | static PyObject * |
5737 | | os_setegid(PyObject *module, PyObject *arg) |
5738 | 0 | { |
5739 | 0 | PyObject *return_value = NULL; |
5740 | 0 | gid_t egid; |
5741 | |
|
5742 | 0 | if (!_Py_Gid_Converter(arg, &egid)) { |
5743 | 0 | goto exit; |
5744 | 0 | } |
5745 | 0 | return_value = os_setegid_impl(module, egid); |
5746 | |
|
5747 | 0 | exit: |
5748 | 0 | return return_value; |
5749 | 0 | } |
5750 | | |
5751 | | #endif /* defined(HAVE_SETEGID) */ |
5752 | | |
5753 | | #if defined(HAVE_SETREUID) |
5754 | | |
5755 | | PyDoc_STRVAR(os_setreuid__doc__, |
5756 | | "setreuid($module, ruid, euid, /)\n" |
5757 | | "--\n" |
5758 | | "\n" |
5759 | | "Set the current process\'s real and effective user ids."); |
5760 | | |
5761 | | #define OS_SETREUID_METHODDEF \ |
5762 | | {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__}, |
5763 | | |
5764 | | static PyObject * |
5765 | | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
5766 | | |
5767 | | static PyObject * |
5768 | | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5769 | 0 | { |
5770 | 0 | PyObject *return_value = NULL; |
5771 | 0 | uid_t ruid; |
5772 | 0 | uid_t euid; |
5773 | |
|
5774 | 0 | if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { |
5775 | 0 | goto exit; |
5776 | 0 | } |
5777 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
5778 | 0 | goto exit; |
5779 | 0 | } |
5780 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
5781 | 0 | goto exit; |
5782 | 0 | } |
5783 | 0 | return_value = os_setreuid_impl(module, ruid, euid); |
5784 | |
|
5785 | 0 | exit: |
5786 | 0 | return return_value; |
5787 | 0 | } |
5788 | | |
5789 | | #endif /* defined(HAVE_SETREUID) */ |
5790 | | |
5791 | | #if defined(HAVE_SETREGID) |
5792 | | |
5793 | | PyDoc_STRVAR(os_setregid__doc__, |
5794 | | "setregid($module, rgid, egid, /)\n" |
5795 | | "--\n" |
5796 | | "\n" |
5797 | | "Set the current process\'s real and effective group ids."); |
5798 | | |
5799 | | #define OS_SETREGID_METHODDEF \ |
5800 | | {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__}, |
5801 | | |
5802 | | static PyObject * |
5803 | | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
5804 | | |
5805 | | static PyObject * |
5806 | | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5807 | 0 | { |
5808 | 0 | PyObject *return_value = NULL; |
5809 | 0 | gid_t rgid; |
5810 | 0 | gid_t egid; |
5811 | |
|
5812 | 0 | if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { |
5813 | 0 | goto exit; |
5814 | 0 | } |
5815 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
5816 | 0 | goto exit; |
5817 | 0 | } |
5818 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
5819 | 0 | goto exit; |
5820 | 0 | } |
5821 | 0 | return_value = os_setregid_impl(module, rgid, egid); |
5822 | |
|
5823 | 0 | exit: |
5824 | 0 | return return_value; |
5825 | 0 | } |
5826 | | |
5827 | | #endif /* defined(HAVE_SETREGID) */ |
5828 | | |
5829 | | #if defined(HAVE_SETGID) |
5830 | | |
5831 | | PyDoc_STRVAR(os_setgid__doc__, |
5832 | | "setgid($module, gid, /)\n" |
5833 | | "--\n" |
5834 | | "\n" |
5835 | | "Set the current process\'s group id."); |
5836 | | |
5837 | | #define OS_SETGID_METHODDEF \ |
5838 | | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
5839 | | |
5840 | | static PyObject * |
5841 | | os_setgid_impl(PyObject *module, gid_t gid); |
5842 | | |
5843 | | static PyObject * |
5844 | | os_setgid(PyObject *module, PyObject *arg) |
5845 | 0 | { |
5846 | 0 | PyObject *return_value = NULL; |
5847 | 0 | gid_t gid; |
5848 | |
|
5849 | 0 | if (!_Py_Gid_Converter(arg, &gid)) { |
5850 | 0 | goto exit; |
5851 | 0 | } |
5852 | 0 | return_value = os_setgid_impl(module, gid); |
5853 | |
|
5854 | 0 | exit: |
5855 | 0 | return return_value; |
5856 | 0 | } |
5857 | | |
5858 | | #endif /* defined(HAVE_SETGID) */ |
5859 | | |
5860 | | #if defined(HAVE_SETGROUPS) |
5861 | | |
5862 | | PyDoc_STRVAR(os_setgroups__doc__, |
5863 | | "setgroups($module, groups, /)\n" |
5864 | | "--\n" |
5865 | | "\n" |
5866 | | "Set the groups of the current process to list."); |
5867 | | |
5868 | | #define OS_SETGROUPS_METHODDEF \ |
5869 | | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
5870 | | |
5871 | | #endif /* defined(HAVE_SETGROUPS) */ |
5872 | | |
5873 | | #if defined(HAVE_WAIT3) |
5874 | | |
5875 | | PyDoc_STRVAR(os_wait3__doc__, |
5876 | | "wait3($module, /, options)\n" |
5877 | | "--\n" |
5878 | | "\n" |
5879 | | "Wait for completion of a child process.\n" |
5880 | | "\n" |
5881 | | "Returns a tuple of information about the child process:\n" |
5882 | | " (pid, status, rusage)"); |
5883 | | |
5884 | | #define OS_WAIT3_METHODDEF \ |
5885 | | {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__}, |
5886 | | |
5887 | | static PyObject * |
5888 | | os_wait3_impl(PyObject *module, int options); |
5889 | | |
5890 | | static PyObject * |
5891 | | os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5892 | 0 | { |
5893 | 0 | PyObject *return_value = NULL; |
5894 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
5895 | |
|
5896 | 0 | #define NUM_KEYWORDS 1 |
5897 | 0 | static struct { |
5898 | 0 | PyGC_Head _this_is_not_used; |
5899 | 0 | PyObject_VAR_HEAD |
5900 | 0 | Py_hash_t ob_hash; |
5901 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
5902 | 0 | } _kwtuple = { |
5903 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
5904 | 0 | .ob_hash = -1, |
5905 | 0 | .ob_item = { &_Py_ID(options), }, |
5906 | 0 | }; |
5907 | 0 | #undef NUM_KEYWORDS |
5908 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
5909 | |
|
5910 | | #else // !Py_BUILD_CORE |
5911 | | # define KWTUPLE NULL |
5912 | | #endif // !Py_BUILD_CORE |
5913 | |
|
5914 | 0 | static const char * const _keywords[] = {"options", NULL}; |
5915 | 0 | static _PyArg_Parser _parser = { |
5916 | 0 | .keywords = _keywords, |
5917 | 0 | .fname = "wait3", |
5918 | 0 | .kwtuple = KWTUPLE, |
5919 | 0 | }; |
5920 | 0 | #undef KWTUPLE |
5921 | 0 | PyObject *argsbuf[1]; |
5922 | 0 | int options; |
5923 | |
|
5924 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
5925 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
5926 | 0 | if (!args) { |
5927 | 0 | goto exit; |
5928 | 0 | } |
5929 | 0 | options = PyLong_AsInt(args[0]); |
5930 | 0 | if (options == -1 && PyErr_Occurred()) { |
5931 | 0 | goto exit; |
5932 | 0 | } |
5933 | 0 | return_value = os_wait3_impl(module, options); |
5934 | |
|
5935 | 0 | exit: |
5936 | 0 | return return_value; |
5937 | 0 | } |
5938 | | |
5939 | | #endif /* defined(HAVE_WAIT3) */ |
5940 | | |
5941 | | #if defined(HAVE_WAIT4) |
5942 | | |
5943 | | PyDoc_STRVAR(os_wait4__doc__, |
5944 | | "wait4($module, /, pid, options)\n" |
5945 | | "--\n" |
5946 | | "\n" |
5947 | | "Wait for completion of a specific child process.\n" |
5948 | | "\n" |
5949 | | "Returns a tuple of information about the child process:\n" |
5950 | | " (pid, status, rusage)"); |
5951 | | |
5952 | | #define OS_WAIT4_METHODDEF \ |
5953 | | {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__}, |
5954 | | |
5955 | | static PyObject * |
5956 | | os_wait4_impl(PyObject *module, pid_t pid, int options); |
5957 | | |
5958 | | static PyObject * |
5959 | | os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5960 | 0 | { |
5961 | 0 | PyObject *return_value = NULL; |
5962 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
5963 | |
|
5964 | 0 | #define NUM_KEYWORDS 2 |
5965 | 0 | static struct { |
5966 | 0 | PyGC_Head _this_is_not_used; |
5967 | 0 | PyObject_VAR_HEAD |
5968 | 0 | Py_hash_t ob_hash; |
5969 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
5970 | 0 | } _kwtuple = { |
5971 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
5972 | 0 | .ob_hash = -1, |
5973 | 0 | .ob_item = { &_Py_ID(pid), &_Py_ID(options), }, |
5974 | 0 | }; |
5975 | 0 | #undef NUM_KEYWORDS |
5976 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
5977 | |
|
5978 | | #else // !Py_BUILD_CORE |
5979 | | # define KWTUPLE NULL |
5980 | | #endif // !Py_BUILD_CORE |
5981 | |
|
5982 | 0 | static const char * const _keywords[] = {"pid", "options", NULL}; |
5983 | 0 | static _PyArg_Parser _parser = { |
5984 | 0 | .keywords = _keywords, |
5985 | 0 | .fname = "wait4", |
5986 | 0 | .kwtuple = KWTUPLE, |
5987 | 0 | }; |
5988 | 0 | #undef KWTUPLE |
5989 | 0 | PyObject *argsbuf[2]; |
5990 | 0 | pid_t pid; |
5991 | 0 | int options; |
5992 | |
|
5993 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
5994 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
5995 | 0 | if (!args) { |
5996 | 0 | goto exit; |
5997 | 0 | } |
5998 | 0 | pid = PyLong_AsPid(args[0]); |
5999 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6000 | 0 | goto exit; |
6001 | 0 | } |
6002 | 0 | options = PyLong_AsInt(args[1]); |
6003 | 0 | if (options == -1 && PyErr_Occurred()) { |
6004 | 0 | goto exit; |
6005 | 0 | } |
6006 | 0 | return_value = os_wait4_impl(module, pid, options); |
6007 | |
|
6008 | 0 | exit: |
6009 | 0 | return return_value; |
6010 | 0 | } |
6011 | | |
6012 | | #endif /* defined(HAVE_WAIT4) */ |
6013 | | |
6014 | | #if defined(HAVE_WAITID) |
6015 | | |
6016 | | PyDoc_STRVAR(os_waitid__doc__, |
6017 | | "waitid($module, idtype, id, options, /)\n" |
6018 | | "--\n" |
6019 | | "\n" |
6020 | | "Returns the result of waiting for a process or processes.\n" |
6021 | | "\n" |
6022 | | " idtype\n" |
6023 | | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
6024 | | " id\n" |
6025 | | " The id to wait on.\n" |
6026 | | " options\n" |
6027 | | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
6028 | | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
6029 | | "\n" |
6030 | | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
6031 | | "no children in a waitable state."); |
6032 | | |
6033 | | #define OS_WAITID_METHODDEF \ |
6034 | | {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__}, |
6035 | | |
6036 | | static PyObject * |
6037 | | os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options); |
6038 | | |
6039 | | static PyObject * |
6040 | | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6041 | 0 | { |
6042 | 0 | PyObject *return_value = NULL; |
6043 | 0 | idtype_t idtype; |
6044 | 0 | id_t id; |
6045 | 0 | int options; |
6046 | |
|
6047 | 0 | if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) { |
6048 | 0 | goto exit; |
6049 | 0 | } |
6050 | 0 | if (!idtype_t_converter(args[0], &idtype)) { |
6051 | 0 | goto exit; |
6052 | 0 | } |
6053 | 0 | id = (id_t)PyLong_AsPid(args[1]); |
6054 | 0 | if (id == (id_t)(-1) && PyErr_Occurred()) { |
6055 | 0 | goto exit; |
6056 | 0 | } |
6057 | 0 | options = PyLong_AsInt(args[2]); |
6058 | 0 | if (options == -1 && PyErr_Occurred()) { |
6059 | 0 | goto exit; |
6060 | 0 | } |
6061 | 0 | return_value = os_waitid_impl(module, idtype, id, options); |
6062 | |
|
6063 | 0 | exit: |
6064 | 0 | return return_value; |
6065 | 0 | } |
6066 | | |
6067 | | #endif /* defined(HAVE_WAITID) */ |
6068 | | |
6069 | | #if defined(HAVE_WAITPID) |
6070 | | |
6071 | | PyDoc_STRVAR(os_waitpid__doc__, |
6072 | | "waitpid($module, pid, options, /)\n" |
6073 | | "--\n" |
6074 | | "\n" |
6075 | | "Wait for completion of a given child process.\n" |
6076 | | "\n" |
6077 | | "Returns a tuple of information regarding the child process:\n" |
6078 | | " (pid, status)\n" |
6079 | | "\n" |
6080 | | "The options argument is ignored on Windows."); |
6081 | | |
6082 | | #define OS_WAITPID_METHODDEF \ |
6083 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6084 | | |
6085 | | static PyObject * |
6086 | | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
6087 | | |
6088 | | static PyObject * |
6089 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6090 | 0 | { |
6091 | 0 | PyObject *return_value = NULL; |
6092 | 0 | pid_t pid; |
6093 | 0 | int options; |
6094 | |
|
6095 | 0 | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6096 | 0 | goto exit; |
6097 | 0 | } |
6098 | 0 | pid = PyLong_AsPid(args[0]); |
6099 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6100 | 0 | goto exit; |
6101 | 0 | } |
6102 | 0 | options = PyLong_AsInt(args[1]); |
6103 | 0 | if (options == -1 && PyErr_Occurred()) { |
6104 | 0 | goto exit; |
6105 | 0 | } |
6106 | 0 | return_value = os_waitpid_impl(module, pid, options); |
6107 | |
|
6108 | 0 | exit: |
6109 | 0 | return return_value; |
6110 | 0 | } |
6111 | | |
6112 | | #endif /* defined(HAVE_WAITPID) */ |
6113 | | |
6114 | | #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) |
6115 | | |
6116 | | PyDoc_STRVAR(os_waitpid__doc__, |
6117 | | "waitpid($module, pid, options, /)\n" |
6118 | | "--\n" |
6119 | | "\n" |
6120 | | "Wait for completion of a given process.\n" |
6121 | | "\n" |
6122 | | "Returns a tuple of information regarding the process:\n" |
6123 | | " (pid, status << 8)\n" |
6124 | | "\n" |
6125 | | "The options argument is ignored on Windows."); |
6126 | | |
6127 | | #define OS_WAITPID_METHODDEF \ |
6128 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6129 | | |
6130 | | static PyObject * |
6131 | | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
6132 | | |
6133 | | static PyObject * |
6134 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6135 | | { |
6136 | | PyObject *return_value = NULL; |
6137 | | intptr_t pid; |
6138 | | int options; |
6139 | | |
6140 | | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6141 | | goto exit; |
6142 | | } |
6143 | | pid = (intptr_t)PyLong_AsVoidPtr(args[0]); |
6144 | | if (!pid && PyErr_Occurred()) { |
6145 | | goto exit; |
6146 | | } |
6147 | | options = PyLong_AsInt(args[1]); |
6148 | | if (options == -1 && PyErr_Occurred()) { |
6149 | | goto exit; |
6150 | | } |
6151 | | return_value = os_waitpid_impl(module, pid, options); |
6152 | | |
6153 | | exit: |
6154 | | return return_value; |
6155 | | } |
6156 | | |
6157 | | #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */ |
6158 | | |
6159 | | #if defined(HAVE_WAIT) |
6160 | | |
6161 | | PyDoc_STRVAR(os_wait__doc__, |
6162 | | "wait($module, /)\n" |
6163 | | "--\n" |
6164 | | "\n" |
6165 | | "Wait for completion of a child process.\n" |
6166 | | "\n" |
6167 | | "Returns a tuple of information about the child process:\n" |
6168 | | " (pid, status)"); |
6169 | | |
6170 | | #define OS_WAIT_METHODDEF \ |
6171 | | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
6172 | | |
6173 | | static PyObject * |
6174 | | os_wait_impl(PyObject *module); |
6175 | | |
6176 | | static PyObject * |
6177 | | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6178 | 0 | { |
6179 | 0 | return os_wait_impl(module); |
6180 | 0 | } |
6181 | | |
6182 | | #endif /* defined(HAVE_WAIT) */ |
6183 | | |
6184 | | #if (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) |
6185 | | |
6186 | | PyDoc_STRVAR(os_pidfd_open__doc__, |
6187 | | "pidfd_open($module, /, pid, flags=0)\n" |
6188 | | "--\n" |
6189 | | "\n" |
6190 | | "Return a file descriptor referring to the process *pid*.\n" |
6191 | | "\n" |
6192 | | "The descriptor can be used to perform process management without races and\n" |
6193 | | "signals."); |
6194 | | |
6195 | | #define OS_PIDFD_OPEN_METHODDEF \ |
6196 | | {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__}, |
6197 | | |
6198 | | static PyObject * |
6199 | | os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags); |
6200 | | |
6201 | | static PyObject * |
6202 | | os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6203 | 0 | { |
6204 | 0 | PyObject *return_value = NULL; |
6205 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6206 | |
|
6207 | 0 | #define NUM_KEYWORDS 2 |
6208 | 0 | static struct { |
6209 | 0 | PyGC_Head _this_is_not_used; |
6210 | 0 | PyObject_VAR_HEAD |
6211 | 0 | Py_hash_t ob_hash; |
6212 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6213 | 0 | } _kwtuple = { |
6214 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6215 | 0 | .ob_hash = -1, |
6216 | 0 | .ob_item = { &_Py_ID(pid), &_Py_ID(flags), }, |
6217 | 0 | }; |
6218 | 0 | #undef NUM_KEYWORDS |
6219 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6220 | |
|
6221 | | #else // !Py_BUILD_CORE |
6222 | | # define KWTUPLE NULL |
6223 | | #endif // !Py_BUILD_CORE |
6224 | |
|
6225 | 0 | static const char * const _keywords[] = {"pid", "flags", NULL}; |
6226 | 0 | static _PyArg_Parser _parser = { |
6227 | 0 | .keywords = _keywords, |
6228 | 0 | .fname = "pidfd_open", |
6229 | 0 | .kwtuple = KWTUPLE, |
6230 | 0 | }; |
6231 | 0 | #undef KWTUPLE |
6232 | 0 | PyObject *argsbuf[2]; |
6233 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6234 | 0 | pid_t pid; |
6235 | 0 | unsigned int flags = 0; |
6236 | |
|
6237 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6238 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6239 | 0 | if (!args) { |
6240 | 0 | goto exit; |
6241 | 0 | } |
6242 | 0 | pid = PyLong_AsPid(args[0]); |
6243 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6244 | 0 | goto exit; |
6245 | 0 | } |
6246 | 0 | if (!noptargs) { |
6247 | 0 | goto skip_optional_pos; |
6248 | 0 | } |
6249 | 0 | if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) { |
6250 | 0 | goto exit; |
6251 | 0 | } |
6252 | 0 | skip_optional_pos: |
6253 | 0 | return_value = os_pidfd_open_impl(module, pid, flags); |
6254 | |
|
6255 | 0 | exit: |
6256 | 0 | return return_value; |
6257 | 0 | } |
6258 | | |
6259 | | #endif /* (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */ |
6260 | | |
6261 | | #if defined(HAVE_SETNS) |
6262 | | |
6263 | | PyDoc_STRVAR(os_setns__doc__, |
6264 | | "setns($module, /, fd, nstype=0)\n" |
6265 | | "--\n" |
6266 | | "\n" |
6267 | | "Move the calling thread into different namespaces.\n" |
6268 | | "\n" |
6269 | | " fd\n" |
6270 | | " A file descriptor to a namespace.\n" |
6271 | | " nstype\n" |
6272 | | " Type of namespace."); |
6273 | | |
6274 | | #define OS_SETNS_METHODDEF \ |
6275 | | {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__}, |
6276 | | |
6277 | | static PyObject * |
6278 | | os_setns_impl(PyObject *module, int fd, int nstype); |
6279 | | |
6280 | | static PyObject * |
6281 | | os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6282 | 0 | { |
6283 | 0 | PyObject *return_value = NULL; |
6284 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6285 | |
|
6286 | 0 | #define NUM_KEYWORDS 2 |
6287 | 0 | static struct { |
6288 | 0 | PyGC_Head _this_is_not_used; |
6289 | 0 | PyObject_VAR_HEAD |
6290 | 0 | Py_hash_t ob_hash; |
6291 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6292 | 0 | } _kwtuple = { |
6293 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6294 | 0 | .ob_hash = -1, |
6295 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), }, |
6296 | 0 | }; |
6297 | 0 | #undef NUM_KEYWORDS |
6298 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6299 | |
|
6300 | | #else // !Py_BUILD_CORE |
6301 | | # define KWTUPLE NULL |
6302 | | #endif // !Py_BUILD_CORE |
6303 | |
|
6304 | 0 | static const char * const _keywords[] = {"fd", "nstype", NULL}; |
6305 | 0 | static _PyArg_Parser _parser = { |
6306 | 0 | .keywords = _keywords, |
6307 | 0 | .fname = "setns", |
6308 | 0 | .kwtuple = KWTUPLE, |
6309 | 0 | }; |
6310 | 0 | #undef KWTUPLE |
6311 | 0 | PyObject *argsbuf[2]; |
6312 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6313 | 0 | int fd; |
6314 | 0 | int nstype = 0; |
6315 | |
|
6316 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6317 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6318 | 0 | if (!args) { |
6319 | 0 | goto exit; |
6320 | 0 | } |
6321 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6322 | 0 | if (fd < 0) { |
6323 | 0 | goto exit; |
6324 | 0 | } |
6325 | 0 | if (!noptargs) { |
6326 | 0 | goto skip_optional_pos; |
6327 | 0 | } |
6328 | 0 | nstype = PyLong_AsInt(args[1]); |
6329 | 0 | if (nstype == -1 && PyErr_Occurred()) { |
6330 | 0 | goto exit; |
6331 | 0 | } |
6332 | 0 | skip_optional_pos: |
6333 | 0 | return_value = os_setns_impl(module, fd, nstype); |
6334 | |
|
6335 | 0 | exit: |
6336 | 0 | return return_value; |
6337 | 0 | } |
6338 | | |
6339 | | #endif /* defined(HAVE_SETNS) */ |
6340 | | |
6341 | | #if defined(HAVE_UNSHARE) |
6342 | | |
6343 | | PyDoc_STRVAR(os_unshare__doc__, |
6344 | | "unshare($module, /, flags)\n" |
6345 | | "--\n" |
6346 | | "\n" |
6347 | | "Disassociate parts of a process (or thread) execution context.\n" |
6348 | | "\n" |
6349 | | " flags\n" |
6350 | | " Namespaces to be unshared."); |
6351 | | |
6352 | | #define OS_UNSHARE_METHODDEF \ |
6353 | | {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__}, |
6354 | | |
6355 | | static PyObject * |
6356 | | os_unshare_impl(PyObject *module, int flags); |
6357 | | |
6358 | | static PyObject * |
6359 | | os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6360 | 0 | { |
6361 | 0 | PyObject *return_value = NULL; |
6362 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6363 | |
|
6364 | 0 | #define NUM_KEYWORDS 1 |
6365 | 0 | static struct { |
6366 | 0 | PyGC_Head _this_is_not_used; |
6367 | 0 | PyObject_VAR_HEAD |
6368 | 0 | Py_hash_t ob_hash; |
6369 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6370 | 0 | } _kwtuple = { |
6371 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6372 | 0 | .ob_hash = -1, |
6373 | 0 | .ob_item = { &_Py_ID(flags), }, |
6374 | 0 | }; |
6375 | 0 | #undef NUM_KEYWORDS |
6376 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6377 | |
|
6378 | | #else // !Py_BUILD_CORE |
6379 | | # define KWTUPLE NULL |
6380 | | #endif // !Py_BUILD_CORE |
6381 | |
|
6382 | 0 | static const char * const _keywords[] = {"flags", NULL}; |
6383 | 0 | static _PyArg_Parser _parser = { |
6384 | 0 | .keywords = _keywords, |
6385 | 0 | .fname = "unshare", |
6386 | 0 | .kwtuple = KWTUPLE, |
6387 | 0 | }; |
6388 | 0 | #undef KWTUPLE |
6389 | 0 | PyObject *argsbuf[1]; |
6390 | 0 | int flags; |
6391 | |
|
6392 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6393 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6394 | 0 | if (!args) { |
6395 | 0 | goto exit; |
6396 | 0 | } |
6397 | 0 | flags = PyLong_AsInt(args[0]); |
6398 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6399 | 0 | goto exit; |
6400 | 0 | } |
6401 | 0 | return_value = os_unshare_impl(module, flags); |
6402 | |
|
6403 | 0 | exit: |
6404 | 0 | return return_value; |
6405 | 0 | } |
6406 | | |
6407 | | #endif /* defined(HAVE_UNSHARE) */ |
6408 | | |
6409 | | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
6410 | | |
6411 | | PyDoc_STRVAR(os_readlink__doc__, |
6412 | | "readlink($module, /, path, *, dir_fd=None)\n" |
6413 | | "--\n" |
6414 | | "\n" |
6415 | | "Return a string representing the path to which the symbolic link points.\n" |
6416 | | "\n" |
6417 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
6418 | | "and path should be relative; path will then be relative to that directory.\n" |
6419 | | "\n" |
6420 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
6421 | | "using it will raise a NotImplementedError."); |
6422 | | |
6423 | | #define OS_READLINK_METHODDEF \ |
6424 | | {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__}, |
6425 | | |
6426 | | static PyObject * |
6427 | | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
6428 | | |
6429 | | static PyObject * |
6430 | | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6431 | 0 | { |
6432 | 0 | PyObject *return_value = NULL; |
6433 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6434 | |
|
6435 | 0 | #define NUM_KEYWORDS 2 |
6436 | 0 | static struct { |
6437 | 0 | PyGC_Head _this_is_not_used; |
6438 | 0 | PyObject_VAR_HEAD |
6439 | 0 | Py_hash_t ob_hash; |
6440 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6441 | 0 | } _kwtuple = { |
6442 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6443 | 0 | .ob_hash = -1, |
6444 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
6445 | 0 | }; |
6446 | 0 | #undef NUM_KEYWORDS |
6447 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6448 | |
|
6449 | | #else // !Py_BUILD_CORE |
6450 | | # define KWTUPLE NULL |
6451 | | #endif // !Py_BUILD_CORE |
6452 | |
|
6453 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
6454 | 0 | static _PyArg_Parser _parser = { |
6455 | 0 | .keywords = _keywords, |
6456 | 0 | .fname = "readlink", |
6457 | 0 | .kwtuple = KWTUPLE, |
6458 | 0 | }; |
6459 | 0 | #undef KWTUPLE |
6460 | 0 | PyObject *argsbuf[2]; |
6461 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6462 | 0 | path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0); |
6463 | 0 | int dir_fd = DEFAULT_DIR_FD; |
6464 | |
|
6465 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6466 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6467 | 0 | if (!args) { |
6468 | 0 | goto exit; |
6469 | 0 | } |
6470 | 0 | if (!path_converter(args[0], &path)) { |
6471 | 0 | goto exit; |
6472 | 0 | } |
6473 | 0 | if (!noptargs) { |
6474 | 0 | goto skip_optional_kwonly; |
6475 | 0 | } |
6476 | 0 | if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
6477 | 0 | goto exit; |
6478 | 0 | } |
6479 | 0 | skip_optional_kwonly: |
6480 | 0 | return_value = os_readlink_impl(module, &path, dir_fd); |
6481 | |
|
6482 | 0 | exit: |
6483 | | /* Cleanup for path */ |
6484 | 0 | path_cleanup(&path); |
6485 | |
|
6486 | 0 | return return_value; |
6487 | 0 | } |
6488 | | |
6489 | | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
6490 | | |
6491 | | #if defined(HAVE_SYMLINK) |
6492 | | |
6493 | | PyDoc_STRVAR(os_symlink__doc__, |
6494 | | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
6495 | | "--\n" |
6496 | | "\n" |
6497 | | "Create a symbolic link pointing to src named dst.\n" |
6498 | | "\n" |
6499 | | "target_is_directory is required on Windows if the target is to be\n" |
6500 | | " interpreted as a directory. (On Windows, symlink requires\n" |
6501 | | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
6502 | | " target_is_directory is ignored on non-Windows platforms.\n" |
6503 | | "\n" |
6504 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
6505 | | " and path should be relative; path will then be relative to that directory.\n" |
6506 | | "dir_fd may not be implemented on your platform.\n" |
6507 | | " If it is unavailable, using it will raise a NotImplementedError."); |
6508 | | |
6509 | | #define OS_SYMLINK_METHODDEF \ |
6510 | | {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__}, |
6511 | | |
6512 | | static PyObject * |
6513 | | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
6514 | | int target_is_directory, int dir_fd); |
6515 | | |
6516 | | static PyObject * |
6517 | | os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6518 | 0 | { |
6519 | 0 | PyObject *return_value = NULL; |
6520 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6521 | |
|
6522 | 0 | #define NUM_KEYWORDS 4 |
6523 | 0 | static struct { |
6524 | 0 | PyGC_Head _this_is_not_used; |
6525 | 0 | PyObject_VAR_HEAD |
6526 | 0 | Py_hash_t ob_hash; |
6527 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6528 | 0 | } _kwtuple = { |
6529 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6530 | 0 | .ob_hash = -1, |
6531 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), }, |
6532 | 0 | }; |
6533 | 0 | #undef NUM_KEYWORDS |
6534 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6535 | |
|
6536 | | #else // !Py_BUILD_CORE |
6537 | | # define KWTUPLE NULL |
6538 | | #endif // !Py_BUILD_CORE |
6539 | |
|
6540 | 0 | static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
6541 | 0 | static _PyArg_Parser _parser = { |
6542 | 0 | .keywords = _keywords, |
6543 | 0 | .fname = "symlink", |
6544 | 0 | .kwtuple = KWTUPLE, |
6545 | 0 | }; |
6546 | 0 | #undef KWTUPLE |
6547 | 0 | PyObject *argsbuf[4]; |
6548 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
6549 | 0 | path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0); |
6550 | 0 | path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0); |
6551 | 0 | int target_is_directory = 0; |
6552 | 0 | int dir_fd = DEFAULT_DIR_FD; |
6553 | |
|
6554 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6555 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6556 | 0 | if (!args) { |
6557 | 0 | goto exit; |
6558 | 0 | } |
6559 | 0 | if (!path_converter(args[0], &src)) { |
6560 | 0 | goto exit; |
6561 | 0 | } |
6562 | 0 | if (!path_converter(args[1], &dst)) { |
6563 | 0 | goto exit; |
6564 | 0 | } |
6565 | 0 | if (!noptargs) { |
6566 | 0 | goto skip_optional_pos; |
6567 | 0 | } |
6568 | 0 | if (args[2]) { |
6569 | 0 | target_is_directory = PyObject_IsTrue(args[2]); |
6570 | 0 | if (target_is_directory < 0) { |
6571 | 0 | goto exit; |
6572 | 0 | } |
6573 | 0 | if (!--noptargs) { |
6574 | 0 | goto skip_optional_pos; |
6575 | 0 | } |
6576 | 0 | } |
6577 | 0 | skip_optional_pos: |
6578 | 0 | if (!noptargs) { |
6579 | 0 | goto skip_optional_kwonly; |
6580 | 0 | } |
6581 | 0 | if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
6582 | 0 | goto exit; |
6583 | 0 | } |
6584 | 0 | skip_optional_kwonly: |
6585 | 0 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
6586 | |
|
6587 | 0 | exit: |
6588 | | /* Cleanup for src */ |
6589 | 0 | path_cleanup(&src); |
6590 | | /* Cleanup for dst */ |
6591 | 0 | path_cleanup(&dst); |
6592 | |
|
6593 | 0 | return return_value; |
6594 | 0 | } |
6595 | | |
6596 | | #endif /* defined(HAVE_SYMLINK) */ |
6597 | | |
6598 | | PyDoc_STRVAR(os_times__doc__, |
6599 | | "times($module, /)\n" |
6600 | | "--\n" |
6601 | | "\n" |
6602 | | "Return a collection containing process timing information.\n" |
6603 | | "\n" |
6604 | | "The object returned behaves like a named tuple with these fields:\n" |
6605 | | " (utime, stime, cutime, cstime, elapsed_time)\n" |
6606 | | "All fields are floating-point numbers."); |
6607 | | |
6608 | | #define OS_TIMES_METHODDEF \ |
6609 | | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
6610 | | |
6611 | | static PyObject * |
6612 | | os_times_impl(PyObject *module); |
6613 | | |
6614 | | static PyObject * |
6615 | | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6616 | 0 | { |
6617 | 0 | return os_times_impl(module); |
6618 | 0 | } |
6619 | | |
6620 | | #if defined(HAVE_TIMERFD_CREATE) |
6621 | | |
6622 | | PyDoc_STRVAR(os_timerfd_create__doc__, |
6623 | | "timerfd_create($module, clockid, /, *, flags=0)\n" |
6624 | | "--\n" |
6625 | | "\n" |
6626 | | "Create and return a timer file descriptor.\n" |
6627 | | "\n" |
6628 | | " clockid\n" |
6629 | | " A valid clock ID constant as timer file descriptor.\n" |
6630 | | "\n" |
6631 | | " time.CLOCK_REALTIME\n" |
6632 | | " time.CLOCK_MONOTONIC\n" |
6633 | | " time.CLOCK_BOOTTIME\n" |
6634 | | " flags\n" |
6635 | | " 0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n" |
6636 | | "\n" |
6637 | | " os.TFD_NONBLOCK\n" |
6638 | | " If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n" |
6639 | | " If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n" |
6640 | | "\n" |
6641 | | " os.TFD_CLOEXEC\n" |
6642 | | " If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag"); |
6643 | | |
6644 | | #define OS_TIMERFD_CREATE_METHODDEF \ |
6645 | | {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__}, |
6646 | | |
6647 | | static PyObject * |
6648 | | os_timerfd_create_impl(PyObject *module, int clockid, int flags); |
6649 | | |
6650 | | static PyObject * |
6651 | | os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6652 | 0 | { |
6653 | 0 | PyObject *return_value = NULL; |
6654 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6655 | |
|
6656 | 0 | #define NUM_KEYWORDS 1 |
6657 | 0 | static struct { |
6658 | 0 | PyGC_Head _this_is_not_used; |
6659 | 0 | PyObject_VAR_HEAD |
6660 | 0 | Py_hash_t ob_hash; |
6661 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6662 | 0 | } _kwtuple = { |
6663 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6664 | 0 | .ob_hash = -1, |
6665 | 0 | .ob_item = { &_Py_ID(flags), }, |
6666 | 0 | }; |
6667 | 0 | #undef NUM_KEYWORDS |
6668 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6669 | |
|
6670 | | #else // !Py_BUILD_CORE |
6671 | | # define KWTUPLE NULL |
6672 | | #endif // !Py_BUILD_CORE |
6673 | |
|
6674 | 0 | static const char * const _keywords[] = {"", "flags", NULL}; |
6675 | 0 | static _PyArg_Parser _parser = { |
6676 | 0 | .keywords = _keywords, |
6677 | 0 | .fname = "timerfd_create", |
6678 | 0 | .kwtuple = KWTUPLE, |
6679 | 0 | }; |
6680 | 0 | #undef KWTUPLE |
6681 | 0 | PyObject *argsbuf[2]; |
6682 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6683 | 0 | int clockid; |
6684 | 0 | int flags = 0; |
6685 | |
|
6686 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6687 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6688 | 0 | if (!args) { |
6689 | 0 | goto exit; |
6690 | 0 | } |
6691 | 0 | clockid = PyLong_AsInt(args[0]); |
6692 | 0 | if (clockid == -1 && PyErr_Occurred()) { |
6693 | 0 | goto exit; |
6694 | 0 | } |
6695 | 0 | if (!noptargs) { |
6696 | 0 | goto skip_optional_kwonly; |
6697 | 0 | } |
6698 | 0 | flags = PyLong_AsInt(args[1]); |
6699 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6700 | 0 | goto exit; |
6701 | 0 | } |
6702 | 0 | skip_optional_kwonly: |
6703 | 0 | return_value = os_timerfd_create_impl(module, clockid, flags); |
6704 | |
|
6705 | 0 | exit: |
6706 | 0 | return return_value; |
6707 | 0 | } |
6708 | | |
6709 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6710 | | |
6711 | | #if defined(HAVE_TIMERFD_CREATE) |
6712 | | |
6713 | | PyDoc_STRVAR(os_timerfd_settime__doc__, |
6714 | | "timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n" |
6715 | | "--\n" |
6716 | | "\n" |
6717 | | "Alter a timer file descriptor\'s internal timer in seconds.\n" |
6718 | | "\n" |
6719 | | " fd\n" |
6720 | | " A timer file descriptor.\n" |
6721 | | " flags\n" |
6722 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
6723 | | " initial\n" |
6724 | | " The initial expiration time, in seconds.\n" |
6725 | | " interval\n" |
6726 | | " The timer\'s interval, in seconds."); |
6727 | | |
6728 | | #define OS_TIMERFD_SETTIME_METHODDEF \ |
6729 | | {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__}, |
6730 | | |
6731 | | static PyObject * |
6732 | | os_timerfd_settime_impl(PyObject *module, int fd, int flags, |
6733 | | double initial_double, double interval_double); |
6734 | | |
6735 | | static PyObject * |
6736 | | os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6737 | 0 | { |
6738 | 0 | PyObject *return_value = NULL; |
6739 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6740 | |
|
6741 | 0 | #define NUM_KEYWORDS 3 |
6742 | 0 | static struct { |
6743 | 0 | PyGC_Head _this_is_not_used; |
6744 | 0 | PyObject_VAR_HEAD |
6745 | 0 | Py_hash_t ob_hash; |
6746 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6747 | 0 | } _kwtuple = { |
6748 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6749 | 0 | .ob_hash = -1, |
6750 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
6751 | 0 | }; |
6752 | 0 | #undef NUM_KEYWORDS |
6753 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6754 | |
|
6755 | | #else // !Py_BUILD_CORE |
6756 | | # define KWTUPLE NULL |
6757 | | #endif // !Py_BUILD_CORE |
6758 | |
|
6759 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
6760 | 0 | static _PyArg_Parser _parser = { |
6761 | 0 | .keywords = _keywords, |
6762 | 0 | .fname = "timerfd_settime", |
6763 | 0 | .kwtuple = KWTUPLE, |
6764 | 0 | }; |
6765 | 0 | #undef KWTUPLE |
6766 | 0 | PyObject *argsbuf[4]; |
6767 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6768 | 0 | int fd; |
6769 | 0 | int flags = 0; |
6770 | 0 | double initial_double = 0.0; |
6771 | 0 | double interval_double = 0.0; |
6772 | |
|
6773 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6774 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6775 | 0 | if (!args) { |
6776 | 0 | goto exit; |
6777 | 0 | } |
6778 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6779 | 0 | if (fd < 0) { |
6780 | 0 | goto exit; |
6781 | 0 | } |
6782 | 0 | if (!noptargs) { |
6783 | 0 | goto skip_optional_kwonly; |
6784 | 0 | } |
6785 | 0 | if (args[1]) { |
6786 | 0 | flags = PyLong_AsInt(args[1]); |
6787 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6788 | 0 | goto exit; |
6789 | 0 | } |
6790 | 0 | if (!--noptargs) { |
6791 | 0 | goto skip_optional_kwonly; |
6792 | 0 | } |
6793 | 0 | } |
6794 | 0 | if (args[2]) { |
6795 | 0 | if (PyFloat_CheckExact(args[2])) { |
6796 | 0 | initial_double = PyFloat_AS_DOUBLE(args[2]); |
6797 | 0 | } |
6798 | 0 | else |
6799 | 0 | { |
6800 | 0 | initial_double = PyFloat_AsDouble(args[2]); |
6801 | 0 | if (initial_double == -1.0 && PyErr_Occurred()) { |
6802 | 0 | goto exit; |
6803 | 0 | } |
6804 | 0 | } |
6805 | 0 | if (!--noptargs) { |
6806 | 0 | goto skip_optional_kwonly; |
6807 | 0 | } |
6808 | 0 | } |
6809 | 0 | if (PyFloat_CheckExact(args[3])) { |
6810 | 0 | interval_double = PyFloat_AS_DOUBLE(args[3]); |
6811 | 0 | } |
6812 | 0 | else |
6813 | 0 | { |
6814 | 0 | interval_double = PyFloat_AsDouble(args[3]); |
6815 | 0 | if (interval_double == -1.0 && PyErr_Occurred()) { |
6816 | 0 | goto exit; |
6817 | 0 | } |
6818 | 0 | } |
6819 | 0 | skip_optional_kwonly: |
6820 | 0 | return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double); |
6821 | |
|
6822 | 0 | exit: |
6823 | 0 | return return_value; |
6824 | 0 | } |
6825 | | |
6826 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6827 | | |
6828 | | #if defined(HAVE_TIMERFD_CREATE) |
6829 | | |
6830 | | PyDoc_STRVAR(os_timerfd_settime_ns__doc__, |
6831 | | "timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n" |
6832 | | "--\n" |
6833 | | "\n" |
6834 | | "Alter a timer file descriptor\'s internal timer in nanoseconds.\n" |
6835 | | "\n" |
6836 | | " fd\n" |
6837 | | " A timer file descriptor.\n" |
6838 | | " flags\n" |
6839 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
6840 | | " initial\n" |
6841 | | " initial expiration timing in seconds.\n" |
6842 | | " interval\n" |
6843 | | " interval for the timer in seconds."); |
6844 | | |
6845 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF \ |
6846 | | {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__}, |
6847 | | |
6848 | | static PyObject * |
6849 | | os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags, |
6850 | | long long initial, long long interval); |
6851 | | |
6852 | | static PyObject * |
6853 | | os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6854 | 0 | { |
6855 | 0 | PyObject *return_value = NULL; |
6856 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6857 | |
|
6858 | 0 | #define NUM_KEYWORDS 3 |
6859 | 0 | static struct { |
6860 | 0 | PyGC_Head _this_is_not_used; |
6861 | 0 | PyObject_VAR_HEAD |
6862 | 0 | Py_hash_t ob_hash; |
6863 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6864 | 0 | } _kwtuple = { |
6865 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6866 | 0 | .ob_hash = -1, |
6867 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
6868 | 0 | }; |
6869 | 0 | #undef NUM_KEYWORDS |
6870 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6871 | |
|
6872 | | #else // !Py_BUILD_CORE |
6873 | | # define KWTUPLE NULL |
6874 | | #endif // !Py_BUILD_CORE |
6875 | |
|
6876 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
6877 | 0 | static _PyArg_Parser _parser = { |
6878 | 0 | .keywords = _keywords, |
6879 | 0 | .fname = "timerfd_settime_ns", |
6880 | 0 | .kwtuple = KWTUPLE, |
6881 | 0 | }; |
6882 | 0 | #undef KWTUPLE |
6883 | 0 | PyObject *argsbuf[4]; |
6884 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6885 | 0 | int fd; |
6886 | 0 | int flags = 0; |
6887 | 0 | long long initial = 0; |
6888 | 0 | long long interval = 0; |
6889 | |
|
6890 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6891 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6892 | 0 | if (!args) { |
6893 | 0 | goto exit; |
6894 | 0 | } |
6895 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6896 | 0 | if (fd < 0) { |
6897 | 0 | goto exit; |
6898 | 0 | } |
6899 | 0 | if (!noptargs) { |
6900 | 0 | goto skip_optional_kwonly; |
6901 | 0 | } |
6902 | 0 | if (args[1]) { |
6903 | 0 | flags = PyLong_AsInt(args[1]); |
6904 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6905 | 0 | goto exit; |
6906 | 0 | } |
6907 | 0 | if (!--noptargs) { |
6908 | 0 | goto skip_optional_kwonly; |
6909 | 0 | } |
6910 | 0 | } |
6911 | 0 | if (args[2]) { |
6912 | 0 | initial = PyLong_AsLongLong(args[2]); |
6913 | 0 | if (initial == -1 && PyErr_Occurred()) { |
6914 | 0 | goto exit; |
6915 | 0 | } |
6916 | 0 | if (!--noptargs) { |
6917 | 0 | goto skip_optional_kwonly; |
6918 | 0 | } |
6919 | 0 | } |
6920 | 0 | interval = PyLong_AsLongLong(args[3]); |
6921 | 0 | if (interval == -1 && PyErr_Occurred()) { |
6922 | 0 | goto exit; |
6923 | 0 | } |
6924 | 0 | skip_optional_kwonly: |
6925 | 0 | return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval); |
6926 | |
|
6927 | 0 | exit: |
6928 | 0 | return return_value; |
6929 | 0 | } |
6930 | | |
6931 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6932 | | |
6933 | | #if defined(HAVE_TIMERFD_CREATE) |
6934 | | |
6935 | | PyDoc_STRVAR(os_timerfd_gettime__doc__, |
6936 | | "timerfd_gettime($module, fd, /)\n" |
6937 | | "--\n" |
6938 | | "\n" |
6939 | | "Return a tuple of a timer file descriptor\'s (interval, next expiration) in float seconds.\n" |
6940 | | "\n" |
6941 | | " fd\n" |
6942 | | " A timer file descriptor."); |
6943 | | |
6944 | | #define OS_TIMERFD_GETTIME_METHODDEF \ |
6945 | | {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__}, |
6946 | | |
6947 | | static PyObject * |
6948 | | os_timerfd_gettime_impl(PyObject *module, int fd); |
6949 | | |
6950 | | static PyObject * |
6951 | | os_timerfd_gettime(PyObject *module, PyObject *arg) |
6952 | 0 | { |
6953 | 0 | PyObject *return_value = NULL; |
6954 | 0 | int fd; |
6955 | |
|
6956 | 0 | fd = PyObject_AsFileDescriptor(arg); |
6957 | 0 | if (fd < 0) { |
6958 | 0 | goto exit; |
6959 | 0 | } |
6960 | 0 | return_value = os_timerfd_gettime_impl(module, fd); |
6961 | |
|
6962 | 0 | exit: |
6963 | 0 | return return_value; |
6964 | 0 | } |
6965 | | |
6966 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6967 | | |
6968 | | #if defined(HAVE_TIMERFD_CREATE) |
6969 | | |
6970 | | PyDoc_STRVAR(os_timerfd_gettime_ns__doc__, |
6971 | | "timerfd_gettime_ns($module, fd, /)\n" |
6972 | | "--\n" |
6973 | | "\n" |
6974 | | "Return a tuple of a timer file descriptor\'s (interval, next expiration) in nanoseconds.\n" |
6975 | | "\n" |
6976 | | " fd\n" |
6977 | | " A timer file descriptor."); |
6978 | | |
6979 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF \ |
6980 | | {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__}, |
6981 | | |
6982 | | static PyObject * |
6983 | | os_timerfd_gettime_ns_impl(PyObject *module, int fd); |
6984 | | |
6985 | | static PyObject * |
6986 | | os_timerfd_gettime_ns(PyObject *module, PyObject *arg) |
6987 | 0 | { |
6988 | 0 | PyObject *return_value = NULL; |
6989 | 0 | int fd; |
6990 | |
|
6991 | 0 | fd = PyObject_AsFileDescriptor(arg); |
6992 | 0 | if (fd < 0) { |
6993 | 0 | goto exit; |
6994 | 0 | } |
6995 | 0 | return_value = os_timerfd_gettime_ns_impl(module, fd); |
6996 | |
|
6997 | 0 | exit: |
6998 | 0 | return return_value; |
6999 | 0 | } |
7000 | | |
7001 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7002 | | |
7003 | | #if defined(HAVE_GETSID) |
7004 | | |
7005 | | PyDoc_STRVAR(os_getsid__doc__, |
7006 | | "getsid($module, pid, /)\n" |
7007 | | "--\n" |
7008 | | "\n" |
7009 | | "Call the system call getsid(pid) and return the result."); |
7010 | | |
7011 | | #define OS_GETSID_METHODDEF \ |
7012 | | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
7013 | | |
7014 | | static PyObject * |
7015 | | os_getsid_impl(PyObject *module, pid_t pid); |
7016 | | |
7017 | | static PyObject * |
7018 | | os_getsid(PyObject *module, PyObject *arg) |
7019 | 0 | { |
7020 | 0 | PyObject *return_value = NULL; |
7021 | 0 | pid_t pid; |
7022 | |
|
7023 | 0 | pid = PyLong_AsPid(arg); |
7024 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7025 | 0 | goto exit; |
7026 | 0 | } |
7027 | 0 | return_value = os_getsid_impl(module, pid); |
7028 | |
|
7029 | 0 | exit: |
7030 | 0 | return return_value; |
7031 | 0 | } |
7032 | | |
7033 | | #endif /* defined(HAVE_GETSID) */ |
7034 | | |
7035 | | #if defined(HAVE_SETSID) |
7036 | | |
7037 | | PyDoc_STRVAR(os_setsid__doc__, |
7038 | | "setsid($module, /)\n" |
7039 | | "--\n" |
7040 | | "\n" |
7041 | | "Call the system call setsid()."); |
7042 | | |
7043 | | #define OS_SETSID_METHODDEF \ |
7044 | | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
7045 | | |
7046 | | static PyObject * |
7047 | | os_setsid_impl(PyObject *module); |
7048 | | |
7049 | | static PyObject * |
7050 | | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
7051 | 0 | { |
7052 | 0 | return os_setsid_impl(module); |
7053 | 0 | } |
7054 | | |
7055 | | #endif /* defined(HAVE_SETSID) */ |
7056 | | |
7057 | | #if defined(HAVE_SETPGID) |
7058 | | |
7059 | | PyDoc_STRVAR(os_setpgid__doc__, |
7060 | | "setpgid($module, pid, pgrp, /)\n" |
7061 | | "--\n" |
7062 | | "\n" |
7063 | | "Call the system call setpgid(pid, pgrp)."); |
7064 | | |
7065 | | #define OS_SETPGID_METHODDEF \ |
7066 | | {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__}, |
7067 | | |
7068 | | static PyObject * |
7069 | | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
7070 | | |
7071 | | static PyObject * |
7072 | | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7073 | 0 | { |
7074 | 0 | PyObject *return_value = NULL; |
7075 | 0 | pid_t pid; |
7076 | 0 | pid_t pgrp; |
7077 | |
|
7078 | 0 | if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) { |
7079 | 0 | goto exit; |
7080 | 0 | } |
7081 | 0 | pid = PyLong_AsPid(args[0]); |
7082 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7083 | 0 | goto exit; |
7084 | 0 | } |
7085 | 0 | pgrp = PyLong_AsPid(args[1]); |
7086 | 0 | if (pgrp == (pid_t)(-1) && PyErr_Occurred()) { |
7087 | 0 | goto exit; |
7088 | 0 | } |
7089 | 0 | return_value = os_setpgid_impl(module, pid, pgrp); |
7090 | |
|
7091 | 0 | exit: |
7092 | 0 | return return_value; |
7093 | 0 | } |
7094 | | |
7095 | | #endif /* defined(HAVE_SETPGID) */ |
7096 | | |
7097 | | #if defined(HAVE_TCGETPGRP) |
7098 | | |
7099 | | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
7100 | | "tcgetpgrp($module, fd, /)\n" |
7101 | | "--\n" |
7102 | | "\n" |
7103 | | "Return the process group associated with the terminal specified by fd."); |
7104 | | |
7105 | | #define OS_TCGETPGRP_METHODDEF \ |
7106 | | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
7107 | | |
7108 | | static PyObject * |
7109 | | os_tcgetpgrp_impl(PyObject *module, int fd); |
7110 | | |
7111 | | static PyObject * |
7112 | | os_tcgetpgrp(PyObject *module, PyObject *arg) |
7113 | 0 | { |
7114 | 0 | PyObject *return_value = NULL; |
7115 | 0 | int fd; |
7116 | |
|
7117 | 0 | fd = PyLong_AsInt(arg); |
7118 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7119 | 0 | goto exit; |
7120 | 0 | } |
7121 | 0 | return_value = os_tcgetpgrp_impl(module, fd); |
7122 | |
|
7123 | 0 | exit: |
7124 | 0 | return return_value; |
7125 | 0 | } |
7126 | | |
7127 | | #endif /* defined(HAVE_TCGETPGRP) */ |
7128 | | |
7129 | | #if defined(HAVE_TCSETPGRP) |
7130 | | |
7131 | | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
7132 | | "tcsetpgrp($module, fd, pgid, /)\n" |
7133 | | "--\n" |
7134 | | "\n" |
7135 | | "Set the process group associated with the terminal specified by fd."); |
7136 | | |
7137 | | #define OS_TCSETPGRP_METHODDEF \ |
7138 | | {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__}, |
7139 | | |
7140 | | static PyObject * |
7141 | | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
7142 | | |
7143 | | static PyObject * |
7144 | | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7145 | 0 | { |
7146 | 0 | PyObject *return_value = NULL; |
7147 | 0 | int fd; |
7148 | 0 | pid_t pgid; |
7149 | |
|
7150 | 0 | if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) { |
7151 | 0 | goto exit; |
7152 | 0 | } |
7153 | 0 | fd = PyLong_AsInt(args[0]); |
7154 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7155 | 0 | goto exit; |
7156 | 0 | } |
7157 | 0 | pgid = PyLong_AsPid(args[1]); |
7158 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
7159 | 0 | goto exit; |
7160 | 0 | } |
7161 | 0 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
7162 | |
|
7163 | 0 | exit: |
7164 | 0 | return return_value; |
7165 | 0 | } |
7166 | | |
7167 | | #endif /* defined(HAVE_TCSETPGRP) */ |
7168 | | |
7169 | | PyDoc_STRVAR(os_open__doc__, |
7170 | | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
7171 | | "--\n" |
7172 | | "\n" |
7173 | | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
7174 | | "\n" |
7175 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
7176 | | " and path should be relative; path will then be relative to that directory.\n" |
7177 | | "dir_fd may not be implemented on your platform.\n" |
7178 | | " If it is unavailable, using it will raise a NotImplementedError."); |
7179 | | |
7180 | | #define OS_OPEN_METHODDEF \ |
7181 | | {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__}, |
7182 | | |
7183 | | static int |
7184 | | os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd); |
7185 | | |
7186 | | static PyObject * |
7187 | | os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7188 | 236 | { |
7189 | 236 | PyObject *return_value = NULL; |
7190 | 236 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7191 | | |
7192 | 236 | #define NUM_KEYWORDS 4 |
7193 | 236 | static struct { |
7194 | 236 | PyGC_Head _this_is_not_used; |
7195 | 236 | PyObject_VAR_HEAD |
7196 | 236 | Py_hash_t ob_hash; |
7197 | 236 | PyObject *ob_item[NUM_KEYWORDS]; |
7198 | 236 | } _kwtuple = { |
7199 | 236 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7200 | 236 | .ob_hash = -1, |
7201 | 236 | .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
7202 | 236 | }; |
7203 | 236 | #undef NUM_KEYWORDS |
7204 | 236 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7205 | | |
7206 | | #else // !Py_BUILD_CORE |
7207 | | # define KWTUPLE NULL |
7208 | | #endif // !Py_BUILD_CORE |
7209 | | |
7210 | 236 | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
7211 | 236 | static _PyArg_Parser _parser = { |
7212 | 236 | .keywords = _keywords, |
7213 | 236 | .fname = "open", |
7214 | 236 | .kwtuple = KWTUPLE, |
7215 | 236 | }; |
7216 | 236 | #undef KWTUPLE |
7217 | 236 | PyObject *argsbuf[4]; |
7218 | 236 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7219 | 236 | path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0); |
7220 | 236 | int flags; |
7221 | 236 | int mode = 511; |
7222 | 236 | int dir_fd = DEFAULT_DIR_FD; |
7223 | 236 | int _return_value; |
7224 | | |
7225 | 236 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7226 | 236 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7227 | 236 | if (!args) { |
7228 | 0 | goto exit; |
7229 | 0 | } |
7230 | 236 | if (!path_converter(args[0], &path)) { |
7231 | 0 | goto exit; |
7232 | 0 | } |
7233 | 236 | flags = PyLong_AsInt(args[1]); |
7234 | 236 | if (flags == -1 && PyErr_Occurred()) { |
7235 | 0 | goto exit; |
7236 | 0 | } |
7237 | 236 | if (!noptargs) { |
7238 | 0 | goto skip_optional_pos; |
7239 | 0 | } |
7240 | 236 | if (args[2]) { |
7241 | 236 | mode = PyLong_AsInt(args[2]); |
7242 | 236 | if (mode == -1 && PyErr_Occurred()) { |
7243 | 0 | goto exit; |
7244 | 0 | } |
7245 | 236 | if (!--noptargs) { |
7246 | 236 | goto skip_optional_pos; |
7247 | 236 | } |
7248 | 236 | } |
7249 | 236 | skip_optional_pos: |
7250 | 236 | if (!noptargs) { |
7251 | 236 | goto skip_optional_kwonly; |
7252 | 236 | } |
7253 | 0 | if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
7254 | 0 | goto exit; |
7255 | 0 | } |
7256 | 236 | skip_optional_kwonly: |
7257 | 236 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
7258 | 236 | if ((_return_value == -1) && PyErr_Occurred()) { |
7259 | 0 | goto exit; |
7260 | 0 | } |
7261 | 236 | return_value = PyLong_FromLong((long)_return_value); |
7262 | | |
7263 | 236 | exit: |
7264 | | /* Cleanup for path */ |
7265 | 236 | path_cleanup(&path); |
7266 | | |
7267 | 236 | return return_value; |
7268 | 236 | } |
7269 | | |
7270 | | PyDoc_STRVAR(os_close__doc__, |
7271 | | "close($module, /, fd)\n" |
7272 | | "--\n" |
7273 | | "\n" |
7274 | | "Close a file descriptor."); |
7275 | | |
7276 | | #define OS_CLOSE_METHODDEF \ |
7277 | | {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__}, |
7278 | | |
7279 | | static PyObject * |
7280 | | os_close_impl(PyObject *module, int fd); |
7281 | | |
7282 | | static PyObject * |
7283 | | os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7284 | 0 | { |
7285 | 0 | PyObject *return_value = NULL; |
7286 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7287 | |
|
7288 | 0 | #define NUM_KEYWORDS 1 |
7289 | 0 | static struct { |
7290 | 0 | PyGC_Head _this_is_not_used; |
7291 | 0 | PyObject_VAR_HEAD |
7292 | 0 | Py_hash_t ob_hash; |
7293 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7294 | 0 | } _kwtuple = { |
7295 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7296 | 0 | .ob_hash = -1, |
7297 | 0 | .ob_item = { &_Py_ID(fd), }, |
7298 | 0 | }; |
7299 | 0 | #undef NUM_KEYWORDS |
7300 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7301 | |
|
7302 | | #else // !Py_BUILD_CORE |
7303 | | # define KWTUPLE NULL |
7304 | | #endif // !Py_BUILD_CORE |
7305 | |
|
7306 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
7307 | 0 | static _PyArg_Parser _parser = { |
7308 | 0 | .keywords = _keywords, |
7309 | 0 | .fname = "close", |
7310 | 0 | .kwtuple = KWTUPLE, |
7311 | 0 | }; |
7312 | 0 | #undef KWTUPLE |
7313 | 0 | PyObject *argsbuf[1]; |
7314 | 0 | int fd; |
7315 | |
|
7316 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7317 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7318 | 0 | if (!args) { |
7319 | 0 | goto exit; |
7320 | 0 | } |
7321 | 0 | fd = PyLong_AsInt(args[0]); |
7322 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7323 | 0 | goto exit; |
7324 | 0 | } |
7325 | 0 | return_value = os_close_impl(module, fd); |
7326 | |
|
7327 | 0 | exit: |
7328 | 0 | return return_value; |
7329 | 0 | } |
7330 | | |
7331 | | PyDoc_STRVAR(os_closerange__doc__, |
7332 | | "closerange($module, fd_low, fd_high, /)\n" |
7333 | | "--\n" |
7334 | | "\n" |
7335 | | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
7336 | | |
7337 | | #define OS_CLOSERANGE_METHODDEF \ |
7338 | | {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__}, |
7339 | | |
7340 | | static PyObject * |
7341 | | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
7342 | | |
7343 | | static PyObject * |
7344 | | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7345 | 0 | { |
7346 | 0 | PyObject *return_value = NULL; |
7347 | 0 | int fd_low; |
7348 | 0 | int fd_high; |
7349 | |
|
7350 | 0 | if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { |
7351 | 0 | goto exit; |
7352 | 0 | } |
7353 | 0 | fd_low = PyLong_AsInt(args[0]); |
7354 | 0 | if (fd_low == -1 && PyErr_Occurred()) { |
7355 | 0 | goto exit; |
7356 | 0 | } |
7357 | 0 | fd_high = PyLong_AsInt(args[1]); |
7358 | 0 | if (fd_high == -1 && PyErr_Occurred()) { |
7359 | 0 | goto exit; |
7360 | 0 | } |
7361 | 0 | return_value = os_closerange_impl(module, fd_low, fd_high); |
7362 | |
|
7363 | 0 | exit: |
7364 | 0 | return return_value; |
7365 | 0 | } |
7366 | | |
7367 | | PyDoc_STRVAR(os_dup__doc__, |
7368 | | "dup($module, fd, /)\n" |
7369 | | "--\n" |
7370 | | "\n" |
7371 | | "Return a duplicate of a file descriptor."); |
7372 | | |
7373 | | #define OS_DUP_METHODDEF \ |
7374 | | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
7375 | | |
7376 | | static int |
7377 | | os_dup_impl(PyObject *module, int fd); |
7378 | | |
7379 | | static PyObject * |
7380 | | os_dup(PyObject *module, PyObject *arg) |
7381 | 0 | { |
7382 | 0 | PyObject *return_value = NULL; |
7383 | 0 | int fd; |
7384 | 0 | int _return_value; |
7385 | |
|
7386 | 0 | fd = PyLong_AsInt(arg); |
7387 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7388 | 0 | goto exit; |
7389 | 0 | } |
7390 | 0 | _return_value = os_dup_impl(module, fd); |
7391 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7392 | 0 | goto exit; |
7393 | 0 | } |
7394 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7395 | |
|
7396 | 0 | exit: |
7397 | 0 | return return_value; |
7398 | 0 | } |
7399 | | |
7400 | | #if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) |
7401 | | |
7402 | | PyDoc_STRVAR(os_dup2__doc__, |
7403 | | "dup2($module, /, fd, fd2, inheritable=True)\n" |
7404 | | "--\n" |
7405 | | "\n" |
7406 | | "Duplicate file descriptor."); |
7407 | | |
7408 | | #define OS_DUP2_METHODDEF \ |
7409 | | {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__}, |
7410 | | |
7411 | | static int |
7412 | | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
7413 | | |
7414 | | static PyObject * |
7415 | | os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7416 | 0 | { |
7417 | 0 | PyObject *return_value = NULL; |
7418 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7419 | |
|
7420 | 0 | #define NUM_KEYWORDS 3 |
7421 | 0 | static struct { |
7422 | 0 | PyGC_Head _this_is_not_used; |
7423 | 0 | PyObject_VAR_HEAD |
7424 | 0 | Py_hash_t ob_hash; |
7425 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7426 | 0 | } _kwtuple = { |
7427 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7428 | 0 | .ob_hash = -1, |
7429 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), }, |
7430 | 0 | }; |
7431 | 0 | #undef NUM_KEYWORDS |
7432 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7433 | |
|
7434 | | #else // !Py_BUILD_CORE |
7435 | | # define KWTUPLE NULL |
7436 | | #endif // !Py_BUILD_CORE |
7437 | |
|
7438 | 0 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
7439 | 0 | static _PyArg_Parser _parser = { |
7440 | 0 | .keywords = _keywords, |
7441 | 0 | .fname = "dup2", |
7442 | 0 | .kwtuple = KWTUPLE, |
7443 | 0 | }; |
7444 | 0 | #undef KWTUPLE |
7445 | 0 | PyObject *argsbuf[3]; |
7446 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7447 | 0 | int fd; |
7448 | 0 | int fd2; |
7449 | 0 | int inheritable = 1; |
7450 | 0 | int _return_value; |
7451 | |
|
7452 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7453 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7454 | 0 | if (!args) { |
7455 | 0 | goto exit; |
7456 | 0 | } |
7457 | 0 | fd = PyLong_AsInt(args[0]); |
7458 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7459 | 0 | goto exit; |
7460 | 0 | } |
7461 | 0 | fd2 = PyLong_AsInt(args[1]); |
7462 | 0 | if (fd2 == -1 && PyErr_Occurred()) { |
7463 | 0 | goto exit; |
7464 | 0 | } |
7465 | 0 | if (!noptargs) { |
7466 | 0 | goto skip_optional_pos; |
7467 | 0 | } |
7468 | 0 | inheritable = PyObject_IsTrue(args[2]); |
7469 | 0 | if (inheritable < 0) { |
7470 | 0 | goto exit; |
7471 | 0 | } |
7472 | 0 | skip_optional_pos: |
7473 | 0 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
7474 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7475 | 0 | goto exit; |
7476 | 0 | } |
7477 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7478 | |
|
7479 | 0 | exit: |
7480 | 0 | return return_value; |
7481 | 0 | } |
7482 | | |
7483 | | #endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */ |
7484 | | |
7485 | | #if defined(HAVE_LOCKF) |
7486 | | |
7487 | | PyDoc_STRVAR(os_lockf__doc__, |
7488 | | "lockf($module, fd, command, length, /)\n" |
7489 | | "--\n" |
7490 | | "\n" |
7491 | | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
7492 | | "\n" |
7493 | | " fd\n" |
7494 | | " An open file descriptor.\n" |
7495 | | " command\n" |
7496 | | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
7497 | | " length\n" |
7498 | | " The number of bytes to lock, starting at the current position."); |
7499 | | |
7500 | | #define OS_LOCKF_METHODDEF \ |
7501 | | {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__}, |
7502 | | |
7503 | | static PyObject * |
7504 | | os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length); |
7505 | | |
7506 | | static PyObject * |
7507 | | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7508 | 0 | { |
7509 | 0 | PyObject *return_value = NULL; |
7510 | 0 | int fd; |
7511 | 0 | int command; |
7512 | 0 | Py_off_t length; |
7513 | |
|
7514 | 0 | if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { |
7515 | 0 | goto exit; |
7516 | 0 | } |
7517 | 0 | fd = PyLong_AsInt(args[0]); |
7518 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7519 | 0 | goto exit; |
7520 | 0 | } |
7521 | 0 | command = PyLong_AsInt(args[1]); |
7522 | 0 | if (command == -1 && PyErr_Occurred()) { |
7523 | 0 | goto exit; |
7524 | 0 | } |
7525 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
7526 | 0 | goto exit; |
7527 | 0 | } |
7528 | 0 | return_value = os_lockf_impl(module, fd, command, length); |
7529 | |
|
7530 | 0 | exit: |
7531 | 0 | return return_value; |
7532 | 0 | } |
7533 | | |
7534 | | #endif /* defined(HAVE_LOCKF) */ |
7535 | | |
7536 | | PyDoc_STRVAR(os_lseek__doc__, |
7537 | | "lseek($module, fd, position, whence, /)\n" |
7538 | | "--\n" |
7539 | | "\n" |
7540 | | "Set the position of a file descriptor. Return the new position.\n" |
7541 | | "\n" |
7542 | | " fd\n" |
7543 | | " An open file descriptor, as returned by os.open().\n" |
7544 | | " position\n" |
7545 | | " Position, interpreted relative to \'whence\'.\n" |
7546 | | " whence\n" |
7547 | | " The relative position to seek from. Valid values are:\n" |
7548 | | " - SEEK_SET: seek from the start of the file.\n" |
7549 | | " - SEEK_CUR: seek from the current file position.\n" |
7550 | | " - SEEK_END: seek from the end of the file.\n" |
7551 | | "\n" |
7552 | | "The return value is the number of bytes relative to the beginning of the file."); |
7553 | | |
7554 | | #define OS_LSEEK_METHODDEF \ |
7555 | | {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__}, |
7556 | | |
7557 | | static Py_off_t |
7558 | | os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how); |
7559 | | |
7560 | | static PyObject * |
7561 | | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7562 | 0 | { |
7563 | 0 | PyObject *return_value = NULL; |
7564 | 0 | int fd; |
7565 | 0 | Py_off_t position; |
7566 | 0 | int how; |
7567 | 0 | Py_off_t _return_value; |
7568 | |
|
7569 | 0 | if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { |
7570 | 0 | goto exit; |
7571 | 0 | } |
7572 | 0 | fd = PyLong_AsInt(args[0]); |
7573 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7574 | 0 | goto exit; |
7575 | 0 | } |
7576 | 0 | if (!Py_off_t_converter(args[1], &position)) { |
7577 | 0 | goto exit; |
7578 | 0 | } |
7579 | 0 | how = PyLong_AsInt(args[2]); |
7580 | 0 | if (how == -1 && PyErr_Occurred()) { |
7581 | 0 | goto exit; |
7582 | 0 | } |
7583 | 0 | _return_value = os_lseek_impl(module, fd, position, how); |
7584 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7585 | 0 | goto exit; |
7586 | 0 | } |
7587 | 0 | return_value = PyLong_FromPy_off_t(_return_value); |
7588 | |
|
7589 | 0 | exit: |
7590 | 0 | return return_value; |
7591 | 0 | } |
7592 | | |
7593 | | PyDoc_STRVAR(os_read__doc__, |
7594 | | "read($module, fd, length, /)\n" |
7595 | | "--\n" |
7596 | | "\n" |
7597 | | "Read from a file descriptor. Returns a bytes object."); |
7598 | | |
7599 | | #define OS_READ_METHODDEF \ |
7600 | | {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__}, |
7601 | | |
7602 | | static PyObject * |
7603 | | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
7604 | | |
7605 | | static PyObject * |
7606 | | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7607 | 0 | { |
7608 | 0 | PyObject *return_value = NULL; |
7609 | 0 | int fd; |
7610 | 0 | Py_ssize_t length; |
7611 | |
|
7612 | 0 | if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { |
7613 | 0 | goto exit; |
7614 | 0 | } |
7615 | 0 | fd = PyLong_AsInt(args[0]); |
7616 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7617 | 0 | goto exit; |
7618 | 0 | } |
7619 | 0 | { |
7620 | 0 | Py_ssize_t ival = -1; |
7621 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
7622 | 0 | if (iobj != NULL) { |
7623 | 0 | ival = PyLong_AsSsize_t(iobj); |
7624 | 0 | Py_DECREF(iobj); |
7625 | 0 | } |
7626 | 0 | if (ival == -1 && PyErr_Occurred()) { |
7627 | 0 | goto exit; |
7628 | 0 | } |
7629 | 0 | length = ival; |
7630 | 0 | } |
7631 | 0 | return_value = os_read_impl(module, fd, length); |
7632 | |
|
7633 | 0 | exit: |
7634 | 0 | return return_value; |
7635 | 0 | } |
7636 | | |
7637 | | PyDoc_STRVAR(os_readinto__doc__, |
7638 | | "readinto($module, fd, buffer, /)\n" |
7639 | | "--\n" |
7640 | | "\n" |
7641 | | "Read into a buffer object from a file descriptor.\n" |
7642 | | "\n" |
7643 | | "The buffer should be mutable and bytes-like. On success, returns the number of\n" |
7644 | | "bytes read. Less bytes may be read than the size of the buffer. The underlying\n" |
7645 | | "system call will be retried when interrupted by a signal, unless the signal\n" |
7646 | | "handler raises an exception. Other errors will not be retried and an error will\n" |
7647 | | "be raised.\n" |
7648 | | "\n" |
7649 | | "Returns 0 if *fd* is at end of file or if the provided *buffer* has length 0\n" |
7650 | | "(which can be used to check for errors without reading data). Never returns\n" |
7651 | | "negative."); |
7652 | | |
7653 | | #define OS_READINTO_METHODDEF \ |
7654 | | {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__}, |
7655 | | |
7656 | | static Py_ssize_t |
7657 | | os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer); |
7658 | | |
7659 | | static PyObject * |
7660 | | os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7661 | 0 | { |
7662 | 0 | PyObject *return_value = NULL; |
7663 | 0 | int fd; |
7664 | 0 | Py_buffer buffer = {NULL, NULL}; |
7665 | 0 | Py_ssize_t _return_value; |
7666 | |
|
7667 | 0 | if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) { |
7668 | 0 | goto exit; |
7669 | 0 | } |
7670 | 0 | fd = PyLong_AsInt(args[0]); |
7671 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7672 | 0 | goto exit; |
7673 | 0 | } |
7674 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) { |
7675 | 0 | _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]); |
7676 | 0 | goto exit; |
7677 | 0 | } |
7678 | 0 | _return_value = os_readinto_impl(module, fd, &buffer); |
7679 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7680 | 0 | goto exit; |
7681 | 0 | } |
7682 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7683 | |
|
7684 | 0 | exit: |
7685 | | /* Cleanup for buffer */ |
7686 | 0 | if (buffer.obj) { |
7687 | 0 | PyBuffer_Release(&buffer); |
7688 | 0 | } |
7689 | |
|
7690 | 0 | return return_value; |
7691 | 0 | } |
7692 | | |
7693 | | #if defined(HAVE_READV) |
7694 | | |
7695 | | PyDoc_STRVAR(os_readv__doc__, |
7696 | | "readv($module, fd, buffers, /)\n" |
7697 | | "--\n" |
7698 | | "\n" |
7699 | | "Read from a file descriptor fd into an iterable of buffers.\n" |
7700 | | "\n" |
7701 | | "The buffers should be mutable buffers accepting bytes.\n" |
7702 | | "readv will transfer data into each buffer until it is full\n" |
7703 | | "and then move on to the next buffer in the sequence to hold\n" |
7704 | | "the rest of the data.\n" |
7705 | | "\n" |
7706 | | "readv returns the total number of bytes read,\n" |
7707 | | "which may be less than the total capacity of all the buffers."); |
7708 | | |
7709 | | #define OS_READV_METHODDEF \ |
7710 | | {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__}, |
7711 | | |
7712 | | static Py_ssize_t |
7713 | | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
7714 | | |
7715 | | static PyObject * |
7716 | | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7717 | 0 | { |
7718 | 0 | PyObject *return_value = NULL; |
7719 | 0 | int fd; |
7720 | 0 | PyObject *buffers; |
7721 | 0 | Py_ssize_t _return_value; |
7722 | |
|
7723 | 0 | if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { |
7724 | 0 | goto exit; |
7725 | 0 | } |
7726 | 0 | fd = PyLong_AsInt(args[0]); |
7727 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7728 | 0 | goto exit; |
7729 | 0 | } |
7730 | 0 | buffers = args[1]; |
7731 | 0 | _return_value = os_readv_impl(module, fd, buffers); |
7732 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7733 | 0 | goto exit; |
7734 | 0 | } |
7735 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7736 | |
|
7737 | 0 | exit: |
7738 | 0 | return return_value; |
7739 | 0 | } |
7740 | | |
7741 | | #endif /* defined(HAVE_READV) */ |
7742 | | |
7743 | | #if defined(HAVE_PREAD) |
7744 | | |
7745 | | PyDoc_STRVAR(os_pread__doc__, |
7746 | | "pread($module, fd, length, offset, /)\n" |
7747 | | "--\n" |
7748 | | "\n" |
7749 | | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
7750 | | "\n" |
7751 | | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
7752 | | "the beginning of the file. The file offset remains unchanged."); |
7753 | | |
7754 | | #define OS_PREAD_METHODDEF \ |
7755 | | {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__}, |
7756 | | |
7757 | | static PyObject * |
7758 | | os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset); |
7759 | | |
7760 | | static PyObject * |
7761 | | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7762 | 0 | { |
7763 | 0 | PyObject *return_value = NULL; |
7764 | 0 | int fd; |
7765 | 0 | Py_ssize_t length; |
7766 | 0 | Py_off_t offset; |
7767 | |
|
7768 | 0 | if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { |
7769 | 0 | goto exit; |
7770 | 0 | } |
7771 | 0 | fd = PyLong_AsInt(args[0]); |
7772 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7773 | 0 | goto exit; |
7774 | 0 | } |
7775 | 0 | { |
7776 | 0 | Py_ssize_t ival = -1; |
7777 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
7778 | 0 | if (iobj != NULL) { |
7779 | 0 | ival = PyLong_AsSsize_t(iobj); |
7780 | 0 | Py_DECREF(iobj); |
7781 | 0 | } |
7782 | 0 | if (ival == -1 && PyErr_Occurred()) { |
7783 | 0 | goto exit; |
7784 | 0 | } |
7785 | 0 | length = ival; |
7786 | 0 | } |
7787 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
7788 | 0 | goto exit; |
7789 | 0 | } |
7790 | 0 | return_value = os_pread_impl(module, fd, length, offset); |
7791 | |
|
7792 | 0 | exit: |
7793 | 0 | return return_value; |
7794 | 0 | } |
7795 | | |
7796 | | #endif /* defined(HAVE_PREAD) */ |
7797 | | |
7798 | | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
7799 | | |
7800 | | PyDoc_STRVAR(os_preadv__doc__, |
7801 | | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
7802 | | "--\n" |
7803 | | "\n" |
7804 | | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
7805 | | "\n" |
7806 | | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
7807 | | "transfer data into each buffer until it is full and then move on to the next\n" |
7808 | | "buffer in the sequence to hold the rest of the data. Its fourth argument,\n" |
7809 | | "specifies the file offset at which the input operation is to be performed. It\n" |
7810 | | "will return the total number of bytes read (which can be less than the total\n" |
7811 | | "capacity of all the objects).\n" |
7812 | | "\n" |
7813 | | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
7814 | | "\n" |
7815 | | "- RWF_HIPRI\n" |
7816 | | "- RWF_NOWAIT\n" |
7817 | | "\n" |
7818 | | "Using non-zero flags requires Linux 4.6 or newer."); |
7819 | | |
7820 | | #define OS_PREADV_METHODDEF \ |
7821 | | {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__}, |
7822 | | |
7823 | | static Py_ssize_t |
7824 | | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
7825 | | int flags); |
7826 | | |
7827 | | static PyObject * |
7828 | | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7829 | 0 | { |
7830 | 0 | PyObject *return_value = NULL; |
7831 | 0 | int fd; |
7832 | 0 | PyObject *buffers; |
7833 | 0 | Py_off_t offset; |
7834 | 0 | int flags = 0; |
7835 | 0 | Py_ssize_t _return_value; |
7836 | |
|
7837 | 0 | if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { |
7838 | 0 | goto exit; |
7839 | 0 | } |
7840 | 0 | fd = PyLong_AsInt(args[0]); |
7841 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7842 | 0 | goto exit; |
7843 | 0 | } |
7844 | 0 | buffers = args[1]; |
7845 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
7846 | 0 | goto exit; |
7847 | 0 | } |
7848 | 0 | if (nargs < 4) { |
7849 | 0 | goto skip_optional; |
7850 | 0 | } |
7851 | 0 | flags = PyLong_AsInt(args[3]); |
7852 | 0 | if (flags == -1 && PyErr_Occurred()) { |
7853 | 0 | goto exit; |
7854 | 0 | } |
7855 | 0 | skip_optional: |
7856 | 0 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
7857 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7858 | 0 | goto exit; |
7859 | 0 | } |
7860 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7861 | |
|
7862 | 0 | exit: |
7863 | 0 | return return_value; |
7864 | 0 | } |
7865 | | |
7866 | | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
7867 | | |
7868 | | PyDoc_STRVAR(os_write__doc__, |
7869 | | "write($module, fd, data, /)\n" |
7870 | | "--\n" |
7871 | | "\n" |
7872 | | "Write a bytes object to a file descriptor."); |
7873 | | |
7874 | | #define OS_WRITE_METHODDEF \ |
7875 | | {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__}, |
7876 | | |
7877 | | static Py_ssize_t |
7878 | | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
7879 | | |
7880 | | static PyObject * |
7881 | | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7882 | 0 | { |
7883 | 0 | PyObject *return_value = NULL; |
7884 | 0 | int fd; |
7885 | 0 | Py_buffer data = {NULL, NULL}; |
7886 | 0 | Py_ssize_t _return_value; |
7887 | |
|
7888 | 0 | if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { |
7889 | 0 | goto exit; |
7890 | 0 | } |
7891 | 0 | fd = PyLong_AsInt(args[0]); |
7892 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7893 | 0 | goto exit; |
7894 | 0 | } |
7895 | 0 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
7896 | 0 | goto exit; |
7897 | 0 | } |
7898 | 0 | _return_value = os_write_impl(module, fd, &data); |
7899 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7900 | 0 | goto exit; |
7901 | 0 | } |
7902 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7903 | |
|
7904 | 0 | exit: |
7905 | | /* Cleanup for data */ |
7906 | 0 | if (data.obj) { |
7907 | 0 | PyBuffer_Release(&data); |
7908 | 0 | } |
7909 | |
|
7910 | 0 | return return_value; |
7911 | 0 | } |
7912 | | |
7913 | | #if defined(HAVE_SENDFILE) && defined(__APPLE__) |
7914 | | |
7915 | | PyDoc_STRVAR(os_sendfile__doc__, |
7916 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
7917 | | " trailers=(), flags=0)\n" |
7918 | | "--\n" |
7919 | | "\n" |
7920 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
7921 | | |
7922 | | #define OS_SENDFILE_METHODDEF \ |
7923 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
7924 | | |
7925 | | static PyObject * |
7926 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
7927 | | Py_off_t sbytes, PyObject *headers, PyObject *trailers, |
7928 | | int flags); |
7929 | | |
7930 | | static PyObject * |
7931 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7932 | | { |
7933 | | PyObject *return_value = NULL; |
7934 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7935 | | |
7936 | | #define NUM_KEYWORDS 7 |
7937 | | static struct { |
7938 | | PyGC_Head _this_is_not_used; |
7939 | | PyObject_VAR_HEAD |
7940 | | Py_hash_t ob_hash; |
7941 | | PyObject *ob_item[NUM_KEYWORDS]; |
7942 | | } _kwtuple = { |
7943 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7944 | | .ob_hash = -1, |
7945 | | .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), }, |
7946 | | }; |
7947 | | #undef NUM_KEYWORDS |
7948 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7949 | | |
7950 | | #else // !Py_BUILD_CORE |
7951 | | # define KWTUPLE NULL |
7952 | | #endif // !Py_BUILD_CORE |
7953 | | |
7954 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
7955 | | static _PyArg_Parser _parser = { |
7956 | | .keywords = _keywords, |
7957 | | .fname = "sendfile", |
7958 | | .kwtuple = KWTUPLE, |
7959 | | }; |
7960 | | #undef KWTUPLE |
7961 | | PyObject *argsbuf[7]; |
7962 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
7963 | | int out_fd; |
7964 | | int in_fd; |
7965 | | Py_off_t offset; |
7966 | | Py_off_t sbytes; |
7967 | | PyObject *headers = NULL; |
7968 | | PyObject *trailers = NULL; |
7969 | | int flags = 0; |
7970 | | |
7971 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7972 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7973 | | if (!args) { |
7974 | | goto exit; |
7975 | | } |
7976 | | out_fd = PyLong_AsInt(args[0]); |
7977 | | if (out_fd == -1 && PyErr_Occurred()) { |
7978 | | goto exit; |
7979 | | } |
7980 | | in_fd = PyLong_AsInt(args[1]); |
7981 | | if (in_fd == -1 && PyErr_Occurred()) { |
7982 | | goto exit; |
7983 | | } |
7984 | | if (!Py_off_t_converter(args[2], &offset)) { |
7985 | | goto exit; |
7986 | | } |
7987 | | if (!Py_off_t_converter(args[3], &sbytes)) { |
7988 | | goto exit; |
7989 | | } |
7990 | | if (!noptargs) { |
7991 | | goto skip_optional_pos; |
7992 | | } |
7993 | | if (args[4]) { |
7994 | | headers = args[4]; |
7995 | | if (!--noptargs) { |
7996 | | goto skip_optional_pos; |
7997 | | } |
7998 | | } |
7999 | | if (args[5]) { |
8000 | | trailers = args[5]; |
8001 | | if (!--noptargs) { |
8002 | | goto skip_optional_pos; |
8003 | | } |
8004 | | } |
8005 | | flags = PyLong_AsInt(args[6]); |
8006 | | if (flags == -1 && PyErr_Occurred()) { |
8007 | | goto exit; |
8008 | | } |
8009 | | skip_optional_pos: |
8010 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags); |
8011 | | |
8012 | | exit: |
8013 | | return return_value; |
8014 | | } |
8015 | | |
8016 | | #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */ |
8017 | | |
8018 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) |
8019 | | |
8020 | | PyDoc_STRVAR(os_sendfile__doc__, |
8021 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
8022 | | " trailers=(), flags=0)\n" |
8023 | | "--\n" |
8024 | | "\n" |
8025 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8026 | | |
8027 | | #define OS_SENDFILE_METHODDEF \ |
8028 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8029 | | |
8030 | | static PyObject * |
8031 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
8032 | | Py_ssize_t count, PyObject *headers, PyObject *trailers, |
8033 | | int flags); |
8034 | | |
8035 | | static PyObject * |
8036 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8037 | | { |
8038 | | PyObject *return_value = NULL; |
8039 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8040 | | |
8041 | | #define NUM_KEYWORDS 7 |
8042 | | static struct { |
8043 | | PyGC_Head _this_is_not_used; |
8044 | | PyObject_VAR_HEAD |
8045 | | Py_hash_t ob_hash; |
8046 | | PyObject *ob_item[NUM_KEYWORDS]; |
8047 | | } _kwtuple = { |
8048 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8049 | | .ob_hash = -1, |
8050 | | .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), }, |
8051 | | }; |
8052 | | #undef NUM_KEYWORDS |
8053 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8054 | | |
8055 | | #else // !Py_BUILD_CORE |
8056 | | # define KWTUPLE NULL |
8057 | | #endif // !Py_BUILD_CORE |
8058 | | |
8059 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
8060 | | static _PyArg_Parser _parser = { |
8061 | | .keywords = _keywords, |
8062 | | .fname = "sendfile", |
8063 | | .kwtuple = KWTUPLE, |
8064 | | }; |
8065 | | #undef KWTUPLE |
8066 | | PyObject *argsbuf[7]; |
8067 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
8068 | | int out_fd; |
8069 | | int in_fd; |
8070 | | Py_off_t offset; |
8071 | | Py_ssize_t count; |
8072 | | PyObject *headers = NULL; |
8073 | | PyObject *trailers = NULL; |
8074 | | int flags = 0; |
8075 | | |
8076 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8077 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8078 | | if (!args) { |
8079 | | goto exit; |
8080 | | } |
8081 | | out_fd = PyLong_AsInt(args[0]); |
8082 | | if (out_fd == -1 && PyErr_Occurred()) { |
8083 | | goto exit; |
8084 | | } |
8085 | | in_fd = PyLong_AsInt(args[1]); |
8086 | | if (in_fd == -1 && PyErr_Occurred()) { |
8087 | | goto exit; |
8088 | | } |
8089 | | if (!Py_off_t_converter(args[2], &offset)) { |
8090 | | goto exit; |
8091 | | } |
8092 | | { |
8093 | | Py_ssize_t ival = -1; |
8094 | | PyObject *iobj = _PyNumber_Index(args[3]); |
8095 | | if (iobj != NULL) { |
8096 | | ival = PyLong_AsSsize_t(iobj); |
8097 | | Py_DECREF(iobj); |
8098 | | } |
8099 | | if (ival == -1 && PyErr_Occurred()) { |
8100 | | goto exit; |
8101 | | } |
8102 | | count = ival; |
8103 | | } |
8104 | | if (!noptargs) { |
8105 | | goto skip_optional_pos; |
8106 | | } |
8107 | | if (args[4]) { |
8108 | | headers = args[4]; |
8109 | | if (!--noptargs) { |
8110 | | goto skip_optional_pos; |
8111 | | } |
8112 | | } |
8113 | | if (args[5]) { |
8114 | | trailers = args[5]; |
8115 | | if (!--noptargs) { |
8116 | | goto skip_optional_pos; |
8117 | | } |
8118 | | } |
8119 | | flags = PyLong_AsInt(args[6]); |
8120 | | if (flags == -1 && PyErr_Occurred()) { |
8121 | | goto exit; |
8122 | | } |
8123 | | skip_optional_pos: |
8124 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags); |
8125 | | |
8126 | | exit: |
8127 | | return return_value; |
8128 | | } |
8129 | | |
8130 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8131 | | |
8132 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) |
8133 | | |
8134 | | PyDoc_STRVAR(os_sendfile__doc__, |
8135 | | "sendfile($module, /, out_fd, in_fd, offset, count)\n" |
8136 | | "--\n" |
8137 | | "\n" |
8138 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8139 | | |
8140 | | #define OS_SENDFILE_METHODDEF \ |
8141 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8142 | | |
8143 | | static PyObject * |
8144 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj, |
8145 | | Py_ssize_t count); |
8146 | | |
8147 | | static PyObject * |
8148 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8149 | 0 | { |
8150 | 0 | PyObject *return_value = NULL; |
8151 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8152 | |
|
8153 | 0 | #define NUM_KEYWORDS 4 |
8154 | 0 | static struct { |
8155 | 0 | PyGC_Head _this_is_not_used; |
8156 | 0 | PyObject_VAR_HEAD |
8157 | 0 | Py_hash_t ob_hash; |
8158 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8159 | 0 | } _kwtuple = { |
8160 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8161 | 0 | .ob_hash = -1, |
8162 | 0 | .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), }, |
8163 | 0 | }; |
8164 | 0 | #undef NUM_KEYWORDS |
8165 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8166 | |
|
8167 | | #else // !Py_BUILD_CORE |
8168 | | # define KWTUPLE NULL |
8169 | | #endif // !Py_BUILD_CORE |
8170 | |
|
8171 | 0 | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL}; |
8172 | 0 | static _PyArg_Parser _parser = { |
8173 | 0 | .keywords = _keywords, |
8174 | 0 | .fname = "sendfile", |
8175 | 0 | .kwtuple = KWTUPLE, |
8176 | 0 | }; |
8177 | 0 | #undef KWTUPLE |
8178 | 0 | PyObject *argsbuf[4]; |
8179 | 0 | int out_fd; |
8180 | 0 | int in_fd; |
8181 | 0 | PyObject *offobj; |
8182 | 0 | Py_ssize_t count; |
8183 | |
|
8184 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8185 | 0 | /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8186 | 0 | if (!args) { |
8187 | 0 | goto exit; |
8188 | 0 | } |
8189 | 0 | out_fd = PyLong_AsInt(args[0]); |
8190 | 0 | if (out_fd == -1 && PyErr_Occurred()) { |
8191 | 0 | goto exit; |
8192 | 0 | } |
8193 | 0 | in_fd = PyLong_AsInt(args[1]); |
8194 | 0 | if (in_fd == -1 && PyErr_Occurred()) { |
8195 | 0 | goto exit; |
8196 | 0 | } |
8197 | 0 | offobj = args[2]; |
8198 | 0 | { |
8199 | 0 | Py_ssize_t ival = -1; |
8200 | 0 | PyObject *iobj = _PyNumber_Index(args[3]); |
8201 | 0 | if (iobj != NULL) { |
8202 | 0 | ival = PyLong_AsSsize_t(iobj); |
8203 | 0 | Py_DECREF(iobj); |
8204 | 0 | } |
8205 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8206 | 0 | goto exit; |
8207 | 0 | } |
8208 | 0 | count = ival; |
8209 | 0 | } |
8210 | 0 | return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); |
8211 | |
|
8212 | 0 | exit: |
8213 | 0 | return return_value; |
8214 | 0 | } |
8215 | | |
8216 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8217 | | |
8218 | | #if defined(__APPLE__) |
8219 | | |
8220 | | PyDoc_STRVAR(os__fcopyfile__doc__, |
8221 | | "_fcopyfile($module, in_fd, out_fd, flags, /)\n" |
8222 | | "--\n" |
8223 | | "\n" |
8224 | | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); |
8225 | | |
8226 | | #define OS__FCOPYFILE_METHODDEF \ |
8227 | | {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__}, |
8228 | | |
8229 | | static PyObject * |
8230 | | os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags); |
8231 | | |
8232 | | static PyObject * |
8233 | | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8234 | | { |
8235 | | PyObject *return_value = NULL; |
8236 | | int in_fd; |
8237 | | int out_fd; |
8238 | | int flags; |
8239 | | |
8240 | | if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { |
8241 | | goto exit; |
8242 | | } |
8243 | | in_fd = PyLong_AsInt(args[0]); |
8244 | | if (in_fd == -1 && PyErr_Occurred()) { |
8245 | | goto exit; |
8246 | | } |
8247 | | out_fd = PyLong_AsInt(args[1]); |
8248 | | if (out_fd == -1 && PyErr_Occurred()) { |
8249 | | goto exit; |
8250 | | } |
8251 | | flags = PyLong_AsInt(args[2]); |
8252 | | if (flags == -1 && PyErr_Occurred()) { |
8253 | | goto exit; |
8254 | | } |
8255 | | return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags); |
8256 | | |
8257 | | exit: |
8258 | | return return_value; |
8259 | | } |
8260 | | |
8261 | | #endif /* defined(__APPLE__) */ |
8262 | | |
8263 | | PyDoc_STRVAR(os_fstat__doc__, |
8264 | | "fstat($module, /, fd)\n" |
8265 | | "--\n" |
8266 | | "\n" |
8267 | | "Perform a stat system call on the given file descriptor.\n" |
8268 | | "\n" |
8269 | | "Like stat(), but for an open file descriptor.\n" |
8270 | | "Equivalent to os.stat(fd)."); |
8271 | | |
8272 | | #define OS_FSTAT_METHODDEF \ |
8273 | | {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__}, |
8274 | | |
8275 | | static PyObject * |
8276 | | os_fstat_impl(PyObject *module, int fd); |
8277 | | |
8278 | | static PyObject * |
8279 | | os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8280 | 0 | { |
8281 | 0 | PyObject *return_value = NULL; |
8282 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8283 | |
|
8284 | 0 | #define NUM_KEYWORDS 1 |
8285 | 0 | static struct { |
8286 | 0 | PyGC_Head _this_is_not_used; |
8287 | 0 | PyObject_VAR_HEAD |
8288 | 0 | Py_hash_t ob_hash; |
8289 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8290 | 0 | } _kwtuple = { |
8291 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8292 | 0 | .ob_hash = -1, |
8293 | 0 | .ob_item = { &_Py_ID(fd), }, |
8294 | 0 | }; |
8295 | 0 | #undef NUM_KEYWORDS |
8296 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8297 | |
|
8298 | | #else // !Py_BUILD_CORE |
8299 | | # define KWTUPLE NULL |
8300 | | #endif // !Py_BUILD_CORE |
8301 | |
|
8302 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
8303 | 0 | static _PyArg_Parser _parser = { |
8304 | 0 | .keywords = _keywords, |
8305 | 0 | .fname = "fstat", |
8306 | 0 | .kwtuple = KWTUPLE, |
8307 | 0 | }; |
8308 | 0 | #undef KWTUPLE |
8309 | 0 | PyObject *argsbuf[1]; |
8310 | 0 | int fd; |
8311 | |
|
8312 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8313 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8314 | 0 | if (!args) { |
8315 | 0 | goto exit; |
8316 | 0 | } |
8317 | 0 | fd = PyLong_AsInt(args[0]); |
8318 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8319 | 0 | goto exit; |
8320 | 0 | } |
8321 | 0 | return_value = os_fstat_impl(module, fd); |
8322 | |
|
8323 | 0 | exit: |
8324 | 0 | return return_value; |
8325 | 0 | } |
8326 | | |
8327 | | PyDoc_STRVAR(os_isatty__doc__, |
8328 | | "isatty($module, fd, /)\n" |
8329 | | "--\n" |
8330 | | "\n" |
8331 | | "Return True if the fd is connected to a terminal.\n" |
8332 | | "\n" |
8333 | | "Return True if the file descriptor is an open file descriptor\n" |
8334 | | "connected to the slave end of a terminal."); |
8335 | | |
8336 | | #define OS_ISATTY_METHODDEF \ |
8337 | | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
8338 | | |
8339 | | static int |
8340 | | os_isatty_impl(PyObject *module, int fd); |
8341 | | |
8342 | | static PyObject * |
8343 | | os_isatty(PyObject *module, PyObject *arg) |
8344 | 0 | { |
8345 | 0 | PyObject *return_value = NULL; |
8346 | 0 | int fd; |
8347 | 0 | int _return_value; |
8348 | |
|
8349 | 0 | fd = PyLong_AsInt(arg); |
8350 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8351 | 0 | goto exit; |
8352 | 0 | } |
8353 | 0 | _return_value = os_isatty_impl(module, fd); |
8354 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8355 | 0 | goto exit; |
8356 | 0 | } |
8357 | 0 | return_value = PyBool_FromLong((long)_return_value); |
8358 | |
|
8359 | 0 | exit: |
8360 | 0 | return return_value; |
8361 | 0 | } |
8362 | | |
8363 | | #if defined(HAVE_PIPE) |
8364 | | |
8365 | | PyDoc_STRVAR(os_pipe__doc__, |
8366 | | "pipe($module, /)\n" |
8367 | | "--\n" |
8368 | | "\n" |
8369 | | "Create a pipe.\n" |
8370 | | "\n" |
8371 | | "Returns a tuple of two file descriptors:\n" |
8372 | | " (read_fd, write_fd)"); |
8373 | | |
8374 | | #define OS_PIPE_METHODDEF \ |
8375 | | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
8376 | | |
8377 | | static PyObject * |
8378 | | os_pipe_impl(PyObject *module); |
8379 | | |
8380 | | static PyObject * |
8381 | | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
8382 | 0 | { |
8383 | 0 | return os_pipe_impl(module); |
8384 | 0 | } |
8385 | | |
8386 | | #endif /* defined(HAVE_PIPE) */ |
8387 | | |
8388 | | #if defined(HAVE_PIPE2) |
8389 | | |
8390 | | PyDoc_STRVAR(os_pipe2__doc__, |
8391 | | "pipe2($module, flags, /)\n" |
8392 | | "--\n" |
8393 | | "\n" |
8394 | | "Create a pipe with flags set atomically.\n" |
8395 | | "\n" |
8396 | | "Returns a tuple of two file descriptors:\n" |
8397 | | " (read_fd, write_fd)\n" |
8398 | | "\n" |
8399 | | "flags can be constructed by ORing together one or more of these values:\n" |
8400 | | "O_NONBLOCK, O_CLOEXEC."); |
8401 | | |
8402 | | #define OS_PIPE2_METHODDEF \ |
8403 | | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
8404 | | |
8405 | | static PyObject * |
8406 | | os_pipe2_impl(PyObject *module, int flags); |
8407 | | |
8408 | | static PyObject * |
8409 | | os_pipe2(PyObject *module, PyObject *arg) |
8410 | 0 | { |
8411 | 0 | PyObject *return_value = NULL; |
8412 | 0 | int flags; |
8413 | |
|
8414 | 0 | flags = PyLong_AsInt(arg); |
8415 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8416 | 0 | goto exit; |
8417 | 0 | } |
8418 | 0 | return_value = os_pipe2_impl(module, flags); |
8419 | |
|
8420 | 0 | exit: |
8421 | 0 | return return_value; |
8422 | 0 | } |
8423 | | |
8424 | | #endif /* defined(HAVE_PIPE2) */ |
8425 | | |
8426 | | #if defined(HAVE_WRITEV) |
8427 | | |
8428 | | PyDoc_STRVAR(os_writev__doc__, |
8429 | | "writev($module, fd, buffers, /)\n" |
8430 | | "--\n" |
8431 | | "\n" |
8432 | | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
8433 | | "\n" |
8434 | | "Returns the total number of bytes written.\n" |
8435 | | "buffers must be a sequence of bytes-like objects."); |
8436 | | |
8437 | | #define OS_WRITEV_METHODDEF \ |
8438 | | {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__}, |
8439 | | |
8440 | | static Py_ssize_t |
8441 | | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
8442 | | |
8443 | | static PyObject * |
8444 | | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8445 | 0 | { |
8446 | 0 | PyObject *return_value = NULL; |
8447 | 0 | int fd; |
8448 | 0 | PyObject *buffers; |
8449 | 0 | Py_ssize_t _return_value; |
8450 | |
|
8451 | 0 | if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { |
8452 | 0 | goto exit; |
8453 | 0 | } |
8454 | 0 | fd = PyLong_AsInt(args[0]); |
8455 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8456 | 0 | goto exit; |
8457 | 0 | } |
8458 | 0 | buffers = args[1]; |
8459 | 0 | _return_value = os_writev_impl(module, fd, buffers); |
8460 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8461 | 0 | goto exit; |
8462 | 0 | } |
8463 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8464 | |
|
8465 | 0 | exit: |
8466 | 0 | return return_value; |
8467 | 0 | } |
8468 | | |
8469 | | #endif /* defined(HAVE_WRITEV) */ |
8470 | | |
8471 | | #if defined(HAVE_PWRITE) |
8472 | | |
8473 | | PyDoc_STRVAR(os_pwrite__doc__, |
8474 | | "pwrite($module, fd, buffer, offset, /)\n" |
8475 | | "--\n" |
8476 | | "\n" |
8477 | | "Write bytes to a file descriptor starting at a particular offset.\n" |
8478 | | "\n" |
8479 | | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
8480 | | "the file. Returns the number of bytes written. Does not change the\n" |
8481 | | "current file offset."); |
8482 | | |
8483 | | #define OS_PWRITE_METHODDEF \ |
8484 | | {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__}, |
8485 | | |
8486 | | static Py_ssize_t |
8487 | | os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset); |
8488 | | |
8489 | | static PyObject * |
8490 | | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8491 | 0 | { |
8492 | 0 | PyObject *return_value = NULL; |
8493 | 0 | int fd; |
8494 | 0 | Py_buffer buffer = {NULL, NULL}; |
8495 | 0 | Py_off_t offset; |
8496 | 0 | Py_ssize_t _return_value; |
8497 | |
|
8498 | 0 | if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { |
8499 | 0 | goto exit; |
8500 | 0 | } |
8501 | 0 | fd = PyLong_AsInt(args[0]); |
8502 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8503 | 0 | goto exit; |
8504 | 0 | } |
8505 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
8506 | 0 | goto exit; |
8507 | 0 | } |
8508 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
8509 | 0 | goto exit; |
8510 | 0 | } |
8511 | 0 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
8512 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8513 | 0 | goto exit; |
8514 | 0 | } |
8515 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8516 | |
|
8517 | 0 | exit: |
8518 | | /* Cleanup for buffer */ |
8519 | 0 | if (buffer.obj) { |
8520 | 0 | PyBuffer_Release(&buffer); |
8521 | 0 | } |
8522 | |
|
8523 | 0 | return return_value; |
8524 | 0 | } |
8525 | | |
8526 | | #endif /* defined(HAVE_PWRITE) */ |
8527 | | |
8528 | | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
8529 | | |
8530 | | PyDoc_STRVAR(os_pwritev__doc__, |
8531 | | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
8532 | | "--\n" |
8533 | | "\n" |
8534 | | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
8535 | | "\n" |
8536 | | "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n" |
8537 | | "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n" |
8538 | | "buffer is written before proceeding to second, and so on. The operating system may\n" |
8539 | | "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n" |
8540 | | "This function writes the contents of each object to the file descriptor and returns\n" |
8541 | | "the total number of bytes written.\n" |
8542 | | "\n" |
8543 | | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
8544 | | "\n" |
8545 | | "- RWF_DSYNC\n" |
8546 | | "- RWF_SYNC\n" |
8547 | | "- RWF_APPEND\n" |
8548 | | "\n" |
8549 | | "Using non-zero flags requires Linux 4.7 or newer."); |
8550 | | |
8551 | | #define OS_PWRITEV_METHODDEF \ |
8552 | | {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__}, |
8553 | | |
8554 | | static Py_ssize_t |
8555 | | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
8556 | | int flags); |
8557 | | |
8558 | | static PyObject * |
8559 | | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8560 | 0 | { |
8561 | 0 | PyObject *return_value = NULL; |
8562 | 0 | int fd; |
8563 | 0 | PyObject *buffers; |
8564 | 0 | Py_off_t offset; |
8565 | 0 | int flags = 0; |
8566 | 0 | Py_ssize_t _return_value; |
8567 | |
|
8568 | 0 | if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { |
8569 | 0 | goto exit; |
8570 | 0 | } |
8571 | 0 | fd = PyLong_AsInt(args[0]); |
8572 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8573 | 0 | goto exit; |
8574 | 0 | } |
8575 | 0 | buffers = args[1]; |
8576 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
8577 | 0 | goto exit; |
8578 | 0 | } |
8579 | 0 | if (nargs < 4) { |
8580 | 0 | goto skip_optional; |
8581 | 0 | } |
8582 | 0 | flags = PyLong_AsInt(args[3]); |
8583 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8584 | 0 | goto exit; |
8585 | 0 | } |
8586 | 0 | skip_optional: |
8587 | 0 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
8588 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8589 | 0 | goto exit; |
8590 | 0 | } |
8591 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8592 | |
|
8593 | 0 | exit: |
8594 | 0 | return return_value; |
8595 | 0 | } |
8596 | | |
8597 | | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
8598 | | |
8599 | | #if defined(HAVE_COPY_FILE_RANGE) |
8600 | | |
8601 | | PyDoc_STRVAR(os_copy_file_range__doc__, |
8602 | | "copy_file_range($module, /, src, dst, count, offset_src=None,\n" |
8603 | | " offset_dst=None)\n" |
8604 | | "--\n" |
8605 | | "\n" |
8606 | | "Copy count bytes from one file descriptor to another.\n" |
8607 | | "\n" |
8608 | | " src\n" |
8609 | | " Source file descriptor.\n" |
8610 | | " dst\n" |
8611 | | " Destination file descriptor.\n" |
8612 | | " count\n" |
8613 | | " Number of bytes to copy.\n" |
8614 | | " offset_src\n" |
8615 | | " Starting offset in src.\n" |
8616 | | " offset_dst\n" |
8617 | | " Starting offset in dst.\n" |
8618 | | "\n" |
8619 | | "If offset_src is None, then src is read from the current position;\n" |
8620 | | "respectively for offset_dst."); |
8621 | | |
8622 | | #define OS_COPY_FILE_RANGE_METHODDEF \ |
8623 | | {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__}, |
8624 | | |
8625 | | static PyObject * |
8626 | | os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
8627 | | PyObject *offset_src, PyObject *offset_dst); |
8628 | | |
8629 | | static PyObject * |
8630 | | os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8631 | 0 | { |
8632 | 0 | PyObject *return_value = NULL; |
8633 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8634 | |
|
8635 | 0 | #define NUM_KEYWORDS 5 |
8636 | 0 | static struct { |
8637 | 0 | PyGC_Head _this_is_not_used; |
8638 | 0 | PyObject_VAR_HEAD |
8639 | 0 | Py_hash_t ob_hash; |
8640 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8641 | 0 | } _kwtuple = { |
8642 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8643 | 0 | .ob_hash = -1, |
8644 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), }, |
8645 | 0 | }; |
8646 | 0 | #undef NUM_KEYWORDS |
8647 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8648 | |
|
8649 | | #else // !Py_BUILD_CORE |
8650 | | # define KWTUPLE NULL |
8651 | | #endif // !Py_BUILD_CORE |
8652 | |
|
8653 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL}; |
8654 | 0 | static _PyArg_Parser _parser = { |
8655 | 0 | .keywords = _keywords, |
8656 | 0 | .fname = "copy_file_range", |
8657 | 0 | .kwtuple = KWTUPLE, |
8658 | 0 | }; |
8659 | 0 | #undef KWTUPLE |
8660 | 0 | PyObject *argsbuf[5]; |
8661 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
8662 | 0 | int src; |
8663 | 0 | int dst; |
8664 | 0 | Py_ssize_t count; |
8665 | 0 | PyObject *offset_src = Py_None; |
8666 | 0 | PyObject *offset_dst = Py_None; |
8667 | |
|
8668 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8669 | 0 | /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8670 | 0 | if (!args) { |
8671 | 0 | goto exit; |
8672 | 0 | } |
8673 | 0 | src = PyLong_AsInt(args[0]); |
8674 | 0 | if (src == -1 && PyErr_Occurred()) { |
8675 | 0 | goto exit; |
8676 | 0 | } |
8677 | 0 | dst = PyLong_AsInt(args[1]); |
8678 | 0 | if (dst == -1 && PyErr_Occurred()) { |
8679 | 0 | goto exit; |
8680 | 0 | } |
8681 | 0 | { |
8682 | 0 | Py_ssize_t ival = -1; |
8683 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
8684 | 0 | if (iobj != NULL) { |
8685 | 0 | ival = PyLong_AsSsize_t(iobj); |
8686 | 0 | Py_DECREF(iobj); |
8687 | 0 | } |
8688 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8689 | 0 | goto exit; |
8690 | 0 | } |
8691 | 0 | count = ival; |
8692 | 0 | } |
8693 | 0 | if (!noptargs) { |
8694 | 0 | goto skip_optional_pos; |
8695 | 0 | } |
8696 | 0 | if (args[3]) { |
8697 | 0 | offset_src = args[3]; |
8698 | 0 | if (!--noptargs) { |
8699 | 0 | goto skip_optional_pos; |
8700 | 0 | } |
8701 | 0 | } |
8702 | 0 | offset_dst = args[4]; |
8703 | 0 | skip_optional_pos: |
8704 | 0 | return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst); |
8705 | |
|
8706 | 0 | exit: |
8707 | 0 | return return_value; |
8708 | 0 | } |
8709 | | |
8710 | | #endif /* defined(HAVE_COPY_FILE_RANGE) */ |
8711 | | |
8712 | | #if ((defined(HAVE_SPLICE) && !defined(_AIX))) |
8713 | | |
8714 | | PyDoc_STRVAR(os_splice__doc__, |
8715 | | "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n" |
8716 | | " flags=0)\n" |
8717 | | "--\n" |
8718 | | "\n" |
8719 | | "Transfer count bytes from one pipe to a descriptor or vice versa.\n" |
8720 | | "\n" |
8721 | | " src\n" |
8722 | | " Source file descriptor.\n" |
8723 | | " dst\n" |
8724 | | " Destination file descriptor.\n" |
8725 | | " count\n" |
8726 | | " Number of bytes to copy.\n" |
8727 | | " offset_src\n" |
8728 | | " Starting offset in src.\n" |
8729 | | " offset_dst\n" |
8730 | | " Starting offset in dst.\n" |
8731 | | " flags\n" |
8732 | | " Flags to modify the semantics of the call.\n" |
8733 | | "\n" |
8734 | | "If offset_src is None, then src is read from the current position;\n" |
8735 | | "respectively for offset_dst. The offset associated to the file\n" |
8736 | | "descriptor that refers to a pipe must be None."); |
8737 | | |
8738 | | #define OS_SPLICE_METHODDEF \ |
8739 | | {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__}, |
8740 | | |
8741 | | static PyObject * |
8742 | | os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
8743 | | PyObject *offset_src, PyObject *offset_dst, |
8744 | | unsigned int flags); |
8745 | | |
8746 | | static PyObject * |
8747 | | os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8748 | 0 | { |
8749 | 0 | PyObject *return_value = NULL; |
8750 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8751 | |
|
8752 | 0 | #define NUM_KEYWORDS 6 |
8753 | 0 | static struct { |
8754 | 0 | PyGC_Head _this_is_not_used; |
8755 | 0 | PyObject_VAR_HEAD |
8756 | 0 | Py_hash_t ob_hash; |
8757 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8758 | 0 | } _kwtuple = { |
8759 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8760 | 0 | .ob_hash = -1, |
8761 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), }, |
8762 | 0 | }; |
8763 | 0 | #undef NUM_KEYWORDS |
8764 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8765 | |
|
8766 | | #else // !Py_BUILD_CORE |
8767 | | # define KWTUPLE NULL |
8768 | | #endif // !Py_BUILD_CORE |
8769 | |
|
8770 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL}; |
8771 | 0 | static _PyArg_Parser _parser = { |
8772 | 0 | .keywords = _keywords, |
8773 | 0 | .fname = "splice", |
8774 | 0 | .kwtuple = KWTUPLE, |
8775 | 0 | }; |
8776 | 0 | #undef KWTUPLE |
8777 | 0 | PyObject *argsbuf[6]; |
8778 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
8779 | 0 | int src; |
8780 | 0 | int dst; |
8781 | 0 | Py_ssize_t count; |
8782 | 0 | PyObject *offset_src = Py_None; |
8783 | 0 | PyObject *offset_dst = Py_None; |
8784 | 0 | unsigned int flags = 0; |
8785 | |
|
8786 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8787 | 0 | /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8788 | 0 | if (!args) { |
8789 | 0 | goto exit; |
8790 | 0 | } |
8791 | 0 | src = PyLong_AsInt(args[0]); |
8792 | 0 | if (src == -1 && PyErr_Occurred()) { |
8793 | 0 | goto exit; |
8794 | 0 | } |
8795 | 0 | dst = PyLong_AsInt(args[1]); |
8796 | 0 | if (dst == -1 && PyErr_Occurred()) { |
8797 | 0 | goto exit; |
8798 | 0 | } |
8799 | 0 | { |
8800 | 0 | Py_ssize_t ival = -1; |
8801 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
8802 | 0 | if (iobj != NULL) { |
8803 | 0 | ival = PyLong_AsSsize_t(iobj); |
8804 | 0 | Py_DECREF(iobj); |
8805 | 0 | } |
8806 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8807 | 0 | goto exit; |
8808 | 0 | } |
8809 | 0 | count = ival; |
8810 | 0 | } |
8811 | 0 | if (!noptargs) { |
8812 | 0 | goto skip_optional_pos; |
8813 | 0 | } |
8814 | 0 | if (args[3]) { |
8815 | 0 | offset_src = args[3]; |
8816 | 0 | if (!--noptargs) { |
8817 | 0 | goto skip_optional_pos; |
8818 | 0 | } |
8819 | 0 | } |
8820 | 0 | if (args[4]) { |
8821 | 0 | offset_dst = args[4]; |
8822 | 0 | if (!--noptargs) { |
8823 | 0 | goto skip_optional_pos; |
8824 | 0 | } |
8825 | 0 | } |
8826 | 0 | if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) { |
8827 | 0 | goto exit; |
8828 | 0 | } |
8829 | 0 | skip_optional_pos: |
8830 | 0 | return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags); |
8831 | |
|
8832 | 0 | exit: |
8833 | 0 | return return_value; |
8834 | 0 | } |
8835 | | |
8836 | | #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */ |
8837 | | |
8838 | | #if defined(HAVE_MKFIFO) |
8839 | | |
8840 | | PyDoc_STRVAR(os_mkfifo__doc__, |
8841 | | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
8842 | | "--\n" |
8843 | | "\n" |
8844 | | "Create a \"fifo\" (a POSIX named pipe).\n" |
8845 | | "\n" |
8846 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
8847 | | " and path should be relative; path will then be relative to that directory.\n" |
8848 | | "dir_fd may not be implemented on your platform.\n" |
8849 | | " If it is unavailable, using it will raise a NotImplementedError."); |
8850 | | |
8851 | | #define OS_MKFIFO_METHODDEF \ |
8852 | | {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__}, |
8853 | | |
8854 | | static PyObject * |
8855 | | os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
8856 | | |
8857 | | static PyObject * |
8858 | | os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8859 | 0 | { |
8860 | 0 | PyObject *return_value = NULL; |
8861 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8862 | |
|
8863 | 0 | #define NUM_KEYWORDS 3 |
8864 | 0 | static struct { |
8865 | 0 | PyGC_Head _this_is_not_used; |
8866 | 0 | PyObject_VAR_HEAD |
8867 | 0 | Py_hash_t ob_hash; |
8868 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8869 | 0 | } _kwtuple = { |
8870 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8871 | 0 | .ob_hash = -1, |
8872 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
8873 | 0 | }; |
8874 | 0 | #undef NUM_KEYWORDS |
8875 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8876 | |
|
8877 | | #else // !Py_BUILD_CORE |
8878 | | # define KWTUPLE NULL |
8879 | | #endif // !Py_BUILD_CORE |
8880 | |
|
8881 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
8882 | 0 | static _PyArg_Parser _parser = { |
8883 | 0 | .keywords = _keywords, |
8884 | 0 | .fname = "mkfifo", |
8885 | 0 | .kwtuple = KWTUPLE, |
8886 | 0 | }; |
8887 | 0 | #undef KWTUPLE |
8888 | 0 | PyObject *argsbuf[3]; |
8889 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
8890 | 0 | path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0); |
8891 | 0 | int mode = 438; |
8892 | 0 | int dir_fd = DEFAULT_DIR_FD; |
8893 | |
|
8894 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8895 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8896 | 0 | if (!args) { |
8897 | 0 | goto exit; |
8898 | 0 | } |
8899 | 0 | if (!path_converter(args[0], &path)) { |
8900 | 0 | goto exit; |
8901 | 0 | } |
8902 | 0 | if (!noptargs) { |
8903 | 0 | goto skip_optional_pos; |
8904 | 0 | } |
8905 | 0 | if (args[1]) { |
8906 | 0 | mode = PyLong_AsInt(args[1]); |
8907 | 0 | if (mode == -1 && PyErr_Occurred()) { |
8908 | 0 | goto exit; |
8909 | 0 | } |
8910 | 0 | if (!--noptargs) { |
8911 | 0 | goto skip_optional_pos; |
8912 | 0 | } |
8913 | 0 | } |
8914 | 0 | skip_optional_pos: |
8915 | 0 | if (!noptargs) { |
8916 | 0 | goto skip_optional_kwonly; |
8917 | 0 | } |
8918 | 0 | if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
8919 | 0 | goto exit; |
8920 | 0 | } |
8921 | 0 | skip_optional_kwonly: |
8922 | 0 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
8923 | |
|
8924 | 0 | exit: |
8925 | | /* Cleanup for path */ |
8926 | 0 | path_cleanup(&path); |
8927 | |
|
8928 | 0 | return return_value; |
8929 | 0 | } |
8930 | | |
8931 | | #endif /* defined(HAVE_MKFIFO) */ |
8932 | | |
8933 | | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
8934 | | |
8935 | | PyDoc_STRVAR(os_mknod__doc__, |
8936 | | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
8937 | | "--\n" |
8938 | | "\n" |
8939 | | "Create a node in the file system.\n" |
8940 | | "\n" |
8941 | | "Create a node in the file system (file, device special file or named pipe)\n" |
8942 | | "at path. mode specifies both the permissions to use and the\n" |
8943 | | "type of node to be created, being combined (bitwise OR) with one of\n" |
8944 | | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
8945 | | "device defines the newly created device special file (probably using\n" |
8946 | | "os.makedev()). Otherwise device is ignored.\n" |
8947 | | "\n" |
8948 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
8949 | | " and path should be relative; path will then be relative to that directory.\n" |
8950 | | "dir_fd may not be implemented on your platform.\n" |
8951 | | " If it is unavailable, using it will raise a NotImplementedError."); |
8952 | | |
8953 | | #define OS_MKNOD_METHODDEF \ |
8954 | | {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__}, |
8955 | | |
8956 | | static PyObject * |
8957 | | os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device, |
8958 | | int dir_fd); |
8959 | | |
8960 | | static PyObject * |
8961 | | os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8962 | 0 | { |
8963 | 0 | PyObject *return_value = NULL; |
8964 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8965 | |
|
8966 | 0 | #define NUM_KEYWORDS 4 |
8967 | 0 | static struct { |
8968 | 0 | PyGC_Head _this_is_not_used; |
8969 | 0 | PyObject_VAR_HEAD |
8970 | 0 | Py_hash_t ob_hash; |
8971 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8972 | 0 | } _kwtuple = { |
8973 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8974 | 0 | .ob_hash = -1, |
8975 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), }, |
8976 | 0 | }; |
8977 | 0 | #undef NUM_KEYWORDS |
8978 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8979 | |
|
8980 | | #else // !Py_BUILD_CORE |
8981 | | # define KWTUPLE NULL |
8982 | | #endif // !Py_BUILD_CORE |
8983 | |
|
8984 | 0 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
8985 | 0 | static _PyArg_Parser _parser = { |
8986 | 0 | .keywords = _keywords, |
8987 | 0 | .fname = "mknod", |
8988 | 0 | .kwtuple = KWTUPLE, |
8989 | 0 | }; |
8990 | 0 | #undef KWTUPLE |
8991 | 0 | PyObject *argsbuf[4]; |
8992 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
8993 | 0 | path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0); |
8994 | 0 | int mode = 384; |
8995 | 0 | dev_t device = 0; |
8996 | 0 | int dir_fd = DEFAULT_DIR_FD; |
8997 | |
|
8998 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8999 | 0 | /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9000 | 0 | if (!args) { |
9001 | 0 | goto exit; |
9002 | 0 | } |
9003 | 0 | if (!path_converter(args[0], &path)) { |
9004 | 0 | goto exit; |
9005 | 0 | } |
9006 | 0 | if (!noptargs) { |
9007 | 0 | goto skip_optional_pos; |
9008 | 0 | } |
9009 | 0 | if (args[1]) { |
9010 | 0 | mode = PyLong_AsInt(args[1]); |
9011 | 0 | if (mode == -1 && PyErr_Occurred()) { |
9012 | 0 | goto exit; |
9013 | 0 | } |
9014 | 0 | if (!--noptargs) { |
9015 | 0 | goto skip_optional_pos; |
9016 | 0 | } |
9017 | 0 | } |
9018 | 0 | if (args[2]) { |
9019 | 0 | if (!_Py_Dev_Converter(args[2], &device)) { |
9020 | 0 | goto exit; |
9021 | 0 | } |
9022 | 0 | if (!--noptargs) { |
9023 | 0 | goto skip_optional_pos; |
9024 | 0 | } |
9025 | 0 | } |
9026 | 0 | skip_optional_pos: |
9027 | 0 | if (!noptargs) { |
9028 | 0 | goto skip_optional_kwonly; |
9029 | 0 | } |
9030 | 0 | if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
9031 | 0 | goto exit; |
9032 | 0 | } |
9033 | 0 | skip_optional_kwonly: |
9034 | 0 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
9035 | |
|
9036 | 0 | exit: |
9037 | | /* Cleanup for path */ |
9038 | 0 | path_cleanup(&path); |
9039 | |
|
9040 | 0 | return return_value; |
9041 | 0 | } |
9042 | | |
9043 | | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
9044 | | |
9045 | | #if defined(HAVE_DEVICE_MACROS) |
9046 | | |
9047 | | PyDoc_STRVAR(os_major__doc__, |
9048 | | "major($module, device, /)\n" |
9049 | | "--\n" |
9050 | | "\n" |
9051 | | "Extracts a device major number from a raw device number."); |
9052 | | |
9053 | | #define OS_MAJOR_METHODDEF \ |
9054 | | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
9055 | | |
9056 | | static PyObject * |
9057 | | os_major_impl(PyObject *module, dev_t device); |
9058 | | |
9059 | | static PyObject * |
9060 | | os_major(PyObject *module, PyObject *arg) |
9061 | 0 | { |
9062 | 0 | PyObject *return_value = NULL; |
9063 | 0 | dev_t device; |
9064 | |
|
9065 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9066 | 0 | goto exit; |
9067 | 0 | } |
9068 | 0 | return_value = os_major_impl(module, device); |
9069 | |
|
9070 | 0 | exit: |
9071 | 0 | return return_value; |
9072 | 0 | } |
9073 | | |
9074 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9075 | | |
9076 | | #if defined(HAVE_DEVICE_MACROS) |
9077 | | |
9078 | | PyDoc_STRVAR(os_minor__doc__, |
9079 | | "minor($module, device, /)\n" |
9080 | | "--\n" |
9081 | | "\n" |
9082 | | "Extracts a device minor number from a raw device number."); |
9083 | | |
9084 | | #define OS_MINOR_METHODDEF \ |
9085 | | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
9086 | | |
9087 | | static PyObject * |
9088 | | os_minor_impl(PyObject *module, dev_t device); |
9089 | | |
9090 | | static PyObject * |
9091 | | os_minor(PyObject *module, PyObject *arg) |
9092 | 0 | { |
9093 | 0 | PyObject *return_value = NULL; |
9094 | 0 | dev_t device; |
9095 | |
|
9096 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9097 | 0 | goto exit; |
9098 | 0 | } |
9099 | 0 | return_value = os_minor_impl(module, device); |
9100 | |
|
9101 | 0 | exit: |
9102 | 0 | return return_value; |
9103 | 0 | } |
9104 | | |
9105 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9106 | | |
9107 | | #if defined(HAVE_DEVICE_MACROS) |
9108 | | |
9109 | | PyDoc_STRVAR(os_makedev__doc__, |
9110 | | "makedev($module, major, minor, /)\n" |
9111 | | "--\n" |
9112 | | "\n" |
9113 | | "Composes a raw device number from the major and minor device numbers."); |
9114 | | |
9115 | | #define OS_MAKEDEV_METHODDEF \ |
9116 | | {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__}, |
9117 | | |
9118 | | static dev_t |
9119 | | os_makedev_impl(PyObject *module, dev_t major, dev_t minor); |
9120 | | |
9121 | | static PyObject * |
9122 | | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9123 | 0 | { |
9124 | 0 | PyObject *return_value = NULL; |
9125 | 0 | dev_t major; |
9126 | 0 | dev_t minor; |
9127 | 0 | dev_t _return_value; |
9128 | |
|
9129 | 0 | if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { |
9130 | 0 | goto exit; |
9131 | 0 | } |
9132 | 0 | if (!_Py_Dev_Converter(args[0], &major)) { |
9133 | 0 | goto exit; |
9134 | 0 | } |
9135 | 0 | if (!_Py_Dev_Converter(args[1], &minor)) { |
9136 | 0 | goto exit; |
9137 | 0 | } |
9138 | 0 | _return_value = os_makedev_impl(module, major, minor); |
9139 | 0 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
9140 | 0 | goto exit; |
9141 | 0 | } |
9142 | 0 | return_value = _PyLong_FromDev(_return_value); |
9143 | |
|
9144 | 0 | exit: |
9145 | 0 | return return_value; |
9146 | 0 | } |
9147 | | |
9148 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9149 | | |
9150 | | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
9151 | | |
9152 | | PyDoc_STRVAR(os_ftruncate__doc__, |
9153 | | "ftruncate($module, fd, length, /)\n" |
9154 | | "--\n" |
9155 | | "\n" |
9156 | | "Truncate a file, specified by file descriptor, to a specific length."); |
9157 | | |
9158 | | #define OS_FTRUNCATE_METHODDEF \ |
9159 | | {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__}, |
9160 | | |
9161 | | static PyObject * |
9162 | | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
9163 | | |
9164 | | static PyObject * |
9165 | | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9166 | 0 | { |
9167 | 0 | PyObject *return_value = NULL; |
9168 | 0 | int fd; |
9169 | 0 | Py_off_t length; |
9170 | |
|
9171 | 0 | if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { |
9172 | 0 | goto exit; |
9173 | 0 | } |
9174 | 0 | fd = PyLong_AsInt(args[0]); |
9175 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9176 | 0 | goto exit; |
9177 | 0 | } |
9178 | 0 | if (!Py_off_t_converter(args[1], &length)) { |
9179 | 0 | goto exit; |
9180 | 0 | } |
9181 | 0 | return_value = os_ftruncate_impl(module, fd, length); |
9182 | |
|
9183 | 0 | exit: |
9184 | 0 | return return_value; |
9185 | 0 | } |
9186 | | |
9187 | | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
9188 | | |
9189 | | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
9190 | | |
9191 | | PyDoc_STRVAR(os_truncate__doc__, |
9192 | | "truncate($module, /, path, length)\n" |
9193 | | "--\n" |
9194 | | "\n" |
9195 | | "Truncate a file, specified by path, to a specific length.\n" |
9196 | | "\n" |
9197 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
9198 | | " If this functionality is unavailable, using it raises an exception."); |
9199 | | |
9200 | | #define OS_TRUNCATE_METHODDEF \ |
9201 | | {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__}, |
9202 | | |
9203 | | static PyObject * |
9204 | | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
9205 | | |
9206 | | static PyObject * |
9207 | | os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9208 | 0 | { |
9209 | 0 | PyObject *return_value = NULL; |
9210 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9211 | |
|
9212 | 0 | #define NUM_KEYWORDS 2 |
9213 | 0 | static struct { |
9214 | 0 | PyGC_Head _this_is_not_used; |
9215 | 0 | PyObject_VAR_HEAD |
9216 | 0 | Py_hash_t ob_hash; |
9217 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9218 | 0 | } _kwtuple = { |
9219 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9220 | 0 | .ob_hash = -1, |
9221 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(length), }, |
9222 | 0 | }; |
9223 | 0 | #undef NUM_KEYWORDS |
9224 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9225 | |
|
9226 | | #else // !Py_BUILD_CORE |
9227 | | # define KWTUPLE NULL |
9228 | | #endif // !Py_BUILD_CORE |
9229 | |
|
9230 | 0 | static const char * const _keywords[] = {"path", "length", NULL}; |
9231 | 0 | static _PyArg_Parser _parser = { |
9232 | 0 | .keywords = _keywords, |
9233 | 0 | .fname = "truncate", |
9234 | 0 | .kwtuple = KWTUPLE, |
9235 | 0 | }; |
9236 | 0 | #undef KWTUPLE |
9237 | 0 | PyObject *argsbuf[2]; |
9238 | 0 | path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE); |
9239 | 0 | Py_off_t length; |
9240 | |
|
9241 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9242 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9243 | 0 | if (!args) { |
9244 | 0 | goto exit; |
9245 | 0 | } |
9246 | 0 | if (!path_converter(args[0], &path)) { |
9247 | 0 | goto exit; |
9248 | 0 | } |
9249 | 0 | if (!Py_off_t_converter(args[1], &length)) { |
9250 | 0 | goto exit; |
9251 | 0 | } |
9252 | 0 | return_value = os_truncate_impl(module, &path, length); |
9253 | |
|
9254 | 0 | exit: |
9255 | | /* Cleanup for path */ |
9256 | 0 | path_cleanup(&path); |
9257 | |
|
9258 | 0 | return return_value; |
9259 | 0 | } |
9260 | | |
9261 | | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
9262 | | |
9263 | | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) |
9264 | | |
9265 | | PyDoc_STRVAR(os_posix_fallocate__doc__, |
9266 | | "posix_fallocate($module, fd, offset, length, /)\n" |
9267 | | "--\n" |
9268 | | "\n" |
9269 | | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
9270 | | "\n" |
9271 | | "Ensure that the file specified by fd encompasses a range of bytes\n" |
9272 | | "starting at offset bytes from the beginning and continuing for length bytes."); |
9273 | | |
9274 | | #define OS_POSIX_FALLOCATE_METHODDEF \ |
9275 | | {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__}, |
9276 | | |
9277 | | static PyObject * |
9278 | | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
9279 | | Py_off_t length); |
9280 | | |
9281 | | static PyObject * |
9282 | | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9283 | 0 | { |
9284 | 0 | PyObject *return_value = NULL; |
9285 | 0 | int fd; |
9286 | 0 | Py_off_t offset; |
9287 | 0 | Py_off_t length; |
9288 | |
|
9289 | 0 | if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { |
9290 | 0 | goto exit; |
9291 | 0 | } |
9292 | 0 | fd = PyLong_AsInt(args[0]); |
9293 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9294 | 0 | goto exit; |
9295 | 0 | } |
9296 | 0 | if (!Py_off_t_converter(args[1], &offset)) { |
9297 | 0 | goto exit; |
9298 | 0 | } |
9299 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
9300 | 0 | goto exit; |
9301 | 0 | } |
9302 | 0 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
9303 | |
|
9304 | 0 | exit: |
9305 | 0 | return return_value; |
9306 | 0 | } |
9307 | | |
9308 | | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */ |
9309 | | |
9310 | | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
9311 | | |
9312 | | PyDoc_STRVAR(os_posix_fadvise__doc__, |
9313 | | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
9314 | | "--\n" |
9315 | | "\n" |
9316 | | "Announce an intention to access data in a specific pattern.\n" |
9317 | | "\n" |
9318 | | "Announce an intention to access data in a specific pattern, thus allowing\n" |
9319 | | "the kernel to make optimizations.\n" |
9320 | | "The advice applies to the region of the file specified by fd starting at\n" |
9321 | | "offset and continuing for length bytes.\n" |
9322 | | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
9323 | | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
9324 | | "POSIX_FADV_DONTNEED."); |
9325 | | |
9326 | | #define OS_POSIX_FADVISE_METHODDEF \ |
9327 | | {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__}, |
9328 | | |
9329 | | static PyObject * |
9330 | | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
9331 | | Py_off_t length, int advice); |
9332 | | |
9333 | | static PyObject * |
9334 | | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9335 | 0 | { |
9336 | 0 | PyObject *return_value = NULL; |
9337 | 0 | int fd; |
9338 | 0 | Py_off_t offset; |
9339 | 0 | Py_off_t length; |
9340 | 0 | int advice; |
9341 | |
|
9342 | 0 | if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { |
9343 | 0 | goto exit; |
9344 | 0 | } |
9345 | 0 | fd = PyLong_AsInt(args[0]); |
9346 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9347 | 0 | goto exit; |
9348 | 0 | } |
9349 | 0 | if (!Py_off_t_converter(args[1], &offset)) { |
9350 | 0 | goto exit; |
9351 | 0 | } |
9352 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
9353 | 0 | goto exit; |
9354 | 0 | } |
9355 | 0 | advice = PyLong_AsInt(args[3]); |
9356 | 0 | if (advice == -1 && PyErr_Occurred()) { |
9357 | 0 | goto exit; |
9358 | 0 | } |
9359 | 0 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
9360 | |
|
9361 | 0 | exit: |
9362 | 0 | return return_value; |
9363 | 0 | } |
9364 | | |
9365 | | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
9366 | | |
9367 | | #if defined(MS_WINDOWS) |
9368 | | |
9369 | | PyDoc_STRVAR(os_putenv__doc__, |
9370 | | "putenv($module, name, value, /)\n" |
9371 | | "--\n" |
9372 | | "\n" |
9373 | | "Change or add an environment variable."); |
9374 | | |
9375 | | #define OS_PUTENV_METHODDEF \ |
9376 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9377 | | |
9378 | | static PyObject * |
9379 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9380 | | |
9381 | | static PyObject * |
9382 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9383 | | { |
9384 | | PyObject *return_value = NULL; |
9385 | | PyObject *name; |
9386 | | PyObject *value; |
9387 | | |
9388 | | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9389 | | goto exit; |
9390 | | } |
9391 | | if (!PyUnicode_Check(args[0])) { |
9392 | | _PyArg_BadArgument("putenv", "argument 1", "str", args[0]); |
9393 | | goto exit; |
9394 | | } |
9395 | | name = args[0]; |
9396 | | if (!PyUnicode_Check(args[1])) { |
9397 | | _PyArg_BadArgument("putenv", "argument 2", "str", args[1]); |
9398 | | goto exit; |
9399 | | } |
9400 | | value = args[1]; |
9401 | | return_value = os_putenv_impl(module, name, value); |
9402 | | |
9403 | | exit: |
9404 | | return return_value; |
9405 | | } |
9406 | | |
9407 | | #endif /* defined(MS_WINDOWS) */ |
9408 | | |
9409 | | #if !defined(MS_WINDOWS) |
9410 | | |
9411 | | PyDoc_STRVAR(os_putenv__doc__, |
9412 | | "putenv($module, name, value, /)\n" |
9413 | | "--\n" |
9414 | | "\n" |
9415 | | "Change or add an environment variable."); |
9416 | | |
9417 | | #define OS_PUTENV_METHODDEF \ |
9418 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9419 | | |
9420 | | static PyObject * |
9421 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9422 | | |
9423 | | static PyObject * |
9424 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9425 | 0 | { |
9426 | 0 | PyObject *return_value = NULL; |
9427 | 0 | PyObject *name = NULL; |
9428 | 0 | PyObject *value = NULL; |
9429 | |
|
9430 | 0 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9431 | 0 | goto exit; |
9432 | 0 | } |
9433 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
9434 | 0 | goto exit; |
9435 | 0 | } |
9436 | 0 | if (!PyUnicode_FSConverter(args[1], &value)) { |
9437 | 0 | goto exit; |
9438 | 0 | } |
9439 | 0 | return_value = os_putenv_impl(module, name, value); |
9440 | |
|
9441 | 0 | exit: |
9442 | | /* Cleanup for name */ |
9443 | 0 | Py_XDECREF(name); |
9444 | | /* Cleanup for value */ |
9445 | 0 | Py_XDECREF(value); |
9446 | |
|
9447 | 0 | return return_value; |
9448 | 0 | } |
9449 | | |
9450 | | #endif /* !defined(MS_WINDOWS) */ |
9451 | | |
9452 | | #if defined(MS_WINDOWS) |
9453 | | |
9454 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9455 | | "unsetenv($module, name, /)\n" |
9456 | | "--\n" |
9457 | | "\n" |
9458 | | "Delete an environment variable."); |
9459 | | |
9460 | | #define OS_UNSETENV_METHODDEF \ |
9461 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9462 | | |
9463 | | static PyObject * |
9464 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9465 | | |
9466 | | static PyObject * |
9467 | | os_unsetenv(PyObject *module, PyObject *arg) |
9468 | | { |
9469 | | PyObject *return_value = NULL; |
9470 | | PyObject *name; |
9471 | | |
9472 | | if (!PyUnicode_Check(arg)) { |
9473 | | _PyArg_BadArgument("unsetenv", "argument", "str", arg); |
9474 | | goto exit; |
9475 | | } |
9476 | | name = arg; |
9477 | | return_value = os_unsetenv_impl(module, name); |
9478 | | |
9479 | | exit: |
9480 | | return return_value; |
9481 | | } |
9482 | | |
9483 | | #endif /* defined(MS_WINDOWS) */ |
9484 | | |
9485 | | #if !defined(MS_WINDOWS) |
9486 | | |
9487 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9488 | | "unsetenv($module, name, /)\n" |
9489 | | "--\n" |
9490 | | "\n" |
9491 | | "Delete an environment variable."); |
9492 | | |
9493 | | #define OS_UNSETENV_METHODDEF \ |
9494 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9495 | | |
9496 | | static PyObject * |
9497 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9498 | | |
9499 | | static PyObject * |
9500 | | os_unsetenv(PyObject *module, PyObject *arg) |
9501 | 0 | { |
9502 | 0 | PyObject *return_value = NULL; |
9503 | 0 | PyObject *name = NULL; |
9504 | |
|
9505 | 0 | if (!PyUnicode_FSConverter(arg, &name)) { |
9506 | 0 | goto exit; |
9507 | 0 | } |
9508 | 0 | return_value = os_unsetenv_impl(module, name); |
9509 | |
|
9510 | 0 | exit: |
9511 | | /* Cleanup for name */ |
9512 | 0 | Py_XDECREF(name); |
9513 | |
|
9514 | 0 | return return_value; |
9515 | 0 | } |
9516 | | |
9517 | | #endif /* !defined(MS_WINDOWS) */ |
9518 | | |
9519 | | PyDoc_STRVAR(os_strerror__doc__, |
9520 | | "strerror($module, code, /)\n" |
9521 | | "--\n" |
9522 | | "\n" |
9523 | | "Translate an error code to a message string."); |
9524 | | |
9525 | | #define OS_STRERROR_METHODDEF \ |
9526 | | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
9527 | | |
9528 | | static PyObject * |
9529 | | os_strerror_impl(PyObject *module, int code); |
9530 | | |
9531 | | static PyObject * |
9532 | | os_strerror(PyObject *module, PyObject *arg) |
9533 | 0 | { |
9534 | 0 | PyObject *return_value = NULL; |
9535 | 0 | int code; |
9536 | |
|
9537 | 0 | code = PyLong_AsInt(arg); |
9538 | 0 | if (code == -1 && PyErr_Occurred()) { |
9539 | 0 | goto exit; |
9540 | 0 | } |
9541 | 0 | return_value = os_strerror_impl(module, code); |
9542 | |
|
9543 | 0 | exit: |
9544 | 0 | return return_value; |
9545 | 0 | } |
9546 | | |
9547 | | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
9548 | | |
9549 | | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
9550 | | "WCOREDUMP($module, status, /)\n" |
9551 | | "--\n" |
9552 | | "\n" |
9553 | | "Return True if the process returning status was dumped to a core file."); |
9554 | | |
9555 | | #define OS_WCOREDUMP_METHODDEF \ |
9556 | | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
9557 | | |
9558 | | static int |
9559 | | os_WCOREDUMP_impl(PyObject *module, int status); |
9560 | | |
9561 | | static PyObject * |
9562 | | os_WCOREDUMP(PyObject *module, PyObject *arg) |
9563 | 0 | { |
9564 | 0 | PyObject *return_value = NULL; |
9565 | 0 | int status; |
9566 | 0 | int _return_value; |
9567 | |
|
9568 | 0 | status = PyLong_AsInt(arg); |
9569 | 0 | if (status == -1 && PyErr_Occurred()) { |
9570 | 0 | goto exit; |
9571 | 0 | } |
9572 | 0 | _return_value = os_WCOREDUMP_impl(module, status); |
9573 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9574 | 0 | goto exit; |
9575 | 0 | } |
9576 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9577 | |
|
9578 | 0 | exit: |
9579 | 0 | return return_value; |
9580 | 0 | } |
9581 | | |
9582 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
9583 | | |
9584 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
9585 | | |
9586 | | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
9587 | | "WIFCONTINUED($module, /, status)\n" |
9588 | | "--\n" |
9589 | | "\n" |
9590 | | "Return True if a particular process was continued from a job control stop.\n" |
9591 | | "\n" |
9592 | | "Return True if the process returning status was continued from a\n" |
9593 | | "job control stop."); |
9594 | | |
9595 | | #define OS_WIFCONTINUED_METHODDEF \ |
9596 | | {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__}, |
9597 | | |
9598 | | static int |
9599 | | os_WIFCONTINUED_impl(PyObject *module, int status); |
9600 | | |
9601 | | static PyObject * |
9602 | | os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9603 | 0 | { |
9604 | 0 | PyObject *return_value = NULL; |
9605 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9606 | |
|
9607 | 0 | #define NUM_KEYWORDS 1 |
9608 | 0 | static struct { |
9609 | 0 | PyGC_Head _this_is_not_used; |
9610 | 0 | PyObject_VAR_HEAD |
9611 | 0 | Py_hash_t ob_hash; |
9612 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9613 | 0 | } _kwtuple = { |
9614 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9615 | 0 | .ob_hash = -1, |
9616 | 0 | .ob_item = { &_Py_ID(status), }, |
9617 | 0 | }; |
9618 | 0 | #undef NUM_KEYWORDS |
9619 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9620 | |
|
9621 | | #else // !Py_BUILD_CORE |
9622 | | # define KWTUPLE NULL |
9623 | | #endif // !Py_BUILD_CORE |
9624 | |
|
9625 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9626 | 0 | static _PyArg_Parser _parser = { |
9627 | 0 | .keywords = _keywords, |
9628 | 0 | .fname = "WIFCONTINUED", |
9629 | 0 | .kwtuple = KWTUPLE, |
9630 | 0 | }; |
9631 | 0 | #undef KWTUPLE |
9632 | 0 | PyObject *argsbuf[1]; |
9633 | 0 | int status; |
9634 | 0 | int _return_value; |
9635 | |
|
9636 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9637 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9638 | 0 | if (!args) { |
9639 | 0 | goto exit; |
9640 | 0 | } |
9641 | 0 | status = PyLong_AsInt(args[0]); |
9642 | 0 | if (status == -1 && PyErr_Occurred()) { |
9643 | 0 | goto exit; |
9644 | 0 | } |
9645 | 0 | _return_value = os_WIFCONTINUED_impl(module, status); |
9646 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9647 | 0 | goto exit; |
9648 | 0 | } |
9649 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9650 | |
|
9651 | 0 | exit: |
9652 | 0 | return return_value; |
9653 | 0 | } |
9654 | | |
9655 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
9656 | | |
9657 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
9658 | | |
9659 | | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
9660 | | "WIFSTOPPED($module, /, status)\n" |
9661 | | "--\n" |
9662 | | "\n" |
9663 | | "Return True if the process returning status was stopped."); |
9664 | | |
9665 | | #define OS_WIFSTOPPED_METHODDEF \ |
9666 | | {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__}, |
9667 | | |
9668 | | static int |
9669 | | os_WIFSTOPPED_impl(PyObject *module, int status); |
9670 | | |
9671 | | static PyObject * |
9672 | | os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9673 | 0 | { |
9674 | 0 | PyObject *return_value = NULL; |
9675 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9676 | |
|
9677 | 0 | #define NUM_KEYWORDS 1 |
9678 | 0 | static struct { |
9679 | 0 | PyGC_Head _this_is_not_used; |
9680 | 0 | PyObject_VAR_HEAD |
9681 | 0 | Py_hash_t ob_hash; |
9682 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9683 | 0 | } _kwtuple = { |
9684 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9685 | 0 | .ob_hash = -1, |
9686 | 0 | .ob_item = { &_Py_ID(status), }, |
9687 | 0 | }; |
9688 | 0 | #undef NUM_KEYWORDS |
9689 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9690 | |
|
9691 | | #else // !Py_BUILD_CORE |
9692 | | # define KWTUPLE NULL |
9693 | | #endif // !Py_BUILD_CORE |
9694 | |
|
9695 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9696 | 0 | static _PyArg_Parser _parser = { |
9697 | 0 | .keywords = _keywords, |
9698 | 0 | .fname = "WIFSTOPPED", |
9699 | 0 | .kwtuple = KWTUPLE, |
9700 | 0 | }; |
9701 | 0 | #undef KWTUPLE |
9702 | 0 | PyObject *argsbuf[1]; |
9703 | 0 | int status; |
9704 | 0 | int _return_value; |
9705 | |
|
9706 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9707 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9708 | 0 | if (!args) { |
9709 | 0 | goto exit; |
9710 | 0 | } |
9711 | 0 | status = PyLong_AsInt(args[0]); |
9712 | 0 | if (status == -1 && PyErr_Occurred()) { |
9713 | 0 | goto exit; |
9714 | 0 | } |
9715 | 0 | _return_value = os_WIFSTOPPED_impl(module, status); |
9716 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9717 | 0 | goto exit; |
9718 | 0 | } |
9719 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9720 | |
|
9721 | 0 | exit: |
9722 | 0 | return return_value; |
9723 | 0 | } |
9724 | | |
9725 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
9726 | | |
9727 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
9728 | | |
9729 | | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
9730 | | "WIFSIGNALED($module, /, status)\n" |
9731 | | "--\n" |
9732 | | "\n" |
9733 | | "Return True if the process returning status was terminated by a signal."); |
9734 | | |
9735 | | #define OS_WIFSIGNALED_METHODDEF \ |
9736 | | {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__}, |
9737 | | |
9738 | | static int |
9739 | | os_WIFSIGNALED_impl(PyObject *module, int status); |
9740 | | |
9741 | | static PyObject * |
9742 | | os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9743 | 0 | { |
9744 | 0 | PyObject *return_value = NULL; |
9745 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9746 | |
|
9747 | 0 | #define NUM_KEYWORDS 1 |
9748 | 0 | static struct { |
9749 | 0 | PyGC_Head _this_is_not_used; |
9750 | 0 | PyObject_VAR_HEAD |
9751 | 0 | Py_hash_t ob_hash; |
9752 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9753 | 0 | } _kwtuple = { |
9754 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9755 | 0 | .ob_hash = -1, |
9756 | 0 | .ob_item = { &_Py_ID(status), }, |
9757 | 0 | }; |
9758 | 0 | #undef NUM_KEYWORDS |
9759 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9760 | |
|
9761 | | #else // !Py_BUILD_CORE |
9762 | | # define KWTUPLE NULL |
9763 | | #endif // !Py_BUILD_CORE |
9764 | |
|
9765 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9766 | 0 | static _PyArg_Parser _parser = { |
9767 | 0 | .keywords = _keywords, |
9768 | 0 | .fname = "WIFSIGNALED", |
9769 | 0 | .kwtuple = KWTUPLE, |
9770 | 0 | }; |
9771 | 0 | #undef KWTUPLE |
9772 | 0 | PyObject *argsbuf[1]; |
9773 | 0 | int status; |
9774 | 0 | int _return_value; |
9775 | |
|
9776 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9777 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9778 | 0 | if (!args) { |
9779 | 0 | goto exit; |
9780 | 0 | } |
9781 | 0 | status = PyLong_AsInt(args[0]); |
9782 | 0 | if (status == -1 && PyErr_Occurred()) { |
9783 | 0 | goto exit; |
9784 | 0 | } |
9785 | 0 | _return_value = os_WIFSIGNALED_impl(module, status); |
9786 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9787 | 0 | goto exit; |
9788 | 0 | } |
9789 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9790 | |
|
9791 | 0 | exit: |
9792 | 0 | return return_value; |
9793 | 0 | } |
9794 | | |
9795 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
9796 | | |
9797 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
9798 | | |
9799 | | PyDoc_STRVAR(os_WIFEXITED__doc__, |
9800 | | "WIFEXITED($module, /, status)\n" |
9801 | | "--\n" |
9802 | | "\n" |
9803 | | "Return True if the process returning status exited via the exit() system call."); |
9804 | | |
9805 | | #define OS_WIFEXITED_METHODDEF \ |
9806 | | {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__}, |
9807 | | |
9808 | | static int |
9809 | | os_WIFEXITED_impl(PyObject *module, int status); |
9810 | | |
9811 | | static PyObject * |
9812 | | os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9813 | 0 | { |
9814 | 0 | PyObject *return_value = NULL; |
9815 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9816 | |
|
9817 | 0 | #define NUM_KEYWORDS 1 |
9818 | 0 | static struct { |
9819 | 0 | PyGC_Head _this_is_not_used; |
9820 | 0 | PyObject_VAR_HEAD |
9821 | 0 | Py_hash_t ob_hash; |
9822 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9823 | 0 | } _kwtuple = { |
9824 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9825 | 0 | .ob_hash = -1, |
9826 | 0 | .ob_item = { &_Py_ID(status), }, |
9827 | 0 | }; |
9828 | 0 | #undef NUM_KEYWORDS |
9829 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9830 | |
|
9831 | | #else // !Py_BUILD_CORE |
9832 | | # define KWTUPLE NULL |
9833 | | #endif // !Py_BUILD_CORE |
9834 | |
|
9835 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9836 | 0 | static _PyArg_Parser _parser = { |
9837 | 0 | .keywords = _keywords, |
9838 | 0 | .fname = "WIFEXITED", |
9839 | 0 | .kwtuple = KWTUPLE, |
9840 | 0 | }; |
9841 | 0 | #undef KWTUPLE |
9842 | 0 | PyObject *argsbuf[1]; |
9843 | 0 | int status; |
9844 | 0 | int _return_value; |
9845 | |
|
9846 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9847 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9848 | 0 | if (!args) { |
9849 | 0 | goto exit; |
9850 | 0 | } |
9851 | 0 | status = PyLong_AsInt(args[0]); |
9852 | 0 | if (status == -1 && PyErr_Occurred()) { |
9853 | 0 | goto exit; |
9854 | 0 | } |
9855 | 0 | _return_value = os_WIFEXITED_impl(module, status); |
9856 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9857 | 0 | goto exit; |
9858 | 0 | } |
9859 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9860 | |
|
9861 | 0 | exit: |
9862 | 0 | return return_value; |
9863 | 0 | } |
9864 | | |
9865 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
9866 | | |
9867 | | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
9868 | | |
9869 | | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
9870 | | "WEXITSTATUS($module, /, status)\n" |
9871 | | "--\n" |
9872 | | "\n" |
9873 | | "Return the process return code from status."); |
9874 | | |
9875 | | #define OS_WEXITSTATUS_METHODDEF \ |
9876 | | {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__}, |
9877 | | |
9878 | | static int |
9879 | | os_WEXITSTATUS_impl(PyObject *module, int status); |
9880 | | |
9881 | | static PyObject * |
9882 | | os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9883 | 0 | { |
9884 | 0 | PyObject *return_value = NULL; |
9885 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9886 | |
|
9887 | 0 | #define NUM_KEYWORDS 1 |
9888 | 0 | static struct { |
9889 | 0 | PyGC_Head _this_is_not_used; |
9890 | 0 | PyObject_VAR_HEAD |
9891 | 0 | Py_hash_t ob_hash; |
9892 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9893 | 0 | } _kwtuple = { |
9894 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9895 | 0 | .ob_hash = -1, |
9896 | 0 | .ob_item = { &_Py_ID(status), }, |
9897 | 0 | }; |
9898 | 0 | #undef NUM_KEYWORDS |
9899 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9900 | |
|
9901 | | #else // !Py_BUILD_CORE |
9902 | | # define KWTUPLE NULL |
9903 | | #endif // !Py_BUILD_CORE |
9904 | |
|
9905 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9906 | 0 | static _PyArg_Parser _parser = { |
9907 | 0 | .keywords = _keywords, |
9908 | 0 | .fname = "WEXITSTATUS", |
9909 | 0 | .kwtuple = KWTUPLE, |
9910 | 0 | }; |
9911 | 0 | #undef KWTUPLE |
9912 | 0 | PyObject *argsbuf[1]; |
9913 | 0 | int status; |
9914 | 0 | int _return_value; |
9915 | |
|
9916 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9917 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9918 | 0 | if (!args) { |
9919 | 0 | goto exit; |
9920 | 0 | } |
9921 | 0 | status = PyLong_AsInt(args[0]); |
9922 | 0 | if (status == -1 && PyErr_Occurred()) { |
9923 | 0 | goto exit; |
9924 | 0 | } |
9925 | 0 | _return_value = os_WEXITSTATUS_impl(module, status); |
9926 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9927 | 0 | goto exit; |
9928 | 0 | } |
9929 | 0 | return_value = PyLong_FromLong((long)_return_value); |
9930 | |
|
9931 | 0 | exit: |
9932 | 0 | return return_value; |
9933 | 0 | } |
9934 | | |
9935 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
9936 | | |
9937 | | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
9938 | | |
9939 | | PyDoc_STRVAR(os_WTERMSIG__doc__, |
9940 | | "WTERMSIG($module, /, status)\n" |
9941 | | "--\n" |
9942 | | "\n" |
9943 | | "Return the signal that terminated the process that provided the status value."); |
9944 | | |
9945 | | #define OS_WTERMSIG_METHODDEF \ |
9946 | | {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__}, |
9947 | | |
9948 | | static int |
9949 | | os_WTERMSIG_impl(PyObject *module, int status); |
9950 | | |
9951 | | static PyObject * |
9952 | | os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9953 | 0 | { |
9954 | 0 | PyObject *return_value = NULL; |
9955 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9956 | |
|
9957 | 0 | #define NUM_KEYWORDS 1 |
9958 | 0 | static struct { |
9959 | 0 | PyGC_Head _this_is_not_used; |
9960 | 0 | PyObject_VAR_HEAD |
9961 | 0 | Py_hash_t ob_hash; |
9962 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9963 | 0 | } _kwtuple = { |
9964 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9965 | 0 | .ob_hash = -1, |
9966 | 0 | .ob_item = { &_Py_ID(status), }, |
9967 | 0 | }; |
9968 | 0 | #undef NUM_KEYWORDS |
9969 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9970 | |
|
9971 | | #else // !Py_BUILD_CORE |
9972 | | # define KWTUPLE NULL |
9973 | | #endif // !Py_BUILD_CORE |
9974 | |
|
9975 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9976 | 0 | static _PyArg_Parser _parser = { |
9977 | 0 | .keywords = _keywords, |
9978 | 0 | .fname = "WTERMSIG", |
9979 | 0 | .kwtuple = KWTUPLE, |
9980 | 0 | }; |
9981 | 0 | #undef KWTUPLE |
9982 | 0 | PyObject *argsbuf[1]; |
9983 | 0 | int status; |
9984 | 0 | int _return_value; |
9985 | |
|
9986 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9987 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9988 | 0 | if (!args) { |
9989 | 0 | goto exit; |
9990 | 0 | } |
9991 | 0 | status = PyLong_AsInt(args[0]); |
9992 | 0 | if (status == -1 && PyErr_Occurred()) { |
9993 | 0 | goto exit; |
9994 | 0 | } |
9995 | 0 | _return_value = os_WTERMSIG_impl(module, status); |
9996 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9997 | 0 | goto exit; |
9998 | 0 | } |
9999 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10000 | |
|
10001 | 0 | exit: |
10002 | 0 | return return_value; |
10003 | 0 | } |
10004 | | |
10005 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
10006 | | |
10007 | | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
10008 | | |
10009 | | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
10010 | | "WSTOPSIG($module, /, status)\n" |
10011 | | "--\n" |
10012 | | "\n" |
10013 | | "Return the signal that stopped the process that provided the status value."); |
10014 | | |
10015 | | #define OS_WSTOPSIG_METHODDEF \ |
10016 | | {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__}, |
10017 | | |
10018 | | static int |
10019 | | os_WSTOPSIG_impl(PyObject *module, int status); |
10020 | | |
10021 | | static PyObject * |
10022 | | os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10023 | 0 | { |
10024 | 0 | PyObject *return_value = NULL; |
10025 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10026 | |
|
10027 | 0 | #define NUM_KEYWORDS 1 |
10028 | 0 | static struct { |
10029 | 0 | PyGC_Head _this_is_not_used; |
10030 | 0 | PyObject_VAR_HEAD |
10031 | 0 | Py_hash_t ob_hash; |
10032 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10033 | 0 | } _kwtuple = { |
10034 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10035 | 0 | .ob_hash = -1, |
10036 | 0 | .ob_item = { &_Py_ID(status), }, |
10037 | 0 | }; |
10038 | 0 | #undef NUM_KEYWORDS |
10039 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10040 | |
|
10041 | | #else // !Py_BUILD_CORE |
10042 | | # define KWTUPLE NULL |
10043 | | #endif // !Py_BUILD_CORE |
10044 | |
|
10045 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10046 | 0 | static _PyArg_Parser _parser = { |
10047 | 0 | .keywords = _keywords, |
10048 | 0 | .fname = "WSTOPSIG", |
10049 | 0 | .kwtuple = KWTUPLE, |
10050 | 0 | }; |
10051 | 0 | #undef KWTUPLE |
10052 | 0 | PyObject *argsbuf[1]; |
10053 | 0 | int status; |
10054 | 0 | int _return_value; |
10055 | |
|
10056 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10057 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10058 | 0 | if (!args) { |
10059 | 0 | goto exit; |
10060 | 0 | } |
10061 | 0 | status = PyLong_AsInt(args[0]); |
10062 | 0 | if (status == -1 && PyErr_Occurred()) { |
10063 | 0 | goto exit; |
10064 | 0 | } |
10065 | 0 | _return_value = os_WSTOPSIG_impl(module, status); |
10066 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10067 | 0 | goto exit; |
10068 | 0 | } |
10069 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10070 | |
|
10071 | 0 | exit: |
10072 | 0 | return return_value; |
10073 | 0 | } |
10074 | | |
10075 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
10076 | | |
10077 | | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10078 | | |
10079 | | PyDoc_STRVAR(os_fstatvfs__doc__, |
10080 | | "fstatvfs($module, fd, /)\n" |
10081 | | "--\n" |
10082 | | "\n" |
10083 | | "Perform an fstatvfs system call on the given fd.\n" |
10084 | | "\n" |
10085 | | "Equivalent to statvfs(fd)."); |
10086 | | |
10087 | | #define OS_FSTATVFS_METHODDEF \ |
10088 | | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
10089 | | |
10090 | | static PyObject * |
10091 | | os_fstatvfs_impl(PyObject *module, int fd); |
10092 | | |
10093 | | static PyObject * |
10094 | | os_fstatvfs(PyObject *module, PyObject *arg) |
10095 | 0 | { |
10096 | 0 | PyObject *return_value = NULL; |
10097 | 0 | int fd; |
10098 | |
|
10099 | 0 | fd = PyLong_AsInt(arg); |
10100 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10101 | 0 | goto exit; |
10102 | 0 | } |
10103 | 0 | return_value = os_fstatvfs_impl(module, fd); |
10104 | |
|
10105 | 0 | exit: |
10106 | 0 | return return_value; |
10107 | 0 | } |
10108 | | |
10109 | | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10110 | | |
10111 | | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10112 | | |
10113 | | PyDoc_STRVAR(os_statvfs__doc__, |
10114 | | "statvfs($module, /, path)\n" |
10115 | | "--\n" |
10116 | | "\n" |
10117 | | "Perform a statvfs system call on the given path.\n" |
10118 | | "\n" |
10119 | | "path may always be specified as a string.\n" |
10120 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
10121 | | " If this functionality is unavailable, using it raises an exception."); |
10122 | | |
10123 | | #define OS_STATVFS_METHODDEF \ |
10124 | | {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__}, |
10125 | | |
10126 | | static PyObject * |
10127 | | os_statvfs_impl(PyObject *module, path_t *path); |
10128 | | |
10129 | | static PyObject * |
10130 | | os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10131 | 0 | { |
10132 | 0 | PyObject *return_value = NULL; |
10133 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10134 | |
|
10135 | 0 | #define NUM_KEYWORDS 1 |
10136 | 0 | static struct { |
10137 | 0 | PyGC_Head _this_is_not_used; |
10138 | 0 | PyObject_VAR_HEAD |
10139 | 0 | Py_hash_t ob_hash; |
10140 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10141 | 0 | } _kwtuple = { |
10142 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10143 | 0 | .ob_hash = -1, |
10144 | 0 | .ob_item = { &_Py_ID(path), }, |
10145 | 0 | }; |
10146 | 0 | #undef NUM_KEYWORDS |
10147 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10148 | |
|
10149 | | #else // !Py_BUILD_CORE |
10150 | | # define KWTUPLE NULL |
10151 | | #endif // !Py_BUILD_CORE |
10152 | |
|
10153 | 0 | static const char * const _keywords[] = {"path", NULL}; |
10154 | 0 | static _PyArg_Parser _parser = { |
10155 | 0 | .keywords = _keywords, |
10156 | 0 | .fname = "statvfs", |
10157 | 0 | .kwtuple = KWTUPLE, |
10158 | 0 | }; |
10159 | 0 | #undef KWTUPLE |
10160 | 0 | PyObject *argsbuf[1]; |
10161 | 0 | path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS); |
10162 | |
|
10163 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10164 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10165 | 0 | if (!args) { |
10166 | 0 | goto exit; |
10167 | 0 | } |
10168 | 0 | if (!path_converter(args[0], &path)) { |
10169 | 0 | goto exit; |
10170 | 0 | } |
10171 | 0 | return_value = os_statvfs_impl(module, &path); |
10172 | |
|
10173 | 0 | exit: |
10174 | | /* Cleanup for path */ |
10175 | 0 | path_cleanup(&path); |
10176 | |
|
10177 | 0 | return return_value; |
10178 | 0 | } |
10179 | | |
10180 | | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10181 | | |
10182 | | #if defined(MS_WINDOWS) |
10183 | | |
10184 | | PyDoc_STRVAR(os__getdiskusage__doc__, |
10185 | | "_getdiskusage($module, /, path)\n" |
10186 | | "--\n" |
10187 | | "\n" |
10188 | | "Return disk usage statistics about the given path as a (total, free) tuple."); |
10189 | | |
10190 | | #define OS__GETDISKUSAGE_METHODDEF \ |
10191 | | {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__}, |
10192 | | |
10193 | | static PyObject * |
10194 | | os__getdiskusage_impl(PyObject *module, path_t *path); |
10195 | | |
10196 | | static PyObject * |
10197 | | os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10198 | | { |
10199 | | PyObject *return_value = NULL; |
10200 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10201 | | |
10202 | | #define NUM_KEYWORDS 1 |
10203 | | static struct { |
10204 | | PyGC_Head _this_is_not_used; |
10205 | | PyObject_VAR_HEAD |
10206 | | Py_hash_t ob_hash; |
10207 | | PyObject *ob_item[NUM_KEYWORDS]; |
10208 | | } _kwtuple = { |
10209 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10210 | | .ob_hash = -1, |
10211 | | .ob_item = { &_Py_ID(path), }, |
10212 | | }; |
10213 | | #undef NUM_KEYWORDS |
10214 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10215 | | |
10216 | | #else // !Py_BUILD_CORE |
10217 | | # define KWTUPLE NULL |
10218 | | #endif // !Py_BUILD_CORE |
10219 | | |
10220 | | static const char * const _keywords[] = {"path", NULL}; |
10221 | | static _PyArg_Parser _parser = { |
10222 | | .keywords = _keywords, |
10223 | | .fname = "_getdiskusage", |
10224 | | .kwtuple = KWTUPLE, |
10225 | | }; |
10226 | | #undef KWTUPLE |
10227 | | PyObject *argsbuf[1]; |
10228 | | path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0); |
10229 | | |
10230 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10231 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10232 | | if (!args) { |
10233 | | goto exit; |
10234 | | } |
10235 | | if (!path_converter(args[0], &path)) { |
10236 | | goto exit; |
10237 | | } |
10238 | | return_value = os__getdiskusage_impl(module, &path); |
10239 | | |
10240 | | exit: |
10241 | | /* Cleanup for path */ |
10242 | | path_cleanup(&path); |
10243 | | |
10244 | | return return_value; |
10245 | | } |
10246 | | |
10247 | | #endif /* defined(MS_WINDOWS) */ |
10248 | | |
10249 | | #if defined(HAVE_FPATHCONF) |
10250 | | |
10251 | | PyDoc_STRVAR(os_fpathconf__doc__, |
10252 | | "fpathconf($module, fd, name, /)\n" |
10253 | | "--\n" |
10254 | | "\n" |
10255 | | "Return the configuration limit name for the file descriptor fd.\n" |
10256 | | "\n" |
10257 | | "If there is no limit, return -1."); |
10258 | | |
10259 | | #define OS_FPATHCONF_METHODDEF \ |
10260 | | {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__}, |
10261 | | |
10262 | | static long |
10263 | | os_fpathconf_impl(PyObject *module, int fd, int name); |
10264 | | |
10265 | | static PyObject * |
10266 | | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10267 | 0 | { |
10268 | 0 | PyObject *return_value = NULL; |
10269 | 0 | int fd; |
10270 | 0 | int name; |
10271 | 0 | long _return_value; |
10272 | |
|
10273 | 0 | if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { |
10274 | 0 | goto exit; |
10275 | 0 | } |
10276 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
10277 | 0 | if (fd < 0) { |
10278 | 0 | goto exit; |
10279 | 0 | } |
10280 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10281 | 0 | goto exit; |
10282 | 0 | } |
10283 | 0 | _return_value = os_fpathconf_impl(module, fd, name); |
10284 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10285 | 0 | goto exit; |
10286 | 0 | } |
10287 | 0 | return_value = PyLong_FromLong(_return_value); |
10288 | |
|
10289 | 0 | exit: |
10290 | 0 | return return_value; |
10291 | 0 | } |
10292 | | |
10293 | | #endif /* defined(HAVE_FPATHCONF) */ |
10294 | | |
10295 | | #if defined(HAVE_PATHCONF) |
10296 | | |
10297 | | PyDoc_STRVAR(os_pathconf__doc__, |
10298 | | "pathconf($module, /, path, name)\n" |
10299 | | "--\n" |
10300 | | "\n" |
10301 | | "Return the configuration limit name for the file or directory path.\n" |
10302 | | "\n" |
10303 | | "If there is no limit, return -1.\n" |
10304 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
10305 | | " If this functionality is unavailable, using it raises an exception."); |
10306 | | |
10307 | | #define OS_PATHCONF_METHODDEF \ |
10308 | | {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__}, |
10309 | | |
10310 | | static long |
10311 | | os_pathconf_impl(PyObject *module, path_t *path, int name); |
10312 | | |
10313 | | static PyObject * |
10314 | | os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10315 | 0 | { |
10316 | 0 | PyObject *return_value = NULL; |
10317 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10318 | |
|
10319 | 0 | #define NUM_KEYWORDS 2 |
10320 | 0 | static struct { |
10321 | 0 | PyGC_Head _this_is_not_used; |
10322 | 0 | PyObject_VAR_HEAD |
10323 | 0 | Py_hash_t ob_hash; |
10324 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10325 | 0 | } _kwtuple = { |
10326 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10327 | 0 | .ob_hash = -1, |
10328 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(name), }, |
10329 | 0 | }; |
10330 | 0 | #undef NUM_KEYWORDS |
10331 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10332 | |
|
10333 | | #else // !Py_BUILD_CORE |
10334 | | # define KWTUPLE NULL |
10335 | | #endif // !Py_BUILD_CORE |
10336 | |
|
10337 | 0 | static const char * const _keywords[] = {"path", "name", NULL}; |
10338 | 0 | static _PyArg_Parser _parser = { |
10339 | 0 | .keywords = _keywords, |
10340 | 0 | .fname = "pathconf", |
10341 | 0 | .kwtuple = KWTUPLE, |
10342 | 0 | }; |
10343 | 0 | #undef KWTUPLE |
10344 | 0 | PyObject *argsbuf[2]; |
10345 | 0 | path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF); |
10346 | 0 | int name; |
10347 | 0 | long _return_value; |
10348 | |
|
10349 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10350 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10351 | 0 | if (!args) { |
10352 | 0 | goto exit; |
10353 | 0 | } |
10354 | 0 | if (!path_converter(args[0], &path)) { |
10355 | 0 | goto exit; |
10356 | 0 | } |
10357 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10358 | 0 | goto exit; |
10359 | 0 | } |
10360 | 0 | _return_value = os_pathconf_impl(module, &path, name); |
10361 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10362 | 0 | goto exit; |
10363 | 0 | } |
10364 | 0 | return_value = PyLong_FromLong(_return_value); |
10365 | |
|
10366 | 0 | exit: |
10367 | | /* Cleanup for path */ |
10368 | 0 | path_cleanup(&path); |
10369 | |
|
10370 | 0 | return return_value; |
10371 | 0 | } |
10372 | | |
10373 | | #endif /* defined(HAVE_PATHCONF) */ |
10374 | | |
10375 | | #if defined(HAVE_CONFSTR) |
10376 | | |
10377 | | PyDoc_STRVAR(os_confstr__doc__, |
10378 | | "confstr($module, name, /)\n" |
10379 | | "--\n" |
10380 | | "\n" |
10381 | | "Return a string-valued system configuration variable."); |
10382 | | |
10383 | | #define OS_CONFSTR_METHODDEF \ |
10384 | | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
10385 | | |
10386 | | static PyObject * |
10387 | | os_confstr_impl(PyObject *module, int name); |
10388 | | |
10389 | | static PyObject * |
10390 | | os_confstr(PyObject *module, PyObject *arg) |
10391 | 0 | { |
10392 | 0 | PyObject *return_value = NULL; |
10393 | 0 | int name; |
10394 | |
|
10395 | 0 | if (!conv_confname(module, arg, &name, "confstr_names")) { |
10396 | 0 | goto exit; |
10397 | 0 | } |
10398 | 0 | return_value = os_confstr_impl(module, name); |
10399 | |
|
10400 | 0 | exit: |
10401 | 0 | return return_value; |
10402 | 0 | } |
10403 | | |
10404 | | #endif /* defined(HAVE_CONFSTR) */ |
10405 | | |
10406 | | #if defined(HAVE_SYSCONF) |
10407 | | |
10408 | | PyDoc_STRVAR(os_sysconf__doc__, |
10409 | | "sysconf($module, name, /)\n" |
10410 | | "--\n" |
10411 | | "\n" |
10412 | | "Return an integer-valued system configuration variable."); |
10413 | | |
10414 | | #define OS_SYSCONF_METHODDEF \ |
10415 | | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
10416 | | |
10417 | | static long |
10418 | | os_sysconf_impl(PyObject *module, int name); |
10419 | | |
10420 | | static PyObject * |
10421 | | os_sysconf(PyObject *module, PyObject *arg) |
10422 | 0 | { |
10423 | 0 | PyObject *return_value = NULL; |
10424 | 0 | int name; |
10425 | 0 | long _return_value; |
10426 | |
|
10427 | 0 | if (!conv_confname(module, arg, &name, "sysconf_names")) { |
10428 | 0 | goto exit; |
10429 | 0 | } |
10430 | 0 | _return_value = os_sysconf_impl(module, name); |
10431 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10432 | 0 | goto exit; |
10433 | 0 | } |
10434 | 0 | return_value = PyLong_FromLong(_return_value); |
10435 | |
|
10436 | 0 | exit: |
10437 | 0 | return return_value; |
10438 | 0 | } |
10439 | | |
10440 | | #endif /* defined(HAVE_SYSCONF) */ |
10441 | | |
10442 | | PyDoc_STRVAR(os_abort__doc__, |
10443 | | "abort($module, /)\n" |
10444 | | "--\n" |
10445 | | "\n" |
10446 | | "Abort the interpreter immediately.\n" |
10447 | | "\n" |
10448 | | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
10449 | | "on the hosting operating system. This function never returns."); |
10450 | | |
10451 | | #define OS_ABORT_METHODDEF \ |
10452 | | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
10453 | | |
10454 | | static PyObject * |
10455 | | os_abort_impl(PyObject *module); |
10456 | | |
10457 | | static PyObject * |
10458 | | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10459 | 0 | { |
10460 | 0 | return os_abort_impl(module); |
10461 | 0 | } |
10462 | | |
10463 | | #if defined(MS_WINDOWS) |
10464 | | |
10465 | | PyDoc_STRVAR(os_startfile__doc__, |
10466 | | "startfile($module, /, filepath, operation=<unrepresentable>,\n" |
10467 | | " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n" |
10468 | | "--\n" |
10469 | | "\n" |
10470 | | "Start a file with its associated application.\n" |
10471 | | "\n" |
10472 | | "When \"operation\" is not specified or \"open\", this acts like\n" |
10473 | | "double-clicking the file in Explorer, or giving the file name as an\n" |
10474 | | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
10475 | | "application (if any) its extension is associated.\n" |
10476 | | "When another \"operation\" is given, it specifies what should be done with\n" |
10477 | | "the file. A typical operation is \"print\".\n" |
10478 | | "\n" |
10479 | | "\"arguments\" is passed to the application, but should be omitted if the\n" |
10480 | | "file is a document.\n" |
10481 | | "\n" |
10482 | | "\"cwd\" is the working directory for the operation. If \"filepath\" is\n" |
10483 | | "relative, it will be resolved against this directory. This argument\n" |
10484 | | "should usually be an absolute path.\n" |
10485 | | "\n" |
10486 | | "\"show_cmd\" can be used to override the recommended visibility option.\n" |
10487 | | "See the Windows ShellExecute documentation for values.\n" |
10488 | | "\n" |
10489 | | "startfile returns as soon as the associated application is launched.\n" |
10490 | | "There is no option to wait for the application to close, and no way\n" |
10491 | | "to retrieve the application\'s exit status.\n" |
10492 | | "\n" |
10493 | | "The filepath is relative to the current directory. If you want to use\n" |
10494 | | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
10495 | | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
10496 | | |
10497 | | #define OS_STARTFILE_METHODDEF \ |
10498 | | {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__}, |
10499 | | |
10500 | | static PyObject * |
10501 | | os_startfile_impl(PyObject *module, path_t *filepath, |
10502 | | const wchar_t *operation, const wchar_t *arguments, |
10503 | | path_t *cwd, int show_cmd); |
10504 | | |
10505 | | static PyObject * |
10506 | | os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10507 | | { |
10508 | | PyObject *return_value = NULL; |
10509 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10510 | | |
10511 | | #define NUM_KEYWORDS 5 |
10512 | | static struct { |
10513 | | PyGC_Head _this_is_not_used; |
10514 | | PyObject_VAR_HEAD |
10515 | | Py_hash_t ob_hash; |
10516 | | PyObject *ob_item[NUM_KEYWORDS]; |
10517 | | } _kwtuple = { |
10518 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10519 | | .ob_hash = -1, |
10520 | | .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), }, |
10521 | | }; |
10522 | | #undef NUM_KEYWORDS |
10523 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10524 | | |
10525 | | #else // !Py_BUILD_CORE |
10526 | | # define KWTUPLE NULL |
10527 | | #endif // !Py_BUILD_CORE |
10528 | | |
10529 | | static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL}; |
10530 | | static _PyArg_Parser _parser = { |
10531 | | .keywords = _keywords, |
10532 | | .fname = "startfile", |
10533 | | .kwtuple = KWTUPLE, |
10534 | | }; |
10535 | | #undef KWTUPLE |
10536 | | PyObject *argsbuf[5]; |
10537 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
10538 | | path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0); |
10539 | | const wchar_t *operation = NULL; |
10540 | | const wchar_t *arguments = NULL; |
10541 | | path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0); |
10542 | | int show_cmd = 1; |
10543 | | |
10544 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10545 | | /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10546 | | if (!args) { |
10547 | | goto exit; |
10548 | | } |
10549 | | if (!path_converter(args[0], &filepath)) { |
10550 | | goto exit; |
10551 | | } |
10552 | | if (!noptargs) { |
10553 | | goto skip_optional_pos; |
10554 | | } |
10555 | | if (args[1]) { |
10556 | | if (!PyUnicode_Check(args[1])) { |
10557 | | _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]); |
10558 | | goto exit; |
10559 | | } |
10560 | | operation = PyUnicode_AsWideCharString(args[1], NULL); |
10561 | | if (operation == NULL) { |
10562 | | goto exit; |
10563 | | } |
10564 | | if (!--noptargs) { |
10565 | | goto skip_optional_pos; |
10566 | | } |
10567 | | } |
10568 | | if (args[2]) { |
10569 | | if (!PyUnicode_Check(args[2])) { |
10570 | | _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]); |
10571 | | goto exit; |
10572 | | } |
10573 | | arguments = PyUnicode_AsWideCharString(args[2], NULL); |
10574 | | if (arguments == NULL) { |
10575 | | goto exit; |
10576 | | } |
10577 | | if (!--noptargs) { |
10578 | | goto skip_optional_pos; |
10579 | | } |
10580 | | } |
10581 | | if (args[3]) { |
10582 | | if (!path_converter(args[3], &cwd)) { |
10583 | | goto exit; |
10584 | | } |
10585 | | if (!--noptargs) { |
10586 | | goto skip_optional_pos; |
10587 | | } |
10588 | | } |
10589 | | show_cmd = PyLong_AsInt(args[4]); |
10590 | | if (show_cmd == -1 && PyErr_Occurred()) { |
10591 | | goto exit; |
10592 | | } |
10593 | | skip_optional_pos: |
10594 | | return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd); |
10595 | | |
10596 | | exit: |
10597 | | /* Cleanup for filepath */ |
10598 | | path_cleanup(&filepath); |
10599 | | /* Cleanup for operation */ |
10600 | | PyMem_Free((void *)operation); |
10601 | | /* Cleanup for arguments */ |
10602 | | PyMem_Free((void *)arguments); |
10603 | | /* Cleanup for cwd */ |
10604 | | path_cleanup(&cwd); |
10605 | | |
10606 | | return return_value; |
10607 | | } |
10608 | | |
10609 | | #endif /* defined(MS_WINDOWS) */ |
10610 | | |
10611 | | #if defined(HAVE_GETLOADAVG) |
10612 | | |
10613 | | PyDoc_STRVAR(os_getloadavg__doc__, |
10614 | | "getloadavg($module, /)\n" |
10615 | | "--\n" |
10616 | | "\n" |
10617 | | "Return average recent system load information.\n" |
10618 | | "\n" |
10619 | | "Return the number of processes in the system run queue averaged over\n" |
10620 | | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
10621 | | "Raises OSError if the load average was unobtainable."); |
10622 | | |
10623 | | #define OS_GETLOADAVG_METHODDEF \ |
10624 | | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
10625 | | |
10626 | | static PyObject * |
10627 | | os_getloadavg_impl(PyObject *module); |
10628 | | |
10629 | | static PyObject * |
10630 | | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10631 | 0 | { |
10632 | 0 | return os_getloadavg_impl(module); |
10633 | 0 | } |
10634 | | |
10635 | | #endif /* defined(HAVE_GETLOADAVG) */ |
10636 | | |
10637 | | PyDoc_STRVAR(os_device_encoding__doc__, |
10638 | | "device_encoding($module, /, fd)\n" |
10639 | | "--\n" |
10640 | | "\n" |
10641 | | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
10642 | | "\n" |
10643 | | "The file descriptor must be attached to a terminal.\n" |
10644 | | "If the device is not a terminal, return None."); |
10645 | | |
10646 | | #define OS_DEVICE_ENCODING_METHODDEF \ |
10647 | | {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__}, |
10648 | | |
10649 | | static PyObject * |
10650 | | os_device_encoding_impl(PyObject *module, int fd); |
10651 | | |
10652 | | static PyObject * |
10653 | | os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10654 | 0 | { |
10655 | 0 | PyObject *return_value = NULL; |
10656 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10657 | |
|
10658 | 0 | #define NUM_KEYWORDS 1 |
10659 | 0 | static struct { |
10660 | 0 | PyGC_Head _this_is_not_used; |
10661 | 0 | PyObject_VAR_HEAD |
10662 | 0 | Py_hash_t ob_hash; |
10663 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10664 | 0 | } _kwtuple = { |
10665 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10666 | 0 | .ob_hash = -1, |
10667 | 0 | .ob_item = { &_Py_ID(fd), }, |
10668 | 0 | }; |
10669 | 0 | #undef NUM_KEYWORDS |
10670 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10671 | |
|
10672 | | #else // !Py_BUILD_CORE |
10673 | | # define KWTUPLE NULL |
10674 | | #endif // !Py_BUILD_CORE |
10675 | |
|
10676 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
10677 | 0 | static _PyArg_Parser _parser = { |
10678 | 0 | .keywords = _keywords, |
10679 | 0 | .fname = "device_encoding", |
10680 | 0 | .kwtuple = KWTUPLE, |
10681 | 0 | }; |
10682 | 0 | #undef KWTUPLE |
10683 | 0 | PyObject *argsbuf[1]; |
10684 | 0 | int fd; |
10685 | |
|
10686 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10687 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10688 | 0 | if (!args) { |
10689 | 0 | goto exit; |
10690 | 0 | } |
10691 | 0 | fd = PyLong_AsInt(args[0]); |
10692 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10693 | 0 | goto exit; |
10694 | 0 | } |
10695 | 0 | return_value = os_device_encoding_impl(module, fd); |
10696 | |
|
10697 | 0 | exit: |
10698 | 0 | return return_value; |
10699 | 0 | } |
10700 | | |
10701 | | #if defined(HAVE_SETRESUID) |
10702 | | |
10703 | | PyDoc_STRVAR(os_setresuid__doc__, |
10704 | | "setresuid($module, ruid, euid, suid, /)\n" |
10705 | | "--\n" |
10706 | | "\n" |
10707 | | "Set the current process\'s real, effective, and saved user ids."); |
10708 | | |
10709 | | #define OS_SETRESUID_METHODDEF \ |
10710 | | {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__}, |
10711 | | |
10712 | | static PyObject * |
10713 | | os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid); |
10714 | | |
10715 | | static PyObject * |
10716 | | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10717 | 0 | { |
10718 | 0 | PyObject *return_value = NULL; |
10719 | 0 | uid_t ruid; |
10720 | 0 | uid_t euid; |
10721 | 0 | uid_t suid; |
10722 | |
|
10723 | 0 | if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { |
10724 | 0 | goto exit; |
10725 | 0 | } |
10726 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
10727 | 0 | goto exit; |
10728 | 0 | } |
10729 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
10730 | 0 | goto exit; |
10731 | 0 | } |
10732 | 0 | if (!_Py_Uid_Converter(args[2], &suid)) { |
10733 | 0 | goto exit; |
10734 | 0 | } |
10735 | 0 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
10736 | |
|
10737 | 0 | exit: |
10738 | 0 | return return_value; |
10739 | 0 | } |
10740 | | |
10741 | | #endif /* defined(HAVE_SETRESUID) */ |
10742 | | |
10743 | | #if defined(HAVE_SETRESGID) |
10744 | | |
10745 | | PyDoc_STRVAR(os_setresgid__doc__, |
10746 | | "setresgid($module, rgid, egid, sgid, /)\n" |
10747 | | "--\n" |
10748 | | "\n" |
10749 | | "Set the current process\'s real, effective, and saved group ids."); |
10750 | | |
10751 | | #define OS_SETRESGID_METHODDEF \ |
10752 | | {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__}, |
10753 | | |
10754 | | static PyObject * |
10755 | | os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid); |
10756 | | |
10757 | | static PyObject * |
10758 | | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10759 | 0 | { |
10760 | 0 | PyObject *return_value = NULL; |
10761 | 0 | gid_t rgid; |
10762 | 0 | gid_t egid; |
10763 | 0 | gid_t sgid; |
10764 | |
|
10765 | 0 | if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { |
10766 | 0 | goto exit; |
10767 | 0 | } |
10768 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
10769 | 0 | goto exit; |
10770 | 0 | } |
10771 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
10772 | 0 | goto exit; |
10773 | 0 | } |
10774 | 0 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
10775 | 0 | goto exit; |
10776 | 0 | } |
10777 | 0 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
10778 | |
|
10779 | 0 | exit: |
10780 | 0 | return return_value; |
10781 | 0 | } |
10782 | | |
10783 | | #endif /* defined(HAVE_SETRESGID) */ |
10784 | | |
10785 | | #if defined(HAVE_GETRESUID) |
10786 | | |
10787 | | PyDoc_STRVAR(os_getresuid__doc__, |
10788 | | "getresuid($module, /)\n" |
10789 | | "--\n" |
10790 | | "\n" |
10791 | | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
10792 | | |
10793 | | #define OS_GETRESUID_METHODDEF \ |
10794 | | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
10795 | | |
10796 | | static PyObject * |
10797 | | os_getresuid_impl(PyObject *module); |
10798 | | |
10799 | | static PyObject * |
10800 | | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10801 | 0 | { |
10802 | 0 | return os_getresuid_impl(module); |
10803 | 0 | } |
10804 | | |
10805 | | #endif /* defined(HAVE_GETRESUID) */ |
10806 | | |
10807 | | #if defined(HAVE_GETRESGID) |
10808 | | |
10809 | | PyDoc_STRVAR(os_getresgid__doc__, |
10810 | | "getresgid($module, /)\n" |
10811 | | "--\n" |
10812 | | "\n" |
10813 | | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
10814 | | |
10815 | | #define OS_GETRESGID_METHODDEF \ |
10816 | | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
10817 | | |
10818 | | static PyObject * |
10819 | | os_getresgid_impl(PyObject *module); |
10820 | | |
10821 | | static PyObject * |
10822 | | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10823 | 0 | { |
10824 | 0 | return os_getresgid_impl(module); |
10825 | 0 | } |
10826 | | |
10827 | | #endif /* defined(HAVE_GETRESGID) */ |
10828 | | |
10829 | | #if defined(USE_XATTRS) |
10830 | | |
10831 | | PyDoc_STRVAR(os_getxattr__doc__, |
10832 | | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
10833 | | "--\n" |
10834 | | "\n" |
10835 | | "Return the value of extended attribute attribute on path.\n" |
10836 | | "\n" |
10837 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
10838 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
10839 | | " link, getxattr will examine the symbolic link itself instead of the file\n" |
10840 | | " the link points to."); |
10841 | | |
10842 | | #define OS_GETXATTR_METHODDEF \ |
10843 | | {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__}, |
10844 | | |
10845 | | static PyObject * |
10846 | | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
10847 | | int follow_symlinks); |
10848 | | |
10849 | | static PyObject * |
10850 | | os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10851 | 0 | { |
10852 | 0 | PyObject *return_value = NULL; |
10853 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10854 | |
|
10855 | 0 | #define NUM_KEYWORDS 3 |
10856 | 0 | static struct { |
10857 | 0 | PyGC_Head _this_is_not_used; |
10858 | 0 | PyObject_VAR_HEAD |
10859 | 0 | Py_hash_t ob_hash; |
10860 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10861 | 0 | } _kwtuple = { |
10862 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10863 | 0 | .ob_hash = -1, |
10864 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
10865 | 0 | }; |
10866 | 0 | #undef NUM_KEYWORDS |
10867 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10868 | |
|
10869 | | #else // !Py_BUILD_CORE |
10870 | | # define KWTUPLE NULL |
10871 | | #endif // !Py_BUILD_CORE |
10872 | |
|
10873 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
10874 | 0 | static _PyArg_Parser _parser = { |
10875 | 0 | .keywords = _keywords, |
10876 | 0 | .fname = "getxattr", |
10877 | 0 | .kwtuple = KWTUPLE, |
10878 | 0 | }; |
10879 | 0 | #undef KWTUPLE |
10880 | 0 | PyObject *argsbuf[3]; |
10881 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
10882 | 0 | path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1); |
10883 | 0 | path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0); |
10884 | 0 | int follow_symlinks = 1; |
10885 | |
|
10886 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10887 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10888 | 0 | if (!args) { |
10889 | 0 | goto exit; |
10890 | 0 | } |
10891 | 0 | if (!path_converter(args[0], &path)) { |
10892 | 0 | goto exit; |
10893 | 0 | } |
10894 | 0 | if (!path_converter(args[1], &attribute)) { |
10895 | 0 | goto exit; |
10896 | 0 | } |
10897 | 0 | if (!noptargs) { |
10898 | 0 | goto skip_optional_kwonly; |
10899 | 0 | } |
10900 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
10901 | 0 | if (follow_symlinks < 0) { |
10902 | 0 | goto exit; |
10903 | 0 | } |
10904 | 0 | skip_optional_kwonly: |
10905 | 0 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
10906 | |
|
10907 | 0 | exit: |
10908 | | /* Cleanup for path */ |
10909 | 0 | path_cleanup(&path); |
10910 | | /* Cleanup for attribute */ |
10911 | 0 | path_cleanup(&attribute); |
10912 | |
|
10913 | 0 | return return_value; |
10914 | 0 | } |
10915 | | |
10916 | | #endif /* defined(USE_XATTRS) */ |
10917 | | |
10918 | | #if defined(USE_XATTRS) |
10919 | | |
10920 | | PyDoc_STRVAR(os_setxattr__doc__, |
10921 | | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
10922 | | " follow_symlinks=True)\n" |
10923 | | "--\n" |
10924 | | "\n" |
10925 | | "Set extended attribute attribute on path to value.\n" |
10926 | | "\n" |
10927 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
10928 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
10929 | | " link, setxattr will modify the symbolic link itself instead of the file\n" |
10930 | | " the link points to."); |
10931 | | |
10932 | | #define OS_SETXATTR_METHODDEF \ |
10933 | | {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__}, |
10934 | | |
10935 | | static PyObject * |
10936 | | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
10937 | | Py_buffer *value, int flags, int follow_symlinks); |
10938 | | |
10939 | | static PyObject * |
10940 | | os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10941 | 0 | { |
10942 | 0 | PyObject *return_value = NULL; |
10943 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10944 | |
|
10945 | 0 | #define NUM_KEYWORDS 5 |
10946 | 0 | static struct { |
10947 | 0 | PyGC_Head _this_is_not_used; |
10948 | 0 | PyObject_VAR_HEAD |
10949 | 0 | Py_hash_t ob_hash; |
10950 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10951 | 0 | } _kwtuple = { |
10952 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10953 | 0 | .ob_hash = -1, |
10954 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), }, |
10955 | 0 | }; |
10956 | 0 | #undef NUM_KEYWORDS |
10957 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10958 | |
|
10959 | | #else // !Py_BUILD_CORE |
10960 | | # define KWTUPLE NULL |
10961 | | #endif // !Py_BUILD_CORE |
10962 | |
|
10963 | 0 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
10964 | 0 | static _PyArg_Parser _parser = { |
10965 | 0 | .keywords = _keywords, |
10966 | 0 | .fname = "setxattr", |
10967 | 0 | .kwtuple = KWTUPLE, |
10968 | 0 | }; |
10969 | 0 | #undef KWTUPLE |
10970 | 0 | PyObject *argsbuf[5]; |
10971 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
10972 | 0 | path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1); |
10973 | 0 | path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0); |
10974 | 0 | Py_buffer value = {NULL, NULL}; |
10975 | 0 | int flags = 0; |
10976 | 0 | int follow_symlinks = 1; |
10977 | |
|
10978 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10979 | 0 | /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10980 | 0 | if (!args) { |
10981 | 0 | goto exit; |
10982 | 0 | } |
10983 | 0 | if (!path_converter(args[0], &path)) { |
10984 | 0 | goto exit; |
10985 | 0 | } |
10986 | 0 | if (!path_converter(args[1], &attribute)) { |
10987 | 0 | goto exit; |
10988 | 0 | } |
10989 | 0 | if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) { |
10990 | 0 | goto exit; |
10991 | 0 | } |
10992 | 0 | if (!noptargs) { |
10993 | 0 | goto skip_optional_pos; |
10994 | 0 | } |
10995 | 0 | if (args[3]) { |
10996 | 0 | flags = PyLong_AsInt(args[3]); |
10997 | 0 | if (flags == -1 && PyErr_Occurred()) { |
10998 | 0 | goto exit; |
10999 | 0 | } |
11000 | 0 | if (!--noptargs) { |
11001 | 0 | goto skip_optional_pos; |
11002 | 0 | } |
11003 | 0 | } |
11004 | 0 | skip_optional_pos: |
11005 | 0 | if (!noptargs) { |
11006 | 0 | goto skip_optional_kwonly; |
11007 | 0 | } |
11008 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
11009 | 0 | if (follow_symlinks < 0) { |
11010 | 0 | goto exit; |
11011 | 0 | } |
11012 | 0 | skip_optional_kwonly: |
11013 | 0 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
11014 | |
|
11015 | 0 | exit: |
11016 | | /* Cleanup for path */ |
11017 | 0 | path_cleanup(&path); |
11018 | | /* Cleanup for attribute */ |
11019 | 0 | path_cleanup(&attribute); |
11020 | | /* Cleanup for value */ |
11021 | 0 | if (value.obj) { |
11022 | 0 | PyBuffer_Release(&value); |
11023 | 0 | } |
11024 | |
|
11025 | 0 | return return_value; |
11026 | 0 | } |
11027 | | |
11028 | | #endif /* defined(USE_XATTRS) */ |
11029 | | |
11030 | | #if defined(USE_XATTRS) |
11031 | | |
11032 | | PyDoc_STRVAR(os_removexattr__doc__, |
11033 | | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
11034 | | "--\n" |
11035 | | "\n" |
11036 | | "Remove extended attribute attribute on path.\n" |
11037 | | "\n" |
11038 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
11039 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11040 | | " link, removexattr will modify the symbolic link itself instead of the file\n" |
11041 | | " the link points to."); |
11042 | | |
11043 | | #define OS_REMOVEXATTR_METHODDEF \ |
11044 | | {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__}, |
11045 | | |
11046 | | static PyObject * |
11047 | | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11048 | | int follow_symlinks); |
11049 | | |
11050 | | static PyObject * |
11051 | | os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11052 | 0 | { |
11053 | 0 | PyObject *return_value = NULL; |
11054 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11055 | |
|
11056 | 0 | #define NUM_KEYWORDS 3 |
11057 | 0 | static struct { |
11058 | 0 | PyGC_Head _this_is_not_used; |
11059 | 0 | PyObject_VAR_HEAD |
11060 | 0 | Py_hash_t ob_hash; |
11061 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11062 | 0 | } _kwtuple = { |
11063 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11064 | 0 | .ob_hash = -1, |
11065 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
11066 | 0 | }; |
11067 | 0 | #undef NUM_KEYWORDS |
11068 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11069 | |
|
11070 | | #else // !Py_BUILD_CORE |
11071 | | # define KWTUPLE NULL |
11072 | | #endif // !Py_BUILD_CORE |
11073 | |
|
11074 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
11075 | 0 | static _PyArg_Parser _parser = { |
11076 | 0 | .keywords = _keywords, |
11077 | 0 | .fname = "removexattr", |
11078 | 0 | .kwtuple = KWTUPLE, |
11079 | 0 | }; |
11080 | 0 | #undef KWTUPLE |
11081 | 0 | PyObject *argsbuf[3]; |
11082 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
11083 | 0 | path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1); |
11084 | 0 | path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0); |
11085 | 0 | int follow_symlinks = 1; |
11086 | |
|
11087 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11088 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11089 | 0 | if (!args) { |
11090 | 0 | goto exit; |
11091 | 0 | } |
11092 | 0 | if (!path_converter(args[0], &path)) { |
11093 | 0 | goto exit; |
11094 | 0 | } |
11095 | 0 | if (!path_converter(args[1], &attribute)) { |
11096 | 0 | goto exit; |
11097 | 0 | } |
11098 | 0 | if (!noptargs) { |
11099 | 0 | goto skip_optional_kwonly; |
11100 | 0 | } |
11101 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
11102 | 0 | if (follow_symlinks < 0) { |
11103 | 0 | goto exit; |
11104 | 0 | } |
11105 | 0 | skip_optional_kwonly: |
11106 | 0 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
11107 | |
|
11108 | 0 | exit: |
11109 | | /* Cleanup for path */ |
11110 | 0 | path_cleanup(&path); |
11111 | | /* Cleanup for attribute */ |
11112 | 0 | path_cleanup(&attribute); |
11113 | |
|
11114 | 0 | return return_value; |
11115 | 0 | } |
11116 | | |
11117 | | #endif /* defined(USE_XATTRS) */ |
11118 | | |
11119 | | #if defined(USE_XATTRS) |
11120 | | |
11121 | | PyDoc_STRVAR(os_listxattr__doc__, |
11122 | | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
11123 | | "--\n" |
11124 | | "\n" |
11125 | | "Return a list of extended attributes on path.\n" |
11126 | | "\n" |
11127 | | "path may be either None, a string, a path-like object, or an open file descriptor.\n" |
11128 | | "if path is None, listxattr will examine the current directory.\n" |
11129 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11130 | | " link, listxattr will examine the symbolic link itself instead of the file\n" |
11131 | | " the link points to."); |
11132 | | |
11133 | | #define OS_LISTXATTR_METHODDEF \ |
11134 | | {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__}, |
11135 | | |
11136 | | static PyObject * |
11137 | | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
11138 | | |
11139 | | static PyObject * |
11140 | | os_listxattr(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 2 |
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(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", "follow_symlinks", NULL}; |
11164 | 0 | static _PyArg_Parser _parser = { |
11165 | 0 | .keywords = _keywords, |
11166 | 0 | .fname = "listxattr", |
11167 | 0 | .kwtuple = KWTUPLE, |
11168 | 0 | }; |
11169 | 0 | #undef KWTUPLE |
11170 | 0 | PyObject *argsbuf[2]; |
11171 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
11172 | 0 | path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1); |
11173 | 0 | int follow_symlinks = 1; |
11174 | |
|
11175 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11176 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11177 | 0 | if (!args) { |
11178 | 0 | goto exit; |
11179 | 0 | } |
11180 | 0 | if (!noptargs) { |
11181 | 0 | goto skip_optional_pos; |
11182 | 0 | } |
11183 | 0 | if (args[0]) { |
11184 | 0 | if (!path_converter(args[0], &path)) { |
11185 | 0 | goto exit; |
11186 | 0 | } |
11187 | 0 | if (!--noptargs) { |
11188 | 0 | goto skip_optional_pos; |
11189 | 0 | } |
11190 | 0 | } |
11191 | 0 | skip_optional_pos: |
11192 | 0 | if (!noptargs) { |
11193 | 0 | goto skip_optional_kwonly; |
11194 | 0 | } |
11195 | 0 | follow_symlinks = PyObject_IsTrue(args[1]); |
11196 | 0 | if (follow_symlinks < 0) { |
11197 | 0 | goto exit; |
11198 | 0 | } |
11199 | 0 | skip_optional_kwonly: |
11200 | 0 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
11201 | |
|
11202 | 0 | exit: |
11203 | | /* Cleanup for path */ |
11204 | 0 | path_cleanup(&path); |
11205 | |
|
11206 | 0 | return return_value; |
11207 | 0 | } |
11208 | | |
11209 | | #endif /* defined(USE_XATTRS) */ |
11210 | | |
11211 | | PyDoc_STRVAR(os_urandom__doc__, |
11212 | | "urandom($module, size, /)\n" |
11213 | | "--\n" |
11214 | | "\n" |
11215 | | "Return a bytes object containing random bytes suitable for cryptographic use."); |
11216 | | |
11217 | | #define OS_URANDOM_METHODDEF \ |
11218 | | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
11219 | | |
11220 | | static PyObject * |
11221 | | os_urandom_impl(PyObject *module, Py_ssize_t size); |
11222 | | |
11223 | | static PyObject * |
11224 | | os_urandom(PyObject *module, PyObject *arg) |
11225 | 0 | { |
11226 | 0 | PyObject *return_value = NULL; |
11227 | 0 | Py_ssize_t size; |
11228 | |
|
11229 | 0 | { |
11230 | 0 | Py_ssize_t ival = -1; |
11231 | 0 | PyObject *iobj = _PyNumber_Index(arg); |
11232 | 0 | if (iobj != NULL) { |
11233 | 0 | ival = PyLong_AsSsize_t(iobj); |
11234 | 0 | Py_DECREF(iobj); |
11235 | 0 | } |
11236 | 0 | if (ival == -1 && PyErr_Occurred()) { |
11237 | 0 | goto exit; |
11238 | 0 | } |
11239 | 0 | size = ival; |
11240 | 0 | } |
11241 | 0 | return_value = os_urandom_impl(module, size); |
11242 | |
|
11243 | 0 | exit: |
11244 | 0 | return return_value; |
11245 | 0 | } |
11246 | | |
11247 | | #if defined(HAVE_MEMFD_CREATE) |
11248 | | |
11249 | | PyDoc_STRVAR(os_memfd_create__doc__, |
11250 | | "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n" |
11251 | | "--\n" |
11252 | | "\n"); |
11253 | | |
11254 | | #define OS_MEMFD_CREATE_METHODDEF \ |
11255 | | {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__}, |
11256 | | |
11257 | | static PyObject * |
11258 | | os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags); |
11259 | | |
11260 | | static PyObject * |
11261 | | os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11262 | 0 | { |
11263 | 0 | PyObject *return_value = NULL; |
11264 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11265 | |
|
11266 | 0 | #define NUM_KEYWORDS 2 |
11267 | 0 | static struct { |
11268 | 0 | PyGC_Head _this_is_not_used; |
11269 | 0 | PyObject_VAR_HEAD |
11270 | 0 | Py_hash_t ob_hash; |
11271 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11272 | 0 | } _kwtuple = { |
11273 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11274 | 0 | .ob_hash = -1, |
11275 | 0 | .ob_item = { &_Py_ID(name), &_Py_ID(flags), }, |
11276 | 0 | }; |
11277 | 0 | #undef NUM_KEYWORDS |
11278 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11279 | |
|
11280 | | #else // !Py_BUILD_CORE |
11281 | | # define KWTUPLE NULL |
11282 | | #endif // !Py_BUILD_CORE |
11283 | |
|
11284 | 0 | static const char * const _keywords[] = {"name", "flags", NULL}; |
11285 | 0 | static _PyArg_Parser _parser = { |
11286 | 0 | .keywords = _keywords, |
11287 | 0 | .fname = "memfd_create", |
11288 | 0 | .kwtuple = KWTUPLE, |
11289 | 0 | }; |
11290 | 0 | #undef KWTUPLE |
11291 | 0 | PyObject *argsbuf[2]; |
11292 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11293 | 0 | PyObject *name = NULL; |
11294 | 0 | unsigned int flags = MFD_CLOEXEC; |
11295 | |
|
11296 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11297 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11298 | 0 | if (!args) { |
11299 | 0 | goto exit; |
11300 | 0 | } |
11301 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
11302 | 0 | goto exit; |
11303 | 0 | } |
11304 | 0 | if (!noptargs) { |
11305 | 0 | goto skip_optional_pos; |
11306 | 0 | } |
11307 | 0 | { |
11308 | 0 | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned int), |
11309 | 0 | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
11310 | 0 | Py_ASNATIVEBYTES_ALLOW_INDEX | |
11311 | 0 | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
11312 | 0 | if (_bytes < 0) { |
11313 | 0 | goto exit; |
11314 | 0 | } |
11315 | 0 | if ((size_t)_bytes > sizeof(unsigned int)) { |
11316 | 0 | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
11317 | 0 | "integer value out of range", 1) < 0) |
11318 | 0 | { |
11319 | 0 | goto exit; |
11320 | 0 | } |
11321 | 0 | } |
11322 | 0 | } |
11323 | 0 | skip_optional_pos: |
11324 | 0 | return_value = os_memfd_create_impl(module, name, flags); |
11325 | |
|
11326 | 0 | exit: |
11327 | | /* Cleanup for name */ |
11328 | 0 | Py_XDECREF(name); |
11329 | |
|
11330 | 0 | return return_value; |
11331 | 0 | } |
11332 | | |
11333 | | #endif /* defined(HAVE_MEMFD_CREATE) */ |
11334 | | |
11335 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11336 | | |
11337 | | PyDoc_STRVAR(os_eventfd__doc__, |
11338 | | "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n" |
11339 | | "--\n" |
11340 | | "\n" |
11341 | | "Creates and returns an event notification file descriptor."); |
11342 | | |
11343 | | #define OS_EVENTFD_METHODDEF \ |
11344 | | {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__}, |
11345 | | |
11346 | | static PyObject * |
11347 | | os_eventfd_impl(PyObject *module, unsigned int initval, int flags); |
11348 | | |
11349 | | static PyObject * |
11350 | | os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11351 | 0 | { |
11352 | 0 | PyObject *return_value = NULL; |
11353 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11354 | |
|
11355 | 0 | #define NUM_KEYWORDS 2 |
11356 | 0 | static struct { |
11357 | 0 | PyGC_Head _this_is_not_used; |
11358 | 0 | PyObject_VAR_HEAD |
11359 | 0 | Py_hash_t ob_hash; |
11360 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11361 | 0 | } _kwtuple = { |
11362 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11363 | 0 | .ob_hash = -1, |
11364 | 0 | .ob_item = { &_Py_ID(initval), &_Py_ID(flags), }, |
11365 | 0 | }; |
11366 | 0 | #undef NUM_KEYWORDS |
11367 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11368 | |
|
11369 | | #else // !Py_BUILD_CORE |
11370 | | # define KWTUPLE NULL |
11371 | | #endif // !Py_BUILD_CORE |
11372 | |
|
11373 | 0 | static const char * const _keywords[] = {"initval", "flags", NULL}; |
11374 | 0 | static _PyArg_Parser _parser = { |
11375 | 0 | .keywords = _keywords, |
11376 | 0 | .fname = "eventfd", |
11377 | 0 | .kwtuple = KWTUPLE, |
11378 | 0 | }; |
11379 | 0 | #undef KWTUPLE |
11380 | 0 | PyObject *argsbuf[2]; |
11381 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11382 | 0 | unsigned int initval; |
11383 | 0 | int flags = EFD_CLOEXEC; |
11384 | |
|
11385 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11386 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11387 | 0 | if (!args) { |
11388 | 0 | goto exit; |
11389 | 0 | } |
11390 | 0 | if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) { |
11391 | 0 | goto exit; |
11392 | 0 | } |
11393 | 0 | if (!noptargs) { |
11394 | 0 | goto skip_optional_pos; |
11395 | 0 | } |
11396 | 0 | flags = PyLong_AsInt(args[1]); |
11397 | 0 | if (flags == -1 && PyErr_Occurred()) { |
11398 | 0 | goto exit; |
11399 | 0 | } |
11400 | 0 | skip_optional_pos: |
11401 | 0 | return_value = os_eventfd_impl(module, initval, flags); |
11402 | |
|
11403 | 0 | exit: |
11404 | 0 | return return_value; |
11405 | 0 | } |
11406 | | |
11407 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11408 | | |
11409 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11410 | | |
11411 | | PyDoc_STRVAR(os_eventfd_read__doc__, |
11412 | | "eventfd_read($module, /, fd)\n" |
11413 | | "--\n" |
11414 | | "\n" |
11415 | | "Read eventfd value"); |
11416 | | |
11417 | | #define OS_EVENTFD_READ_METHODDEF \ |
11418 | | {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__}, |
11419 | | |
11420 | | static PyObject * |
11421 | | os_eventfd_read_impl(PyObject *module, int fd); |
11422 | | |
11423 | | static PyObject * |
11424 | | os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11425 | 0 | { |
11426 | 0 | PyObject *return_value = NULL; |
11427 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11428 | |
|
11429 | 0 | #define NUM_KEYWORDS 1 |
11430 | 0 | static struct { |
11431 | 0 | PyGC_Head _this_is_not_used; |
11432 | 0 | PyObject_VAR_HEAD |
11433 | 0 | Py_hash_t ob_hash; |
11434 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11435 | 0 | } _kwtuple = { |
11436 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11437 | 0 | .ob_hash = -1, |
11438 | 0 | .ob_item = { &_Py_ID(fd), }, |
11439 | 0 | }; |
11440 | 0 | #undef NUM_KEYWORDS |
11441 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11442 | |
|
11443 | | #else // !Py_BUILD_CORE |
11444 | | # define KWTUPLE NULL |
11445 | | #endif // !Py_BUILD_CORE |
11446 | |
|
11447 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
11448 | 0 | static _PyArg_Parser _parser = { |
11449 | 0 | .keywords = _keywords, |
11450 | 0 | .fname = "eventfd_read", |
11451 | 0 | .kwtuple = KWTUPLE, |
11452 | 0 | }; |
11453 | 0 | #undef KWTUPLE |
11454 | 0 | PyObject *argsbuf[1]; |
11455 | 0 | int fd; |
11456 | |
|
11457 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11458 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11459 | 0 | if (!args) { |
11460 | 0 | goto exit; |
11461 | 0 | } |
11462 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11463 | 0 | if (fd < 0) { |
11464 | 0 | goto exit; |
11465 | 0 | } |
11466 | 0 | return_value = os_eventfd_read_impl(module, fd); |
11467 | |
|
11468 | 0 | exit: |
11469 | 0 | return return_value; |
11470 | 0 | } |
11471 | | |
11472 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11473 | | |
11474 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11475 | | |
11476 | | PyDoc_STRVAR(os_eventfd_write__doc__, |
11477 | | "eventfd_write($module, /, fd, value)\n" |
11478 | | "--\n" |
11479 | | "\n" |
11480 | | "Write eventfd value."); |
11481 | | |
11482 | | #define OS_EVENTFD_WRITE_METHODDEF \ |
11483 | | {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__}, |
11484 | | |
11485 | | static PyObject * |
11486 | | os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value); |
11487 | | |
11488 | | static PyObject * |
11489 | | os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11490 | 0 | { |
11491 | 0 | PyObject *return_value = NULL; |
11492 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11493 | |
|
11494 | 0 | #define NUM_KEYWORDS 2 |
11495 | 0 | static struct { |
11496 | 0 | PyGC_Head _this_is_not_used; |
11497 | 0 | PyObject_VAR_HEAD |
11498 | 0 | Py_hash_t ob_hash; |
11499 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11500 | 0 | } _kwtuple = { |
11501 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11502 | 0 | .ob_hash = -1, |
11503 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(value), }, |
11504 | 0 | }; |
11505 | 0 | #undef NUM_KEYWORDS |
11506 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11507 | |
|
11508 | | #else // !Py_BUILD_CORE |
11509 | | # define KWTUPLE NULL |
11510 | | #endif // !Py_BUILD_CORE |
11511 | |
|
11512 | 0 | static const char * const _keywords[] = {"fd", "value", NULL}; |
11513 | 0 | static _PyArg_Parser _parser = { |
11514 | 0 | .keywords = _keywords, |
11515 | 0 | .fname = "eventfd_write", |
11516 | 0 | .kwtuple = KWTUPLE, |
11517 | 0 | }; |
11518 | 0 | #undef KWTUPLE |
11519 | 0 | PyObject *argsbuf[2]; |
11520 | 0 | int fd; |
11521 | 0 | unsigned long long value; |
11522 | |
|
11523 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11524 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11525 | 0 | if (!args) { |
11526 | 0 | goto exit; |
11527 | 0 | } |
11528 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11529 | 0 | if (fd < 0) { |
11530 | 0 | goto exit; |
11531 | 0 | } |
11532 | 0 | if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) { |
11533 | 0 | goto exit; |
11534 | 0 | } |
11535 | 0 | return_value = os_eventfd_write_impl(module, fd, value); |
11536 | |
|
11537 | 0 | exit: |
11538 | 0 | return return_value; |
11539 | 0 | } |
11540 | | |
11541 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11542 | | |
11543 | | #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) |
11544 | | |
11545 | | PyDoc_STRVAR(os_get_terminal_size__doc__, |
11546 | | "get_terminal_size($module, fd=<unrepresentable>, /)\n" |
11547 | | "--\n" |
11548 | | "\n" |
11549 | | "Return the size of the terminal window as (columns, lines).\n" |
11550 | | "\n" |
11551 | | "The optional argument fd (default standard output) specifies\n" |
11552 | | "which file descriptor should be queried.\n" |
11553 | | "\n" |
11554 | | "If the file descriptor is not connected to a terminal, an OSError\n" |
11555 | | "is thrown.\n" |
11556 | | "\n" |
11557 | | "This function will only be defined if an implementation is\n" |
11558 | | "available for this system.\n" |
11559 | | "\n" |
11560 | | "shutil.get_terminal_size is the high-level function which should\n" |
11561 | | "normally be used, os.get_terminal_size is the low-level implementation."); |
11562 | | |
11563 | | #define OS_GET_TERMINAL_SIZE_METHODDEF \ |
11564 | | {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__}, |
11565 | | |
11566 | | static PyObject * |
11567 | | os_get_terminal_size_impl(PyObject *module, int fd); |
11568 | | |
11569 | | static PyObject * |
11570 | | os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11571 | 0 | { |
11572 | 0 | PyObject *return_value = NULL; |
11573 | 0 | int fd = fileno(stdout); |
11574 | |
|
11575 | 0 | if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) { |
11576 | 0 | goto exit; |
11577 | 0 | } |
11578 | 0 | if (nargs < 1) { |
11579 | 0 | goto skip_optional; |
11580 | 0 | } |
11581 | 0 | fd = PyLong_AsInt(args[0]); |
11582 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11583 | 0 | goto exit; |
11584 | 0 | } |
11585 | 0 | skip_optional: |
11586 | 0 | return_value = os_get_terminal_size_impl(module, fd); |
11587 | |
|
11588 | 0 | exit: |
11589 | 0 | return return_value; |
11590 | 0 | } |
11591 | | |
11592 | | #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */ |
11593 | | |
11594 | | PyDoc_STRVAR(os_cpu_count__doc__, |
11595 | | "cpu_count($module, /)\n" |
11596 | | "--\n" |
11597 | | "\n" |
11598 | | "Return the number of logical CPUs in the system.\n" |
11599 | | "\n" |
11600 | | "Return None if indeterminable."); |
11601 | | |
11602 | | #define OS_CPU_COUNT_METHODDEF \ |
11603 | | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
11604 | | |
11605 | | static PyObject * |
11606 | | os_cpu_count_impl(PyObject *module); |
11607 | | |
11608 | | static PyObject * |
11609 | | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
11610 | 0 | { |
11611 | 0 | return os_cpu_count_impl(module); |
11612 | 0 | } |
11613 | | |
11614 | | PyDoc_STRVAR(os_get_inheritable__doc__, |
11615 | | "get_inheritable($module, fd, /)\n" |
11616 | | "--\n" |
11617 | | "\n" |
11618 | | "Get the close-on-exe flag of the specified file descriptor."); |
11619 | | |
11620 | | #define OS_GET_INHERITABLE_METHODDEF \ |
11621 | | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
11622 | | |
11623 | | static int |
11624 | | os_get_inheritable_impl(PyObject *module, int fd); |
11625 | | |
11626 | | static PyObject * |
11627 | | os_get_inheritable(PyObject *module, PyObject *arg) |
11628 | 0 | { |
11629 | 0 | PyObject *return_value = NULL; |
11630 | 0 | int fd; |
11631 | 0 | int _return_value; |
11632 | |
|
11633 | 0 | fd = PyLong_AsInt(arg); |
11634 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11635 | 0 | goto exit; |
11636 | 0 | } |
11637 | 0 | _return_value = os_get_inheritable_impl(module, fd); |
11638 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11639 | 0 | goto exit; |
11640 | 0 | } |
11641 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11642 | |
|
11643 | 0 | exit: |
11644 | 0 | return return_value; |
11645 | 0 | } |
11646 | | |
11647 | | PyDoc_STRVAR(os_set_inheritable__doc__, |
11648 | | "set_inheritable($module, fd, inheritable, /)\n" |
11649 | | "--\n" |
11650 | | "\n" |
11651 | | "Set the inheritable flag of the specified file descriptor."); |
11652 | | |
11653 | | #define OS_SET_INHERITABLE_METHODDEF \ |
11654 | | {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__}, |
11655 | | |
11656 | | static PyObject * |
11657 | | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
11658 | | |
11659 | | static PyObject * |
11660 | | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11661 | 0 | { |
11662 | 0 | PyObject *return_value = NULL; |
11663 | 0 | int fd; |
11664 | 0 | int inheritable; |
11665 | |
|
11666 | 0 | if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { |
11667 | 0 | goto exit; |
11668 | 0 | } |
11669 | 0 | fd = PyLong_AsInt(args[0]); |
11670 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11671 | 0 | goto exit; |
11672 | 0 | } |
11673 | 0 | inheritable = PyLong_AsInt(args[1]); |
11674 | 0 | if (inheritable == -1 && PyErr_Occurred()) { |
11675 | 0 | goto exit; |
11676 | 0 | } |
11677 | 0 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
11678 | |
|
11679 | 0 | exit: |
11680 | 0 | return return_value; |
11681 | 0 | } |
11682 | | |
11683 | | #if defined(MS_WINDOWS) |
11684 | | |
11685 | | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
11686 | | "get_handle_inheritable($module, handle, /)\n" |
11687 | | "--\n" |
11688 | | "\n" |
11689 | | "Get the close-on-exe flag of the specified file descriptor."); |
11690 | | |
11691 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
11692 | | {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__}, |
11693 | | |
11694 | | static int |
11695 | | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
11696 | | |
11697 | | static PyObject * |
11698 | | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
11699 | | { |
11700 | | PyObject *return_value = NULL; |
11701 | | intptr_t handle; |
11702 | | int _return_value; |
11703 | | |
11704 | | handle = (intptr_t)PyLong_AsVoidPtr(arg); |
11705 | | if (!handle && PyErr_Occurred()) { |
11706 | | goto exit; |
11707 | | } |
11708 | | _return_value = os_get_handle_inheritable_impl(module, handle); |
11709 | | if ((_return_value == -1) && PyErr_Occurred()) { |
11710 | | goto exit; |
11711 | | } |
11712 | | return_value = PyBool_FromLong((long)_return_value); |
11713 | | |
11714 | | exit: |
11715 | | return return_value; |
11716 | | } |
11717 | | |
11718 | | #endif /* defined(MS_WINDOWS) */ |
11719 | | |
11720 | | #if defined(MS_WINDOWS) |
11721 | | |
11722 | | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
11723 | | "set_handle_inheritable($module, handle, inheritable, /)\n" |
11724 | | "--\n" |
11725 | | "\n" |
11726 | | "Set the inheritable flag of the specified handle."); |
11727 | | |
11728 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
11729 | | {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__}, |
11730 | | |
11731 | | static PyObject * |
11732 | | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
11733 | | int inheritable); |
11734 | | |
11735 | | static PyObject * |
11736 | | os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11737 | | { |
11738 | | PyObject *return_value = NULL; |
11739 | | intptr_t handle; |
11740 | | int inheritable; |
11741 | | |
11742 | | if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) { |
11743 | | goto exit; |
11744 | | } |
11745 | | handle = (intptr_t)PyLong_AsVoidPtr(args[0]); |
11746 | | if (!handle && PyErr_Occurred()) { |
11747 | | goto exit; |
11748 | | } |
11749 | | inheritable = PyObject_IsTrue(args[1]); |
11750 | | if (inheritable < 0) { |
11751 | | goto exit; |
11752 | | } |
11753 | | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
11754 | | |
11755 | | exit: |
11756 | | return return_value; |
11757 | | } |
11758 | | |
11759 | | #endif /* defined(MS_WINDOWS) */ |
11760 | | |
11761 | | PyDoc_STRVAR(os_get_blocking__doc__, |
11762 | | "get_blocking($module, fd, /)\n" |
11763 | | "--\n" |
11764 | | "\n" |
11765 | | "Get the blocking mode of the file descriptor.\n" |
11766 | | "\n" |
11767 | | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared."); |
11768 | | |
11769 | | #define OS_GET_BLOCKING_METHODDEF \ |
11770 | | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
11771 | | |
11772 | | static int |
11773 | | os_get_blocking_impl(PyObject *module, int fd); |
11774 | | |
11775 | | static PyObject * |
11776 | | os_get_blocking(PyObject *module, PyObject *arg) |
11777 | 0 | { |
11778 | 0 | PyObject *return_value = NULL; |
11779 | 0 | int fd; |
11780 | 0 | int _return_value; |
11781 | |
|
11782 | 0 | fd = PyLong_AsInt(arg); |
11783 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11784 | 0 | goto exit; |
11785 | 0 | } |
11786 | 0 | _return_value = os_get_blocking_impl(module, fd); |
11787 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11788 | 0 | goto exit; |
11789 | 0 | } |
11790 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11791 | |
|
11792 | 0 | exit: |
11793 | 0 | return return_value; |
11794 | 0 | } |
11795 | | |
11796 | | PyDoc_STRVAR(os_set_blocking__doc__, |
11797 | | "set_blocking($module, fd, blocking, /)\n" |
11798 | | "--\n" |
11799 | | "\n" |
11800 | | "Set the blocking mode of the specified file descriptor.\n" |
11801 | | "\n" |
11802 | | "Set the O_NONBLOCK flag if blocking is False,\n" |
11803 | | "clear the O_NONBLOCK flag otherwise."); |
11804 | | |
11805 | | #define OS_SET_BLOCKING_METHODDEF \ |
11806 | | {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__}, |
11807 | | |
11808 | | static PyObject * |
11809 | | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
11810 | | |
11811 | | static PyObject * |
11812 | | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11813 | 0 | { |
11814 | 0 | PyObject *return_value = NULL; |
11815 | 0 | int fd; |
11816 | 0 | int blocking; |
11817 | |
|
11818 | 0 | if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { |
11819 | 0 | goto exit; |
11820 | 0 | } |
11821 | 0 | fd = PyLong_AsInt(args[0]); |
11822 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11823 | 0 | goto exit; |
11824 | 0 | } |
11825 | 0 | blocking = PyObject_IsTrue(args[1]); |
11826 | 0 | if (blocking < 0) { |
11827 | 0 | goto exit; |
11828 | 0 | } |
11829 | 0 | return_value = os_set_blocking_impl(module, fd, blocking); |
11830 | |
|
11831 | 0 | exit: |
11832 | 0 | return return_value; |
11833 | 0 | } |
11834 | | |
11835 | | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
11836 | | "is_symlink($self, /)\n" |
11837 | | "--\n" |
11838 | | "\n" |
11839 | | "Return True if the entry is a symbolic link; cached per entry."); |
11840 | | |
11841 | | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
11842 | | {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__}, |
11843 | | |
11844 | | static int |
11845 | | os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class); |
11846 | | |
11847 | | static PyObject * |
11848 | | os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11849 | 0 | { |
11850 | 0 | PyObject *return_value = NULL; |
11851 | 0 | int _return_value; |
11852 | |
|
11853 | 0 | if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
11854 | 0 | PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments"); |
11855 | 0 | goto exit; |
11856 | 0 | } |
11857 | 0 | _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class); |
11858 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11859 | 0 | goto exit; |
11860 | 0 | } |
11861 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11862 | |
|
11863 | 0 | exit: |
11864 | 0 | return return_value; |
11865 | 0 | } |
11866 | | |
11867 | | PyDoc_STRVAR(os_DirEntry_is_junction__doc__, |
11868 | | "is_junction($self, /)\n" |
11869 | | "--\n" |
11870 | | "\n" |
11871 | | "Return True if the entry is a junction; cached per entry."); |
11872 | | |
11873 | | #define OS_DIRENTRY_IS_JUNCTION_METHODDEF \ |
11874 | | {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__}, |
11875 | | |
11876 | | static int |
11877 | | os_DirEntry_is_junction_impl(DirEntry *self); |
11878 | | |
11879 | | static PyObject * |
11880 | | os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored)) |
11881 | 0 | { |
11882 | 0 | PyObject *return_value = NULL; |
11883 | 0 | int _return_value; |
11884 | |
|
11885 | 0 | _return_value = os_DirEntry_is_junction_impl((DirEntry *)self); |
11886 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11887 | 0 | goto exit; |
11888 | 0 | } |
11889 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11890 | |
|
11891 | 0 | exit: |
11892 | 0 | return return_value; |
11893 | 0 | } |
11894 | | |
11895 | | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
11896 | | "stat($self, /, *, follow_symlinks=True)\n" |
11897 | | "--\n" |
11898 | | "\n" |
11899 | | "Return stat_result object for the entry; cached per entry."); |
11900 | | |
11901 | | #define OS_DIRENTRY_STAT_METHODDEF \ |
11902 | | {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__}, |
11903 | | |
11904 | | static PyObject * |
11905 | | os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class, |
11906 | | int follow_symlinks); |
11907 | | |
11908 | | static PyObject * |
11909 | | os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11910 | 0 | { |
11911 | 0 | PyObject *return_value = NULL; |
11912 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11913 | |
|
11914 | 0 | #define NUM_KEYWORDS 1 |
11915 | 0 | static struct { |
11916 | 0 | PyGC_Head _this_is_not_used; |
11917 | 0 | PyObject_VAR_HEAD |
11918 | 0 | Py_hash_t ob_hash; |
11919 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11920 | 0 | } _kwtuple = { |
11921 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11922 | 0 | .ob_hash = -1, |
11923 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
11924 | 0 | }; |
11925 | 0 | #undef NUM_KEYWORDS |
11926 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11927 | |
|
11928 | | #else // !Py_BUILD_CORE |
11929 | | # define KWTUPLE NULL |
11930 | | #endif // !Py_BUILD_CORE |
11931 | |
|
11932 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
11933 | 0 | static _PyArg_Parser _parser = { |
11934 | 0 | .keywords = _keywords, |
11935 | 0 | .fname = "stat", |
11936 | 0 | .kwtuple = KWTUPLE, |
11937 | 0 | }; |
11938 | 0 | #undef KWTUPLE |
11939 | 0 | PyObject *argsbuf[1]; |
11940 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
11941 | 0 | int follow_symlinks = 1; |
11942 | |
|
11943 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11944 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11945 | 0 | if (!args) { |
11946 | 0 | goto exit; |
11947 | 0 | } |
11948 | 0 | if (!noptargs) { |
11949 | 0 | goto skip_optional_kwonly; |
11950 | 0 | } |
11951 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
11952 | 0 | if (follow_symlinks < 0) { |
11953 | 0 | goto exit; |
11954 | 0 | } |
11955 | 0 | skip_optional_kwonly: |
11956 | 0 | return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks); |
11957 | |
|
11958 | 0 | exit: |
11959 | 0 | return return_value; |
11960 | 0 | } |
11961 | | |
11962 | | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
11963 | | "is_dir($self, /, *, follow_symlinks=True)\n" |
11964 | | "--\n" |
11965 | | "\n" |
11966 | | "Return True if the entry is a directory; cached per entry."); |
11967 | | |
11968 | | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
11969 | | {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__}, |
11970 | | |
11971 | | static int |
11972 | | os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class, |
11973 | | int follow_symlinks); |
11974 | | |
11975 | | static PyObject * |
11976 | | os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11977 | 0 | { |
11978 | 0 | PyObject *return_value = NULL; |
11979 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11980 | |
|
11981 | 0 | #define NUM_KEYWORDS 1 |
11982 | 0 | static struct { |
11983 | 0 | PyGC_Head _this_is_not_used; |
11984 | 0 | PyObject_VAR_HEAD |
11985 | 0 | Py_hash_t ob_hash; |
11986 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11987 | 0 | } _kwtuple = { |
11988 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11989 | 0 | .ob_hash = -1, |
11990 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
11991 | 0 | }; |
11992 | 0 | #undef NUM_KEYWORDS |
11993 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11994 | |
|
11995 | | #else // !Py_BUILD_CORE |
11996 | | # define KWTUPLE NULL |
11997 | | #endif // !Py_BUILD_CORE |
11998 | |
|
11999 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12000 | 0 | static _PyArg_Parser _parser = { |
12001 | 0 | .keywords = _keywords, |
12002 | 0 | .fname = "is_dir", |
12003 | 0 | .kwtuple = KWTUPLE, |
12004 | 0 | }; |
12005 | 0 | #undef KWTUPLE |
12006 | 0 | PyObject *argsbuf[1]; |
12007 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12008 | 0 | int follow_symlinks = 1; |
12009 | 0 | int _return_value; |
12010 | |
|
12011 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12012 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12013 | 0 | if (!args) { |
12014 | 0 | goto exit; |
12015 | 0 | } |
12016 | 0 | if (!noptargs) { |
12017 | 0 | goto skip_optional_kwonly; |
12018 | 0 | } |
12019 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12020 | 0 | if (follow_symlinks < 0) { |
12021 | 0 | goto exit; |
12022 | 0 | } |
12023 | 0 | skip_optional_kwonly: |
12024 | 0 | _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks); |
12025 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12026 | 0 | goto exit; |
12027 | 0 | } |
12028 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12029 | |
|
12030 | 0 | exit: |
12031 | 0 | return return_value; |
12032 | 0 | } |
12033 | | |
12034 | | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
12035 | | "is_file($self, /, *, follow_symlinks=True)\n" |
12036 | | "--\n" |
12037 | | "\n" |
12038 | | "Return True if the entry is a file; cached per entry."); |
12039 | | |
12040 | | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
12041 | | {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__}, |
12042 | | |
12043 | | static int |
12044 | | os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class, |
12045 | | int follow_symlinks); |
12046 | | |
12047 | | static PyObject * |
12048 | | os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12049 | 0 | { |
12050 | 0 | PyObject *return_value = NULL; |
12051 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12052 | |
|
12053 | 0 | #define NUM_KEYWORDS 1 |
12054 | 0 | static struct { |
12055 | 0 | PyGC_Head _this_is_not_used; |
12056 | 0 | PyObject_VAR_HEAD |
12057 | 0 | Py_hash_t ob_hash; |
12058 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12059 | 0 | } _kwtuple = { |
12060 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12061 | 0 | .ob_hash = -1, |
12062 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12063 | 0 | }; |
12064 | 0 | #undef NUM_KEYWORDS |
12065 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12066 | |
|
12067 | | #else // !Py_BUILD_CORE |
12068 | | # define KWTUPLE NULL |
12069 | | #endif // !Py_BUILD_CORE |
12070 | |
|
12071 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12072 | 0 | static _PyArg_Parser _parser = { |
12073 | 0 | .keywords = _keywords, |
12074 | 0 | .fname = "is_file", |
12075 | 0 | .kwtuple = KWTUPLE, |
12076 | 0 | }; |
12077 | 0 | #undef KWTUPLE |
12078 | 0 | PyObject *argsbuf[1]; |
12079 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12080 | 0 | int follow_symlinks = 1; |
12081 | 0 | int _return_value; |
12082 | |
|
12083 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12084 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12085 | 0 | if (!args) { |
12086 | 0 | goto exit; |
12087 | 0 | } |
12088 | 0 | if (!noptargs) { |
12089 | 0 | goto skip_optional_kwonly; |
12090 | 0 | } |
12091 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12092 | 0 | if (follow_symlinks < 0) { |
12093 | 0 | goto exit; |
12094 | 0 | } |
12095 | 0 | skip_optional_kwonly: |
12096 | 0 | _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks); |
12097 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12098 | 0 | goto exit; |
12099 | 0 | } |
12100 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12101 | |
|
12102 | 0 | exit: |
12103 | 0 | return return_value; |
12104 | 0 | } |
12105 | | |
12106 | | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
12107 | | "inode($self, /)\n" |
12108 | | "--\n" |
12109 | | "\n" |
12110 | | "Return inode of the entry; cached per entry."); |
12111 | | |
12112 | | #define OS_DIRENTRY_INODE_METHODDEF \ |
12113 | | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
12114 | | |
12115 | | static PyObject * |
12116 | | os_DirEntry_inode_impl(DirEntry *self); |
12117 | | |
12118 | | static PyObject * |
12119 | | os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12120 | 0 | { |
12121 | 0 | return os_DirEntry_inode_impl((DirEntry *)self); |
12122 | 0 | } |
12123 | | |
12124 | | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
12125 | | "__fspath__($self, /)\n" |
12126 | | "--\n" |
12127 | | "\n" |
12128 | | "Returns the path for the entry."); |
12129 | | |
12130 | | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
12131 | | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
12132 | | |
12133 | | static PyObject * |
12134 | | os_DirEntry___fspath___impl(DirEntry *self); |
12135 | | |
12136 | | static PyObject * |
12137 | | os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12138 | 0 | { |
12139 | 0 | return os_DirEntry___fspath___impl((DirEntry *)self); |
12140 | 0 | } |
12141 | | |
12142 | | PyDoc_STRVAR(os_scandir__doc__, |
12143 | | "scandir($module, /, path=None)\n" |
12144 | | "--\n" |
12145 | | "\n" |
12146 | | "Return an iterator of DirEntry objects for given path.\n" |
12147 | | "\n" |
12148 | | "path can be specified as either str, bytes, or a path-like object. If path\n" |
12149 | | "is bytes, the names of yielded DirEntry objects will also be bytes; in\n" |
12150 | | "all other circumstances they will be str.\n" |
12151 | | "\n" |
12152 | | "If path is None, uses the path=\'.\'."); |
12153 | | |
12154 | | #define OS_SCANDIR_METHODDEF \ |
12155 | | {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__}, |
12156 | | |
12157 | | static PyObject * |
12158 | | os_scandir_impl(PyObject *module, path_t *path); |
12159 | | |
12160 | | static PyObject * |
12161 | | os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12162 | 0 | { |
12163 | 0 | PyObject *return_value = NULL; |
12164 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12165 | |
|
12166 | 0 | #define NUM_KEYWORDS 1 |
12167 | 0 | static struct { |
12168 | 0 | PyGC_Head _this_is_not_used; |
12169 | 0 | PyObject_VAR_HEAD |
12170 | 0 | Py_hash_t ob_hash; |
12171 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12172 | 0 | } _kwtuple = { |
12173 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12174 | 0 | .ob_hash = -1, |
12175 | 0 | .ob_item = { &_Py_ID(path), }, |
12176 | 0 | }; |
12177 | 0 | #undef NUM_KEYWORDS |
12178 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12179 | |
|
12180 | | #else // !Py_BUILD_CORE |
12181 | | # define KWTUPLE NULL |
12182 | | #endif // !Py_BUILD_CORE |
12183 | |
|
12184 | 0 | static const char * const _keywords[] = {"path", NULL}; |
12185 | 0 | static _PyArg_Parser _parser = { |
12186 | 0 | .keywords = _keywords, |
12187 | 0 | .fname = "scandir", |
12188 | 0 | .kwtuple = KWTUPLE, |
12189 | 0 | }; |
12190 | 0 | #undef KWTUPLE |
12191 | 0 | PyObject *argsbuf[1]; |
12192 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12193 | 0 | path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
12194 | |
|
12195 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12196 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12197 | 0 | if (!args) { |
12198 | 0 | goto exit; |
12199 | 0 | } |
12200 | 0 | if (!noptargs) { |
12201 | 0 | goto skip_optional_pos; |
12202 | 0 | } |
12203 | 0 | if (!path_converter(args[0], &path)) { |
12204 | 0 | goto exit; |
12205 | 0 | } |
12206 | 0 | skip_optional_pos: |
12207 | 0 | return_value = os_scandir_impl(module, &path); |
12208 | |
|
12209 | 0 | exit: |
12210 | | /* Cleanup for path */ |
12211 | 0 | path_cleanup(&path); |
12212 | |
|
12213 | 0 | return return_value; |
12214 | 0 | } |
12215 | | |
12216 | | PyDoc_STRVAR(os_fspath__doc__, |
12217 | | "fspath($module, /, path)\n" |
12218 | | "--\n" |
12219 | | "\n" |
12220 | | "Return the file system path representation of the object.\n" |
12221 | | "\n" |
12222 | | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
12223 | | "object defines __fspath__(), then return the result of that method. All other\n" |
12224 | | "types raise a TypeError."); |
12225 | | |
12226 | | #define OS_FSPATH_METHODDEF \ |
12227 | | {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__}, |
12228 | | |
12229 | | static PyObject * |
12230 | | os_fspath_impl(PyObject *module, PyObject *path); |
12231 | | |
12232 | | static PyObject * |
12233 | | os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12234 | 3.01k | { |
12235 | 3.01k | PyObject *return_value = NULL; |
12236 | 3.01k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12237 | | |
12238 | 3.01k | #define NUM_KEYWORDS 1 |
12239 | 3.01k | static struct { |
12240 | 3.01k | PyGC_Head _this_is_not_used; |
12241 | 3.01k | PyObject_VAR_HEAD |
12242 | 3.01k | Py_hash_t ob_hash; |
12243 | 3.01k | PyObject *ob_item[NUM_KEYWORDS]; |
12244 | 3.01k | } _kwtuple = { |
12245 | 3.01k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12246 | 3.01k | .ob_hash = -1, |
12247 | 3.01k | .ob_item = { &_Py_ID(path), }, |
12248 | 3.01k | }; |
12249 | 3.01k | #undef NUM_KEYWORDS |
12250 | 3.01k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12251 | | |
12252 | | #else // !Py_BUILD_CORE |
12253 | | # define KWTUPLE NULL |
12254 | | #endif // !Py_BUILD_CORE |
12255 | | |
12256 | 3.01k | static const char * const _keywords[] = {"path", NULL}; |
12257 | 3.01k | static _PyArg_Parser _parser = { |
12258 | 3.01k | .keywords = _keywords, |
12259 | 3.01k | .fname = "fspath", |
12260 | 3.01k | .kwtuple = KWTUPLE, |
12261 | 3.01k | }; |
12262 | 3.01k | #undef KWTUPLE |
12263 | 3.01k | PyObject *argsbuf[1]; |
12264 | 3.01k | PyObject *path; |
12265 | | |
12266 | 3.01k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12267 | 3.01k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12268 | 3.01k | if (!args) { |
12269 | 0 | goto exit; |
12270 | 0 | } |
12271 | 3.01k | path = args[0]; |
12272 | 3.01k | return_value = os_fspath_impl(module, path); |
12273 | | |
12274 | 3.01k | exit: |
12275 | 3.01k | return return_value; |
12276 | 3.01k | } |
12277 | | |
12278 | | #if defined(HAVE_GETRANDOM_SYSCALL) |
12279 | | |
12280 | | PyDoc_STRVAR(os_getrandom__doc__, |
12281 | | "getrandom($module, /, size, flags=0)\n" |
12282 | | "--\n" |
12283 | | "\n" |
12284 | | "Obtain a series of random bytes."); |
12285 | | |
12286 | | #define OS_GETRANDOM_METHODDEF \ |
12287 | | {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__}, |
12288 | | |
12289 | | static PyObject * |
12290 | | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
12291 | | |
12292 | | static PyObject * |
12293 | | os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12294 | 0 | { |
12295 | 0 | PyObject *return_value = NULL; |
12296 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12297 | |
|
12298 | 0 | #define NUM_KEYWORDS 2 |
12299 | 0 | static struct { |
12300 | 0 | PyGC_Head _this_is_not_used; |
12301 | 0 | PyObject_VAR_HEAD |
12302 | 0 | Py_hash_t ob_hash; |
12303 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12304 | 0 | } _kwtuple = { |
12305 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12306 | 0 | .ob_hash = -1, |
12307 | 0 | .ob_item = { &_Py_ID(size), &_Py_ID(flags), }, |
12308 | 0 | }; |
12309 | 0 | #undef NUM_KEYWORDS |
12310 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12311 | |
|
12312 | | #else // !Py_BUILD_CORE |
12313 | | # define KWTUPLE NULL |
12314 | | #endif // !Py_BUILD_CORE |
12315 | |
|
12316 | 0 | static const char * const _keywords[] = {"size", "flags", NULL}; |
12317 | 0 | static _PyArg_Parser _parser = { |
12318 | 0 | .keywords = _keywords, |
12319 | 0 | .fname = "getrandom", |
12320 | 0 | .kwtuple = KWTUPLE, |
12321 | 0 | }; |
12322 | 0 | #undef KWTUPLE |
12323 | 0 | PyObject *argsbuf[2]; |
12324 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
12325 | 0 | Py_ssize_t size; |
12326 | 0 | int flags = 0; |
12327 | |
|
12328 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12329 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12330 | 0 | if (!args) { |
12331 | 0 | goto exit; |
12332 | 0 | } |
12333 | 0 | { |
12334 | 0 | Py_ssize_t ival = -1; |
12335 | 0 | PyObject *iobj = _PyNumber_Index(args[0]); |
12336 | 0 | if (iobj != NULL) { |
12337 | 0 | ival = PyLong_AsSsize_t(iobj); |
12338 | 0 | Py_DECREF(iobj); |
12339 | 0 | } |
12340 | 0 | if (ival == -1 && PyErr_Occurred()) { |
12341 | 0 | goto exit; |
12342 | 0 | } |
12343 | 0 | size = ival; |
12344 | 0 | } |
12345 | 0 | if (!noptargs) { |
12346 | 0 | goto skip_optional_pos; |
12347 | 0 | } |
12348 | 0 | flags = PyLong_AsInt(args[1]); |
12349 | 0 | if (flags == -1 && PyErr_Occurred()) { |
12350 | 0 | goto exit; |
12351 | 0 | } |
12352 | 0 | skip_optional_pos: |
12353 | 0 | return_value = os_getrandom_impl(module, size, flags); |
12354 | |
|
12355 | 0 | exit: |
12356 | 0 | return return_value; |
12357 | 0 | } |
12358 | | |
12359 | | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
12360 | | |
12361 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12362 | | |
12363 | | PyDoc_STRVAR(os__add_dll_directory__doc__, |
12364 | | "_add_dll_directory($module, /, path)\n" |
12365 | | "--\n" |
12366 | | "\n" |
12367 | | "Add a path to the DLL search path.\n" |
12368 | | "\n" |
12369 | | "This search path is used when resolving dependencies for imported\n" |
12370 | | "extension modules (the module itself is resolved through sys.path),\n" |
12371 | | "and also by ctypes.\n" |
12372 | | "\n" |
12373 | | "Returns an opaque value that may be passed to os.remove_dll_directory\n" |
12374 | | "to remove this directory from the search path."); |
12375 | | |
12376 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF \ |
12377 | | {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__}, |
12378 | | |
12379 | | static PyObject * |
12380 | | os__add_dll_directory_impl(PyObject *module, path_t *path); |
12381 | | |
12382 | | static PyObject * |
12383 | | os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12384 | | { |
12385 | | PyObject *return_value = NULL; |
12386 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12387 | | |
12388 | | #define NUM_KEYWORDS 1 |
12389 | | static struct { |
12390 | | PyGC_Head _this_is_not_used; |
12391 | | PyObject_VAR_HEAD |
12392 | | Py_hash_t ob_hash; |
12393 | | PyObject *ob_item[NUM_KEYWORDS]; |
12394 | | } _kwtuple = { |
12395 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12396 | | .ob_hash = -1, |
12397 | | .ob_item = { &_Py_ID(path), }, |
12398 | | }; |
12399 | | #undef NUM_KEYWORDS |
12400 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12401 | | |
12402 | | #else // !Py_BUILD_CORE |
12403 | | # define KWTUPLE NULL |
12404 | | #endif // !Py_BUILD_CORE |
12405 | | |
12406 | | static const char * const _keywords[] = {"path", NULL}; |
12407 | | static _PyArg_Parser _parser = { |
12408 | | .keywords = _keywords, |
12409 | | .fname = "_add_dll_directory", |
12410 | | .kwtuple = KWTUPLE, |
12411 | | }; |
12412 | | #undef KWTUPLE |
12413 | | PyObject *argsbuf[1]; |
12414 | | path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0); |
12415 | | |
12416 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12417 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12418 | | if (!args) { |
12419 | | goto exit; |
12420 | | } |
12421 | | if (!path_converter(args[0], &path)) { |
12422 | | goto exit; |
12423 | | } |
12424 | | return_value = os__add_dll_directory_impl(module, &path); |
12425 | | |
12426 | | exit: |
12427 | | /* Cleanup for path */ |
12428 | | path_cleanup(&path); |
12429 | | |
12430 | | return return_value; |
12431 | | } |
12432 | | |
12433 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12434 | | |
12435 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12436 | | |
12437 | | PyDoc_STRVAR(os__remove_dll_directory__doc__, |
12438 | | "_remove_dll_directory($module, /, cookie)\n" |
12439 | | "--\n" |
12440 | | "\n" |
12441 | | "Removes a path from the DLL search path.\n" |
12442 | | "\n" |
12443 | | "The parameter is an opaque value that was returned from\n" |
12444 | | "os.add_dll_directory. You can only remove directories that you added\n" |
12445 | | "yourself."); |
12446 | | |
12447 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \ |
12448 | | {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__}, |
12449 | | |
12450 | | static PyObject * |
12451 | | os__remove_dll_directory_impl(PyObject *module, PyObject *cookie); |
12452 | | |
12453 | | static PyObject * |
12454 | | os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12455 | | { |
12456 | | PyObject *return_value = NULL; |
12457 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12458 | | |
12459 | | #define NUM_KEYWORDS 1 |
12460 | | static struct { |
12461 | | PyGC_Head _this_is_not_used; |
12462 | | PyObject_VAR_HEAD |
12463 | | Py_hash_t ob_hash; |
12464 | | PyObject *ob_item[NUM_KEYWORDS]; |
12465 | | } _kwtuple = { |
12466 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12467 | | .ob_hash = -1, |
12468 | | .ob_item = { &_Py_ID(cookie), }, |
12469 | | }; |
12470 | | #undef NUM_KEYWORDS |
12471 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12472 | | |
12473 | | #else // !Py_BUILD_CORE |
12474 | | # define KWTUPLE NULL |
12475 | | #endif // !Py_BUILD_CORE |
12476 | | |
12477 | | static const char * const _keywords[] = {"cookie", NULL}; |
12478 | | static _PyArg_Parser _parser = { |
12479 | | .keywords = _keywords, |
12480 | | .fname = "_remove_dll_directory", |
12481 | | .kwtuple = KWTUPLE, |
12482 | | }; |
12483 | | #undef KWTUPLE |
12484 | | PyObject *argsbuf[1]; |
12485 | | PyObject *cookie; |
12486 | | |
12487 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12488 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12489 | | if (!args) { |
12490 | | goto exit; |
12491 | | } |
12492 | | cookie = args[0]; |
12493 | | return_value = os__remove_dll_directory_impl(module, cookie); |
12494 | | |
12495 | | exit: |
12496 | | return return_value; |
12497 | | } |
12498 | | |
12499 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12500 | | |
12501 | | #if (defined(WIFEXITED) || defined(MS_WINDOWS)) |
12502 | | |
12503 | | PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__, |
12504 | | "waitstatus_to_exitcode($module, /, status)\n" |
12505 | | "--\n" |
12506 | | "\n" |
12507 | | "Convert a wait status to an exit code.\n" |
12508 | | "\n" |
12509 | | "On Unix:\n" |
12510 | | "\n" |
12511 | | "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n" |
12512 | | "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n" |
12513 | | "* Otherwise, raise a ValueError.\n" |
12514 | | "\n" |
12515 | | "On Windows, return status shifted right by 8 bits.\n" |
12516 | | "\n" |
12517 | | "On Unix, if the process is being traced or if waitpid() was called with\n" |
12518 | | "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n" |
12519 | | "This function must not be called if WIFSTOPPED(status) is true."); |
12520 | | |
12521 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \ |
12522 | | {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__}, |
12523 | | |
12524 | | static PyObject * |
12525 | | os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj); |
12526 | | |
12527 | | static PyObject * |
12528 | | os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12529 | 0 | { |
12530 | 0 | PyObject *return_value = NULL; |
12531 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12532 | |
|
12533 | 0 | #define NUM_KEYWORDS 1 |
12534 | 0 | static struct { |
12535 | 0 | PyGC_Head _this_is_not_used; |
12536 | 0 | PyObject_VAR_HEAD |
12537 | 0 | Py_hash_t ob_hash; |
12538 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12539 | 0 | } _kwtuple = { |
12540 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12541 | 0 | .ob_hash = -1, |
12542 | 0 | .ob_item = { &_Py_ID(status), }, |
12543 | 0 | }; |
12544 | 0 | #undef NUM_KEYWORDS |
12545 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12546 | |
|
12547 | | #else // !Py_BUILD_CORE |
12548 | | # define KWTUPLE NULL |
12549 | | #endif // !Py_BUILD_CORE |
12550 | |
|
12551 | 0 | static const char * const _keywords[] = {"status", NULL}; |
12552 | 0 | static _PyArg_Parser _parser = { |
12553 | 0 | .keywords = _keywords, |
12554 | 0 | .fname = "waitstatus_to_exitcode", |
12555 | 0 | .kwtuple = KWTUPLE, |
12556 | 0 | }; |
12557 | 0 | #undef KWTUPLE |
12558 | 0 | PyObject *argsbuf[1]; |
12559 | 0 | PyObject *status_obj; |
12560 | |
|
12561 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12562 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12563 | 0 | if (!args) { |
12564 | 0 | goto exit; |
12565 | 0 | } |
12566 | 0 | status_obj = args[0]; |
12567 | 0 | return_value = os_waitstatus_to_exitcode_impl(module, status_obj); |
12568 | |
|
12569 | 0 | exit: |
12570 | 0 | return return_value; |
12571 | 0 | } |
12572 | | |
12573 | | #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */ |
12574 | | |
12575 | | #if defined(MS_WINDOWS) |
12576 | | |
12577 | | PyDoc_STRVAR(os__supports_virtual_terminal__doc__, |
12578 | | "_supports_virtual_terminal($module, /)\n" |
12579 | | "--\n" |
12580 | | "\n" |
12581 | | "Checks if virtual terminal is supported in windows"); |
12582 | | |
12583 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF \ |
12584 | | {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__}, |
12585 | | |
12586 | | static PyObject * |
12587 | | os__supports_virtual_terminal_impl(PyObject *module); |
12588 | | |
12589 | | static PyObject * |
12590 | | os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12591 | | { |
12592 | | return os__supports_virtual_terminal_impl(module); |
12593 | | } |
12594 | | |
12595 | | #endif /* defined(MS_WINDOWS) */ |
12596 | | |
12597 | | PyDoc_STRVAR(os__inputhook__doc__, |
12598 | | "_inputhook($module, /)\n" |
12599 | | "--\n" |
12600 | | "\n" |
12601 | | "Calls PyOS_CallInputHook droppong the GIL first"); |
12602 | | |
12603 | | #define OS__INPUTHOOK_METHODDEF \ |
12604 | | {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__}, |
12605 | | |
12606 | | static PyObject * |
12607 | | os__inputhook_impl(PyObject *module); |
12608 | | |
12609 | | static PyObject * |
12610 | | os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12611 | 0 | { |
12612 | 0 | return os__inputhook_impl(module); |
12613 | 0 | } |
12614 | | |
12615 | | PyDoc_STRVAR(os__is_inputhook_installed__doc__, |
12616 | | "_is_inputhook_installed($module, /)\n" |
12617 | | "--\n" |
12618 | | "\n" |
12619 | | "Checks if PyOS_CallInputHook is set"); |
12620 | | |
12621 | | #define OS__IS_INPUTHOOK_INSTALLED_METHODDEF \ |
12622 | | {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__}, |
12623 | | |
12624 | | static PyObject * |
12625 | | os__is_inputhook_installed_impl(PyObject *module); |
12626 | | |
12627 | | static PyObject * |
12628 | | os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12629 | 0 | { |
12630 | 0 | return os__is_inputhook_installed_impl(module); |
12631 | 0 | } |
12632 | | |
12633 | | PyDoc_STRVAR(os__create_environ__doc__, |
12634 | | "_create_environ($module, /)\n" |
12635 | | "--\n" |
12636 | | "\n" |
12637 | | "Create the environment dictionary."); |
12638 | | |
12639 | | #define OS__CREATE_ENVIRON_METHODDEF \ |
12640 | | {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__}, |
12641 | | |
12642 | | static PyObject * |
12643 | | os__create_environ_impl(PyObject *module); |
12644 | | |
12645 | | static PyObject * |
12646 | | os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12647 | 0 | { |
12648 | 0 | return os__create_environ_impl(module); |
12649 | 0 | } |
12650 | | |
12651 | | #if defined(__EMSCRIPTEN__) |
12652 | | |
12653 | | PyDoc_STRVAR(os__emscripten_debugger__doc__, |
12654 | | "_emscripten_debugger($module, /)\n" |
12655 | | "--\n" |
12656 | | "\n" |
12657 | | "Create a breakpoint for the JavaScript debugger. Emscripten only."); |
12658 | | |
12659 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF \ |
12660 | | {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__}, |
12661 | | |
12662 | | static PyObject * |
12663 | | os__emscripten_debugger_impl(PyObject *module); |
12664 | | |
12665 | | static PyObject * |
12666 | | os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12667 | | { |
12668 | | return os__emscripten_debugger_impl(module); |
12669 | | } |
12670 | | |
12671 | | #endif /* defined(__EMSCRIPTEN__) */ |
12672 | | |
12673 | | #if defined(__EMSCRIPTEN__) |
12674 | | |
12675 | | PyDoc_STRVAR(os__emscripten_log__doc__, |
12676 | | "_emscripten_log($module, /, arg)\n" |
12677 | | "--\n" |
12678 | | "\n" |
12679 | | "Log something to the JS console. Emscripten only."); |
12680 | | |
12681 | | #define OS__EMSCRIPTEN_LOG_METHODDEF \ |
12682 | | {"_emscripten_log", _PyCFunction_CAST(os__emscripten_log), METH_FASTCALL|METH_KEYWORDS, os__emscripten_log__doc__}, |
12683 | | |
12684 | | static PyObject * |
12685 | | os__emscripten_log_impl(PyObject *module, const char *arg); |
12686 | | |
12687 | | static PyObject * |
12688 | | os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12689 | | { |
12690 | | PyObject *return_value = NULL; |
12691 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12692 | | |
12693 | | #define NUM_KEYWORDS 1 |
12694 | | static struct { |
12695 | | PyGC_Head _this_is_not_used; |
12696 | | PyObject_VAR_HEAD |
12697 | | Py_hash_t ob_hash; |
12698 | | PyObject *ob_item[NUM_KEYWORDS]; |
12699 | | } _kwtuple = { |
12700 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12701 | | .ob_hash = -1, |
12702 | | .ob_item = { &_Py_ID(arg), }, |
12703 | | }; |
12704 | | #undef NUM_KEYWORDS |
12705 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12706 | | |
12707 | | #else // !Py_BUILD_CORE |
12708 | | # define KWTUPLE NULL |
12709 | | #endif // !Py_BUILD_CORE |
12710 | | |
12711 | | static const char * const _keywords[] = {"arg", NULL}; |
12712 | | static _PyArg_Parser _parser = { |
12713 | | .keywords = _keywords, |
12714 | | .fname = "_emscripten_log", |
12715 | | .kwtuple = KWTUPLE, |
12716 | | }; |
12717 | | #undef KWTUPLE |
12718 | | PyObject *argsbuf[1]; |
12719 | | const char *arg; |
12720 | | |
12721 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12722 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12723 | | if (!args) { |
12724 | | goto exit; |
12725 | | } |
12726 | | if (!PyUnicode_Check(args[0])) { |
12727 | | _PyArg_BadArgument("_emscripten_log", "argument 'arg'", "str", args[0]); |
12728 | | goto exit; |
12729 | | } |
12730 | | Py_ssize_t arg_length; |
12731 | | arg = PyUnicode_AsUTF8AndSize(args[0], &arg_length); |
12732 | | if (arg == NULL) { |
12733 | | goto exit; |
12734 | | } |
12735 | | if (strlen(arg) != (size_t)arg_length) { |
12736 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
12737 | | goto exit; |
12738 | | } |
12739 | | return_value = os__emscripten_log_impl(module, arg); |
12740 | | |
12741 | | exit: |
12742 | | return return_value; |
12743 | | } |
12744 | | |
12745 | | #endif /* defined(__EMSCRIPTEN__) */ |
12746 | | |
12747 | | #ifndef OS_TTYNAME_METHODDEF |
12748 | | #define OS_TTYNAME_METHODDEF |
12749 | | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
12750 | | |
12751 | | #ifndef OS_CTERMID_METHODDEF |
12752 | | #define OS_CTERMID_METHODDEF |
12753 | | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
12754 | | |
12755 | | #ifndef OS_FCHDIR_METHODDEF |
12756 | | #define OS_FCHDIR_METHODDEF |
12757 | | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
12758 | | |
12759 | | #ifndef OS_FCHMOD_METHODDEF |
12760 | | #define OS_FCHMOD_METHODDEF |
12761 | | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
12762 | | |
12763 | | #ifndef OS_LCHMOD_METHODDEF |
12764 | | #define OS_LCHMOD_METHODDEF |
12765 | | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
12766 | | |
12767 | | #ifndef OS_CHFLAGS_METHODDEF |
12768 | | #define OS_CHFLAGS_METHODDEF |
12769 | | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
12770 | | |
12771 | | #ifndef OS_LCHFLAGS_METHODDEF |
12772 | | #define OS_LCHFLAGS_METHODDEF |
12773 | | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
12774 | | |
12775 | | #ifndef OS_CHROOT_METHODDEF |
12776 | | #define OS_CHROOT_METHODDEF |
12777 | | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
12778 | | |
12779 | | #ifndef OS_FSYNC_METHODDEF |
12780 | | #define OS_FSYNC_METHODDEF |
12781 | | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
12782 | | |
12783 | | #ifndef OS_SYNC_METHODDEF |
12784 | | #define OS_SYNC_METHODDEF |
12785 | | #endif /* !defined(OS_SYNC_METHODDEF) */ |
12786 | | |
12787 | | #ifndef OS_FDATASYNC_METHODDEF |
12788 | | #define OS_FDATASYNC_METHODDEF |
12789 | | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
12790 | | |
12791 | | #ifndef OS_CHOWN_METHODDEF |
12792 | | #define OS_CHOWN_METHODDEF |
12793 | | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
12794 | | |
12795 | | #ifndef OS_FCHOWN_METHODDEF |
12796 | | #define OS_FCHOWN_METHODDEF |
12797 | | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
12798 | | |
12799 | | #ifndef OS_LCHOWN_METHODDEF |
12800 | | #define OS_LCHOWN_METHODDEF |
12801 | | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
12802 | | |
12803 | | #ifndef OS_LINK_METHODDEF |
12804 | | #define OS_LINK_METHODDEF |
12805 | | #endif /* !defined(OS_LINK_METHODDEF) */ |
12806 | | |
12807 | | #ifndef OS_LISTDRIVES_METHODDEF |
12808 | | #define OS_LISTDRIVES_METHODDEF |
12809 | | #endif /* !defined(OS_LISTDRIVES_METHODDEF) */ |
12810 | | |
12811 | | #ifndef OS_LISTVOLUMES_METHODDEF |
12812 | | #define OS_LISTVOLUMES_METHODDEF |
12813 | | #endif /* !defined(OS_LISTVOLUMES_METHODDEF) */ |
12814 | | |
12815 | | #ifndef OS_LISTMOUNTS_METHODDEF |
12816 | | #define OS_LISTMOUNTS_METHODDEF |
12817 | | #endif /* !defined(OS_LISTMOUNTS_METHODDEF) */ |
12818 | | |
12819 | | #ifndef OS__PATH_ISDEVDRIVE_METHODDEF |
12820 | | #define OS__PATH_ISDEVDRIVE_METHODDEF |
12821 | | #endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */ |
12822 | | |
12823 | | #ifndef OS__GETFULLPATHNAME_METHODDEF |
12824 | | #define OS__GETFULLPATHNAME_METHODDEF |
12825 | | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
12826 | | |
12827 | | #ifndef OS__GETFINALPATHNAME_METHODDEF |
12828 | | #define OS__GETFINALPATHNAME_METHODDEF |
12829 | | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
12830 | | |
12831 | | #ifndef OS__FINDFIRSTFILE_METHODDEF |
12832 | | #define OS__FINDFIRSTFILE_METHODDEF |
12833 | | #endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */ |
12834 | | |
12835 | | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
12836 | | #define OS__GETVOLUMEPATHNAME_METHODDEF |
12837 | | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
12838 | | |
12839 | | #ifndef OS__PATH_SPLITROOT_METHODDEF |
12840 | | #define OS__PATH_SPLITROOT_METHODDEF |
12841 | | #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */ |
12842 | | |
12843 | | #ifndef OS__PATH_EXISTS_METHODDEF |
12844 | | #define OS__PATH_EXISTS_METHODDEF |
12845 | | #endif /* !defined(OS__PATH_EXISTS_METHODDEF) */ |
12846 | | |
12847 | | #ifndef OS__PATH_LEXISTS_METHODDEF |
12848 | | #define OS__PATH_LEXISTS_METHODDEF |
12849 | | #endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */ |
12850 | | |
12851 | | #ifndef OS__PATH_ISDIR_METHODDEF |
12852 | | #define OS__PATH_ISDIR_METHODDEF |
12853 | | #endif /* !defined(OS__PATH_ISDIR_METHODDEF) */ |
12854 | | |
12855 | | #ifndef OS__PATH_ISFILE_METHODDEF |
12856 | | #define OS__PATH_ISFILE_METHODDEF |
12857 | | #endif /* !defined(OS__PATH_ISFILE_METHODDEF) */ |
12858 | | |
12859 | | #ifndef OS__PATH_ISLINK_METHODDEF |
12860 | | #define OS__PATH_ISLINK_METHODDEF |
12861 | | #endif /* !defined(OS__PATH_ISLINK_METHODDEF) */ |
12862 | | |
12863 | | #ifndef OS__PATH_ISJUNCTION_METHODDEF |
12864 | | #define OS__PATH_ISJUNCTION_METHODDEF |
12865 | | #endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */ |
12866 | | |
12867 | | #ifndef OS_NICE_METHODDEF |
12868 | | #define OS_NICE_METHODDEF |
12869 | | #endif /* !defined(OS_NICE_METHODDEF) */ |
12870 | | |
12871 | | #ifndef OS_GETPRIORITY_METHODDEF |
12872 | | #define OS_GETPRIORITY_METHODDEF |
12873 | | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
12874 | | |
12875 | | #ifndef OS_SETPRIORITY_METHODDEF |
12876 | | #define OS_SETPRIORITY_METHODDEF |
12877 | | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
12878 | | |
12879 | | #ifndef OS_SYSTEM_METHODDEF |
12880 | | #define OS_SYSTEM_METHODDEF |
12881 | | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
12882 | | |
12883 | | #ifndef OS_UMASK_METHODDEF |
12884 | | #define OS_UMASK_METHODDEF |
12885 | | #endif /* !defined(OS_UMASK_METHODDEF) */ |
12886 | | |
12887 | | #ifndef OS_UNAME_METHODDEF |
12888 | | #define OS_UNAME_METHODDEF |
12889 | | #endif /* !defined(OS_UNAME_METHODDEF) */ |
12890 | | |
12891 | | #ifndef OS_EXECV_METHODDEF |
12892 | | #define OS_EXECV_METHODDEF |
12893 | | #endif /* !defined(OS_EXECV_METHODDEF) */ |
12894 | | |
12895 | | #ifndef OS_EXECVE_METHODDEF |
12896 | | #define OS_EXECVE_METHODDEF |
12897 | | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
12898 | | |
12899 | | #ifndef OS_POSIX_SPAWN_METHODDEF |
12900 | | #define OS_POSIX_SPAWN_METHODDEF |
12901 | | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
12902 | | |
12903 | | #ifndef OS_POSIX_SPAWNP_METHODDEF |
12904 | | #define OS_POSIX_SPAWNP_METHODDEF |
12905 | | #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */ |
12906 | | |
12907 | | #ifndef OS_SPAWNV_METHODDEF |
12908 | | #define OS_SPAWNV_METHODDEF |
12909 | | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
12910 | | |
12911 | | #ifndef OS_SPAWNVE_METHODDEF |
12912 | | #define OS_SPAWNVE_METHODDEF |
12913 | | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
12914 | | |
12915 | | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
12916 | | #define OS_REGISTER_AT_FORK_METHODDEF |
12917 | | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
12918 | | |
12919 | | #ifndef OS_FORK1_METHODDEF |
12920 | | #define OS_FORK1_METHODDEF |
12921 | | #endif /* !defined(OS_FORK1_METHODDEF) */ |
12922 | | |
12923 | | #ifndef OS_FORK_METHODDEF |
12924 | | #define OS_FORK_METHODDEF |
12925 | | #endif /* !defined(OS_FORK_METHODDEF) */ |
12926 | | |
12927 | | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
12928 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
12929 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
12930 | | |
12931 | | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
12932 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
12933 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
12934 | | |
12935 | | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
12936 | | #define OS_SCHED_GETSCHEDULER_METHODDEF |
12937 | | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
12938 | | |
12939 | | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
12940 | | #define OS_SCHED_SETSCHEDULER_METHODDEF |
12941 | | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
12942 | | |
12943 | | #ifndef OS_SCHED_GETPARAM_METHODDEF |
12944 | | #define OS_SCHED_GETPARAM_METHODDEF |
12945 | | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
12946 | | |
12947 | | #ifndef OS_SCHED_SETPARAM_METHODDEF |
12948 | | #define OS_SCHED_SETPARAM_METHODDEF |
12949 | | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
12950 | | |
12951 | | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
12952 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
12953 | | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
12954 | | |
12955 | | #ifndef OS_SCHED_YIELD_METHODDEF |
12956 | | #define OS_SCHED_YIELD_METHODDEF |
12957 | | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
12958 | | |
12959 | | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
12960 | | #define OS_SCHED_SETAFFINITY_METHODDEF |
12961 | | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
12962 | | |
12963 | | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
12964 | | #define OS_SCHED_GETAFFINITY_METHODDEF |
12965 | | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
12966 | | |
12967 | | #ifndef OS_POSIX_OPENPT_METHODDEF |
12968 | | #define OS_POSIX_OPENPT_METHODDEF |
12969 | | #endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */ |
12970 | | |
12971 | | #ifndef OS_GRANTPT_METHODDEF |
12972 | | #define OS_GRANTPT_METHODDEF |
12973 | | #endif /* !defined(OS_GRANTPT_METHODDEF) */ |
12974 | | |
12975 | | #ifndef OS_UNLOCKPT_METHODDEF |
12976 | | #define OS_UNLOCKPT_METHODDEF |
12977 | | #endif /* !defined(OS_UNLOCKPT_METHODDEF) */ |
12978 | | |
12979 | | #ifndef OS_PTSNAME_METHODDEF |
12980 | | #define OS_PTSNAME_METHODDEF |
12981 | | #endif /* !defined(OS_PTSNAME_METHODDEF) */ |
12982 | | |
12983 | | #ifndef OS_OPENPTY_METHODDEF |
12984 | | #define OS_OPENPTY_METHODDEF |
12985 | | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
12986 | | |
12987 | | #ifndef OS_LOGIN_TTY_METHODDEF |
12988 | | #define OS_LOGIN_TTY_METHODDEF |
12989 | | #endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ |
12990 | | |
12991 | | #ifndef OS_FORKPTY_METHODDEF |
12992 | | #define OS_FORKPTY_METHODDEF |
12993 | | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
12994 | | |
12995 | | #ifndef OS_GETEGID_METHODDEF |
12996 | | #define OS_GETEGID_METHODDEF |
12997 | | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
12998 | | |
12999 | | #ifndef OS_GETEUID_METHODDEF |
13000 | | #define OS_GETEUID_METHODDEF |
13001 | | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
13002 | | |
13003 | | #ifndef OS_GETGID_METHODDEF |
13004 | | #define OS_GETGID_METHODDEF |
13005 | | #endif /* !defined(OS_GETGID_METHODDEF) */ |
13006 | | |
13007 | | #ifndef OS_GETPID_METHODDEF |
13008 | | #define OS_GETPID_METHODDEF |
13009 | | #endif /* !defined(OS_GETPID_METHODDEF) */ |
13010 | | |
13011 | | #ifndef OS_GETGROUPLIST_METHODDEF |
13012 | | #define OS_GETGROUPLIST_METHODDEF |
13013 | | #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */ |
13014 | | |
13015 | | #ifndef OS_GETGROUPS_METHODDEF |
13016 | | #define OS_GETGROUPS_METHODDEF |
13017 | | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
13018 | | |
13019 | | #ifndef OS_INITGROUPS_METHODDEF |
13020 | | #define OS_INITGROUPS_METHODDEF |
13021 | | #endif /* !defined(OS_INITGROUPS_METHODDEF) */ |
13022 | | |
13023 | | #ifndef OS_GETPGID_METHODDEF |
13024 | | #define OS_GETPGID_METHODDEF |
13025 | | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
13026 | | |
13027 | | #ifndef OS_GETPGRP_METHODDEF |
13028 | | #define OS_GETPGRP_METHODDEF |
13029 | | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
13030 | | |
13031 | | #ifndef OS_SETPGRP_METHODDEF |
13032 | | #define OS_SETPGRP_METHODDEF |
13033 | | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
13034 | | |
13035 | | #ifndef OS_GETPPID_METHODDEF |
13036 | | #define OS_GETPPID_METHODDEF |
13037 | | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
13038 | | |
13039 | | #ifndef OS_GETLOGIN_METHODDEF |
13040 | | #define OS_GETLOGIN_METHODDEF |
13041 | | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
13042 | | |
13043 | | #ifndef OS_GETUID_METHODDEF |
13044 | | #define OS_GETUID_METHODDEF |
13045 | | #endif /* !defined(OS_GETUID_METHODDEF) */ |
13046 | | |
13047 | | #ifndef OS_KILL_METHODDEF |
13048 | | #define OS_KILL_METHODDEF |
13049 | | #endif /* !defined(OS_KILL_METHODDEF) */ |
13050 | | |
13051 | | #ifndef OS_KILLPG_METHODDEF |
13052 | | #define OS_KILLPG_METHODDEF |
13053 | | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
13054 | | |
13055 | | #ifndef OS_PLOCK_METHODDEF |
13056 | | #define OS_PLOCK_METHODDEF |
13057 | | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
13058 | | |
13059 | | #ifndef OS_SETUID_METHODDEF |
13060 | | #define OS_SETUID_METHODDEF |
13061 | | #endif /* !defined(OS_SETUID_METHODDEF) */ |
13062 | | |
13063 | | #ifndef OS_SETEUID_METHODDEF |
13064 | | #define OS_SETEUID_METHODDEF |
13065 | | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
13066 | | |
13067 | | #ifndef OS_SETEGID_METHODDEF |
13068 | | #define OS_SETEGID_METHODDEF |
13069 | | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
13070 | | |
13071 | | #ifndef OS_SETREUID_METHODDEF |
13072 | | #define OS_SETREUID_METHODDEF |
13073 | | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
13074 | | |
13075 | | #ifndef OS_SETREGID_METHODDEF |
13076 | | #define OS_SETREGID_METHODDEF |
13077 | | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
13078 | | |
13079 | | #ifndef OS_SETGID_METHODDEF |
13080 | | #define OS_SETGID_METHODDEF |
13081 | | #endif /* !defined(OS_SETGID_METHODDEF) */ |
13082 | | |
13083 | | #ifndef OS_SETGROUPS_METHODDEF |
13084 | | #define OS_SETGROUPS_METHODDEF |
13085 | | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
13086 | | |
13087 | | #ifndef OS_WAIT3_METHODDEF |
13088 | | #define OS_WAIT3_METHODDEF |
13089 | | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
13090 | | |
13091 | | #ifndef OS_WAIT4_METHODDEF |
13092 | | #define OS_WAIT4_METHODDEF |
13093 | | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
13094 | | |
13095 | | #ifndef OS_WAITID_METHODDEF |
13096 | | #define OS_WAITID_METHODDEF |
13097 | | #endif /* !defined(OS_WAITID_METHODDEF) */ |
13098 | | |
13099 | | #ifndef OS_WAITPID_METHODDEF |
13100 | | #define OS_WAITPID_METHODDEF |
13101 | | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
13102 | | |
13103 | | #ifndef OS_WAIT_METHODDEF |
13104 | | #define OS_WAIT_METHODDEF |
13105 | | #endif /* !defined(OS_WAIT_METHODDEF) */ |
13106 | | |
13107 | | #ifndef OS_PIDFD_OPEN_METHODDEF |
13108 | | #define OS_PIDFD_OPEN_METHODDEF |
13109 | | #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */ |
13110 | | |
13111 | | #ifndef OS_SETNS_METHODDEF |
13112 | | #define OS_SETNS_METHODDEF |
13113 | | #endif /* !defined(OS_SETNS_METHODDEF) */ |
13114 | | |
13115 | | #ifndef OS_UNSHARE_METHODDEF |
13116 | | #define OS_UNSHARE_METHODDEF |
13117 | | #endif /* !defined(OS_UNSHARE_METHODDEF) */ |
13118 | | |
13119 | | #ifndef OS_READLINK_METHODDEF |
13120 | | #define OS_READLINK_METHODDEF |
13121 | | #endif /* !defined(OS_READLINK_METHODDEF) */ |
13122 | | |
13123 | | #ifndef OS_SYMLINK_METHODDEF |
13124 | | #define OS_SYMLINK_METHODDEF |
13125 | | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
13126 | | |
13127 | | #ifndef OS_TIMERFD_CREATE_METHODDEF |
13128 | | #define OS_TIMERFD_CREATE_METHODDEF |
13129 | | #endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */ |
13130 | | |
13131 | | #ifndef OS_TIMERFD_SETTIME_METHODDEF |
13132 | | #define OS_TIMERFD_SETTIME_METHODDEF |
13133 | | #endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */ |
13134 | | |
13135 | | #ifndef OS_TIMERFD_SETTIME_NS_METHODDEF |
13136 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF |
13137 | | #endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */ |
13138 | | |
13139 | | #ifndef OS_TIMERFD_GETTIME_METHODDEF |
13140 | | #define OS_TIMERFD_GETTIME_METHODDEF |
13141 | | #endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */ |
13142 | | |
13143 | | #ifndef OS_TIMERFD_GETTIME_NS_METHODDEF |
13144 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF |
13145 | | #endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */ |
13146 | | |
13147 | | #ifndef OS_GETSID_METHODDEF |
13148 | | #define OS_GETSID_METHODDEF |
13149 | | #endif /* !defined(OS_GETSID_METHODDEF) */ |
13150 | | |
13151 | | #ifndef OS_SETSID_METHODDEF |
13152 | | #define OS_SETSID_METHODDEF |
13153 | | #endif /* !defined(OS_SETSID_METHODDEF) */ |
13154 | | |
13155 | | #ifndef OS_SETPGID_METHODDEF |
13156 | | #define OS_SETPGID_METHODDEF |
13157 | | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
13158 | | |
13159 | | #ifndef OS_TCGETPGRP_METHODDEF |
13160 | | #define OS_TCGETPGRP_METHODDEF |
13161 | | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
13162 | | |
13163 | | #ifndef OS_TCSETPGRP_METHODDEF |
13164 | | #define OS_TCSETPGRP_METHODDEF |
13165 | | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
13166 | | |
13167 | | #ifndef OS_DUP2_METHODDEF |
13168 | | #define OS_DUP2_METHODDEF |
13169 | | #endif /* !defined(OS_DUP2_METHODDEF) */ |
13170 | | |
13171 | | #ifndef OS_LOCKF_METHODDEF |
13172 | | #define OS_LOCKF_METHODDEF |
13173 | | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
13174 | | |
13175 | | #ifndef OS_READV_METHODDEF |
13176 | | #define OS_READV_METHODDEF |
13177 | | #endif /* !defined(OS_READV_METHODDEF) */ |
13178 | | |
13179 | | #ifndef OS_PREAD_METHODDEF |
13180 | | #define OS_PREAD_METHODDEF |
13181 | | #endif /* !defined(OS_PREAD_METHODDEF) */ |
13182 | | |
13183 | | #ifndef OS_PREADV_METHODDEF |
13184 | | #define OS_PREADV_METHODDEF |
13185 | | #endif /* !defined(OS_PREADV_METHODDEF) */ |
13186 | | |
13187 | | #ifndef OS_SENDFILE_METHODDEF |
13188 | | #define OS_SENDFILE_METHODDEF |
13189 | | #endif /* !defined(OS_SENDFILE_METHODDEF) */ |
13190 | | |
13191 | | #ifndef OS__FCOPYFILE_METHODDEF |
13192 | | #define OS__FCOPYFILE_METHODDEF |
13193 | | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
13194 | | |
13195 | | #ifndef OS_PIPE_METHODDEF |
13196 | | #define OS_PIPE_METHODDEF |
13197 | | #endif /* !defined(OS_PIPE_METHODDEF) */ |
13198 | | |
13199 | | #ifndef OS_PIPE2_METHODDEF |
13200 | | #define OS_PIPE2_METHODDEF |
13201 | | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
13202 | | |
13203 | | #ifndef OS_WRITEV_METHODDEF |
13204 | | #define OS_WRITEV_METHODDEF |
13205 | | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
13206 | | |
13207 | | #ifndef OS_PWRITE_METHODDEF |
13208 | | #define OS_PWRITE_METHODDEF |
13209 | | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
13210 | | |
13211 | | #ifndef OS_PWRITEV_METHODDEF |
13212 | | #define OS_PWRITEV_METHODDEF |
13213 | | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
13214 | | |
13215 | | #ifndef OS_COPY_FILE_RANGE_METHODDEF |
13216 | | #define OS_COPY_FILE_RANGE_METHODDEF |
13217 | | #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */ |
13218 | | |
13219 | | #ifndef OS_SPLICE_METHODDEF |
13220 | | #define OS_SPLICE_METHODDEF |
13221 | | #endif /* !defined(OS_SPLICE_METHODDEF) */ |
13222 | | |
13223 | | #ifndef OS_MKFIFO_METHODDEF |
13224 | | #define OS_MKFIFO_METHODDEF |
13225 | | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
13226 | | |
13227 | | #ifndef OS_MKNOD_METHODDEF |
13228 | | #define OS_MKNOD_METHODDEF |
13229 | | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
13230 | | |
13231 | | #ifndef OS_MAJOR_METHODDEF |
13232 | | #define OS_MAJOR_METHODDEF |
13233 | | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
13234 | | |
13235 | | #ifndef OS_MINOR_METHODDEF |
13236 | | #define OS_MINOR_METHODDEF |
13237 | | #endif /* !defined(OS_MINOR_METHODDEF) */ |
13238 | | |
13239 | | #ifndef OS_MAKEDEV_METHODDEF |
13240 | | #define OS_MAKEDEV_METHODDEF |
13241 | | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
13242 | | |
13243 | | #ifndef OS_FTRUNCATE_METHODDEF |
13244 | | #define OS_FTRUNCATE_METHODDEF |
13245 | | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
13246 | | |
13247 | | #ifndef OS_TRUNCATE_METHODDEF |
13248 | | #define OS_TRUNCATE_METHODDEF |
13249 | | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
13250 | | |
13251 | | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
13252 | | #define OS_POSIX_FALLOCATE_METHODDEF |
13253 | | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
13254 | | |
13255 | | #ifndef OS_POSIX_FADVISE_METHODDEF |
13256 | | #define OS_POSIX_FADVISE_METHODDEF |
13257 | | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
13258 | | |
13259 | | #ifndef OS_PUTENV_METHODDEF |
13260 | | #define OS_PUTENV_METHODDEF |
13261 | | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
13262 | | |
13263 | | #ifndef OS_UNSETENV_METHODDEF |
13264 | | #define OS_UNSETENV_METHODDEF |
13265 | | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
13266 | | |
13267 | | #ifndef OS_WCOREDUMP_METHODDEF |
13268 | | #define OS_WCOREDUMP_METHODDEF |
13269 | | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
13270 | | |
13271 | | #ifndef OS_WIFCONTINUED_METHODDEF |
13272 | | #define OS_WIFCONTINUED_METHODDEF |
13273 | | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
13274 | | |
13275 | | #ifndef OS_WIFSTOPPED_METHODDEF |
13276 | | #define OS_WIFSTOPPED_METHODDEF |
13277 | | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
13278 | | |
13279 | | #ifndef OS_WIFSIGNALED_METHODDEF |
13280 | | #define OS_WIFSIGNALED_METHODDEF |
13281 | | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
13282 | | |
13283 | | #ifndef OS_WIFEXITED_METHODDEF |
13284 | | #define OS_WIFEXITED_METHODDEF |
13285 | | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
13286 | | |
13287 | | #ifndef OS_WEXITSTATUS_METHODDEF |
13288 | | #define OS_WEXITSTATUS_METHODDEF |
13289 | | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
13290 | | |
13291 | | #ifndef OS_WTERMSIG_METHODDEF |
13292 | | #define OS_WTERMSIG_METHODDEF |
13293 | | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
13294 | | |
13295 | | #ifndef OS_WSTOPSIG_METHODDEF |
13296 | | #define OS_WSTOPSIG_METHODDEF |
13297 | | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
13298 | | |
13299 | | #ifndef OS_FSTATVFS_METHODDEF |
13300 | | #define OS_FSTATVFS_METHODDEF |
13301 | | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
13302 | | |
13303 | | #ifndef OS_STATVFS_METHODDEF |
13304 | | #define OS_STATVFS_METHODDEF |
13305 | | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
13306 | | |
13307 | | #ifndef OS__GETDISKUSAGE_METHODDEF |
13308 | | #define OS__GETDISKUSAGE_METHODDEF |
13309 | | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
13310 | | |
13311 | | #ifndef OS_FPATHCONF_METHODDEF |
13312 | | #define OS_FPATHCONF_METHODDEF |
13313 | | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
13314 | | |
13315 | | #ifndef OS_PATHCONF_METHODDEF |
13316 | | #define OS_PATHCONF_METHODDEF |
13317 | | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
13318 | | |
13319 | | #ifndef OS_CONFSTR_METHODDEF |
13320 | | #define OS_CONFSTR_METHODDEF |
13321 | | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
13322 | | |
13323 | | #ifndef OS_SYSCONF_METHODDEF |
13324 | | #define OS_SYSCONF_METHODDEF |
13325 | | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
13326 | | |
13327 | | #ifndef OS_STARTFILE_METHODDEF |
13328 | | #define OS_STARTFILE_METHODDEF |
13329 | | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
13330 | | |
13331 | | #ifndef OS_GETLOADAVG_METHODDEF |
13332 | | #define OS_GETLOADAVG_METHODDEF |
13333 | | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
13334 | | |
13335 | | #ifndef OS_SETRESUID_METHODDEF |
13336 | | #define OS_SETRESUID_METHODDEF |
13337 | | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
13338 | | |
13339 | | #ifndef OS_SETRESGID_METHODDEF |
13340 | | #define OS_SETRESGID_METHODDEF |
13341 | | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
13342 | | |
13343 | | #ifndef OS_GETRESUID_METHODDEF |
13344 | | #define OS_GETRESUID_METHODDEF |
13345 | | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
13346 | | |
13347 | | #ifndef OS_GETRESGID_METHODDEF |
13348 | | #define OS_GETRESGID_METHODDEF |
13349 | | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
13350 | | |
13351 | | #ifndef OS_GETXATTR_METHODDEF |
13352 | | #define OS_GETXATTR_METHODDEF |
13353 | | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
13354 | | |
13355 | | #ifndef OS_SETXATTR_METHODDEF |
13356 | | #define OS_SETXATTR_METHODDEF |
13357 | | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
13358 | | |
13359 | | #ifndef OS_REMOVEXATTR_METHODDEF |
13360 | | #define OS_REMOVEXATTR_METHODDEF |
13361 | | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
13362 | | |
13363 | | #ifndef OS_LISTXATTR_METHODDEF |
13364 | | #define OS_LISTXATTR_METHODDEF |
13365 | | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
13366 | | |
13367 | | #ifndef OS_MEMFD_CREATE_METHODDEF |
13368 | | #define OS_MEMFD_CREATE_METHODDEF |
13369 | | #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */ |
13370 | | |
13371 | | #ifndef OS_EVENTFD_METHODDEF |
13372 | | #define OS_EVENTFD_METHODDEF |
13373 | | #endif /* !defined(OS_EVENTFD_METHODDEF) */ |
13374 | | |
13375 | | #ifndef OS_EVENTFD_READ_METHODDEF |
13376 | | #define OS_EVENTFD_READ_METHODDEF |
13377 | | #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */ |
13378 | | |
13379 | | #ifndef OS_EVENTFD_WRITE_METHODDEF |
13380 | | #define OS_EVENTFD_WRITE_METHODDEF |
13381 | | #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */ |
13382 | | |
13383 | | #ifndef OS_GET_TERMINAL_SIZE_METHODDEF |
13384 | | #define OS_GET_TERMINAL_SIZE_METHODDEF |
13385 | | #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */ |
13386 | | |
13387 | | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
13388 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
13389 | | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
13390 | | |
13391 | | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
13392 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
13393 | | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
13394 | | |
13395 | | #ifndef OS_GETRANDOM_METHODDEF |
13396 | | #define OS_GETRANDOM_METHODDEF |
13397 | | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
13398 | | |
13399 | | #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF |
13400 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF |
13401 | | #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */ |
13402 | | |
13403 | | #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13404 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13405 | | #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */ |
13406 | | |
13407 | | #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13408 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13409 | | #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ |
13410 | | |
13411 | | #ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13412 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13413 | | #endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */ |
13414 | | |
13415 | | #ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13416 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13417 | | #endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */ |
13418 | | |
13419 | | #ifndef OS__EMSCRIPTEN_LOG_METHODDEF |
13420 | | #define OS__EMSCRIPTEN_LOG_METHODDEF |
13421 | | #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ |
13422 | | /*[clinic end generated code: output=23de5d098e2dd73f input=a9049054013a1b77]*/ |